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_object.h>
   69 #include <vm/vm_page.h>
   70 
   71 #include <machine/bootinfo.h>
   72 #include <machine/clock.h>
   73 #include <machine/cpu.h>
   74 #include <machine/cpuregs.h>
   75 #include <machine/hwfunc.h>
   76 #include <machine/md_var.h>
   77 #include <machine/metadata.h>
   78 #include <machine/pmap.h>
   79 #include <machine/trap.h>
   80 
   81 extern int      *edata;
   82 extern int      *end;
   83 
   84 void
   85 platform_cpu_init()
   86 {
   87         /* Nothing special */
   88 }
   89 
   90 static void
   91 mips_init(void)
   92 {
   93         int i;
   94 #ifdef FDT
   95         struct mem_region mr[FDT_MEM_REGIONS];
   96         uint64_t val;
   97         int mr_cnt;
   98         int j;
   99 #endif
  100 
  101         for (i = 0; i < 10; i++) {
  102                 phys_avail[i] = 0;
  103         }
  104 
  105         /* phys_avail regions are in bytes */
  106         phys_avail[0] = MIPS_KSEG0_TO_PHYS(kernel_kseg0_end);
  107         phys_avail[1] = ctob(realmem);
  108 
  109         dump_avail[0] = phys_avail[0];
  110         dump_avail[1] = phys_avail[1];
  111 
  112         physmem = realmem;
  113 
  114 #ifdef FDT
  115         if (fdt_get_mem_regions(mr, &mr_cnt, &val) == 0) {
  116 
  117                 physmem = btoc(val);
  118 
  119                 KASSERT((phys_avail[0] >= mr[0].mr_start) && \
  120                         (phys_avail[0] < (mr[0].mr_start + mr[0].mr_size)),
  121                         ("First region is not within FDT memory range"));
  122 
  123                 /* Limit size of the first region */
  124                 phys_avail[1] = (mr[0].mr_start + MIN(mr[0].mr_size, ctob(realmem)));
  125                 dump_avail[1] = phys_avail[1];
  126 
  127                 /* Add the rest of regions */
  128                 for (i = 1, j = 2; i < mr_cnt; i++, j+=2) {
  129                         phys_avail[j] = mr[i].mr_start;
  130                         phys_avail[j+1] = (mr[i].mr_start + mr[i].mr_size);
  131                         dump_avail[j] = phys_avail[j];
  132                         dump_avail[j+1] = phys_avail[j+1];
  133                 }
  134         }
  135 #endif
  136 
  137         init_param1();
  138         init_param2(physmem);
  139         mips_cpu_init();
  140         pmap_bootstrap();
  141         mips_proc0_init();
  142         mutex_init();
  143         kdb_init();
  144 #ifdef KDB
  145         if (boothowto & RB_KDB)
  146                 kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger");
  147 #endif
  148 }
  149 
  150 /*
  151  * Perform a board-level soft-reset.
  152  */
  153 void
  154 platform_reset(void)
  155 {
  156 
  157         /* XXX SMP will likely require us to do more. */
  158         __asm__ __volatile__(
  159                 "mfc0 $k0, $12\n\t"
  160                 "li $k1, 0x00100000\n\t"
  161                 "or $k0, $k0, $k1\n\t"
  162                 "mtc0 $k0, $12\n");
  163         for( ; ; )
  164                 __asm__ __volatile("wait");
  165 }
  166 
  167 void
  168 platform_start(__register_t a0, __register_t a1,  __register_t a2, 
  169     __register_t a3)
  170 {
  171         struct bootinfo *bootinfop;
  172         vm_offset_t kernend;
  173         uint64_t platform_counter_freq;
  174         int argc = a0;
  175         char **argv = (char **)a1;
  176         char **envp = (char **)a2;
  177         long memsize;
  178 #ifdef FDT
  179         vm_offset_t dtbp;
  180         void *kmdp;
  181 #endif
  182         int i;
  183 
  184         /* clear the BSS and SBSS segments */
  185         kernend = (vm_offset_t)&end;
  186         memset(&edata, 0, kernend - (vm_offset_t)(&edata));
  187 
  188         mips_postboot_fixup();
  189 
  190         mips_pcpu0_init();
  191 
  192         /*
  193          * Over time, we've changed out boot-time binary interface for the
  194          * kernel.  Miniboot simply provides a 'memsize' in a3, whereas the
  195          * FreeBSD boot loader provides a 'bootinfo *' in a3.  While slightly
  196          * grody, we support both here by detecting 'pointer-like' values in
  197          * a3 and assuming physical memory can never be that back.
  198          *
  199          * XXXRW: Pull more values than memsize out of bootinfop -- e.g.,
  200          * module information.
  201          */
  202         if (a3 >= 0x9800000000000000ULL) {
  203                 bootinfop = (void *)a3;
  204                 memsize = bootinfop->bi_memsize;
  205                 preload_metadata = (caddr_t)bootinfop->bi_modulep;
  206         } else {
  207                 bootinfop = NULL;
  208                 memsize = a3;
  209         }
  210 
  211 #ifdef FDT
  212         /*
  213          * Find the dtb passed in by the boot loader (currently fictional).
  214          */
  215         kmdp = preload_search_by_type("elf kernel");
  216         dtbp = MD_FETCH(kmdp, MODINFOMD_DTBP, vm_offset_t);
  217 
  218 #if defined(FDT_DTB_STATIC)
  219         /*
  220          * In case the device tree blob was not retrieved (from metadata) try
  221          * to use the statically embedded one.
  222          */
  223         if (dtbp == (vm_offset_t)NULL)
  224                 dtbp = (vm_offset_t)&fdt_static_dtb;
  225 #else
  226 #error  "Non-static FDT not yet supported on BERI"
  227 #endif
  228 
  229         if (OF_install(OFW_FDT, 0) == FALSE)
  230                 while (1);
  231         if (OF_init((void *)dtbp) != 0)
  232                 while (1);
  233 
  234         /*
  235          * Configure more boot-time parameters passed in by loader.
  236          */
  237         boothowto = MD_FETCH(kmdp, MODINFOMD_HOWTO, int);
  238         init_static_kenv(MD_FETCH(kmdp, MODINFOMD_ENVP, char *), 0);
  239 
  240         /*
  241          * Get bootargs from FDT if specified.
  242          */
  243         ofw_parse_bootargs();
  244 #endif
  245 
  246         /*
  247          * XXXRW: We have no way to compare wallclock time to cycle rate on
  248          * BERI, so for now assume we run at the MALTA default (100MHz).
  249          */
  250         platform_counter_freq = MIPS_DEFAULT_HZ;
  251         mips_timer_early_init(platform_counter_freq);
  252 
  253         cninit();
  254         printf("entry: platform_start()\n");
  255 
  256         bootverbose = 1;
  257         if (bootverbose) {
  258                 printf("cmd line: ");
  259                 for (i = 0; i < argc; i++)
  260                         printf("%s ", argv[i]);
  261                 printf("\n");
  262 
  263                 printf("envp:\n");
  264                 for (i = 0; envp[i]; i += 2)
  265                         printf("\t%s = %s\n", envp[i], envp[i+1]);
  266 
  267                 if (bootinfop != NULL)
  268                         printf("bootinfo found at %p\n", bootinfop);
  269 
  270                 printf("memsize = %p\n", (void *)memsize);
  271         }
  272 
  273         realmem = btoc(memsize);
  274         mips_init();
  275 
  276         mips_timer_init_params(platform_counter_freq, 0);
  277 }

Cache object: 19c47b1c444178a96e091e6900eeb3f9


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