Wed Aug 11 13:46:28 2010 UTC ()
Support XIP; look up "device" vm_physseg for managed pages.  Initialize
vm_physseg MD part.


(uebayasi)
diff -r1.60.2.3 -r1.60.2.4 src/sys/arch/powerpc/ibm4xx/pmap.c

cvs diff -r1.60.2.3 -r1.60.2.4 src/sys/arch/powerpc/ibm4xx/pmap.c (expand / switch to unified diff)

--- src/sys/arch/powerpc/ibm4xx/pmap.c 2010/04/30 14:39:42 1.60.2.3
+++ src/sys/arch/powerpc/ibm4xx/pmap.c 2010/08/11 13:46:28 1.60.2.4
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: pmap.c,v 1.60.2.3 2010/04/30 14:39:42 uebayasi Exp $ */ 1/* $NetBSD: pmap.c,v 1.60.2.4 2010/08/11 13:46:28 uebayasi Exp $ */
2 2
3/* 3/*
4 * Copyright 2001 Wasabi Systems, Inc. 4 * Copyright 2001 Wasabi Systems, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc. 7 * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -57,27 +57,29 @@ @@ -57,27 +57,29 @@
57 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR 57 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
58 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 58 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
59 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 59 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
60 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 60 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
61 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 61 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
62 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 62 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
63 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 63 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
64 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 64 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
65 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 65 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
66 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 66 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
67 */ 67 */
68 68
69#include <sys/cdefs.h> 69#include <sys/cdefs.h>
70__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.60.2.3 2010/04/30 14:39:42 uebayasi Exp $"); 70__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.60.2.4 2010/08/11 13:46:28 uebayasi Exp $");
 71
 72#include "opt_xip.h"
71 73
72#include <sys/param.h> 74#include <sys/param.h>
73#include <sys/malloc.h> 75#include <sys/malloc.h>
74#include <sys/proc.h> 76#include <sys/proc.h>
75#include <sys/queue.h> 77#include <sys/queue.h>
76#include <sys/systm.h> 78#include <sys/systm.h>
77#include <sys/pool.h> 79#include <sys/pool.h>
78#include <sys/device.h> 80#include <sys/device.h>
79 81
80#include <uvm/uvm.h> 82#include <uvm/uvm.h>
81 83
82#include <machine/cpu.h> 84#include <machine/cpu.h>
83#include <machine/pcb.h> 85#include <machine/pcb.h>
@@ -182,41 +184,51 @@ static inline volatile u_int *pte_find(s @@ -182,41 +184,51 @@ static inline volatile u_int *pte_find(s
182static inline int pte_enter(struct pmap *, vaddr_t, u_int); 184static inline int pte_enter(struct pmap *, vaddr_t, u_int);
183 185
184static inline int pmap_enter_pv(struct pmap *, vaddr_t, paddr_t, int); 186static inline int pmap_enter_pv(struct pmap *, vaddr_t, paddr_t, int);
185static void pmap_remove_pv(struct pmap *, vaddr_t, paddr_t); 187static void pmap_remove_pv(struct pmap *, vaddr_t, paddr_t);
186 188
187static int ppc4xx_tlb_size_mask(size_t, int *, int *); 189static int ppc4xx_tlb_size_mask(size_t, int *, int *);
188 190
189 191
190inline struct pv_entry * 192inline struct pv_entry *
191pa_to_pv(paddr_t pa) 193pa_to_pv(paddr_t pa)
192{ 194{
193 int bank, pg; 195 int bank, pg;
194 196
 197#ifdef XIP
 198 bank = vm_physseg_find_device(atop(pa), &pg);
 199 if (bank != -1)
 200 return &VM_PHYSDEV_PTR(bank)->pmseg.pvent[pg];
 201#endif
195 bank = vm_physseg_find(atop(pa), &pg); 202 bank = vm_physseg_find(atop(pa), &pg);
196 if (bank == -1) 203 if (bank != -1)
197 return NULL; 204 return &VM_PHYSMEM_PTR(bank)->pmseg.pvent[pg];
198 return &VM_PHYSMEM_PTR(bank)->pmseg.pvent[pg]; 205 return NULL;
199} 206}
200 207
201static inline char * 208static inline char *
202pa_to_attr(paddr_t pa) 209pa_to_attr(paddr_t pa)
203{ 210{
204 int bank, pg; 211 int bank, pg;
205 212
 213#ifdef XIP
 214 bank = vm_physseg_find_device(atop(pa), &pg);
 215 if (bank != -1)
 216 return &VM_PHYSDEV_PTR(bank)->pmseg.attrs[pg];
 217#endif
206 bank = vm_physseg_find(atop(pa), &pg); 218 bank = vm_physseg_find(atop(pa), &pg);
207 if (bank == -1) 219 if (bank != -1)
208 return NULL; 220 return &VM_PHYSMEM_PTR(bank)->pmseg.attrs[pg];
209 return &VM_PHYSMEM_PTR(bank)->pmseg.attrs[pg]; 221 return NULL;
210} 222}
211 223
212/* 224/*
213 * Insert PTE into page table. 225 * Insert PTE into page table.
214 */ 226 */
215int 227int
216pte_enter(struct pmap *pm, vaddr_t va, u_int pte) 228pte_enter(struct pmap *pm, vaddr_t va, u_int pte)
217{ 229{
218 int seg = STIDX(va); 230 int seg = STIDX(va);
219 int ptn = PTIDX(va); 231 int ptn = PTIDX(va);
220 u_int oldpte; 232 u_int oldpte;
221 233
222 if (!pm->pm_ptbl[seg]) { 234 if (!pm->pm_ptbl[seg]) {
@@ -477,26 +489,56 @@ pmap_init(void) @@ -477,26 +489,56 @@ pmap_init(void)
477 VM_PHYSMEM_PTR(bank)->pmseg.attrs = attr; 489 VM_PHYSMEM_PTR(bank)->pmseg.attrs = attr;
478 pv += sz; 490 pv += sz;
479 attr += sz; 491 attr += sz;
480 } 492 }
481 493
482 pmap_initialized = 1; 494 pmap_initialized = 1;
483 splx(s); 495 splx(s);
484 496
485 /* Setup a pool for additional pvlist structures */ 497 /* Setup a pool for additional pvlist structures */
486 pool_init(&pv_pool, sizeof(struct pv_entry), 0, 0, 0, "pv_entry", NULL, 498 pool_init(&pv_pool, sizeof(struct pv_entry), 0, 0, 0, "pv_entry", NULL,
487 IPL_VM); 499 IPL_VM);
488} 500}
489 501
 502void
 503pmap_physseg_init(struct vm_physseg *seg)
 504{
 505 size_t npages;
 506 vsize_t sz;
 507 struct pv_entry *pv;
 508 char *attr;
 509
 510 npages = seg->end - seg->start + 1;
 511 sz = (vsize_t)((sizeof(struct pv_entry) + 1) * npages);
 512 sz = round_page(sz);
 513 pv = (void *)uvm_km_alloc(kernel_map, sz, 0, UVM_KMF_WIRED | UVM_KMF_ZERO);
 514 attr = (void *)(pv + npages);
 515
 516 seg->pmseg.pvent = pv;
 517 seg->pmseg.attrs = attr;
 518}
 519
 520void
 521pmap_physseg_fini(struct vm_physseg *seg)
 522{
 523 size_t npages;
 524 vsize_t sz;
 525
 526 npages = seg->end - seg->start + 1;
 527 sz = (vsize_t)((sizeof(struct pv_entry) + 1) * npages);
 528 sz = round_page(sz);
 529 uvm_km_free(kernel_map, (vaddr_t)seg->pmseg.pvent, sz, UVM_KMF_WIRED);
 530}
 531
490/* 532/*
491 * How much virtual space is available to the kernel? 533 * How much virtual space is available to the kernel?
492 */ 534 */
493void 535void
494pmap_virtual_space(vaddr_t *start, vaddr_t *end) 536pmap_virtual_space(vaddr_t *start, vaddr_t *end)
495{ 537{
496 538
497#if 0 539#if 0
498 /* 540 /*
499 * Reserve one segment for kernel virtual memory 541 * Reserve one segment for kernel virtual memory
500 */ 542 */
501 *start = (vaddr_t)(KERNEL_SR << ADDR_SR_SHFT); 543 *start = (vaddr_t)(KERNEL_SR << ADDR_SR_SHFT);
502 *end = *start + SEGMENT_LENGTH; 544 *end = *start + SEGMENT_LENGTH;