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/atheros/ar531x/ar5315_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) 2016, Hiroki Mori
    3  * Copyright (c) 2009 Oleksandr Tymoshenko
    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/atheros/ar531x/ar5315_machdep.c 336245 2018-07-13 16:43:17Z imp $");
   30 
   31 #include "opt_ddb.h"
   32 #include "opt_ar531x.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 #include <sys/boot.h>
   43 
   44 #include <vm/vm.h>
   45 #include <vm/vm_page.h>
   46 
   47 #include <net/ethernet.h>
   48 
   49 #include <machine/clock.h>
   50 #include <machine/cpu.h>
   51 #include <machine/cpuregs.h>
   52 #include <machine/hwfunc.h>
   53 #include <machine/md_var.h>
   54 #include <machine/trap.h>
   55 #include <machine/vmparam.h>
   56 
   57 #include <mips/atheros/ar531x/ar5315reg.h>
   58 
   59 #include <mips/atheros/ar531x/ar5315_setup.h>
   60 #include <mips/atheros/ar531x/ar5315_cpudef.h>
   61 
   62 extern char edata[], end[];
   63 
   64 uint32_t ar711_base_mac[ETHER_ADDR_LEN];
   65 /* 4KB static data aread to keep a copy of the bootload env until
   66    the dynamic kenv is setup */
   67 char boot1_env[4096];
   68 
   69 void
   70 platform_cpu_init()
   71 {
   72         /* Nothing special */
   73 }
   74 
   75 void
   76 platform_reset(void)
   77 {
   78         ar531x_device_reset();
   79         /* Wait for reset */
   80         while(1)
   81                 ;
   82 }
   83 
   84 /*
   85  * Obtain the MAC address via the Redboot environment.
   86  */
   87 static void
   88 ar5315_redboot_get_macaddr(void)
   89 {
   90         char *var;
   91         int count = 0;
   92 
   93         /*
   94          * "ethaddr" is passed via envp on RedBoot platforms
   95          * "kmac" is passed via argv on RouterBOOT platforms
   96          */
   97         if ((var = kern_getenv("ethaddr")) != NULL ||
   98             (var = kern_getenv("kmac")) != NULL) {
   99                 count = sscanf(var, "%x%*c%x%*c%x%*c%x%*c%x%*c%x",
  100                     &ar711_base_mac[0], &ar711_base_mac[1],
  101                     &ar711_base_mac[2], &ar711_base_mac[3],
  102                     &ar711_base_mac[4], &ar711_base_mac[5]);
  103                 if (count < 6)
  104                         memset(ar711_base_mac, 0,
  105                             sizeof(ar711_base_mac));
  106                 freeenv(var);
  107         }
  108 }
  109 
  110 #if defined(SOC_VENDOR) || defined(SOC_MODEL) || defined(SOC_REV)
  111 static SYSCTL_NODE(_hw, OID_AUTO, soc, CTLFLAG_RD, 0,
  112     "System on Chip information");
  113 #endif
  114 #if defined(SOC_VENDOR)
  115 static char hw_soc_vendor[] = SOC_VENDOR;
  116 SYSCTL_STRING(_hw_soc, OID_AUTO, vendor, CTLFLAG_RD, hw_soc_vendor, 0,
  117            "SoC vendor");
  118 #endif
  119 #if defined(SOC_MODEL)
  120 static char hw_soc_model[] = SOC_MODEL;
  121 SYSCTL_STRING(_hw_soc, OID_AUTO, model, CTLFLAG_RD, hw_soc_model, 0,
  122            "SoC model");
  123 #endif
  124 #if defined(SOC_REV)
  125 static char hw_soc_revision[] = SOC_REV;
  126 SYSCTL_STRING(_hw_soc, OID_AUTO, revision, CTLFLAG_RD, hw_soc_revision, 0,
  127            "SoC revision");
  128 #endif
  129 
  130 #if defined(DEVICE_VENDOR) || defined(DEVICE_MODEL) || defined(DEVICE_REV)
  131 static SYSCTL_NODE(_hw, OID_AUTO, device, CTLFLAG_RD, 0, "Board information");
  132 #endif
  133 #if defined(DEVICE_VENDOR)
  134 static char hw_device_vendor[] = DEVICE_VENDOR;
  135 SYSCTL_STRING(_hw_device, OID_AUTO, vendor, CTLFLAG_RD, hw_device_vendor, 0,
  136            "Board vendor");
  137 #endif
  138 #if defined(DEVICE_MODEL)
  139 static char hw_device_model[] = DEVICE_MODEL;
  140 SYSCTL_STRING(_hw_device, OID_AUTO, model, CTLFLAG_RD, hw_device_model, 0,
  141            "Board model");
  142 #endif
  143 #if defined(DEVICE_REV)
  144 static char hw_device_revision[] = DEVICE_REV;
  145 SYSCTL_STRING(_hw_device, OID_AUTO, revision, CTLFLAG_RD, hw_device_revision, 0,
  146            "Board revision");
  147 #endif
  148 
  149 void
  150 platform_start(__register_t a0 __unused, __register_t a1 __unused, 
  151     __register_t a2 __unused, __register_t a3 __unused)
  152 {
  153         uint64_t platform_counter_freq;
  154         int argc = 0, i;
  155         char **argv = NULL;
  156 #ifndef AR531X_ENV_UBOOT
  157         char **envp = NULL;
  158 #endif
  159         vm_offset_t kernend;
  160 
  161         /* 
  162          * clear the BSS and SBSS segments, this should be first call in
  163          * the function
  164          */
  165         kernend = (vm_offset_t)&end;
  166         memset(&edata, 0, kernend - (vm_offset_t)(&edata));
  167 
  168         mips_postboot_fixup();
  169 
  170         /* Initialize pcpu stuff */
  171         mips_pcpu0_init();
  172 
  173         /*
  174          * Until some more sensible abstractions for uboot/redboot
  175          * environment handling, we have to make this a compile-time
  176          * hack.  The existing code handles the uboot environment
  177          * very incorrectly so we should just ignore initialising
  178          * the relevant pointers.
  179          */
  180 #ifndef AR531X_ENV_UBOOT
  181         argc = a0;
  182         argv = (char**)a1;
  183         envp = (char**)a2;
  184 #endif
  185         /* 
  186          * Protect ourselves from garbage in registers 
  187          */
  188         if (MIPS_IS_VALID_PTR(envp)) {
  189                 for (i = 0; envp[i]; i += 2) {
  190                         if (strcmp(envp[i], "memsize") == 0)
  191                                 realmem = btoc(strtoul(envp[i+1], NULL, 16));
  192                 }
  193         }
  194 
  195         ar5315_detect_sys_type();
  196 
  197 // RedBoot SDRAM Detect is missing
  198 //      ar531x_detect_mem_size();
  199 
  200         /*
  201          * Just wild guess. RedBoot let us down and didn't reported 
  202          * memory size
  203          */
  204         if (realmem == 0)
  205                 realmem = btoc(16*1024*1024);
  206 
  207         /*
  208          * Allow build-time override in case Redboot lies
  209          * or in other situations (eg where there's u-boot)
  210          * where there isn't (yet) a convienent method of
  211          * being told how much RAM is available.
  212          *
  213          * This happens on at least the Ubiquiti LS-SR71A
  214          * board, where redboot says there's 16mb of RAM
  215          * but in fact there's 32mb.
  216          */
  217 #if     defined(AR531X_REALMEM)
  218                 realmem = btoc(AR531X_REALMEM);
  219 #endif
  220 
  221         /* phys_avail regions are in bytes */
  222         phys_avail[0] = MIPS_KSEG0_TO_PHYS(kernel_kseg0_end);
  223         phys_avail[1] = ctob(realmem);
  224 
  225         dump_avail[0] = phys_avail[0];
  226         dump_avail[1] = phys_avail[1] - phys_avail[0];
  227 
  228         physmem = realmem;
  229 
  230         /*
  231          * ns8250 uart code uses DELAY so ticker should be inititalized 
  232          * before cninit. And tick_init_params refers to hz, so * init_param1 
  233          * should be called first.
  234          */
  235         init_param1();
  236         boothowto |= (RB_SERIAL | RB_MULTIPLE); /* Use multiple consoles */
  237 //      boothowto |= RB_VERBOSE;
  238 //      boothowto |= (RB_SINGLE);
  239 
  240         /* Detect the system type - this is needed for subsequent chipset-specific calls */
  241 
  242 
  243         ar531x_device_soc_init();
  244         ar531x_detect_sys_frequency();
  245 
  246         platform_counter_freq = ar531x_cpu_freq();
  247         mips_timer_init_params(platform_counter_freq, 1);
  248         cninit();
  249         init_static_kenv(boot1_env, sizeof(boot1_env));
  250 
  251         printf("CPU platform: %s\n", ar5315_get_system_type());
  252         printf("CPU Frequency=%d MHz\n", ar531x_cpu_freq() / 1000000);
  253         printf("CPU DDR Frequency=%d MHz\n", ar531x_ddr_freq() / 1000000);
  254         printf("CPU AHB Frequency=%d MHz\n", ar531x_ahb_freq() / 1000000); 
  255 
  256         printf("platform frequency: %lld\n", platform_counter_freq);
  257         printf("arguments: \n");
  258         printf("  a0 = %08x\n", a0);
  259         printf("  a1 = %08x\n", a1);
  260         printf("  a2 = %08x\n", a2);
  261         printf("  a3 = %08x\n", a3);
  262 
  263         /*
  264          * XXX this code is very redboot specific.
  265          */
  266         printf("Cmd line:");
  267         if (MIPS_IS_VALID_PTR(argv)) {
  268                 for (i = 0; i < argc; i++) {
  269                         printf(" %s", argv[i]);
  270                         boothowto |= boot_parse_arg(argv[i]);
  271                 }
  272         }
  273         else
  274                 printf ("argv is invalid");
  275         printf("\n");
  276 
  277         printf("Environment:\n");
  278 #if 0
  279         if (MIPS_IS_VALID_PTR(envp)) {
  280                 if (envp[0] && strchr(envp[0], '=') ) {
  281                         char *env_val; //
  282                         for (i = 0; envp[i]; i++) {
  283                                 env_val = strchr(envp[i], '=');
  284                                 /* Not sure if we correct to change data, but env in RAM */
  285                                 *(env_val++) = '\0';
  286                                 printf("=  %s = %s\n", envp[i], env_val);
  287                                 kern_setenv(envp[i], env_val);
  288                         }
  289                 } else {
  290                         for (i = 0; envp[i]; i+=2) {
  291                                 printf("  %s = %s\n", envp[i], envp[i+1]);
  292                                 kern_setenv(envp[i], envp[i+1]);
  293                         }
  294                 }
  295         }
  296         else 
  297                 printf ("envp is invalid\n");
  298 #else
  299         printf ("envp skiped\n");
  300 #endif
  301 
  302         /* Redboot if_are MAC address is in the environment */
  303         ar5315_redboot_get_macaddr();
  304 
  305         init_param2(physmem);
  306         mips_cpu_init();
  307         pmap_bootstrap();
  308         mips_proc0_init();
  309         mutex_init();
  310 
  311         ar531x_device_start();
  312 
  313         kdb_init();
  314 #ifdef KDB
  315         if (boothowto & RB_KDB)
  316                 kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger");
  317 #endif
  318 
  319 }

Cache object: 0f144c32d684ebced972bbb588afcb08


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