Module Name: src Committed By: cegger Date: Sat Nov 7 07:32:53 UTC 2009
Modified Files: src/sys/arch/x86/x86: bus_space.c pmap.c Log Message: Implement pmap_kenter_pa(9) new flag argument in x86. Make x86 bus_space(9) using it to eliminate an extra TLB flush. Patch showed on tech-kern@ http://mail-index.netbsd.org/tech-kern/2009/11/04/msg006434.html Thanks to Martin Husemann for spotting copy&pasto errors in the original patch version. To generate a diff of this commit: cvs rdiff -u -r1.25 -r1.26 src/sys/arch/x86/x86/bus_space.c cvs rdiff -u -r1.95 -r1.96 src/sys/arch/x86/x86/pmap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/x86/x86/bus_space.c diff -u src/sys/arch/x86/x86/bus_space.c:1.25 src/sys/arch/x86/x86/bus_space.c:1.26 --- src/sys/arch/x86/x86/bus_space.c:1.25 Sat Nov 7 07:27:48 2009 +++ src/sys/arch/x86/x86/bus_space.c Sat Nov 7 07:32:53 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: bus_space.c,v 1.25 2009/11/07 07:27:48 cegger Exp $ */ +/* $NetBSD: bus_space.c,v 1.26 2009/11/07 07:32:53 cegger Exp $ */ /*- * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: bus_space.c,v 1.25 2009/11/07 07:27:48 cegger Exp $"); +__KERNEL_RCSID(0, "$NetBSD: bus_space.c,v 1.26 2009/11/07 07:32:53 cegger Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -293,11 +293,14 @@ { paddr_t pa, endpa; vaddr_t va, sva; - pt_entry_t *pte, xpte; + u_int pmapflags = 0; pa = x86_trunc_page(bpa); endpa = x86_round_page(bpa + size); + if (!cacheable) + pmapflags |= PMAP_NOCACHE; + #ifdef DIAGNOSTIC if (endpa != 0 && endpa <= pa) panic("x86_mem_add_mapping: overflow"); @@ -316,35 +319,15 @@ } *bshp = (bus_space_handle_t)(sva + (bpa & PGOFSET)); - va = sva; - xpte = 0; - for (; pa != endpa; pa += PAGE_SIZE, va += PAGE_SIZE) { - /* - * PG_N doesn't exist on 386's, so we assume that - * the mainboard has wired up device space non-cacheable - * on those machines. - * - * XXX should hand this bit to pmap_kenter_pa to - * save the extra invalidate! - */ + for (va = sva; pa != endpa; pa += PAGE_SIZE, va += PAGE_SIZE) { #ifdef XEN - pmap_kenter_ma(va, pa, VM_PROT_READ | VM_PROT_WRITE, 0); + pmap_kenter_ma(va, pa, VM_PROT_READ | VM_PROT_WRITE, pmapflags); #else - pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE, 0); + pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE, pmapflags); #endif /* XEN */ - - pte = kvtopte(va); - if (cacheable) - pmap_pte_clearbits(pte, PG_N); - else - pmap_pte_setbits(pte, PG_N); - xpte |= *pte; - } - kpreempt_disable(); - pmap_tlb_shootdown(pmap_kernel(), sva, sva + (endpa - pa), xpte); - pmap_tlb_shootwait(); - kpreempt_enable(); + } + pmap_update(pmap_kernel()); return 0; } Index: src/sys/arch/x86/x86/pmap.c diff -u src/sys/arch/x86/x86/pmap.c:1.95 src/sys/arch/x86/x86/pmap.c:1.96 --- src/sys/arch/x86/x86/pmap.c:1.95 Sat Nov 7 07:27:49 2009 +++ src/sys/arch/x86/x86/pmap.c Sat Nov 7 07:32:53 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: pmap.c,v 1.95 2009/11/07 07:27:49 cegger Exp $ */ +/* $NetBSD: pmap.c,v 1.96 2009/11/07 07:32:53 cegger Exp $ */ /* * Copyright (c) 2007 Manuel Bouyer. @@ -149,7 +149,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.95 2009/11/07 07:27:49 cegger Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.96 2009/11/07 07:32:53 cegger Exp $"); #include "opt_user_ldt.h" #include "opt_lockdebug.h" @@ -1030,6 +1030,8 @@ #endif /* DOM0OPS */ npte = pmap_pa2pte(pa); npte |= protection_codes[prot] | PG_k | PG_V | pmap_pg_g; + if (flags & PMAP_NOCACHE) + npte |= PG_N; opte = pmap_pte_testset(pte, npte); /* zap! */ #if defined(DIAGNOSTIC) /* XXX For now... */ @@ -1125,6 +1127,9 @@ npte = ma | ((prot & VM_PROT_WRITE) ? PG_RW : PG_RO) | PG_V | PG_k; + if (flags & PMAP_NOCACHE) + npte |= PG_N; + #ifndef XEN if ((cpu_feature & CPUID_NOX) && !(prot & VM_PROT_EXECUTE)) npte |= PG_NX;