Implement basic bus space access macros/functions.

Note:  we currently do not use the extent manager.
This commit is contained in:
scottr 1997-02-03 17:32:54 +00:00
parent b2f7c338bf
commit f042e543c9
2 changed files with 482 additions and 6 deletions

View File

@ -0,0 +1,370 @@
/* $NetBSD: bus.h,v 1.1 1997/02/03 17:32:54 scottr Exp $ */
/*
* Copyright "g" (c) 1997 Scott Reynolds. All rights reserved.
* Copyright "g" (c) 1996 Jason R. Thorpe. 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 Scott Reynolds 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 _MAC68K_BUS_H_
#define _MAC68K_BUS_H_
/*
* Value for the mac68k bus space tag, not to be used directly by MI code.
*/
#define MAC68K_BUS_SPACE_MEM 0 /* space is mem space */
/*
* Bus address and size types
*/
typedef u_long bus_addr_t;
typedef u_long bus_size_t;
/*
* Access methods for bus resources and address space.
*/
typedef u_long bus_space_tag_t;
typedef caddr_t bus_space_handle_t;
int bus_space_map __P((bus_space_tag_t, bus_addr_t, bus_size_t,
int, bus_space_handle_t *));
void bus_space_unmap __P((bus_space_tag_t, bus_space_handle_t,
bus_size_t));
int bus_space_subregion __P((bus_space_tag_t t, bus_space_handle_t bsh,
bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp));
/*
* u_intN_t bus_space_read_N __P((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.
*/
#define bus_space_read_1(t, h, o) \
((void) t, (*(volatile u_int8_t *)((h) + (o))))
#define bus_space_read_2(t, h, o) \
((void) t, (*(volatile u_int16_t *)((h) + (o))))
#define bus_space_read_4(t, h, o) \
((void) t, (*(volatile u_int32_t *)((h) + (o))))
#if 0 /* Cause a link error for bus_space_read_8 */
#define bus_space_read_8(t, h, o) !!! bus_space_read_8 unimplemented !!!
#endif
/*
* void bus_space_read_multi_N __P((bus_space_tag_t tag,
* bus_space_handle_t bsh, bus_size_t offset,
* u_intN_t *addr, size_t count));
*
* Read `count' 1, 2, 4, or 8 byte quantities from bus space
* described by tag/handle/offset and copy into buffer provided.
*/
#define bus_space_read_multi_1(t, h, o, a, c) do { \
__asm __volatile (" \
movl %0,a0 ; \
movl %1,a1 ; \
movl %2,d0 ; \
1: movb a0@,a1@+ ; \
subql #1,d0 ; \
jne 1b" : \
: \
"r" ((h) + (o)), "g" (a), "g" (c) : \
"a0","a1","d0"); \
} while (0);
#define bus_space_read_multi_2(t, h, o, a, c) do { \
__asm __volatile (" \
movl %0,a0 ; \
movl %1,a1 ; \
movl %2,d0 ; \
1: movw a0@,a1@+ ; \
subql #1,d0 ; \
jne 1b" : \
: \
"r" ((h) + (o)), "g" (a), "g" (c) : \
"a0","a1","d0"); \
} while (0);
#define bus_space_read_multi_4(t, h, o, a, c) do { \
__asm __volatile (" \
movl %0,a0 ; \
movl %1,a1 ; \
movl %2,d0 ; \
1: movl a0@,a1@+ ; \
subql #1,d0 ; \
jne 1b" : \
: \
"r" ((h) + (o)), "g" (a), "g" (c) : \
"a0","a1","d0"); \
} while (0);
#if 0 /* Cause a link error for bus_space_read_multi_8 */
#define bus_space_read_multi_8 !!! bus_space_read_multi_8 unimplemented !!!
#endif
/*
* void bus_space_read_region_N __P((bus_space_tag_t tag,
* bus_space_handle_t bsh, bus_size_t offset,
* u_intN_t *addr, size_t count));
*
* Read `count' 1, 2, 4, or 8 byte quantities from bus space
* described by tag/handle and starting at `offset' and copy into
* buffer provided.
*/
#define bus_space_read_region_1(t, h, o, a, c) do { \
__asm __volatile (" \
movl %0,a0 ; \
movl %1,a1 ; \
movl %2,d0 ; \
1: movb a0@+,a1@+ ; \
subql #1,d0 ; \
jne 1b" : \
: \
"r" ((h) + (o)), "g" (a), "g" (c) : \
"a0","a1","d0"); \
} while (0);
#define bus_space_read_region_2(t, h, o, a, c) do { \
__asm __volatile (" \
movl %0,a0 ; \
movl %1,a1 ; \
movl %2,d0 ; \
1: movw a0@+,a1@+ ; \
subql #1,d0 ; \
jne 1b" : \
: \
"r" ((h) + (o)), "g" (a), "g" (c) : \
"a0","a1","d0"); \
} while (0);
#define bus_space_read_region_4(t, h, o, a, c) do { \
__asm __volatile (" \
movl %0,a0 ; \
movl %1,a1 ; \
movl %2,d0 ; \
1: movl a0@+,a1@+ ; \
subql #1,d0 ; \
jne 1b" : \
: \
"r" ((h) + (o)), "g" (a), "g" (c) : \
"a0","a1","d0"); \
} while (0);
#if 0 /* Cause a link error for bus_space_read_region_8 */
#define bus_space_read_region_8 !!! bus_space_read_region_8 unimplemented !!!
#endif
/*
* void bus_space_write_N __P((bus_space_tag_t tag,
* bus_space_handle_t bsh, bus_size_t offset,
* u_intN_t value));
*
* Write the 1, 2, 4, or 8 byte value `value' to bus space
* described by tag/handle/offset.
*/
#define bus_space_write_1(t, h, o, v) \
((void) t, ((void)(*(volatile u_int8_t *)((h) + (o)) = (v))))
#define bus_space_write_2(t, h, o, v) \
((void) t, ((void)(*(volatile u_int16_t *)((h) + (o)) = (v))))
#define bus_space_write_4(t, h, o, v) \
((void) t, ((void)(*(volatile u_int32_t *)((h) + (o)) = (v))))
#if 0 /* Cause a link error for bus_space_write_8 */
#define bus_space_write_8 !!! bus_space_write_8 not implemented !!!
#endif
/*
* void bus_space_write_multi_N __P((bus_space_tag_t tag,
* bus_space_handle_t bsh, bus_size_t offset,
* const u_intN_t *addr, size_t count));
*
* Write `count' 1, 2, 4, or 8 byte quantities from the buffer
* provided to bus space described by tag/handle/offset.
*/
#define bus_space_write_multi_1(t, h, o, a, c) do { \
__asm __volatile (" \
movl %0,a0 ; \
movl %1,a1 ; \
movl %2,d0 ; \
1: movb a1@+,a0@ ; \
subql #1,d0 ; \
jne 1b" : \
: \
"r" ((h) + (o)), "g" (a), "g" (c) : \
"a0","a1","d0"); \
} while (0);
#define bus_space_write_multi_2(t, h, o, a, c) do { \
__asm __volatile (" \
movl %0,a0 ; \
movl %1,a1 ; \
movl %2,d0 ; \
1: movw a1@+,a0@ ; \
subql #1,d0 ; \
jne 1b" : \
: \
"r" ((h) + (o)), "g" (a), "g" (c) : \
"a0","a1","d0"); \
} while (0);
#define bus_space_write_multi_4(t, h, o, a, c) do { \
__asm __volatile (" \
movl %0,a0 ; \
movl %1,a1 ; \
movl %2,d0 ; \
1: movl a1@+,a0@ ; \
subql #1,d0 ; \
jne 1b" : \
: \
"r" ((h) + (o)), "g" (a), "g" (c) : \
"a0","a1","d0"); \
} while (0);
#if 0 /* Cause a link error for bus_space_write_8 */
#define bus_space_write_multi_8(t, h, o, a, c) \
!!! bus_space_write_multi_8 unimplimented !!!
#endif
/*
* void bus_space_write_region_N __P((bus_space_tag_t tag,
* bus_space_handle_t bsh, bus_size_t offset,
* const u_intN_t *addr, size_t count));
*
* Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
* to bus space described by tag/handle starting at `offset'.
*/
#define bus_space_write_region_1(t, h, o, a, c) do { \
__asm __volatile (" \
movl %0,a0 ; \
movl %1,a1 ; \
movl %2,d0 ; \
1: movb a1@+,a0@+ ; \
subql #1,d0 ; \
jne 1b" : \
: \
"r" ((h) + (o)), "g" (a), "g" (c) : \
"a0","a1","d0"); \
} while (0);
#define bus_space_write_region_2(t, h, o, a, c) do { \
__asm __volatile (" \
movl %0,a0 ; \
movl %1,a1 ; \
movl %2,d0 ; \
1: movw a1@+,a0@+ ; \
subql #1,d0 ; \
jne 1b" : \
: \
"r" ((h) + (o)), "g" (a), "g" (c) : \
"a0","a1","d0"); \
} while (0);
#define bus_space_write_region_4(t, h, o, a, c) do { \
__asm __volatile (" \
movl %0,a0 ; \
movl %1,a1 ; \
movl %2,d0 ; \
1: movl a1@+,a0@+ ; \
subql #1,d0 ; \
jne 1b" : \
: \
"r" ((h) + (o)), "g" (a), "g" (c) : \
"a0","a1","d0"); \
} while (0);
#if 0 /* Cause a link error for bus_space_write_region_8 */
#define bus_space_write_region_8 \
!!! bus_space_write_region_8 unimplemented !!!
#endif
/*
* void bus_space_set_multi_N __P((bus_space_tag_t tag,
* bus_space_handle_t bsh, bus_size_t offset, u_intN_t val,
* size_t count));
*
* Write the 1, 2, 4, or 8 byte value `val' to bus space described
* by tag/handle/offset `count' times.
*/
/* XXX IMPLEMENT bus_space_set_multi_N() XXX */
/*
* void bus_space_set_region_N __P((bus_space_tag_t tag,
* bus_space_handle_t bsh, bus_size_t offset, u_intN_t val,
* size_t count));
*
* Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
* by tag/handle starting at `offset'.
*/
/* XXX IMPLEMENT bus_space_set_region_N() XXX */
/*
* void bus_space_copy_N __P((bus_space_tag_t tag,
* bus_space_handle_t bsh1, bus_size_t off1,
* bus_space_handle_t bsh2, bus_size_t off2,
* size_t count));
*
* Copy `count' 1, 2, 4, or 8 byte values from bus space starting
* at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
*/
/* XXX IMPLEMENT bus_space_copy_N() XXX */
/*
* Bus read/write barrier methods.
*
* void bus_space_barrier __P((bus_space_tag_t tag,
* bus_space_handle_t bsh, bus_size_t offset,
* bus_size_t len, int flags));
*
* Note: the 680x0 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 */
/*
* Machine-dependent extensions.
*/
int bus_probe __P((bus_space_tag_t t, bus_space_handle_t bsh,
bus_size_t offset, int sz));
#endif /* _MAC68K_BUS_H_ */

