]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/arm/at91/at91_machdep.c
Merge OpenSSL 1.0.2d.
[FreeBSD/FreeBSD.git] / sys / arm / at91 / at91_machdep.c
1 /*-
2  * Copyright (c) 1994-1998 Mark Brinicombe.
3  * Copyright (c) 1994 Brini.
4  * All rights reserved.
5  *
6  * This code is derived from software written for Brini by Mark Brinicombe
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *      This product includes software developed by Brini.
19  * 4. The name of the company nor the name of the author may be used to
20  *    endorse or promote products derived from this software without specific
21  *    prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED
24  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26  * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  *
35  * RiscBSD kernel project
36  *
37  * machdep.c
38  *
39  * Machine dependant functions for kernel setup
40  *
41  * This file needs a lot of work.
42  *
43  * Created      : 17/09/94
44  */
45
46 #include "opt_kstack_pages.h"
47 #include "opt_platform.h"
48
49 #include <sys/cdefs.h>
50 __FBSDID("$FreeBSD$");
51
52 #define _ARM32_BUS_DMA_PRIVATE
53 #include <sys/param.h>
54 #include <sys/systm.h>
55 #include <sys/sysproto.h>
56 #include <sys/signalvar.h>
57 #include <sys/imgact.h>
58 #include <sys/kernel.h>
59 #include <sys/ktr.h>
60 #include <sys/linker.h>
61 #include <sys/lock.h>
62 #include <sys/malloc.h>
63 #include <sys/mutex.h>
64 #include <sys/pcpu.h>
65 #include <sys/proc.h>
66 #include <sys/ptrace.h>
67 #include <sys/cons.h>
68 #include <sys/bio.h>
69 #include <sys/bus.h>
70 #include <sys/buf.h>
71 #include <sys/exec.h>
72 #include <sys/kdb.h>
73 #include <sys/msgbuf.h>
74 #include <machine/physmem.h>
75 #include <machine/reg.h>
76 #include <machine/cpu.h>
77 #include <machine/board.h>
78
79 #include <vm/vm.h>
80 #include <vm/pmap.h>
81 #include <vm/vm_object.h>
82 #include <vm/vm_page.h>
83 #include <vm/vm_map.h>
84 #include <machine/devmap.h>
85 #include <machine/vmparam.h>
86 #include <machine/pcb.h>
87 #include <machine/undefined.h>
88 #include <machine/machdep.h>
89 #include <machine/metadata.h>
90 #include <machine/armreg.h>
91 #include <machine/bus.h>
92 #include <sys/reboot.h>
93
94 #include <arm/at91/at91board.h>
95 #include <arm/at91/at91var.h>
96 #include <arm/at91/at91soc.h>
97 #include <arm/at91/at91_usartreg.h>
98 #include <arm/at91/at91rm92reg.h>
99 #include <arm/at91/at91sam9g20reg.h>
100 #include <arm/at91/at91sam9g45reg.h>
101
102 #ifndef MAXCPU
103 #define MAXCPU 1
104 #endif
105
106 /* Page table for mapping proc0 zero page */
107 #define KERNEL_PT_SYS           0
108 #define KERNEL_PT_KERN          1
109 #define KERNEL_PT_KERN_NUM      22
110 /* L2 table for mapping after kernel */
111 #define KERNEL_PT_AFKERNEL      KERNEL_PT_KERN + KERNEL_PT_KERN_NUM
112 #define KERNEL_PT_AFKERNEL_NUM  5
113
114 /* this should be evenly divisable by PAGE_SIZE / L2_TABLE_SIZE_REAL (or 4) */
115 #define NUM_KERNEL_PTS          (KERNEL_PT_AFKERNEL + KERNEL_PT_AFKERNEL_NUM)
116
117 extern struct bus_space at91_bs_tag;
118
119 struct pv_addr kernel_pt_table[NUM_KERNEL_PTS];
120
121 /* Static device mappings. */
122 const struct arm_devmap_entry at91_devmap[] = {
123         /*
124          * Map the critical on-board devices. The interrupt vector at
125          * 0xffff0000 makes it impossible to map them PA == VA, so we map all
126          * 0xfffxxxxx addresses to 0xdffxxxxx. This covers all critical devices
127          * on all members of the AT91SAM9 and AT91RM9200 families.
128          */
129         {
130                 0xdff00000,
131                 0xfff00000,
132                 0x00100000,
133                 VM_PROT_READ|VM_PROT_WRITE,
134                 PTE_DEVICE,
135         },
136         /* There's a notion that we should do the rest of these lazily. */
137         /*
138          * We can't just map the OHCI registers VA == PA, because
139          * AT91xx_xxx_BASE belongs to the userland address space.
140          * We could just choose a different virtual address, but a better
141          * solution would probably be to just use pmap_mapdev() to allocate
142          * KVA, as we don't need the OHCI controller before the vm
143          * initialization is done. However, the AT91 resource allocation
144          * system doesn't know how to use pmap_mapdev() yet.
145          * Care must be taken to ensure PA and VM address do not overlap
146          * between entries.
147          */
148         {
149                 /*
150                  * Add the ohci controller, and anything else that might be
151                  * on this chip select for a VA/PA mapping.
152                  */
153                 /* Internal Memory 1MB  */
154                 AT91RM92_OHCI_VA_BASE,
155                 AT91RM92_OHCI_BASE,
156                 0x00100000,
157                 VM_PROT_READ|VM_PROT_WRITE,
158                 PTE_DEVICE,
159         },
160         {
161                 /* CompactFlash controller. Portion of EBI CS4 1MB */
162                 AT91RM92_CF_VA_BASE,
163                 AT91RM92_CF_BASE,
164                 0x00100000,
165                 VM_PROT_READ|VM_PROT_WRITE,
166                 PTE_DEVICE,
167         },
168         /*
169          * The next two should be good for the 9260, 9261 and 9G20 since
170          * addresses mapping is the same.
171          */
172         {
173                 /* Internal Memory 1MB  */
174                 AT91SAM9G20_OHCI_VA_BASE,
175                 AT91SAM9G20_OHCI_BASE,
176                 0x00100000,
177                 VM_PROT_READ|VM_PROT_WRITE,
178                 PTE_DEVICE,
179         },
180         {
181                 /* EBI CS3 256MB */
182                 AT91SAM9G20_NAND_VA_BASE,
183                 AT91SAM9G20_NAND_BASE,
184                 AT91SAM9G20_NAND_SIZE,
185                 VM_PROT_READ|VM_PROT_WRITE,
186                 PTE_DEVICE,
187         },
188         /*
189          * The next should be good for the 9G45.
190          */
191         {
192                 /* Internal Memory 1MB  */
193                 AT91SAM9G45_OHCI_VA_BASE,
194                 AT91SAM9G45_OHCI_BASE,
195                 0x00100000,
196                 VM_PROT_READ|VM_PROT_WRITE,
197                 PTE_DEVICE,
198         },
199         { 0, 0, 0, 0, 0, }
200 };
201
202 #ifdef LINUX_BOOT_ABI
203 extern int membanks;
204 extern int memstart[];
205 extern int memsize[];
206 #endif
207
208 long
209 at91_ramsize(void)
210 {
211         uint32_t cr, mdr, mr, *SDRAMC;
212         int banks, rows, cols, bw;
213 #ifdef LINUX_BOOT_ABI
214         /*
215          * If we found any ATAGs that were for memory, return the first bank.
216          */
217         if (membanks > 0)
218                 return (memsize[0]);
219 #endif
220
221         if (at91_is_rm92()) {
222                 SDRAMC = (uint32_t *)(AT91_BASE + AT91RM92_SDRAMC_BASE);
223                 cr = SDRAMC[AT91RM92_SDRAMC_CR / 4];
224                 mr = SDRAMC[AT91RM92_SDRAMC_MR / 4];
225                 banks = (cr & AT91RM92_SDRAMC_CR_NB_4) ? 2 : 1;
226                 rows = ((cr & AT91RM92_SDRAMC_CR_NR_MASK) >> 2) + 11;
227                 cols = (cr & AT91RM92_SDRAMC_CR_NC_MASK) + 8;
228                 bw = (mr & AT91RM92_SDRAMC_MR_DBW_16) ? 1 : 2;
229         } else if (at91_cpu_is(AT91_T_SAM9G45)) {
230                 SDRAMC = (uint32_t *)(AT91_BASE + AT91SAM9G45_DDRSDRC0_BASE);
231                 cr = SDRAMC[AT91SAM9G45_DDRSDRC_CR / 4];
232                 mdr = SDRAMC[AT91SAM9G45_DDRSDRC_MDR / 4];
233                 banks = 0;
234                 rows = ((cr & AT91SAM9G45_DDRSDRC_CR_NR_MASK) >> 2) + 11;
235                 cols = (cr & AT91SAM9G45_DDRSDRC_CR_NC_MASK) + 8;
236                 bw = (mdr & AT91SAM9G45_DDRSDRC_MDR_DBW_16) ? 1 : 2;
237
238                 /* Fix the calculation for DDR memory */
239                 mdr &= AT91SAM9G45_DDRSDRC_MDR_MASK;
240                 if (mdr & AT91SAM9G45_DDRSDRC_MDR_LPDDR1 ||
241                     mdr & AT91SAM9G45_DDRSDRC_MDR_DDR2) {
242                         /* The cols value is 1 higher for DDR */
243                         cols += 1;
244                         /* DDR has 4 internal banks. */
245                         banks = 2;
246                 }
247         } else {
248                 /*
249                  * This should be good for the 9260, 9261, 9G20, 9G35 and 9X25
250                  * as addresses and registers are the same.
251                  */
252                 SDRAMC = (uint32_t *)(AT91_BASE + AT91SAM9G20_SDRAMC_BASE);
253                 cr = SDRAMC[AT91SAM9G20_SDRAMC_CR / 4];
254                 mr = SDRAMC[AT91SAM9G20_SDRAMC_MR / 4];
255                 banks = (cr & AT91SAM9G20_SDRAMC_CR_NB_4) ? 2 : 1;
256                 rows = ((cr & AT91SAM9G20_SDRAMC_CR_NR_MASK) >> 2) + 11;
257                 cols = (cr & AT91SAM9G20_SDRAMC_CR_NC_MASK) + 8;
258                 bw = (cr & AT91SAM9G20_SDRAMC_CR_DBW_16) ? 1 : 2;
259         }
260
261         return (1 << (cols + rows + banks + bw));
262 }
263
264 static const char *soc_type_name[] = {
265         [AT91_T_CAP9] = "at91cap9",
266         [AT91_T_RM9200] = "at91rm9200",
267         [AT91_T_SAM9260] = "at91sam9260",
268         [AT91_T_SAM9261] = "at91sam9261",
269         [AT91_T_SAM9263] = "at91sam9263",
270         [AT91_T_SAM9G10] = "at91sam9g10",
271         [AT91_T_SAM9G20] = "at91sam9g20",
272         [AT91_T_SAM9G45] = "at91sam9g45",
273         [AT91_T_SAM9N12] = "at91sam9n12",
274         [AT91_T_SAM9RL] = "at91sam9rl",
275         [AT91_T_SAM9X5] = "at91sam9x5",
276         [AT91_T_NONE] = "UNKNOWN"
277 };
278
279 static const char *soc_subtype_name[] = {
280         [AT91_ST_NONE] = "UNKNOWN",
281         [AT91_ST_RM9200_BGA] = "at91rm9200_bga",
282         [AT91_ST_RM9200_PQFP] = "at91rm9200_pqfp",
283         [AT91_ST_SAM9XE] = "at91sam9xe",
284         [AT91_ST_SAM9G45] = "at91sam9g45",
285         [AT91_ST_SAM9M10] = "at91sam9m10",
286         [AT91_ST_SAM9G46] = "at91sam9g46",
287         [AT91_ST_SAM9M11] = "at91sam9m11",
288         [AT91_ST_SAM9G15] = "at91sam9g15",
289         [AT91_ST_SAM9G25] = "at91sam9g25",
290         [AT91_ST_SAM9G35] = "at91sam9g35",
291         [AT91_ST_SAM9X25] = "at91sam9x25",
292         [AT91_ST_SAM9X35] = "at91sam9x35",
293 };
294
295 struct at91_soc_info soc_info;
296
297 /*
298  * Read the SoC ID from the CIDR register and try to match it against the
299  * values we know.  If we find a good one, we return true.  If not, we
300  * return false.  When we find a good one, we also find the subtype
301  * and CPU family.
302  */
303 static int
304 at91_try_id(uint32_t dbgu_base)
305 {
306         uint32_t socid;
307
308         soc_info.cidr = *(volatile uint32_t *)(AT91_BASE + dbgu_base +
309             DBGU_C1R);
310         socid = soc_info.cidr & ~AT91_CPU_VERSION_MASK;
311
312         soc_info.type = AT91_T_NONE;
313         soc_info.subtype = AT91_ST_NONE;
314         soc_info.family = (soc_info.cidr & AT91_CPU_FAMILY_MASK) >> 20;
315         soc_info.exid = *(volatile uint32_t *)(AT91_BASE + dbgu_base +
316             DBGU_C2R);
317
318         switch (socid) {
319         case AT91_CPU_CAP9:
320                 soc_info.type = AT91_T_CAP9;
321                 break;
322         case AT91_CPU_RM9200:
323                 soc_info.type = AT91_T_RM9200;
324                 break;
325         case AT91_CPU_SAM9XE128:
326         case AT91_CPU_SAM9XE256:
327         case AT91_CPU_SAM9XE512:
328         case AT91_CPU_SAM9260:
329                 soc_info.type = AT91_T_SAM9260;
330                 if (soc_info.family == AT91_FAMILY_SAM9XE)
331                         soc_info.subtype = AT91_ST_SAM9XE;
332                 break;
333         case AT91_CPU_SAM9261:
334                 soc_info.type = AT91_T_SAM9261;
335                 break;
336         case AT91_CPU_SAM9263:
337                 soc_info.type = AT91_T_SAM9263;
338                 break;
339         case AT91_CPU_SAM9G10:
340                 soc_info.type = AT91_T_SAM9G10;
341                 break;
342         case AT91_CPU_SAM9G20:
343                 soc_info.type = AT91_T_SAM9G20;
344                 break;
345         case AT91_CPU_SAM9G45:
346                 soc_info.type = AT91_T_SAM9G45;
347                 break;
348         case AT91_CPU_SAM9N12:
349                 soc_info.type = AT91_T_SAM9N12;
350                 break;
351         case AT91_CPU_SAM9RL64:
352                 soc_info.type = AT91_T_SAM9RL;
353                 break;
354         case AT91_CPU_SAM9X5:
355                 soc_info.type = AT91_T_SAM9X5;
356                 break;
357         default:
358                 return (0);
359         }
360
361         switch (soc_info.type) {
362         case AT91_T_SAM9G45:
363                 switch (soc_info.exid) {
364                 case AT91_EXID_SAM9G45:
365                         soc_info.subtype = AT91_ST_SAM9G45;
366                         break;
367                 case AT91_EXID_SAM9G46:
368                         soc_info.subtype = AT91_ST_SAM9G46;
369                         break;
370                 case AT91_EXID_SAM9M10:
371                         soc_info.subtype = AT91_ST_SAM9M10;
372                         break;
373                 case AT91_EXID_SAM9M11:
374                         soc_info.subtype = AT91_ST_SAM9M11;
375                         break;
376                 }
377                 break;
378         case AT91_T_SAM9X5:
379                 switch (soc_info.exid) {
380                 case AT91_EXID_SAM9G15:
381                         soc_info.subtype = AT91_ST_SAM9G15;
382                         break;
383                 case AT91_EXID_SAM9G25:
384                         soc_info.subtype = AT91_ST_SAM9G25;
385                         break;
386                 case AT91_EXID_SAM9G35:
387                         soc_info.subtype = AT91_ST_SAM9G35;
388                         break;
389                 case AT91_EXID_SAM9X25:
390                         soc_info.subtype = AT91_ST_SAM9X25;
391                         break;
392                 case AT91_EXID_SAM9X35:
393                         soc_info.subtype = AT91_ST_SAM9X35;
394                         break;
395                 }
396                 break;
397         default:
398                 break;
399         }
400         /*
401          * Disable interrupts in the DBGU unit...
402          */
403         *(volatile uint32_t *)(AT91_BASE + dbgu_base + USART_IDR) = 0xffffffff;
404
405         /*
406          * Save the name for later...
407          */
408         snprintf(soc_info.name, sizeof(soc_info.name), "%s%s%s",
409             soc_type_name[soc_info.type],
410             soc_info.subtype == AT91_ST_NONE ? "" : " subtype ",
411             soc_info.subtype == AT91_ST_NONE ? "" :
412             soc_subtype_name[soc_info.subtype]);
413
414         /*
415          * try to get the matching CPU support.
416          */
417         soc_info.soc_data = at91_match_soc(soc_info.type, soc_info.subtype);
418         soc_info.dbgu_base = AT91_BASE + dbgu_base;
419
420         return (1);
421 }
422
423 void
424 at91_soc_id(void)
425 {
426
427         if (!at91_try_id(AT91_DBGU0))
428                 at91_try_id(AT91_DBGU1);
429 }
430
431 #ifdef ARM_MANY_BOARD
432 /* likely belongs in arm/arm/machdep.c, but since board_init is still at91 only... */
433 SET_DECLARE(arm_board_set, const struct arm_board);
434
435 /* Not yet fully functional, but enough to build ATMEL config */
436 static long
437 board_init(void)
438 {
439         return -1;
440 }
441 #endif
442
443 #ifndef FDT
444 /* Physical and virtual addresses for some global pages */
445
446 struct pv_addr msgbufpv;
447 struct pv_addr kernelstack;
448 struct pv_addr systempage;
449 struct pv_addr irqstack;
450 struct pv_addr abtstack;
451 struct pv_addr undstack;
452
453 void *
454 initarm(struct arm_boot_params *abp)
455 {
456         struct pv_addr  kernel_l1pt;
457         struct pv_addr  dpcpu;
458         int i;
459         u_int l1pagetable;
460         vm_offset_t freemempos;
461         vm_offset_t afterkern;
462         uint32_t memsize;
463         vm_offset_t lastaddr;
464
465         lastaddr = parse_boot_param(abp);
466         arm_physmem_kernaddr = abp->abp_physaddr;
467         set_cpufuncs();
468         pcpu0_init();
469
470         /* Do basic tuning, hz etc */
471         init_param1();
472
473         freemempos = (lastaddr + PAGE_MASK) & ~PAGE_MASK;
474         /* Define a macro to simplify memory allocation */
475 #define valloc_pages(var, np)                                           \
476         alloc_pages((var).pv_va, (np));                                 \
477         (var).pv_pa = (var).pv_va + (abp->abp_physaddr - KERNVIRTADDR);
478
479 #define alloc_pages(var, np)                                            \
480         (var) = freemempos;                                             \
481         freemempos += (np * PAGE_SIZE);                                 \
482         memset((char *)(var), 0, ((np) * PAGE_SIZE));
483
484         while (((freemempos - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) != 0)
485                 freemempos += PAGE_SIZE;
486         valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
487         for (i = 0; i < NUM_KERNEL_PTS; ++i) {
488                 if (!(i % (PAGE_SIZE / L2_TABLE_SIZE_REAL))) {
489                         valloc_pages(kernel_pt_table[i],
490                             L2_TABLE_SIZE / PAGE_SIZE);
491                 } else {
492                         kernel_pt_table[i].pv_va = freemempos -
493                             (i % (PAGE_SIZE / L2_TABLE_SIZE_REAL)) *
494                             L2_TABLE_SIZE_REAL;
495                         kernel_pt_table[i].pv_pa =
496                             kernel_pt_table[i].pv_va - KERNVIRTADDR +
497                             abp->abp_physaddr;
498                 }
499         }
500         /*
501          * Allocate a page for the system page mapped to 0x00000000
502          * or 0xffff0000. This page will just contain the system vectors
503          * and can be shared by all processes.
504          */
505         valloc_pages(systempage, 1);
506
507         /* Allocate dynamic per-cpu area. */
508         valloc_pages(dpcpu, DPCPU_SIZE / PAGE_SIZE);
509         dpcpu_init((void *)dpcpu.pv_va, 0);
510
511         /* Allocate stacks for all modes */
512         valloc_pages(irqstack, IRQ_STACK_SIZE * MAXCPU);
513         valloc_pages(abtstack, ABT_STACK_SIZE * MAXCPU);
514         valloc_pages(undstack, UND_STACK_SIZE * MAXCPU);
515         valloc_pages(kernelstack, kstack_pages * MAXCPU);
516         valloc_pages(msgbufpv, round_page(msgbufsize) / PAGE_SIZE);
517
518         /*
519          * Now we start construction of the L1 page table
520          * We start by mapping the L2 page tables into the L1.
521          * This means that we can replace L1 mappings later on if necessary
522          */
523         l1pagetable = kernel_l1pt.pv_va;
524
525         /* Map the L2 pages tables in the L1 page table */
526         pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH,
527             &kernel_pt_table[KERNEL_PT_SYS]);
528         for (i = 0; i < KERNEL_PT_KERN_NUM; i++)
529                 pmap_link_l2pt(l1pagetable, KERNBASE + i * L1_S_SIZE,
530                     &kernel_pt_table[KERNEL_PT_KERN + i]);
531         pmap_map_chunk(l1pagetable, KERNBASE, PHYSADDR,
532            (((uint32_t)lastaddr - KERNBASE) + PAGE_SIZE) & ~(PAGE_SIZE - 1),
533             VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
534         afterkern = round_page((lastaddr + L1_S_SIZE) & ~(L1_S_SIZE - 1));
535         for (i = 0; i < KERNEL_PT_AFKERNEL_NUM; i++) {
536                 pmap_link_l2pt(l1pagetable, afterkern + i * L1_S_SIZE,
537                     &kernel_pt_table[KERNEL_PT_AFKERNEL + i]);
538         }
539
540         /* Map the vector page. */
541         pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa,
542             VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
543
544         /* Map the DPCPU pages */
545         pmap_map_chunk(l1pagetable, dpcpu.pv_va, dpcpu.pv_pa, DPCPU_SIZE,
546             VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
547
548         /* Map the stack pages */
549         pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
550             IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
551         pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
552             ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
553         pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
554             UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
555         pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
556             kstack_pages * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
557
558         pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
559             L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
560         pmap_map_chunk(l1pagetable, msgbufpv.pv_va, msgbufpv.pv_pa,
561             msgbufsize, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
562
563         for (i = 0; i < NUM_KERNEL_PTS; ++i) {
564                 pmap_map_chunk(l1pagetable, kernel_pt_table[i].pv_va,
565                     kernel_pt_table[i].pv_pa, L2_TABLE_SIZE,
566                     VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
567         }
568
569         arm_devmap_bootstrap(l1pagetable, at91_devmap);
570         cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL * 2)) | DOMAIN_CLIENT);
571         setttb(kernel_l1pt.pv_pa);
572         cpu_tlb_flushID();
573         cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL * 2));
574
575         at91_soc_id();
576
577         /*
578          * Initialize all the clocks, so that the console can work.  We can only
579          * do this if at91_soc_id() was able to fill in the support data.  Even
580          * if we can't init the clocks, still try to do a console init so we can
581          * try to print the error message about missing soc support.  There's a
582          * chance the printf will work if the bootloader set up the DBGU.
583          */
584         if (soc_info.soc_data != NULL) {
585                 soc_info.soc_data->soc_clock_init();
586                 at91_pmc_init_clock();
587         }
588
589         cninit();
590
591         if (soc_info.soc_data == NULL)
592                 printf("Warning: No soc support for %s found.\n", soc_info.name);
593
594         memsize = board_init();
595         if (memsize == -1) {
596                 printf("board_init() failed, cannot determine ram size; "
597                     "assuming 16MB\n");
598                 memsize = 16 * 1024 * 1024;
599         }
600
601         /*
602          * Pages were allocated during the secondary bootstrap for the
603          * stacks for different CPU modes.
604          * We must now set the r13 registers in the different CPU modes to
605          * point to these stacks.
606          * Since the ARM stacks use STMFD etc. we must set r13 to the top end
607          * of the stack memory.
608          */
609         cpu_control(CPU_CONTROL_MMU_ENABLE, CPU_CONTROL_MMU_ENABLE);
610         cpu_setup();
611
612         set_stackptrs(0);
613
614         /*
615          * We must now clean the cache again....
616          * Cleaning may be done by reading new data to displace any
617          * dirty data in the cache. This will have happened in setttb()
618          * but since we are boot strapping the addresses used for the read
619          * may have just been remapped and thus the cache could be out
620          * of sync. A re-clean after the switch will cure this.
621          * After booting there are no gross relocations of the kernel thus
622          * this problem will not occur after initarm().
623          */
624         cpu_idcache_wbinv_all();
625
626         undefined_init();
627
628         init_proc0(kernelstack.pv_va);
629
630         arm_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
631
632         pmap_curmaxkvaddr = afterkern + L1_S_SIZE * (KERNEL_PT_KERN_NUM - 1);
633         /* Always use the 256MB of KVA we have available between the kernel and devices */
634         vm_max_kernel_address = KERNVIRTADDR + (256 << 20);
635         pmap_bootstrap(freemempos, &kernel_l1pt);
636         msgbufp = (void*)msgbufpv.pv_va;
637         msgbufinit(msgbufp, msgbufsize);
638         mutex_init();
639
640         /*
641          * Add the physical ram we have available.
642          *
643          * Exclude the kernel, and all the things we allocated which immediately
644          * follow the kernel, from the VM allocation pool but not from crash
645          * dumps.  virtual_avail is a global variable which tracks the kva we've
646          * "allocated" while setting up pmaps.
647          *
648          * Prepare the list of physical memory available to the vm subsystem.
649          */
650         arm_physmem_hardware_region(PHYSADDR, memsize);
651         arm_physmem_exclude_region(abp->abp_physaddr, 
652             virtual_avail - KERNVIRTADDR, EXFLAG_NOALLOC);
653         arm_physmem_init_kernel_globals();
654
655         init_param2(physmem);
656         kdb_init();
657         return ((void *)(kernelstack.pv_va + USPACE_SVC_STACK_TOP -
658             sizeof(struct pcb)));
659 }
660 #endif
661
662 /*
663  * These functions are handled elsewhere, so make them nops here.
664  */
665 void
666 cpu_startprofclock(void)
667 {
668
669 }
670
671 void
672 cpu_stopprofclock(void)
673 {
674
675 }
676
677 void
678 cpu_initclocks(void)
679 {
680
681 }
682
683 void
684 DELAY(int n)
685 {
686
687         if (soc_info.soc_data)
688                 soc_info.soc_data->soc_delay(n);
689 }
690
691 void
692 cpu_reset(void)
693 {
694
695         if (soc_info.soc_data)
696                 soc_info.soc_data->soc_reset();
697         while (1)
698                 continue;
699 }