diff options
author | 2009-10-16 00:15:46 +0000 | |
---|---|---|
committer | 2009-10-16 00:15:46 +0000 | |
commit | 180f56c5ee4d88aef238528f6cc6d76927d3cf88 (patch) | |
tree | dde7720fc6fefed1298a446ce97d10385bc02169 | |
parent | regen (diff) | |
download | wireguard-openbsd-180f56c5ee4d88aef238528f6cc6d76927d3cf88.tar.xz wireguard-openbsd-180f56c5ee4d88aef238528f6cc6d76927d3cf88.zip |
Get serial console speed from prom, and use it instead of hardcoding 9600 bps,
on all systems but O2 (to catch up soon). Also use the IOC4 MCR register to
figure out the IOC4 clock, instead of checking the widget control register,
to be consistent with iof(4).
-rw-r--r-- | sys/arch/sgi/dev/com_ioc.c | 4 | ||||
-rw-r--r-- | sys/arch/sgi/dev/com_iof.c | 5 | ||||
-rw-r--r-- | sys/arch/sgi/include/autoconf.h | 3 | ||||
-rw-r--r-- | sys/arch/sgi/include/mnode.h | 4 | ||||
-rw-r--r-- | sys/arch/sgi/sgi/autoconf.c | 137 | ||||
-rw-r--r-- | sys/arch/sgi/sgi/ip27_machdep.c | 42 | ||||
-rw-r--r-- | sys/arch/sgi/sgi/ip30_machdep.c | 13 | ||||
-rw-r--r-- | sys/arch/sgi/sgi/ip32_machdep.c | 9 | ||||
-rw-r--r-- | sys/arch/sgi/sgi/machdep.c | 99 | ||||
-rw-r--r-- | sys/arch/sgi/sgi/sginode.c | 12 |
10 files changed, 188 insertions, 140 deletions
diff --git a/sys/arch/sgi/dev/com_ioc.c b/sys/arch/sgi/dev/com_ioc.c index a666ce6b17c..1f5a838f20b 100644 --- a/sys/arch/sgi/dev/com_ioc.c +++ b/sys/arch/sgi/dev/com_ioc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: com_ioc.c,v 1.6 2009/10/11 19:36:25 miod Exp $ */ +/* $OpenBSD: com_ioc.c,v 1.7 2009/10/16 00:15:46 miod Exp $ */ /* * Copyright (c) 2001-2004 Opsycon AB (www.opsycon.se / www.opsycon.com) @@ -115,7 +115,7 @@ com_ioc_attach(struct device *parent, struct device *self, void *aux) sc->sc_iot = comconsiot; sc->sc_iobase = comconsaddr; - if (comcnattach(sc->sc_iot, sc->sc_iobase, TTYDEF_SPEED, + if (comcnattach(sc->sc_iot, sc->sc_iobase, comconsrate, sc->sc_frequency, (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8)) panic("can't setup serial console"); ioh = comconsioh; diff --git a/sys/arch/sgi/dev/com_iof.c b/sys/arch/sgi/dev/com_iof.c index 1b3240c7817..0bbe36fae3d 100644 --- a/sys/arch/sgi/dev/com_iof.c +++ b/sys/arch/sgi/dev/com_iof.c @@ -1,4 +1,4 @@ -/* $OpenBSD: com_iof.c,v 1.4 2009/10/13 21:17:11 miod Exp $ */ +/* $OpenBSD: com_iof.c,v 1.5 2009/10/16 00:15:46 miod Exp $ */ /* * Copyright (c) 2001-2004 Opsycon AB (www.opsycon.se / www.opsycon.com) @@ -112,9 +112,8 @@ com_iof_attach(struct device *parent, struct device *self, void *aux) */ sc->sc_iot = comconsiot; sc->sc_iobase = comconsaddr; - sc->sc_frequency = comconsfreq; - if (comcnattach(sc->sc_iot, sc->sc_iobase, TTYDEF_SPEED, + if (comcnattach(sc->sc_iot, sc->sc_iobase, comconsrate, sc->sc_frequency, (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8)) panic("can't setup serial console"); ioh = comconsioh; diff --git a/sys/arch/sgi/include/autoconf.h b/sys/arch/sgi/include/autoconf.h index e6a83e4ce2d..59710f5a3f4 100644 --- a/sys/arch/sgi/include/autoconf.h +++ b/sys/arch/sgi/include/autoconf.h @@ -1,4 +1,4 @@ -/* $OpenBSD: autoconf.h,v 1.19 2009/08/06 21:06:32 miod Exp $ */ +/* $OpenBSD: autoconf.h,v 1.20 2009/10/16 00:15:48 miod Exp $ */ /* * Copyright (c) 2001-2003 Opsycon AB (www.opsycon.se / www.opsycon.com) @@ -82,6 +82,7 @@ struct confargs { }; void enaddr_aton(const char *, u_int8_t *); +u_long bios_getenvint(const char *); struct device; diff --git a/sys/arch/sgi/include/mnode.h b/sys/arch/sgi/include/mnode.h index fc4499816c2..08085e543cf 100644 --- a/sys/arch/sgi/include/mnode.h +++ b/sys/arch/sgi/include/mnode.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mnode.h,v 1.10 2009/10/08 19:11:57 miod Exp $ */ +/* $OpenBSD: mnode.h,v 1.11 2009/10/16 00:15:48 miod Exp $ */ /* * Copyright (c) 2004 Opsycon AB (www.opsycon.se / www.opsycon.com) @@ -408,7 +408,7 @@ typedef struct gda { * Functions. */ -vaddr_t kl_get_console_base(void); +console_t *kl_get_console(void); void kl_init(int); void kl_scan_config(int); void kl_scan_done(void); diff --git a/sys/arch/sgi/sgi/autoconf.c b/sys/arch/sgi/sgi/autoconf.c index dea21684613..872fc644452 100644 --- a/sys/arch/sgi/sgi/autoconf.c +++ b/sys/arch/sgi/sgi/autoconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: autoconf.c,v 1.22 2009/08/24 22:43:10 miod Exp $ */ +/* $OpenBSD: autoconf.c,v 1.23 2009/10/16 00:15:49 miod Exp $ */ /* * Copyright (c) 2009 Miodrag Vallat. * @@ -15,6 +15,31 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ /* + * Copyright (c) 2003-2004 Opsycon AB (www.opsycon.se / www.opsycon.com) + * + * 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 ``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 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. + * + */ +/* * Copyright (c) 1996 Per Fogelstrom * Copyright (c) 1995 Theo de Raadt * Copyright (c) 1988 University of Utah. @@ -70,6 +95,7 @@ #include <sys/device.h> #include <machine/autoconf.h> +#include <mips64/arcbios.h> #include <mips64/archtype.h> #include <sgi/xbow/xbow.h> @@ -79,6 +105,8 @@ extern void dumpconf(void); +static u_long atoi(const char *, int, const char **); + void bootpath_convert(void); const char *bootpath_get(int *); void bootpath_init(void); @@ -426,3 +454,110 @@ struct nam2blk nam2blk[] = { { "vnd", 2 }, { NULL, -1 } }; + +/* + * Convert "xx:xx:xx:xx:xx:xx" string to Ethernet hardware address. + */ +void +enaddr_aton(const char *s, u_int8_t *a) +{ + int i; + + if (s != NULL) { + for (i = 0; i < 6; i++) { + a[i] = atoi(s, 16, &s); + if (*s == ':') + s++; + } + } +} + +/* + * Get a numeric environment variable + */ +u_long +bios_getenvint(const char *name) +{ + const char *envvar; + u_long value; + + envvar = Bios_GetEnvironmentVariable(name); + if (envvar != NULL) { + value = atoi(envvar, 10, &envvar); + if (*envvar != '\0') + value = 0; + } else + value = 0; + + return value; +} + +/* + * Convert an ASCII string into an integer. + */ +static u_long +atoi(const char *s, int b, const char **o) +{ + int c; + unsigned base = b, d; + int neg = 0; + u_long val = 0; + + if (s == NULL || *s == 0) { + if (o != NULL) + *o = s; + return 0; + } + + /* Skip spaces if any. */ + do { + c = *s++; + } while (c == ' ' || c == '\t'); + + /* Parse sign, allow more than one (compat). */ + while (c == '-') { + neg = !neg; + c = *s++; + } + + /* Parse base specification, if any. */ + if (c == '0') { + c = *s++; + switch (c) { + case 'X': + case 'x': + base = 16; + c = *s++; + break; + case 'B': + case 'b': + base = 2; + c = *s++; + break; + default: + base = 8; + } + } + + /* Parse number proper. */ + for (;;) { + if (c >= '0' && c <= '9') + d = c - '0'; + else if (c >= 'a' && c <= 'z') + d = c - 'a' + 10; + else if (c >= 'A' && c <= 'Z') + d = c - 'A' + 10; + else + break; + c = *s++; + if (d >= base) + break; + val *= base; + val += d; + } + if (neg) + val = -val; + if (o != NULL) + *o = s - 1; + return val; +} diff --git a/sys/arch/sgi/sgi/ip27_machdep.c b/sys/arch/sgi/sgi/ip27_machdep.c index 7e52f6828b1..7460292bf94 100644 --- a/sys/arch/sgi/sgi/ip27_machdep.c +++ b/sys/arch/sgi/sgi/ip27_machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip27_machdep.c,v 1.22 2009/10/14 20:21:16 miod Exp $ */ +/* $OpenBSD: ip27_machdep.c,v 1.23 2009/10/16 00:15:49 miod Exp $ */ /* * Copyright (c) 2008, 2009 Miodrag Vallat. @@ -45,6 +45,7 @@ #include <sgi/xbow/xbow.h> #include <sgi/xbow/xbridgereg.h> +#include <sgi/pci/iofreg.h> #include <dev/ic/comvar.h> extern char *hw_prod; @@ -82,9 +83,9 @@ ip27_setup() { size_t gsz; uint node; - uint32_t ctrl; uint64_t synergy0_0; int brick; + console_t *cons; nmi_t *nmi; uncached_base = PHYS_TO_XKPHYS_UNCACHED(0, SP_NC); @@ -188,42 +189,35 @@ ip27_setup() * space. */ + cons = kl_get_console(); xbow_build_bus_space(&sys_config.console_io, 0, 8 /* whatever nonzero */); /* Constrain to the correct window */ sys_config.console_io.bus_base = - kl_get_console_base() & 0xffffffffff000000UL; + cons->uart_base & 0xffffffffff000000UL; - comconsaddr = kl_get_console_base() & 0x0000000000ffffffUL; + comconsaddr = cons->uart_base & 0x0000000000ffffffUL; + comconsrate = cons->baud; + if (comconsrate < 50 || comconsrate > 115200) + comconsrate = 9600; if ((comconsaddr & 0xfff) < 0x380) { /* IOC3 */ comconsfreq = 22000000 / 3; - bios_printf("IOC3 style console\n"); } else { /* IOC4 */ + uint32_t ioc4_mcr; + paddr_t ioc4_base; + /* * IOC4 clocks are derived from the PCI clock, so we need to * figure out whether this is an 66MHz or a 33MHz bus. - * Note that this assumes the IOC4 is connected to a Bridge - * or PIC widget, and that even if this is a PIC widget, - * the common widget register space can be correctly read - * with non-doubleword aligned word reads. */ - comconsfreq = 66666667; - bios_printf("IOC4 style console\n"); - ctrl = *(volatile uint32_t *) - ((sys_config.console_io.bus_base + WIDGET_CONTROL) | 4); - switch (ctrl & BRIDGE_WIDGET_CONTROL_SPEED_MASK) { - default: - bios_printf("WARNING! UNRECOGNIZED IOC4 SPEED\n" - "ASSUMING 66MHZ\n"); - break; - case BRIDGE_WIDGET_CONTROL_SPEED_66MHZ: - break; - case BRIDGE_WIDGET_CONTROL_SPEED_33MHZ: - comconsfreq >>= 1; - break; - } + ioc4_base = cons->uart_base & ~0xfffffUL; /* point to devio */ + ioc4_mcr = *(volatile uint32_t *)(ioc4_base + IOC4_MCR); + if (ioc4_mcr & IOC4_MCR_PCI_66MHZ) + comconsfreq = 66666667; + else + comconsfreq = 33333333; } comconsiot = &sys_config.console_io; diff --git a/sys/arch/sgi/sgi/ip30_machdep.c b/sys/arch/sgi/sgi/ip30_machdep.c index 56f7984e9bd..81effc84571 100644 --- a/sys/arch/sgi/sgi/ip30_machdep.c +++ b/sys/arch/sgi/sgi/ip30_machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip30_machdep.c,v 1.10 2009/10/14 20:21:16 miod Exp $ */ +/* $OpenBSD: ip30_machdep.c,v 1.11 2009/10/16 00:15:49 miod Exp $ */ /* * Copyright (c) 2008, 2009 Miodrag Vallat. @@ -60,6 +60,7 @@ ip30_setup() uint64_t start, count; #endif paddr_t iocbase; + u_long cpuspeed; /* * Although being r10k/r12k based, the uncached spaces are @@ -101,6 +102,11 @@ ip30_setup() xbow_widget_map = ip30_widget_map; xbow_widget_id = ip30_widget_id; + cpuspeed = bios_getenvint("cpufreq"); + if (cpuspeed < 100) + cpuspeed = 175; /* reasonable default */ + sys_config.cpu[0].clock = cpuspeed * 1000000; + /* * Initialize the early console parameters. * On Octane, the BRIDGE is always widet 15, and IOC3 is always @@ -119,12 +125,15 @@ ip30_setup() comconsaddr = 0x500000 + IOC3_UARTA_BASE; comconsfreq = 22000000 / 3; comconsiot = &sys_config.console_io; + comconsrate = bios_getenvint("dbaud"); + if (comconsrate < 50 || comconsrate > 115200) + comconsrate = 9600; /* * Octane and Octane2 can be told apart with a GPIO source bit * in the onboard IOC3. */ - iocbase = ip30_widget_long(0, 15) + 0x500000; + iocbase = ip30_widget_short(0, 15) + 0x500000; if (*(volatile uint32_t *)(iocbase + IOC3_GPPR(IP30_GPIO_CLASSIC)) != 0) hw_prod = "Octane"; else diff --git a/sys/arch/sgi/sgi/ip32_machdep.c b/sys/arch/sgi/sgi/ip32_machdep.c index ff271e3b424..343da1cda59 100644 --- a/sys/arch/sgi/sgi/ip32_machdep.c +++ b/sys/arch/sgi/sgi/ip32_machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip32_machdep.c,v 1.7 2009/10/14 20:21:16 miod Exp $ */ +/* $OpenBSD: ip32_machdep.c,v 1.8 2009/10/16 00:15:49 miod Exp $ */ /* * Copyright (c) 2003-2004 Opsycon AB (www.opsycon.se / www.opsycon.com) @@ -133,6 +133,8 @@ crime_configure_memory(void) void ip32_setup() { + u_long cpuspeed; + uncached_base = PHYS_TO_XKPHYS(0, CCA_NC); crime_configure_memory(); @@ -144,6 +146,11 @@ ip32_setup() break; } + cpuspeed = bios_getenvint("cpufreq"); + if (cpuspeed < 100) + cpuspeed = 180; /* reasonable default */ + sys_config.cpu[0].clock = cpuspeed * 1000000; + comconsaddr = MACE_ISA_SER1_OFFS; comconsfreq = 1843200; comconsiot = &macebus_tag; diff --git a/sys/arch/sgi/sgi/machdep.c b/sys/arch/sgi/sgi/machdep.c index eb16254a97b..840b50f8088 100644 --- a/sys/arch/sgi/sgi/machdep.c +++ b/sys/arch/sgi/sgi/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.84 2009/10/14 20:21:16 miod Exp $ */ +/* $OpenBSD: machdep.c,v 1.85 2009/10/16 00:15:49 miod Exp $ */ /* * Copyright (c) 2003-2004 Opsycon AB (www.opsycon.se / www.opsycon.com) @@ -123,7 +123,6 @@ void dumpsys(void); void dumpconf(void); static void dobootopts(int, void *); -static int atoi(const char *, int, const char **); void arcbios_halt(int); void build_trampoline(vaddr_t, vaddr_t); @@ -219,12 +218,6 @@ mips_init(int argc, void *argv, caddr_t boot_esym) bios_printf("Found SGI-IP32, setting up.\n"); strlcpy(cpu_model, "IP32", sizeof(cpu_model)); ip32_setup(); - - sys_config.cpu[0].clock = 180000000; /* Reasonable default */ - cp = Bios_GetEnvironmentVariable("cpufreq"); - if (cp && atoi(cp, 10, NULL) > 100) - sys_config.cpu[0].clock = atoi(cp, 10, NULL) * 1000000; - break; #endif @@ -250,12 +243,6 @@ mips_init(int argc, void *argv, caddr_t boot_esym) bios_printf("Found SGI-IP30, setting up.\n"); strlcpy(cpu_model, "IP30", sizeof(cpu_model)); ip30_setup(); - - sys_config.cpu[0].clock = 175000000; /* Reasonable default */ - cp = Bios_GetEnvironmentVariable("cpufreq"); - if (cp && atoi(cp, 10, NULL) > 100) - sys_config.cpu[0].clock = atoi(cp, 10, NULL) * 1000000; - break; #endif @@ -998,90 +985,6 @@ initcpu() { } -/* - * Convert "xx:xx:xx:xx:xx:xx" string to Ethernet hardware address. - */ -void -enaddr_aton(const char *s, u_int8_t *a) -{ - int i; - - if (s != NULL) { - for(i = 0; i < 6; i++) { - a[i] = atoi(s, 16, &s); - if (*s == ':') - s++; - } - } -} - -/* - * Convert an ASCII string into an integer. - */ -static int -atoi(const char *s, int b, const char **o) -{ - int c; - unsigned base = b, d; - int neg = 0, val = 0; - - if (s == NULL || *s == 0) { - if (o != NULL) - *o = s; - return 0; - } - - /* Skip spaces if any. */ - do { - c = *s++; - } while (c == ' ' || c == '\t'); - - /* Parse sign, allow more than one (compat). */ - while (c == '-') { - neg = !neg; - c = *s++; - } - - /* Parse base specification, if any. */ - if (c == '0') { - c = *s++; - switch (c) { - case 'X': - case 'x': - base = 16; - c = *s++; - break; - case 'B': - case 'b': - base = 2; - c = *s++; - break; - default: - base = 8; - } - } - - /* Parse number proper. */ - for (;;) { - if (c >= '0' && c <= '9') - d = c - '0'; - else if (c >= 'a' && c <= 'z') - d = c - 'a' + 10; - else if (c >= 'A' && c <= 'Z') - d = c - 'A' + 10; - else - break; - val *= base; - val += d; - c = *s++; - } - if (neg) - val = -val; - if (o != NULL) - *o = s - 1; - return val; -} - #ifdef RM7K_PERFCNTR /* diff --git a/sys/arch/sgi/sgi/sginode.c b/sys/arch/sgi/sgi/sginode.c index 258f3acd107..d6e926d4b3c 100644 --- a/sys/arch/sgi/sgi/sginode.c +++ b/sys/arch/sgi/sgi/sginode.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sginode.c,v 1.11 2009/07/06 22:46:43 miod Exp $ */ +/* $OpenBSD: sginode.c,v 1.12 2009/10/16 00:15:49 miod Exp $ */ /* * Copyright (c) 2008, 2009 Miodrag Vallat. * @@ -115,7 +115,7 @@ kl_scan_done() } /* - * Callback routine for the initial enumration (boards). + * Callback routine for the initial enumeration (boards). */ int kl_first_pass_board(lboard_t *boardinfo, void *arg) @@ -293,14 +293,14 @@ kl_scan_board(lboard_t *boardinfo, uint type, int (*cb)(klinfo_t *, void *), } /* - * Return the virtual address of the console device. + * Return the console device information. */ -vaddr_t -kl_get_console_base() +console_t * +kl_get_console() { kl_config_hdr_t *cfghdr = IP27_KLCONFIG_HDR(0); - return (vaddr_t)cfghdr->cons_info.uart_base; + return &cfghdr->cons_info; } /* |