- change find_prom_map() to take paddr_t and return vaddr_t rather than

bus_space_handle_t since bus space handle without bus space tag looks weird
- replace old sun3 obio_find_mapping() with new common find_prom_map()
- add bus_space_vaddr(), from hp300
This commit is contained in:
tsutsui 2006-10-03 13:02:32 +00:00
parent adb2b00a4a
commit c207dcd880
14 changed files with 90 additions and 125 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: zs_any.c,v 1.15 2006/10/01 03:53:27 tsutsui Exp $ */
/* $NetBSD: zs_any.c,v 1.16 2006/10/03 13:02:32 tsutsui Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
@ -45,7 +45,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: zs_any.c,v 1.15 2006/10/01 03:53:27 tsutsui Exp $");
__KERNEL_RCSID(0, "$NetBSD: zs_any.c,v 1.16 2006/10/03 13:02:32 tsutsui Exp $");
#include "opt_kgdb.h"
@ -188,7 +188,7 @@ void *
zs_find_prom(int unit)
{
bus_addr_t zs0_phys;
bus_space_handle_t bh;
vaddr_t va;
if (unit != 0)
return (NULL);
@ -197,10 +197,9 @@ zs_find_prom(int unit)
* The physical address of zs0 is model-dependent.
*/
zs0_phys = (cpu_machine_id == ID_SUN2_120 ? 0x002000 : 0x7f2000);
if (find_prom_map(zs0_phys, PMAP_OBIO, sizeof(struct zsdevice),
&bh))
if (find_prom_map(zs0_phys, PMAP_OBIO, sizeof(struct zsdevice), &va))
return (NULL);
return (bh);
return (void *)va;
}
#endif /* KGDB */

View File

