Factor *peek out of bus_subr.c and move it to autoconf.c
(to reduce duplication). Add bus_tmapin and bus_tmapout for use in probe functions (gets a temporary mapping). Add bus_mapout() to undo bus_mapin() if needed.
This commit is contained in:
parent
e387ffba22
commit
5193e1e30e
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: autoconf.h,v 1.17 1998/02/05 04:56:48 gwr Exp $ */
|
||||
/* $NetBSD: autoconf.h,v 1.18 1998/02/08 05:02:50 gwr Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1996 The NetBSD Foundation, Inc.
|
||||
|
@ -75,6 +75,9 @@ int bus_scan __P((struct device *, struct cfdata *, void *));
|
|||
int bus_print __P((void *, const char *));
|
||||
int bus_peek __P((int, int, int));
|
||||
void * bus_mapin __P((int, int, int));
|
||||
void bus_mapout __P((void *, int));
|
||||
void * bus_tmapin __P((int, int));
|
||||
void bus_tmapout __P((void *));
|
||||
|
||||
/* These are how drivers connect interrupt handlers. */
|
||||
typedef int (*isr_func_t) __P((void *));
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: autoconf.c,v 1.50 1998/02/05 04:57:25 gwr Exp $ */
|
||||
/* $NetBSD: autoconf.c,v 1.51 1998/02/08 05:02:51 gwr Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1996 The NetBSD Foundation, Inc.
|
||||
|
@ -88,6 +88,78 @@ configure()
|
|||
cold = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* bus_scan:
|
||||
* This function is passed to config_search() by the attach function
|
||||
* for each of the "bus" drivers (obctl, obio, obmem, vme, ...).
|
||||
* The purpose of this function is to copy the "locators" into our
|
||||
* confargs structure, so child drivers may use the confargs both
|
||||
* as match parameters and as temporary storage for the defaulted
|
||||
* locator values determined in the child_match and preserved for
|
||||
* the child_attach function. If the bus attach functions just
|
||||
* used config_found, then we would not have an opportunity to
|
||||
* setup the confargs for each child match and attach call.
|
||||
*/
|
||||
int bus_scan(parent, cf, aux)
|
||||
struct device *parent;
|
||||
struct cfdata *cf;
|
||||
void *aux;
|
||||
{
|
||||
struct confargs *ca = aux;
|
||||
cfmatch_t mf;
|
||||
|
||||
#ifdef DIAGNOSTIC
|
||||
if (cf->cf_fstate == FSTATE_STAR)
|
||||
panic("bus_scan: FSTATE_STAR");
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Copy the locators into our confargs.
|
||||
* Our parent set ca->ca_bustype already.
|
||||
*/
|
||||
ca->ca_paddr = cf->cf_paddr;
|
||||
ca->ca_intpri = cf->cf_intpri;
|
||||
ca->ca_intvec = cf->cf_intvec;
|
||||
|
||||
/*
|
||||
* Note that this allows the match function to save
|
||||
* defaulted locators in the confargs that will be
|
||||
* preserved for the related attach call.
|
||||
* XXX - This is a hack...
|
||||
*/
|
||||
mf = cf->cf_attach->ca_match;
|
||||
if ((*mf)(parent, cf, ca) > 0) {
|
||||
config_attach(parent, cf, ca, bus_print);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* bus_print:
|
||||
* Just print out the final (non-default) locators.
|
||||
* The parent name is non-NULL when there was no match
|
||||
* found by config_found().
|
||||
*/
|
||||
int
|
||||
bus_print(args, name)
|
||||
void *args;
|
||||
const char *name;
|
||||
{
|
||||
struct confargs *ca = args;
|
||||
|
||||
if (name)
|
||||
printf("%s:", name);
|
||||
|
||||
if (ca->ca_paddr != -1)
|
||||
printf(" addr 0x%x", ca->ca_paddr);
|
||||
if (ca->ca_intpri != -1)
|
||||
printf(" ipl %d", ca->ca_intpri);
|
||||
if (ca->ca_intvec != -1)
|
||||
printf(" vect 0x%x", ca->ca_intvec);
|
||||
|
||||
return(UNCONF);
|
||||
}
|
||||
|
||||
/****************************************************************/
|
||||
|
||||
/*
|
||||
|
@ -265,3 +337,99 @@ find_dev_byname(name)
|
|||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Misc. helpers used by driver match/attach functions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Read addr with size len (1,2,4) into val.
|
||||
* If this generates a bus error, return -1
|
||||
*
|
||||
* Create a temporary mapping,
|
||||
* Try the access using peek_*
|
||||
* Clean up temp. mapping
|
||||
*/
|
||||
int
|
||||
bus_peek(bustype, pa, sz)
|
||||
int bustype, pa, sz;
|
||||
{
|
||||
caddr_t va;
|
||||
int rv;
|
||||
|
||||
va = bus_tmapin(bustype, pa);
|
||||
switch (sz) {
|
||||
case 1:
|
||||
rv = peek_byte(va);
|
||||
break;
|
||||
case 2:
|
||||
rv = peek_word(va);
|
||||
break;
|
||||
case 4:
|
||||
rv = peek_long(va);
|
||||
break;
|
||||
default:
|
||||
printf(" bus_peek: invalid size=%d\n", sz);
|
||||
rv = -1;
|
||||
}
|
||||
bus_tmapout(va);
|
||||
|
||||
return (rv);
|
||||
}
|
||||
|
||||
/* from hp300: badbaddr() */
|
||||
int
|
||||
peek_byte(addr)
|
||||
register caddr_t addr;
|
||||
{
|
||||
label_t faultbuf;
|
||||
register int x;
|
||||
|
||||
nofault = &faultbuf;
|
||||
if (setjmp(&faultbuf))
|
||||
x = -1;
|
||||
else
|
||||
x = *(volatile u_char *)addr;
|
||||
|
||||
nofault = NULL;
|
||||
return(x);
|
||||
}
|
||||
|
||||
int
|
||||
peek_word(addr)
|
||||
register caddr_t addr;
|
||||
{
|
||||
label_t faultbuf;
|
||||
register int x;
|
||||
|
||||
nofault = &faultbuf;
|
||||
if (setjmp(&faultbuf))
|
||||
x = -1;
|
||||
else
|
||||
x = *(volatile u_short *)addr;
|
||||
|
||||
nofault = NULL;
|
||||
return(x);
|
||||
}
|
||||
|
||||
int
|
||||
peek_long(addr)
|
||||
register caddr_t addr;
|
||||
{
|
||||
label_t faultbuf;
|
||||
register int x;
|
||||
|
||||
nofault = &faultbuf;
|
||||
if (setjmp(&faultbuf))
|
||||
x = -1;
|
||||
else {
|
||||
x = *(volatile int *)addr;
|
||||
if (x == -1) {
|
||||
printf("peek_long: uh-oh, actually read -1!\n");
|
||||
x &= 0x7FFFffff; /* XXX */
|
||||
}
|
||||
}
|
||||
|
||||
nofault = NULL;
|
||||
return(x);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: bus_subr.c,v 1.4 1998/02/05 04:57:26 gwr Exp $ */
|
||||
/* $NetBSD: bus_subr.c,v 1.5 1998/02/08 05:02:52 gwr Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1996 The NetBSD Foundation, Inc.
|
||||
|
@ -37,7 +37,8 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
* bus_xxx support functions
|
||||
* bus_xxx support functions, Sun3-specific part.
|
||||
* The common stuff is in autoconf.c
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
|
@ -58,84 +59,11 @@
|
|||
#include <sun3/sun3/machdep.h>
|
||||
#include <sun3/sun3/vme.h>
|
||||
|
||||
/*
|
||||
* bus_scan:
|
||||
* This function is passed to config_search() by the attach function
|
||||
* for each of the "bus" drivers (obctl, obio, obmem, vmes, vmel).
|
||||
* The purpose of this function is to copy the "locators" into our
|
||||
* confargs structure, so child drivers may use the confargs both
|
||||
* as match parameters and as temporary storage for the defaulted
|
||||
* locator values determined in the child_match and preserved for
|
||||
* the child_attach function. If the bus attach functions just
|
||||
* used config_found, then we would not have an opportunity to
|
||||
* setup the confargs for each child match and attach call.
|
||||
*/
|
||||
int bus_scan(parent, cf, aux)
|
||||
struct device *parent;
|
||||
struct cfdata *cf;
|
||||
void *aux;
|
||||
{
|
||||
struct confargs *ca = aux;
|
||||
cfmatch_t mf;
|
||||
|
||||
#ifdef DIAGNOSTIC
|
||||
if (cf->cf_fstate == FSTATE_STAR)
|
||||
panic("bus_scan: FSTATE_STAR");
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Copy the locators into our confargs.
|
||||
* Our parent set ca->ca_bustype already.
|
||||
*/
|
||||
ca->ca_paddr = cf->cf_paddr;
|
||||
ca->ca_intpri = cf->cf_intpri;
|
||||
ca->ca_intvec = cf->cf_intvec;
|
||||
|
||||
/*
|
||||
* Note that this allows the match function to save
|
||||
* defaulted locators in the confargs that will be
|
||||
* preserved for the related attach call.
|
||||
* XXX - This is a hack...
|
||||
*/
|
||||
mf = cf->cf_attach->ca_match;
|
||||
if ((*mf)(parent, cf, ca) > 0) {
|
||||
config_attach(parent, cf, ca, bus_print);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* bus_print:
|
||||
* Just print out the final (non-default) locators.
|
||||
* The parent name is non-NULL when there was no match
|
||||
* found by config_found().
|
||||
*/
|
||||
int
|
||||
bus_print(args, name)
|
||||
void *args;
|
||||
const char *name;
|
||||
{
|
||||
struct confargs *ca = args;
|
||||
|
||||
if (name)
|
||||
printf("%s:", name);
|
||||
|
||||
if (ca->ca_paddr != -1)
|
||||
printf(" addr 0x%x", ca->ca_paddr);
|
||||
if (ca->ca_intpri != -1)
|
||||
printf(" ipl %d", ca->ca_intpri);
|
||||
if (ca->ca_intvec != -1)
|
||||
printf(" vect 0x%x", ca->ca_intvec);
|
||||
|
||||
return(UNCONF);
|
||||
}
|
||||
|
||||
/****************************************************************/
|
||||
/* support functions */
|
||||
|
||||
label_t *nofault;
|
||||
|
||||
/* These are defined in pmap.c */
|
||||
extern vm_offset_t tmp_vpages[];
|
||||
extern int tmp_vpages_inuse;
|
||||
|
||||
#define OBIO_MASK 0xFFffff
|
||||
#define PMAP_OBMEM 0
|
||||
|
@ -159,87 +87,80 @@ static const struct {
|
|||
};
|
||||
|
||||
/*
|
||||
* Read addr with size len (1,2,4) into val.
|
||||
* If this generates a bus error, return -1
|
||||
*
|
||||
* Create a temporary mapping,
|
||||
* Try the access using peek_*
|
||||
* Clean up temp. mapping
|
||||
* Create a temporary, one-page mapping for a device.
|
||||
* This is used by some device probe routines that
|
||||
* need to do peek/write/read tricks.
|
||||
*/
|
||||
int
|
||||
bus_peek(bustype, pa, sz)
|
||||
int bustype, pa, sz;
|
||||
void *
|
||||
bus_tmapin(bustype, pa)
|
||||
int bustype, pa;
|
||||
{
|
||||
int off, pte, rv;
|
||||
vm_offset_t pgva;
|
||||
caddr_t va;
|
||||
int off, pte;
|
||||
|
||||
if ((bustype < 0) || (bustype >= BUS__NTYPES))
|
||||
panic("bus_peek: bustype");
|
||||
panic("bus_tmapin: bustype");
|
||||
|
||||
off = pa & PGOFSET;
|
||||
pa -= off;
|
||||
|
||||
pa &= bus_info[bustype].mask;
|
||||
pa |= bus_info[bustype].base;
|
||||
|
||||
off = pa & PGOFSET;
|
||||
pa -= off;
|
||||
pte = PA_PGNUM(pa);
|
||||
|
||||
pte |= (bus_info[bustype].type << PG_MOD_SHIFT);
|
||||
pte |= (PG_VALID | PG_WRITE | PG_SYSTEM | PG_NC);
|
||||
|
||||
pgva = tmp_vpages[0];
|
||||
va = (caddr_t)pgva + off;
|
||||
if (tmp_vpages_inuse)
|
||||
panic("bus_tmapin: tmp_vpages_inuse");
|
||||
tmp_vpages_inuse++;
|
||||
|
||||
/* All mappings in tmp_vpages are non-cached, so no flush. */
|
||||
pgva = tmp_vpages[1];
|
||||
set_pte(pgva, pte);
|
||||
|
||||
switch (sz) {
|
||||
case 1:
|
||||
rv = peek_byte(va);
|
||||
break;
|
||||
case 2:
|
||||
rv = peek_word(va);
|
||||
break;
|
||||
case 4:
|
||||
rv = peek_long(va);
|
||||
break;
|
||||
default:
|
||||
printf(" bus_peek: invalid size=%d\n", sz);
|
||||
rv = -1;
|
||||
}
|
||||
|
||||
/* All mappings in tmp_vpages are non-cached, so no flush. */
|
||||
set_pte(pgva, PG_INVAL);
|
||||
|
||||
return (rv);
|
||||
return ((void *)(pgva + off));
|
||||
}
|
||||
|
||||
void bus_tmapout(vp)
|
||||
void *vp;
|
||||
{
|
||||
vm_offset_t pgva;
|
||||
|
||||
pgva = m68k_trunc_page(vp);
|
||||
if (pgva != tmp_vpages[1])
|
||||
return;
|
||||
|
||||
set_pte(pgva, PG_INVAL);
|
||||
--tmp_vpages_inuse;
|
||||
}
|
||||
|
||||
/*
|
||||
* Make a permanent mapping for a device.
|
||||
*/
|
||||
void *
|
||||
bus_mapin(bustype, pa, sz)
|
||||
int bustype, pa, sz;
|
||||
{
|
||||
void *rv;
|
||||
vm_offset_t va;
|
||||
int off;
|
||||
|
||||
if ((bustype < 0) || (bustype >= BUS__NTYPES))
|
||||
panic("bus_mapin: bustype");
|
||||
|
||||
/* Borrow PROM mappings if we can. */
|
||||
if (bustype == BUS_OBIO) {
|
||||
rv = obio_find_mapping(pa, sz);
|
||||
if (rv)
|
||||
return (rv);
|
||||
}
|
||||
|
||||
pa &= bus_info[bustype].mask;
|
||||
pa |= bus_info[bustype].base;
|
||||
|
||||
off = pa & PGOFSET;
|
||||
pa -= off;
|
||||
sz += off;
|
||||
sz = m68k_round_page(sz);
|
||||
|
||||
/* Borrow PROM mappings if we can. */
|
||||
if (bustype == BUS_OBIO) {
|
||||
va = (vm_offset_t) obio_find_mapping(pa, sz);
|
||||
if (va != 0)
|
||||
goto done;
|
||||
}
|
||||
|
||||
pa &= bus_info[bustype].mask;
|
||||
pa |= bus_info[bustype].base;
|
||||
pa |= bus_info[bustype].type;
|
||||
pa |= PMAP_NC; /* non-cached */
|
||||
|
||||
|
@ -247,77 +168,32 @@ bus_mapin(bustype, pa, sz)
|
|||
va = kmem_alloc_wait(kernel_map, sz);
|
||||
if (va == 0)
|
||||
panic("bus_mapin");
|
||||
rv = (void*)(va + off);
|
||||
|
||||
/* Map it to the specified bus. */
|
||||
#if 0
|
||||
/* XXX: This has a problem with wrap-around... */
|
||||
pmap_map((int)va, pa, pa + sz, VM_PROT_ALL);
|
||||
#else
|
||||
do {
|
||||
pmap_enter(pmap_kernel(), va, pa, VM_PROT_ALL, FALSE);
|
||||
va += NBPG;
|
||||
pa += NBPG;
|
||||
sz -= NBPG;
|
||||
} while (sz > 0);
|
||||
#endif
|
||||
pmap_map(va, pa, pa + sz, VM_PROT_ALL);
|
||||
|
||||
return (rv);
|
||||
done:
|
||||
return ((void*)(va + off));
|
||||
}
|
||||
|
||||
/* from hp300: badbaddr() */
|
||||
int
|
||||
peek_byte(addr)
|
||||
register caddr_t addr;
|
||||
void
|
||||
bus_mapout(ptr, sz)
|
||||
void *ptr;
|
||||
int sz;
|
||||
{
|
||||
label_t faultbuf;
|
||||
register int x;
|
||||
vm_offset_t va;
|
||||
int off;
|
||||
|
||||
nofault = &faultbuf;
|
||||
if (setjmp(&faultbuf))
|
||||
x = -1;
|
||||
else
|
||||
x = *(volatile u_char *)addr;
|
||||
va = (vm_offset_t)ptr;
|
||||
|
||||
nofault = NULL;
|
||||
return(x);
|
||||
}
|
||||
|
||||
int
|
||||
peek_word(addr)
|
||||
register caddr_t addr;
|
||||
{
|
||||
label_t faultbuf;
|
||||
register int x;
|
||||
|
||||
nofault = &faultbuf;
|
||||
if (setjmp(&faultbuf))
|
||||
x = -1;
|
||||
else
|
||||
x = *(volatile u_short *)addr;
|
||||
|
||||
nofault = NULL;
|
||||
return(x);
|
||||
}
|
||||
|
||||
int
|
||||
peek_long(addr)
|
||||
register caddr_t addr;
|
||||
{
|
||||
label_t faultbuf;
|
||||
register int x;
|
||||
|
||||
nofault = &faultbuf;
|
||||
if (setjmp(&faultbuf))
|
||||
x = -1;
|
||||
else {
|
||||
x = *(volatile int *)addr;
|
||||
if (x == -1) {
|
||||
printf("peek_long: uh-oh, actually read -1!\n");
|
||||
x &= 0x7FFFffff; /* XXX */
|
||||
}
|
||||
}
|
||||
|
||||
nofault = NULL;
|
||||
return(x);
|
||||
/* If it was a PROM mapping, do NOT free it! */
|
||||
if ((va >= SUN3_MONSTART) && (va < SUN3_MONEND))
|
||||
return;
|
||||
|
||||
off = va & PGOFSET;
|
||||
va -= off;
|
||||
sz += off;
|
||||
sz = m68k_round_page(sz);
|
||||
|
||||
kmem_free_wakeup(kernel_map, va, sz);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: bus_subr.c,v 1.10 1998/02/05 04:57:53 gwr Exp $ */
|
||||
/* $NetBSD: bus_subr.c,v 1.11 1998/02/08 05:02:53 gwr Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1996 The NetBSD Foundation, Inc.
|
||||
|
@ -37,7 +37,8 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
* bus_xxx support functions
|
||||
* bus_xxx support functions, Sun3X-specific part.
|
||||
* The common stuff is in autoconf.c
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
|
@ -57,81 +58,6 @@
|
|||
#include <sun3/sun3/machdep.h>
|
||||
#include <sun3/sun3x/vme.h>
|
||||
|
||||
/*
|
||||
* bus_scan:
|
||||
* This function is passed to config_search() by the attach function
|
||||
* for each of the "bus" drivers (obctl, obio, obmem, vmes, vmel).
|
||||
* The purpose of this function is to copy the "locators" into our
|
||||
* confargs structure, so child drivers may use the confargs both
|
||||
* as match parameters and as temporary storage for the defaulted
|
||||
* locator values determined in the child_match and preserved for
|
||||
* the child_attach function. If the bus attach functions just
|
||||
* used config_found, then we would not have an opportunity to
|
||||
* setup the confargs for each child match and attach call.
|
||||
*/
|
||||
int bus_scan(parent, cf, aux)
|
||||
struct device *parent;
|
||||
struct cfdata *cf;
|
||||
void *aux;
|
||||
{
|
||||
struct confargs *ca = aux;
|
||||
cfmatch_t mf;
|
||||
|
||||
#ifdef DIAGNOSTIC
|
||||
if (cf->cf_fstate == FSTATE_STAR)
|
||||
panic("bus_scan: FSTATE_STAR");
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Copy the locators into our confargs.
|
||||
* Our parent set ca->ca_bustype already.
|
||||
*/
|
||||
ca->ca_paddr = cf->cf_paddr;
|
||||
ca->ca_intpri = cf->cf_intpri;
|
||||
ca->ca_intvec = cf->cf_intvec;
|
||||
|
||||
/*
|
||||
* Note that this allows the match function to save
|
||||
* defaulted locators in the confargs that will be
|
||||
* preserved for the related attach call.
|
||||
* XXX - This is a hack...
|
||||
*/
|
||||
mf = cf->cf_attach->ca_match;
|
||||
if ((*mf)(parent, cf, ca) > 0) {
|
||||
config_attach(parent, cf, ca, bus_print);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* bus_print:
|
||||
* Just print out the final (non-default) locators.
|
||||
* The parent name is non-NULL when there was no match
|
||||
* found by config_found().
|
||||
*/
|
||||
int
|
||||
bus_print(args, name)
|
||||
void *args;
|
||||
const char *name;
|
||||
{
|
||||
struct confargs *ca = args;
|
||||
|
||||
if (name)
|
||||
printf("%s:", name);
|
||||
|
||||
if (ca->ca_paddr != -1)
|
||||
printf(" addr 0x%x", ca->ca_paddr);
|
||||
if (ca->ca_intpri != -1)
|
||||
printf(" ipl %d", ca->ca_intpri);
|
||||
if (ca->ca_intvec != -1)
|
||||
printf(" vect 0x%x", ca->ca_intvec);
|
||||
|
||||
return(UNCONF);
|
||||
}
|
||||
|
||||
/****************************************************************/
|
||||
/* support functions */
|
||||
|
||||
label_t *nofault;
|
||||
|
||||
/* These are defined in pmap.c */
|
||||
|
@ -156,167 +82,115 @@ static const struct {
|
|||
};
|
||||
|
||||
/*
|
||||
* Read addr with size len (1,2,4) into val.
|
||||
* If this generates a bus error, return -1
|
||||
*
|
||||
* Create a temporary mapping,
|
||||
* Try the access using peek_*
|
||||
* Clean up temp. mapping
|
||||
* Create a temporary, one-page mapping for a device.
|
||||
* This is used by some device probe routines that
|
||||
* need to do peek/write/read tricks.
|
||||
*/
|
||||
int
|
||||
bus_peek(bustype, pa, sz)
|
||||
int bustype, pa, sz;
|
||||
void *
|
||||
bus_tmapin(bustype, pa)
|
||||
int bustype, pa;
|
||||
{
|
||||
int off, rv, s;
|
||||
vm_offset_t pgva;
|
||||
caddr_t va;
|
||||
int off, pte, s;
|
||||
|
||||
if ((bustype < 0) || (bustype >= BUS__NTYPES))
|
||||
panic("bus_peek: bustype");
|
||||
|
||||
pa &= bus_info[bustype].mask;
|
||||
pa |= bus_info[bustype].base;
|
||||
panic("bus_tmapin: bustype");
|
||||
|
||||
off = pa & PGOFSET;
|
||||
pa -= off;
|
||||
|
||||
pa &= bus_info[bustype].mask;
|
||||
pa |= bus_info[bustype].base;
|
||||
pa |= PMAP_NC;
|
||||
|
||||
s = splimp();
|
||||
if (tmp_vpages_inuse)
|
||||
panic("bus_peek: temporary vpages are in use.");
|
||||
panic("bus_tmapin: tmp_vpages_inuse");
|
||||
tmp_vpages_inuse++;
|
||||
|
||||
pgva = tmp_vpages[1];
|
||||
va = (caddr_t)pgva + off;
|
||||
|
||||
pmap_enter(pmap_kernel(), pgva, pa,
|
||||
(VM_PROT_READ|VM_PROT_WRITE), TRUE);
|
||||
splx(s);
|
||||
|
||||
switch (sz) {
|
||||
case 1:
|
||||
rv = peek_byte(va);
|
||||
break;
|
||||
case 2:
|
||||
rv = peek_word(va);
|
||||
break;
|
||||
case 4:
|
||||
rv = peek_long(va);
|
||||
break;
|
||||
default:
|
||||
printf(" bus_peek: invalid size=%d\n", sz);
|
||||
rv = -1;
|
||||
}
|
||||
return ((void *)(pgva + off));
|
||||
}
|
||||
|
||||
void bus_tmapout(vp)
|
||||
void *vp;
|
||||
{
|
||||
vm_offset_t pgva;
|
||||
int s;
|
||||
|
||||
pgva = m68k_trunc_page(vp);
|
||||
if (pgva != tmp_vpages[1])
|
||||
return;
|
||||
|
||||
s = splimp();
|
||||
pmap_remove(pmap_kernel(), pgva, pgva + NBPG);
|
||||
--tmp_vpages_inuse;
|
||||
splx(s);
|
||||
|
||||
return (rv);
|
||||
}
|
||||
|
||||
/*
|
||||
* Make a permanent mapping for a device.
|
||||
*/
|
||||
void *
|
||||
bus_mapin(bustype, pa, sz)
|
||||
int bustype, pa, sz;
|
||||
{
|
||||
void *rv;
|
||||
vm_offset_t va;
|
||||
int off;
|
||||
|
||||
if ((bustype < 0) || (bustype >= BUS__NTYPES))
|
||||
panic("bus_mapin: bustype");
|
||||
|
||||
/* Borrow PROM mappings if we can. */
|
||||
if (bustype == BUS_OBIO) {
|
||||
rv = obio_find_mapping(pa, sz);
|
||||
if (rv)
|
||||
return (rv);
|
||||
}
|
||||
|
||||
pa &= bus_info[bustype].mask;
|
||||
pa |= bus_info[bustype].base;
|
||||
|
||||
off = pa & PGOFSET;
|
||||
pa -= off;
|
||||
sz += off;
|
||||
sz = m68k_round_page(sz);
|
||||
|
||||
/* Borrow PROM mappings if we can. */
|
||||
if (bustype == BUS_OBIO) {
|
||||
va = (vm_offset_t) obio_find_mapping(pa, sz);
|
||||
if (va != 0)
|
||||
goto done;
|
||||
}
|
||||
|
||||
pa &= bus_info[bustype].mask;
|
||||
pa |= bus_info[bustype].base;
|
||||
pa |= PMAP_NC; /* non-cached */
|
||||
|
||||
/* Get some kernel virtual address space. */
|
||||
va = kmem_alloc_wait(kernel_map, sz);
|
||||
if (va == 0)
|
||||
panic("bus_mapin");
|
||||
rv = (void*)(va + off);
|
||||
|
||||
/* Map it to the specified bus. */
|
||||
#if 0
|
||||
/* XXX: This has a problem with wrap-around... (on the sun3x? -j) */
|
||||
pmap_map((int)va, pa, pa + sz, VM_PROT_ALL);
|
||||
#else
|
||||
do {
|
||||
pmap_enter(pmap_kernel(), va, pa, VM_PROT_ALL, FALSE);
|
||||
va += NBPG;
|
||||
pa += NBPG;
|
||||
sz -= NBPG;
|
||||
} while (sz > 0);
|
||||
#endif
|
||||
pmap_map(va, pa, pa + sz, VM_PROT_ALL);
|
||||
|
||||
return (rv);
|
||||
done:
|
||||
return ((void*)(va + off));
|
||||
}
|
||||
|
||||
/* from hp300: badbaddr() */
|
||||
int
|
||||
peek_byte(addr)
|
||||
register caddr_t addr;
|
||||
void
|
||||
bus_mapout(ptr, sz)
|
||||
void *ptr;
|
||||
int sz;
|
||||
{
|
||||
label_t faultbuf;
|
||||
register int x;
|
||||
vm_offset_t va;
|
||||
int off;
|
||||
|
||||
nofault = &faultbuf;
|
||||
if (setjmp(&faultbuf))
|
||||
x = -1;
|
||||
else
|
||||
x = *(volatile u_char *)addr;
|
||||
va = (vm_offset_t)ptr;
|
||||
|
||||
nofault = NULL;
|
||||
return(x);
|
||||
}
|
||||
|
||||
int
|
||||
peek_word(addr)
|
||||
register caddr_t addr;
|
||||
{
|
||||
label_t faultbuf;
|
||||
register int x;
|
||||
|
||||
nofault = &faultbuf;
|
||||
if (setjmp(&faultbuf))
|
||||
x = -1;
|
||||
else
|
||||
x = *(volatile u_short *)addr;
|
||||
|
||||
nofault = NULL;
|
||||
return(x);
|
||||
}
|
||||
|
||||
int
|
||||
peek_long(addr)
|
||||
register caddr_t addr;
|
||||
{
|
||||
label_t faultbuf;
|
||||
register int x;
|
||||
|
||||
nofault = &faultbuf;
|
||||
if (setjmp(&faultbuf))
|
||||
x = -1;
|
||||
else {
|
||||
x = *(volatile int *)addr;
|
||||
if (x == -1) {
|
||||
printf("peek_long: uh-oh, actually read -1!\n");
|
||||
x &= 0x7FFFffff; /* XXX */
|
||||
}
|
||||
}
|
||||
|
||||
nofault = NULL;
|
||||
return(x);
|
||||
/* If it was a PROM mapping, do NOT free it! */
|
||||
if ((va >= SUN3X_MONSTART) && (va < SUN3X_MONEND))
|
||||
return;
|
||||
|
||||
off = va & PGOFSET;
|
||||
va -= off;
|
||||
sz += off;
|
||||
sz = m68k_round_page(sz);
|
||||
|
||||
kmem_free_wakeup(kernel_map, va, sz);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue