2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
29 * Mach Operating System
30 * Copyright (c) 1990,1991,1992 The University of Utah and
31 * the Center for Software Science (CSS).
32 * Copyright (c) 1991,1987 Carnegie Mellon University.
33 * All rights reserved.
35 * Permission to use, copy, modify and distribute this software and its
36 * documentation is hereby granted, provided that both the copyright
37 * notice and this permission notice appear in all copies of the
38 * software, derivative works or modified versions, and any portions
39 * thereof, and that both notices appear in supporting documentation,
40 * and that all advertising materials mentioning features or use of
41 * this software display the following acknowledgement: ``This product
42 * includes software developed by the Center for Software Science at
43 * the University of Utah.''
45 * CARNEGIE MELLON, THE UNIVERSITY OF UTAH AND CSS ALLOW FREE USE OF
46 * THIS SOFTWARE IN ITS "AS IS" CONDITION, AND DISCLAIM ANY LIABILITY
47 * OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF
50 * CSS requests users of this software to return to css-dist@cs.utah.edu any
51 * improvements that they make and grant CSS redistribution rights.
53 * Carnegie Mellon requests users of this software to return to
54 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
55 * School of Computer Science
56 * Carnegie Mellon University
57 * Pittsburgh PA 15213-3890
58 * any improvements or extensions that they make and grant Carnegie Mellon
59 * the rights to redistribute these changes.
61 * Utah $Hdr: pmap.c 1.28 92/06/23$
62 * Author: Mike Hibler, Bob Wheeler, University of Utah CSS, 10/90
66 * Manages physical address maps for powerpc.
68 * In addition to hardware address maps, this
69 * module is called upon to provide software-use-only
70 * maps which may or may not be stored in the same
71 * form as hardware maps. These pseudo-maps are
72 * used to store intermediate results from copy
73 * operations to and from address spaces.
75 * Since the information managed by this module is
76 * also stored by the logical address mapping module,
77 * this module may throw away valid virtual-to-physical
78 * mappings at almost any time. However, invalidations
79 * of virtual-to-physical mappings must be done as
82 * In order to cope with hardware architectures which
83 * make virtual-to-physical map invalidates expensive,
84 * this module may delay invalidate or reduced protection
85 * operations until such time as they are actually
86 * necessary. This module is given full information to
87 * when physical maps must be made correct.
91 #include <zone_debug.h>
94 #include <mach_kgdb.h>
95 #include <mach_vm_debug.h>
96 #include <db_machine_commands.h>
98 #include <kern/thread.h>
99 #include <kern/simple_lock.h>
100 #include <mach/vm_attributes.h>
101 #include <mach/vm_param.h>
102 #include <kern/spl.h>
104 #include <kern/misc_protos.h>
105 #include <ppc/misc_protos.h>
106 #include <ppc/proc_reg.h>
109 #include <vm/vm_map.h>
110 #include <vm/vm_page.h>
112 #include <ppc/pmap.h>
113 #include <ppc/pmap_internals.h>
115 #include <ppc/mappings.h>
117 #include <ppc/new_screen.h>
118 #include <ppc/Firmware.h>
119 #include <ppc/savearea.h>
120 #include <ppc/exception.h>
121 #include <ddb/db_output.h>
123 #if DB_MACHINE_COMMANDS
124 /* optionally enable traces of pmap operations in post-mortem trace table */
125 /* #define PMAP_LOWTRACE 1 */
126 #define PMAP_LOWTRACE 0
127 #else /* DB_MACHINE_COMMANDS */
128 /* Can not trace even if we wanted to */
129 #define PMAP_LOWTRACE 0
130 #endif /* DB_MACHINE_COMMANDS */
134 #if PERFTIMES && DEBUG
135 #define debugLog2(a, b, c) dbgLog2(a, b, c)
137 #define debugLog2(a, b, c)
140 extern unsigned int avail_remaining
;
141 extern unsigned int mappingdeb0
;
142 extern struct Saveanchor saveanchor
; /* Aliged savearea anchor */
143 extern int real_ncpus
; /* Number of actual CPUs */
144 unsigned int debugbackpocket
; /* (TEST/DEBUG) */
146 vm_offset_t avail_next
;
147 vm_offset_t first_free_virt
;
148 int current_free_region
; /* Used in pmap_next_page */
151 void pmap_activate(pmap_t pmap
, thread_t th
, int which_cpu
);
152 void pmap_deactivate(pmap_t pmap
, thread_t th
, int which_cpu
);
153 void copy_to_phys(vm_offset_t sva
, vm_offset_t dpa
, int bytecount
);
156 int pmap_list_resident_pages(pmap_t pmap
, vm_offset_t
*listp
, int space
);
160 #define PDB_USER 0x01 /* exported functions */
161 #define PDB_MAPPING 0x02 /* low-level mapping routines */
162 #define PDB_ENTER 0x04 /* pmap_enter specifics */
163 #define PDB_COPY 0x08 /* copy page debugging */
164 #define PDB_ZERO 0x10 /* zero page debugging */
165 #define PDB_WIRED 0x20 /* things concerning wired entries */
166 #define PDB_PTEG 0x40 /* PTEG overflows */
167 #define PDB_LOCK 0x100 /* locks */
168 #define PDB_IO 0x200 /* Improper use of WIMG_IO checks - PCI machines */
173 /* NOTE: kernel_pmap_store must be in V=R storage and aligned!!!!!!!!!!!!!! */
175 extern struct pmap kernel_pmap_store
;
176 pmap_t kernel_pmap
; /* Pointer to kernel pmap and anchor for in-use pmaps */
177 pmap_t cursor_pmap
; /* Pointer to last pmap allocated or previous if removed from in-use list */
178 struct zone
*pmap_zone
; /* zone of pmap structures */
179 boolean_t pmap_initialized
= FALSE
;
182 * Physical-to-virtual translations are handled by inverted page table
183 * structures, phys_tables. Multiple mappings of a single page are handled
184 * by linking the affected mapping structures. We initialise one region
185 * for phys_tables of the physical memory we know about, but more may be
186 * added as it is discovered (eg. by drivers).
188 struct phys_entry
*phys_table
; /* For debugging */
190 lock_t pmap_system_lock
;
192 decl_simple_lock_data(,tlb_system_lock
)
195 * free pmap list. caches the first free_pmap_max pmaps that are freed up
197 int free_pmap_max
= 32;
199 pmap_t free_pmap_list
;
200 decl_simple_lock_data(,free_pmap_lock
)
203 * Function to get index into phys_table for a given physical address
206 struct phys_entry
*pmap_find_physentry(vm_offset_t pa
)
209 struct phys_entry
*entry
;
211 for (i
= pmap_mem_regions_count
-1; i
>= 0; i
--) {
212 if (pa
< pmap_mem_regions
[i
].start
)
214 if (pa
>= pmap_mem_regions
[i
].end
)
217 entry
= &pmap_mem_regions
[i
].phys_table
[(pa
- pmap_mem_regions
[i
].start
) >> PPC_PGSHIFT
];
218 __asm__
volatile("dcbt 0,%0" : : "r" (entry
)); /* We will use this in a little bit */
221 kprintf("DEBUG : pmap_find_physentry 0x%08x out of range\n",pa
);
227 * pmap_add_physical_memory(vm_offset_t spa, vm_offset_t epa,
228 * boolean_t available, unsigned int attr)
229 * Allocate some extra physentries for the physical addresses given,
230 * specifying some default attribute that on the powerpc specifies
231 * the default cachability for any mappings using these addresses
232 * If the memory is marked as available, it is added to the general
233 * VM pool, otherwise it is not (it is reserved for card IO etc).
235 kern_return_t
pmap_add_physical_memory(vm_offset_t spa
, vm_offset_t epa
,
236 boolean_t available
, unsigned int attr
)
241 /* Only map whole pages */
243 panic("Forget it! You can't map no more memory, you greedy puke!\n");
245 spa
= trunc_page(spa
);
246 epa
= round_page(epa
);
248 /* First check that the region doesn't already exist */
251 for (i
= 0; i
< pmap_mem_regions_count
; i
++) {
252 /* If we're below the next region, then no conflict */
253 if (epa
< pmap_mem_regions
[i
].start
)
255 if (spa
< pmap_mem_regions
[i
].end
) {
257 kprintf("pmap_add_physical_memory(0x%08x,0x%08x,0x%08x) - memory already present\n",spa
,epa
,attr
);
259 return KERN_NO_SPACE
;
264 kprintf("pmap_add_physical_memory; region insert spot: %d out of %d\n", i
, pmap_mem_regions_count
); /* (TEST/DEBUG) */
267 /* Check that we've got enough space for another region */
268 if (pmap_mem_regions_count
== PMAP_MEM_REGION_MAX
)
269 return KERN_RESOURCE_SHORTAGE
;
271 /* Once here, i points to the mem_region above ours in physical mem */
273 /* allocate a new phys_table for this new region */
275 kprintf("pmap_add_physical_memory; kalloc\n"); /* (TEST/DEBUG) */
278 phys_table
= (struct phys_entry
*)
279 kalloc(sizeof(struct phys_entry
) * atop(epa
-spa
));
281 kprintf("pmap_add_physical_memory; new phys_table: %08X\n", phys_table
); /* (TEST/DEBUG) */
284 /* Initialise the new phys_table entries */
285 for (j
= 0; j
< atop(epa
-spa
); j
++) {
287 phys_table
[j
].phys_link
= MAPPING_NULL
;
289 mapping_phys_init(&phys_table
[j
], spa
+(j
*PAGE_SIZE
), attr
); /* Initialize the hardware specific portions */
294 /* Move all the phys_table entries up some to make room in
297 for (j
= pmap_mem_regions_count
; j
> i
; j
--)
298 pmap_mem_regions
[j
] = pmap_mem_regions
[j
-1];
300 /* Insert a new entry with some memory to back it */
302 pmap_mem_regions
[i
].start
= spa
;
303 pmap_mem_regions
[i
].end
= epa
;
304 pmap_mem_regions
[i
].phys_table
= phys_table
;
306 pmap_mem_regions_count
++;
310 for(i
=0; i
<pmap_mem_regions_count
; i
++) { /* (TEST/DEBUG) */
311 kprintf("region %d: %08X %08X %08X\n", i
, pmap_mem_regions
[i
].start
,
312 pmap_mem_regions
[i
].end
, pmap_mem_regions
[i
].phys_table
); /* (TEST/DEBUG) */
317 kprintf("warning : pmap_add_physical_mem() "
318 "available not yet supported\n");
325 * pmap_map(va, spa, epa, prot)
326 * is called during boot to map memory in the kernel's address map.
327 * A virtual address range starting at "va" is mapped to the physical
328 * address range "spa" to "epa" with machine independent protection
331 * "va", "spa", and "epa" are byte addresses and must be on machine
332 * independent page boundaries.
334 * Pages with a contiguous virtual address range, the same protection, and attributes.
335 * therefore, we map it with a single block.
351 debugLog2(40, va
, spa
); /* Log pmap_map call */
353 pmap_map_block(kernel_pmap
, va
, spa
, epa
- spa
, prot
, PTE_WIMG_DEFAULT
, blkPerm
); /* Set up a permanent block mapped area */
355 debugLog2(41, epa
, prot
); /* Log pmap_map call */
361 * pmap_map_bd(va, spa, epa, prot)
362 * Back-door routine for mapping kernel VM at initialisation.
363 * Used for mapping memory outside the known physical memory
364 * space, with caching disabled. Designed for use by device probes.
366 * A virtual address range starting at "va" is mapped to the physical
367 * address range "spa" to "epa" with machine independent protection
370 * "va", "spa", and "epa" are byte addresses and must be on machine
371 * independent page boundaries.
373 * WARNING: The current version of memcpy() can use the dcbz instruction
374 * on the destination addresses. This will cause an alignment exception
375 * and consequent overhead if the destination is caching-disabled. So
376 * avoid memcpy()ing into the memory mapped by this function.
378 * also, many other pmap_ routines will misbehave if you try and change
379 * protections or remove these mappings, they are designed to be permanent.
381 * These areas will be added to the autogen list, if possible. Existing translations
382 * are overridden and their mapping stuctures are released. This takes place in
383 * the autogen_map function.
386 * this routine is called only during system initialization when only
387 * one processor is active, so no need to take locks...
396 register struct mapping
*mp
;
397 register struct phys_entry
*pp
;
405 debugLog2(42, va
, epa
); /* Log pmap_map_bd call */
407 pmap_map_block(kernel_pmap
, va
, spa
, epa
- spa
, prot
, PTE_WIMG_IO
, blkPerm
); /* Set up autogen area */
409 debugLog2(43, epa
, prot
); /* Log pmap_map_bd exit */
415 * Bootstrap the system enough to run with virtual memory.
416 * Map the kernel's code and data, and allocate the system page table.
417 * Called with mapping done by BATs. Page_size must already be set.
420 * mem_size: Total memory present
421 * first_avail: First virtual address available
422 * first_phys_avail: First physical address available
425 pmap_bootstrap(unsigned int mem_size
, vm_offset_t
*first_avail
, vm_offset_t
*first_phys_avail
, unsigned int kmapsize
)
427 register struct mapping
*mp
;
430 int i
, num
, j
, rsize
, mapsize
, vmpagesz
, vmmapsz
;
432 vm_offset_t first_used_addr
;
435 *first_avail
= round_page(*first_avail
);
438 kprintf("first_avail=%08X; first_phys_avail=%08X; avail_remaining=%d\n",
439 *first_avail
, *first_phys_avail
, avail_remaining
);
442 assert(PAGE_SIZE
== PPC_PGBYTES
);
445 * Initialize kernel pmap
447 kernel_pmap
= &kernel_pmap_store
;
448 cursor_pmap
= &kernel_pmap_store
;
450 lock_init(&pmap_system_lock
,
451 FALSE
, /* NOT a sleep lock */
455 simple_lock_init(&kernel_pmap
->lock
, ETAP_VM_PMAP_KERNEL
);
457 kernel_pmap
->pmap_link
.next
= (queue_t
)kernel_pmap
; /* Set up anchor forward */
458 kernel_pmap
->pmap_link
.prev
= (queue_t
)kernel_pmap
; /* Set up anchor reverse */
459 kernel_pmap
->ref_count
= 1;
460 kernel_pmap
->space
= PPC_SID_KERNEL
;
461 kernel_pmap
->pmapvr
= 0; /* Virtual = Real */
462 kernel_pmap
->bmaps
= 0; /* No block pages just yet */
463 for(i
=0; i
< 128; i
++) { /* Clear usage slots */
464 kernel_pmap
->pmapUsage
[i
] = 0;
466 for(i
=0; i
< 16; i
++) { /* Initialize for laughs */
467 kernel_pmap
->pmapSegs
[i
] = SEG_REG_PROT
| (i
<< 20) | PPC_SID_KERNEL
;
471 * Allocate: (from first_avail up)
472 * Aligned to its own size:
473 * hash table (for mem size 2**x, allocate 2**(x-10) entries)
474 * mapping table (same size and immediatly following hash table)
476 /* hash_table_size must be a power of 2, recommended sizes are
477 * taken from PPC601 User Manual, table 6-19. We take the next
478 * highest size if mem_size is not a power of two.
479 * TODO NMGS make this configurable at boot time.
482 num
= sizeof(pte_t
) * (mem_size
>> 10);
484 for (hash_table_size
= 64 * 1024; /* minimum size = 64Kbytes */
485 hash_table_size
< num
;
486 hash_table_size
*= 2)
489 if (num
> (sizeof(pte_t
) * 524288))
490 hash_table_size
= hash_table_size
/2; /* reduce by half above 512MB */
492 /* Scale to within any physical memory layout constraints */
494 num
= atop(mem_size
); /* num now holds mem_size in pages */
496 /* size of all structures that we're going to allocate */
499 (InitialSaveBloks
* PAGE_SIZE
) + /* Allow space for the initial context saveareas */
500 ((InitialSaveBloks
/ 2) * PAGE_SIZE
) + /* For backpocket saveareas */
501 hash_table_size
+ /* For hash table */
502 hash_table_size
+ /* For PTEG allocation table */
503 (num
* sizeof(struct phys_entry
)) /* For the physical entries */
506 mapsize
= size
= round_page(size
); /* Get size of area to map that we just calculated */
507 mapsize
= mapsize
+ kmapsize
; /* Account for the kernel text size */
509 vmpagesz
= round_page(num
* sizeof(struct vm_page
)); /* Allow for all vm_pages needed to map physical mem */
510 vmmapsz
= round_page((num
/ 8) * sizeof(struct vm_map_entry
)); /* Allow for vm_maps */
512 mapsize
= mapsize
+ vmpagesz
+ vmmapsz
; /* Add the VM system estimates into the grand total */
514 mapsize
= mapsize
+ (4 * 1024 * 1024); /* Allow for 4 meg of extra mappings */
515 mapsize
= ((mapsize
/ PAGE_SIZE
) + MAPPERBLOK
- 1) / MAPPERBLOK
; /* Get number of blocks of mappings we need */
516 mapsize
= mapsize
+ ((mapsize
+ MAPPERBLOK
- 1) / MAPPERBLOK
); /* Account for the mappings themselves */
519 kprintf("pmap_bootstrap: initial vm_pages = %08X\n", vmpagesz
);
520 kprintf("pmap_bootstrap: initial vm_maps = %08X\n", vmmapsz
);
521 kprintf("pmap_bootstrap: size before mappings = %08X\n", size
);
522 kprintf("pmap_bootstrap: kernel map size = %08X\n", kmapsize
);
523 kprintf("pmap_bootstrap: mapping blocks rqrd = %08X\n", mapsize
);
526 size
= size
+ (mapsize
* PAGE_SIZE
); /* Get the true size we need */
528 /* hash table must be aligned to its size */
530 addr
= (*first_avail
+
531 (hash_table_size
-1)) & ~(hash_table_size
-1);
533 if (addr
+ size
> pmap_mem_regions
[0].end
) {
534 hash_table_size
/= 2;
538 /* If we have had to shrink hash table to too small, panic */
539 if (hash_table_size
== 32 * 1024)
540 panic("cannot lay out pmap memory map correctly");
544 kprintf("hash table size=%08X, total size of area=%08X, addr=%08X\n",
545 hash_table_size
, size
, addr
);
547 if (round_page(*first_phys_avail
) < trunc_page(addr
)) {
548 /* We are stepping over at least one page here, so
549 * add this region to the free regions so that it can
550 * be allocated by pmap_steal
552 free_regions
[free_regions_count
].start
= round_page(*first_phys_avail
);
553 free_regions
[free_regions_count
].end
= trunc_page(addr
);
555 avail_remaining
+= (free_regions
[free_regions_count
].end
-
556 free_regions
[free_regions_count
].start
) /
559 kprintf("ADDED FREE REGION from 0x%08x to 0x%08x, avail_remaining = %d\n",
560 free_regions
[free_regions_count
].start
,free_regions
[free_regions_count
].end
,
563 free_regions_count
++;
566 /* Zero everything - this also invalidates the hash table entries */
567 bzero((char *)addr
, size
);
569 /* Set up some pointers to our new structures */
571 /* from here, addr points to the next free address */
573 first_used_addr
= addr
; /* remember where we started */
575 /* Set up hash table address and dma buffer address, keeping
576 * alignment. These mappings are all 1-1, so dma_r == dma_v
578 * If hash_table_size == dma_buffer_alignment, then put hash_table
579 * first, since dma_buffer_size may be smaller than alignment, but
580 * hash table alignment==hash_table_size.
582 hash_table_base
= addr
;
584 addr
+= hash_table_size
;
585 addr
+= hash_table_size
; /* Add another for the PTEG Control Area */
586 assert((hash_table_base
& (hash_table_size
-1)) == 0);
588 pcaptr
= (PCA
*)(hash_table_base
+hash_table_size
); /* Point to the PCA table */
589 mapCtl
.mapcflush
.pcaptr
= pcaptr
;
591 for(i
=0; i
< (hash_table_size
/64) ; i
++) { /* For all of PTEG control areas: */
592 pcaptr
[i
].flgs
.PCAalflgs
.PCAfree
=0xFF; /* Mark all slots free */
593 pcaptr
[i
].flgs
.PCAalflgs
.PCAsteal
=0x01; /* Initialize steal position */
596 savearea_init(&addr
); /* Initialize the savearea chains and data */
598 /* phys_table is static to help debugging,
599 * this variable is no longer actually used
600 * outside of this scope
603 phys_table
= (struct phys_entry
*) addr
;
606 kprintf("hash_table_base =%08X\n", hash_table_base
);
607 kprintf("phys_table =%08X\n", phys_table
);
608 kprintf("pmap_mem_regions_count =%08X\n", pmap_mem_regions_count
);
611 for (i
= 0; i
< pmap_mem_regions_count
; i
++) {
613 pmap_mem_regions
[i
].phys_table
= phys_table
;
614 rsize
= (pmap_mem_regions
[i
].end
- (unsigned int)pmap_mem_regions
[i
].start
)/PAGE_SIZE
;
617 kprintf("Initializing physical table for region %d\n", i
);
618 kprintf(" table=%08X, size=%08X, start=%08X, end=%08X\n",
619 phys_table
, rsize
, pmap_mem_regions
[i
].start
,
620 (unsigned int)pmap_mem_regions
[i
].end
);
623 for (j
= 0; j
< rsize
; j
++) {
624 phys_table
[j
].phys_link
= MAPPING_NULL
;
625 mapping_phys_init(&phys_table
[j
], (unsigned int)pmap_mem_regions
[i
].start
+(j
*PAGE_SIZE
),
626 PTE_WIMG_DEFAULT
); /* Initializes hw specific storage attributes */
628 phys_table
= phys_table
+
629 atop(pmap_mem_regions
[i
].end
- pmap_mem_regions
[i
].start
);
632 /* restore phys_table for debug */
633 phys_table
= (struct phys_entry
*) addr
;
635 addr
+= sizeof(struct phys_entry
) * num
;
637 simple_lock_init(&tlb_system_lock
, ETAP_VM_PMAP_TLB
);
639 /* Initialise the registers necessary for supporting the hashtable */
641 kprintf("*** hash_table_init: base=%08X, size=%08X\n", hash_table_base
, hash_table_size
);
644 hash_table_init(hash_table_base
, hash_table_size
);
647 * Remaining space is for mapping entries. Tell the initializer routine that
648 * the mapping system can't release this block because it's permanently assigned
651 mapping_init(); /* Initialize the mapping tables */
653 for(i
= addr
; i
< first_used_addr
+ size
; i
+= PAGE_SIZE
) { /* Add initial mapping blocks */
654 mapping_free_init(i
, 1, 0); /* Pass block address and say that this one is not releasable */
656 mapCtl
.mapcmin
= MAPPERBLOK
; /* Make sure we only adjust one at a time */
660 kprintf("mapping kernel memory from 0x%08x to 0x%08x, to address 0x%08x\n",
661 first_used_addr
, round_page(first_used_addr
+size
),
665 /* Map V=R the page tables */
666 pmap_map(first_used_addr
, first_used_addr
,
667 round_page(first_used_addr
+size
), VM_PROT_READ
| VM_PROT_WRITE
);
671 for(i
=first_used_addr
; i
< round_page(first_used_addr
+size
); i
+=PAGE_SIZE
) { /* Step through all these mappings */
672 if(i
!= (j
= kvtophys(i
))) { /* Verify that the mapping was made V=R */
673 kprintf("*** V=R mapping failed to verify: V=%08X; R=%08X\n", i
, j
);
678 *first_avail
= round_page(first_used_addr
+ size
);
679 first_free_virt
= round_page(first_used_addr
+ size
);
681 /* All the rest of memory is free - add it to the free
682 * regions so that it can be allocated by pmap_steal
684 free_regions
[free_regions_count
].start
= *first_avail
;
685 free_regions
[free_regions_count
].end
= pmap_mem_regions
[0].end
;
687 avail_remaining
+= (free_regions
[free_regions_count
].end
-
688 free_regions
[free_regions_count
].start
) /
692 kprintf("ADDED FREE REGION from 0x%08x to 0x%08x, avail_remaining = %d\n",
693 free_regions
[free_regions_count
].start
,free_regions
[free_regions_count
].end
,
697 free_regions_count
++;
699 current_free_region
= 0;
701 avail_next
= free_regions
[current_free_region
].start
;
704 kprintf("Number of free regions=%d\n",free_regions_count
); /* (TEST/DEBUG) */
705 kprintf("Current free region=%d\n",current_free_region
); /* (TEST/DEBUG) */
706 for(i
=0;i
<free_regions_count
; i
++) { /* (TEST/DEBUG) */
707 kprintf("Free region %3d - from %08X to %08X\n", i
, free_regions
[i
].start
,
708 free_regions
[i
].end
); /* (TEST/DEBUG) */
710 for (i
= 0; i
< pmap_mem_regions_count
; i
++) { /* (TEST/DEBUG) */
711 kprintf("PMAP region %3d - from %08X to %08X; phys=%08X\n", i
, /* (TEST/DEBUG) */
712 pmap_mem_regions
[i
].start
, /* (TEST/DEBUG) */
713 pmap_mem_regions
[i
].end
, /* (TEST/DEBUG) */
714 pmap_mem_regions
[i
].phys_table
); /* (TEST/DEBUG) */
721 * pmap_init(spa, epa)
722 * finishes the initialization of the pmap module.
723 * This procedure is called from vm_mem_init() in vm/vm_init.c
724 * to initialize any remaining data structures that the pmap module
725 * needs to map virtual memory (VM is already ON).
727 * Note that the pmap needs to be sized and aligned to
728 * a power of two. This is because it is used both in virtual and
729 * real so it can't span a page boundary.
737 pmap_zone
= zinit(pmapSize
, 400 * pmapSize
, 4096, "pmap");
739 zone_debug_disable(pmap_zone
); /* Can't debug this one 'cause it messes with size and alignment */
740 #endif /* ZONE_DEBUG */
742 pmap_initialized
= TRUE
;
745 * Initialize list of freed up pmaps
747 free_pmap_list
= 0; /* Set that there are no free pmaps */
749 simple_lock_init(&free_pmap_lock
, ETAP_VM_PMAP_CACHE
);
752 unsigned int pmap_free_pages(void)
754 return avail_remaining
;
757 boolean_t
pmap_next_page(vm_offset_t
*addrp
)
759 /* Non optimal, but only used for virtual memory startup.
760 * Allocate memory from a table of free physical addresses
761 * If there are no more free entries, too bad. We have two
762 * tables to look through, free_regions[] which holds free
763 * regions from inside pmap_mem_regions[0], and the others...
764 * pmap_mem_regions[1..]
767 /* current_free_region indicates the next free entry,
768 * if it's less than free_regions_count, then we're still
769 * in free_regions, otherwise we're in pmap_mem_regions
772 if (current_free_region
>= free_regions_count
) {
773 /* We're into the pmap_mem_regions, handle this
774 * separately to free_regions
777 int current_pmap_mem_region
= current_free_region
-
778 free_regions_count
+ 1;
779 if (current_pmap_mem_region
> pmap_mem_regions_count
)
782 avail_next
+= PAGE_SIZE
;
784 if (avail_next
>= pmap_mem_regions
[current_pmap_mem_region
].end
) {
785 current_free_region
++;
786 current_pmap_mem_region
++;
787 avail_next
= pmap_mem_regions
[current_pmap_mem_region
].start
;
789 kprintf("pmap_next_page : next region start=0x%08x\n",avail_next
);
795 /* We're in the free_regions, allocate next page and increment
800 avail_next
+= PAGE_SIZE
;
803 if (avail_next
>= free_regions
[current_free_region
].end
) {
804 current_free_region
++;
805 if (current_free_region
< free_regions_count
)
806 avail_next
= free_regions
[current_free_region
].start
;
808 avail_next
= pmap_mem_regions
[current_free_region
-
809 free_regions_count
+ 1].start
;
811 kprintf("pmap_next_page : next region start=0x%08x\n",avail_next
);
817 void pmap_virtual_space(
821 *startp
= round_page(first_free_virt
);
822 *endp
= VM_MAX_KERNEL_ADDRESS
;
828 * Create and return a physical map.
830 * If the size specified for the map is zero, the map is an actual physical
831 * map, and may be referenced by the hardware.
833 * A pmap is either in the free list or in the in-use list. The only use
834 * of the in-use list (aside from debugging) is to handle the VSID wrap situation.
835 * Whenever a new pmap is allocated (i.e., not recovered from the free list). The
836 * in-use list is matched until a hole in the VSID sequence is found. (Note
837 * that the in-use pmaps are queued in VSID sequence order.) This is all done
838 * while free_pmap_lock is held.
840 * If the size specified is non-zero, the map will be used in software
841 * only, and is bounded by that size.
844 pmap_create(vm_size_t size
)
846 pmap_t pmap
, ckpmap
, fore
, aft
;
849 unsigned int currSID
;
852 dbgTrace(0xF1D00001, size
, 0); /* (TEST/DEBUG) */
856 if (pmdebug
& PDB_USER
)
857 kprintf("pmap_create(size=%x)%c", size
, size
? '\n' : ' ');
861 * A software use-only map doesn't even need a pmap structure.
867 * If there is a pmap in the pmap free list, reuse it.
868 * Note that we use free_pmap_list for all chaining of pmaps, both to
869 * the free list and the in use chain (anchored from kernel_pmap).
872 simple_lock(&free_pmap_lock
);
874 if(free_pmap_list
) { /* Any free? */
875 pmap
= free_pmap_list
; /* Yes, allocate it */
876 free_pmap_list
= (pmap_t
)pmap
->bmaps
; /* Dequeue this one (we chain free ones through bmaps) */
880 simple_unlock(&free_pmap_lock
); /* Unlock just in case */
883 pmap
= (pmap_t
) zalloc(pmap_zone
); /* Get one */
884 if (pmap
== PMAP_NULL
) return(PMAP_NULL
); /* Handle out-of-memory condition */
886 bzero((char *)pmap
, pmapSize
); /* Clean up the pmap */
889 simple_lock(&free_pmap_lock
); /* Lock it back up */
891 ckpmap
= cursor_pmap
; /* Get starting point for free ID search */
892 currSID
= ckpmap
->spaceNum
; /* Get the actual space ID number */
894 while(1) { /* Keep trying until something happens */
896 currSID
= (currSID
+ 1) & SID_MAX
; /* Get the next in the sequence */
897 ckpmap
= (pmap_t
)ckpmap
->pmap_link
.next
; /* On to the next in-use pmap */
899 if(ckpmap
->spaceNum
!= currSID
) break; /* If we are out of sequence, this is free */
901 if(ckpmap
== cursor_pmap
) { /* See if we have 2^20 already allocated */
902 panic("pmap_create: Maximum number (2^20) active address spaces reached\n"); /* Die pig dog */
906 pmap
->space
= (currSID
* incrVSID
) & SID_MAX
; /* Calculate the actual VSID */
907 pmap
->spaceNum
= currSID
; /* Set the space ID number */
910 * Now we link into the chain just before the out of sequence guy.
913 fore
= (pmap_t
)ckpmap
->pmap_link
.prev
; /* Get the current's previous */
914 pmap
->pmap_link
.next
= (queue_t
)ckpmap
; /* My next points to the current */
915 fore
->pmap_link
.next
= (queue_t
)pmap
; /* Current's previous's next points to me */
916 pmap
->pmap_link
.prev
= (queue_t
)fore
; /* My prev points to what the current pointed to */
917 ckpmap
->pmap_link
.prev
= (queue_t
)pmap
; /* Current's prev points to me */
919 simple_lock_init(&pmap
->lock
, ETAP_VM_PMAP
);
920 pmap
->pmapvr
= (unsigned int)pmap
^ (unsigned int)pmap_extract(kernel_pmap
, (vm_offset_t
)pmap
); /* Get physical pointer to the pmap and make mask */
923 pmap
->stats
.resident_count
= 0;
924 pmap
->stats
.wired_count
= 0;
925 pmap
->bmaps
= 0; /* Clear block map pointer to 0 */
926 pmap
->vflags
= 0; /* Mark all alternates invalid for now */
927 for(i
=0; i
< 128; i
++) { /* Clean out usage slots */
928 pmap
->pmapUsage
[i
] = 0;
930 for(i
=0; i
< 16; i
++) { /* Initialize for laughs */
931 pmap
->pmapSegs
[i
] = SEG_REG_PROT
| (i
<< 20) | pmap
->space
;
935 dbgTrace(0xF1D00002, (unsigned int)pmap
, (unsigned int)pmap
->space
); /* (TEST/DEBUG) */
939 if (pmdebug
& PDB_USER
)
940 kprintf("-> %x, space id = %d\n", pmap
, pmap
->space
);
943 simple_unlock(&free_pmap_lock
);
951 * Gives up a reference to the specified pmap. When the reference count
952 * reaches zero the pmap structure is added to the pmap free list.
954 * Should only be called if the map contains no valid mappings.
957 pmap_destroy(pmap_t pmap
)
964 dbgTrace(0xF1D00003, (unsigned int)pmap
, 0); /* (TEST/DEBUG) */
968 if (pmdebug
& PDB_USER
)
969 kprintf("pmap_destroy(pmap=%x)\n", pmap
);
972 if (pmap
== PMAP_NULL
)
975 ref_count
=hw_atomic_sub(&pmap
->ref_count
, 1); /* Back off the count */
976 if(ref_count
>0) return; /* Still more users, leave now... */
978 if(ref_count
< 0) /* Did we go too far? */
979 panic("pmap_destroy(): ref_count < 0");
982 if(pmap
->stats
.resident_count
!= 0)
983 panic("PMAP_DESTROY: pmap not empty");
985 if(pmap
->stats
.resident_count
!= 0) {
986 pmap_remove(pmap
, 0, 0xFFFFF000);
991 * Add the pmap to the pmap free list.
996 * Add the pmap to the pmap free list.
998 simple_lock(&free_pmap_lock
);
1000 if (free_pmap_count
<= free_pmap_max
) { /* Do we have enough spares? */
1002 pmap
->bmaps
= (struct blokmap
*)free_pmap_list
; /* Queue in front */
1003 free_pmap_list
= pmap
;
1005 simple_unlock(&free_pmap_lock
);
1008 if(cursor_pmap
== pmap
) cursor_pmap
= (pmap_t
)pmap
->pmap_link
.prev
; /* If we are releasing the cursor, back up */
1009 fore
= (pmap_t
)pmap
->pmap_link
.prev
;
1010 aft
= (pmap_t
)pmap
->pmap_link
.next
;
1011 fore
->pmap_link
.next
= pmap
->pmap_link
.next
; /* My previous's next is my next */
1012 aft
->pmap_link
.prev
= pmap
->pmap_link
.prev
; /* My next's previous is my previous */
1013 simple_unlock(&free_pmap_lock
);
1014 zfree(pmap_zone
, (vm_offset_t
) pmap
);
1020 * pmap_reference(pmap)
1021 * gains a reference to the specified pmap.
1024 pmap_reference(pmap_t pmap
)
1029 dbgTrace(0xF1D00004, (unsigned int)pmap
, 0); /* (TEST/DEBUG) */
1033 if (pmdebug
& PDB_USER
)
1034 kprintf("pmap_reference(pmap=%x)\n", pmap
);
1037 if (pmap
!= PMAP_NULL
) hw_atomic_add(&pmap
->ref_count
, 1); /* Bump the count */
1041 * pmap_remove_some_phys
1043 * Removes mappings of the associated page from the specified pmap
1046 void pmap_remove_some_phys(
1050 register struct phys_entry
*pp
;
1051 register struct mapping
*mp
, *mpv
;
1054 if (pmap
== PMAP_NULL
) return; /* Do nothing if no pmap */
1056 pp
= pmap_find_physentry(pa
); /* Get the physent for this page */
1057 if (pp
== PHYS_NULL
) return; /* Leave if not in physical RAM */
1059 if (pmap
->vflags
& pmapVMhost
)
1062 mapping_purge_pmap(pp
, pmap
);
1064 return; /* Leave... */
1068 * pmap_remove(pmap, s, e)
1069 * unmaps all virtual addresses v in the virtual address
1070 * range determined by [s, e) and pmap.
1071 * s and e must be on machine independent page boundaries and
1072 * s must be less than or equal to e.
1074 * Note that pmap_remove does not remove any mappings in nested pmaps. We just
1075 * skip those segments.
1084 struct mapping
*mp
, *blm
;
1088 dbgTrace(0xF1D00005, (unsigned int)pmap
, sva
|((eva
-sva
)>>12)); /* (TEST/DEBUG) */
1092 if (pmdebug
& PDB_USER
)
1093 kprintf("pmap_remove(pmap=%x, sva=%x, eva=%x)\n",
1097 if (pmap
== PMAP_NULL
)
1100 /* It is just possible that eva might have wrapped around to zero,
1101 * and sometimes we get asked to liberate something of size zero
1102 * even though it's dumb (eg. after zero length read_overwrites)
1106 /* If these are not page aligned the loop might not terminate */
1107 assert((sva
== trunc_page(sva
)) && (eva
== trunc_page(eva
)));
1109 /* We liberate addresses from high to low, since the stack grows
1110 * down. This means that we won't need to test addresses below
1111 * the limit of stack growth
1114 debugLog2(44, sva
, eva
); /* Log pmap_map call */
1116 sva
= trunc_page(sva
); /* Make it clean */
1117 lpage
= trunc_page(eva
) - PAGE_SIZE
; /* Point to the last page contained in the range */
1120 * Here we will remove all of the block mappings that overlap this range.
1121 * hw_rem_blk removes one mapping in the range and returns. If it returns
1122 * 0, there are no blocks in the range.
1125 while(mp
= (mapping
*)hw_rem_blk(pmap
, sva
, lpage
)) { /* Keep going until no more */
1126 if((unsigned int)mp
& 1) { /* Make sure we don't unmap a permanent one */
1127 blm
= (struct mapping
*)hw_cpv((mapping
*)((unsigned int)mp
& 0xFFFFFFFC)); /* Get virtual address */
1128 panic("mapping_remove: attempt to unmap a permanent mapping - pmap = %08X, va = %08X, mapping = %08X\n",
1131 if (!((unsigned int)mp
& 2))
1132 mapping_free(hw_cpv(mp
)); /* Release it */
1134 while (pmap
->stats
.resident_count
&& (eva
> sva
)) {
1136 eva
-= PAGE_SIZE
; /* Back up a page */
1139 if((0x00008000 >> (sva
>> 28)) & pmap
->vflags
)
1140 panic("pmap_remove: attempt to remove nested vaddr; pmap = %08X, vaddr = %08X\n", pmap
, sva
); /* (TEST/DEBUG) panic */
1142 if(!(pmap
->pmapUsage
[(eva
>> pmapUsageShft
) & pmapUsageMask
])) { /* See if this chunk has anything in it */
1143 eva
= eva
& (-pmapUsageSize
); /* Back up into the previous slot */
1144 continue; /* Check the next... */
1146 mapping_remove(pmap
, eva
); /* Remove the mapping for this address */
1149 debugLog2(45, 0, 0); /* Log pmap_map call */
1157 * Lower the permission for all mappings to a given page.
1164 register struct phys_entry
*pp
;
1169 dbgTrace(0xF1D00006, (unsigned int)pa
, (unsigned int)prot
); /* (TEST/DEBUG) */
1173 if (pmdebug
& PDB_USER
)
1174 kprintf("pmap_page_protect(pa=%x, prot=%x)\n", pa
, prot
);
1177 debugLog2(46, pa
, prot
); /* Log pmap_page_protect call */
1181 case VM_PROT_READ
|VM_PROT_EXECUTE
:
1191 pp
= pmap_find_physentry(pa
); /* Get the physent for this page */
1192 if (pp
== PHYS_NULL
) return; /* Leave if not in physical RAM */
1194 if (remove
) { /* If the protection was set to none, we'll remove all mappings */
1195 mapping_purge(pp
); /* Get rid of them all */
1197 debugLog2(47, 0, 0); /* Log pmap_map call */
1198 return; /* Leave... */
1201 /* When we get here, it means that we are to change the protection for a
1205 mapping_protect_phys(pp
, prot
, 0); /* Change protection of all mappings to page. */
1207 debugLog2(47, 1, 0); /* Log pmap_map call */
1211 * pmap_protect(pmap, s, e, prot)
1212 * changes the protection on all virtual addresses v in the
1213 * virtual address range determined by [s, e] and pmap to prot.
1214 * s and e must be on machine independent page boundaries and
1215 * s must be less than or equal to e.
1217 * Note that any requests to change the protection of a nested pmap are
1218 * ignored. Those changes MUST be done by calling this with the correct pmap.
1227 register struct phys_entry
*pp
;
1228 register struct mapping
*mp
, *mpv
;
1231 dbgTrace(0xF1D00008, (unsigned int)pmap
, (unsigned int)(sva
|((eva
-sva
)>>12))); /* (TEST/DEBUG) */
1235 if (pmdebug
& PDB_USER
)
1236 kprintf("pmap_protect(pmap=%x, sva=%x, eva=%x, prot=%x)\n", pmap
, sva
, eva
, prot
);
1241 if (pmap
== PMAP_NULL
) return; /* Do nothing if no pmap */
1243 debugLog2(48, sva
, eva
); /* Log pmap_map call */
1245 if (prot
== VM_PROT_NONE
) { /* Should we kill the address range?? */
1246 pmap_remove(pmap
, sva
, eva
); /* Yeah, dump 'em */
1248 debugLog2(49, prot
, 0); /* Log pmap_map call */
1250 return; /* Leave... */
1253 sva
= trunc_page(sva
); /* Start up a page boundary */
1255 while(sva
< eva
) { /* Step through */
1257 if(!(pmap
->pmapUsage
[(sva
>> pmapUsageShft
) & pmapUsageMask
])) { /* See if this chunk has anything in it */
1258 sva
= (sva
+ pmapUsageSize
) &(-pmapUsageSize
); /* Jump up into the next slot if nothing here */
1259 if(!sva
) break; /* We tried to wrap, kill loop... */
1260 continue; /* Check the next... */
1264 if((0x00008000 >> (sva
>> 28)) & pmap
->vflags
)
1265 panic("pmap_protect: attempt to protect nested vaddr; pmap = %08X, vaddr = %08X\n", pmap
, sva
); /* (TEST/DEBUG) panic */
1268 mapping_protect(pmap
, sva
, prot
); /* Change the protection on the page */
1269 sva
+= PAGE_SIZE
; /* On to the next page */
1272 debugLog2(49, prot
, 1); /* Log pmap_map call */
1273 return; /* Leave... */
1281 * Create a translation for the virtual address (virt) to the physical
1282 * address (phys) in the pmap with the protection requested. If the
1283 * translation is wired then we can not allow a full page fault, i.e.,
1284 * the mapping control block is not eligible to be stolen in a low memory
1287 * NB: This is the only routine which MAY NOT lazy-evaluate
1288 * or lose information. That is, this routine must actually
1289 * insert this page into the given map NOW.
1292 pmap_enter(pmap_t pmap
, vm_offset_t va
, vm_offset_t pa
, vm_prot_t prot
,
1293 unsigned int flags
, boolean_t wired
)
1297 struct phys_entry
*pp
;
1301 dbgTrace(0xF1D00009, (unsigned int)pmap
, (unsigned int)va
); /* (TEST/DEBUG) */
1302 dbgTrace(0xF1D04009, (unsigned int)pa
, (unsigned int)prot
); /* (TEST/DEBUG) */
1305 if (pmap
== PMAP_NULL
) return; /* If they gave us no pmap, just leave... */
1307 debugLog2(50, va
, pa
); /* Log pmap_map call */
1309 pp
= pmap_find_physentry(pa
); /* Get the physent for this physical page */
1311 if((0x00008000 >> (va
>> 28)) & pmap
->vflags
)
1312 panic("pmap_enter: attempt to map into nested vaddr; pmap = %08X, vaddr = %08X\n", pmap
, va
); /* (TEST/DEBUG) panic */
1314 spl
=splhigh(); /* Have to disallow interrupts between the
1315 time we possibly clear a mapping and the time
1316 we get it remapped again. An I/O SLIH could
1317 try to drive an IOR using the page before
1318 we get it mapped (Dude! This was a tough
1321 mapping_remove(pmap
, va
); /* Remove any other mapping at this address */
1323 if(flags
& VM_WIMG_USE_DEFAULT
) {
1325 /* Set attr to the phys default */
1326 memattr
= ((pp
->pte1
&0x00000078) >> 3);
1328 memattr
= PTE_WIMG_UNCACHED_COHERENT_GUARDED
;
1331 memattr
= flags
& VM_WIMG_MASK
;
1335 /* Make the address mapping */
1336 mp
=mapping_make(pmap
, pp
, va
, pa
, prot
, memattr
, 0);
1338 splx(spl
); /* I'm not busy no more - come what may */
1340 debugLog2(51, prot
, 0); /* Log pmap_map call */
1343 if (pmdebug
& (PDB_USER
|PDB_ENTER
))
1344 kprintf("leaving pmap_enter\n");
1350 * pmap_extract(pmap, va)
1351 * returns the physical address corrsponding to the
1352 * virtual address specified by pmap and va if the
1353 * virtual address is mapped and 0 if it is not.
1355 vm_offset_t
pmap_extract(pmap_t pmap
, vm_offset_t va
) {
1358 register struct mapping
*mp
, *mpv
;
1359 register vm_offset_t pa
;
1365 dbgTrace(0xF1D0000B, (unsigned int)pmap
, (unsigned int)va
); /* (TEST/DEBUG) */
1368 if (pmdebug
& PDB_USER
)
1369 kprintf("pmap_extract(pmap=%x, va=%x)\n", pmap
, va
);
1372 seg
= va
>> 28; /* Isolate segment */
1373 if((0x00008000 >> seg
) & pmap
->vflags
) actpmap
= pmap
->pmapPmaps
[seg
]; /* Set nested pmap if there is one */
1374 else actpmap
= pmap
; /* Otherwise use the one passed in */
1376 pa
= (vm_offset_t
) 0; /* Clear this to 0 */
1378 debugLog2(52, actpmap
->space
, va
); /* Log pmap_map call */
1380 spl
= splhigh(); /* We can't allow any loss of control here */
1382 if(mp
=hw_lock_phys_vir(actpmap
->space
, va
)) { /* Find the mapping for this vaddr and lock physent */
1383 if((unsigned int)mp
&1) { /* Did the lock on the phys entry time out? */
1384 panic("pmap_extract: timeout obtaining lock on physical entry\n"); /* Scream bloody murder! */
1385 splx(spl
); /* Interruptions are cool now */
1389 mpv
= hw_cpv(mp
); /* Get virtual address of mapping */
1390 pa
= (vm_offset_t
)((mpv
->PTEr
& -PAGE_SIZE
) | ((unsigned int)va
& (PAGE_SIZE
-1))); /* Build the physical address */
1391 if(mpv
->physent
) hw_unlock_bit((unsigned int *)&mpv
->physent
->phys_link
, PHYS_LOCK
); /* Unlock the physical entry */
1392 splx(spl
); /* Interruptions are cool now */
1394 debugLog2(53, pa
, 0); /* Log pmap_map call */
1396 return pa
; /* Return the physical address... */
1399 pa
= hw_cvp_blk(pmap
, va
); /* Try to convert odd-sized page (returns 0 if not found) */
1400 /* Note no nested pmaps here */
1401 splx(spl
); /* Restore 'rupts */
1402 debugLog2(53, pa
, 0); /* Log pmap_map call */
1403 return pa
; /* Return physical address or 0 */
1407 * pmap_attribute_cache_sync
1408 * Handle the machine attribute calls which involve sync the prcessor
1412 pmap_attribute_cache_sync(address
, size
, attribute
, value
)
1413 vm_offset_t address
;
1415 vm_machine_attribute_t attribute
;
1416 vm_machine_attribute_val_t
* value
;
1419 switch (*value
) { /* What type was that again? */
1420 case MATTR_VAL_CACHE_SYNC
: /* It is sync I+D caches */
1421 sync_cache(address
, PAGE_SIZE
); /* Sync up dem caches */
1422 break; /* Done with this one here... */
1424 case MATTR_VAL_CACHE_FLUSH
: /* It is flush from all caches */
1425 flush_dcache(address
, PAGE_SIZE
, TRUE
); /* Flush out the data cache */
1426 invalidate_icache(address
,
1427 PAGE_SIZE
, TRUE
); /* Flush out the instruction cache */
1428 break; /* Done with this one here... */
1430 case MATTR_VAL_DCACHE_FLUSH
: /* It is flush from data cache(s) */
1431 flush_dcache(address
, PAGE_SIZE
, TRUE
); /* Flush out the data cache */
1432 break; /* Done with this one here... */
1434 case MATTR_VAL_ICACHE_FLUSH
: /* It is flush from instr cache(s) */
1435 invalidate_icache(address
,
1436 PAGE_SIZE
, TRUE
); /* Flush out the instruction cache */
1437 break; /* Done with this one here... */
1441 return KERN_SUCCESS
;;
1448 * Set/Get special memory attributes; Set is not implemented.
1450 * Note: 'VAL_GET_INFO' is used to return info about a page.
1451 * If less than 1 page is specified, return the physical page
1452 * mapping and a count of the number of mappings to that page.
1453 * If more than one page is specified, return the number
1454 * of resident pages and the number of shared (more than
1455 * one mapping) pages in the range;
1459 pmap_attribute(pmap
, address
, size
, attribute
, value
)
1461 vm_offset_t address
;
1463 vm_machine_attribute_t attribute
;
1464 vm_machine_attribute_val_t
* value
;
1467 vm_offset_t sva
, eva
;
1470 register struct mapping
*mp
, *mpv
;
1471 register struct phys_entry
*pp
;
1475 if (attribute
!= MATTR_CACHE
)
1476 return KERN_INVALID_ARGUMENT
;
1478 /* We can't get the caching attribute for more than one page
1481 if ((*value
== MATTR_VAL_GET
) &&
1482 (trunc_page(address
) != trunc_page(address
+size
-1)))
1483 return KERN_INVALID_ARGUMENT
;
1485 if (pmap
== PMAP_NULL
)
1486 return KERN_SUCCESS
;
1488 sva
= trunc_page(address
);
1489 eva
= round_page(address
+ size
);
1492 debugLog2(54, address
, attribute
); /* Log pmap_map call */
1495 case MATTR_VAL_CACHE_SYNC
: /* sync I+D caches */
1496 case MATTR_VAL_CACHE_FLUSH
: /* flush from all caches */
1497 case MATTR_VAL_DCACHE_FLUSH
: /* flush from data cache(s) */
1498 case MATTR_VAL_ICACHE_FLUSH
: /* flush from instr cache(s) */
1499 sva
= trunc_page(sva
);
1503 seg
= sva
>> 28; /* Isolate segment */
1504 if((0x00008000 >> seg
) & pmap
->vflags
) actpmap
= pmap
->pmapPmaps
[seg
]; /* Set nested pmap if there is one */
1505 else actpmap
= pmap
; /* Otherwise use the one passed in */
1508 * Note: the following should work ok with nested pmaps because there are not overlayed mappings
1510 if(!(actpmap
->pmapUsage
[(sva
>> pmapUsageShft
) & pmapUsageMask
])) { /* See if this chunk has anything in it */
1511 sva
= (sva
+ pmapUsageSize
) & (-pmapUsageSize
); /* Jump up into the next slot if nothing here */
1512 if(!sva
) break; /* We tried to wrap, kill loop... */
1513 continue; /* Check the next... */
1516 if(!(mp
= hw_lock_phys_vir(actpmap
->space
, sva
))) { /* Find the mapping for this vaddr and lock physent */
1517 sva
+= PAGE_SIZE
; /* Point to the next page */
1518 continue; /* Skip if the page is not mapped... */
1521 if((unsigned int)mp
&1) { /* Did the lock on the phys entry time out? */
1522 panic("pmap_attribute: timeout obtaining lock on physical entry\n"); /* Scream bloody murder! */
1526 mpv
= hw_cpv(mp
); /* Get virtual address of mapping */
1527 if((unsigned int)mpv
->physent
) { /* Is there a physical entry? */
1528 pa
= (vm_offset_t
)mpv
->physent
->pte1
& -PAGE_SIZE
; /* Yes, get the physical address from there */
1531 pa
= (vm_offset_t
)(mpv
->PTEr
& PAGE_SIZE
); /* Otherwise from the mapping */
1534 switch (*value
) { /* What type was that again? */
1535 case MATTR_VAL_CACHE_SYNC
: /* It is sync I+D caches */
1536 sync_cache(pa
, PAGE_SIZE
); /* Sync up dem caches */
1537 break; /* Done with this one here... */
1539 case MATTR_VAL_CACHE_FLUSH
: /* It is flush from all caches */
1540 flush_dcache(pa
, PAGE_SIZE
, TRUE
); /* Flush out the data cache */
1541 invalidate_icache(pa
, PAGE_SIZE
, TRUE
); /* Flush out the instruction cache */
1542 break; /* Done with this one here... */
1544 case MATTR_VAL_DCACHE_FLUSH
: /* It is flush from data cache(s) */
1545 flush_dcache(pa
, PAGE_SIZE
, TRUE
); /* Flush out the data cache */
1546 break; /* Done with this one here... */
1548 case MATTR_VAL_ICACHE_FLUSH
: /* It is flush from instr cache(s) */
1549 invalidate_icache(pa
, PAGE_SIZE
, TRUE
); /* Flush out the instruction cache */
1550 break; /* Done with this one here... */
1552 if(mpv
->physent
) hw_unlock_bit((unsigned int *)&mpv
->physent
->phys_link
, PHYS_LOCK
); /* Unlock the physical entry if it exists*/
1554 sva
+= PAGE_SIZE
; /* Point to the next page */
1559 case MATTR_VAL_GET_INFO
: /* Get info */
1561 s
= splhigh(); /* Lock 'em out */
1563 if (size
<= PAGE_SIZE
) { /* Do they want just one page */
1564 seg
= sva
>> 28; /* Isolate segment */
1565 if((0x00008000 >> seg
) & pmap
->vflags
) actpmap
= pmap
->pmapPmaps
[seg
]; /* Set nested pmap if there is one */
1566 else actpmap
= pmap
; /* Otherwise use the one passed in */
1567 if(!(mp
= hw_lock_phys_vir(actpmap
->space
, sva
))) { /* Find the mapping for this vaddr and lock physent */
1568 *value
= 0; /* Return nothing if no mapping */
1571 if((unsigned int)mp
&1) { /* Did the lock on the phys entry time out? */
1572 panic("pmap_attribute: timeout obtaining lock on physical entry\n"); /* Scream bloody murder! */
1574 mpv
= hw_cpv(mp
); /* Get virtual address of mapping */
1575 if(pp
= mpv
->physent
) { /* Check for a physical entry */
1576 total
= 0; /* Clear the count */
1577 for (mpv
= (mapping
*)hw_cpv((mapping
*)((unsigned int)pp
->phys_link
& ~PHYS_FLAGS
)); mpv
!= NULL
; mpv
= hw_cpv(mp
->next
)) total
++; /* Count the mapping */
1578 *value
= (vm_machine_attribute_val_t
) ((pp
->pte1
& -PAGE_SIZE
) | total
); /* Pass back the physical address and the count of mappings */
1579 hw_unlock_bit((unsigned int *)&pp
->phys_link
, PHYS_LOCK
); /* Clear the physical entry lock */
1581 else { /* This is the case for an I/O mapped area */
1582 *value
= (vm_machine_attribute_val_t
) ((mpv
->PTEr
& -PAGE_SIZE
) | 1); /* Pass back the physical address and the count of mappings */
1589 seg
= sva
>> 28; /* Isolate segment */
1590 if((0x00008000 >> seg
) & pmap
->vflags
) actpmap
= pmap
->pmapPmaps
[seg
]; /* Set nested pmap if there is one */
1591 else actpmap
= pmap
; /* Otherwise use the one passed in */
1593 if(!(actpmap
->pmapUsage
[(sva
>> pmapUsageShft
) & pmapUsageMask
])) { /* See if this chunk has anything in it */
1594 sva
= (sva
+ pmapUsageSize
) & (-pmapUsageSize
); /* Jump up into the next slot if nothing here */
1595 if(!sva
) break; /* We tried to wrap, kill loop... */
1596 continue; /* Check the next... */
1598 if(mp
= hw_lock_phys_vir(actpmap
->space
, sva
)) { /* Find the mapping for this vaddr and lock physent */
1599 if((unsigned int)mp
&1) { /* Did the lock on the phys entry time out? */
1600 panic("pmap_attribute: timeout obtaining lock on physical entry\n"); /* Scream bloody murder! */
1603 mpv
= hw_cpv(mp
); /* Get virtual address of mapping */
1604 total
+= 65536 + (mpv
->physent
&& ((mapping
*)((unsigned int)mpv
->physent
->phys_link
& -32))->next
); /* Count the "resident" and shared pages */
1605 hw_unlock_bit((unsigned int *)&mpv
->physent
->phys_link
, PHYS_LOCK
); /* Clear the physical entry lock */
1614 case MATTR_VAL_GET
: /* return current value */
1615 case MATTR_VAL_OFF
: /* turn attribute off */
1616 case MATTR_VAL_ON
: /* turn attribute on */
1618 ret
= KERN_INVALID_ARGUMENT
;
1622 debugLog2(55, 0, 0); /* Log pmap_map call */
1628 * pmap_sync_caches_phys(vm_offset_t pa)
1630 * Invalidates all of the instruction cache on a physical page and
1631 * pushes any dirty data from the data cache for the same physical page
1634 void pmap_sync_caches_phys(vm_offset_t pa
) {
1638 s
= splhigh(); /* No interruptions here */
1639 sync_cache(trunc_page(pa
), PAGE_SIZE
); /* Sync up dem caches */
1640 splx(s
); /* Allow interruptions */
1647 * Garbage collects the physical map system for pages that are no longer used.
1648 * It isn't implemented or needed or wanted.
1651 pmap_collect(pmap_t pmap
)
1657 * Routine: pmap_activate
1659 * Binds the given physical map to the given
1660 * processor, and returns a hardware map description.
1661 * It isn't implemented or needed or wanted.
1673 * It isn't implemented or needed or wanted.
1690 * are implemented in movc.s, these
1691 * are just wrappers to help debugging
1694 extern void pmap_zero_page_assembler(vm_offset_t p
);
1695 extern void pmap_copy_page_assembler(vm_offset_t src
, vm_offset_t dst
);
1698 * pmap_zero_page(pa)
1700 * pmap_zero_page zeros the specified (machine independent) page pa.
1706 register struct mapping
*mp
;
1707 register struct phys_entry
*pp
;
1709 if (pmdebug
& (PDB_USER
|PDB_ZERO
))
1710 kprintf("pmap_zero_page(pa=%x)\n", p
);
1713 * XXX can these happen?
1715 if (pmap_find_physentry(p
) == PHYS_NULL
)
1716 panic("zero_page: physaddr out of range");
1718 pmap_zero_page_assembler(p
);
1722 * pmap_copy_page(src, dst)
1724 * pmap_copy_page copies the specified (machine independent)
1725 * page from physical address src to physical address dst.
1727 * We need to invalidate the cache for address dst before
1728 * we do the copy. Apparently there won't be any mappings
1729 * to the dst address normally.
1736 register struct phys_entry
*pp
;
1738 if (pmdebug
& (PDB_USER
|PDB_COPY
))
1739 kprintf("pmap_copy_page(spa=%x, dpa=%x)\n", src
, dst
);
1740 if (pmdebug
& PDB_COPY
)
1741 kprintf("pmap_copy_page: phys_copy(%x, %x, %x)\n",
1742 src
, dst
, PAGE_SIZE
);
1744 pmap_copy_page_assembler(src
, dst
);
1749 * pmap_pageable(pmap, s, e, pageable)
1750 * Make the specified pages (by pmap, offset)
1751 * pageable (or not) as requested.
1753 * A page which is not pageable may not take
1754 * a fault; therefore, its page table entry
1755 * must remain valid for the duration.
1757 * This routine is merely advisory; pmap_enter()
1758 * will specify that these pages are to be wired
1759 * down (or not) as appropriate.
1761 * (called from vm/vm_fault.c).
1771 return; /* This is not used... */
1775 * Routine: pmap_change_wiring
1776 * NOTE USED ANYMORE.
1780 register pmap_t pmap
,
1784 return; /* This is not used... */
1788 * pmap_modify_pages(pmap, s, e)
1789 * sets the modified bit on all virtual addresses v in the
1790 * virtual address range determined by [s, e] and pmap,
1791 * s and e must be on machine independent page boundaries and
1792 * s must be less than or equal to e.
1804 dbgTrace(0xF1D00010, (unsigned int)pmap
, (unsigned int)(sva
|((eva
-sva
)>>12))); /* (TEST/DEBUG) */
1808 if (pmdebug
& PDB_USER
) kprintf("pmap_modify_pages(pmap=%x, sva=%x, eva=%x)\n", pmap
, sva
, eva
);
1811 if (pmap
== PMAP_NULL
) return; /* If no pmap, can't do it... */
1813 debugLog2(56, sva
, eva
); /* Log pmap_map call */
1815 spl
=splhigh(); /* Don't bother me */
1817 for ( ; sva
< eva
; sva
+= PAGE_SIZE
) { /* Cycle through the whole range */
1818 mp
= hw_lock_phys_vir(pmap
->space
, sva
); /* Lock the physical entry for this mapping */
1819 if(mp
) { /* Did we find one? */
1820 if((unsigned int)mp
&1) { /* Did the lock on the phys entry time out? */
1821 panic("pmap_modify_pages: timeout obtaining lock on physical entry\n"); /* Scream bloody murder! */
1824 mp
= hw_cpv(mp
); /* Convert to virtual addressing */
1825 if(!mp
->physent
) continue; /* No physical entry means an I/O page, we can't set attributes */
1826 mapping_set_mod(mp
->physent
); /* Set the modfied bit for this page */
1827 hw_unlock_bit((unsigned int *)&mp
->physent
->phys_link
, PHYS_LOCK
); /* Unlock the physical entry */
1830 splx(spl
); /* Restore the interrupt level */
1832 debugLog2(57, 0, 0); /* Log pmap_map call */
1833 return; /* Leave... */
1837 * pmap_clear_modify(phys)
1838 * clears the hardware modified ("dirty") bit for one
1839 * machine independant page starting at the given
1840 * physical address. phys must be aligned on a machine
1841 * independant page boundary.
1844 pmap_clear_modify(vm_offset_t pa
)
1846 register struct phys_entry
*pp
;
1850 dbgTrace(0xF1D00011, (unsigned int)pa
, 0); /* (TEST/DEBUG) */
1853 if (pmdebug
& PDB_USER
)
1854 kprintf("pmap_clear_modify(pa=%x)\n", pa
);
1857 pp
= pmap_find_physentry(pa
); /* Find the physent for this page */
1858 if (pp
== PHYS_NULL
) return; /* If there isn't one, just leave... */
1860 debugLog2(58, pa
, 0); /* Log pmap_map call */
1862 spl
=splhigh(); /* Don't bother me */
1864 if(!hw_lock_bit((unsigned int *)&pp
->phys_link
, PHYS_LOCK
, LockTimeOut
)) { /* Try to get the lock on the physical entry */
1865 panic("pmap_clear_modify: Timeout getting lock on physent at %08X\n", pp
); /* Arrrgghhhh! */
1866 splx(spl
); /* Restore 'rupts */
1867 return; /* Should die before here */
1870 mapping_clr_mod(pp
); /* Clear all change bits for physical page */
1872 hw_unlock_bit((unsigned int *)&pp
->phys_link
, PHYS_LOCK
); /* Unlock the physical entry */
1873 splx(spl
); /* Restore the interrupt level */
1875 debugLog2(59, 0, 0); /* Log pmap_map call */
1879 * pmap_is_modified(phys)
1880 * returns TRUE if the given physical page has been modified
1881 * since the last call to pmap_clear_modify().
1884 pmap_is_modified(register vm_offset_t pa
)
1886 register struct phys_entry
*pp
;
1892 dbgTrace(0xF1D00012, (unsigned int)pa
, 0); /* (TEST/DEBUG) */
1895 if (pmdebug
& PDB_USER
)
1896 kprintf("pmap_is_modified(pa=%x)\n", pa
);
1899 pp
= pmap_find_physentry(pa
); /* Find the physent for this page */
1900 if (pp
== PHYS_NULL
) return(FALSE
); /* Just indicate not set... */
1902 debugLog2(60, pa
, 0); /* Log pmap_map call */
1904 spl
=splhigh(); /* Don't bother me */
1906 if(!hw_lock_bit((unsigned int *)&pp
->phys_link
, PHYS_LOCK
, LockTimeOut
)) { /* Try to get the lock on the physical entry */
1907 panic("pmap_is_modified: Timeout getting lock on physent at %08X\n", pp
); /* Arrrgghhhh! */
1908 splx(spl
); /* Restore 'rupts */
1909 return 0; /* Should die before here */
1912 ret
= mapping_tst_mod(pp
); /* Check for modified */
1914 hw_unlock_bit((unsigned int *)&pp
->phys_link
, PHYS_LOCK
); /* Unlock the physical entry */
1915 splx(spl
); /* Restore the interrupt level */
1917 debugLog2(61, ret
, 0); /* Log pmap_map call */
1923 * pmap_clear_reference(phys)
1924 * clears the hardware referenced bit in the given machine
1925 * independant physical page.
1929 pmap_clear_reference(vm_offset_t pa
)
1931 register struct phys_entry
*pp
;
1936 dbgTrace(0xF1D00013, (unsigned int)pa
, 0); /* (TEST/DEBUG) */
1939 if (pmdebug
& PDB_USER
)
1940 kprintf("pmap_clear_reference(pa=%x)\n", pa
);
1943 pp
= pmap_find_physentry(pa
); /* Find the physent for this page */
1944 if (pp
== PHYS_NULL
) return; /* If there isn't one, just leave... */
1946 debugLog2(62, pa
, 0); /* Log pmap_map call */
1948 spl
=splhigh(); /* Don't bother me */
1949 mapping_clr_ref(pp
); /* Clear all reference bits for physical page */
1950 splx(spl
); /* Restore the interrupt level */
1952 debugLog2(63, 0, 0); /* Log pmap_map call */
1957 * pmap_is_referenced(phys)
1958 * returns TRUE if the given physical page has been referenced
1959 * since the last call to pmap_clear_reference().
1962 pmap_is_referenced(vm_offset_t pa
)
1964 register struct phys_entry
*pp
;
1970 dbgTrace(0xF1D00014, (unsigned int)pa
, 0); /* (TEST/DEBUG) */
1973 if (pmdebug
& PDB_USER
)
1974 kprintf("pmap_is_referenced(pa=%x)\n", pa
);
1977 pp
= pmap_find_physentry(pa
); /* Find the physent for this page */
1978 if (pp
== PHYS_NULL
) return(FALSE
); /* Just indicate not set... */
1980 debugLog2(64, pa
, 0); /* Log pmap_map call */
1982 spl
=splhigh(); /* Don't bother me */
1984 if(!hw_lock_bit((unsigned int *)&pp
->phys_link
, PHYS_LOCK
, LockTimeOut
)) { /* Try to get the lock on the physical entry */
1985 panic("pmap_is_referenced: Timeout getting lock on physent at %08X\n", pp
); /* Arrrgghhhh! */
1986 splx(spl
); /* Restore 'rupts */
1987 return 0; /* Should die before here */
1990 ret
= mapping_tst_ref(pp
); /* Check for referenced */
1992 hw_unlock_bit((unsigned int *)&pp
->phys_link
, PHYS_LOCK
); /* Unlock the physical entry */
1993 splx(spl
); /* Restore the interrupt level */
1995 debugLog2(65, ret
, 0); /* Log pmap_map call */
2002 pmap_list_resident_pages(
2003 register pmap_t pmap
,
2004 register vm_offset_t
*listp
,
2009 #endif /* MACH_VM_DEBUG */
2016 pmap_copy_part_page(
2018 vm_offset_t src_offset
,
2020 vm_offset_t dst_offset
,
2023 register struct phys_entry
*pp_src
, *pp_dst
;
2028 dbgTrace(0xF1D00019, (unsigned int)src
+src_offset
, (unsigned int)dst
+dst_offset
); /* (TEST/DEBUG) */
2029 dbgTrace(0xF1D04019, (unsigned int)len
, 0); /* (TEST/DEBUG) */
2033 assert(((dst
& PAGE_MASK
)+dst_offset
+len
) <= PAGE_SIZE
);
2034 assert(((src
& PAGE_MASK
)+src_offset
+len
) <= PAGE_SIZE
);
2037 * Since the source and destination are physical addresses,
2038 * turn off data translation to perform a bcopy() in bcopy_phys().
2040 phys_copy((vm_offset_t
) src
+src_offset
,
2041 (vm_offset_t
) dst
+dst_offset
, len
);
2047 pmap_zero_part_page(
2052 panic("pmap_zero_part_page");
2055 boolean_t
pmap_verify_free(vm_offset_t pa
) {
2057 struct phys_entry
*pp
;
2060 dbgTrace(0xF1D00007, (unsigned int)pa
, 0); /* (TEST/DEBUG) */
2064 if (pmdebug
& PDB_USER
)
2065 kprintf("pmap_verify_free(pa=%x)\n", pa
);
2068 if (!pmap_initialized
) return(TRUE
);
2070 pp
= pmap_find_physentry(pa
); /* Look up the physical entry */
2071 if (pp
== PHYS_NULL
) return FALSE
; /* If there isn't one, show no mapping... */
2072 return ((mapping
*)((unsigned int)pp
->phys_link
& ~PHYS_FLAGS
) == MAPPING_NULL
); /* Otherwise, return TRUE if mapping exists... */
2076 /* Determine if we need to switch space and set up for it if so */
2078 void pmap_switch(pmap_t map
)
2083 if (watchacts
& WA_PCB
) {
2084 kprintf("Switching to map at 0x%08x, space=%d\n",
2090 /* when changing to kernel space, don't bother
2091 * doing anything, the kernel is mapped from here already.
2093 if (map
->space
== PPC_SID_KERNEL
) { /* Are we switching into kernel space? */
2094 return; /* If so, we don't do anything... */
2097 hw_set_user_space(map
); /* Indicate if we need to load the SRs or not */
2098 return; /* Bye, bye, butterfly... */
2102 * kern_return_t pmap_nest(grand, subord, vaddr, size)
2104 * grand = the pmap that we will nest subord into
2105 * subord = the pmap that goes into the grand
2106 * vaddr = start of range in pmap to be inserted
2107 * size = size of range in pmap to be inserted
2109 * Inserts a pmap into another. This is used to implement shared segments.
2110 * On the current PPC processors, this is limited to segment (256MB) aligned
2111 * segment sized ranges.
2114 kern_return_t
pmap_nest(pmap_t grand
, pmap_t subord
, vm_offset_t vaddr
, vm_size_t size
) {
2116 unsigned int oflags
, seg
, grandr
;
2119 if(size
!= 0x10000000) return KERN_INVALID_VALUE
; /* We can only do this for 256MB for now */
2120 if(vaddr
& 0x0FFFFFFF) return KERN_INVALID_VALUE
; /* We can only do this aligned to 256MB */
2122 while(1) { /* Test and set the subordinate flag */
2123 oflags
= subord
->vflags
& ~pmapAltSeg
; /* Get old unset value */
2124 if(subord
->vflags
& pmapAltSeg
) { /* Are trying to nest one already nested? */
2125 panic("pmap_nest: Attempt to nest an already nested pmap\n");
2127 if(hw_compare_and_store(oflags
, oflags
| pmapSubord
, &subord
->vflags
)) break; /* Done if we got it set */
2130 simple_lock(&grand
->lock
); /* Lock the superior pmap */
2132 if(grand
->vflags
& pmapSubord
) { /* Are we only one level deep? */
2133 simple_unlock(&grand
->lock
); /* Unlock the superior pmap */
2134 panic("pmap_nest: Attempt to nest into subordinate pmap\n");
2135 return KERN_FAILURE
; /* Shame on you */
2138 seg
= vaddr
>> 28; /* Isolate the segment number */
2139 if((0x00008000 >> seg
) & grand
->vflags
) { /* See if it is already in use */
2140 simple_unlock(&grand
->lock
); /* Unlock the superior pmap */
2141 panic("pmap_nest: Attempt to nest into already nested segment\n");
2142 return KERN_FAILURE
; /* Shame on you */
2145 grand
->pmapPmaps
[seg
] = subord
; /* Set the pointer to the subordinate */
2146 grand
->pmapSegs
[seg
] = SEG_REG_PROT
| (seg
<< 20) | subord
->space
; /* Set the vsid to the subordinate's vsid */
2147 grand
->vflags
|= (0x00008000 >> seg
); /* Set in-use bit */
2149 grandr
= (unsigned int)grand
^ grand
->pmapvr
; /* Get real address of the grand pmap */
2151 simple_unlock(&grand
->lock
); /* Unlock the grand pmap */
2155 * Note that the following will force the segment registers to be reloaded following
2156 * the next interrupt on all processors if they are using the pmap we just changed.
2161 for(i
=0; i
< real_ncpus
; i
++) { /* Cycle through processors */
2162 (void)hw_compare_and_store((unsigned int)grandr
, 0, &per_proc_info
[i
].Lastpmap
); /* Clear if ours */
2165 return KERN_SUCCESS
; /* Bye, bye, butterfly... */
2170 * kern_return_t pmap_unnest(grand, vaddr, size)
2172 * grand = the pmap that we will nest subord into
2173 * vaddr = start of range in pmap to be inserted
2174 * size = size of range in pmap to be inserted
2176 * Removes a pmap from another. This is used to implement shared segments.
2177 * On the current PPC processors, this is limited to segment (256MB) aligned
2178 * segment sized ranges.
2181 kern_return_t
pmap_unnest(pmap_t grand
, vm_offset_t vaddr
, vm_size_t size
) {
2183 unsigned int oflags
, seg
, grandr
, tstamp
;
2186 if(size
!= 0x10000000) return KERN_INVALID_VALUE
; /* We can only do this for 256MB for now */
2187 if(vaddr
& 0x0FFFFFFF) return KERN_INVALID_VALUE
; /* We can only do this aligned to 256MB */
2189 simple_lock(&grand
->lock
); /* Lock the superior pmap */
2190 disable_preemption(); /* It's all for me! */
2192 seg
= vaddr
>> 28; /* Isolate the segment number */
2193 if(!((0x00008000 >> seg
) & grand
->vflags
)) { /* See if it is already in use */
2194 enable_preemption(); /* Ok, your turn */
2195 simple_unlock(&grand
->lock
); /* Unlock the superior pmap */
2196 panic("pmap_unnest: Attempt to unnest an unnested segment\n");
2197 return KERN_FAILURE
; /* Shame on you */
2200 grand
->pmapPmaps
[seg
] = (pmap_t
)0; /* Clear the pointer to the subordinate */
2201 grand
->pmapSegs
[seg
] = grand
->space
; /* Set the pointer to the subordinate's vsid */
2202 grand
->pmapSegs
[seg
] = SEG_REG_PROT
| (seg
<< 20) | grand
->space
; /* Set the vsid to the grand's vsid */
2203 grand
->vflags
&= ~(0x00008000 >> seg
); /* Clear in-use bit */
2205 grandr
= (unsigned int)grand
^ grand
->pmapvr
; /* Get real address of the grand pmap */
2207 simple_unlock(&grand
->lock
); /* Unlock the superior pmap */
2210 * Note that the following will force the segment registers to be reloaded
2211 * on all processors (if they are using the pmap we just changed) before returning.
2213 * This is needed. The reason is that until the segment register is
2214 * reloaded, another thread in the same task on a different processor will
2215 * be able to access memory that it isn't allowed to anymore. That can happen
2216 * because access to the subordinate pmap is being removed, but the pmap is still
2219 * Note that we only kick the other processor if we see that it was using the pmap while we
2224 mycpu
= cpu_number(); /* Who am I? Am I just a dream? */
2225 for(i
=0; i
< real_ncpus
; i
++) { /* Cycle through processors */
2226 if(hw_compare_and_store((unsigned int)grandr
, 0, &per_proc_info
[i
].Lastpmap
)) { /* Clear if ours and kick the other guy if he was using it */
2227 if(i
== mycpu
) continue; /* Don't diddle ourselves */
2228 tstamp
= per_proc_info
[i
].ruptStamp
[1]; /* Save the processor's last interrupt time stamp */
2229 if(cpu_signal(i
, SIGPwake
, 0, 0) != KERN_SUCCESS
) { /* Make sure we see the pmap change */
2232 if(!hw_cpu_wcng(&per_proc_info
[i
].ruptStamp
[1], tstamp
, LockTimeOut
)) { /* Wait for the other processors to enter debug */
2233 panic("pmap_unnest: Other processor (%d) did not see interruption request\n", i
);
2238 enable_preemption(); /* Others can run now */
2239 return KERN_SUCCESS
; /* Bye, bye, butterfly... */
2243 void pmap_ver(pmap_t pmap
, vm_offset_t sva
, vm_offset_t eva
) {
2250 sva
= trunc_page(sva
);
2251 eva
= trunc_page(eva
);
2253 for(i
= 0; i
< (pmapUsageMask
+ 1); i
++) { /* Step through them all */
2254 if((pmap
->pmapUsage
[i
]) > 8192) { /* See if this is a sane number */
2255 panic("pmap_ver: pmapUsage slot for %08X has invalid count (%d) for pmap %08X\n",
2256 i
* pmapUsageSize
, pmap
->pmapUsage
[i
], pmap
);
2260 while(1) { /* Try multiple times */
2262 for(i
= 0; i
< (pmapUsageMask
+ 1); i
++) { /* Step through them all */
2263 cnt
= cnt
+ pmap
->pmapUsage
[i
]; /* Sum all slots */
2265 if(cnt
== pmap
->stats
.resident_count
) break; /* We're ok if we match... */
2268 for(i
= 0; i
< 100000; i
++) {
2272 panic("pmap_ver: pmapUsage total (%d) does not match resident count (%d) for pmap %08X\n",
2273 cnt
, pmap
->stats
.resident_count
, pmap
);
2277 for(xx
= sva
; xx
< eva
; xx
+= PAGE_SIZE
) { /* See if any slots not clear */
2278 if(pmap_extract(pmap
, xx
)) {
2279 panic("pmap_ver: range (%08X to %08X) not empty at %08X for pmap %08X\n",
2280 sva
, eva
, xx
, pmap
);
2286 /* temporary workaround */
2288 coredumpok(vm_map_t map
, vm_offset_t va
)