From owner-svn-src-stable-8@FreeBSD.ORG Tue Nov 16 05:46:36 2010 Return-Path: Delivered-To: svn-src-stable-8@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4A219106566B; Tue, 16 Nov 2010 05:46:36 +0000 (UTC) (envelope-from alc@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 379158FC0C; Tue, 16 Nov 2010 05:46:36 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id oAG5ka82041158; Tue, 16 Nov 2010 05:46:36 GMT (envelope-from alc@svn.freebsd.org) Received: (from alc@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id oAG5kaS7041154; Tue, 16 Nov 2010 05:46:36 GMT (envelope-from alc@svn.freebsd.org) Message-Id: <201011160546.oAG5kaS7041154@svn.freebsd.org> From: Alan Cox Date: Tue, 16 Nov 2010 05:46:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r215373 - in stable/8/sys/i386: i386 include X-BeenThere: svn-src-stable-8@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for only the 8-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 Nov 2010 05:46:36 -0000 Author: alc Date: Tue Nov 16 05:46:35 2010 New Revision: 215373 URL: http://svn.freebsd.org/changeset/base/215373 Log: MFC r213455 Initialize KPTmap in locore so that vm86.c can call vtophys() (or really pmap_kextract()) before pmap_bootstrap() is called. Document the set of pmap functions that may be called before pmap_bootstrap() is called. Modified: stable/8/sys/i386/i386/locore.s stable/8/sys/i386/i386/pmap.c stable/8/sys/i386/include/pmap.h Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) stable/8/sys/dev/xen/xenpci/ (props changed) Modified: stable/8/sys/i386/i386/locore.s ============================================================================== --- stable/8/sys/i386/i386/locore.s Tue Nov 16 05:06:20 2010 (r215372) +++ stable/8/sys/i386/i386/locore.s Tue Nov 16 05:46:35 2010 (r215373) @@ -104,6 +104,9 @@ IdlePTD: .long 0 /* phys addr of kernel IdlePDPT: .long 0 /* phys addr of kernel PDPT */ #endif + .globl KPTmap +KPTmap: .long 0 /* address of kernel page tables */ + .globl KPTphys KPTphys: .long 0 /* phys addr of kernel page tables */ @@ -717,6 +720,8 @@ no_kernend: /* Allocate Kernel Page Tables */ ALLOCPAGES(NKPT) movl %esi,R(KPTphys) + addl $(KERNBASE-(KPTDI<<(PDRSHIFT-PAGE_SHIFT+PTESHIFT))),%esi + movl %esi,R(KPTmap) /* Allocate Page Table Directory */ #ifdef PAE @@ -780,6 +785,11 @@ no_kernend: shrl $PAGE_SHIFT,%ecx fillkptphys($PG_RW) +/* Map page table pages. */ + movl R(KPTphys),%eax + movl $NKPT,%ecx + fillkptphys($PG_RW) + /* Map page directory. */ #ifdef PAE movl R(IdlePDPT), %eax Modified: stable/8/sys/i386/i386/pmap.c ============================================================================== --- stable/8/sys/i386/i386/pmap.c Tue Nov 16 05:06:20 2010 (r215372) +++ stable/8/sys/i386/i386/pmap.c Tue Nov 16 05:46:35 2010 (r215373) @@ -243,7 +243,7 @@ struct sysmaps { caddr_t CADDR2; }; static struct sysmaps sysmaps_pcpu[MAXCPU]; -pt_entry_t *CMAP1 = 0, *KPTmap; +pt_entry_t *CMAP1 = 0; static pt_entry_t *CMAP3; static pd_entry_t *KPTD; caddr_t CADDR1 = 0, ptvmmap = 0; @@ -375,12 +375,11 @@ pmap_bootstrap(vm_paddr_t firstaddr) int i; /* - * XXX The calculation of virtual_avail is wrong. It's NKPT*PAGE_SIZE too - * large. It should instead be correctly calculated in locore.s and - * not based on 'first' (which is a physical address, not a virtual - * address, for the start of unused physical memory). The kernel - * page tables are NOT double mapped and thus should not be included - * in this calculation. + * Initialize the first available kernel virtual address. However, + * using "firstaddr" may waste a few pages of the kernel virtual + * address space, because locore may not have mapped every physical + * page that it allocated. Preferably, locore would provide a first + * unused virtual address in addition to "firstaddr". */ virtual_avail = (vm_offset_t) KERNBASE + firstaddr; virtual_avail = pmap_kmem_choose(virtual_avail); @@ -452,6 +451,10 @@ pmap_bootstrap(vm_paddr_t firstaddr) /* * KPTmap is used by pmap_kextract(). + * + * KPTmap is first initialized by locore. However, that initial + * KPTmap can only support NKPT page table pages. Here, a larger + * KPTmap is created that can support KVA_PAGES page table pages. */ SYSMAP(pt_entry_t *, KPTD, KPTmap, KVA_PAGES) @@ -1364,6 +1367,8 @@ pmap_extract_and_hold(pmap_t pmap, vm_of /* * Add a wired page to the kva. * Note: not SMP coherent. + * + * This function may be used before pmap_bootstrap() is called. */ PMAP_INLINE void pmap_kenter(vm_offset_t va, vm_paddr_t pa) @@ -1386,6 +1391,8 @@ pmap_kenter_attr(vm_offset_t va, vm_padd /* * Remove a page from the kernel pagetables. * Note: not SMP coherent. + * + * This function may be used before pmap_bootstrap() is called. */ PMAP_INLINE void pmap_kremove(vm_offset_t va) Modified: stable/8/sys/i386/include/pmap.h ============================================================================== --- stable/8/sys/i386/include/pmap.h Tue Nov 16 05:06:20 2010 (r215372) +++ stable/8/sys/i386/include/pmap.h Tue Nov 16 05:46:35 2010 (r215373) @@ -191,12 +191,21 @@ extern pdpt_entry_t *IdlePDPT; extern pd_entry_t *IdlePTD; /* physical address of "Idle" state directory */ /* - * virtual address to page table entry and - * to physical address. - * Note: these work recursively, thus vtopte of a pte will give - * the corresponding pde that in turn maps it. + * Translate a virtual address to the kernel virtual address of its page table + * entry (PTE). This can be used recursively. If the address of a PTE as + * previously returned by this macro is itself given as the argument, then the + * address of the page directory entry (PDE) that maps the PTE will be + * returned. + * + * This macro may be used before pmap_bootstrap() is called. */ #define vtopte(va) (PTmap + i386_btop(va)) + +/* + * Translate a virtual address to its physical address. + * + * This macro may be used before pmap_bootstrap() is called. + */ #define vtophys(va) pmap_kextract((vm_offset_t)(va)) #ifdef XEN @@ -272,14 +281,18 @@ pte_load_store_ma(pt_entry_t *ptep, pt_e * table pages, and not user page table pages, and (2) it provides access to * a kernel page table page after the corresponding virtual addresses have * been promoted to a 2/4MB page mapping. + * + * KPTmap is first initialized by locore to support just NPKT page table + * pages. Later, it is reinitialized by pmap_bootstrap() to allow for + * expansion of the kernel page table. */ extern pt_entry_t *KPTmap; /* - * Routine: pmap_kextract - * Function: - * Extract the physical page address associated - * kernel virtual address. + * Extract from the kernel page table the physical address that is mapped by + * the given virtual address "va". + * + * This function may be used before pmap_bootstrap() is called. */ static __inline vm_paddr_t pmap_kextract(vm_offset_t va) @@ -483,6 +496,11 @@ extern vm_offset_t virtual_end; #define pmap_page_get_memattr(m) ((vm_memattr_t)(m)->md.pat_mode) #define pmap_unmapbios(va, sz) pmap_unmapdev((va), (sz)) +/* + * Only the following functions or macros may be used before pmap_bootstrap() + * is called: pmap_kenter(), pmap_kextract(), pmap_kremove(), vtophys(), and + * vtopte(). + */ void pmap_bootstrap(vm_paddr_t); int pmap_cache_bits(int mode, boolean_t is_pde); int pmap_change_attr(vm_offset_t, vm_size_t, int);