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/ar71xx_machdep.c

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 2009 Oleksandr Tymoshenko
    3  * All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    8  * 1. Redistributions of source code must retain the above copyright
    9  *    notice, this list of conditions and the following disclaimer.
   10  * 2. Redistributions in binary form must reproduce the above copyright
   11  *    notice, this list of conditions and the following disclaimer in the
   12  *    documentation and/or other materials provided with the distribution.
   13  *
   14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   24  * SUCH DAMAGE.
   25  */
   26 
   27 #include <sys/cdefs.h>
   28 __FBSDID("$FreeBSD: stable/8/sys/mips/atheros/ar71xx_machdep.c 215965 2010-11-28 01:08:42Z gonzo $");
   29 
   30 #include <sys/param.h>
   31 #include <machine/cpuregs.h>
   32 
   33 #include <mips/sentry5/s5reg.h>
   34 
   35 #include "opt_ddb.h"
   36 
   37 #include <sys/param.h>
   38 #include <sys/conf.h>
   39 #include <sys/kernel.h>
   40 #include <sys/systm.h>
   41 #include <sys/bus.h>
   42 #include <sys/cons.h>
   43 #include <sys/kdb.h>
   44 #include <sys/reboot.h>
   45 
   46 #include <vm/vm.h>
   47 #include <vm/vm_page.h>
   48 
   49 #include <net/ethernet.h>
   50 
   51 #include <machine/clock.h>
   52 #include <machine/cpu.h>
   53 #include <machine/hwfunc.h>
   54 #include <machine/md_var.h>
   55 #include <machine/trap.h>
   56 #include <machine/vmparam.h>
   57 
   58 #include <mips/atheros/ar71xxreg.h>
   59 
   60 #include <mips/atheros/ar71xx_setup.h>
   61 #include <mips/atheros/ar71xx_cpudef.h>
   62 
   63 extern char edata[], end[];
   64 
   65 uint32_t ar711_base_mac[ETHER_ADDR_LEN];
   66 /* 4KB static data aread to keep a copy of the bootload env until
   67    the dynamic kenv is setup */
   68 char boot1_env[4096];
   69 int boot1_env_pos = 0;
   70 
   71 static void
   72 static_setenv(char *n, char *v)
   73 {
   74         int nlen, vlen;
   75 
   76         nlen = strlen(n);
   77         vlen = strlen(v);
   78         if (boot1_env_pos + nlen + vlen + 2 > sizeof(boot1_env)) {
   79                 printf("*** Environment could not be copied in full\n");
   80                 return;
   81         }
   82         memcpy (&boot1_env[boot1_env_pos], n, nlen);
   83         boot1_env_pos += nlen + 1;
   84         boot1_env[boot1_env_pos-1] = '\0';
   85         memcpy (&boot1_env[boot1_env_pos], v, vlen);
   86         boot1_env_pos += vlen + 1;
   87         boot1_env[boot1_env_pos-1] = '\0';
   88 }
   89 
   90 /*
   91  * We get a string in from Redboot with the all the arguments together,
   92  * "foo=bar bar=baz". Split them up and save in kenv.
   93  */
   94 static void
   95 parse_argv(char *str)
   96 {
   97         char *n, *v;
   98 
   99         while ((v = strsep(&str, " ")) != NULL) {
  100                 if (*v == '\0')
  101                         continue;
  102                 if (*v == '-') {
  103                         while (*v != '\0') {
  104                                 v++;
  105                                 switch (*v) {
  106                                 case 'a': boothowto |= RB_ASKNAME; break;
  107                                 case 'd': boothowto |= RB_KDB; break;
  108                                 case 'g': boothowto |= RB_GDB; break;
  109                                 case 's': boothowto |= RB_SINGLE; break;
  110                                 case 'v': boothowto |= RB_VERBOSE; break;
  111                                 }
  112                         }
  113                 } else {
  114                         n = strsep(&v, "=");
  115                         if (v == NULL)
  116                                 v = "1";
  117                         static_setenv(n, v);
  118                 }
  119         }
  120 }
  121 
  122 void
  123 platform_cpu_init()
  124 {
  125         /* Nothing special */
  126 }
  127 
  128 void
  129 platform_halt(void)
  130 {
  131 
  132 }
  133 
  134 void
  135 platform_identify(void)
  136 {
  137 
  138 }
  139 
  140 void
  141 platform_reset(void)
  142 {
  143         ar71xx_device_stop(RST_RESET_FULL_CHIP);
  144         /* Wait for reset */
  145         while(1)
  146                 ;
  147 }
  148 
  149 void
  150 platform_trap_enter(void)
  151 {
  152 
  153 }
  154 
  155 void
  156 platform_trap_exit(void)
  157 {
  158 
  159 }
  160 
  161 void
  162 platform_start(__register_t a0 __unused, __register_t a1 __unused, 
  163     __register_t a2 __unused, __register_t a3 __unused)
  164 {
  165         uint64_t platform_counter_freq;
  166         int argc, i, count = 0;
  167         char **argv, **envp, *var;
  168         vm_offset_t kernend;
  169 
  170         /* 
  171          * clear the BSS and SBSS segments, this should be first call in
  172          * the function
  173          */
  174         kernend = (vm_offset_t)&end;
  175         memset(&edata, 0, kernend - (vm_offset_t)(&edata));
  176 
  177         mips_postboot_fixup();
  178 
  179         /* Initialize pcpu stuff */
  180         mips_pcpu0_init();
  181 
  182         argc = a0;
  183         argv = (char**)a1;
  184         envp = (char**)a2;
  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         /*
  196          * Just wild guess. RedBoot let us down and didn't reported 
  197          * memory size
  198          */
  199         if (realmem == 0)
  200                 realmem = btoc(32*1024*1024);
  201 
  202         /* phys_avail regions are in bytes */
  203         phys_avail[0] = MIPS_KSEG0_TO_PHYS(kernel_kseg0_end);
  204         phys_avail[1] = ctob(realmem);
  205 
  206         physmem = realmem;
  207 
  208         /*
  209          * ns8250 uart code uses DELAY so ticker should be inititalized 
  210          * before cninit. And tick_init_params refers to hz, so * init_param1 
  211          * should be called first.
  212          */
  213         init_param1();
  214 
  215         /* Detect the system type - this is needed for subsequent chipset-specific calls */
  216         ar71xx_detect_sys_type();
  217         ar71xx_detect_sys_frequency();
  218 
  219         platform_counter_freq = ar71xx_cpu_freq();
  220         mips_timer_init_params(platform_counter_freq, 1);
  221         cninit();
  222 
  223         printf("CPU platform: %s\n", ar71xx_get_system_type());
  224         printf("CPU Frequency=%d MHz\n", u_ar71xx_cpu_freq / 1000000);
  225         printf("CPU DDR Frequency=%d MHz\n", u_ar71xx_ddr_freq / 1000000);
  226         printf("CPU AHB Frequency=%d MHz\n", u_ar71xx_ahb_freq / 1000000); 
  227 
  228         printf("platform frequency: %lld\n", platform_counter_freq);
  229         printf("arguments: \n");
  230         printf("  a0 = %08x\n", a0);
  231         printf("  a1 = %08x\n", a1);
  232         printf("  a2 = %08x\n", a2);
  233         printf("  a3 = %08x\n", a3);
  234 
  235         printf("Cmd line:");
  236         if (MIPS_IS_VALID_PTR(argv)) {
  237                 for (i = 0; i < argc; i++) {
  238                         printf(" %s", argv[i]);
  239                         parse_argv(argv[i]);
  240                 }
  241         }
  242         else
  243                 printf ("argv is invalid");
  244         printf("\n");
  245 
  246         printf("Environment:\n");
  247         if (MIPS_IS_VALID_PTR(envp)) {
  248                 for (i = 0; envp[i]; i+=2) {
  249                         printf("  %s = %s\n", envp[i], envp[i+1]);
  250                         static_setenv(envp[i], envp[i+1]);
  251                 }
  252         }
  253         else 
  254                 printf ("envp is invalid\n");
  255         kern_envp = boot1_env;
  256 
  257         /*
  258          * "ethaddr" is passed via envp on RedBoot platforms
  259          * "kmac" is passed via argv on RouterBOOT platforms
  260          */
  261         if ((var = getenv("ethaddr")) != NULL ||
  262             (var = getenv("kmac")) != NULL) {
  263                 count = sscanf(var, "%x%*c%x%*c%x%*c%x%*c%x%*c%x",
  264                     &ar711_base_mac[0], &ar711_base_mac[1],
  265                     &ar711_base_mac[2], &ar711_base_mac[3],
  266                     &ar711_base_mac[4], &ar711_base_mac[5]);
  267                 if (count < 6)
  268                         memset(ar711_base_mac, 0,
  269                             sizeof(ar711_base_mac));
  270                 freeenv(var);
  271         }
  272 
  273         init_param2(physmem);
  274         mips_cpu_init();
  275         pmap_bootstrap();
  276         mips_proc0_init();
  277         mutex_init();
  278 
  279         /*
  280          * Reset USB devices 
  281          */
  282         ar71xx_init_usb_peripheral();
  283 
  284         kdb_init();
  285 #ifdef KDB
  286         if (boothowto & RB_KDB)
  287                 kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger");
  288 #endif
  289 }

Cache object: 0cbf5018d9d39885f0bd8e78605461c3


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