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/econa/econa_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 /*-
    2  * Copyright (c) 2009 Yohanes Nugroho <yohanes@gmail.com>
    3  * Copyright (c) 1994-1998 Mark Brinicombe.
    4  * Copyright (c) 1994 Brini.
    5  * All rights reserved.
    6  *
    7  * This code is derived from software written for Brini by Mark Brinicombe
    8  *
    9  * Redistribution and use in source and binary forms, with or without
   10  * modification, are permitted provided that the following conditions
   11  * are met:
   12  * 1. Redistributions of source code must retain the above copyright
   13  *    notice, this list of conditions and the following disclaimer.
   14  * 2. Redistributions in binary form must reproduce the above copyright
   15  *    notice, this list of conditions and the following disclaimer in the
   16  *    documentation and/or other materials provided with the distribution.
   17  * 3. All advertising materials mentioning features or use of this software
   18  *    must display the following acknowledgement:
   19  *      This product includes software developed by Brini.
   20  * 4. The name of the company nor the name of the author may be used to
   21  *    endorse or promote products derived from this software without specific
   22  *    prior written permission.
   23  *
   24  * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED
   25  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
   26  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   27  * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
   28  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   29  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
   30  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   34  * SUCH DAMAGE.
   35  *
   36  */
   37 
   38 #include <sys/cdefs.h>
   39 __FBSDID("$FreeBSD: releng/10.0/sys/arm/econa/econa_machdep.c 247564 2013-03-01 19:02:41Z alc $");
   40 
   41 #define _ARM32_BUS_DMA_PRIVATE
   42 #include <sys/param.h>
   43 #include <sys/systm.h>
   44 #include <sys/sysproto.h>
   45 #include <sys/signalvar.h>
   46 #include <sys/imgact.h>
   47 #include <sys/kernel.h>
   48 #include <sys/ktr.h>
   49 #include <sys/linker.h>
   50 #include <sys/lock.h>
   51 #include <sys/malloc.h>
   52 #include <sys/mutex.h>
   53 #include <sys/pcpu.h>
   54 #include <sys/proc.h>
   55 #include <sys/ptrace.h>
   56 #include <sys/cons.h>
   57 #include <sys/bio.h>
   58 #include <sys/bus.h>
   59 #include <sys/buf.h>
   60 #include <sys/exec.h>
   61 #include <sys/kdb.h>
   62 #include <sys/msgbuf.h>
   63 #include <machine/reg.h>
   64 #include <machine/cpu.h>
   65 
   66 #include <vm/vm.h>
   67 #include <vm/pmap.h>
   68 #include <vm/vm_object.h>
   69 #include <vm/vm_page.h>
   70 #include <vm/vm_map.h>
   71 #include <machine/vmparam.h>
   72 #include <machine/pcb.h>
   73 #include <machine/undefined.h>
   74 #include <machine/machdep.h>
   75 #include <machine/metadata.h>
   76 #include <machine/armreg.h>
   77 #include <machine/bus.h>
   78 #include <sys/reboot.h>
   79 #include "econa_reg.h"
   80 
   81 /* Page table for mapping proc0 zero page */
   82 #define KERNEL_PT_SYS           0
   83 #define KERNEL_PT_KERN          1
   84 #define KERNEL_PT_KERN_NUM      22
   85 /* L2 table for mapping after kernel */
   86 #define KERNEL_PT_AFKERNEL      KERNEL_PT_KERN + KERNEL_PT_KERN_NUM
   87 #define KERNEL_PT_AFKERNEL_NUM  5
   88 
   89 /* this should be evenly divisable by PAGE_SIZE / L2_TABLE_SIZE_REAL (or 4) */
   90 #define NUM_KERNEL_PTS  (KERNEL_PT_AFKERNEL + KERNEL_PT_AFKERNEL_NUM)
   91 
   92 extern u_int data_abort_handler_address;
   93 extern u_int prefetch_abort_handler_address;
   94 extern u_int undefined_handler_address;
   95 
   96 struct pv_addr kernel_pt_table[NUM_KERNEL_PTS];
   97 
   98 /* Physical and virtual addresses for some global pages */
   99 
  100 vm_paddr_t phys_avail[10];
  101 vm_paddr_t dump_avail[4];
  102 
  103 struct pv_addr systempage;
  104 struct pv_addr msgbufpv;
  105 struct pv_addr irqstack;
  106 struct pv_addr undstack;
  107 struct pv_addr abtstack;
  108 struct pv_addr kernelstack;
  109 
  110 /* Static device mappings. */
  111 static const struct pmap_devmap econa_devmap[] = {
  112         {
  113                 /*
  114                  * This maps DDR SDRAM
  115                  */
  116                 ECONA_SDRAM_BASE, /*virtual*/
  117                 ECONA_SDRAM_BASE, /*physical*/
  118                 ECONA_SDRAM_SIZE, /*size*/
  119                 VM_PROT_READ|VM_PROT_WRITE,
  120                 PTE_NOCACHE,
  121         },
  122         /*
  123          * Map the on-board devices VA == PA so that we can access them
  124          * with the MMU on or off.
  125          */
  126         {
  127                 /*
  128                  * This maps the interrupt controller, the UART
  129                  * and the timer.
  130                  */
  131                 ECONA_IO_BASE, /*virtual*/
  132                 ECONA_IO_BASE, /*physical*/
  133                 ECONA_IO_SIZE, /*size*/
  134                 VM_PROT_READ|VM_PROT_WRITE,
  135                 PTE_NOCACHE,
  136         },
  137         {
  138                 /*
  139                  * OHCI + EHCI
  140                  */
  141                 ECONA_OHCI_VBASE, /*virtual*/
  142                 ECONA_OHCI_PBASE, /*physical*/
  143                 ECONA_USB_SIZE, /*size*/
  144                 VM_PROT_READ|VM_PROT_WRITE,
  145                 PTE_NOCACHE,
  146         },
  147         {
  148                 /*
  149                  * CFI
  150                  */
  151                 ECONA_CFI_VBASE, /*virtual*/
  152                 ECONA_CFI_PBASE, /*physical*/
  153                 ECONA_CFI_SIZE,
  154                 VM_PROT_READ|VM_PROT_WRITE,
  155                 PTE_NOCACHE,
  156         },
  157         {
  158                 0,
  159                 0,
  160                 0,
  161                 0,
  162                 0,
  163         }
  164 };
  165 
  166 
  167 void *
  168 initarm(struct arm_boot_params *abp)
  169 {
  170         struct pv_addr  kernel_l1pt;
  171         volatile uint32_t * ddr = (uint32_t *)0x4000000C;
  172         int loop, i;
  173         u_int l1pagetable;
  174         vm_offset_t afterkern;
  175         vm_offset_t freemempos;
  176         vm_offset_t lastaddr;
  177         uint32_t memsize;
  178         int mem_info;
  179 
  180         boothowto = RB_VERBOSE;
  181         lastaddr = parse_boot_param(abp);
  182         set_cpufuncs();
  183         pcpu0_init();
  184 
  185         /* Do basic tuning, hz etc */
  186         init_param1();
  187                 
  188 
  189         freemempos = (lastaddr + PAGE_MASK) & ~PAGE_MASK;
  190         /* Define a macro to simplify memory allocation */
  191 #define valloc_pages(var, np)                   \
  192         alloc_pages((var).pv_va, (np));         \
  193         (var).pv_pa = (var).pv_va + (KERNPHYSADDR - KERNVIRTADDR);
  194 
  195 #define alloc_pages(var, np)                    \
  196         (var) = freemempos;             \
  197         freemempos += (np * PAGE_SIZE);         \
  198         memset((char *)(var), 0, ((np) * PAGE_SIZE));
  199 
  200         while (((freemempos - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) != 0)
  201                 freemempos += PAGE_SIZE;
  202         valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
  203         for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
  204                 if (!(loop % (PAGE_SIZE / L2_TABLE_SIZE_REAL))) {
  205                         valloc_pages(kernel_pt_table[loop],
  206                             L2_TABLE_SIZE / PAGE_SIZE);
  207                 } else {
  208                         kernel_pt_table[loop].pv_va = freemempos -
  209                             (loop % (PAGE_SIZE / L2_TABLE_SIZE_REAL)) *
  210                             L2_TABLE_SIZE_REAL;
  211                         kernel_pt_table[loop].pv_pa =
  212                             kernel_pt_table[loop].pv_va - KERNVIRTADDR +
  213                             KERNPHYSADDR;
  214                 }
  215         }
  216         /*
  217          * Allocate a page for the system page mapped to V0x00000000
  218          * This page will just contain the system vectors and can be
  219          * shared by all processes.
  220          */
  221         valloc_pages(systempage, 1);
  222 
  223         /* Allocate stacks for all modes */
  224         valloc_pages(irqstack, IRQ_STACK_SIZE);
  225         valloc_pages(abtstack, ABT_STACK_SIZE);
  226         valloc_pages(undstack, UND_STACK_SIZE);
  227         valloc_pages(kernelstack, KSTACK_PAGES);
  228         valloc_pages(msgbufpv, round_page(msgbufsize) / PAGE_SIZE);
  229 
  230         /*
  231          * Now we start construction of the L1 page table
  232          * We start by mapping the L2 page tables into the L1.
  233          * This means that we can replace L1 mappings later on if necessary
  234          */
  235         l1pagetable = kernel_l1pt.pv_va;
  236 
  237         /* Map the L2 pages tables in the L1 page table */
  238         pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH,
  239             &kernel_pt_table[KERNEL_PT_SYS]);
  240         for (i = 0; i < KERNEL_PT_KERN_NUM; i++)
  241                 pmap_link_l2pt(l1pagetable, KERNBASE + i * L1_S_SIZE,
  242                     &kernel_pt_table[KERNEL_PT_KERN + i]);
  243         pmap_map_chunk(l1pagetable, KERNBASE, PHYSADDR,
  244            (((uint32_t)lastaddr - KERNBASE) + PAGE_SIZE) & ~(PAGE_SIZE - 1),
  245             VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
  246         afterkern = round_page((lastaddr + L1_S_SIZE) & ~(L1_S_SIZE - 1));
  247         for (i = 0; i < KERNEL_PT_AFKERNEL_NUM; i++) {
  248                 pmap_link_l2pt(l1pagetable, afterkern + i * L1_S_SIZE,
  249                     &kernel_pt_table[KERNEL_PT_AFKERNEL + i]);
  250         }
  251 
  252         /* Map the vector page. */
  253         pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa,
  254             VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
  255 
  256 
  257         /* Map the stack pages */
  258         pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
  259             IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
  260         pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
  261             ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
  262         pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
  263             UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
  264         pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
  265             KSTACK_PAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
  266 
  267         pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
  268             L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
  269         pmap_map_chunk(l1pagetable, msgbufpv.pv_va, msgbufpv.pv_pa,
  270             msgbufsize, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
  271 
  272         for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
  273                 pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
  274                     kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
  275                     VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
  276         }
  277 
  278         pmap_devmap_bootstrap(l1pagetable, econa_devmap);
  279         cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
  280         setttb(kernel_l1pt.pv_pa);
  281         cpu_tlb_flushID();
  282         cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
  283         cninit();
  284         mem_info = ((*ddr) >> 4) & 0x3;
  285         memsize = (8<<mem_info)*1024*1024;
  286         physmem = memsize / PAGE_SIZE;
  287 
  288         /*
  289          * Pages were allocated during the secondary bootstrap for the
  290          * stacks for different CPU modes.
  291          * We must now set the r13 registers in the different CPU modes to
  292          * point to these stacks.
  293          * Since the ARM stacks use STMFD etc. we must set r13 to the top end
  294          * of the stack memory.
  295          */
  296         cpu_control(CPU_CONTROL_MMU_ENABLE, CPU_CONTROL_MMU_ENABLE);
  297 
  298         set_stackptrs(0);
  299 
  300         /*
  301          * We must now clean the cache again....
  302          * Cleaning may be done by reading new data to displace any
  303          * dirty data in the cache. This will have happened in setttb()
  304          * but since we are boot strapping the addresses used for the read
  305          * may have just been remapped and thus the cache could be out
  306          * of sync. A re-clean after the switch will cure this.
  307          * After booting there are no gross relocations of the kernel thus
  308          * this problem will not occur after initarm().
  309          */
  310         cpu_idcache_wbinv_all();
  311 
  312         /* Set stack for exception handlers */
  313         data_abort_handler_address = (u_int)data_abort_handler;
  314         prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
  315         undefined_handler_address = (u_int)undefinedinstruction_bounce;
  316         undefined_init();
  317 
  318         init_proc0(kernelstack.pv_va);
  319 
  320         arm_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
  321 
  322         pmap_curmaxkvaddr = afterkern + L1_S_SIZE * (KERNEL_PT_KERN_NUM - 1);
  323         arm_dump_avail_init(memsize, sizeof(dump_avail) / sizeof(dump_avail[0]));
  324         vm_max_kernel_address = KERNVIRTADDR + 3 * memsize;
  325         pmap_bootstrap(freemempos, &kernel_l1pt);
  326 
  327         msgbufp = (void*)msgbufpv.pv_va;
  328         msgbufinit(msgbufp, msgbufsize);
  329 
  330         mutex_init();
  331 
  332         i = 0;
  333 #if PHYSADDR != KERNPHYSADDR
  334         phys_avail[i++] = PHYSADDR;
  335         phys_avail[i++] = KERNPHYSADDR;
  336 #endif
  337         phys_avail[i++] = virtual_avail - KERNVIRTADDR + KERNPHYSADDR;
  338 
  339         phys_avail[i++] = PHYSADDR + memsize;
  340         phys_avail[i++] = 0;
  341         phys_avail[i++] = 0;
  342         init_param2(physmem);
  343         kdb_init();
  344 
  345         return ((void *)(kernelstack.pv_va + USPACE_SVC_STACK_TOP -
  346             sizeof(struct pcb)));
  347 }

Cache object: 673801ae5ea4650b3b374999b7291448


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