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/mips/beri/beri_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  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
    3  *
    4  * Copyright (c) 2006 Wojciech A. Koszek <wkoszek@FreeBSD.org>
    5  * Copyright (c) 2012-2014 Robert N. M. Watson
    6  * All rights reserved.
    7  *
    8  * This software was developed by SRI International and the University of
    9  * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)
   10  * ("CTSRD"), as part of the DARPA CRASH research programme.
   11  *
   12  * Redistribution and use in source and binary forms, with or without
   13  * modification, are permitted provided that the following conditions
   14  * are met:
   15  * 1. Redistributions of source code must retain the above copyright
   16  *    notice, this list of conditions and the following disclaimer.
   17  * 2. Redistributions in binary form must reproduce the above copyright
   18  *    notice, this list of conditions and the following disclaimer in the
   19  *    documentation and/or other materials provided with the distribution.
   20  *
   21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   31  * SUCH DAMAGE.
   32  */
   33 #include <sys/cdefs.h>
   34 __FBSDID("$FreeBSD$");
   35 
   36 #include "opt_ddb.h"
   37 #include "opt_platform.h"
   38 
   39 #include <sys/param.h>
   40 #include <sys/conf.h>
   41 #include <sys/kernel.h>
   42 #include <sys/systm.h>
   43 #include <sys/imgact.h>
   44 #include <sys/bio.h>
   45 #include <sys/buf.h>
   46 #include <sys/bus.h>
   47 #include <sys/cpu.h>
   48 #include <sys/cons.h>
   49 #include <sys/exec.h>
   50 #include <sys/linker.h>
   51 #include <sys/ucontext.h>
   52 #include <sys/proc.h>
   53 #include <sys/kdb.h>
   54 #include <sys/ptrace.h>
   55 #include <sys/reboot.h>
   56 #include <sys/signalvar.h>
   57 #include <sys/sysent.h>
   58 #include <sys/sysproto.h>
   59 #include <sys/user.h>
   60 
   61 #ifdef FDT
   62 #include <dev/fdt/fdt_common.h>
   63 #include <dev/ofw/openfirm.h>
   64 #include <dev/ofw/ofw_subr.h>
   65 #endif
   66 
   67 #include <vm/vm.h>
   68 #include <vm/vm_param.h>
   69 #include <vm/vm_object.h>
   70 #include <vm/vm_page.h>
   71 #include <vm/vm_phys.h>
   72 #include <vm/vm_dumpset.h>
   73 
   74 #include <machine/bootinfo.h>
   75 #include <machine/clock.h>
   76 #include <machine/cpu.h>
   77 #include <machine/cpuregs.h>
   78 #include <machine/hwfunc.h>
   79 #include <machine/md_var.h>
   80 #include <machine/metadata.h>
   81 #include <machine/pmap.h>
   82 #include <machine/trap.h>
   83 
   84 extern int      *edata;
   85 extern int      *end;
   86 
   87 void
   88 platform_cpu_init()
   89 {
   90         /* Nothing special */
   91 }
   92 
   93 static void
   94 mips_init(void)
   95 {
   96         int i;
   97 #ifdef FDT
   98         struct mem_region mr[FDT_MEM_REGIONS];
   99         uint64_t val;
  100         int mr_cnt;
  101         int j;
  102 #endif
  103 
  104         for (i = 0; i < 10; i++) {
  105                 phys_avail[i] = 0;
  106         }
  107 
  108         /* phys_avail regions are in bytes */
  109         phys_avail[0] = MIPS_KSEG0_TO_PHYS(kernel_kseg0_end);
  110         phys_avail[1] = ctob(realmem);
  111 
  112         dump_avail[0] = phys_avail[0];
  113         dump_avail[1] = phys_avail[1];
  114 
  115         physmem = realmem;
  116 
  117 #ifdef FDT
  118         if (fdt_get_mem_regions(mr, &mr_cnt, &val) == 0) {
  119                 physmem = btoc(val);
  120 
  121                 KASSERT((phys_avail[0] >= mr[0].mr_start) && \
  122                         (phys_avail[0] < (mr[0].mr_start + mr[0].mr_size)),
  123                         ("First region is not within FDT memory range"));
  124 
  125                 /* Limit size of the first region */
  126                 phys_avail[1] = (mr[0].mr_start + MIN(mr[0].mr_size, ctob(realmem)));
  127                 dump_avail[1] = phys_avail[1];
  128 
  129                 /* Add the rest of regions */
  130                 for (i = 1, j = 2; i < mr_cnt; i++, j+=2) {
  131                         phys_avail[j] = mr[i].mr_start;
  132                         phys_avail[j+1] = (mr[i].mr_start + mr[i].mr_size);
  133                         dump_avail[j] = phys_avail[j];
  134                         dump_avail[j+1] = phys_avail[j+1];
  135                 }
  136         }
  137 #endif
  138 
  139         init_param1();
  140         init_param2(physmem);
  141         mips_cpu_init();
  142         pmap_bootstrap();
  143         mips_proc0_init();
  144         mutex_init();
  145         kdb_init();
  146 #ifdef KDB
  147         if (boothowto & RB_KDB)
  148                 kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger");
  149 #endif
  150 }
  151 
  152 /*
  153  * Perform a board-level soft-reset.
  154  */
  155 void
  156 platform_reset(void)
  157 {
  158 
  159         /* XXX SMP will likely require us to do more. */
  160         __asm__ __volatile__(
  161                 "mfc0 $k0, $12\n\t"
  162                 "li $k1, 0x00100000\n\t"
  163                 "or $k0, $k0, $k1\n\t"
  164                 "mtc0 $k0, $12\n");
  165         for( ; ; )
  166                 __asm__ __volatile("wait");
  167 }
  168 
  169 void
  170 platform_start(__register_t a0, __register_t a1,  __register_t a2, 
  171     __register_t a3)
  172 {
  173         struct bootinfo *bootinfop;
  174         vm_offset_t kernend;
  175         uint64_t platform_counter_freq;
  176         int argc = a0;
  177         char **argv = (char **)a1;
  178         char **envp = (char **)a2;
  179         long memsize;
  180 #ifdef FDT
  181         vm_offset_t dtbp;
  182         void *kmdp;
  183 #endif
  184         int i;
  185 
  186         /* clear the BSS and SBSS segments */
  187         kernend = (vm_offset_t)&end;
  188         memset(&edata, 0, kernend - (vm_offset_t)(&edata));
  189 
  190         mips_postboot_fixup();
  191 
  192         mips_pcpu0_init();
  193 
  194         /*
  195          * Over time, we've changed out boot-time binary interface for the
  196          * kernel.  Miniboot simply provides a 'memsize' in a3, whereas the
  197          * FreeBSD boot loader provides a 'bootinfo *' in a3.  While slightly
  198          * grody, we support both here by detecting 'pointer-like' values in
  199          * a3 and assuming physical memory can never be that back.
  200          *
  201          * XXXRW: Pull more values than memsize out of bootinfop -- e.g.,
  202          * module information.
  203          */
  204         if (a3 >= 0x9800000000000000ULL) {
  205                 bootinfop = (void *)a3;
  206                 memsize = bootinfop->bi_memsize;
  207                 preload_metadata = (caddr_t)bootinfop->bi_modulep;
  208         } else {
  209                 bootinfop = NULL;
  210                 memsize = a3;
  211         }
  212 
  213 #ifdef FDT
  214         /*
  215          * Find the dtb passed in by the boot loader (currently fictional).
  216          */
  217         kmdp = preload_search_by_type("elf kernel");
  218         dtbp = MD_FETCH(kmdp, MODINFOMD_DTBP, vm_offset_t);
  219 
  220 #if defined(FDT_DTB_STATIC)
  221         /*
  222          * In case the device tree blob was not retrieved (from metadata) try
  223          * to use the statically embedded one.
  224          */
  225         if (dtbp == (vm_offset_t)NULL)
  226                 dtbp = (vm_offset_t)&fdt_static_dtb;
  227 #else
  228 #error  "Non-static FDT not yet supported on BERI"
  229 #endif
  230 
  231         if (OF_install(OFW_FDT, 0) == FALSE)
  232                 while (1);
  233         if (OF_init((void *)dtbp) != 0)
  234                 while (1);
  235 
  236         /*
  237          * Configure more boot-time parameters passed in by loader.
  238          */
  239         boothowto = MD_FETCH(kmdp, MODINFOMD_HOWTO, int);
  240         init_static_kenv(MD_FETCH(kmdp, MODINFOMD_ENVP, char *), 0);
  241 
  242         /*
  243          * Get bootargs from FDT if specified.
  244          */
  245         ofw_parse_bootargs();
  246 #endif
  247 
  248         /*
  249          * XXXRW: We have no way to compare wallclock time to cycle rate on
  250          * BERI, so for now assume we run at the MALTA default (100MHz).
  251          */
  252         platform_counter_freq = MIPS_DEFAULT_HZ;
  253         mips_timer_early_init(platform_counter_freq);
  254 
  255         cninit();
  256         printf("entry: platform_start()\n");
  257 
  258         bootverbose = 1;
  259         if (bootverbose) {
  260                 printf("cmd line: ");
  261                 for (i = 0; i < argc; i++)
  262                         printf("%s ", argv[i]);
  263                 printf("\n");
  264 
  265                 printf("envp:\n");
  266                 for (i = 0; envp[i]; i += 2)
  267                         printf("\t%s = %s\n", envp[i], envp[i+1]);
  268 
  269                 if (bootinfop != NULL)
  270                         printf("bootinfo found at %p\n", bootinfop);
  271 
  272                 printf("memsize = %p\n", (void *)memsize);
  273         }
  274 
  275         realmem = btoc(memsize);
  276         mips_init();
  277 
  278         mips_timer_init_params(platform_counter_freq, 0);
  279 }

Cache object: 320f4d28f78e1a8930dc3f321c601d4c


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