Use the new pmap_devmap facility in the on-board device mapping code.
This commit is contained in:
parent
cf8a25bdfc
commit
05d2fb4399
@ -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.
|
||||
@ -843,6 +843,13 @@ consinit(void)
|
||||
|
||||
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 (comcnattach(&obio_bs_tag, comcnaddrs[comcnunit], comcnspeed,
|
||||
BECC_PERIPH_CLOCK, COM_TYPE_NORMAL, comcnmode))
|
||||
|
@ -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.
|
||||
*
|
||||
* Written by Jason R. Thorpe for Wasabi Systems, Inc.
|
||||
@ -46,8 +46,6 @@
|
||||
|
||||
#include <machine/bus.h>
|
||||
|
||||
#include <evbarm/adi_brh/brhreg.h>
|
||||
|
||||
/* Prototypes for all the bus_space structure functions */
|
||||
bs_protos(obio);
|
||||
bs_protos(generic);
|
||||
@ -139,45 +137,35 @@ int
|
||||
obio_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int flags,
|
||||
bus_space_handle_t *bshp)
|
||||
{
|
||||
uint32_t startpa, endpa, pa;
|
||||
const struct pmap_devmap *pd;
|
||||
paddr_t startpa, endpa, pa, offset;
|
||||
vaddr_t va;
|
||||
pt_entry_t *pte;
|
||||
|
||||
/*
|
||||
* Some devices have already been mapped during bootstrap.
|
||||
*/
|
||||
switch (bpa) {
|
||||
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);
|
||||
|
||||
/* XXX use some extent to check for duplicate mappings? */
|
||||
|
||||
va = uvm_km_valloc(kernel_map, endpa - startpa);
|
||||
if (! va)
|
||||
return ENOMEM;
|
||||
|
||||
*bshp = (bus_space_handle_t) (va + (bpa - startpa));
|
||||
|
||||
for (pa=startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) {
|
||||
pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE);
|
||||
pte = vtopte(va);
|
||||
*pte &= ~L2_S_CACHE_MASK;
|
||||
PTE_SYNC(pte);
|
||||
}
|
||||
pmap_update(pmap_kernel());
|
||||
break;
|
||||
if ((pd = pmap_devmap_find_pa(bpa, size)) != NULL) {
|
||||
/* Device was statically mapped. */
|
||||
*bshp = pd->pd_va + (bpa - pd->pd_pa);
|
||||
return (0);
|
||||
}
|
||||
|
||||
endpa = round_page(bpa + size);
|
||||
offset = bpa & PAGE_MASK;
|
||||
startpa = trunc_page(bpa);
|
||||
|
||||
va = uvm_km_valloc(kernel_map, endpa - startpa);
|
||||
if (va == 0)
|
||||
return ENOMEM;
|
||||
|
||||
*bshp = va + offset;
|
||||
|
||||
for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) {
|
||||
pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE);
|
||||
pte = vtopte(va);
|
||||
*pte &= ~L2_S_CACHE_MASK;
|
||||
PTE_SYNC(pte);
|
||||
}
|
||||
pmap_update(pmap_kernel());
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@ -194,16 +182,18 @@ obio_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend, bus_size_t size,
|
||||
void
|
||||
obio_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size)
|
||||
{
|
||||
vaddr_t va, endva;
|
||||
|
||||
switch (bsh) {
|
||||
case BRH_UART1_VBASE:
|
||||
case BRH_UART2_VBASE:
|
||||
/* Nothing to do. */
|
||||
|
||||
default:
|
||||
/* Handle other cases, like flash? */
|
||||
panic("obio_bs_unmap: impossible");
|
||||
if (pmap_devmap_find_va(bsh, size) != NULL) {
|
||||
/* Device was statically mapped; nothing to do. */
|
||||
return;
|
||||
}
|
||||
|
||||
endva = round_page(bsh + size);
|
||||
va = trunc_page(bsh);
|
||||
|
||||
pmap_kremove(va, endva - va);
|
||||
uvm_km_free(kernel_map, va, endva - va);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -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.
|
||||
@ -804,6 +804,13 @@ consinit(void)
|
||||
|
||||
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 (comcnattach(&obio_bs_tag, comcnaddrs[comcnunit], comcnspeed,
|
||||
COM_FREQ, COM_TYPE_NORMAL, comcnmode))
|
||||
|
@ -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.
|
||||
*
|
||||
* Written by Jason R. Thorpe for Wasabi Systems, Inc.
|
||||
@ -46,8 +46,6 @@
|
||||
|
||||
#include <machine/bus.h>
|
||||
|
||||
#include "iq80310reg.h"
|
||||
|
||||
/* Prototypes for all the bus_space structure functions */
|
||||
bs_protos(obio);
|
||||
bs_protos(generic);
|
||||
@ -138,46 +136,36 @@ int
|
||||
obio_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int flags,
|
||||
bus_space_handle_t *bshp)
|
||||
{
|
||||
u_long startpa, endpa, pa;
|
||||
const struct pmap_devmap *pd;
|
||||
paddr_t startpa, endpa, pa, offset;
|
||||
vaddr_t va;
|
||||
pt_entry_t *pte;
|
||||
|
||||
if (bpa > IQ80310_OBIO_BASE) {
|
||||
|
||||
/*
|
||||
* 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);
|
||||
|
||||
/* XXX use extent manager to check duplicate mapping */
|
||||
|
||||
va = uvm_km_valloc(kernel_map, endpa - startpa);
|
||||
if (! va)
|
||||
return(ENOMEM);
|
||||
|
||||
*bshp = (bus_space_handle_t)(va + (bpa - startpa));
|
||||
|
||||
for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) {
|
||||
pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE);
|
||||
pte = vtopte(va);
|
||||
*pte &= ~L2_S_CACHE_MASK;
|
||||
PTE_SYNC(pte);
|
||||
}
|
||||
pmap_update(pmap_kernel());
|
||||
|
||||
if ((pd = pmap_devmap_find_pa(bpa, size)) != NULL) {
|
||||
/* Device was statically mapped. */
|
||||
*bshp = pd->pd_va + (bpa - pd->pd_pa);
|
||||
return (0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
endpa = round_page(bpa + size);
|
||||
offset = bpa & PAGE_MASK;
|
||||
startpa = trunc_page(bpa);
|
||||
|
||||
va = uvm_km_valloc(kernel_map, endpa - startpa);
|
||||
if (va == 0)
|
||||
return(ENOMEM);
|
||||
|
||||
*bshp = va + offset;
|
||||
|
||||
for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) {
|
||||
pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE);
|
||||
pte = vtopte(va);
|
||||
*pte &= ~L2_S_CACHE_MASK;
|
||||
PTE_SYNC(pte);
|
||||
}
|
||||
pmap_update(pmap_kernel());
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
@ -193,11 +181,18 @@ obio_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend, bus_size_t size,
|
||||
void
|
||||
obio_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size)
|
||||
{
|
||||
vaddr_t va, endva;
|
||||
|
||||
/* Nothing to do. */
|
||||
/* XXX -- technically, if we alloc and map above, we should
|
||||
* unmap and free here, but we bail on this for now.
|
||||
*/
|
||||
if (pmap_devmap_find_va(bsh, size) != NULL) {
|
||||
/* Device was statically mapped; nothing to do. */
|
||||
return;
|
||||
}
|
||||
|
||||
endva = round_page(bsh + size);
|
||||
va = trunc_page(bsh);
|
||||
|
||||
pmap_kremove(va, endva - va);
|
||||
uvm_km_free(kernel_map, va, endva - va);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -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.
|
||||
@ -820,6 +820,13 @@ consinit(void)
|
||||
|
||||
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 (comcnattach(&obio_bs_tag, comcnaddrs[comcnunit], comcnspeed,
|
||||
COM_FREQ, COM_TYPE_NORMAL, comcnmode))
|
||||
|
@ -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.
|
||||
*
|
||||
* Written by Jason R. Thorpe for Wasabi Systems, Inc.
|
||||
@ -46,8 +46,6 @@
|
||||
|
||||
#include <machine/bus.h>
|
||||
|
||||
#include "iq80321reg.h"
|
||||
|
||||
/* Prototypes for all the bus_space structure functions */
|
||||
bs_protos(obio);
|
||||
bs_protos(generic);
|
||||
@ -139,43 +137,36 @@ int
|
||||
obio_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int flags,
|
||||
bus_space_handle_t *bshp)
|
||||
{
|
||||
uint32_t startpa, endpa, pa;
|
||||
const struct pmap_devmap *pd;
|
||||
paddr_t startpa, endpa, pa, offset;
|
||||
vaddr_t va;
|
||||
pt_entry_t *pte;
|
||||
|
||||
if (bpa > IQ80321_IOPXS_VBASE) {
|
||||
/*
|
||||
* IQ80321 on-board devices are mapped VA==PA. All
|
||||
* addresses we're provided, therefore, don't need
|
||||
* 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? */
|
||||
|
||||
va = uvm_km_valloc(kernel_map, endpa - startpa);
|
||||
if (! va)
|
||||
return ENOMEM;
|
||||
|
||||
*bshp = (bus_space_handle_t) (va + (bpa - startpa));
|
||||
|
||||
for (pa=startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) {
|
||||
pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE);
|
||||
pte = vtopte(va);
|
||||
*pte &= ~L2_S_CACHE_MASK;
|
||||
PTE_SYNC(pte);
|
||||
}
|
||||
pmap_update(pmap_kernel());
|
||||
if ((pd = pmap_devmap_find_pa(bpa, size)) != NULL) {
|
||||
/* Device was statically mapped. */
|
||||
*bshp = pd->pd_va + (bpa - pd->pd_pa);
|
||||
return (0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
endpa = round_page(bpa + size);
|
||||
offset = bpa & PAGE_MASK;
|
||||
startpa = trunc_page(bpa);
|
||||
|
||||
va = uvm_km_valloc(kernel_map, endpa - startpa);
|
||||
if (va == 0)
|
||||
return (ENOMEM);
|
||||
|
||||
*bshp = va + offset;
|
||||
|
||||
for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) {
|
||||
pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE);
|
||||
pte = vtopte(va);
|
||||
*pte &= ~L2_S_CACHE_MASK;
|
||||
PTE_SYNC(pte);
|
||||
}
|
||||
pmap_update(pmap_kernel());
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
@ -191,11 +182,18 @@ obio_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend, bus_size_t size,
|
||||
void
|
||||
obio_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size)
|
||||
{
|
||||
vaddr_t va, endva;
|
||||
|
||||
/* Nothing to do. */
|
||||
/* XXX -- technically, if we alloc and map above, we should
|
||||
* unmap and free here, but we bail on this for now.
|
||||
*/
|
||||
if (pmap_devmap_find_va(bsh, size) != NULL) {
|
||||
/* Device was statically mapped; nothing to do. */
|
||||
return;
|
||||
}
|
||||
|
||||
endva = round_page(bsh + size);
|
||||
va = trunc_page(bsh);
|
||||
|
||||
pmap_kremove(va, endva - va);
|
||||
uvm_km_free(kernel_map, va, endva - va);
|
||||
}
|
||||
|
||||
void
|
||||
|
Loading…
Reference in New Issue
Block a user