arm32_kvminit.c revision 1.40 1 /* $NetBSD: arm32_kvminit.c,v 1.40 2017/07/06 15:09:17 skrll Exp $ */
2
3 /*
4 * Copyright (c) 2002, 2003, 2005 Genetec Corporation. All rights reserved.
5 * Written by Hiroyuki Bessho for Genetec Corporation.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of Genetec Corporation may not be used to endorse or
16 * promote products derived from this software without specific prior
17 * written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENETEC CORPORATION
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 *
31 * Copyright (c) 2001 Wasabi Systems, Inc.
32 * All rights reserved.
33 *
34 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
44 * 3. All advertising materials mentioning features or use of this software
45 * must display the following acknowledgement:
46 * This product includes software developed for the NetBSD Project by
47 * Wasabi Systems, Inc.
48 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
49 * or promote products derived from this software without specific prior
50 * written permission.
51 *
52 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
53 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
54 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
55 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
56 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
57 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
58 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
59 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
60 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
61 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
62 * POSSIBILITY OF SUCH DAMAGE.
63 *
64 * Copyright (c) 1997,1998 Mark Brinicombe.
65 * Copyright (c) 1997,1998 Causality Limited.
66 * All rights reserved.
67 *
68 * Redistribution and use in source and binary forms, with or without
69 * modification, are permitted provided that the following conditions
70 * are met:
71 * 1. Redistributions of source code must retain the above copyright
72 * notice, this list of conditions and the following disclaimer.
73 * 2. Redistributions in binary form must reproduce the above copyright
74 * notice, this list of conditions and the following disclaimer in the
75 * documentation and/or other materials provided with the distribution.
76 * 3. All advertising materials mentioning features or use of this software
77 * must display the following acknowledgement:
78 * This product includes software developed by Mark Brinicombe
79 * for the NetBSD Project.
80 * 4. The name of the company nor the name of the author may be used to
81 * endorse or promote products derived from this software without specific
82 * prior written permission.
83 *
84 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
85 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
86 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
87 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
88 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
89 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
90 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
91 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
92 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
93 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
94 * SUCH DAMAGE.
95 *
96 * Copyright (c) 2007 Microsoft
97 * All rights reserved.
98 *
99 * Redistribution and use in source and binary forms, with or without
100 * modification, are permitted provided that the following conditions
101 * are met:
102 * 1. Redistributions of source code must retain the above copyright
103 * notice, this list of conditions and the following disclaimer.
104 * 2. Redistributions in binary form must reproduce the above copyright
105 * notice, this list of conditions and the following disclaimer in the
106 * documentation and/or other materials provided with the distribution.
107 * 3. All advertising materials mentioning features or use of this software
108 * must display the following acknowledgement:
109 * This product includes software developed by Microsoft
110 *
111 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
112 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
113 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
114 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTERS BE LIABLE FOR ANY DIRECT,
115 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
116 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
117 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
118 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
119 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
120 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
121 * SUCH DAMAGE.
122 */
123
124 #include "opt_multiprocessor.h"
125
126 #include <sys/cdefs.h>
127 __KERNEL_RCSID(0, "$NetBSD: arm32_kvminit.c,v 1.40 2017/07/06 15:09:17 skrll Exp $");
128
129 #include <sys/param.h>
130 #include <sys/device.h>
131 #include <sys/kernel.h>
132 #include <sys/reboot.h>
133 #include <sys/bus.h>
134
135 #include <dev/cons.h>
136
137 #include <uvm/uvm_extern.h>
138
139 #include <arm/locore.h>
140 #include <arm/db_machdep.h>
141 #include <arm/undefined.h>
142 #include <arm/bootconfig.h>
143 #include <arm/arm32/machdep.h>
144
145 #ifdef MULTIPROCESSOR
146 #ifndef __HAVE_CPU_UAREA_ALLOC_IDLELWP
147 #error __HAVE_CPU_UAREA_ALLOC_IDLELWP required to not waste pages for idlestack
148 #endif
149 #endif
150
151 struct bootmem_info bootmem_info;
152
153 extern void *msgbufaddr;
154 paddr_t msgbufphys;
155 paddr_t physical_start;
156 paddr_t physical_end;
157
158 extern char etext[];
159 extern char __data_start[], _edata[];
160 extern char __bss_start[], __bss_end__[];
161 extern char _end[];
162
163 /* Page tables for mapping kernel VM */
164 #define KERNEL_L2PT_VMDATA_NUM 8 /* start with 32MB of KVM */
165
166 /*
167 * Macros to translate between physical and virtual for a subset of the
168 * kernel address space. *Not* for general use.
169 */
170 #if defined(KERNEL_BASE_VOFFSET)
171 #define KERN_VTOPHYS(bmi, va) \
172 ((paddr_t)((vaddr_t)(va) - KERNEL_BASE_VOFFSET))
173 #define KERN_PHYSTOV(bmi, pa) \
174 ((vaddr_t)((paddr_t)(pa) + KERNEL_BASE_VOFFSET))
175 #else
176 #define KERN_VTOPHYS(bmi, va) \
177 ((paddr_t)((vaddr_t)(va) - KERNEL_BASE + (bmi)->bmi_start))
178 #define KERN_PHYSTOV(bmi, pa) \
179 ((vaddr_t)((paddr_t)(pa) - (bmi)->bmi_start + KERNEL_BASE))
180 #endif
181
182 void
183 arm32_bootmem_init(paddr_t memstart, psize_t memsize, vsize_t kernelstart)
184 {
185 struct bootmem_info * const bmi = &bootmem_info;
186 pv_addr_t *pv = bmi->bmi_freeblocks;
187
188 #ifdef VERBOSE_INIT_ARM
189 printf("%s: memstart=%#lx, memsize=%#lx, kernelstart=%#lx\n",
190 __func__, memstart, memsize, kernelstart);
191 #endif
192
193 physical_start = bmi->bmi_start = memstart;
194 physical_end = bmi->bmi_end = memstart + memsize;
195 #ifndef ARM_HAS_LPAE
196 if (physical_end == 0) {
197 physical_end = -PAGE_SIZE;
198 memsize -= PAGE_SIZE;
199 bmi->bmi_end -= PAGE_SIZE;
200 #ifdef VERBOSE_INIT_ARM
201 printf("%s: memsize shrunk by a page to avoid ending at 4GB\n",
202 __func__);
203 #endif
204 }
205 #endif
206 physmem = memsize / PAGE_SIZE;
207
208 /*
209 * Let's record where the kernel lives.
210 */
211 bmi->bmi_kernelstart = kernelstart;
212 bmi->bmi_kernelend = KERN_VTOPHYS(bmi, round_page((vaddr_t)_end));
213
214 #ifdef VERBOSE_INIT_ARM
215 printf("%s: kernelend=%#lx\n", __func__, bmi->bmi_kernelend);
216 #endif
217
218 /*
219 * Now the rest of the free memory must be after the kernel.
220 */
221 pv->pv_pa = bmi->bmi_kernelend;
222 pv->pv_va = KERN_PHYSTOV(bmi, pv->pv_pa);
223 pv->pv_size = bmi->bmi_end - bmi->bmi_kernelend;
224 bmi->bmi_freepages += pv->pv_size / PAGE_SIZE;
225 #ifdef VERBOSE_INIT_ARM
226 printf("%s: adding %lu free pages: [%#lx..%#lx] (VA %#lx)\n",
227 __func__, pv->pv_size / PAGE_SIZE, pv->pv_pa,
228 pv->pv_pa + pv->pv_size - 1, pv->pv_va);
229 #endif
230 pv++;
231
232 /*
233 * Add a free block for any memory before the kernel.
234 */
235 if (bmi->bmi_start < bmi->bmi_kernelstart) {
236 pv->pv_pa = bmi->bmi_start;
237 pv->pv_va = KERN_PHYSTOV(bmi, pv->pv_pa);
238 pv->pv_size = bmi->bmi_kernelstart - pv->pv_pa;
239 bmi->bmi_freepages += pv->pv_size / PAGE_SIZE;
240 #ifdef VERBOSE_INIT_ARM
241 printf("%s: adding %lu free pages: [%#lx..%#lx] (VA %#lx)\n",
242 __func__, pv->pv_size / PAGE_SIZE, pv->pv_pa,
243 pv->pv_pa + pv->pv_size - 1, pv->pv_va);
244 #endif
245 pv++;
246 }
247
248 bmi->bmi_nfreeblocks = pv - bmi->bmi_freeblocks;
249
250 SLIST_INIT(&bmi->bmi_freechunks);
251 SLIST_INIT(&bmi->bmi_chunks);
252 }
253
254 static bool
255 concat_pvaddr(pv_addr_t *acc_pv, pv_addr_t *pv)
256 {
257 if (acc_pv->pv_pa + acc_pv->pv_size == pv->pv_pa
258 && acc_pv->pv_va + acc_pv->pv_size == pv->pv_va
259 && acc_pv->pv_prot == pv->pv_prot
260 && acc_pv->pv_cache == pv->pv_cache) {
261 #ifdef VERBOSE_INIT_ARMX
262 printf("%s: appending pv %p (%#lx..%#lx) to %#lx..%#lx\n",
263 __func__, pv, pv->pv_pa, pv->pv_pa + pv->pv_size + 1,
264 acc_pv->pv_pa, acc_pv->pv_pa + acc_pv->pv_size + 1);
265 #endif
266 acc_pv->pv_size += pv->pv_size;
267 return true;
268 }
269
270 return false;
271 }
272
273 static void
274 add_pages(struct bootmem_info *bmi, pv_addr_t *pv)
275 {
276 pv_addr_t **pvp = &SLIST_FIRST(&bmi->bmi_chunks);
277 while ((*pvp) != NULL && (*pvp)->pv_va <= pv->pv_va) {
278 pv_addr_t * const pv0 = (*pvp);
279 KASSERT(SLIST_NEXT(pv0, pv_list) == NULL || pv0->pv_pa < SLIST_NEXT(pv0, pv_list)->pv_pa);
280 if (concat_pvaddr(pv0, pv)) {
281 #ifdef VERBOSE_INIT_ARM
282 printf("%s: %s pv %p (%#lx..%#lx) to %#lx..%#lx\n",
283 __func__, "appending", pv,
284 pv->pv_pa, pv->pv_pa + pv->pv_size - 1,
285 pv0->pv_pa, pv0->pv_pa + pv0->pv_size - pv->pv_size - 1);
286 #endif
287 pv = SLIST_NEXT(pv0, pv_list);
288 if (pv != NULL && concat_pvaddr(pv0, pv)) {
289 #ifdef VERBOSE_INIT_ARM
290 printf("%s: %s pv %p (%#lx..%#lx) to %#lx..%#lx\n",
291 __func__, "merging", pv,
292 pv->pv_pa, pv->pv_pa + pv->pv_size - 1,
293 pv0->pv_pa,
294 pv0->pv_pa + pv0->pv_size - pv->pv_size - 1);
295 #endif
296 SLIST_REMOVE_AFTER(pv0, pv_list);
297 SLIST_INSERT_HEAD(&bmi->bmi_freechunks, pv, pv_list);
298 }
299 return;
300 }
301 KASSERT(pv->pv_va != (*pvp)->pv_va);
302 pvp = &SLIST_NEXT(*pvp, pv_list);
303 }
304 KASSERT((*pvp) == NULL || pv->pv_va < (*pvp)->pv_va);
305 pv_addr_t * const new_pv = SLIST_FIRST(&bmi->bmi_freechunks);
306 KASSERT(new_pv != NULL);
307 SLIST_REMOVE_HEAD(&bmi->bmi_freechunks, pv_list);
308 *new_pv = *pv;
309 SLIST_NEXT(new_pv, pv_list) = *pvp;
310 (*pvp) = new_pv;
311 #ifdef VERBOSE_INIT_ARM
312 printf("%s: adding pv %p (pa %#lx, va %#lx, %lu pages) ",
313 __func__, new_pv, new_pv->pv_pa, new_pv->pv_va,
314 new_pv->pv_size / PAGE_SIZE);
315 if (SLIST_NEXT(new_pv, pv_list))
316 printf("before pa %#lx\n", SLIST_NEXT(new_pv, pv_list)->pv_pa);
317 else
318 printf("at tail\n");
319 #endif
320 }
321
322 static void
323 valloc_pages(struct bootmem_info *bmi, pv_addr_t *pv, size_t npages,
324 int prot, int cache, bool zero_p)
325 {
326 size_t nbytes = npages * PAGE_SIZE;
327 pv_addr_t *free_pv = bmi->bmi_freeblocks;
328 size_t free_idx = 0;
329 static bool l1pt_found;
330
331 KASSERT(npages > 0);
332
333 /*
334 * If we haven't allocated the kernel L1 page table and we are aligned
335 * at a L1 table boundary, alloc the memory for it.
336 */
337 if (!l1pt_found
338 && (free_pv->pv_pa & (L1_TABLE_SIZE - 1)) == 0
339 && free_pv->pv_size >= L1_TABLE_SIZE) {
340 l1pt_found = true;
341 valloc_pages(bmi, &kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE,
342 VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE, true);
343 add_pages(bmi, &kernel_l1pt);
344 }
345
346 while (nbytes > free_pv->pv_size) {
347 free_pv++;
348 free_idx++;
349 if (free_idx == bmi->bmi_nfreeblocks) {
350 panic("%s: could not allocate %zu bytes",
351 __func__, nbytes);
352 }
353 }
354
355 /*
356 * As we allocate the memory, make sure that we don't walk over
357 * our current first level translation table.
358 */
359 KASSERT((armreg_ttbr_read() & ~(L1_TABLE_SIZE - 1)) != free_pv->pv_pa);
360
361 pv->pv_pa = free_pv->pv_pa;
362 pv->pv_va = free_pv->pv_va;
363 pv->pv_size = nbytes;
364 pv->pv_prot = prot;
365 pv->pv_cache = cache;
366
367 /*
368 * If PTE_PAGETABLE uses the same cache modes as PTE_CACHE
369 * just use PTE_CACHE.
370 */
371 if (cache == PTE_PAGETABLE
372 && pte_l1_s_cache_mode == pte_l1_s_cache_mode_pt
373 && pte_l2_l_cache_mode == pte_l2_l_cache_mode_pt
374 && pte_l2_s_cache_mode == pte_l2_s_cache_mode_pt)
375 pv->pv_cache = PTE_CACHE;
376
377 free_pv->pv_pa += nbytes;
378 free_pv->pv_va += nbytes;
379 free_pv->pv_size -= nbytes;
380 if (free_pv->pv_size == 0) {
381 --bmi->bmi_nfreeblocks;
382 for (; free_idx < bmi->bmi_nfreeblocks; free_idx++) {
383 free_pv[0] = free_pv[1];
384 }
385 }
386
387 bmi->bmi_freepages -= npages;
388
389 if (zero_p)
390 memset((void *)pv->pv_va, 0, nbytes);
391 }
392
393 void
394 arm32_kernel_vm_init(vaddr_t kernel_vm_base, vaddr_t vectors, vaddr_t iovbase,
395 const struct pmap_devmap *devmap, bool mapallmem_p)
396 {
397 struct bootmem_info * const bmi = &bootmem_info;
398 #ifdef MULTIPROCESSOR
399 const size_t cpu_num = arm_cpu_max;
400 #else
401 const size_t cpu_num = 1;
402 #endif
403 #ifdef ARM_HAS_VBAR
404 const bool map_vectors_p = false;
405 #elif defined(CPU_ARMV7) || defined(CPU_ARM11)
406 const bool map_vectors_p = vectors == ARM_VECTORS_HIGH
407 || (armreg_pfr1_read() & ARM_PFR1_SEC_MASK) == 0;
408 #else
409 const bool map_vectors_p = true;
410 #endif
411
412 #ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS
413 KASSERT(mapallmem_p);
414 #ifdef ARM_MMU_EXTENDED
415 /*
416 * The direct map VA space ends at the start of the kernel VM space.
417 */
418 pmap_directlimit = kernel_vm_base;
419 #else
420 KASSERT(kernel_vm_base - KERNEL_BASE >= physical_end - physical_start);
421 #endif /* ARM_MMU_EXTENDED */
422 #endif /* __HAVE_MM_MD_DIRECT_MAPPED_PHYS */
423
424 /*
425 * Calculate the number of L2 pages needed for mapping the
426 * kernel + data + stuff. Assume 2 L2 pages for kernel, 1 for vectors,
427 * and 1 for IO
428 */
429 size_t kernel_size = bmi->bmi_kernelend;
430 kernel_size -= (bmi->bmi_kernelstart & -L2_S_SEGSIZE);
431 kernel_size += L1_TABLE_SIZE_REAL;
432 kernel_size += PAGE_SIZE * KERNEL_L2PT_VMDATA_NUM;
433 if (map_vectors_p) {
434 kernel_size += PAGE_SIZE; /* L2PT for VECTORS */
435 }
436 if (iovbase) {
437 kernel_size += PAGE_SIZE; /* L2PT for IO */
438 }
439 kernel_size +=
440 cpu_num * (ABT_STACK_SIZE + FIQ_STACK_SIZE + IRQ_STACK_SIZE
441 + UND_STACK_SIZE + UPAGES) * PAGE_SIZE;
442 kernel_size += round_page(MSGBUFSIZE);
443 kernel_size += 0x10000; /* slop */
444 if (!mapallmem_p) {
445 kernel_size += PAGE_SIZE
446 * ((kernel_size + L2_S_SEGSIZE - 1) / L2_S_SEGSIZE);
447 }
448 kernel_size = round_page(kernel_size);
449
450 /*
451 * Now we know how many L2 pages it will take.
452 */
453 const size_t KERNEL_L2PT_KERNEL_NUM =
454 round_page(kernel_size + L2_S_SEGSIZE - 1) / L2_S_SEGSIZE;
455
456 #ifdef VERBOSE_INIT_ARM
457 printf("%s: %zu L2 pages are needed to map %#zx kernel bytes\n",
458 __func__, KERNEL_L2PT_KERNEL_NUM, kernel_size);
459 #endif
460
461 KASSERT(KERNEL_L2PT_KERNEL_NUM + KERNEL_L2PT_VMDATA_NUM < __arraycount(bmi->bmi_l2pts));
462 pv_addr_t * const kernel_l2pt = bmi->bmi_l2pts;
463 pv_addr_t * const vmdata_l2pt = kernel_l2pt + KERNEL_L2PT_KERNEL_NUM;
464 pv_addr_t msgbuf;
465 pv_addr_t text;
466 pv_addr_t data;
467 pv_addr_t chunks[KERNEL_L2PT_KERNEL_NUM+KERNEL_L2PT_VMDATA_NUM+11];
468 #if ARM_MMU_XSCALE == 1
469 pv_addr_t minidataclean;
470 #endif
471
472 /*
473 * We need to allocate some fixed page tables to get the kernel going.
474 *
475 * We are going to allocate our bootstrap pages from the beginning of
476 * the free space that we just calculated. We allocate one page
477 * directory and a number of page tables and store the physical
478 * addresses in the bmi_l2pts array in bootmem_info.
479 *
480 * The kernel page directory must be on a 16K boundary. The page
481 * tables must be on 4K boundaries. What we do is allocate the
482 * page directory on the first 16K boundary that we encounter, and
483 * the page tables on 4K boundaries otherwise. Since we allocate
484 * at least 3 L2 page tables, we are guaranteed to encounter at
485 * least one 16K aligned region.
486 */
487
488 #ifdef VERBOSE_INIT_ARM
489 printf("%s: allocating page tables for", __func__);
490 #endif
491 for (size_t i = 0; i < __arraycount(chunks); i++) {
492 SLIST_INSERT_HEAD(&bmi->bmi_freechunks, &chunks[i], pv_list);
493 }
494
495 kernel_l1pt.pv_pa = 0;
496 kernel_l1pt.pv_va = 0;
497
498 /*
499 * Allocate the L2 pages, but if we get to a page that is aligned for
500 * an L1 page table, we will allocate the pages for it first and then
501 * allocate the L2 page.
502 */
503
504 if (map_vectors_p) {
505 /*
506 * First allocate L2 page for the vectors.
507 */
508 #ifdef VERBOSE_INIT_ARM
509 printf(" vector");
510 #endif
511 valloc_pages(bmi, &bmi->bmi_vector_l2pt, 1,
512 VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE, true);
513 add_pages(bmi, &bmi->bmi_vector_l2pt);
514 }
515
516 /*
517 * Now allocate L2 pages for the kernel
518 */
519 #ifdef VERBOSE_INIT_ARM
520 printf(" kernel");
521 #endif
522 for (size_t idx = 0; idx < KERNEL_L2PT_KERNEL_NUM; ++idx) {
523 valloc_pages(bmi, &kernel_l2pt[idx], 1,
524 VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE, true);
525 add_pages(bmi, &kernel_l2pt[idx]);
526 }
527
528 /*
529 * Now allocate L2 pages for the initial kernel VA space.
530 */
531 #ifdef VERBOSE_INIT_ARM
532 printf(" vm");
533 #endif
534 for (size_t idx = 0; idx < KERNEL_L2PT_VMDATA_NUM; ++idx) {
535 valloc_pages(bmi, &vmdata_l2pt[idx], 1,
536 VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE, true);
537 add_pages(bmi, &vmdata_l2pt[idx]);
538 }
539
540 /*
541 * If someone wanted a L2 page for I/O, allocate it now.
542 */
543 if (iovbase) {
544 #ifdef VERBOSE_INIT_ARM
545 printf(" io");
546 #endif
547 valloc_pages(bmi, &bmi->bmi_io_l2pt, 1,
548 VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE, true);
549 add_pages(bmi, &bmi->bmi_io_l2pt);
550 }
551
552 #ifdef VERBOSE_INIT_ARM
553 printf("%s: allocating stacks\n", __func__);
554 #endif
555
556 /* Allocate stacks for all modes and CPUs */
557 valloc_pages(bmi, &abtstack, ABT_STACK_SIZE * cpu_num,
558 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE, true);
559 add_pages(bmi, &abtstack);
560 valloc_pages(bmi, &fiqstack, FIQ_STACK_SIZE * cpu_num,
561 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE, true);
562 add_pages(bmi, &fiqstack);
563 valloc_pages(bmi, &irqstack, IRQ_STACK_SIZE * cpu_num,
564 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE, true);
565 add_pages(bmi, &irqstack);
566 valloc_pages(bmi, &undstack, UND_STACK_SIZE * cpu_num,
567 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE, true);
568 add_pages(bmi, &undstack);
569 valloc_pages(bmi, &idlestack, UPAGES * cpu_num, /* SVC32 */
570 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE, true);
571 add_pages(bmi, &idlestack);
572 valloc_pages(bmi, &kernelstack, UPAGES, /* SVC32 */
573 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE, true);
574 add_pages(bmi, &kernelstack);
575
576 /* Allocate the message buffer from the end of memory. */
577 const size_t msgbuf_pgs = round_page(MSGBUFSIZE) / PAGE_SIZE;
578 valloc_pages(bmi, &msgbuf, msgbuf_pgs,
579 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE, false);
580 add_pages(bmi, &msgbuf);
581 msgbufphys = msgbuf.pv_pa;
582 msgbufaddr = (void *)msgbuf.pv_va;
583
584 if (map_vectors_p) {
585 /*
586 * Allocate a page for the system vector page.
587 * This page will just contain the system vectors and can be
588 * shared by all processes.
589 */
590 valloc_pages(bmi, &systempage, 1, VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE,
591 PTE_CACHE, true);
592 }
593 systempage.pv_va = vectors;
594
595 /*
596 * If the caller needed a few extra pages for some reason, allocate
597 * them now.
598 */
599 #if ARM_MMU_XSCALE == 1
600 #if (ARM_NMMUS > 1)
601 if (xscale_use_minidata)
602 #endif
603 valloc_pages(bmi, &minidataclean, 1,
604 VM_PROT_READ|VM_PROT_WRITE, 0, true);
605 #endif
606
607 /*
608 * Ok we have allocated physical pages for the primary kernel
609 * page tables and stacks. Let's just confirm that.
610 */
611 if (kernel_l1pt.pv_va == 0
612 && (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE - 1)) != 0))
613 panic("%s: Failed to allocate or align the kernel "
614 "page directory", __func__);
615
616
617 #ifdef VERBOSE_INIT_ARM
618 printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
619 #endif
620
621 /*
622 * Now we start construction of the L1 page table
623 * We start by mapping the L2 page tables into the L1.
624 * This means that we can replace L1 mappings later on if necessary
625 */
626 vaddr_t l1pt_va = kernel_l1pt.pv_va;
627 paddr_t l1pt_pa = kernel_l1pt.pv_pa;
628
629 if (map_vectors_p) {
630 /* Map the L2 pages tables in the L1 page table */
631 pmap_link_l2pt(l1pt_va, systempage.pv_va & -L2_S_SEGSIZE,
632 &bmi->bmi_vector_l2pt);
633 #ifdef VERBOSE_INIT_ARM
634 printf("%s: adding L2 pt (VA %#lx, PA %#lx) "
635 "for VA %#lx\n (vectors)",
636 __func__, bmi->bmi_vector_l2pt.pv_va,
637 bmi->bmi_vector_l2pt.pv_pa, systempage.pv_va);
638 #endif
639 }
640
641 const vaddr_t kernel_base =
642 KERN_PHYSTOV(bmi, bmi->bmi_kernelstart & -L2_S_SEGSIZE);
643 for (size_t idx = 0; idx < KERNEL_L2PT_KERNEL_NUM; idx++) {
644 pmap_link_l2pt(l1pt_va, kernel_base + idx * L2_S_SEGSIZE,
645 &kernel_l2pt[idx]);
646 #ifdef VERBOSE_INIT_ARM
647 printf("%s: adding L2 pt (VA %#lx, PA %#lx) for VA %#lx (kernel)\n",
648 __func__, kernel_l2pt[idx].pv_va,
649 kernel_l2pt[idx].pv_pa, kernel_base + idx * L2_S_SEGSIZE);
650 #endif
651 }
652
653 for (size_t idx = 0; idx < KERNEL_L2PT_VMDATA_NUM; idx++) {
654 pmap_link_l2pt(l1pt_va, kernel_vm_base + idx * L2_S_SEGSIZE,
655 &vmdata_l2pt[idx]);
656 #ifdef VERBOSE_INIT_ARM
657 printf("%s: adding L2 pt (VA %#lx, PA %#lx) for VA %#lx (vm)\n",
658 __func__, vmdata_l2pt[idx].pv_va, vmdata_l2pt[idx].pv_pa,
659 kernel_vm_base + idx * L2_S_SEGSIZE);
660 #endif
661 }
662 if (iovbase) {
663 pmap_link_l2pt(l1pt_va, iovbase & -L2_S_SEGSIZE, &bmi->bmi_io_l2pt);
664 #ifdef VERBOSE_INIT_ARM
665 printf("%s: adding L2 pt (VA %#lx, PA %#lx) for VA %#lx (io)\n",
666 __func__, bmi->bmi_io_l2pt.pv_va, bmi->bmi_io_l2pt.pv_pa,
667 iovbase & -L2_S_SEGSIZE);
668 #endif
669 }
670
671 /* update the top of the kernel VM */
672 pmap_curmaxkvaddr =
673 kernel_vm_base + (KERNEL_L2PT_VMDATA_NUM * L2_S_SEGSIZE);
674
675 #ifdef VERBOSE_INIT_ARM
676 printf("Mapping kernel\n");
677 #endif
678
679 extern char etext[], _end[];
680 size_t totalsize = bmi->bmi_kernelend - bmi->bmi_kernelstart;
681 size_t textsize = KERN_VTOPHYS(bmi, (uintptr_t)etext) - bmi->bmi_kernelstart;
682
683 textsize = (textsize + PGOFSET) & ~PGOFSET;
684
685 /* start at offset of kernel in RAM */
686
687 text.pv_pa = bmi->bmi_kernelstart;
688 text.pv_va = KERN_PHYSTOV(bmi, bmi->bmi_kernelstart);
689 text.pv_size = textsize;
690 text.pv_prot = VM_PROT_READ | VM_PROT_EXECUTE;
691 text.pv_cache = PTE_CACHE;
692
693 #ifdef VERBOSE_INIT_ARM
694 printf("%s: adding chunk for kernel text %#lx..%#lx (VA %#lx)\n",
695 __func__, text.pv_pa, text.pv_pa + text.pv_size - 1, text.pv_va);
696 #endif
697
698 add_pages(bmi, &text);
699
700 data.pv_pa = text.pv_pa + textsize;
701 data.pv_va = text.pv_va + textsize;
702 data.pv_size = totalsize - textsize;
703 data.pv_prot = VM_PROT_READ|VM_PROT_WRITE;
704 data.pv_cache = PTE_CACHE;
705
706 #ifdef VERBOSE_INIT_ARM
707 printf("%s: adding chunk for kernel data/bss %#lx..%#lx (VA %#lx)\n",
708 __func__, data.pv_pa, data.pv_pa + data.pv_size - 1, data.pv_va);
709 #endif
710
711 add_pages(bmi, &data);
712
713 #ifdef VERBOSE_INIT_ARM
714 printf("Listing Chunks\n");
715
716 pv_addr_t *lpv;
717 SLIST_FOREACH(lpv, &bmi->bmi_chunks, pv_list) {
718 printf("%s: pv %p: chunk VA %#lx..%#lx "
719 "(PA %#lx, prot %d, cache %d)\n",
720 __func__, lpv, lpv->pv_va, lpv->pv_va + lpv->pv_size - 1,
721 lpv->pv_pa, lpv->pv_prot, lpv->pv_cache);
722 }
723 printf("\nMapping Chunks\n");
724 #endif
725
726 pv_addr_t cur_pv;
727 pv_addr_t *pv = SLIST_FIRST(&bmi->bmi_chunks);
728 if (!mapallmem_p || pv->pv_pa == bmi->bmi_start) {
729 cur_pv = *pv;
730 KASSERTMSG(cur_pv.pv_va >= KERNEL_BASE, "%#lx", cur_pv.pv_va);
731 pv = SLIST_NEXT(pv, pv_list);
732 } else {
733 cur_pv.pv_va = KERNEL_BASE;
734 cur_pv.pv_pa = KERN_VTOPHYS(bmi, cur_pv.pv_va);
735 cur_pv.pv_size = pv->pv_pa - cur_pv.pv_pa;
736 cur_pv.pv_prot = VM_PROT_READ | VM_PROT_WRITE;
737 cur_pv.pv_cache = PTE_CACHE;
738 }
739 while (pv != NULL) {
740 if (mapallmem_p) {
741 if (concat_pvaddr(&cur_pv, pv)) {
742 pv = SLIST_NEXT(pv, pv_list);
743 continue;
744 }
745 if (cur_pv.pv_pa + cur_pv.pv_size < pv->pv_pa) {
746 /*
747 * See if we can extend the current pv to emcompass the
748 * hole, and if so do it and retry the concatenation.
749 */
750 if (cur_pv.pv_prot == (VM_PROT_READ|VM_PROT_WRITE)
751 && cur_pv.pv_cache == PTE_CACHE) {
752 cur_pv.pv_size = pv->pv_pa - cur_pv.pv_va;
753 continue;
754 }
755
756 /*
757 * We couldn't so emit the current chunk and then
758 */
759 #ifdef VERBOSE_INIT_ARM
760 printf("%s: mapping chunk VA %#lx..%#lx "
761 "(PA %#lx, prot %d, cache %d)\n",
762 __func__,
763 cur_pv.pv_va, cur_pv.pv_va + cur_pv.pv_size - 1,
764 cur_pv.pv_pa, cur_pv.pv_prot, cur_pv.pv_cache);
765 #endif
766 pmap_map_chunk(l1pt_va, cur_pv.pv_va, cur_pv.pv_pa,
767 cur_pv.pv_size, cur_pv.pv_prot, cur_pv.pv_cache);
768
769 /*
770 * set the current chunk to the hole and try again.
771 */
772 cur_pv.pv_pa += cur_pv.pv_size;
773 cur_pv.pv_va += cur_pv.pv_size;
774 cur_pv.pv_size = pv->pv_pa - cur_pv.pv_va;
775 cur_pv.pv_prot = VM_PROT_READ | VM_PROT_WRITE;
776 cur_pv.pv_cache = PTE_CACHE;
777 continue;
778 }
779 }
780
781 /*
782 * The new pv didn't concatenate so emit the current one
783 * and use the new pv as the current pv.
784 */
785 #ifdef VERBOSE_INIT_ARM
786 printf("%s: mapping chunk VA %#lx..%#lx "
787 "(PA %#lx, prot %d, cache %d)\n",
788 __func__, cur_pv.pv_va, cur_pv.pv_va + cur_pv.pv_size - 1,
789 cur_pv.pv_pa, cur_pv.pv_prot, cur_pv.pv_cache);
790 #endif
791 pmap_map_chunk(l1pt_va, cur_pv.pv_va, cur_pv.pv_pa,
792 cur_pv.pv_size, cur_pv.pv_prot, cur_pv.pv_cache);
793 cur_pv = *pv;
794 pv = SLIST_NEXT(pv, pv_list);
795 }
796
797 /*
798 * If we are mapping all of memory, let's map the rest of memory.
799 */
800 if (mapallmem_p && cur_pv.pv_pa + cur_pv.pv_size < bmi->bmi_end) {
801 if (cur_pv.pv_prot == (VM_PROT_READ | VM_PROT_WRITE)
802 && cur_pv.pv_cache == PTE_CACHE) {
803 cur_pv.pv_size = bmi->bmi_end - cur_pv.pv_pa;
804 } else {
805 KASSERTMSG(cur_pv.pv_va + cur_pv.pv_size <= kernel_vm_base,
806 "%#lx >= %#lx", cur_pv.pv_va + cur_pv.pv_size,
807 kernel_vm_base);
808 #ifdef VERBOSE_INIT_ARM
809 printf("%s: mapping chunk VA %#lx..%#lx "
810 "(PA %#lx, prot %d, cache %d)\n",
811 __func__, cur_pv.pv_va, cur_pv.pv_va + cur_pv.pv_size - 1,
812 cur_pv.pv_pa, cur_pv.pv_prot, cur_pv.pv_cache);
813 #endif
814 pmap_map_chunk(l1pt_va, cur_pv.pv_va, cur_pv.pv_pa,
815 cur_pv.pv_size, cur_pv.pv_prot, cur_pv.pv_cache);
816 cur_pv.pv_pa += cur_pv.pv_size;
817 cur_pv.pv_va += cur_pv.pv_size;
818 cur_pv.pv_size = bmi->bmi_end - cur_pv.pv_pa;
819 cur_pv.pv_prot = VM_PROT_READ | VM_PROT_WRITE;
820 cur_pv.pv_cache = PTE_CACHE;
821 }
822 }
823
824 // The amount we can direct is limited by the start of the
825 // virtual part of the kernel address space. Don't overrun
826 // into it.
827 if (mapallmem_p && cur_pv.pv_va + cur_pv.pv_size > kernel_vm_base) {
828 cur_pv.pv_size = kernel_vm_base - cur_pv.pv_va;
829 }
830
831 /*
832 * Now we map the final chunk.
833 */
834 #ifdef VERBOSE_INIT_ARM
835 printf("%s: mapping last chunk VA %#lx..%#lx (PA %#lx, prot %d, cache %d)\n",
836 __func__, cur_pv.pv_va, cur_pv.pv_va + cur_pv.pv_size - 1,
837 cur_pv.pv_pa, cur_pv.pv_prot, cur_pv.pv_cache);
838 #endif
839 pmap_map_chunk(l1pt_va, cur_pv.pv_va, cur_pv.pv_pa,
840 cur_pv.pv_size, cur_pv.pv_prot, cur_pv.pv_cache);
841
842 /*
843 * Now we map the stuff that isn't directly after the kernel
844 */
845 if (map_vectors_p) {
846 /* Map the vector page. */
847 pmap_map_entry(l1pt_va, systempage.pv_va, systempage.pv_pa,
848 VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE, PTE_CACHE);
849 }
850
851 /* Map the Mini-Data cache clean area. */
852 #if ARM_MMU_XSCALE == 1
853 #if (ARM_NMMUS > 1)
854 if (xscale_use_minidata)
855 #endif
856 xscale_setup_minidata(l1pt_va, minidataclean.pv_va,
857 minidataclean.pv_pa);
858 #endif
859
860 /*
861 * Map integrated peripherals at same address in first level page
862 * table so that we can continue to use console.
863 */
864 if (devmap)
865 pmap_devmap_bootstrap(l1pt_va, devmap);
866
867 #ifdef VERBOSE_INIT_ARM
868 /* Tell the user about where all the bits and pieces live. */
869 printf("%22s Physical Virtual Num\n", " ");
870 printf("%22s Starting Ending Starting Ending Pages\n", " ");
871
872 static const char mem_fmt[] =
873 "%20s: 0x%08lx 0x%08lx 0x%08lx 0x%08lx %u\n";
874 static const char mem_fmt_nov[] =
875 "%20s: 0x%08lx 0x%08lx %zu\n";
876
877 printf(mem_fmt, "SDRAM", bmi->bmi_start, bmi->bmi_end - 1,
878 KERN_PHYSTOV(bmi, bmi->bmi_start), KERN_PHYSTOV(bmi, bmi->bmi_end - 1),
879 (int)physmem);
880 printf(mem_fmt, "text section",
881 text.pv_pa, text.pv_pa + text.pv_size - 1,
882 text.pv_va, text.pv_va + text.pv_size - 1,
883 (int)(text.pv_size / PAGE_SIZE));
884 printf(mem_fmt, "data section",
885 KERN_VTOPHYS(bmi, __data_start), KERN_VTOPHYS(bmi, _edata),
886 (vaddr_t)__data_start, (vaddr_t)_edata,
887 (int)((round_page((vaddr_t)_edata)
888 - trunc_page((vaddr_t)__data_start)) / PAGE_SIZE));
889 printf(mem_fmt, "bss section",
890 KERN_VTOPHYS(bmi, __bss_start), KERN_VTOPHYS(bmi, __bss_end__),
891 (vaddr_t)__bss_start, (vaddr_t)__bss_end__,
892 (int)((round_page((vaddr_t)__bss_end__)
893 - trunc_page((vaddr_t)__bss_start)) / PAGE_SIZE));
894 printf(mem_fmt, "L1 page directory",
895 kernel_l1pt.pv_pa, kernel_l1pt.pv_pa + L1_TABLE_SIZE - 1,
896 kernel_l1pt.pv_va, kernel_l1pt.pv_va + L1_TABLE_SIZE - 1,
897 L1_TABLE_SIZE / PAGE_SIZE);
898 printf(mem_fmt, "ABT stack (CPU 0)",
899 abtstack.pv_pa, abtstack.pv_pa + (ABT_STACK_SIZE * PAGE_SIZE) - 1,
900 abtstack.pv_va, abtstack.pv_va + (ABT_STACK_SIZE * PAGE_SIZE) - 1,
901 ABT_STACK_SIZE);
902 printf(mem_fmt, "FIQ stack (CPU 0)",
903 fiqstack.pv_pa, fiqstack.pv_pa + (FIQ_STACK_SIZE * PAGE_SIZE) - 1,
904 fiqstack.pv_va, fiqstack.pv_va + (FIQ_STACK_SIZE * PAGE_SIZE) - 1,
905 FIQ_STACK_SIZE);
906 printf(mem_fmt, "IRQ stack (CPU 0)",
907 irqstack.pv_pa, irqstack.pv_pa + (IRQ_STACK_SIZE * PAGE_SIZE) - 1,
908 irqstack.pv_va, irqstack.pv_va + (IRQ_STACK_SIZE * PAGE_SIZE) - 1,
909 IRQ_STACK_SIZE);
910 printf(mem_fmt, "UND stack (CPU 0)",
911 undstack.pv_pa, undstack.pv_pa + (UND_STACK_SIZE * PAGE_SIZE) - 1,
912 undstack.pv_va, undstack.pv_va + (UND_STACK_SIZE * PAGE_SIZE) - 1,
913 UND_STACK_SIZE);
914 printf(mem_fmt, "IDLE stack (CPU 0)",
915 idlestack.pv_pa, idlestack.pv_pa + (UPAGES * PAGE_SIZE) - 1,
916 idlestack.pv_va, idlestack.pv_va + (UPAGES * PAGE_SIZE) - 1,
917 UPAGES);
918 printf(mem_fmt, "SVC stack",
919 kernelstack.pv_pa, kernelstack.pv_pa + (UPAGES * PAGE_SIZE) - 1,
920 kernelstack.pv_va, kernelstack.pv_va + (UPAGES * PAGE_SIZE) - 1,
921 UPAGES);
922 printf(mem_fmt, "Message Buffer",
923 msgbuf.pv_pa, msgbuf.pv_pa + (msgbuf_pgs * PAGE_SIZE) - 1,
924 msgbuf.pv_va, msgbuf.pv_va + (msgbuf_pgs * PAGE_SIZE) - 1,
925 (int)msgbuf_pgs);
926 if (map_vectors_p) {
927 printf(mem_fmt, "Exception Vectors",
928 systempage.pv_pa, systempage.pv_pa + PAGE_SIZE - 1,
929 systempage.pv_va, systempage.pv_va + PAGE_SIZE - 1,
930 1);
931 }
932 for (size_t i = 0; i < bmi->bmi_nfreeblocks; i++) {
933 pv = &bmi->bmi_freeblocks[i];
934
935 printf(mem_fmt_nov, "Free Memory",
936 pv->pv_pa, pv->pv_pa + pv->pv_size - 1,
937 pv->pv_size / PAGE_SIZE);
938 }
939 #endif
940 /*
941 * Now we have the real page tables in place so we can switch to them.
942 * Once this is done we will be running with the REAL kernel page
943 * tables.
944 */
945
946 #if defined(VERBOSE_INIT_ARM)
947 printf("TTBR0=%#x", armreg_ttbr_read());
948 #ifdef _ARM_ARCH_6
949 printf(" TTBR1=%#x TTBCR=%#x CONTEXTIDR=%#x",
950 armreg_ttbr1_read(), armreg_ttbcr_read(),
951 armreg_contextidr_read());
952 #endif
953 printf("\n");
954 #endif
955
956 /* Switch tables */
957 #ifdef VERBOSE_INIT_ARM
958 printf("switching to new L1 page table @%#lx...", l1pt_pa);
959 #endif
960
961 #ifdef ARM_MMU_EXTENDED
962 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2))
963 | (DOMAIN_CLIENT << (PMAP_DOMAIN_USER*2)));
964 #else
965 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
966 #endif
967 cpu_idcache_wbinv_all();
968 #ifdef VERBOSE_INIT_ARM
969 printf(" ttb");
970 #endif
971 #ifdef ARM_MMU_EXTENDED
972 /*
973 * TTBCR should have been initialized by the MD start code.
974 */
975 KASSERT((armreg_contextidr_read() & 0xff) == 0);
976 KASSERT(armreg_ttbcr_read() == __SHIFTIN(1, TTBCR_S_N));
977 /*
978 * Disable lookups via TTBR0 until there is an activated pmap.
979 */
980 armreg_ttbcr_write(armreg_ttbcr_read() | TTBCR_S_PD0);
981 cpu_setttb(l1pt_pa, KERNEL_PID);
982 arm_isb();
983 #else
984 cpu_setttb(l1pt_pa, true);
985 cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
986 #endif
987 cpu_tlb_flushID();
988
989 #ifdef VERBOSE_INIT_ARM
990 #ifdef ARM_MMU_EXTENDED
991 printf(" (TTBCR=%#x TTBR0=%#x TTBR1=%#x)",
992 armreg_ttbcr_read(), armreg_ttbr_read(), armreg_ttbr1_read());
993 #else
994 printf(" (TTBR0=%#x)", armreg_ttbr_read());
995 #endif
996 #endif
997
998 #ifdef MULTIPROCESSOR
999 /*
1000 * Kick the secondaries to load the TTB. After which they'll go
1001 * back to sleep to wait for the final kick so they will hatch.
1002 */
1003 #ifdef VERBOSE_INIT_ARM
1004 printf(" hatchlings");
1005 #endif
1006 cpu_boot_secondary_processors();
1007 #endif
1008
1009 #ifdef VERBOSE_INIT_ARM
1010 printf(" OK\n");
1011 #endif
1012 }
1013