board_bwct.c revision 160363
1155324Simp/*- 2155324Simp * Copyright (c) 1994-1998 Mark Brinicombe. 3155324Simp * Copyright (c) 1994 Brini. 4155324Simp * All rights reserved. 5155324Simp * 6155324Simp * This code is derived from software written for Brini by Mark Brinicombe 7155324Simp * 8155324Simp * Redistribution and use in source and binary forms, with or without 9155324Simp * modification, are permitted provided that the following conditions 10155324Simp * are met: 11155324Simp * 1. Redistributions of source code must retain the above copyright 12155324Simp * notice, this list of conditions and the following disclaimer. 13155324Simp * 2. Redistributions in binary form must reproduce the above copyright 14155324Simp * notice, this list of conditions and the following disclaimer in the 15155324Simp * documentation and/or other materials provided with the distribution. 16155324Simp * 3. All advertising materials mentioning features or use of this software 17155324Simp * must display the following acknowledgement: 18155324Simp * This product includes software developed by Brini. 19155324Simp * 4. The name of the company nor the name of the author may be used to 20155324Simp * endorse or promote products derived from this software without specific 21155324Simp * prior written permission. 22155324Simp * 23155324Simp * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED 24155324Simp * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 25155324Simp * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26155324Simp * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27155324Simp * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28155324Simp * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29155324Simp * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30155324Simp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31155324Simp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32155324Simp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33155324Simp * SUCH DAMAGE. 34155324Simp * 35155324Simp * RiscBSD kernel project 36155324Simp * 37155324Simp * machdep.c 38155324Simp * 39155324Simp * Machine dependant functions for kernel setup 40155324Simp * 41155324Simp * This file needs a lot of work. 42155324Simp * 43155324Simp * Created : 17/09/94 44155324Simp */ 45155324Simp 46155324Simp#include "opt_msgbuf.h" 47155324Simp#include "opt_ddb.h" 48160363Simp#include "opt_at91.h" 49155324Simp 50155324Simp#include <sys/cdefs.h> 51155324Simp__FBSDID("$FreeBSD: head/sys/arm/at91/kb920x_machdep.c 160363 2006-07-14 22:22:57Z imp $"); 52155324Simp 53155324Simp#define _ARM32_BUS_DMA_PRIVATE 54155324Simp#include <sys/param.h> 55155324Simp#include <sys/systm.h> 56155324Simp#include <sys/sysproto.h> 57155324Simp#include <sys/signalvar.h> 58155324Simp#include <sys/imgact.h> 59155324Simp#include <sys/kernel.h> 60155324Simp#include <sys/ktr.h> 61155324Simp#include <sys/linker.h> 62155324Simp#include <sys/lock.h> 63155324Simp#include <sys/malloc.h> 64155324Simp#include <sys/mutex.h> 65155324Simp#include <sys/pcpu.h> 66155324Simp#include <sys/proc.h> 67155324Simp#include <sys/ptrace.h> 68155324Simp#include <sys/cons.h> 69155324Simp#include <sys/bio.h> 70155324Simp#include <sys/bus.h> 71155324Simp#include <sys/buf.h> 72155324Simp#include <sys/exec.h> 73155324Simp#include <sys/kdb.h> 74155324Simp#include <sys/msgbuf.h> 75155324Simp#include <machine/reg.h> 76155324Simp#include <machine/cpu.h> 77155324Simp 78155324Simp#include <vm/vm.h> 79155324Simp#include <vm/pmap.h> 80155324Simp#include <vm/vm.h> 81155324Simp#include <vm/vm_object.h> 82155324Simp#include <vm/vm_page.h> 83155324Simp#include <vm/vm_pager.h> 84155324Simp#include <vm/vm_map.h> 85155324Simp#include <vm/vnode_pager.h> 86155324Simp#include <machine/pmap.h> 87155324Simp#include <machine/vmparam.h> 88155324Simp#include <machine/pcb.h> 89155324Simp#include <machine/undefined.h> 90155324Simp#include <machine/machdep.h> 91155324Simp#include <machine/metadata.h> 92155324Simp#include <machine/armreg.h> 93155324Simp#include <machine/bus.h> 94155324Simp#include <sys/reboot.h> 95155324Simp 96155324Simp#include <arm/at91/at91rm92reg.h> 97160363Simp#include <arm/at91/at91_piovar.h> 98160363Simp#include <arm/at91/at91_pio_rm9200.h> 99155324Simp 100155324Simp#define KERNEL_PT_SYS 0 /* Page table for mapping proc0 zero page */ 101155324Simp#define KERNEL_PT_KERN 1 102159556Scognet#define KERNEL_PT_KERN_NUM 22 103155324Simp#define KERNEL_PT_AFKERNEL KERNEL_PT_KERN + KERNEL_PT_KERN_NUM /* L2 table for mapping after kernel */ 104155324Simp#define KERNEL_PT_AFKERNEL_NUM 5 105155324Simp 106155324Simp/* this should be evenly divisable by PAGE_SIZE / L2_TABLE_SIZE_REAL (or 4) */ 107155324Simp#define NUM_KERNEL_PTS (KERNEL_PT_AFKERNEL + KERNEL_PT_AFKERNEL_NUM) 108155324Simp 109155324Simp/* Define various stack sizes in pages */ 110155324Simp#define IRQ_STACK_SIZE 1 111155324Simp#define ABT_STACK_SIZE 1 112155324Simp#define UND_STACK_SIZE 1 113155324Simp 114155324Simpextern u_int data_abort_handler_address; 115155324Simpextern u_int prefetch_abort_handler_address; 116155324Simpextern u_int undefined_handler_address; 117155324Simp 118155324Simpstruct pv_addr kernel_pt_table[NUM_KERNEL_PTS]; 119155324Simp 120155324Simpextern void *_end; 121155324Simp 122155324Simpextern int *end; 123155324Simp 124155324Simpstruct pcpu __pcpu; 125155324Simpstruct pcpu *pcpup = &__pcpu; 126155324Simp 127155324Simp/* Physical and virtual addresses for some global pages */ 128155324Simp 129155324Simpvm_paddr_t phys_avail[10]; 130155324Simpvm_paddr_t dump_avail[4]; 131155324Simpvm_offset_t physical_pages; 132155324Simpvm_offset_t clean_sva, clean_eva; 133155324Simp 134155324Simpstruct pv_addr systempage; 135155324Simpstruct pv_addr msgbufpv; 136155324Simpstruct pv_addr irqstack; 137155324Simpstruct pv_addr undstack; 138155324Simpstruct pv_addr abtstack; 139155324Simpstruct pv_addr kernelstack; 140155324Simpstruct pv_addr minidataclean; 141155324Simp 142155324Simpstatic struct trapframe proc0_tf; 143155324Simp 144155324Simp/* Static device mappings. */ 145155324Simpstatic const struct pmap_devmap kb920x_devmap[] = { 146155324Simp /* 147155324Simp * Map the on-board devices VA == PA so that we can access them 148155324Simp * with the MMU on or off. 149155324Simp */ 150156832Simp { 151156832Simp /* 152156832Simp * This at least maps the interrupt controller, the UART 153156832Simp * and the timer. Other devices should use newbus to 154156832Simp * map their memory anyway. 155156832Simp */ 156156832Simp 0xfff00000, 157156832Simp 0xfff00000, 158156832Simp 0x100000, 159156832Simp VM_PROT_READ|VM_PROT_WRITE, 160156832Simp PTE_NOCACHE, 161156832Simp }, 162160282Scognet#if 0 163156832Simp { 164156832Simp /* 165156832Simp * Add the ohci controller, and anything else that might be 166156832Simp * on this chip select for a VA/PA mapping. 167156832Simp */ 168156832Simp AT91RM92_OHCI_BASE, 169156832Simp AT91RM92_OHCI_BASE, 170156832Simp AT91RM92_OHCI_SIZE, 171156832Simp VM_PROT_READ|VM_PROT_WRITE, 172156832Simp PTE_NOCACHE, 173156832Simp }, 174160282Scognet#endif 175156832Simp { 176156832Simp 0, 177156832Simp 0, 178156832Simp 0, 179156832Simp 0, 180156832Simp 0, 181156832Simp } 182155324Simp}; 183155324Simp 184155324Simp#define SDRAM_START 0xa0000000 185155324Simp 186155324Simp#ifdef DDB 187155324Simpextern vm_offset_t ksym_start, ksym_end; 188155324Simp#endif 189155324Simp 190159814Simpstatic long 191160363Simpramsize(void) 192159795Simp{ 193159795Simp uint32_t *SDRAMC = (uint32_t *)(AT91RM92_BASE + AT91RM92_SDRAMC_BASE); 194159795Simp uint32_t cr, mr; 195160363Simp int banks, rows, cols, bw; 196159795Simp 197159795Simp cr = SDRAMC[AT91RM92_SDRAMC_CR / 4]; 198159795Simp mr = SDRAMC[AT91RM92_SDRAMC_MR / 4]; 199159795Simp bw = (mr & AT91RM92_SDRAMC_MR_DBW_16) ? 1 : 2; 200159795Simp banks = (cr & AT91RM92_SDRAMC_CR_NB_4) ? 2 : 1; 201159795Simp rows = ((cr & AT91RM92_SDRAMC_CR_NR_MASK) >> 2) + 11; 202159795Simp cols = (cr & AT91RM92_SDRAMC_CR_NC_MASK) + 8; 203159814Simp return (1 << (cols + rows + banks + bw)); 204159795Simp} 205159795Simp 206160363Simpstatic long 207160363Simpboard_init(void) 208160363Simp{ 209160363Simp /* 210160363Simp * Since the USART supprots RS-485 multidrop mode, it allows the 211160363Simp * TX pins to float. However, for RS-232 operations, we don't want 212160363Simp * these pins to float. Instead, they should be pulled up to avoid 213160363Simp * mismatches. Linux does something similar when it configures the 214160363Simp * TX lines. This implies that we also allow the RX lines to float 215160363Simp * rather than be in the state they are left in by the boot loader. 216160363Simp * Since they are input pins, I think that this is the right thing 217160363Simp * to do. 218160363Simp */ 219160363Simp 220160363Simp /* PIOA's A periph: Turn USART 0 and 2's TX/RX pins */ 221160363Simp at91_pio_use_periph_a(AT91RM92_PIOA_BASE, 222160363Simp AT91C_PA18_RXD0 | AT91C_PA22_RXD2, 0); 223160363Simp at91_pio_use_periph_a(AT91RM92_PIOA_BASE, 224160363Simp AT91C_PA17_TXD0 | AT91C_PA23_TXD2, 1); 225160363Simp /* PIOA's B periph: Turn USART 3's TX/RX pins */ 226160363Simp at91_pio_use_periph_b(AT91RM92_PIOA_BASE, AT91C_PA6_RXD3, 0); 227160363Simp at91_pio_use_periph_b(AT91RM92_PIOA_BASE, AT91C_PA5_TXD3, 1); 228160363Simp#if AT91_TSC 229160363Simp /* We're using TC0's A1 and A2 input */ 230160363Simp at91_pio_use_periph_b(AT91RM92_PIOA_BASE, 231160363Simp AT91C_PA19_TIOA1 | AT91C_PA21_TIOA2, 0); 232160363Simp#endif 233160363Simp /* PIOB's A periph: Turn USART 1's TX/RX pins */ 234160363Simp at91_pio_use_periph_a(AT91RM92_PIOB_BASE, AT91C_PB21_RXD1, 0); 235160363Simp at91_pio_use_periph_a(AT91RM92_PIOB_BASE, AT91C_PB20_TXD1, 1); 236160363Simp 237160363Simp /* Pin assignment */ 238160363Simp#if AT91_TSC 239160363Simp /* Assert PA24 low -- talk to rubidium */ 240160363Simp at91_pio_use_gpio(AT91RM92_PIOA_BASE, AT91C_PIO_PA24); 241160363Simp at91_pio_gpio_output(AT91RM92_PIOA_BASE, AT91C_PIO_PA24, 0); 242160363Simp at91_pio_gpio_clear(AT91RM92_PIOA_BASE, AT91C_PIO_PA24); 243160363Simp#endif 244160363Simp 245160363Simp return (ramsize()); 246160363Simp} 247160363Simp 248155324Simpvoid * 249155324Simpinitarm(void *arg, void *arg2) 250155324Simp{ 251155324Simp struct pv_addr kernel_l1pt; 252155324Simp int loop; 253155324Simp u_int l1pagetable; 254155324Simp vm_offset_t freemempos; 255155324Simp vm_offset_t afterkern; 256155324Simp int i = 0; 257155324Simp uint32_t fake_preload[35]; 258159795Simp uint32_t memsize; 259157024Scognet vm_offset_t lastaddr; 260157024Scognet#ifdef DDB 261157024Scognet vm_offset_t zstart = 0, zend = 0; 262157024Scognet#endif 263155324Simp 264155324Simp i = 0; 265155324Simp 266155324Simp set_cpufuncs(); 267155324Simp 268155324Simp fake_preload[i++] = MODINFO_NAME; 269155324Simp fake_preload[i++] = strlen("elf kernel") + 1; 270155324Simp strcpy((char*)&fake_preload[i++], "elf kernel"); 271155324Simp i += 2; 272155324Simp fake_preload[i++] = MODINFO_TYPE; 273155324Simp fake_preload[i++] = strlen("elf kernel") + 1; 274155324Simp strcpy((char*)&fake_preload[i++], "elf kernel"); 275155324Simp i += 2; 276155324Simp fake_preload[i++] = MODINFO_ADDR; 277155324Simp fake_preload[i++] = sizeof(vm_offset_t); 278155324Simp fake_preload[i++] = KERNBASE; 279155324Simp fake_preload[i++] = MODINFO_SIZE; 280155324Simp fake_preload[i++] = sizeof(uint32_t); 281155324Simp fake_preload[i++] = (uint32_t)&end - KERNBASE; 282157024Scognet#ifdef DDB 283157024Scognet if (*(uint32_t *)KERNVIRTADDR == MAGIC_TRAMP_NUMBER) { 284157024Scognet fake_preload[i++] = MODINFO_METADATA|MODINFOMD_SSYM; 285157024Scognet fake_preload[i++] = sizeof(vm_offset_t); 286157024Scognet fake_preload[i++] = *(uint32_t *)(KERNVIRTADDR + 4); 287157024Scognet fake_preload[i++] = MODINFO_METADATA|MODINFOMD_ESYM; 288157024Scognet fake_preload[i++] = sizeof(vm_offset_t); 289157024Scognet fake_preload[i++] = *(uint32_t *)(KERNVIRTADDR + 8); 290157024Scognet lastaddr = *(uint32_t *)(KERNVIRTADDR + 8); 291157024Scognet zend = lastaddr; 292157024Scognet zstart = *(uint32_t *)(KERNVIRTADDR + 4); 293157024Scognet ksym_start = zstart; 294157024Scognet ksym_end = zend; 295157024Scognet } else 296157024Scognet#endif 297157024Scognet lastaddr = (vm_offset_t)&end; 298157024Scognet 299155324Simp fake_preload[i++] = 0; 300155324Simp fake_preload[i] = 0; 301155324Simp preload_metadata = (void *)fake_preload; 302155324Simp 303155324Simp 304155324Simp pcpu_init(pcpup, 0, sizeof(struct pcpu)); 305155324Simp PCPU_SET(curthread, &thread0); 306155324Simp 307155324Simp#define KERNEL_TEXT_BASE (KERNBASE) 308157024Scognet freemempos = (lastaddr + PAGE_MASK) & ~PAGE_MASK; 309155324Simp /* Define a macro to simplify memory allocation */ 310155324Simp#define valloc_pages(var, np) \ 311155324Simp alloc_pages((var).pv_va, (np)); \ 312155324Simp (var).pv_pa = (var).pv_va + (KERNPHYSADDR - KERNVIRTADDR); 313155324Simp 314155324Simp#define alloc_pages(var, np) \ 315155324Simp (var) = freemempos; \ 316155324Simp freemempos += (np * PAGE_SIZE); \ 317155324Simp memset((char *)(var), 0, ((np) * PAGE_SIZE)); 318155324Simp 319155324Simp while (((freemempos - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) != 0) 320155324Simp freemempos += PAGE_SIZE; 321155324Simp valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE); 322155324Simp for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) { 323155324Simp if (!(loop % (PAGE_SIZE / L2_TABLE_SIZE_REAL))) { 324155324Simp valloc_pages(kernel_pt_table[loop], 325155324Simp L2_TABLE_SIZE / PAGE_SIZE); 326155324Simp } else { 327155324Simp kernel_pt_table[loop].pv_va = freemempos - 328155324Simp (loop % (PAGE_SIZE / L2_TABLE_SIZE_REAL)) * 329155324Simp L2_TABLE_SIZE_REAL; 330155324Simp kernel_pt_table[loop].pv_pa = 331155324Simp kernel_pt_table[loop].pv_va - KERNVIRTADDR + 332155324Simp KERNPHYSADDR; 333155324Simp } 334155324Simp i++; 335155324Simp } 336155324Simp /* 337155324Simp * Allocate a page for the system page mapped to V0x00000000 338155324Simp * This page will just contain the system vectors and can be 339155324Simp * shared by all processes. 340155324Simp */ 341155324Simp valloc_pages(systempage, 1); 342155324Simp 343155324Simp /* Allocate stacks for all modes */ 344155324Simp valloc_pages(irqstack, IRQ_STACK_SIZE); 345155324Simp valloc_pages(abtstack, ABT_STACK_SIZE); 346155324Simp valloc_pages(undstack, UND_STACK_SIZE); 347155324Simp valloc_pages(kernelstack, KSTACK_PAGES); 348155324Simp alloc_pages(minidataclean.pv_pa, 1); 349155324Simp valloc_pages(msgbufpv, round_page(MSGBUF_SIZE) / PAGE_SIZE); 350155324Simp /* 351155324Simp * Now we start construction of the L1 page table 352155324Simp * We start by mapping the L2 page tables into the L1. 353155324Simp * This means that we can replace L1 mappings later on if necessary 354155324Simp */ 355155324Simp l1pagetable = kernel_l1pt.pv_va; 356155324Simp 357155324Simp /* Map the L2 pages tables in the L1 page table */ 358155324Simp pmap_link_l2pt(l1pagetable, ARM_VECTORS_LOW, 359155324Simp &kernel_pt_table[KERNEL_PT_SYS]); 360155324Simp for (i = 0; i < KERNEL_PT_KERN_NUM; i++) 361155324Simp pmap_link_l2pt(l1pagetable, KERNBASE + i * 0x100000, 362155324Simp &kernel_pt_table[KERNEL_PT_KERN + i]); 363155324Simp pmap_map_chunk(l1pagetable, KERNBASE, KERNPHYSADDR, 364157024Scognet (((uint32_t)(lastaddr) - KERNBASE) + PAGE_SIZE) & ~(PAGE_SIZE - 1), 365155324Simp VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 366157024Scognet afterkern = round_page((lastaddr + L1_S_SIZE) & ~(L1_S_SIZE 367155324Simp - 1)); 368155324Simp for (i = 0; i < KERNEL_PT_AFKERNEL_NUM; i++) { 369155324Simp pmap_link_l2pt(l1pagetable, afterkern + i * 0x00100000, 370155324Simp &kernel_pt_table[KERNEL_PT_AFKERNEL + i]); 371155324Simp } 372155324Simp pmap_map_entry(l1pagetable, afterkern, minidataclean.pv_pa, 373155324Simp VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 374155324Simp 375155324Simp 376155324Simp /* Map the vector page. */ 377155324Simp pmap_map_entry(l1pagetable, ARM_VECTORS_LOW, systempage.pv_pa, 378155324Simp VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 379155324Simp /* Map the stack pages */ 380155324Simp pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa, 381155324Simp IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 382155324Simp pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa, 383155324Simp ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 384155324Simp pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa, 385155324Simp UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 386155324Simp pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa, 387155324Simp KSTACK_PAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 388155324Simp 389155324Simp pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa, 390155324Simp L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE); 391155324Simp pmap_map_chunk(l1pagetable, msgbufpv.pv_va, msgbufpv.pv_pa, 392155324Simp MSGBUF_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 393155324Simp 394155324Simp 395155324Simp for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) { 396155324Simp pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va, 397155324Simp kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE, 398155324Simp VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE); 399155324Simp } 400155324Simp 401155324Simp pmap_devmap_bootstrap(l1pagetable, kb920x_devmap); 402155324Simp cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT); 403155324Simp setttb(kernel_l1pt.pv_pa); 404155324Simp cpu_tlb_flushID(); 405155324Simp cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)); 406157029Scognet cninit(); 407159795Simp memsize = board_init(); 408159814Simp physmem = memsize / PAGE_SIZE; 409159814Simp 410155324Simp /* 411155324Simp * Pages were allocated during the secondary bootstrap for the 412155324Simp * stacks for different CPU modes. 413155324Simp * We must now set the r13 registers in the different CPU modes to 414155324Simp * point to these stacks. 415155324Simp * Since the ARM stacks use STMFD etc. we must set r13 to the top end 416155324Simp * of the stack memory. 417155324Simp */ 418155324Simp 419155324Simp cpu_control(CPU_CONTROL_MMU_ENABLE, CPU_CONTROL_MMU_ENABLE); 420155324Simp set_stackptr(PSR_IRQ32_MODE, 421155324Simp irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE); 422155324Simp set_stackptr(PSR_ABT32_MODE, 423155324Simp abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE); 424155324Simp set_stackptr(PSR_UND32_MODE, 425155324Simp undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE); 426155324Simp 427155324Simp 428155324Simp 429155324Simp /* 430155324Simp * We must now clean the cache again.... 431155324Simp * Cleaning may be done by reading new data to displace any 432155324Simp * dirty data in the cache. This will have happened in setttb() 433155324Simp * but since we are boot strapping the addresses used for the read 434155324Simp * may have just been remapped and thus the cache could be out 435155324Simp * of sync. A re-clean after the switch will cure this. 436155324Simp * After booting there are no gross reloations of the kernel thus 437155324Simp * this problem will not occur after initarm(). 438155324Simp */ 439155324Simp cpu_idcache_wbinv_all(); 440155324Simp 441155324Simp /* Set stack for exception handlers */ 442155324Simp 443155324Simp data_abort_handler_address = (u_int)data_abort_handler; 444155324Simp prefetch_abort_handler_address = (u_int)prefetch_abort_handler; 445155324Simp undefined_handler_address = (u_int)undefinedinstruction_bounce; 446155324Simp undefined_init(); 447155324Simp 448155324Simp proc_linkup(&proc0, &ksegrp0, &thread0); 449155324Simp thread0.td_kstack = kernelstack.pv_va; 450155324Simp thread0.td_pcb = (struct pcb *) 451155324Simp (thread0.td_kstack + KSTACK_PAGES * PAGE_SIZE) - 1; 452155324Simp thread0.td_pcb->pcb_flags = 0; 453155324Simp thread0.td_frame = &proc0_tf; 454155324Simp pcpup->pc_curpcb = thread0.td_pcb; 455155324Simp 456155324Simp arm_vector_init(ARM_VECTORS_LOW, ARM_VEC_ALL); 457155324Simp 458155324Simp pmap_curmaxkvaddr = afterkern + 0x100000 * (KERNEL_PT_KERN_NUM - 1); 459155324Simp pmap_bootstrap(freemempos, 460155324Simp KERNVIRTADDR + 3 * memsize, 461155324Simp &kernel_l1pt); 462155324Simp msgbufp = (void*)msgbufpv.pv_va; 463155324Simp msgbufinit(msgbufp, MSGBUF_SIZE); 464155324Simp mutex_init(); 465155324Simp 466155324Simp i = 0; 467155324Simp dump_avail[0] = KERNPHYSADDR; 468155324Simp dump_avail[1] = KERNPHYSADDR + memsize; 469155324Simp dump_avail[2] = 0; 470155324Simp dump_avail[3] = 0; 471155324Simp 472155324Simp phys_avail[0] = freemempos - KERNVIRTADDR + KERNPHYSADDR; 473155324Simp phys_avail[1] = KERNPHYSADDR + memsize; 474155324Simp phys_avail[2] = 0; 475155324Simp phys_avail[3] = 0; 476155324Simp /* Do basic tuning, hz etc */ 477155324Simp init_param1(); 478159814Simp init_param2(physmem); 479155324Simp avail_end = KERNPHYSADDR + memsize - 1; 480155324Simp kdb_init(); 481155324Simp return ((void *)(kernelstack.pv_va + USPACE_SVC_STACK_TOP - 482155324Simp sizeof(struct pcb))); 483155324Simp} 484