implement pmap_k{enter_pa,remove}() correctly.
remove various checks for impossible conditions. other misc cleanup.
This commit is contained in:
parent
e6b1a09d07
commit
177230d1d6
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: pmap.c,v 1.77 2001/06/02 18:09:15 chs Exp $ */
|
||||
/* $NetBSD: pmap.c,v 1.78 2001/08/04 18:42:39 chs Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1999 The NetBSD Foundation, Inc.
|
||||
|
@ -344,11 +344,11 @@ pmap_virtual_space(vstartp, vendp)
|
|||
|
||||
/*
|
||||
* pmap_procwr: [ INTERFACE ]
|
||||
*
|
||||
*
|
||||
* Synchronize caches corresponding to [addr, addr+len) in p.
|
||||
*
|
||||
* Note: no locking is necessary in this function.
|
||||
*/
|
||||
*/
|
||||
void
|
||||
pmap_procwr(p, va, len)
|
||||
struct proc *p;
|
||||
|
@ -492,7 +492,7 @@ pmap_init()
|
|||
s = ptoa(npages);
|
||||
addr2 = addr + s;
|
||||
kpt_pages = &((struct kpt_page *)addr2)[npages];
|
||||
kpt_free_list = (struct kpt_page *)0;
|
||||
kpt_free_list = NULL;
|
||||
do {
|
||||
addr2 -= NBPG;
|
||||
(--kpt_pages)->kpt_next = kpt_free_list;
|
||||
|
@ -519,7 +519,7 @@ pmap_init()
|
|||
* XXX We don't want to hang when we run out of
|
||||
* page tables, so we lower maxproc so that fork()
|
||||
* will fail instead. Note that root could still raise
|
||||
* this value via sysctl(2).
|
||||
* this value via sysctl(3).
|
||||
*/
|
||||
maxproc = (MAC_PTMAXSIZE / MAC_MAX_PTSIZE);
|
||||
} else
|
||||
|
@ -773,9 +773,6 @@ pmap_destroy(pmap)
|
|||
{
|
||||
int count;
|
||||
|
||||
if (pmap == NULL)
|
||||
return;
|
||||
|
||||
PMAP_DPRINTF(PDB_FOLLOW, ("pmap_destroy(%p)\n", pmap));
|
||||
|
||||
simple_lock(&pmap->pm_lock);
|
||||
|
@ -826,9 +823,6 @@ pmap_reference(pmap)
|
|||
pmap_t pmap;
|
||||
{
|
||||
|
||||
if (pmap == NULL)
|
||||
return;
|
||||
|
||||
PMAP_DPRINTF(PDB_FOLLOW, ("pmap_reference(%p)\n", pmap));
|
||||
|
||||
simple_lock(&pmap->pm_lock);
|
||||
|
@ -904,9 +898,6 @@ pmap_do_remove(pmap, sva, eva, remove_wired)
|
|||
PMAP_DPRINTF(PDB_FOLLOW|PDB_REMOVE|PDB_PROTECT,
|
||||
("pmap_remove(%p, %lx, %lx)\n", pmap, sva, eva));
|
||||
|
||||
if (pmap == NULL)
|
||||
return;
|
||||
|
||||
flags = active_pmap(pmap) ? PRM_TFLUSH : 0;
|
||||
while (sva < eva) {
|
||||
nssva = mac68k_trunc_seg(sva) + MAC_SEG_SIZE;
|
||||
|
@ -956,9 +947,6 @@ pmap_page_protect(pg, prot)
|
|||
(prot == VM_PROT_NONE && (pmapdebug & PDB_REMOVE)))
|
||||
printf("pmap_page_protect(%lx, %x)\n", pa, prot);
|
||||
#endif
|
||||
if (PAGE_IS_MANAGED(pa) == 0)
|
||||
return;
|
||||
|
||||
switch (prot) {
|
||||
case VM_PROT_READ|VM_PROT_WRITE:
|
||||
case VM_PROT_ALL:
|
||||
|
@ -1021,16 +1009,10 @@ pmap_protect(pmap, sva, eva, prot)
|
|||
("pmap_protect(%p, %lx, %lx, %x)\n",
|
||||
pmap, sva, eva, prot));
|
||||
|
||||
if (pmap == NULL)
|
||||
return;
|
||||
|
||||
if ((prot & VM_PROT_READ) == VM_PROT_NONE) {
|
||||
pmap_remove(pmap, sva, eva);
|
||||
return;
|
||||
}
|
||||
if (prot & VM_PROT_WRITE)
|
||||
return;
|
||||
|
||||
isro = pte_prot(pmap, prot);
|
||||
needtflush = active_pmap(pmap);
|
||||
firstpage = TRUE;
|
||||
|
@ -1304,7 +1286,54 @@ pmap_kenter_pa(va, pa, prot)
|
|||
paddr_t pa;
|
||||
vm_prot_t prot;
|
||||
{
|
||||
pmap_enter(pmap_kernel(), va, pa, prot, PMAP_WIRED);
|
||||
struct pmap *pmap = pmap_kernel();
|
||||
pt_entry_t *pte;
|
||||
int s, npte;
|
||||
|
||||
PMAP_DPRINTF(PDB_FOLLOW|PDB_ENTER,
|
||||
("pmap_kenter_pa(%lx, %lx, %x)\n", va, pa, prot));
|
||||
|
||||
/*
|
||||
* Segment table entry not valid, we need a new PT page
|
||||
*/
|
||||
|
||||
if (!pmap_ste_v(pmap, va)) {
|
||||
s = splvm();
|
||||
pmap_enter_ptpage(pmap, va);
|
||||
splx(s);
|
||||
}
|
||||
|
||||
pa = m68k_trunc_page(pa);
|
||||
pte = pmap_pte(pmap, va);
|
||||
|
||||
PMAP_DPRINTF(PDB_ENTER, ("enter: pte %p, *pte %x\n", pte, *pte));
|
||||
KASSERT(!pmap_pte_v(pte));
|
||||
|
||||
/*
|
||||
* Increment counters
|
||||
*/
|
||||
|
||||
pmap->pm_stats.resident_count++;
|
||||
pmap->pm_stats.wired_count++;
|
||||
|
||||
/*
|
||||
* Build the new PTE.
|
||||
*/
|
||||
|
||||
npte = pa | pte_prot(pmap, prot) | PG_V | PG_W;
|
||||
#if defined(M68040)
|
||||
if (mmutype == MMU_68040 && (npte & (PG_PROT)) == PG_RW)
|
||||
npte |= PG_CCB;
|
||||
#endif
|
||||
|
||||
PMAP_DPRINTF(PDB_ENTER, ("enter: new pte value %x\n", npte));
|
||||
#if defined(M68040)
|
||||
if (mmutype == MMU_68040) {
|
||||
DCFP(pa);
|
||||
ICPP(pa);
|
||||
}
|
||||
#endif
|
||||
*pte = npte;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1312,7 +1341,71 @@ pmap_kremove(va, len)
|
|||
vaddr_t va;
|
||||
vsize_t len;
|
||||
{
|
||||
pmap_remove(pmap_kernel(), va, va + len);
|
||||
struct pmap *pmap = pmap_kernel();
|
||||
vaddr_t sva, eva, nssva;
|
||||
pt_entry_t *pte;
|
||||
|
||||
PMAP_DPRINTF(PDB_FOLLOW|PDB_REMOVE|PDB_PROTECT,
|
||||
("pmap_kremove(%lx, %lx)\n", va, len));
|
||||
|
||||
sva = va;
|
||||
eva = va + len;
|
||||
while (sva < eva) {
|
||||
nssva = m68k_trunc_seg(sva) + NBSEG;
|
||||
if (nssva == 0 || nssva > eva)
|
||||
nssva = eva;
|
||||
|
||||
/*
|
||||
* If VA belongs to an unallocated segment,
|
||||
* skip to the next segment boundary.
|
||||
*/
|
||||
|
||||
if (!pmap_ste_v(pmap, sva)) {
|
||||
sva = nssva;
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* Invalidate every valid mapping within this segment.
|
||||
*/
|
||||
|
||||
pte = pmap_pte(pmap, sva);
|
||||
while (sva < nssva) {
|
||||
if (pmap_pte_v(pte)) {
|
||||
#ifdef DEBUG
|
||||
struct pv_entry *pv;
|
||||
int s;
|
||||
|
||||
pv = pa_to_pvh(pmap_pte_pa(pte));
|
||||
s = splvm();
|
||||
while (pv->pv_pmap != NULL) {
|
||||
KASSERT(pv->pv_pmap != pmap_kernel() ||
|
||||
pv->pv_va != sva);
|
||||
pv = pv->pv_next;
|
||||
if (pv == NULL) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
splx(s);
|
||||
#endif
|
||||
/*
|
||||
* Update statistics
|
||||
*/
|
||||
|
||||
pmap->pm_stats.wired_count--;
|
||||
pmap->pm_stats.resident_count--;
|
||||
|
||||
/*
|
||||
* Invalidate the PTE.
|
||||
*/
|
||||
|
||||
*pte = PG_NV;
|
||||
TBIS(va);
|
||||
}
|
||||
pte++;
|
||||
sva += NBPG;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1332,9 +1425,6 @@ pmap_unwire(pmap, va)
|
|||
PMAP_DPRINTF(PDB_FOLLOW,
|
||||
("pmap_unwire(%p, %lx)\n", pmap, va));
|
||||
|
||||
if (pmap == NULL)
|
||||
return;
|
||||
|
||||
pte = pmap_pte(pmap, va);
|
||||
#ifdef DEBUG
|
||||
/*
|
||||
|
@ -1392,7 +1482,7 @@ pmap_extract(pmap, va, pap)
|
|||
PMAP_DPRINTF(PDB_FOLLOW,
|
||||
("pmap_extract(%p, %lx) -> ", pmap, va));
|
||||
|
||||
if (pmap && pmap_ste_v(pmap, va)) {
|
||||
if (pmap_ste_v(pmap, va)) {
|
||||
pte = *(u_int *)pmap_pte(pmap, va);
|
||||
if (pte) {
|
||||
pa = (pte & PG_FRAME) | (va & ~PG_FRAME);
|
||||
|
@ -1552,7 +1642,7 @@ ok:
|
|||
* We call pmap_remove_entry to take care of invalidating
|
||||
* ST and Sysptmap entries.
|
||||
*/
|
||||
(void) pmap_extract(pmap, pv->pv_va, (paddr_t *)&kpa);
|
||||
(void) pmap_extract(pmap, pv->pv_va, &kpa);
|
||||
pmap_remove_mapping(pmap, pv->pv_va, PT_ENTRY_NULL,
|
||||
PRM_TFLUSH|PRM_CFLUSH);
|
||||
/*
|
||||
|
@ -1561,12 +1651,12 @@ ok:
|
|||
* that page back on the free list.
|
||||
*/
|
||||
for (pkpt = &kpt_used_list, kpt = *pkpt;
|
||||
kpt != (struct kpt_page *)0;
|
||||
kpt != NULL;
|
||||
pkpt = &kpt->kpt_next, kpt = *pkpt)
|
||||
if (kpt->kpt_pa == kpa)
|
||||
break;
|
||||
#ifdef DEBUG
|
||||
if (kpt == (struct kpt_page *)0)
|
||||
if (kpt == NULL)
|
||||
panic("pmap_collect: lost a KPT page");
|
||||
if (pmapdebug & (PDB_PTPAGE|PDB_COLLECT))
|
||||
printf("collect: %lx (%lx) to free list\n",
|
||||
|
@ -1990,6 +2080,11 @@ pmap_remove_mapping(pmap, va, pte, flags)
|
|||
PMAP_DPRINTF(PDB_REMOVE|PDB_SEGTAB,
|
||||
("remove: free stab %p\n",
|
||||
ptpmap->pm_stab));
|
||||
pmap_remove(pmap_kernel(),
|
||||
(vaddr_t)ptpmap->pm_stab,
|
||||
(vaddr_t)ptpmap->pm_stab + MAC_STSIZE);
|
||||
uvm_pagefree(PHYS_TO_VM_PAGE((paddr_t)
|
||||
ptpmap->pm_stpa));
|
||||
uvm_km_free_wakeup(st_map,
|
||||
(vaddr_t)ptpmap->pm_stab, MAC_STSIZE);
|
||||
ptpmap->pm_stab = Segtabzero;
|
||||
|
@ -2046,14 +2141,13 @@ pmap_testbit(pa, bit)
|
|||
pt_entry_t *pte;
|
||||
int s;
|
||||
|
||||
if (PAGE_IS_MANAGED(pa) == 0)
|
||||
return(FALSE);
|
||||
|
||||
pv = pa_to_pvh(pa);
|
||||
s = splvm();
|
||||
|
||||
/*
|
||||
* Check saved info first
|
||||
*/
|
||||
|
||||
if (*pa_to_attribute(pa) & bit) {
|
||||
splx(s);
|
||||
return(TRUE);
|
||||
|
@ -2063,6 +2157,7 @@ pmap_testbit(pa, bit)
|
|||
* Not found. Check current mappings, returning immediately if
|
||||
* found. Cache a hit to speed future lookups.
|
||||
*/
|
||||
|
||||
if (pv->pv_pmap != NULL) {
|
||||
for (; pv; pv = pv->pv_next) {
|
||||
pte = pmap_pte(pv->pv_pmap, pv->pv_va);
|
||||
|
@ -2100,61 +2195,47 @@ pmap_changebit(pa, set, mask)
|
|||
PMAP_DPRINTF(PDB_BITS,
|
||||
("pmap_changebit(%lx, %x, %x)\n", pa, set, mask));
|
||||
|
||||
if (PAGE_IS_MANAGED(pa) == 0)
|
||||
return;
|
||||
|
||||
pv = pa_to_pvh(pa);
|
||||
s = splvm();
|
||||
|
||||
/*
|
||||
* Clear saved attributes (modify, reference)
|
||||
*/
|
||||
|
||||
*pa_to_attribute(pa) &= mask;
|
||||
|
||||
/*
|
||||
* Loop over all current mappings setting/clearing as appropos
|
||||
* If setting RO do we need to clear the VAC?
|
||||
*/
|
||||
if (pv->pv_pmap != NULL) {
|
||||
#ifdef DEBUG
|
||||
int toflush = 0;
|
||||
#endif
|
||||
for (; pv; pv = pv->pv_next) {
|
||||
#ifdef DEBUG
|
||||
toflush |= (pv->pv_pmap == pmap_kernel()) ? 2 : 1;
|
||||
#endif
|
||||
va = pv->pv_va;
|
||||
|
||||
/*
|
||||
* XXX don't write protect pager mappings
|
||||
*/
|
||||
if (set == PG_RO) {
|
||||
if (va >= uvm.pager_sva && va < uvm.pager_eva)
|
||||
continue;
|
||||
}
|
||||
|
||||
pte = pmap_pte(pv->pv_pmap, va);
|
||||
npte = (*pte | set) & mask;
|
||||
if (*pte != npte) {
|
||||
if (pv->pv_pmap == NULL) {
|
||||
splx(s);
|
||||
return;
|
||||
}
|
||||
for (; pv; pv = pv->pv_next) {
|
||||
va = pv->pv_va;
|
||||
pte = pmap_pte(pv->pv_pmap, va);
|
||||
npte = (*pte | set) & mask;
|
||||
if (*pte != npte) {
|
||||
#if defined(M68040)
|
||||
/*
|
||||
* If we are changing caching status or
|
||||
* protection make sure the caches are
|
||||
* flushed (but only once).
|
||||
*/
|
||||
if (firstpage && (mmutype == MMU_68040) &&
|
||||
((set == PG_RO) ||
|
||||
(set & PG_CMASK) ||
|
||||
(mask & PG_CMASK) == 0)) {
|
||||
firstpage = FALSE;
|
||||
DCFP(pa);
|
||||
ICPP(pa);
|
||||
}
|
||||
#endif
|
||||
*pte = npte;
|
||||
if (active_pmap(pv->pv_pmap))
|
||||
TBIS(va);
|
||||
/*
|
||||
* If we are changing caching status or
|
||||
* protection make sure the caches are
|
||||
* flushed (but only once).
|
||||
*/
|
||||
if (firstpage && (mmutype == MMU_68040) &&
|
||||
((set == PG_RO) ||
|
||||
(set & PG_CMASK) ||
|
||||
(mask & PG_CMASK) == 0)) {
|
||||
firstpage = FALSE;
|
||||
DCFP(pa);
|
||||
ICPP(pa);
|
||||
}
|
||||
#endif
|
||||
*pte = npte;
|
||||
if (active_pmap(pv->pv_pmap))
|
||||
TBIS(va);
|
||||
}
|
||||
}
|
||||
splx(s);
|
||||
|
@ -2221,7 +2302,7 @@ pmap_enter_ptpage(pmap, va)
|
|||
if (*ste == SG_NV) {
|
||||
int ix;
|
||||
caddr_t addr;
|
||||
|
||||
|
||||
ix = bmtol2(pmap->pm_stfree);
|
||||
if (ix == -1)
|
||||
panic("enter: out of address space"); /* XXX */
|
||||
|
@ -2260,7 +2341,7 @@ pmap_enter_ptpage(pmap, va)
|
|||
struct kpt_page *kpt;
|
||||
|
||||
s = splvm();
|
||||
if ((kpt = kpt_free_list) == (struct kpt_page *)0) {
|
||||
if ((kpt = kpt_free_list) == NULL) {
|
||||
/*
|
||||
* No PT pages available.
|
||||
* Try once to free up unused ones.
|
||||
|
@ -2268,7 +2349,7 @@ pmap_enter_ptpage(pmap, va)
|
|||
PMAP_DPRINTF(PDB_COLLECT,
|
||||
("enter: no KPT pages, collecting...\n"));
|
||||
pmap_collect(pmap_kernel());
|
||||
if ((kpt = kpt_free_list) == (struct kpt_page *)0)
|
||||
if ((kpt = kpt_free_list) == NULL)
|
||||
panic("pmap_enter_ptpage: can't get KPT page");
|
||||
}
|
||||
kpt_free_list = kpt->kpt_next;
|
||||
|
@ -2276,8 +2357,8 @@ pmap_enter_ptpage(pmap, va)
|
|||
kpt_used_list = kpt;
|
||||
ptpa = kpt->kpt_pa;
|
||||
bzero((caddr_t)kpt->kpt_va, NBPG);
|
||||
pmap_enter(pmap, va, ptpa, VM_PROT_DEFAULT,
|
||||
VM_PROT_DEFAULT|PMAP_WIRED);
|
||||
pmap_enter(pmap, va, ptpa, VM_PROT_READ | VM_PROT_WRITE,
|
||||
VM_PROT_READ | VM_PROT_WRITE | PMAP_WIRED);
|
||||
pmap_update();
|
||||
#ifdef DEBUG
|
||||
if (pmapdebug & (PDB_ENTER|PDB_PTPAGE)) {
|
||||
|
|
Loading…
Reference in New Issue