Use the new pmap_devmap facility in the on-board device mapping code.

This commit is contained in:
thorpej 2003-06-15 18:43:48 +00:00
parent cf8a25bdfc
commit 05d2fb4399
6 changed files with 136 additions and 132 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: brh_machdep.c,v 1.16 2003/06/15 17:45:24 thorpej Exp $ */ /* $NetBSD: brh_machdep.c,v 1.17 2003/06/15 18:43:48 thorpej Exp $ */
/* /*
* Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc. * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc.
@ -843,6 +843,13 @@ consinit(void)
consinit_called = 1; consinit_called = 1;
/*
* brh_start() has mapped the console devices for us per
* the devmap, so register it now so drivers can map the
* console device.
*/
pmap_devmap_register(brh_devmap);
#if NCOM > 0 #if NCOM > 0
if (comcnattach(&obio_bs_tag, comcnaddrs[comcnunit], comcnspeed, if (comcnattach(&obio_bs_tag, comcnaddrs[comcnunit], comcnspeed,
BECC_PERIPH_CLOCK, COM_TYPE_NORMAL, comcnmode)) BECC_PERIPH_CLOCK, COM_TYPE_NORMAL, comcnmode))

View File

@ -1,7 +1,7 @@
/* $NetBSD: obio_space.c,v 1.1 2003/01/25 02:00:17 thorpej Exp $ */ /* $NetBSD: obio_space.c,v 1.2 2003/06/15 18:43:49 thorpej Exp $ */
/* /*
* Copyright (c) 2001, 2002 Wasabi Systems, Inc. * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc.
* All rights reserved. * All rights reserved.
* *
* Written by Jason R. Thorpe for Wasabi Systems, Inc. * Written by Jason R. Thorpe for Wasabi Systems, Inc.
@ -46,8 +46,6 @@
#include <machine/bus.h> #include <machine/bus.h>
#include <evbarm/adi_brh/brhreg.h>
/* Prototypes for all the bus_space structure functions */ /* Prototypes for all the bus_space structure functions */
bs_protos(obio); bs_protos(obio);
bs_protos(generic); bs_protos(generic);
@ -139,34 +137,26 @@ int
obio_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int flags, obio_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int flags,
bus_space_handle_t *bshp) bus_space_handle_t *bshp)
{ {
uint32_t startpa, endpa, pa; const struct pmap_devmap *pd;
paddr_t startpa, endpa, pa, offset;
vaddr_t va; vaddr_t va;
pt_entry_t *pte; pt_entry_t *pte;
/* if ((pd = pmap_devmap_find_pa(bpa, size)) != NULL) {
* Some devices have already been mapped during bootstrap. /* Device was statically mapped. */
*/ *bshp = pd->pd_va + (bpa - pd->pd_pa);
switch (bpa) { return (0);
case BRH_UART1_BASE: }
*bshp = BRH_UART1_VBASE;
break;
case BRH_UART2_BASE:
*bshp = BRH_UART2_VBASE;
break;
default:
/* XXX -- add code to check for valid request */
startpa = trunc_page(bpa);
endpa = round_page(bpa + size); endpa = round_page(bpa + size);
offset = bpa & PAGE_MASK;
/* XXX use some extent to check for duplicate mappings? */ startpa = trunc_page(bpa);
va = uvm_km_valloc(kernel_map, endpa - startpa); va = uvm_km_valloc(kernel_map, endpa - startpa);
if (! va) if (va == 0)
return ENOMEM; return ENOMEM;
*bshp = (bus_space_handle_t) (va + (bpa - startpa)); *bshp = va + offset;
for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) { for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) {
pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE); pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE);
@ -175,8 +165,6 @@ obio_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int flags,
PTE_SYNC(pte); PTE_SYNC(pte);
} }
pmap_update(pmap_kernel()); pmap_update(pmap_kernel());
break;
}
return (0); return (0);
} }
@ -194,16 +182,18 @@ obio_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend, bus_size_t size,
void void
obio_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size) obio_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size)
{ {
vaddr_t va, endva;
switch (bsh) { if (pmap_devmap_find_va(bsh, size) != NULL) {
case BRH_UART1_VBASE: /* Device was statically mapped; nothing to do. */
case BRH_UART2_VBASE: return;
/* Nothing to do. */
default:
/* Handle other cases, like flash? */
panic("obio_bs_unmap: impossible");
} }
endva = round_page(bsh + size);
va = trunc_page(bsh);
pmap_kremove(va, endva - va);
uvm_km_free(kernel_map, va, endva - va);
} }
void void

