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.0/sys/arm/xscale/i80321/iq31244_machdep.c 147545 2005-06-23 11:40:45Z 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 physical_start;
  138 vm_paddr_t physical_end;
  139 vm_offset_t physical_pages;
  140 vm_offset_t clean_sva, clean_eva;
  141 
  142 struct pv_addr systempage;
  143 struct pv_addr msgbufpv;
  144 struct pv_addr irqstack;
  145 struct pv_addr undstack;
  146 struct pv_addr abtstack;
  147 struct pv_addr kernelstack;
  148 struct pv_addr minidataclean;
  149 
  150 void enable_mmu(vm_offset_t);
  151 static struct trapframe proc0_tf;
  152 
  153 #define IQ80321_OBIO_BASE 0xfe800000UL
  154 #define IQ80321_OBIO_SIZE 0x00100000UL
  155 /* Static device mappings. */
  156 static const struct pmap_devmap iq80321_devmap[] = {
  157         /* 
  158          * Map the on-board devices VA == PA so that we can access them
  159          * with the MMU on or off.
  160          */
  161             {
  162                     IQ80321_OBIO_BASE,
  163                     IQ80321_OBIO_BASE,
  164                     IQ80321_OBIO_SIZE,
  165                     VM_PROT_READ|VM_PROT_WRITE,                             
  166                     PTE_NOCACHE,
  167             },
  168             {
  169                     IQ80321_IOW_VBASE,
  170                     VERDE_OUT_XLATE_IO_WIN0_BASE,
  171                     VERDE_OUT_XLATE_IO_WIN_SIZE,
  172                     VM_PROT_READ|VM_PROT_WRITE,
  173                     PTE_NOCACHE,
  174             },
  175             
  176             {
  177                     IQ80321_80321_VBASE,
  178                     VERDE_PMMR_BASE,
  179                     VERDE_PMMR_SIZE,
  180                     VM_PROT_READ|VM_PROT_WRITE,
  181                     PTE_NOCACHE,
  182             },
  183             {
  184                     0,
  185                     0,
  186                     0,
  187                     0,
  188                     0,
  189             }
  190 };
  191 
  192 #define SDRAM_START 0xa0000000
  193 
  194 extern vm_offset_t xscale_cache_clean_addr;
  195 
  196 void *
  197 initarm(void *arg, void *arg2)
  198 {
  199         struct pv_addr  kernel_l1pt;
  200         int loop;
  201         u_int kerneldatasize, symbolsize;
  202         u_int l1pagetable;
  203         vm_offset_t freemempos;
  204         vm_offset_t freemem_pt;
  205         vm_offset_t afterkern;
  206         vm_offset_t freemem_after;
  207         int i = 0;
  208         uint32_t fake_preload[35];
  209         uint32_t memsize, memstart;
  210 
  211         i = 0;
  212 
  213         set_cpufuncs();
  214         fake_preload[i++] = MODINFO_NAME;
  215         fake_preload[i++] = strlen("elf kernel") + 1;
  216         strcpy((char*)&fake_preload[i++], "elf kernel");
  217         i += 2;
  218         fake_preload[i++] = MODINFO_TYPE;
  219         fake_preload[i++] = strlen("elf kernel") + 1;
  220         strcpy((char*)&fake_preload[i++], "elf kernel");
  221         i += 2;
  222         fake_preload[i++] = MODINFO_ADDR;
  223         fake_preload[i++] = sizeof(vm_offset_t);
  224         fake_preload[i++] = KERNBASE + 0x00200000;
  225         fake_preload[i++] = MODINFO_SIZE;
  226         fake_preload[i++] = sizeof(uint32_t);
  227         fake_preload[i++] = (uint32_t)&end - KERNBASE - 0x00200000;
  228         fake_preload[i++] = 0;
  229         fake_preload[i] = 0;
  230         preload_metadata = (void *)fake_preload;
  231 
  232 
  233         pcpu_init(pcpup, 0, sizeof(struct pcpu));
  234         PCPU_SET(curthread, &thread0);
  235 
  236         physical_start = (vm_offset_t) SDRAM_START;
  237         physical_end =  (vm_offset_t) &end + SDRAM_START - 0xc0000000;
  238 #define KERNEL_TEXT_BASE (KERNBASE + 0x00200000)
  239         kerneldatasize = (u_int32_t)&end - (u_int32_t)KERNEL_TEXT_BASE;
  240         symbolsize = 0;
  241         freemempos = 0xa0200000;
  242         /* Define a macro to simplify memory allocation */
  243 #define valloc_pages(var, np)                   \
  244         alloc_pages((var).pv_pa, (np));         \
  245         (var).pv_va = (var).pv_pa + 0x20000000;
  246 
  247 #define alloc_pages(var, np)                    \
  248         freemempos -= (np * PAGE_SIZE);         \
  249         (var) = freemempos;             \
  250         memset((char *)(var), 0, ((np) * PAGE_SIZE));
  251 
  252         while (((freemempos - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) != 0)
  253                 freemempos -= PAGE_SIZE;
  254         valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
  255         for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
  256                 if (!(loop % (PAGE_SIZE / L2_TABLE_SIZE_REAL))) {
  257                         valloc_pages(kernel_pt_table[loop],
  258                             L2_TABLE_SIZE / PAGE_SIZE);
  259                 } else {
  260                         kernel_pt_table[loop].pv_pa = freemempos -
  261                             (loop % (PAGE_SIZE / L2_TABLE_SIZE_REAL)) *
  262                             L2_TABLE_SIZE_REAL;
  263                         kernel_pt_table[loop].pv_va = 
  264                             kernel_pt_table[loop].pv_pa + 0x20000000;
  265                 }
  266                 i++;
  267         }
  268         freemempos -= 2 * PAGE_SIZE;
  269 
  270         freemem_pt = freemempos;
  271         freemempos = 0xa0100000;
  272         /*
  273          * Allocate a page for the system page mapped to V0x00000000
  274          * This page will just contain the system vectors and can be
  275          * shared by all processes.
  276          */
  277         valloc_pages(systempage, 1);
  278 
  279         /* Allocate stacks for all modes */
  280         valloc_pages(irqstack, IRQ_STACK_SIZE);
  281         valloc_pages(abtstack, ABT_STACK_SIZE);
  282         valloc_pages(undstack, UND_STACK_SIZE);
  283         valloc_pages(kernelstack, KSTACK_PAGES);
  284         alloc_pages(minidataclean.pv_pa, 1);
  285         valloc_pages(msgbufpv, round_page(MSGBUF_SIZE) / PAGE_SIZE);
  286 #ifdef ARM_USE_SMALL_ALLOC
  287         freemempos -= PAGE_SIZE;
  288         freemem_pt = trunc_page(freemem_pt);
  289         freemem_after = freemempos - ((freemem_pt - 0xa0100000) /
  290             PAGE_SIZE) * sizeof(struct arm_small_page);
  291         arm_add_smallalloc_pages((void *)(freemem_after + 0x20000000)
  292             , (void *)0xc0100000, freemem_pt - 0xa0100000, 1);
  293         freemem_after -= ((freemem_after - 0xa0001000) / PAGE_SIZE) *
  294             sizeof(struct arm_small_page);
  295         arm_add_smallalloc_pages((void *)(freemem_after + 0x20000000)
  296         , (void *)0xc0001000, trunc_page(freemem_after) - 0xa0001000, 0);
  297         freemempos = trunc_page(freemem_after);
  298         freemempos -= PAGE_SIZE;
  299 #endif
  300         /*
  301          * Allocate memory for the l1 and l2 page tables. The scheme to avoid
  302          * wasting memory by allocating the l1pt on the first 16k memory was
  303          * taken from NetBSD rpc_machdep.c. NKPT should be greater than 12 for
  304          * this to work (which is supposed to be the case).
  305          */
  306 
  307         /*
  308          * Now we start construction of the L1 page table
  309          * We start by mapping the L2 page tables into the L1.
  310          * This means that we can replace L1 mappings later on if necessary
  311          */
  312         l1pagetable = kernel_l1pt.pv_va;
  313 
  314         /* Map the L2 pages tables in the L1 page table */
  315         pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH & ~(0x00100000 - 1),
  316             &kernel_pt_table[KERNEL_PT_SYS]);
  317         pmap_link_l2pt(l1pagetable, IQ80321_IOPXS_VBASE,
  318                         &kernel_pt_table[KERNEL_PT_IOPXS]);
  319         pmap_link_l2pt(l1pagetable, KERNBASE,
  320             &kernel_pt_table[KERNEL_PT_BEFOREKERN]);
  321         pmap_map_chunk(l1pagetable, KERNBASE, SDRAM_START, 0x100000,
  322             VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
  323         pmap_map_chunk(l1pagetable, KERNBASE + 0x100000, SDRAM_START + 0x100000,
  324             0x100000, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
  325         pmap_map_chunk(l1pagetable, KERNBASE + 0x200000, SDRAM_START + 0x200000,
  326            (((uint32_t)(&end) - KERNBASE - 0x200000) + L1_S_SIZE) & ~(L1_S_SIZE - 1),
  327             VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
  328         freemem_after = ((int)&end + PAGE_SIZE) & ~(PAGE_SIZE - 1);
  329         afterkern = round_page(((vm_offset_t)&end + L1_S_SIZE) & ~(L1_S_SIZE 
  330             - 1));
  331         for (i = 0; i < KERNEL_PT_AFKERNEL_NUM; i++) {
  332                 pmap_link_l2pt(l1pagetable, afterkern + i * 0x00100000,
  333                     &kernel_pt_table[KERNEL_PT_AFKERNEL + i]);
  334         }
  335         pmap_map_entry(l1pagetable, afterkern, minidataclean.pv_pa, 
  336             VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
  337         
  338 
  339 #ifdef ARM_USE_SMALL_ALLOC
  340         if ((freemem_after + 2 * PAGE_SIZE) <= afterkern) {
  341                 arm_add_smallalloc_pages((void *)(freemem_after),
  342                     (void*)(freemem_after + PAGE_SIZE),
  343                     afterkern - (freemem_after + PAGE_SIZE), 0);
  344                     
  345         }
  346 #endif
  347 
  348         /* Map the Mini-Data cache clean area. */
  349         xscale_setup_minidata(l1pagetable, afterkern,
  350             minidataclean.pv_pa);
  351 
  352         /* Map the vector page. */
  353         pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa,
  354             VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
  355         pmap_devmap_bootstrap(l1pagetable, iq80321_devmap);
  356         /*
  357          * Give the XScale global cache clean code an appropriately
  358          * sized chunk of unmapped VA space starting at 0xff000000
  359          * (our device mappings end before this address).
  360          */
  361         xscale_cache_clean_addr = 0xff000000U;
  362 
  363         cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
  364         setttb(kernel_l1pt.pv_pa);
  365         cpu_tlb_flushID();
  366         cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
  367         /*
  368          * Pages were allocated during the secondary bootstrap for the
  369          * stacks for different CPU modes.
  370          * We must now set the r13 registers in the different CPU modes to
  371          * point to these stacks.
  372          * Since the ARM stacks use STMFD etc. we must set r13 to the top end
  373          * of the stack memory.
  374          */
  375 
  376                                    
  377         set_stackptr(PSR_IRQ32_MODE,
  378             irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
  379         set_stackptr(PSR_ABT32_MODE,
  380             abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
  381         set_stackptr(PSR_UND32_MODE,
  382             undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
  383 
  384 
  385 
  386         /*
  387          * We must now clean the cache again....
  388          * Cleaning may be done by reading new data to displace any
  389          * dirty data in the cache. This will have happened in setttb()
  390          * but since we are boot strapping the addresses used for the read
  391          * may have just been remapped and thus the cache could be out
  392          * of sync. A re-clean after the switch will cure this.
  393          * After booting there are no gross reloations of the kernel thus
  394          * this problem will not occur after initarm().
  395          */
  396         cpu_idcache_wbinv_all();
  397         /*
  398          * Fetch the SDRAM start/size from the i80321 SDRAM configration
  399          * registers.
  400          */
  401         i80321_calibrate_delay();
  402         i80321_sdram_bounds(&obio_bs_tag, IQ80321_80321_VBASE + VERDE_MCU_BASE,
  403             &memstart, &memsize);
  404         physmem = memsize / PAGE_SIZE;
  405         cninit();
  406 
  407         /* Set stack for exception handlers */
  408         
  409         data_abort_handler_address = (u_int)data_abort_handler;
  410         prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
  411         undefined_handler_address = (u_int)undefinedinstruction_bounce;
  412         undefined_init();
  413                                 
  414         proc_linkup(&proc0, &ksegrp0, &thread0);
  415         thread0.td_kstack = kernelstack.pv_va;
  416         thread0.td_pcb = (struct pcb *)
  417                 (thread0.td_kstack + KSTACK_PAGES * PAGE_SIZE) - 1;
  418         thread0.td_pcb->pcb_flags = 0;
  419         thread0.td_frame = &proc0_tf;
  420         pcpup->pc_curpcb = thread0.td_pcb;
  421         
  422         /* Enable MMU, I-cache, D-cache, write buffer. */
  423 
  424         arm_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
  425 
  426 
  427 
  428         pmap_curmaxkvaddr = afterkern + PAGE_SIZE;
  429         pmap_bootstrap(pmap_curmaxkvaddr, 
  430             0xd0000000, &kernel_l1pt);
  431         msgbufp = (void*)msgbufpv.pv_va;
  432         msgbufinit(msgbufp, MSGBUF_SIZE);
  433         mutex_init();
  434         
  435         i = 0;
  436 #ifdef ARM_USE_SMALL_ALLOC
  437         phys_avail[i++] = 0xa0000000;
  438         phys_avail[i++] = 0xa0001000;   /*
  439                                          *XXX: Gross hack to get our
  440                                          * pages in the vm_page_array
  441                                          . */
  442 #endif
  443         phys_avail[i++] = round_page(virtual_avail - KERNBASE + SDRAM_START);
  444         phys_avail[i++] = trunc_page(0xa0000000 + memsize - 1);
  445         phys_avail[i++] = 0;
  446         phys_avail[i] = 0;
  447         
  448         /* Do basic tuning, hz etc */
  449         init_param1();
  450         init_param2(physmem);
  451         avail_end = 0xa0000000 + memsize - 1;
  452         kdb_init();
  453         return ((void *)(kernelstack.pv_va + USPACE_SVC_STACK_TOP -
  454             sizeof(struct pcb)));
  455 }

Cache object: e544493190e4e3c23539d7298d87c695


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