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$");
30 #include <sys/param.h>
31 #include <machine/cpuregs.h>
33 #include <mips/sentry5/s5reg.h>
37 #include <sys/param.h>
39 #include <sys/kernel.h>
40 #include <sys/systm.h>
44 #include <sys/reboot.h>
47 #include <vm/vm_page.h>
49 #include <net/ethernet.h>
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>
58 #include <mips/atheros/ar71xxreg.h>
60 #include <mips/atheros/ar71xx_setup.h>
61 #include <mips/atheros/ar71xx_cpudef.h>
63 extern char edata[], end[];
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 */
69 int boot1_env_pos = 0;
72 static_setenv(char *n, char *v)
78 if (boot1_env_pos + nlen + vlen + 2 > sizeof(boot1_env)) {
79 printf("*** Environment could not be copied in full\n");
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';
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.
99 while ((v = strsep(&str, " ")) != NULL) {
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;
125 /* Nothing special */
135 platform_identify(void)
143 ar71xx_device_stop(RST_RESET_FULL_CHIP);
150 platform_trap_enter(void)
156 platform_trap_exit(void)
162 platform_start(__register_t a0 __unused, __register_t a1 __unused,
163 __register_t a2 __unused, __register_t a3 __unused)
165 uint64_t platform_counter_freq;
166 int argc, i, count = 0;
167 char **argv, **envp, *var;
171 * clear the BSS and SBSS segments, this should be first call in
174 kernend = (vm_offset_t)&end;
175 memset(&edata, 0, kernend - (vm_offset_t)(&edata));
177 mips_postboot_fixup();
179 /* Initialize pcpu stuff */
186 * Protect ourselves from garbage in registers
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));
196 * Just wild guess. RedBoot let us down and didn't reported
200 realmem = btoc(32*1024*1024);
202 /* phys_avail regions are in bytes */
203 phys_avail[0] = MIPS_KSEG0_TO_PHYS(kernel_kseg0_end);
204 phys_avail[1] = ctob(realmem);
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.
215 /* Detect the system type - this is needed for subsequent chipset-specific calls */
216 ar71xx_detect_sys_type();
217 ar71xx_detect_sys_frequency();
219 platform_counter_freq = ar71xx_cpu_freq();
220 mips_timer_init_params(platform_counter_freq, 1);
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);
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);
236 if (MIPS_IS_VALID_PTR(argv)) {
237 for (i = 0; i < argc; i++) {
238 printf(" %s", argv[i]);
243 printf ("argv is invalid");
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]);
254 printf ("envp is invalid\n");
255 kern_envp = boot1_env;
258 * "ethaddr" is passed via envp on RedBoot platforms
259 * "kmac" is passed via argv on RouterBOOT platforms
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]);
268 memset(ar711_base_mac, 0,
269 sizeof(ar711_base_mac));
273 init_param2(physmem);
282 ar71xx_init_usb_peripheral();
286 if (boothowto & RB_KDB)
287 kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger");