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