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/ingenic/jz4780_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 Oleksandr Tymoshenko
    3  * Copyright (c) 2015 Alexander Kabaev
    4  * All rights reserved.
    5  *
    6  * Redistribution and use in source and binary forms, with or without
    7  * modification, are permitted provided that the following conditions
    8  * are met:
    9  * 1. Redistributions of source code must retain the above copyright
   10  *    notice, this list of conditions and the following disclaimer.
   11  * 2. Redistributions in binary form must reproduce the above copyright
   12  *    notice, this list of conditions and the following disclaimer in the
   13  *    documentation and/or other materials provided with the distribution.
   14  *
   15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   25  * SUCH DAMAGE.
   26  */
   27 
   28 #include <sys/cdefs.h>
   29 __FBSDID("$FreeBSD: releng/12.0/sys/mips/ingenic/jz4780_machdep.c 336245 2018-07-13 16:43:17Z imp $");
   30 
   31 #include "opt_ddb.h"
   32 #include "opt_platform.h"
   33 
   34 #include <sys/param.h>
   35 #include <sys/conf.h>
   36 #include <sys/kernel.h>
   37 #include <sys/systm.h>
   38 #include <sys/bus.h>
   39 #include <sys/cons.h>
   40 #include <sys/kdb.h>
   41 #include <sys/reboot.h>
   42 
   43 #ifdef FDT
   44 #include <dev/fdt/fdt_common.h>
   45 #include <dev/ofw/openfirm.h>
   46 #endif
   47 
   48 #include <vm/vm.h>
   49 #include <vm/vm_page.h>
   50 
   51 #include <net/ethernet.h>
   52 
   53 #include <machine/clock.h>
   54 #include <machine/cpu.h>
   55 #include <machine/cpufunc.h>
   56 #include <machine/hwfunc.h>
   57 #include <machine/md_var.h>
   58 #include <machine/trap.h>
   59 #include <machine/vmparam.h>
   60 
   61 #include <mips/ingenic/jz4780_regs.h>
   62 #include <mips/ingenic/jz4780_cpuregs.h>
   63 
   64 uint32_t * const led = (uint32_t *)0xb0010548;
   65 
   66 extern char edata[], end[];
   67 static char boot1_env[4096];
   68 
   69 void
   70 platform_cpu_init(void)
   71 {
   72         uint32_t reg;
   73 
   74         /*
   75          * Do not expect mbox interrups while writing
   76          * mbox
   77          */
   78         reg = mips_rd_xburst_reim();
   79         reg &= ~JZ_REIM_MIRQ0M;
   80         mips_wr_xburst_reim(reg);
   81 
   82         /* Clean mailboxes */
   83         mips_wr_xburst_mbox0(0);
   84         mips_wr_xburst_mbox1(0);
   85         mips_wr_xburst_core_sts(~JZ_CORESTS_MIRQ0P);
   86 
   87         /* Unmask mbox interrupts */
   88         reg |= JZ_REIM_MIRQ0M;
   89         mips_wr_xburst_reim(reg);
   90 }
   91 
   92 void
   93 platform_reset(void)
   94 {
   95         /*
   96          * For now, provoke a watchdog reset in about a second, so UART buffers
   97          * have a fighting chance to flush before we pull the plug
   98          */
   99         writereg(JZ_TCU_BASE + JZ_WDOG_TCER, 0);        /* disable watchdog */
  100         writereg(JZ_TCU_BASE + JZ_WDOG_TCNT, 0);        /* reset counter */
  101         writereg(JZ_TCU_BASE + JZ_WDOG_TDR, 128);       /* wait for ~1s */
  102         writereg(JZ_TCU_BASE + JZ_WDOG_TCSR, TCSR_RTC_EN | TCSR_DIV_256);
  103         writereg(JZ_TCU_BASE + JZ_WDOG_TCER, TCER_ENABLE);      /* fire! */
  104 
  105         /* Wait for reset */
  106         while (1)
  107                 ;
  108 }
  109 
  110 static void
  111 mips_init(void)
  112 {
  113         int i;
  114 #ifdef FDT
  115         struct mem_region mr[FDT_MEM_REGIONS];
  116         uint64_t val;
  117         int mr_cnt;
  118         int j;
  119 #endif
  120 
  121         for (i = 0; i < 10; i++) {
  122                 phys_avail[i] = 0;
  123         }
  124 
  125         /* The minimal amount of memory Ingenic SoC can have. */
  126         dump_avail[0] = phys_avail[0] = MIPS_KSEG0_TO_PHYS(kernel_kseg0_end);
  127         physmem = realmem = btoc(32 * 1024 * 1024);
  128 
  129         /*
  130          * X1000 mips cpu special.
  131          * TODO: do anyone know what is this ?
  132          */
  133         __asm(
  134                 "li     $2, 0xa9000000  \n\t"
  135                 "mtc0   $2, $5, 4       \n\t"
  136                 "nop                    \n\t"
  137                 ::"r"(2));
  138 
  139 #ifdef FDT
  140         if (fdt_get_mem_regions(mr, &mr_cnt, &val) == 0) {
  141 
  142                 physmem = realmem = btoc(val);
  143 
  144                 KASSERT((phys_avail[0] >= mr[0].mr_start) && \
  145                         (phys_avail[0] < (mr[0].mr_start + mr[0].mr_size)),
  146                         ("First region is not within FDT memory range"));
  147 
  148                 /* Limit size of the first region */
  149                 phys_avail[1] = (mr[0].mr_start + MIN(mr[0].mr_size, ctob(realmem)));
  150                 dump_avail[1] = phys_avail[1];
  151 
  152                 /* Add the rest of regions */
  153                 for (i = 1, j = 2; i < mr_cnt; i++, j+=2) {
  154                         phys_avail[j] = mr[i].mr_start;
  155                         phys_avail[j+1] = (mr[i].mr_start + mr[i].mr_size);
  156                         dump_avail[j] = phys_avail[j];
  157                         dump_avail[j+1] = phys_avail[j+1];
  158                 }
  159         }
  160 #endif
  161 
  162         init_param1();
  163         init_param2(physmem);
  164         mips_cpu_init();
  165         pmap_bootstrap();
  166         mips_proc0_init();
  167         mutex_init();
  168         kdb_init();
  169         led[0] = 0x8000;
  170 #ifdef KDB
  171         if (boothowto & RB_KDB)
  172                 kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger");
  173 #endif
  174 }
  175 
  176 #ifdef FDT
  177 static void
  178 _parse_bootargs(char *cmdline)
  179 {
  180         char *v;
  181 
  182         while ((v = strsep(&cmdline, " \n")) != NULL) {
  183                 if (*v == '\0')
  184                         continue;
  185                 boothowto |= boot_parse_arg(v);
  186         }
  187 }
  188 #endif
  189 
  190 void
  191 platform_start(__register_t a0,  __register_t a1,
  192     __register_t a2 __unused, __register_t a3 __unused)
  193 {
  194         char **argv;
  195         int  argc;
  196         vm_offset_t kernend;
  197 #ifdef FDT
  198         vm_offset_t dtbp;
  199         phandle_t chosen;
  200         char buf[2048];         /* early stack supposedly big enough */
  201 #endif
  202         /*
  203          * clear the BSS and SBSS segments, this should be first call in
  204          * the function
  205          */
  206         kernend = (vm_offset_t)&end;
  207         memset(&edata, 0, kernend - (vm_offset_t)(&edata));
  208 
  209         mips_postboot_fixup();
  210 
  211         /* Initialize pcpu stuff */
  212         mips_pcpu0_init();
  213 
  214         /* Something to hold kernel env until kmem is available */
  215         init_static_kenv(boot1_env, sizeof(boot1_env));
  216 #ifdef FDT
  217         /*
  218          * Find the dtb passed in by the boot loader (currently fictional).
  219          */
  220         dtbp = (vm_offset_t)NULL;
  221 
  222 #if defined(FDT_DTB_STATIC)
  223         /*
  224          * In case the device tree blob was not retrieved (from metadata) try
  225          * to use the statically embedded one.
  226          */
  227         if (dtbp == (vm_offset_t)NULL)
  228                 dtbp = (vm_offset_t)&fdt_static_dtb;
  229 #else
  230 #error  "Non-static FDT not supported on JZ4780"
  231 #endif
  232         if (OF_install(OFW_FDT, 0) == FALSE)
  233                 while (1);
  234         if (OF_init((void *)dtbp) != 0)
  235                 while (1);
  236 #endif
  237 
  238         cninit();
  239 #ifdef FDT
  240         /*
  241          * Get bootargs from FDT if specified.
  242          */
  243         chosen = OF_finddevice("/chosen");
  244         if (OF_getprop(chosen, "bootargs", buf, sizeof(buf)) != -1)
  245                 boothowto |= boot_parse_cmdline(buf);
  246 #endif
  247         /* Parse cmdline from U-Boot */
  248         argc = a0;
  249         argv = (char **)a1;
  250         boothowto |= boot_parse_cmdline(argc, argv);
  251 
  252         mips_init();
  253 }

Cache object: 644ada42647ab3ddac819c02c5a8baba


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