View File

@ -1,6 +1,7 @@
/* $NetBSD: machdep.c,v 1.129 1997/01/09 07:20:46 scottr Exp $ */
/* $NetBSD: machdep.c,v 1.130 1997/02/03 17:32:57 scottr Exp $ */
/*
* Copyright (c) 1996 Jason R. Thorpe. All rights reserved.
* Copyright (c) 1988 University of Utah.
* Copyright (c) 1982, 1990 The Regents of the University of California.
* All rights reserved.
@ -116,6 +117,7 @@
#include <machine/reg.h>
#include <machine/psl.h>
#include <machine/pte.h>
#include <machine/bus.h>
#include <net/netisr.h>
#define MAXMEM 64*1024*CLSIZE /* XXX - from cmap.h */
@ -2483,13 +2485,11 @@ mac68k_set_io_offsets(base)
vm_offset_t base;
{
extern volatile u_char *sccA;
extern volatile u_char *ASCBase;
switch (current_mac_model->class) {
case MACH_CLASSQ:
Via1Base = (volatile u_char *) base;
sccA = (volatile u_char *) base + 0xc000;
ASCBase = (volatile u_char *) base + 0x14000;
switch (current_mac_model->machineid) {
case MACH_MACQ900:
case MACH_MACQ950:
@ -2510,13 +2510,11 @@ mac68k_set_io_offsets(base)
*/
Via1Base = (volatile u_char *) base;
sccA = (volatile u_char *) base + 0xc020;
ASCBase = (volatile u_char *) base + 0x14000;
SCSIBase = base + 0x10000;
break;
case MACH_CLASSAV:
Via1Base = (volatile u_char *) base;
sccA = (volatile u_char *) base + 0x4000;
ASCBase = (volatile u_char *) base + 0x14000;
SCSIBase = base + 0x18000;
break;
case MACH_CLASSII:
@ -2527,7 +2525,6 @@ mac68k_set_io_offsets(base)
case MACH_CLASSLC:
Via1Base = (volatile u_char *) base;
sccA = (volatile u_char *) base + 0x4000;
ASCBase = (volatile u_char *) base + 0x14000;
SCSIBase = base;
break;
default:
@ -2862,3 +2859,112 @@ printstar(void)
movl sp@+,a1;
movl sp@+,a0");
}
int
bus_space_map(t, bpa, size, cacheable, bshp)
bus_space_tag_t t;
bus_addr_t bpa;
bus_size_t size;
int cacheable;
bus_space_handle_t *bshp;
{
vm_offset_t va;
u_long pa, endpa;
pa = mac68k_trunc_page(bpa + t);
endpa = mac68k_round_page((bpa + t + size) - 1);
#ifdef DIAGNOSTIC
if (endpa <= pa)
panic("bus_space_map: overflow");
#endif
va = kmem_alloc_pageable(kernel_map, endpa - pa);
if (va == 0)
return 1;
*bshp = (caddr_t)(va + (bpa & PGOFSET));
for(; pa < endpa; pa += NBPG, va += NBPG) {
pmap_enter(pmap_kernel(), (vm_offset_t)va, pa,
VM_PROT_READ|VM_PROT_WRITE, TRUE);
if (!cacheable)
pmap_changebit(pa, PG_CI, TRUE);
}
return (0);
}
void
bus_space_unmap(t, bsh, size)
bus_space_tag_t t;
bus_space_handle_t bsh;
bus_size_t size;
{
vm_offset_t va, endva;
va = mac68k_trunc_page(bsh);
endva = mac68k_round_page((bsh + size) - 1);
#ifdef DIAGNOSTIC
if (endva <= va)
panic("bus_space_unmap: overflow");
#endif
kmem_free(kernel_map, va, endva - va);
}
int
bus_space_subregion(t, bsh, offset, size, nbshp)
bus_space_tag_t t;
bus_space_handle_t bsh;
bus_size_t offset, size;
bus_space_handle_t *nbshp;
{
*nbshp = bsh + offset;
return (0);
}
int
bus_probe(t, bsh, offset, sz)
bus_space_tag_t t;
bus_space_handle_t bsh;
bus_size_t offset;
int sz;
{
int i;
label_t faultbuf;
#ifdef lint
i = *addr;
if (i)
return (0);
#endif
nofault = (int *) &faultbuf;
if (setjmp((label_t *) nofault)) {
nofault = (int *) 0;
return (0);
}
switch (sz) {
case 1:
i = bus_space_read_1(t, bsh, offset);
break;
case 2:
i = bus_space_read_2(t, bsh, offset);
break;
case 4:
i = bus_space_read_4(t, bsh, offset);
break;
case 8:
/*FALLTHROUGH*/
default:
#ifdef DIAGNOSTIC
printf("bus_probe: unsupported data size %d\n", sz);
#endif
nofault = (int *) 0;
return (0);
}
nofault = (int *) 0;
return (1);
}