2 * Copyright (c) 2016, Hiroki Mori
3 * Copyright (c) 2009 Oleksandr Tymoshenko
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
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
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
32 #include "opt_ar531x.h"
34 #include <sys/param.h>
36 #include <sys/kernel.h>
37 #include <sys/systm.h>
41 #include <sys/reboot.h>
45 #include <vm/vm_page.h>
47 #include <net/ethernet.h>
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>
57 #include <mips/atheros/ar531x/ar5315reg.h>
59 #include <mips/atheros/ar531x/ar5315_setup.h>
60 #include <mips/atheros/ar531x/ar5315_cpudef.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 */
78 ar531x_device_reset();
85 * Obtain the MAC address via the Redboot environment.
88 ar5315_redboot_get_macaddr(void)
94 * "ethaddr" is passed via envp on RedBoot platforms
95 * "kmac" is passed via argv on RouterBOOT platforms
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]);
104 memset(ar711_base_mac, 0,
105 sizeof(ar711_base_mac));
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");
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,
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,
125 static char hw_soc_revision[] = SOC_REV;
126 SYSCTL_STRING(_hw_soc, OID_AUTO, revision, CTLFLAG_RD, hw_soc_revision, 0,
130 #if defined(DEVICE_VENDOR) || defined(DEVICE_MODEL) || defined(DEVICE_REV)
131 static SYSCTL_NODE(_hw, OID_AUTO, device, CTLFLAG_RD, 0, "Board information");
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,
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,
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,
149 extern char cpu_model[];
152 platform_start(__register_t a0 __unused, __register_t a1 __unused,
153 __register_t a2 __unused, __register_t a3 __unused)
155 uint64_t platform_counter_freq;
158 #ifndef AR531X_ENV_UBOOT
164 * clear the BSS and SBSS segments, this should be first call in
167 kernend = (vm_offset_t)&end;
168 memset(&edata, 0, kernend - (vm_offset_t)(&edata));
170 mips_postboot_fixup();
172 /* Initialize pcpu stuff */
176 * Until some more sensible abstractions for uboot/redboot
177 * environment handling, we have to make this a compile-time
178 * hack. The existing code handles the uboot environment
179 * very incorrectly so we should just ignore initialising
180 * the relevant pointers.
182 #ifndef AR531X_ENV_UBOOT
188 * Protect ourselves from garbage in registers
190 if (MIPS_IS_VALID_PTR(envp)) {
191 for (i = 0; envp[i]; i += 2) {
192 if (strcmp(envp[i], "memsize") == 0)
193 realmem = btoc(strtoul(envp[i+1], NULL, 16));
197 ar5315_detect_sys_type();
199 // RedBoot SDRAM Detect is missing
200 // ar531x_detect_mem_size();
203 * Just wild guess. RedBoot let us down and didn't reported
207 realmem = btoc(16*1024*1024);
210 * Allow build-time override in case Redboot lies
211 * or in other situations (eg where there's u-boot)
212 * where there isn't (yet) a convienent method of
213 * being told how much RAM is available.
215 * This happens on at least the Ubiquiti LS-SR71A
216 * board, where redboot says there's 16mb of RAM
217 * but in fact there's 32mb.
219 #if defined(AR531X_REALMEM)
220 realmem = btoc(AR531X_REALMEM);
223 /* phys_avail regions are in bytes */
224 phys_avail[0] = MIPS_KSEG0_TO_PHYS(kernel_kseg0_end);
225 phys_avail[1] = ctob(realmem);
227 dump_avail[0] = phys_avail[0];
228 dump_avail[1] = phys_avail[1] - phys_avail[0];
233 * ns8250 uart code uses DELAY so ticker should be inititalized
234 * before cninit. And tick_init_params refers to hz, so * init_param1
235 * should be called first.
238 boothowto |= (RB_SERIAL | RB_MULTIPLE); /* Use multiple consoles */
239 // boothowto |= RB_VERBOSE;
240 // boothowto |= (RB_SINGLE);
242 /* Detect the system type - this is needed for subsequent chipset-specific calls */
245 ar531x_device_soc_init();
246 ar531x_detect_sys_frequency();
248 platform_counter_freq = ar531x_cpu_freq();
249 mips_timer_init_params(platform_counter_freq, 1);
251 init_static_kenv(boot1_env, sizeof(boot1_env));
253 printf("CPU platform: %s\n", ar5315_get_system_type());
254 printf("CPU Frequency=%d MHz\n", ar531x_cpu_freq() / 1000000);
255 printf("CPU DDR Frequency=%d MHz\n", ar531x_ddr_freq() / 1000000);
256 printf("CPU AHB Frequency=%d MHz\n", ar531x_ahb_freq() / 1000000);
258 printf("platform frequency: %lld\n", platform_counter_freq);
259 printf("arguments: \n");
260 printf(" a0 = %08x\n", a0);
261 printf(" a1 = %08x\n", a1);
262 printf(" a2 = %08x\n", a2);
263 printf(" a3 = %08x\n", a3);
265 strcpy(cpu_model, ar5315_get_system_type());
268 * XXX this code is very redboot specific.
271 if (MIPS_IS_VALID_PTR(argv)) {
272 for (i = 0; i < argc; i++) {
273 printf(" %s", argv[i]);
274 boothowto |= boot_parse_arg(argv[i]);
278 printf ("argv is invalid");
281 printf("Environment:\n");
283 if (MIPS_IS_VALID_PTR(envp)) {
284 if (envp[0] && strchr(envp[0], '=') ) {
286 for (i = 0; envp[i]; i++) {
287 env_val = strchr(envp[i], '=');
288 /* Not sure if we correct to change data, but env in RAM */
290 printf("= %s = %s\n", envp[i], env_val);
291 kern_setenv(envp[i], env_val);
294 for (i = 0; envp[i]; i+=2) {
295 printf(" %s = %s\n", envp[i], envp[i+1]);
296 kern_setenv(envp[i], envp[i+1]);
301 printf ("envp is invalid\n");
303 printf ("envp skiped\n");
306 /* Redboot if_are MAC address is in the environment */
307 ar5315_redboot_get_macaddr();
309 init_param2(physmem);
315 ar531x_device_start();
319 if (boothowto & RB_KDB)
320 kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger");