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/i8134x/crb_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 <sys/cdefs.h>
   49 __FBSDID("$FreeBSD: releng/9.2/sys/arm/xscale/i8134x/crb_machdep.c 220836 2011-04-19 15:05:12Z pluknet $");
   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/reg.h>
   74 #include <machine/cpu.h>
   75 
   76 #include <vm/vm.h>
   77 #include <vm/pmap.h>
   78 #include <vm/vm_object.h>
   79 #include <vm/vm_page.h>
   80 #include <vm/vm_pager.h>
   81 #include <vm/vm_map.h>
   82 #include <vm/vnode_pager.h>
   83 #include <machine/pmap.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 
   94 #include <arm/xscale/i80321/i80321var.h> /* For i80321_calibrate_delay() */
   95 
   96 #include <arm/xscale/i8134x/i81342reg.h>
   97 #include <arm/xscale/i8134x/i81342var.h>
   98 #include <arm/xscale/i8134x/obiovar.h>
   99 
  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 #define UND_STACK_SIZE  1
  114 
  115 extern u_int data_abort_handler_address;
  116 extern u_int prefetch_abort_handler_address;
  117 extern u_int undefined_handler_address;
  118 
  119 struct pv_addr kernel_pt_table[NUM_KERNEL_PTS];
  120 extern int *end;
  121 
  122 struct pcpu __pcpu;
  123 struct pcpu *pcpup = &__pcpu;
  124 
  125 /* Physical and virtual addresses for some global pages */
  126 
  127 vm_paddr_t phys_avail[10];
  128 vm_paddr_t dump_avail[4];
  129 vm_offset_t physical_pages;
  130 
  131 struct pv_addr systempage;
  132 struct pv_addr msgbufpv;
  133 struct pv_addr irqstack;
  134 struct pv_addr undstack;
  135 struct pv_addr abtstack;
  136 struct pv_addr kernelstack;
  137 
  138 static struct trapframe proc0_tf;
  139 
  140 /* Static device mappings. */
  141 static const struct pmap_devmap iq81342_devmap[] = {
  142             {
  143                     IOP34X_VADDR,
  144                     IOP34X_HWADDR,
  145                     IOP34X_SIZE,
  146                     VM_PROT_READ|VM_PROT_WRITE,
  147                     PTE_NOCACHE,
  148             },
  149             {
  150                     /*
  151                      * Cheat and map a whole section, this will bring
  152                      * both PCI-X and PCI-E outbound I/O
  153                      */
  154                     IOP34X_PCIX_OIOBAR_VADDR &~ (0x100000 - 1),
  155                     IOP34X_PCIX_OIOBAR &~ (0x100000 - 1),
  156                     0x100000,
  157                     VM_PROT_READ|VM_PROT_WRITE,
  158                     PTE_NOCACHE,
  159             },
  160             {
  161                     IOP34X_PCE1_VADDR,
  162                     IOP34X_PCE1,
  163                     IOP34X_PCE1_SIZE,
  164                     VM_PROT_READ|VM_PROT_WRITE,
  165                     PTE_NOCACHE,
  166             },
  167             {       
  168                     0,
  169                     0,
  170                     0,
  171                     0,
  172                     0,
  173             }
  174 };
  175 
  176 #define SDRAM_START 0x00000000
  177 
  178 extern vm_offset_t xscale_cache_clean_addr;
  179 
  180 void *
  181 initarm(void *arg, void *arg2)
  182 {
  183         struct pv_addr  kernel_l1pt;
  184         struct pv_addr  dpcpu;
  185         int loop, i;
  186         u_int l1pagetable;
  187         vm_offset_t freemempos;
  188         vm_offset_t freemem_pt;
  189         vm_offset_t afterkern;
  190         vm_offset_t freemem_after;
  191         vm_offset_t lastaddr;
  192         uint32_t memsize, memstart;
  193 
  194         set_cpufuncs();
  195         lastaddr = fake_preload_metadata();
  196         pcpu_init(pcpup, 0, sizeof(struct pcpu));
  197         PCPU_SET(curthread, &thread0);
  198 
  199         /* Do basic tuning, hz etc */
  200         init_param1();
  201 
  202         freemempos = 0x00200000;
  203         /* Define a macro to simplify memory allocation */
  204 #define valloc_pages(var, np)                   \
  205         alloc_pages((var).pv_pa, (np));         \
  206         (var).pv_va = (var).pv_pa + 0xc0000000;
  207 
  208 #define alloc_pages(var, np)                    \
  209         freemempos -= (np * PAGE_SIZE);         \
  210         (var) = freemempos;             \
  211         memset((char *)(var), 0, ((np) * PAGE_SIZE));
  212 
  213         while (((freemempos - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) != 0)
  214                 freemempos -= PAGE_SIZE;
  215         valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
  216         for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
  217                 if (!(loop % (PAGE_SIZE / L2_TABLE_SIZE_REAL))) {
  218                         valloc_pages(kernel_pt_table[loop],
  219                             L2_TABLE_SIZE / PAGE_SIZE);
  220                 } else {
  221                         kernel_pt_table[loop].pv_pa = freemempos +
  222                             (loop % (PAGE_SIZE / L2_TABLE_SIZE_REAL)) *
  223                             L2_TABLE_SIZE_REAL;
  224                         kernel_pt_table[loop].pv_va = 
  225                             kernel_pt_table[loop].pv_pa + 0xc0000000;
  226                 }
  227         }
  228         freemem_pt = freemempos;
  229         freemempos = 0x00100000;
  230         /*
  231          * Allocate a page for the system page mapped to V0x00000000
  232          * This page will just contain the system vectors and can be
  233          * shared by all processes.
  234          */
  235         valloc_pages(systempage, 1);
  236 
  237         /* Allocate dynamic per-cpu area. */
  238         valloc_pages(dpcpu, DPCPU_SIZE / PAGE_SIZE);
  239         dpcpu_init((void *)dpcpu.pv_va, 0);
  240 
  241         /* Allocate stacks for all modes */
  242         valloc_pages(irqstack, IRQ_STACK_SIZE);
  243         valloc_pages(abtstack, ABT_STACK_SIZE);
  244         valloc_pages(undstack, UND_STACK_SIZE);
  245         valloc_pages(kernelstack, KSTACK_PAGES);
  246         valloc_pages(msgbufpv, round_page(msgbufsize) / PAGE_SIZE);
  247 #ifdef ARM_USE_SMALL_ALLOC
  248         freemempos -= PAGE_SIZE;
  249         freemem_pt = trunc_page(freemem_pt);
  250         freemem_after = freemempos - ((freemem_pt - 0x00100000) /
  251             PAGE_SIZE) * sizeof(struct arm_small_page);
  252         arm_add_smallalloc_pages((void *)(freemem_after + 0xc0000000)
  253             , (void *)0xc0100000, freemem_pt - 0x00100000, 1);
  254         freemem_after -= ((freemem_after - 0x00001000) / PAGE_SIZE) *
  255             sizeof(struct arm_small_page);
  256 #if 0
  257         arm_add_smallalloc_pages((void *)(freemem_after + 0xc0000000)
  258         , (void *)0xc0001000, trunc_page(freemem_after) - 0x00001000, 0);
  259 #endif
  260         freemempos = trunc_page(freemem_after);
  261         freemempos -= PAGE_SIZE;
  262 #endif
  263         /*
  264          * Now we start construction of the L1 page table
  265          * We start by mapping the L2 page tables into the L1.
  266          * This means that we can replace L1 mappings later on if necessary
  267          */
  268         l1pagetable = kernel_l1pt.pv_va;
  269 
  270         /* Map the L2 pages tables in the L1 page table */
  271         pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH & ~(0x00100000 - 1),
  272             &kernel_pt_table[KERNEL_PT_SYS]);
  273         pmap_map_chunk(l1pagetable, KERNBASE, SDRAM_START, 0x100000,
  274             VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
  275 
  276         pmap_map_chunk(l1pagetable, KERNBASE + 0x100000, SDRAM_START + 0x100000,
  277             0x100000, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
  278 
  279         pmap_map_chunk(l1pagetable, KERNBASE + 0x200000, SDRAM_START + 0x200000,
  280            (((uint32_t)(lastaddr) - KERNBASE - 0x200000) + L1_S_SIZE) & ~(L1_S_SIZE - 1),
  281             VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
  282         freemem_after = ((int)lastaddr + PAGE_SIZE) & ~(PAGE_SIZE - 1);
  283         afterkern = round_page(((vm_offset_t)lastaddr + L1_S_SIZE) & ~(L1_S_SIZE 
  284             - 1));
  285         for (i = 0; i < KERNEL_PT_AFKERNEL_NUM; i++) {
  286                 pmap_link_l2pt(l1pagetable, afterkern + i * 0x00100000,
  287                     &kernel_pt_table[KERNEL_PT_AFKERNEL + i]);
  288         }
  289         
  290 
  291 #ifdef ARM_USE_SMALL_ALLOC
  292         if ((freemem_after + 2 * PAGE_SIZE) <= afterkern) {
  293                 arm_add_smallalloc_pages((void *)(freemem_after),
  294                     (void*)(freemem_after + PAGE_SIZE),
  295                     afterkern - (freemem_after + PAGE_SIZE), 0);
  296                     
  297         }
  298 #endif
  299 
  300         /* Map the vector page. */
  301         pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa,
  302             VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
  303         pmap_devmap_bootstrap(l1pagetable, iq81342_devmap);
  304         /*
  305          * Give the XScale global cache clean code an appropriately
  306          * sized chunk of unmapped VA space starting at 0xff000000
  307          * (our device mappings end before this address).
  308          */
  309         xscale_cache_clean_addr = 0xff000000U;
  310 
  311         cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
  312         setttb(kernel_l1pt.pv_pa);
  313         cpu_tlb_flushID();
  314         cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
  315         /*
  316          * Pages were allocated during the secondary bootstrap for the
  317          * stacks for different CPU modes.
  318          * We must now set the r13 registers in the different CPU modes to
  319          * point to these stacks.
  320          * Since the ARM stacks use STMFD etc. we must set r13 to the top end
  321          * of the stack memory.
  322          */
  323 
  324                                    
  325         set_stackptr(PSR_IRQ32_MODE,
  326             irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
  327         set_stackptr(PSR_ABT32_MODE,
  328             abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
  329         set_stackptr(PSR_UND32_MODE,
  330             undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
  331 
  332 
  333 
  334         /*
  335          * We must now clean the cache again....
  336          * Cleaning may be done by reading new data to displace any
  337          * dirty data in the cache. This will have happened in setttb()
  338          * but since we are boot strapping the addresses used for the read
  339          * may have just been remapped and thus the cache could be out
  340          * of sync. A re-clean after the switch will cure this.
  341          * After booting there are no gross relocations of the kernel thus
  342          * this problem will not occur after initarm().
  343          */
  344         cpu_idcache_wbinv_all();
  345         i80321_calibrate_delay();
  346         i81342_sdram_bounds(&obio_bs_tag, IOP34X_VADDR, &memstart, &memsize);
  347         physmem = memsize / PAGE_SIZE;
  348         cninit();
  349         /* Set stack for exception handlers */
  350         
  351         data_abort_handler_address = (u_int)data_abort_handler;
  352         prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
  353         undefined_handler_address = (u_int)undefinedinstruction_bounce;
  354         undefined_init();
  355                                 
  356         proc_linkup0(&proc0, &thread0);
  357         thread0.td_kstack = kernelstack.pv_va;
  358         thread0.td_pcb = (struct pcb *)
  359                 (thread0.td_kstack + KSTACK_PAGES * PAGE_SIZE) - 1;
  360         thread0.td_pcb->pcb_flags = 0;
  361         thread0.td_frame = &proc0_tf;
  362         pcpup->pc_curpcb = thread0.td_pcb;
  363         
  364         arm_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
  365 
  366         pmap_curmaxkvaddr = afterkern + PAGE_SIZE;
  367         /*
  368          * ARM_USE_SMALL_ALLOC uses dump_avail, so it must be filled before
  369          * calling pmap_bootstrap.
  370          */
  371         dump_avail[0] = 0x00000000;
  372         dump_avail[1] = 0x00000000 + memsize;
  373         dump_avail[2] = 0;
  374         dump_avail[3] = 0;
  375                                         
  376         pmap_bootstrap(pmap_curmaxkvaddr, 
  377             0xd0000000, &kernel_l1pt);
  378         msgbufp = (void*)msgbufpv.pv_va;
  379         msgbufinit(msgbufp, msgbufsize);
  380         mutex_init();
  381         
  382         i = 0;
  383 #ifdef ARM_USE_SMALL_ALLOC
  384         phys_avail[i++] = 0x00000000;
  385         phys_avail[i++] = 0x00001000;   /*
  386                                          *XXX: Gross hack to get our
  387                                          * pages in the vm_page_array
  388                                          . */
  389 #endif
  390         phys_avail[i++] = round_page(virtual_avail - KERNBASE + SDRAM_START);
  391         phys_avail[i++] = trunc_page(0x00000000 + memsize - 1);
  392         phys_avail[i++] = 0;
  393         phys_avail[i] = 0;
  394         
  395         init_param2(physmem);
  396         kdb_init();
  397         return ((void *)(kernelstack.pv_va + USPACE_SVC_STACK_TOP -
  398             sizeof(struct pcb)));
  399 }

Cache object: d65522001034d9a36f20a1670b5040ff


[ 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.