View File

@ -1,4 +1,4 @@
/* $NetBSD: iq80310_machdep.c,v 1.59 2003/06/15 17:45:25 thorpej Exp $ */ /* $NetBSD: iq80310_machdep.c,v 1.60 2003/06/15 18:43:49 thorpej Exp $ */
/* /*
* Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc. * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc.
@ -804,6 +804,13 @@ consinit(void)
consinit_called = 1; consinit_called = 1;
/*
* Console devices are mapped VA==PA. Our devmap reflects
* this, so register it now so drivers can map the console
* device.
*/
pmap_devmap_register(iq80310_devmap);
#if NCOM > 0 #if NCOM > 0
if (comcnattach(&obio_bs_tag, comcnaddrs[comcnunit], comcnspeed, if (comcnattach(&obio_bs_tag, comcnaddrs[comcnunit], comcnspeed,
COM_FREQ, COM_TYPE_NORMAL, comcnmode)) COM_FREQ, COM_TYPE_NORMAL, comcnmode))

View File

@ -1,7 +1,7 @@
/* $NetBSD: obio_space.c,v 1.8 2002/09/27 15:36:00 provos Exp $ */ /* $NetBSD: obio_space.c,v 1.9 2003/06/15 18:43:50 thorpej Exp $ */
/* /*
* Copyright (c) 2001 Wasabi Systems, Inc. * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc.
* All rights reserved. * All rights reserved.
* *
* Written by Jason R. Thorpe for Wasabi Systems, Inc. * Written by Jason R. Thorpe for Wasabi Systems, Inc.
@ -46,8 +46,6 @@
#include <machine/bus.h> #include <machine/bus.h>
#include "iq80310reg.h"
/* Prototypes for all the bus_space structure functions */ /* Prototypes for all the bus_space structure functions */
bs_protos(obio); bs_protos(obio);
bs_protos(generic); bs_protos(generic);
@ -138,34 +136,26 @@ int
obio_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int flags, obio_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int flags,
bus_space_handle_t *bshp) bus_space_handle_t *bshp)
{ {
u_long startpa, endpa, pa; const struct pmap_devmap *pd;
paddr_t startpa, endpa, pa, offset;
vaddr_t va; vaddr_t va;
pt_entry_t *pte; pt_entry_t *pte;
if (bpa > IQ80310_OBIO_BASE) { if ((pd = pmap_devmap_find_pa(bpa, size)) != NULL) {
/* Device was statically mapped. */
*bshp = pd->pd_va + (bpa - pd->pd_pa);
return (0);
}
/*
* IQ80310 on-board devices are mapped VA==PA. All addresses
* we're provided, therefore, don't need any additional mapping.
*/
*bshp = bpa;
} else {
/*
* Some devices actually lie outside the range above.
* Notably: flash.
*/
startpa = trunc_page(bpa);
endpa = round_page(bpa + size); endpa = round_page(bpa + size);
offset = bpa & PAGE_MASK;
/* XXX use extent manager to check duplicate mapping */ startpa = trunc_page(bpa);
va = uvm_km_valloc(kernel_map, endpa - startpa); va = uvm_km_valloc(kernel_map, endpa - startpa);
if (! va) if (va == 0)
return(ENOMEM); return(ENOMEM);
*bshp = (bus_space_handle_t)(va + (bpa - startpa)); *bshp = va + offset;
for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) { for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) {
pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE); pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE);
@ -175,9 +165,7 @@ obio_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int flags,
} }
pmap_update(pmap_kernel()); pmap_update(pmap_kernel());
} return (0);
return 0;
} }
int int
@ -193,11 +181,18 @@ obio_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend, bus_size_t size,
void void
obio_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size) obio_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size)
{ {
vaddr_t va, endva;
/* Nothing to do. */ if (pmap_devmap_find_va(bsh, size) != NULL) {
/* XXX -- technically, if we alloc and map above, we should /* Device was statically mapped; nothing to do. */
* unmap and free here, but we bail on this for now. return;
*/ }
endva = round_page(bsh + size);
va = trunc_page(bsh);
pmap_kremove(va, endva - va);
uvm_km_free(kernel_map, va, endva - va);
} }
void void

