/*-
* Copyright (c) 1996, 1997, 1998, 2001 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
* NASA Ames Research Center.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Copyright (c) 1997-1999, 2001 Eduardo E. Horvath. All rights reserved.
* Copyright (c) 1996 Charles M. Hannum. All rights reserved.
* Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Christopher G. Demetriou
* for the NetBSD Project.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#if 0
/*
* The following macro could be used to generate the bus_space*() functions
* but it uses a gcc extension and is ANSI-only.
#define PROTO_bus_space_xxx (bus_space_tag_t t, ...)
#define RETURNTYPE_bus_space_xxx void *
#define BUSFUN(name, returntype, t, args...) \
static __inline RETURNTYPE_##name \
bus_##name PROTO_##name \
{ \
while (t->sparc_##name == NULL) \
t = t->parent; \
return (*(t)->sparc_##name)(t, args); \
}
*/
#endif
/*
* Bus space function prototypes.
*/
static void *bus_intr_establish(
bus_space_tag_t,
int, /*bus-specific intr*/
int, /*device class level,
see machine/intr.h*/
int (*)(void *), /*handler*/
void *); /*handler arg*/
/* This macro finds the first "upstream" implementation of method `f' */
#define _BS_CALL(t,f) \
while (t->f == NULL) \
t = t->parent; \
return (*(t)->f)
#define _BS_VOID_CALL(t,f) \
while (t->f == NULL) \
t = t->parent; \
(*(t)->f)
static __inline void *
bus_intr_establish(bus_space_tag_t t, int p, int l, int (*h)(void *), void *a)
{
_BS_CALL(t, sparc_intr_establish)(t, p, l, h, a, NULL);
}
/* XXXX Things get complicated if we use unmapped register accesses. */
#define bus_space_vaddr(t, h) (PHYS_ASI((h)._asi) ? \
NULL : (void *)(vaddr_t)((h)._ptr))
static __inline void
sparc_bus_space_barrier(bus_space_tag_t t, bus_space_handle_t h,
bus_size_t o, bus_size_t s, int f)
{
/*
* We have a bit of a problem with the bus_space_barrier()
* interface. It defines a read barrier and a write barrier
* which really don't map to the 7 different types of memory
* barriers in the SPARC v9 instruction set.
*/
if (f == BUS_SPACE_BARRIER_READ)
/* A load followed by a load to the same location? */
__asm volatile("membar #Lookaside");
else if (f == BUS_SPACE_BARRIER_WRITE)
/* A store followed by a store? */
__asm volatile("membar #StoreStore");
else
/* A store followed by a load? */
__asm volatile("membar #StoreLoad|#MemIssue|#Lookaside");
}
/*
* uintN_t bus_space_read_N(bus_space_tag_t tag,
* bus_space_handle_t bsh, bus_size_t offset);
*
* Read a 1, 2, 4, or 8 byte quantity from bus space
* described by tag/handle/offset.
*/
#ifndef BUS_SPACE_DEBUG
#define bus_space_read_1(t, h, o) \
(0 ? (t)->type : lduba((h)._ptr + (o), (h)._asi))