Implement sparse bus space support.

This commit is contained in:
tsubai 1998-12-06 15:39:12 +00:00
parent 5ff97947fe
commit fbeabd992c
1 changed files with 148 additions and 175 deletions

View File

@ -1,5 +1,4 @@
/* $NetBSD: bus.h,v 1.5 1998/10/03 21:24:00 thorpej Exp $ */
/* $OpenBSD: bus.h,v 1.1 1997/10/13 10:53:42 pefo Exp $ */
/* $NetBSD: bus.h,v 1.6 1998/12/06 15:39:12 tsubai Exp $ */
/*-
* Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
@ -69,61 +68,36 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Copyright (c) 1997 Per Fogelstrom. All rights reserved.
* Copyright (c) 1996 Niklas Hallqvist. 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.
*/
#ifndef _MACPPC_BUS_H_
#define _MACPPC_BUS_H_
#include <machine/pio.h>
/*
* Values for the PowerMac bus space tag, not to be used directly by MI code.
*/
/* #define MACPPC_BUS_REVERSE 1 */
/*
* Bus access types.
*/
typedef u_int32_t bus_addr_t;
typedef u_int32_t bus_size_t;
typedef u_int32_t bus_space_handle_t;
typedef u_int32_t bus_space_tag_t;
/*
* Access methods for bus resources
* Values for the macppc bus space tag, not to be used directly by MI code.
*/
#define __BUS_SPACE_HAS_STREAM_METHODS
#define MACPPC_BUS_ADDR_MASK 0xfffff000
#define MACPPC_BUS_STRIDE_MASK 0x0000000f
#define macppc_make_bus_space_tag(addr, stride) \
(((addr) & MACPPC_BUS_ADDR_MASK) | (stride))
#define __BA(t, h, o) ((void *)((h) + ((o) << ((t) & MACPPC_BUS_STRIDE_MASK))))
/*
* Bus address and size types
*/
typedef u_int32_t bus_addr_t;
typedef u_int32_t bus_size_t;
/*
* Access methods for bus resources and address space.
*/
typedef u_int32_t bus_space_tag_t;
typedef u_int32_t bus_space_handle_t;
/*
* int bus_space_map __P((bus_space_tag_t t, bus_addr_t addr,
* bus_size_t size, int flags, bus_space_handle_t *bshp));
@ -134,10 +108,24 @@ typedef u_int32_t bus_space_tag_t;
#define BUS_SPACE_MAP_CACHEABLE 0x01
#define BUS_SPACE_MAP_LINEAR 0x02
#define bus_space_map(t, addr, size, cacheable, bshp) \
((*(bshp) = (bus_space_handle_t)mapiodev(((u_int)(t)) + (addr), size)), 0)
extern void * mapiodev __P((paddr_t, psize_t));
static __inline int
bus_space_map(t, addr, size, flags, bshp)
bus_space_tag_t t;
bus_addr_t addr;
bus_size_t size;
int flags;
bus_space_handle_t *bshp;
{
paddr_t base = t & MACPPC_BUS_ADDR_MASK;
int stride = t & MACPPC_BUS_STRIDE_MASK;
*bshp = (bus_space_handle_t)
mapiodev(base + (addr << stride), size << stride);
return 0;
}
/*
* int bus_space_unmap __P((bus_space_tag_t t,
* bus_space_handle_t bsh, bus_size_t size));
@ -156,7 +144,7 @@ extern void * mapiodev __P((paddr_t, psize_t));
*/
#define bus_space_subregion(t, bsh, offset, size, bshp) \
((*(bshp) = (bsh) + (offset)), 0)
((*(bshp) = (bus_space_handle_t)__BA(t, bsh, offset)), 0)
/*
* int bus_space_alloc __P((bus_space_tag_t t, bus_addr_t rstart,
@ -189,16 +177,16 @@ extern void * mapiodev __P((paddr_t, psize_t));
* described by tag/handle/offset.
*/
#define bus_space_read_1(t, h, o) (in8((h) + (o)))
#define bus_space_read_2(t, h, o) (in16rb((h) + (o)))
#define bus_space_read_4(t, h, o) (in32rb((h) + (o)))
#define bus_space_read_1(t, h, o) (in8(__BA(t, h, o)))
#define bus_space_read_2(t, h, o) (in16rb(__BA(t, h, o)))
#define bus_space_read_4(t, h, o) (in32rb(__BA(t, h, o)))
#if 0 /* Cause a link error for bus_space_read_8 */
#define bus_space_read_8(t, h, o) !!! unimplemented !!!
#endif
#define bus_space_read_stream_1(t, h, o) (in8((h) + (o)))
#define bus_space_read_stream_2(t, h, o) (in16((h) + (o)))
#define bus_space_read_stream_4(t, h, o) (in32((h) + (o)))
#define bus_space_read_stream_1(t, h, o) (in8(__BA(t, h, o)))
#define bus_space_read_stream_2(t, h, o) (in16(__BA(t, h, o)))
#define bus_space_read_stream_4(t, h, o) (in32(__BA(t, h, o)))
#if 0 /* Cause a link error for bus_space_read_stream_8 */
#define bus_space_read_8(t, h, o) !!! unimplemented !!!
#endif
@ -213,15 +201,15 @@ extern void * mapiodev __P((paddr_t, psize_t));
*/
#define bus_space_read_multi_1(t, h, o, a, c) do { \
ins8((u_int8_t *)((h) + (o)), (a), (c)); \
ins8(__BA(t, h, o), (a), (c)); \
} while (0)
#define bus_space_read_multi_2(t, h, o, a, c) do { \
ins16rb((u_int16_t *)((h) + (o)), (a), (c)); \
ins16rb(__BA(t, h, o), (a), (c)); \
} while (0)
#define bus_space_read_multi_4(t, h, o, a, c) do { \
ins32rb((u_int32_t *)((h) + (o)), (a), (c)); \
ins32rb(__BA(t, h, o), (a), (c)); \
} while (0)
#if 0 /* Cause a link error for bus_space_read_multi_8 */
@ -229,15 +217,15 @@ extern void * mapiodev __P((paddr_t, psize_t));
#endif
#define bus_space_read_multi_stream_1(t, h, o, a, c) do { \
ins8((u_int8_t *)((h) + (o)), (a), (c)); \
ins8(__BA(t, h, o), (a), (c)); \
} while (0)
#define bus_space_read_multi_stream_2(t, h, o, a, c) do { \
ins16((u_int16_t *)((h) + (o)), (a), (c)); \
ins16(__BA(t, h, o), (a), (c)); \
} while (0)
#define bus_space_read_multi_stream_4(t, h, o, a, c) do { \
ins32((u_int32_t *)((h) + (o)), (a), (c)); \
ins32(__BA(t, h, o), (a), (c)); \
} while (0)
#if 0 /* Cause a link error for bus_space_read_multi_stream_8 */
@ -262,9 +250,8 @@ bus_space_read_region_1(tag, bsh, offset, addr, count)
u_int8_t *addr;
size_t count;
{
volatile u_int8_t *s;
volatile u_int8_t *s = __BA(tag, bsh, offset);
s = (volatile u_int8_t *)(bsh + offset);
while (count--)
*addr++ = *s++;
__asm __volatile("eieio; sync");
@ -278,9 +265,8 @@ bus_space_read_region_2(tag, bsh, offset, addr, count)
u_int16_t *addr;
size_t count;
{
volatile u_int16_t *s;
volatile u_int16_t *s = __BA(tag, bsh, offset);
s = (volatile u_int16_t *)(bsh + offset);
while (count--)
__asm __volatile("lhbrx %0, 0, %1" :
"=r"(*addr++) : "r"(s++));
@ -295,9 +281,8 @@ bus_space_read_region_4(tag, bsh, offset, addr, count)
u_int32_t *addr;
size_t count;
{
volatile u_int32_t *s;
volatile u_int32_t *s = __BA(tag, bsh, offset);
s = (volatile u_int32_t *)(bsh + offset);
while (count--)
__asm __volatile("lwbrx %0, 0, %1" :
"=r"(*addr++) : "r"(s++));
@ -316,9 +301,8 @@ bus_space_read_region_stream_2(tag, bsh, offset, addr, count)
u_int16_t *addr;
size_t count;
{
volatile u_int16_t *s;
volatile u_int16_t *s = __BA(tag, bsh, offset);
s = (volatile u_int16_t *)(bsh + offset);
while (count--)
*addr++ = *s++;
__asm __volatile("eieio; sync");
@ -332,9 +316,8 @@ bus_space_read_region_stream_4(tag, bsh, offset, addr, count)
u_int32_t *addr;
size_t count;
{
volatile u_int32_t *s;
volatile u_int32_t *s = __BA(tag, bsh, offset);
s = (volatile u_int32_t *)(bsh + offset);
while (count--)
*addr++ = *s++;
__asm __volatile("eieio; sync");
@ -353,16 +336,16 @@ bus_space_read_region_stream_4(tag, bsh, offset, addr, count)
* described by tag/handle/offset.
*/
#define bus_space_write_1(t, h, o, v) out8((h) + (o), (v))
#define bus_space_write_2(t, h, o, v) out16rb((h) + (o), (v))
#define bus_space_write_4(t, h, o, v) out32rb((h) + (o), (v))
#define bus_space_write_1(t, h, o, v) out8(__BA(t, h, o), (v))
#define bus_space_write_2(t, h, o, v) out16rb(__BA(t, h, o), (v))
#define bus_space_write_4(t, h, o, v) out32rb(__BA(t, h, o), (v))
#define bus_space_write_stream_1(t, h, o, v) out8((h) + (o), (v))
#define bus_space_write_stream_2(t, h, o, v) out16((h) + (o), (v))
#define bus_space_write_stream_4(t, h, o, v) out32((h) + (o), (v))
#define bus_space_write_stream_1(t, h, o, v) out8(__BA(t, h, o), (v))
#define bus_space_write_stream_2(t, h, o, v) out16(__BA(t, h, o), (v))
#define bus_space_write_stream_4(t, h, o, v) out32(__BA(t, h, o), (v))
#if 0 /* Cause a link error for bus_space_write_8 */
#define bus_space_write_8
#define bus_space_write_8 !!! unimplemented !!!
#endif
/*
@ -375,31 +358,31 @@ bus_space_read_region_stream_4(tag, bsh, offset, addr, count)
*/
#define bus_space_write_multi_1(t, h, o, a, c) do { \
outsb((u_int8_t *)((h) + (o)), (a), (c)); \
outsb(__BA(t, h, o), (a), (c)); \
} while (0)
#define bus_space_write_multi_2(t, h, o, a, c) do { \
outsw((u_int16_t *)((h) + (o)), (a), (c)); \
outsw(__BA(t, h, o), (a), (c)); \
} while (0)
#define bus_space_write_multi_4(t, h, o, a, c) do { \
outsl((u_int32_t *)((h) + (o)), (a), (c)); \
outsl(__BA(t, h, o), (a), (c)); \
} while (0)
#if 0
#define bus_space_write_multi_8
#define bus_space_write_multi_8 !!! unimplemented !!!
#endif
#define bus_space_write_multi_stream_2(t, h, o, a, c) do { \
outsw((u_int16_t *)((h) + (o)), (a), (c)); \
outsw(__BA(t, h, o), (a), (c)); \
} while (0)
#define bus_space_write_multi_stream_4(t, h, o, a, c) do { \
outsl((u_int32_t *)((h) + (o)), (a), (c)); \
outsl(__BA(t, h, o), (a), (c)); \
} while (0)
#if 0
#define bus_space_write_multi_stream_8
#define bus_space_write_multi_stream_8 !!! unimplemented !!!
#endif
/*
@ -419,9 +402,8 @@ bus_space_write_region_1(tag, bsh, offset, addr, count)
const u_int8_t *addr;
size_t count;
{
volatile u_int8_t *d;
volatile u_int8_t *d = __BA(tag, bsh, offset);
d = (volatile u_int8_t *)(bsh + offset);
while (count--)
*d++ = *addr++;
__asm __volatile("eieio; sync");
@ -435,9 +417,8 @@ bus_space_write_region_2(tag, bsh, offset, addr, count)
const u_int16_t *addr;
size_t count;
{
volatile u_int16_t *d;
volatile u_int16_t *d = __BA(tag, bsh, offset);
d = (volatile u_int16_t *)(bsh + offset);
while (count--)
__asm __volatile("sthbrx %0, 0, %1" ::
"r"(*addr++), "r"(d++));
@ -452,9 +433,8 @@ bus_space_write_region_4(tag, bsh, offset, addr, count)
const u_int32_t *addr;
size_t count;
{
volatile u_int32_t *d;
volatile u_int32_t *d = __BA(tag, bsh, offset);
d = (volatile u_int32_t *)(bsh + offset);
while (count--)
__asm __volatile("stwbrx %0, 0, %1" ::
"r"(*addr++), "r"(d++));
@ -473,9 +453,8 @@ bus_space_write_region_stream_2(tag, bsh, offset, addr, count)
const u_int16_t *addr;
size_t count;
{
volatile u_int16_t *d;
volatile u_int16_t *d = __BA(tag, bsh, offset);
d = (volatile u_int16_t *)(bsh + offset);
while (count--)
*d++ = *addr++;
__asm __volatile("eieio; sync");
@ -489,9 +468,8 @@ bus_space_write_region_stream_4(tag, bsh, offset, addr, count)
const u_int32_t *addr;
size_t count;
{
volatile u_int32_t *d;
volatile u_int32_t *d = __BA(tag, bsh, offset);
d = (volatile u_int32_t *)(bsh + offset);
while (count--)
*d++ = *addr++;
__asm __volatile("eieio; sync");
@ -518,9 +496,8 @@ bus_space_set_multi_1(tag, bsh, offset, val, count)
u_int8_t val;
size_t count;
{
volatile u_int8_t *d;
volatile u_int8_t *d = __BA(tag, bsh, offset);
d = (volatile u_int8_t *)(bsh + offset);
while (count--)
*d = val;
__asm __volatile("eieio; sync");
@ -534,9 +511,8 @@ bus_space_set_multi_2(tag, bsh, offset, val, count)
u_int16_t val;
size_t count;
{
volatile u_int16_t *d;
volatile u_int16_t *d = __BA(tag, bsh, offset);
d = (volatile u_int16_t *)(bsh + offset);
while (count--)
__asm __volatile("sthbrx %0, 0, %1" ::
"r"(val), "r"(d));
@ -551,9 +527,8 @@ bus_space_set_multi_4(tag, bsh, offset, val, count)
u_int32_t val;
size_t count;
{
volatile u_int32_t *d;
volatile u_int32_t *d = __BA(tag, bsh, offset);
d = (volatile u_int32_t *)(bsh + offset);
while (count--)
__asm __volatile("stwbrx %0, 0, %1" ::
"r"(val), "r"(d));
@ -572,9 +547,8 @@ bus_space_set_multi_stream_2(tag, bsh, offset, val, count)
u_int16_t val;
size_t count;
{
volatile u_int16_t *d;
volatile u_int16_t *d = __BA(tag, bsh, offset);
d = (volatile u_int16_t *)(bsh + offset);
while (count--)
*d = val;
__asm __volatile("eieio; sync");
@ -588,17 +562,15 @@ bus_space_set_multi_stream_4(tag, bsh, offset, val, count)
u_int32_t val;
size_t count;
{
volatile u_int32_t *d;
volatile u_int32_t *d = __BA(tag, bsh, offset);
d = (volatile u_int32_t *)(bsh + offset);
while (count--)
*d = val;
__asm __volatile("eieio; sync");
}
#if 0
#define bus_space_set_multi_stream_8 \
!!! bus_space_set_multi_stream_8 unimplemented !!!
#define bus_space_set_multi_stream_8 !!! unimplemented !!!
#endif
/*
@ -618,9 +590,8 @@ bus_space_set_region_1(tag, bsh, offset, val, count)
u_int8_t val;
size_t count;
{
volatile u_int8_t *d;
volatile u_int8_t *d = __BA(tag, bsh, offset);
d = (volatile u_int8_t *)(bsh + offset);
while (count--)
*d++ = val;
__asm __volatile("eieio; sync");
@ -634,9 +605,8 @@ bus_space_set_region_2(tag, bsh, offset, val, count)
u_int16_t val;
size_t count;
{
volatile u_int16_t *d;
volatile u_int16_t *d = __BA(tag, bsh, offset);
d = (volatile u_int16_t *)(bsh + offset);
while (count--)
__asm __volatile("sthbrx %0, 0, %1" ::
"r"(val), "r"(d++));
@ -651,9 +621,8 @@ bus_space_set_region_4(tag, bsh, offset, val, count)
u_int32_t val;
size_t count;
{
volatile u_int32_t *d;
volatile u_int32_t *d = __BA(tag, bsh, offset);
d = (volatile u_int32_t *)(bsh + offset);
while (count--)
__asm __volatile("stwbrx %0, 0, %1" ::
"r"(val), "r"(d++));
@ -672,9 +641,8 @@ bus_space_set_region_stream_2(tag, bsh, offset, val, count)
u_int16_t val;
size_t count;
{
volatile u_int16_t *d;
volatile u_int16_t *d = __BA(tag, bsh, offset);
d = (volatile u_int16_t *)(bsh + offset);
while (count--)
*d++ = val;
__asm __volatile("eieio; sync");
@ -688,17 +656,15 @@ bus_space_set_region_stream_4(tag, bsh, offset, val, count)
u_int32_t val;
size_t count;
{
volatile u_int32_t *d;
volatile u_int32_t *d = __BA(tag, bsh, offset);
d = (volatile u_int32_t *)(bsh + offset);
while (count--)
*d++ = val;
__asm __volatile("eieio; sync");
}
#if 0
#define bus_space_set_region_stream_8 \
!!! bus_space_set_region_stream_8 unimplemented !!!
#define bus_space_set_region_stream_8 !!! unimplemented !!!
#endif
/*
@ -723,10 +689,17 @@ bus_space_set_region_stream_4(tag, bsh, offset, val, count)
* Note: the macppc does not currently require barriers, but we must
* provide the flags to MI code.
*/
#define bus_space_barrier(t, h, o, l, f) \
((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f)))
#define BUS_BARRIER_READ 0x01 /* force read barrier */
#define BUS_BARRIER_WRITE 0x02 /* force write barrier */
#define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */
#define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */
#ifdef __BUS_SPACE_COMPAT_OLDDEFS
/* compatibility definitions; deprecated */
#define BUS_BARRIER_READ BUS_SPACE_BARRIER_READ
#define BUS_BARRIER_WRITE BUS_SPACE_BARRIER_WRITE
#endif
/*
* Bus DMA methods.