View File

@ -1,4 +1,4 @@
/* $NetBSD: iq80321_machdep.c,v 1.28 2003/06/15 17:45:25 thorpej Exp $ */ /* $NetBSD: iq80321_machdep.c,v 1.29 2003/06/15 18:43:50 thorpej Exp $ */
/* /*
* Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc. * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc.
@ -820,6 +820,13 @@ consinit(void)
consinit_called = 1; consinit_called = 1;
/*
* Console devices are mapped VA==PA. Our devmap reflects
* this, so register it now so drivers can map the console
* device.
*/
pmap_devmap_register(iq80321_devmap);
#if NCOM > 0 #if NCOM > 0
if (comcnattach(&obio_bs_tag, comcnaddrs[comcnunit], comcnspeed, if (comcnattach(&obio_bs_tag, comcnaddrs[comcnunit], comcnspeed,
COM_FREQ, COM_TYPE_NORMAL, comcnmode)) COM_FREQ, COM_TYPE_NORMAL, comcnmode))

View File

@ -1,7 +1,7 @@
/* $NetBSD: obio_space.c,v 1.4 2003/01/02 23:04:08 briggs Exp $ */ /* $NetBSD: obio_space.c,v 1.5 2003/06/15 18:43:50 thorpej Exp $ */
/* /*
* Copyright (c) 2001, 2002 Wasabi Systems, Inc. * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc.
* All rights reserved. * All rights reserved.
* *
* Written by Jason R. Thorpe for Wasabi Systems, Inc. * Written by Jason R. Thorpe for Wasabi Systems, Inc.
@ -46,8 +46,6 @@
#include <machine/bus.h> #include <machine/bus.h>
#include "iq80321reg.h"
/* Prototypes for all the bus_space structure functions */ /* Prototypes for all the bus_space structure functions */
bs_protos(obio); bs_protos(obio);
bs_protos(generic); bs_protos(generic);
@ -139,32 +137,26 @@ int
obio_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int flags, obio_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int flags,
bus_space_handle_t *bshp) bus_space_handle_t *bshp)
{ {
uint32_t startpa, endpa, pa; const struct pmap_devmap *pd;
paddr_t startpa, endpa, pa, offset;
vaddr_t va; vaddr_t va;
pt_entry_t *pte; pt_entry_t *pte;
if (bpa > IQ80321_IOPXS_VBASE) { if ((pd = pmap_devmap_find_pa(bpa, size)) != NULL) {
/* /* Device was statically mapped. */
* IQ80321 on-board devices are mapped VA==PA. All *bshp = pd->pd_va + (bpa - pd->pd_pa);
* addresses we're provided, therefore, don't need return (0);
* any additional mapping. }
*/
*bshp = bpa;
} else {
/*
* Some devices, however, may lie outside the
* already-mapped space (notably flash).
*/
startpa = trunc_page(bpa);
endpa = round_page(bpa + size);
/* XXX use some extent to check for duplicate mappings? */ endpa = round_page(bpa + size);
offset = bpa & PAGE_MASK;
startpa = trunc_page(bpa);
va = uvm_km_valloc(kernel_map, endpa - startpa); va = uvm_km_valloc(kernel_map, endpa - startpa);
if (! va) if (va == 0)
return ENOMEM; return (ENOMEM);
*bshp = (bus_space_handle_t) (va + (bpa - startpa)); *bshp = va + offset;
for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) { for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) {
pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE); pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE);
@ -173,9 +165,8 @@ obio_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int flags,
PTE_SYNC(pte); PTE_SYNC(pte);
} }
pmap_update(pmap_kernel()); pmap_update(pmap_kernel());
}
return 0; return (0);
} }
int int
@ -191,11 +182,18 @@ obio_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend, bus_size_t size,
void void
obio_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size) obio_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size)
{ {
vaddr_t va, endva;
/* Nothing to do. */ if (pmap_devmap_find_va(bsh, size) != NULL) {
/* XXX -- technically, if we alloc and map above, we should /* Device was statically mapped; nothing to do. */
* unmap and free here, but we bail on this for now. return;
*/ }
endva = round_page(bsh + size);
va = trunc_page(bsh);
pmap_kremove(va, endva - va);
uvm_km_free(kernel_map, va, endva - va);
} }
void void