@ -1,4 +1,4 @@
/* $NetBSD: machdep.c,v 1.42 2006/10/01 03:53:27 tsutsui Exp $ */
/* $NetBSD: machdep.c,v 1.43 2006/10/03 13:02:32 tsutsui Exp $ */
/*
* Copyright (c) 1982, 1986, 1990, 1993
@ -160,7 +160,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.42 2006/10/01 03:53:27 tsutsui Exp $");
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.43 2006/10/03 13:02:32 tsutsui Exp $");
#include "opt_ddb.h"
#include "opt_kgdb.h"
@ -1139,12 +1139,11 @@ vmebus_translate(vme_am_t mod, vme_addr_t addr, bus_type_t *btp,
* If we can find a mapping that was established by the PROM, use it.
*/
int
find_prom_map(bus_addr_t pa, bus_type_t iospace, int len,
bus_space_handle_t *hp)
find_prom_map(paddr_t pa, bus_type_t iospace, int len, vaddr_t *vap)
{
u_long pf;
int pgtype;
u_long va, eva;
vaddr_t va, eva;
int sme;
u_long pte;
int saved_ctx;
@ -1188,8 +1187,7 @@ find_prom_map(bus_addr_t pa, bus_type_t iospace, int len,
* Found the PROM mapping.
* note: preserve page offset
*/
*hp = (bus_space_handle_t)(va |
((u_long)pa & PGOFSET));
*vap = (va | ((vaddr_t)pa & PGOFSET));
restore_context(saved_ctx);
return 0;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: zs.c,v 1.76 2006/03/28 17:38:28 thorpej Exp $ */
/* $NetBSD: zs.c,v 1.77 2006/10/03 13:02:32 tsutsui Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
@ -45,7 +45,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: zs.c,v 1.76 2006/03/28 17:38:28 thorpej Exp $");
__KERNEL_RCSID(0, "$NetBSD: zs.c,v 1.77 2006/10/03 13:02:32 tsutsui Exp $");
#include "opt_kgdb.h"
@ -61,6 +61,8 @@ __KERNEL_RCSID(0, "$NetBSD: zs.c,v 1.76 2006/03/28 17:38:28 thorpej Exp $");
#include <sys/time.h>
#include <sys/syslog.h>
#include <uvm/uvm_extern.h>
#include <machine/autoconf.h>
#include <machine/cpu.h>
#include <machine/mon.h>
@ -164,11 +166,13 @@ static u_char zs_init_reg[16] = {
void
zs_init(void)
{
vaddr_t va;
int i;
for (i = 0; i < NZS; i++) {
zsaddr[i] = (struct zsdevice *)
obio_find_mapping(zs_physaddr[i], sizeof(struct zschan));
if (find_prom_map(zs_physaddr[i], PMAP_OBIO,
sizeof(struct zschan), &va) == 0)
zsaddr[i] = (void *)va;
}
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: bus_subr.c,v 1.15 2006/10/01 03:53:27 tsutsui Exp $ */
/* $NetBSD: bus_subr.c,v 1.16 2006/10/03 13:02:32 tsutsui Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
@ -42,7 +42,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: bus_subr.c,v 1.15 2006/10/01 03:53:27 tsutsui Exp $");
__KERNEL_RCSID(0, "$NetBSD: bus_subr.c,v 1.16 2006/10/03 13:02:32 tsutsui Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -152,8 +152,7 @@ bus_mapin(int bustype, int pa, int sz)
/* Borrow PROM mappings if we can. */
if (bustype == BUS_OBIO) {
va = (vaddr_t) obio_find_mapping(pa, sz);
if (va != 0)
if (find_prom_map(pa, PMAP_OBIO, sz, &va) == 0)
goto done;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: intreg.c,v 1.23 2005/12/11 12:19:27 christos Exp $ */
/* $NetBSD: intreg.c,v 1.24 2006/10/03 13:02:32 tsutsui Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
@ -42,7 +42,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: intreg.c,v 1.23 2005/12/11 12:19:27 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: intreg.c,v 1.24 2006/10/03 13:02:32 tsutsui Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -79,11 +79,14 @@ int intreg_attached;
void
intreg_init(void)
{
interrupt_reg = obio_find_mapping(IREG_ADDR, 1);
if (!interrupt_reg) {
vaddr_t va;
if (find_prom_map(IREG_ADDR, PMAP_OBIO, 1, &va) != 0) {
mon_printf("intreg_init\n");
sunmon_abort();
}
interrupt_reg = (void *)va;
/* Turn off all interrupts until clock_attach */
*interrupt_reg = 0;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: leds.c,v 1.10 2005/12/11 12:19:27 christos Exp $ */
/* $NetBSD: leds.c,v 1.11 2006/10/03 13:02:32 tsutsui Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@ -45,7 +45,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: leds.c,v 1.10 2005/12/11 12:19:27 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: leds.c,v 1.11 2006/10/03 13:02:32 tsutsui Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -55,6 +55,8 @@ __KERNEL_RCSID(0, "$NetBSD: leds.c,v 1.10 2005/12/11 12:19:27 christos Exp $");
#include <sys/malloc.h>
#include <sys/proc.h>
#include <uvm/uvm_extern.h>
#include <machine/autoconf.h>
#include <machine/idprom.h>
#include <machine/leds.h>
@ -94,9 +96,11 @@ static struct led_patterns ledpat = {
void
leds_init(void)
{
#ifdef _SUN3X_
diagreg = obio_find_mapping(OBIO_DIAGREG, 1);
vaddr_t va;
find_prom_map(OBIO_DIAGREG, PMAP_OBIO, 1, &va);
diagreg = (void *)va;
if (cpu_machine_id == ID_SUN3X_80)
ledpat.patlen = 1;
#endif /* SUN3X */

View File

@ -1,4 +1,4 @@
/* $NetBSD: machdep.h,v 1.35 2006/06/28 09:55:08 tsutsui Exp $ */
/* $NetBSD: machdep.h,v 1.36 2006/10/03 13:02:32 tsutsui Exp $ */
/*
* Copyright (c) 1982, 1990 The Regents of the University of California.
@ -132,7 +132,6 @@ void m68881_restore(struct fpframe *);
void netintr(void);
caddr_t obio_find_mapping(paddr_t, psize_t);
void obio_init(void);
void setvbr(void **);

View File

@ -1,4 +1,4 @@
/* $NetBSD: obio.c,v 1.51 2006/10/01 06:26:01 tsutsui Exp $ */
/* $NetBSD: obio.c,v 1.52 2006/10/03 13:02:32 tsutsui Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: obio.c,v 1.51 2006/10/01 06:26:01 tsutsui Exp $");
__KERNEL_RCSID(0, "$NetBSD: obio.c,v 1.52 2006/10/03 13:02:32 tsutsui Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -239,47 +239,16 @@ obio_submatch(struct device *parent, struct cfdata *cf,
* (array_index * SAVE_INCR)
* and the length of the mapping is one page.
*/
static caddr_t prom_mappings[SAVE_SLOTS];
static vaddr_t prom_mappings[SAVE_SLOTS];
/*
* Find a virtual address for a device at physical address 'pa'.
* If one is found among the mappings already made by the PROM
* at power-up time, use it. Otherwise return 0 as a sign that
* a mapping will have to be created.
*/
caddr_t
obio_find_mapping(paddr_t pa, psize_t sz)
{
vsize_t off;
vaddr_t va;
off = pa & PGOFSET;
pa -= off;
sz += off;
/* The saved mappings are all one page long. */
if (sz > PAGE_SIZE)
return (caddr_t)0;
/* Within our table? */
if (pa >= SAVE_LAST)
return (caddr_t)0;
/* Do we have this one? */
va = (vaddr_t)prom_mappings[pa >> SAVE_SHIFT];
if (va == 0)
return (caddr_t)0;
/* Found it! */
return ((caddr_t)(va + off));
}
/*
* The similar function with the above but used by bus_space(9)
* at power-up time, use it and return 0. Otherwise return errno
* as a sign that a mapping will have to be created.
*/
int
find_prom_map(bus_addr_t pa, bus_type_t iospace, int sz,
bus_space_handle_t *hp)
find_prom_map(paddr_t pa, bus_type_t iospace, int sz, vaddr_t *vap)
{
vsize_t off;
vaddr_t va;
@ -297,12 +266,12 @@ find_prom_map(bus_addr_t pa, bus_type_t iospace, int sz,
return ENOENT;
/* Do we have this one? */
va = (vaddr_t)prom_mappings[pa >> SAVE_SHIFT];
va = prom_mappings[pa >> SAVE_SHIFT];
if (va == 0)
return ENOENT;
/* Found it! */
*hp = va + off;
*vap = va + off;
return 0;
}
@ -345,8 +314,8 @@ save_prom_mappings(void)
((pa & SAVE_MASK) == 0))
{
i = pa >> SAVE_SHIFT;
if (prom_mappings[i] == NULL) {
prom_mappings[i] = (caddr_t)pgva;
if (prom_mappings[i] == 0) {
prom_mappings[i] = pgva;
}
}
/* Make sure it has the right permissions. */
@ -379,10 +348,11 @@ static void
make_required_mappings(void)
{
paddr_t *rmp;
vaddr_t va;
rmp = required_mappings;
while (*rmp != (paddr_t)-1) {
if (!obio_find_mapping(*rmp, PAGE_SIZE)) {
if (find_prom_map(*rmp, PMAP_OBIO, PAGE_SIZE, &va) != 0) {
/*
* XXX - Ack! Need to create one!
* I don't think this can happen, but if

View File

@ -1,4 +1,4 @@
/* $NetBSD: bus_subr.c,v 1.29 2006/09/30 15:49:30 tsutsui Exp $ */
/* $NetBSD: bus_subr.c,v 1.30 2006/10/03 13:02:32 tsutsui Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
@ -42,7 +42,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: bus_subr.c,v 1.29 2006/09/30 15:49:30 tsutsui Exp $");
__KERNEL_RCSID(0, "$NetBSD: bus_subr.c,v 1.30 2006/10/03 13:02:32 tsutsui Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -152,8 +152,7 @@ bus_mapin(int bustype, int pa, int sz)
/* Borrow PROM mappings if we can. */
if (bustype == BUS_OBIO) {
va = (vaddr_t) obio_find_mapping(pa, sz);
if (va != 0)
if (find_prom_map(pa, PMAP_OBIO, sz, &va) == 0)
goto done;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: enable.c,v 1.6 2005/12/11 12:19:27 christos Exp $ */
/* $NetBSD: enable.c,v 1.7 2006/10/03 13:02:32 tsutsui Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@ -37,9 +37,11 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: enable.c,v 1.6 2005/12/11 12:19:27 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: enable.c,v 1.7 2006/10/03 13:02:32 tsutsui Exp $");
#include <sys/param.h>
#include <uvm/uvm_extern.h>
#include <machine/bus.h>
#include <dev/sun/fbio.h>
#include <sun3/dev/fbvar.h>
#include <sun3/sun3/machdep.h>
@ -51,8 +53,10 @@ volatile short *enable_reg;
void
enable_init(void)
{
vaddr_t va;
enable_reg = (short*) obio_find_mapping(OBIO_ENABLEREG, 2);
find_prom_map(OBIO_ENABLEREG, PMAP_OBIO, 2, &va);
enable_reg = (void *)va;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: idprom.c,v 1.12 2005/12/11 12:19:27 christos Exp $ */
/* $NetBSD: idprom.c,v 1.13 2006/10/03 13:02:32 tsutsui Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
@ -41,13 +41,15 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: idprom.c,v 1.12 2005/12/11 12:19:27 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: idprom.c,v 1.13 2006/10/03 13:02:32 tsutsui Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/kernel.h>
#include <uvm/uvm_extern.h>
#include <machine/autoconf.h>
#include <machine/idprom.h>
@ -144,18 +146,18 @@ static void
idprom_get(u_char *dst)
{
u_char *src;
caddr_t va;
vaddr_t va;
int len;
/* First, probe for a separate IDPROM (3/470). */
va = obio_find_mapping(OBIO_IDPROM1, IDPROM_SIZE);
if (peek_byte(va) == -1) {
find_prom_map(OBIO_IDPROM1, PMAP_OBIO, IDPROM_SIZE, &va);
if (peek_byte((caddr_t)va) == -1) {
/* IDPROM is in the EEPROM */
va = obio_find_mapping(OBIO_IDPROM2, IDPROM_SIZE);
find_prom_map(OBIO_IDPROM2, PMAP_OBIO, IDPROM_SIZE, &va);
}
/* Copy the IDPROM contents and do the checksum. */
src = (u_char *) va;
src = (void *)va;
len = IDPROM_SIZE;
do {
*dst++ = *src++;

View File

@ -1,4 +1,4 @@
/* $NetBSD: obio.c,v 1.27 2006/10/01 03:53:27 tsutsui Exp $ */
/* $NetBSD: obio.c,v 1.28 2006/10/03 13:02:32 tsutsui Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: obio.c,v 1.27 2006/10/01 03:53:27 tsutsui Exp $");
__KERNEL_RCSID(0, "$NetBSD: obio.c,v 1.28 2006/10/03 13:02:32 tsutsui Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -272,38 +272,11 @@ static struct prom_map {
/*
* Find a virtual address for a device at physical address 'pa'.
* If one is found among the mappings already made by the PROM
* at power-up time, use it. Otherwise return 0 as a sign that
* a mapping will have to be created.
*/
caddr_t
obio_find_mapping(paddr_t pa, psize_t sz)
{
int i;
vsize_t off;
off = pa & PGOFSET;
pa -= off;
sz += off;
/* The saved mappings are all one page long. */
if (sz > PAGE_SIZE)
return (caddr_t)0;
/* Linear search for it. The list is short. */
for (i = 0; i < PROM_MAP_CNT; i++) {
if (pa == prom_mappings[i].pa) {
return ((caddr_t)(prom_mappings[i].va + off));
}
}
return (caddr_t)0;
}
/*
* The similar function with the above but used by bus_space(9)
* at power-up time, use it and return 0. Otherwise return errno
* as a sign that a mapping will have to be created.
*/
int
find_prom_map(bus_addr_t pa, bus_type_t iospace, int sz,
bus_space_handle_t *hp)
find_prom_map(paddr_t pa, bus_type_t iospace, int sz, vaddr_t *vap)
{
int i;
vsize_t off;
@ -319,7 +292,7 @@ find_prom_map(bus_addr_t pa, bus_type_t iospace, int sz,
/* Linear search for it. The list is short. */
for (i = 0; i < PROM_MAP_CNT; i++) {
if (pa == prom_mappings[i].pa) {
*hp = prom_mappings[i].va + off;
*vap = prom_mappings[i].va + off;
return 0;
}
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: bus.h,v 1.12 2006/10/01 03:53:28 tsutsui Exp $ */
/* $NetBSD: bus.h,v 1.13 2006/10/03 13:02:33 tsutsui Exp $ */
/*-
* Copyright (c) 1996, 1997, 1998, 2001 The NetBSD Foundation, Inc.
@ -316,6 +316,15 @@ int bus_space_alloc(bus_space_tag_t, bus_addr_t, bus_addr_t, bus_size_t,
void bus_space_free(bus_space_tag_t, bus_space_handle_t, bus_size_t);
#endif
/*
* void *bus_space_vaddr(bus_space_tag_t, bus_space_handle_t);
*
* Get the kernel virtual address for the mapped bus space.
* Only allowed for regions mapped with BUS_SPACE_MAP_LINEAR.
* (XXX not enforced)
*/
#define bus_space_vaddr(t, h) ((void)(t), (void *)(h))
/* flags for bus space map functions */
#define BUS_SPACE_MAP_CACHEABLE 0x0001
#define BUS_SPACE_MAP_LINEAR 0x0002
@ -789,7 +798,7 @@ bus_space_copy_region_8(bus_space_tag_t t, bus_space_handle_t h1, bus_size_t o1,
#define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
int find_prom_map(bus_addr_t, bus_type_t, int, bus_space_handle_t *);
int find_prom_map(paddr_t, bus_type_t, int, vaddr_t *);
/*--------------------------------*/

View File

@ -1,4 +1,4 @@
/* $NetBSD: bus.c,v 1.17 2006/10/01 03:53:28 tsutsui Exp $ */
/* $NetBSD: bus.c,v 1.18 2006/10/03 13:02:33 tsutsui Exp $ */
/*
* Copyright (c) 1982, 1986, 1990, 1993
@ -160,7 +160,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: bus.c,v 1.17 2006/10/01 03:53:28 tsutsui Exp $");
__KERNEL_RCSID(0, "$NetBSD: bus.c,v 1.18 2006/10/03 13:02:33 tsutsui Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -521,8 +521,10 @@ sun68k_bus_map(bus_space_tag_t t, bus_type_t iospace, bus_addr_t addr,
* and use a PROM mapping.
*/
if ((flags & _SUN68K_BUS_MAP_USE_PROM) != 0 &&
find_prom_map(addr, iospace, size, hp) == 0)
find_prom_map(addr, iospace, size, &v) == 0) {
*hp = (bus_space_handle_t)v;
return (0);
}
/*
* Adjust the user's request to be page-aligned.