2 * Copyright (c) 2009 Oleksandr Tymoshenko
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
31 #include "opt_ar71xx.h"
33 #include <sys/param.h>
35 #include <sys/kernel.h>
36 #include <sys/systm.h>
40 #include <sys/reboot.h>
43 #include <vm/vm_page.h>
45 #include <net/ethernet.h>
47 #include <machine/clock.h>
48 #include <machine/cpu.h>
49 #include <machine/cpuregs.h>
50 #include <machine/hwfunc.h>
51 #include <machine/md_var.h>
52 #include <machine/trap.h>
53 #include <machine/vmparam.h>
55 #include <mips/atheros/ar71xxreg.h>
57 #include <mips/atheros/ar71xx_setup.h>
58 #include <mips/atheros/ar71xx_cpudef.h>
60 #include <mips/sentry5/s5reg.h>
62 extern char edata[], end[];
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 */
70 * We get a string in from Redboot with the all the arguments together,
71 * "foo=bar bar=baz". Split them up and save in kenv.
78 while ((v = strsep(&str, " ")) != NULL) {
85 case 'a': boothowto |= RB_ASKNAME; break;
86 case 'd': boothowto |= RB_KDB; break;
87 case 'g': boothowto |= RB_GDB; break;
88 case 's': boothowto |= RB_SINGLE; break;
89 case 'v': boothowto |= RB_VERBOSE; break;
105 /* Nothing special */
111 ar71xx_device_stop(RST_RESET_FULL_CHIP);
118 * Obtain the MAC address via the Redboot environment.
121 ar71xx_redboot_get_macaddr(void)
127 * "ethaddr" is passed via envp on RedBoot platforms
128 * "kmac" is passed via argv on RouterBOOT platforms
130 if ((var = getenv("ethaddr")) != NULL ||
131 (var = getenv("kmac")) != NULL) {
132 count = sscanf(var, "%x%*c%x%*c%x%*c%x%*c%x%*c%x",
133 &ar711_base_mac[0], &ar711_base_mac[1],
134 &ar711_base_mac[2], &ar711_base_mac[3],
135 &ar711_base_mac[4], &ar711_base_mac[5]);
137 memset(ar711_base_mac, 0,
138 sizeof(ar711_base_mac));
144 platform_start(__register_t a0 __unused, __register_t a1 __unused,
145 __register_t a2 __unused, __register_t a3 __unused)
147 uint64_t platform_counter_freq;
149 char **argv = NULL, **envp = NULL;
153 * clear the BSS and SBSS segments, this should be first call in
156 kernend = (vm_offset_t)&end;
157 memset(&edata, 0, kernend - (vm_offset_t)(&edata));
159 mips_postboot_fixup();
161 /* Initialize pcpu stuff */
165 * Until some more sensible abstractions for uboot/redboot
166 * environment handling, we have to make this a compile-time
167 * hack. The existing code handles the uboot environment
168 * very incorrectly so we should just ignore initialising
169 * the relevant pointers.
171 #ifndef AR71XX_ENV_UBOOT
177 * Protect ourselves from garbage in registers
179 if (MIPS_IS_VALID_PTR(envp)) {
180 for (i = 0; envp[i]; i += 2) {
181 if (strcmp(envp[i], "memsize") == 0)
182 realmem = btoc(strtoul(envp[i+1], NULL, 16));
187 * Just wild guess. RedBoot let us down and didn't reported
191 realmem = btoc(32*1024*1024);
194 * Allow build-time override in case Redboot lies
195 * or in other situations (eg where there's u-boot)
196 * where there isn't (yet) a convienent method of
197 * being told how much RAM is available.
199 * This happens on at least the Ubiquiti LS-SR71A
200 * board, where redboot says there's 16mb of RAM
201 * but in fact there's 32mb.
203 #if defined(AR71XX_REALMEM)
204 realmem = btoc(AR71XX_REALMEM);
207 /* phys_avail regions are in bytes */
208 phys_avail[0] = MIPS_KSEG0_TO_PHYS(kernel_kseg0_end);
209 phys_avail[1] = ctob(realmem);
211 dump_avail[0] = phys_avail[0];
212 dump_avail[1] = phys_avail[1] - phys_avail[0];
217 * ns8250 uart code uses DELAY so ticker should be inititalized
218 * before cninit. And tick_init_params refers to hz, so * init_param1
219 * should be called first.
223 /* Detect the system type - this is needed for subsequent chipset-specific calls */
224 ar71xx_detect_sys_type();
225 ar71xx_detect_sys_frequency();
227 platform_counter_freq = ar71xx_cpu_freq();
228 mips_timer_init_params(platform_counter_freq, 1);
230 init_static_kenv(boot1_env, sizeof(boot1_env));
232 printf("CPU platform: %s\n", ar71xx_get_system_type());
233 printf("CPU Frequency=%d MHz\n", u_ar71xx_cpu_freq / 1000000);
234 printf("CPU DDR Frequency=%d MHz\n", u_ar71xx_ddr_freq / 1000000);
235 printf("CPU AHB Frequency=%d MHz\n", u_ar71xx_ahb_freq / 1000000);
236 printf("platform frequency: %lld\n", platform_counter_freq);
237 printf("CPU reference clock: %d MHz\n", u_ar71xx_refclk / 1000000);
238 printf("arguments: \n");
239 printf(" a0 = %08x\n", a0);
240 printf(" a1 = %08x\n", a1);
241 printf(" a2 = %08x\n", a2);
242 printf(" a3 = %08x\n", a3);
245 * XXX this code is very redboot specific.
248 if (MIPS_IS_VALID_PTR(argv)) {
249 for (i = 0; i < argc; i++) {
250 printf(" %s", argv[i]);
255 printf ("argv is invalid");
258 printf("Environment:\n");
259 if (MIPS_IS_VALID_PTR(envp)) {
260 for (i = 0; envp[i]; i+=2) {
261 printf(" %s = %s\n", envp[i], envp[i+1]);
262 setenv(envp[i], envp[i+1]);
266 printf ("envp is invalid\n");
268 /* Redboot if_arge MAC address is in the environment */
269 ar71xx_redboot_get_macaddr();
271 init_param2(physmem);
280 ar71xx_init_usb_peripheral();
284 if (boothowto & RB_KDB)
285 kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger");