The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/arm/xscale/i80321/iq31244_machdep.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: hpc_machdep.c,v 1.70 2003/09/16 08:18:22 agc Exp $     */
    2 
    3 /*-
    4  * Copyright (c) 1994-1998 Mark Brinicombe.
    5  * Copyright (c) 1994 Brini.
    6  * All rights reserved.
    7  *
    8  * This code is derived from software written for Brini by Mark Brinicombe
    9  *
   10  * Redistribution and use in source and binary forms, with or without
   11  * modification, are permitted provided that the following conditions
   12  * are met:
   13  * 1. Redistributions of source code must retain the above copyright
   14  *    notice, this list of conditions and the following disclaimer.
   15  * 2. Redistributions in binary form must reproduce the above copyright
   16  *    notice, this list of conditions and the following disclaimer in the
   17  *    documentation and/or other materials provided with the distribution.
   18  * 3. All advertising materials mentioning features or use of this software
   19  *    must display the following acknowledgement:
   20  *      This product includes software developed by Brini.
   21  * 4. The name of the company nor the name of the author may be used to
   22  *    endorse or promote products derived from this software without specific
   23  *    prior written permission.
   24  *
   25  * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED
   26  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
   27  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   28  * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
   29  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   30  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
   31  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   35  * SUCH DAMAGE.
   36  *
   37  * RiscBSD kernel project
   38  *
   39  * machdep.c
   40  *
   41  * Machine dependant functions for kernel setup
   42  *
   43  * This file needs a lot of work. 
   44  *
   45  * Created      : 17/09/94
   46  */
   47 
   48 #include "opt_msgbuf.h"
   49 
   50 #include <sys/cdefs.h>
   51 __FBSDID("$FreeBSD: releng/6.3/sys/arm/xscale/i80321/iq31244_machdep.c 172716 2007-10-16 21:24:44Z cognet $");
   52 
   53 #define _ARM32_BUS_DMA_PRIVATE
   54 #include <sys/param.h>
   55 #include <sys/systm.h>
   56 #include <sys/sysproto.h>
   57 #include <sys/signalvar.h>
   58 #include <sys/imgact.h>
   59 #include <sys/kernel.h>
   60 #include <sys/ktr.h>
   61 #include <sys/linker.h>
   62 #include <sys/lock.h>
   63 #include <sys/malloc.h>
   64 #include <sys/mutex.h>
   65 #include <sys/pcpu.h>
   66 #include <sys/proc.h>
   67 #include <sys/ptrace.h>
   68 #include <sys/cons.h>
   69 #include <sys/bio.h>
   70 #include <sys/bus.h>
   71 #include <sys/buf.h>
   72 #include <sys/exec.h>
   73 #include <sys/kdb.h>
   74 #include <sys/msgbuf.h>
   75 #include <machine/reg.h>
   76 #include <machine/cpu.h>
   77 
   78 #include <vm/vm.h>
   79 #include <vm/pmap.h>
   80 #include <vm/vm.h>
   81 #include <vm/vm_object.h>
   82 #include <vm/vm_page.h>
   83 #include <vm/vm_pager.h>
   84 #include <vm/vm_map.h>
   85 #include <vm/vnode_pager.h>
   86 #include <machine/pmap.h>
   87 #include <machine/vmparam.h>
   88 #include <machine/pcb.h>
   89 #include <machine/undefined.h>
   90 #include <machine/machdep.h>
   91 #include <machine/metadata.h>
   92 #include <machine/armreg.h>
   93 #include <machine/bus.h>
   94 #include <sys/reboot.h>
   95 
   96 #include <arm/xscale/i80321/i80321reg.h>
   97 #include <arm/xscale/i80321/i80321var.h>
   98 #include <arm/xscale/i80321/iq80321reg.h>
   99 #include <arm/xscale/i80321/obiovar.h>
  100 
  101 #define KERNEL_PT_SYS           0       /* Page table for mapping proc0 zero page */
  102 #define KERNEL_PT_IOPXS         1
  103 #define KERNEL_PT_BEFOREKERN    2
  104 #define KERNEL_PT_AFKERNEL      3       /* L2 table for mapping after kernel */
  105 #define KERNEL_PT_AFKERNEL_NUM  9
  106 
  107 /* this should be evenly divisable by PAGE_SIZE / L2_TABLE_SIZE_REAL (or 4) */
  108 #define NUM_KERNEL_PTS          (KERNEL_PT_AFKERNEL + KERNEL_PT_AFKERNEL_NUM)
  109 
  110 /* Define various stack sizes in pages */
  111 #define IRQ_STACK_SIZE  1
  112 #define ABT_STACK_SIZE  1
  113 #ifdef IPKDB
  114 #define UND_STACK_SIZE  2
  115 #else
  116 #define UND_STACK_SIZE  1
  117 #endif
  118 
  119 extern u_int data_abort_handler_address;
  120 extern u_int prefetch_abort_handler_address;
  121 extern u_int undefined_handler_address;
  122 
  123 struct pv_addr kernel_pt_table[NUM_KERNEL_PTS];
  124 
  125 extern void *_end;
  126 
  127 extern vm_offset_t sa1_cache_clean_addr;
  128 
  129 extern int *end;
  130 
  131 struct pcpu __pcpu;
  132 struct pcpu *pcpup = &__pcpu;
  133 
  134 /* Physical and virtual addresses for some global pages */
  135 
  136 vm_paddr_t phys_avail[10];
  137 vm_paddr_t dump_avail[4];
  138 vm_paddr_t physical_start;
  139 vm_paddr_t physical_end;
  140 vm_offset_t physical_pages;
  141 vm_offset_t clean_sva, clean_eva;
  142 
  143 struct pv_addr systempage;
  144 struct pv_addr msgbufpv;
  145 struct pv_addr irqstack;
  146 struct pv_addr undstack;
  147 struct pv_addr abtstack;
  148 struct pv_addr kernelstack;
  149 struct pv_addr minidataclean;
  150 
  151 void enable_mmu(vm_offset_t);
  152 static struct trapframe proc0_tf;
  153 
  154 #define IQ80321_OBIO_BASE 0xfe800000UL
  155 #define IQ80321_OBIO_SIZE 0x00100000UL
  156 /* Static device mappings. */
  157 static const struct pmap_devmap iq80321_devmap[] = {
  158         /* 
  159          * Map the on-board devices VA == PA so that we can access them
  160          * with the MMU on or off.
  161          */
  162             {
  163                     IQ80321_OBIO_BASE,
  164                     IQ80321_OBIO_BASE,
  165                     IQ80321_OBIO_SIZE,
  166                     VM_PROT_READ|VM_PROT_WRITE,                             
  167                     PTE_NOCACHE,
  168             },
  169             {
  170                     IQ80321_IOW_VBASE,
  171                     VERDE_OUT_XLATE_IO_WIN0_BASE,
  172                     VERDE_OUT_XLATE_IO_WIN_SIZE,
  173                     VM_PROT_READ|VM_PROT_WRITE,
  174                     PTE_NOCACHE,
  175             },
  176             
  177             {
  178                     IQ80321_80321_VBASE,
  179                     VERDE_PMMR_BASE,
  180                     VERDE_PMMR_SIZE,
  181                     VM_PROT_READ|VM_PROT_WRITE,
  182                     PTE_NOCACHE,
  183             },
  184             {
  185                     0,
  186                     0,
  187                     0,
  188                     0,
  189                     0,
  190             }
  191 };
  192 
  193 #define SDRAM_START 0xa0000000
  194 
  195 extern vm_offset_t xscale_cache_clean_addr;
  196 
  197 void *
  198 initarm(void *arg, void *arg2)
  199 {
  200         struct pv_addr  kernel_l1pt;
  201         int loop;
  202         u_int kerneldatasize, symbolsize;
  203         u_int l1pagetable;
  204         vm_offset_t freemempos;
  205         vm_offset_t freemem_pt;
  206         vm_offset_t afterkern;
  207         vm_offset_t freemem_after;
  208         int i = 0;
  209         uint32_t fake_preload[35];
  210         uint32_t memsize, memstart;
  211 
  212         i = 0;
  213 
  214         set_cpufuncs();
  215         fake_preload[i++] = MODINFO_NAME;
  216         fake_preload[i++] = strlen("elf kernel") + 1;
  217         strcpy((char*)&fake_preload[i++], "elf kernel");
  218         i += 2;
  219         fake_preload[i++] = MODINFO_TYPE;
  220         fake_preload[i++] = strlen("elf kernel") + 1;
  221         strcpy((char*)&fake_preload[i++], "elf kernel");
  222         i += 2;
  223         fake_preload[i++] = MODINFO_ADDR;
  224         fake_preload[i++] = sizeof(vm_offset_t);
  225         fake_preload[i++] = KERNBASE + 0x00200000;
  226         fake_preload[i++] = MODINFO_SIZE;
  227         fake_preload[i++] = sizeof(uint32_t);
  228         fake_preload[i++] = (uint32_t)&end - KERNBASE - 0x00200000;
  229         fake_preload[i++] = 0;
  230         fake_preload[i] = 0;
  231         preload_metadata = (void *)fake_preload;
  232 
  233 
  234         pcpu_init(pcpup, 0, sizeof(struct pcpu));
  235         PCPU_SET(curthread, &thread0);
  236 
  237         physical_start = (vm_offset_t) SDRAM_START;
  238         physical_end =  (vm_offset_t) &end + SDRAM_START - 0xc0000000;
  239 #define KERNEL_TEXT_BASE (KERNBASE + 0x00200000)
  240         kerneldatasize = (u_int32_t)&end - (u_int32_t)KERNEL_TEXT_BASE;
  241         symbolsize = 0;
  242         freemempos = 0xa0200000;
  243         /* Define a macro to simplify memory allocation */
  244 #define valloc_pages(var, np)                   \
  245         alloc_pages((var).pv_pa, (np));         \
  246         (var).pv_va = (var).pv_pa + 0x20000000;
  247 
  248 #define alloc_pages(var, np)                    \
  249         freemempos -= (np * PAGE_SIZE);         \
  250         (var) = freemempos;             \
  251         memset((char *)(var), 0, ((np) * PAGE_SIZE));
  252 
  253         while (((freemempos - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) != 0)
  254                 freemempos -= PAGE_SIZE;
  255         valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
  256         for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
  257                 if (!(loop % (PAGE_SIZE / L2_TABLE_SIZE_REAL))) {
  258                         valloc_pages(kernel_pt_table[loop],
  259                             L2_TABLE_SIZE / PAGE_SIZE);
  260                 } else {
  261                         kernel_pt_table[loop].pv_pa = freemempos +
  262                             (loop % (PAGE_SIZE / L2_TABLE_SIZE_REAL)) *
  263                             L2_TABLE_SIZE_REAL;
  264                         kernel_pt_table[loop].pv_va = 
  265                             kernel_pt_table[loop].pv_pa + 0x20000000;
  266                 }
  267                 i++;
  268         }
  269         freemem_pt = freemempos;
  270         freemempos = 0xa0100000;
  271         /*
  272          * Allocate a page for the system page mapped to V0x00000000
  273          * This page will just contain the system vectors and can be
  274          * shared by all processes.
  275          */
  276         valloc_pages(systempage, 1);
  277 
  278         /* Allocate stacks for all modes */
  279         valloc_pages(irqstack, IRQ_STACK_SIZE);
  280         valloc_pages(abtstack, ABT_STACK_SIZE);
  281         valloc_pages(undstack, UND_STACK_SIZE);
  282         valloc_pages(kernelstack, KSTACK_PAGES);
  283         alloc_pages(minidataclean.pv_pa, 1);
  284         valloc_pages(msgbufpv, round_page(MSGBUF_SIZE) / PAGE_SIZE);
  285 #ifdef ARM_USE_SMALL_ALLOC
  286         freemempos -= PAGE_SIZE;
  287         freemem_pt = trunc_page(freemem_pt);
  288         freemem_after = freemempos - ((freemem_pt - 0xa0100000) /
  289             PAGE_SIZE) * sizeof(struct arm_small_page);
  290         arm_add_smallalloc_pages((void *)(freemem_after + 0x20000000)
  291             , (void *)0xc0100000, freemem_pt - 0xa0100000, 1);
  292         freemem_after -= ((freemem_after - 0xa0001000) / PAGE_SIZE) *
  293             sizeof(struct arm_small_page);
  294         arm_add_smallalloc_pages((void *)(freemem_after + 0x20000000)
  295         , (void *)0xc0001000, trunc_page(freemem_after) - 0xa0001000, 0);
  296         freemempos = trunc_page(freemem_after);
  297         freemempos -= PAGE_SIZE;
  298 #endif
  299         /*
  300          * Allocate memory for the l1 and l2 page tables. The scheme to avoid
  301          * wasting memory by allocating the l1pt on the first 16k memory was
  302          * taken from NetBSD rpc_machdep.c. NKPT should be greater than 12 for
  303          * this to work (which is supposed to be the case).
  304          */
  305 
  306         /*
  307          * Now we start construction of the L1 page table
  308          * We start by mapping the L2 page tables into the L1.
  309          * This means that we can replace L1 mappings later on if necessary
  310          */
  311         l1pagetable = kernel_l1pt.pv_va;
  312 
  313         /* Map the L2 pages tables in the L1 page table */
  314         pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH & ~(0x00100000 - 1),
  315             &kernel_pt_table[KERNEL_PT_SYS]);
  316         pmap_link_l2pt(l1pagetable, IQ80321_IOPXS_VBASE,
  317                         &kernel_pt_table[KERNEL_PT_IOPXS]);
  318         pmap_link_l2pt(l1pagetable, KERNBASE,
  319             &kernel_pt_table[KERNEL_PT_BEFOREKERN]);
  320         pmap_map_chunk(l1pagetable, KERNBASE, SDRAM_START, 0x100000,
  321             VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
  322         pmap_map_chunk(l1pagetable, KERNBASE + 0x100000, SDRAM_START + 0x100000,
  323             0x100000, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
  324         pmap_map_chunk(l1pagetable, KERNBASE + 0x200000, SDRAM_START + 0x200000,
  325            (((uint32_t)(&end) - KERNBASE - 0x200000) + L1_S_SIZE) & ~(L1_S_SIZE - 1),
  326             VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
  327         freemem_after = ((int)&end + PAGE_SIZE) & ~(PAGE_SIZE - 1);
  328         afterkern = round_page(((vm_offset_t)&end + L1_S_SIZE) & ~(L1_S_SIZE 
  329             - 1));
  330         for (i = 0; i < KERNEL_PT_AFKERNEL_NUM; i++) {
  331                 pmap_link_l2pt(l1pagetable, afterkern + i * 0x00100000,
  332                     &kernel_pt_table[KERNEL_PT_AFKERNEL + i]);
  333         }
  334         pmap_map_entry(l1pagetable, afterkern, minidataclean.pv_pa, 
  335             VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
  336         
  337 
  338 #ifdef ARM_USE_SMALL_ALLOC
  339         if ((freemem_after + 2 * PAGE_SIZE) <= afterkern) {
  340                 arm_add_smallalloc_pages((void *)(freemem_after),
  341                     (void*)(freemem_after + PAGE_SIZE),
  342                     afterkern - (freemem_after + PAGE_SIZE), 0);
  343                     
  344         }
  345 #endif
  346 
  347         /* Map the Mini-Data cache clean area. */
  348         xscale_setup_minidata(l1pagetable, afterkern,
  349             minidataclean.pv_pa);
  350 
  351         /* Map the vector page. */
  352         pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa,
  353             VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
  354         pmap_devmap_bootstrap(l1pagetable, iq80321_devmap);
  355         /*
  356          * Give the XScale global cache clean code an appropriately
  357          * sized chunk of unmapped VA space starting at 0xff000000
  358          * (our device mappings end before this address).
  359          */
  360         xscale_cache_clean_addr = 0xff000000U;
  361 
  362         cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
  363         setttb(kernel_l1pt.pv_pa);
  364         cpu_tlb_flushID();
  365         cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
  366         /*
  367          * Pages were allocated during the secondary bootstrap for the
  368          * stacks for different CPU modes.
  369          * We must now set the r13 registers in the different CPU modes to
  370          * point to these stacks.
  371          * Since the ARM stacks use STMFD etc. we must set r13 to the top end
  372          * of the stack memory.
  373          */
  374 
  375                                    
  376         set_stackptr(PSR_IRQ32_MODE,
  377             irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
  378         set_stackptr(PSR_ABT32_MODE,
  379             abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
  380         set_stackptr(PSR_UND32_MODE,
  381             undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
  382 
  383 
  384 
  385         /*
  386          * We must now clean the cache again....
  387          * Cleaning may be done by reading new data to displace any
  388          * dirty data in the cache. This will have happened in setttb()
  389          * but since we are boot strapping the addresses used for the read
  390          * may have just been remapped and thus the cache could be out
  391          * of sync. A re-clean after the switch will cure this.
  392          * After booting there are no gross reloations of the kernel thus
  393          * this problem will not occur after initarm().
  394          */
  395         cpu_idcache_wbinv_all();
  396         /*
  397          * Fetch the SDRAM start/size from the i80321 SDRAM configration
  398          * registers.
  399          */
  400         i80321_calibrate_delay();
  401         i80321_sdram_bounds(&obio_bs_tag, IQ80321_80321_VBASE + VERDE_MCU_BASE,
  402             &memstart, &memsize);
  403         physmem = memsize / PAGE_SIZE;
  404         cninit();
  405 
  406         /* Set stack for exception handlers */
  407         
  408         data_abort_handler_address = (u_int)data_abort_handler;
  409         prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
  410         undefined_handler_address = (u_int)undefinedinstruction_bounce;
  411         undefined_init();
  412                                 
  413         proc_linkup(&proc0, &ksegrp0, &thread0);
  414         thread0.td_kstack = kernelstack.pv_va;
  415         thread0.td_pcb = (struct pcb *)
  416                 (thread0.td_kstack + KSTACK_PAGES * PAGE_SIZE) - 1;
  417         thread0.td_pcb->pcb_flags = 0;
  418         thread0.td_frame = &proc0_tf;
  419         pcpup->pc_curpcb = thread0.td_pcb;
  420         
  421         /* Enable MMU, I-cache, D-cache, write buffer. */
  422 
  423         arm_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
  424 
  425 
  426 
  427         pmap_curmaxkvaddr = afterkern + PAGE_SIZE;
  428         /*
  429          * ARM_USE_SMALL_ALLOC uses dump_avail, so it must be filled before
  430          * calling pmap_bootstrap.
  431          */
  432         dump_avail[0] = 0xa0000000;
  433         dump_avail[1] = 0xa0000000 + memsize;
  434         dump_avail[2] = 0;
  435         dump_avail[3] = 0;
  436         pmap_bootstrap(pmap_curmaxkvaddr, 
  437             0xd0000000, &kernel_l1pt);
  438         msgbufp = (void*)msgbufpv.pv_va;
  439         msgbufinit(msgbufp, MSGBUF_SIZE);
  440         mutex_init();
  441         
  442         i = 0;
  443 #ifdef ARM_USE_SMALL_ALLOC
  444         phys_avail[i++] = 0xa0000000;
  445         phys_avail[i++] = 0xa0001000;   /*
  446                                          *XXX: Gross hack to get our
  447                                          * pages in the vm_page_array
  448                                          . */
  449 #endif
  450         phys_avail[i++] = round_page(virtual_avail - KERNBASE + SDRAM_START);
  451         phys_avail[i++] = trunc_page(0xa0000000 + memsize - 1);
  452         phys_avail[i++] = 0;
  453         phys_avail[i] = 0;
  454         
  455         /* Do basic tuning, hz etc */
  456         init_param1();
  457         init_param2(physmem);
  458         avail_end = 0xa0000000 + memsize - 1;
  459         kdb_init();
  460         return ((void *)(kernelstack.pv_va + USPACE_SVC_STACK_TOP -
  461             sizeof(struct pcb)));
  462 }

Cache object: 9f8364cd45b0ff8431557564f1d9bf16


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.