2009-04-14 22:53:22 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2009 Oleksandr Tymoshenko
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
|
|
#include "opt_ddb.h"
|
2012-01-16 05:07:32 +00:00
|
|
|
#include "opt_ar71xx.h"
|
2009-04-14 22:53:22 +00:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/cons.h>
|
|
|
|
#include <sys/kdb.h>
|
2009-10-28 21:27:56 +00:00
|
|
|
#include <sys/reboot.h>
|
2009-04-14 22:53:22 +00:00
|
|
|
|
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/vm_page.h>
|
|
|
|
|
2009-05-16 02:43:24 +00:00
|
|
|
#include <net/ethernet.h>
|
|
|
|
|
2009-04-14 22:53:22 +00:00
|
|
|
#include <machine/clock.h>
|
|
|
|
#include <machine/cpu.h>
|
2011-06-26 10:07:48 +00:00
|
|
|
#include <machine/cpuregs.h>
|
2009-04-14 22:53:22 +00:00
|
|
|
#include <machine/hwfunc.h>
|
|
|
|
#include <machine/md_var.h>
|
|
|
|
#include <machine/trap.h>
|
|
|
|
#include <machine/vmparam.h>
|
|
|
|
|
|
|
|
#include <mips/atheros/ar71xxreg.h>
|
|
|
|
|
2010-08-19 02:03:12 +00:00
|
|
|
#include <mips/atheros/ar71xx_setup.h>
|
|
|
|
#include <mips/atheros/ar71xx_cpudef.h>
|
|
|
|
|
2011-06-26 10:07:48 +00:00
|
|
|
#include <mips/sentry5/s5reg.h>
|
|
|
|
|
2010-01-25 00:44:05 +00:00
|
|
|
extern char edata[], end[];
|
|
|
|
|
2009-05-16 02:43:24 +00:00
|
|
|
uint32_t ar711_base_mac[ETHER_ADDR_LEN];
|
2009-10-28 21:27:56 +00:00
|
|
|
/* 4KB static data aread to keep a copy of the bootload env until
|
|
|
|
the dynamic kenv is setup */
|
|
|
|
char boot1_env[4096];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We get a string in from Redboot with the all the arguments together,
|
|
|
|
* "foo=bar bar=baz". Split them up and save in kenv.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
parse_argv(char *str)
|
|
|
|
{
|
|
|
|
char *n, *v;
|
|
|
|
|
|
|
|
while ((v = strsep(&str, " ")) != NULL) {
|
|
|
|
if (*v == '\0')
|
|
|
|
continue;
|
|
|
|
if (*v == '-') {
|
|
|
|
while (*v != '\0') {
|
|
|
|
v++;
|
|
|
|
switch (*v) {
|
|
|
|
case 'a': boothowto |= RB_ASKNAME; break;
|
|
|
|
case 'd': boothowto |= RB_KDB; break;
|
|
|
|
case 'g': boothowto |= RB_GDB; break;
|
|
|
|
case 's': boothowto |= RB_SINGLE; break;
|
|
|
|
case 'v': boothowto |= RB_VERBOSE; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
n = strsep(&v, "=");
|
|
|
|
if (v == NULL)
|
|
|
|
setenv(n, "1");
|
|
|
|
else
|
|
|
|
setenv(n, v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-04-14 22:53:22 +00:00
|
|
|
|
2009-10-30 08:53:11 +00:00
|
|
|
void
|
|
|
|
platform_cpu_init()
|
|
|
|
{
|
|
|
|
/* Nothing special */
|
|
|
|
}
|
|
|
|
|
2009-04-14 22:53:22 +00:00
|
|
|
void
|
|
|
|
platform_reset(void)
|
|
|
|
{
|
2010-08-19 02:12:04 +00:00
|
|
|
ar71xx_device_stop(RST_RESET_FULL_CHIP);
|
2009-04-14 22:53:22 +00:00
|
|
|
/* Wait for reset */
|
|
|
|
while(1)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2011-03-27 13:55:35 +00:00
|
|
|
/*
|
|
|
|
* Obtain the MAC address via the Redboot environment.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ar71xx_redboot_get_macaddr(void)
|
|
|
|
{
|
|
|
|
char *var;
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "ethaddr" is passed via envp on RedBoot platforms
|
|
|
|
* "kmac" is passed via argv on RouterBOOT platforms
|
|
|
|
*/
|
|
|
|
if ((var = getenv("ethaddr")) != NULL ||
|
|
|
|
(var = getenv("kmac")) != NULL) {
|
|
|
|
count = sscanf(var, "%x%*c%x%*c%x%*c%x%*c%x%*c%x",
|
|
|
|
&ar711_base_mac[0], &ar711_base_mac[1],
|
|
|
|
&ar711_base_mac[2], &ar711_base_mac[3],
|
|
|
|
&ar711_base_mac[4], &ar711_base_mac[5]);
|
|
|
|
if (count < 6)
|
|
|
|
memset(ar711_base_mac, 0,
|
|
|
|
sizeof(ar711_base_mac));
|
|
|
|
freeenv(var);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-14 22:53:22 +00:00
|
|
|
void
|
|
|
|
platform_start(__register_t a0 __unused, __register_t a1 __unused,
|
|
|
|
__register_t a2 __unused, __register_t a3 __unused)
|
|
|
|
{
|
2009-07-09 20:11:26 +00:00
|
|
|
uint64_t platform_counter_freq;
|
2011-11-24 07:32:52 +00:00
|
|
|
int argc = 0, i;
|
|
|
|
char **argv = NULL, **envp = NULL;
|
2010-01-25 00:44:05 +00:00
|
|
|
vm_offset_t kernend;
|
2009-04-14 22:53:22 +00:00
|
|
|
|
2010-01-25 00:44:05 +00:00
|
|
|
/*
|
|
|
|
* clear the BSS and SBSS segments, this should be first call in
|
|
|
|
* the function
|
|
|
|
*/
|
|
|
|
kernend = (vm_offset_t)&end;
|
2009-04-14 22:53:22 +00:00
|
|
|
memset(&edata, 0, kernend - (vm_offset_t)(&edata));
|
|
|
|
|
2010-01-25 00:44:05 +00:00
|
|
|
mips_postboot_fixup();
|
|
|
|
|
2010-01-08 22:48:21 +00:00
|
|
|
/* Initialize pcpu stuff */
|
2010-01-09 03:08:22 +00:00
|
|
|
mips_pcpu0_init();
|
2010-01-08 22:48:21 +00:00
|
|
|
|
2011-11-24 07:32:52 +00:00
|
|
|
/*
|
|
|
|
* Until some more sensible abstractions for uboot/redboot
|
|
|
|
* environment handling, we have to make this a compile-time
|
|
|
|
* hack. The existing code handles the uboot environment
|
|
|
|
* very incorrectly so we should just ignore initialising
|
|
|
|
* the relevant pointers.
|
|
|
|
*/
|
|
|
|
#ifndef AR71XX_ENV_UBOOT
|
2009-05-16 02:43:24 +00:00
|
|
|
argc = a0;
|
|
|
|
argv = (char**)a1;
|
|
|
|
envp = (char**)a2;
|
2011-11-24 07:32:52 +00:00
|
|
|
#endif
|
2009-05-16 02:43:24 +00:00
|
|
|
/*
|
|
|
|
* Protect ourselves from garbage in registers
|
|
|
|
*/
|
|
|
|
if (MIPS_IS_VALID_PTR(envp)) {
|
2010-09-17 01:09:12 +00:00
|
|
|
for (i = 0; envp[i]; i += 2) {
|
2009-05-16 02:43:24 +00:00
|
|
|
if (strcmp(envp[i], "memsize") == 0)
|
|
|
|
realmem = btoc(strtoul(envp[i+1], NULL, 16));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Just wild guess. RedBoot let us down and didn't reported
|
|
|
|
* memory size
|
|
|
|
*/
|
|
|
|
if (realmem == 0)
|
|
|
|
realmem = btoc(32*1024*1024);
|
|
|
|
|
2011-03-27 08:44:27 +00:00
|
|
|
/*
|
|
|
|
* Allow build-time override in case Redboot lies
|
|
|
|
* or in other situations (eg where there's u-boot)
|
|
|
|
* where there isn't (yet) a convienent method of
|
|
|
|
* being told how much RAM is available.
|
|
|
|
*
|
|
|
|
* This happens on at least the Ubiquiti LS-SR71A
|
|
|
|
* board, where redboot says there's 16mb of RAM
|
|
|
|
* but in fact there's 32mb.
|
|
|
|
*/
|
|
|
|
#if defined(AR71XX_REALMEM)
|
2011-03-28 09:10:59 +00:00
|
|
|
realmem = btoc(AR71XX_REALMEM);
|
2011-03-27 08:44:27 +00:00
|
|
|
#endif
|
|
|
|
|
2009-04-14 22:53:22 +00:00
|
|
|
/* phys_avail regions are in bytes */
|
2010-01-25 00:44:05 +00:00
|
|
|
phys_avail[0] = MIPS_KSEG0_TO_PHYS(kernel_kseg0_end);
|
2009-04-14 22:53:22 +00:00
|
|
|
phys_avail[1] = ctob(realmem);
|
|
|
|
|
2010-12-09 07:01:03 +00:00
|
|
|
dump_avail[0] = phys_avail[0];
|
|
|
|
dump_avail[1] = phys_avail[1] - phys_avail[0];
|
|
|
|
|
2009-04-14 22:53:22 +00:00
|
|
|
physmem = realmem;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ns8250 uart code uses DELAY so ticker should be inititalized
|
|
|
|
* before cninit. And tick_init_params refers to hz, so * init_param1
|
|
|
|
* should be called first.
|
|
|
|
*/
|
|
|
|
init_param1();
|
2010-08-19 02:03:12 +00:00
|
|
|
|
|
|
|
/* Detect the system type - this is needed for subsequent chipset-specific calls */
|
|
|
|
ar71xx_detect_sys_type();
|
|
|
|
ar71xx_detect_sys_frequency();
|
|
|
|
|
2009-07-09 20:11:26 +00:00
|
|
|
platform_counter_freq = ar71xx_cpu_freq();
|
2009-05-19 02:51:30 +00:00
|
|
|
mips_timer_init_params(platform_counter_freq, 1);
|
2009-04-14 22:53:22 +00:00
|
|
|
cninit();
|
2009-10-28 21:27:56 +00:00
|
|
|
init_static_kenv(boot1_env, sizeof(boot1_env));
|
2009-04-14 22:53:22 +00:00
|
|
|
|
2010-08-19 02:03:12 +00:00
|
|
|
printf("CPU platform: %s\n", ar71xx_get_system_type());
|
|
|
|
printf("CPU Frequency=%d MHz\n", u_ar71xx_cpu_freq / 1000000);
|
|
|
|
printf("CPU DDR Frequency=%d MHz\n", u_ar71xx_ddr_freq / 1000000);
|
2013-03-29 06:31:31 +00:00
|
|
|
printf("CPU AHB Frequency=%d MHz\n", u_ar71xx_ahb_freq / 1000000);
|
2013-10-15 01:37:00 +00:00
|
|
|
printf("platform frequency: %lld MHz\n", platform_counter_freq / 1000000);
|
2013-03-29 06:31:31 +00:00
|
|
|
printf("CPU reference clock: %d MHz\n", u_ar71xx_refclk / 1000000);
|
2013-10-15 01:37:00 +00:00
|
|
|
printf("CPU MDIO clock: %d MHz\n", u_ar71xx_mdio_freq / 1000000);
|
2009-04-14 22:53:22 +00:00
|
|
|
printf("arguments: \n");
|
|
|
|
printf(" a0 = %08x\n", a0);
|
|
|
|
printf(" a1 = %08x\n", a1);
|
|
|
|
printf(" a2 = %08x\n", a2);
|
|
|
|
printf(" a3 = %08x\n", a3);
|
|
|
|
|
2011-11-24 07:32:52 +00:00
|
|
|
/*
|
|
|
|
* XXX this code is very redboot specific.
|
|
|
|
*/
|
2009-05-16 02:43:24 +00:00
|
|
|
printf("Cmd line:");
|
|
|
|
if (MIPS_IS_VALID_PTR(argv)) {
|
2009-10-28 21:27:56 +00:00
|
|
|
for (i = 0; i < argc; i++) {
|
2009-05-16 02:43:24 +00:00
|
|
|
printf(" %s", argv[i]);
|
2009-10-28 21:27:56 +00:00
|
|
|
parse_argv(argv[i]);
|
|
|
|
}
|
2009-05-16 02:43:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
printf ("argv is invalid");
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
printf("Environment:\n");
|
|
|
|
if (MIPS_IS_VALID_PTR(envp)) {
|
2009-10-28 21:27:56 +00:00
|
|
|
for (i = 0; envp[i]; i+=2) {
|
2009-05-16 02:43:24 +00:00
|
|
|
printf(" %s = %s\n", envp[i], envp[i+1]);
|
2009-10-28 21:27:56 +00:00
|
|
|
setenv(envp[i], envp[i+1]);
|
|
|
|
}
|
2009-05-16 02:43:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
printf ("envp is invalid\n");
|
|
|
|
|
2011-03-27 13:55:35 +00:00
|
|
|
/* Redboot if_arge MAC address is in the environment */
|
|
|
|
ar71xx_redboot_get_macaddr();
|
2010-09-17 01:09:12 +00:00
|
|
|
|
2009-04-14 22:53:22 +00:00
|
|
|
init_param2(physmem);
|
|
|
|
mips_cpu_init();
|
|
|
|
pmap_bootstrap();
|
|
|
|
mips_proc0_init();
|
|
|
|
mutex_init();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset USB devices
|
|
|
|
*/
|
2010-08-19 02:14:53 +00:00
|
|
|
ar71xx_init_usb_peripheral();
|
2009-04-14 22:53:22 +00:00
|
|
|
|
2013-10-15 01:37:00 +00:00
|
|
|
/*
|
|
|
|
* Reset internal ethernet switch, if one exists
|
|
|
|
*/
|
|
|
|
ar71xx_reset_ethernet_switch();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialise the gmac driver.
|
|
|
|
*/
|
|
|
|
ar71xx_init_gmac();
|
|
|
|
|
2009-04-14 22:53:22 +00:00
|
|
|
kdb_init();
|
2010-01-23 00:18:12 +00:00
|
|
|
#ifdef KDB
|
|
|
|
if (boothowto & RB_KDB)
|
|
|
|
kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger");
|
2009-04-14 22:53:22 +00:00
|
|
|
#endif
|
|
|
|
}
|