1*8ce44338Smlelstv /* $NetBSD: autoconf.c,v 1.6 2012/07/29 18:05:47 mlelstv Exp $ */
25f7e80a8Spooka
35f7e80a8Spooka /*
49b6bd2d9Srmind * Copyright (c) 1988 University of Utah.
55f7e80a8Spooka * Copyright (c) 1992, 1993
65f7e80a8Spooka * The Regents of the University of California. All rights reserved.
75f7e80a8Spooka *
85f7e80a8Spooka * This code is derived from software contributed to Berkeley by
95f7e80a8Spooka * the Systems Programming Group of the University of Utah Computer
105f7e80a8Spooka * Science Department and Ralph Campbell.
115f7e80a8Spooka *
125f7e80a8Spooka * Redistribution and use in source and binary forms, with or without
135f7e80a8Spooka * modification, are permitted provided that the following conditions
145f7e80a8Spooka * are met:
155f7e80a8Spooka * 1. Redistributions of source code must retain the above copyright
165f7e80a8Spooka * notice, this list of conditions and the following disclaimer.
175f7e80a8Spooka * 2. Redistributions in binary form must reproduce the above copyright
185f7e80a8Spooka * notice, this list of conditions and the following disclaimer in the
195f7e80a8Spooka * documentation and/or other materials provided with the distribution.
205f7e80a8Spooka * 3. Neither the name of the University nor the names of its contributors
215f7e80a8Spooka * may be used to endorse or promote products derived from this software
225f7e80a8Spooka * without specific prior written permission.
235f7e80a8Spooka *
245f7e80a8Spooka * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
255f7e80a8Spooka * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
265f7e80a8Spooka * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
275f7e80a8Spooka * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
285f7e80a8Spooka * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
295f7e80a8Spooka * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
305f7e80a8Spooka * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
315f7e80a8Spooka * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
325f7e80a8Spooka * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
335f7e80a8Spooka * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
345f7e80a8Spooka * SUCH DAMAGE.
355f7e80a8Spooka *
365f7e80a8Spooka * from: Utah Hdr: autoconf.c 1.31 91/01/21
375f7e80a8Spooka *
385f7e80a8Spooka * @(#)autoconf.c 8.1 (Berkeley) 6/10/93
395f7e80a8Spooka */
405f7e80a8Spooka
419b6bd2d9Srmind #include <sys/cdefs.h>
42*8ce44338Smlelstv __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.6 2012/07/29 18:05:47 mlelstv Exp $");
435f7e80a8Spooka
445f7e80a8Spooka #include <sys/param.h>
455f7e80a8Spooka #include <sys/systm.h>
465f7e80a8Spooka #include <sys/conf.h>
475f7e80a8Spooka #include <sys/reboot.h>
485f7e80a8Spooka #include <sys/device.h>
495f7e80a8Spooka
505f7e80a8Spooka #include <machine/autoconf.h>
515f7e80a8Spooka #include <machine/intr.h>
525f7e80a8Spooka #include <machine/sysconf.h>
535f7e80a8Spooka
545f7e80a8Spooka static int booted_bus, booted_unit;
555f7e80a8Spooka static const char *booted_controller;
565f7e80a8Spooka
575f7e80a8Spooka /*
585f7e80a8Spooka * Configure all devices on system
595f7e80a8Spooka */
605f7e80a8Spooka void
cpu_configure(void)615f7e80a8Spooka cpu_configure(void)
625f7e80a8Spooka {
639dc6c88bStsutsui
645f7e80a8Spooka /* Kick off autoconfiguration. */
655f7e80a8Spooka (void)splhigh();
665f7e80a8Spooka
6790bc6e58Stsutsui /* Interrupt initialization. */
6890bc6e58Stsutsui intr_init();
6990bc6e58Stsutsui
705f7e80a8Spooka evcnt_attach_static(&emips_clock_evcnt);
715f7e80a8Spooka evcnt_attach_static(&emips_fpu_evcnt);
725f7e80a8Spooka evcnt_attach_static(&emips_memerr_evcnt);
735f7e80a8Spooka
745f7e80a8Spooka if (config_rootfound("mainbus", NULL) == NULL)
755f7e80a8Spooka panic("no mainbus found");
765f7e80a8Spooka
775f7e80a8Spooka /* Reset any bus errors due to probing nonexistent devices. */
785f7e80a8Spooka (*platform.bus_reset)();
795f7e80a8Spooka
805f7e80a8Spooka /* Configuration is finished, turn on interrupts. */
81701ad559Smatt spl0(); /* enable all source forcing SOFT_INTs cleared */
825f7e80a8Spooka }
835f7e80a8Spooka
845f7e80a8Spooka /*
855f7e80a8Spooka * Look at the string 'cp' and decode the boot device.
865f7e80a8Spooka * Boot names are something like '0/ace(0,0)/netbsd' or 'tftp()/nfsnetbsd'
879dc6c88bStsutsui * meaning:
889dc6c88bStsutsui * [BusNumber/]<ControllerName>([<DiskNumber>,<PartitionNumber])/<kernelname>
895f7e80a8Spooka */
905f7e80a8Spooka void
makebootdev(char * cp)915f7e80a8Spooka makebootdev(char *cp)
925f7e80a8Spooka {
935f7e80a8Spooka int i;
945f7e80a8Spooka static char booted_controller_name[8];
955f7e80a8Spooka
965f7e80a8Spooka booted_device = NULL;
975f7e80a8Spooka booted_bus = booted_unit = booted_partition = 0;
985f7e80a8Spooka booted_controller = NULL;
995f7e80a8Spooka
1005f7e80a8Spooka if (*cp >= '0' && *cp <= '9') {
1015f7e80a8Spooka booted_bus = *cp++ - '0';
1029dc6c88bStsutsui if (*cp == '/')
1039dc6c88bStsutsui cp++;
1045f7e80a8Spooka }
1055f7e80a8Spooka
1065f7e80a8Spooka if (strncmp(cp, "tftp(", 5) == 0) {
1075f7e80a8Spooka booted_controller = "BOOTP";
1085f7e80a8Spooka goto out;
1095f7e80a8Spooka }
1105f7e80a8Spooka
1119dc6c88bStsutsui /*
1129dc6c88bStsutsui * Stash away the controller name and use it later
1135f7e80a8Spooka */
1145f7e80a8Spooka for (i = 0; i < 7 && *cp && *cp != '('; i++)
1155f7e80a8Spooka booted_controller_name[i] = *cp++;
1165f7e80a8Spooka booted_controller_name[7] = 0; /* sanity */
1175f7e80a8Spooka
1189dc6c88bStsutsui if (*cp == '(')
1199dc6c88bStsutsui cp++;
1205f7e80a8Spooka if (*cp >= '0' && *cp <= '9')
1215f7e80a8Spooka booted_unit = *cp++ - '0';
1225f7e80a8Spooka
1239dc6c88bStsutsui if (*cp == ',')
1249dc6c88bStsutsui cp++;
1255f7e80a8Spooka if (*cp >= '0' && *cp <= '9')
1265f7e80a8Spooka booted_partition = *cp - '0';
1275f7e80a8Spooka booted_controller = booted_controller_name;
1285f7e80a8Spooka
1295f7e80a8Spooka out:
1305f7e80a8Spooka #if DEBUG
1319dc6c88bStsutsui printf("bootdev: %d/%s(%d,%d)\n",
1329dc6c88bStsutsui booted_bus, booted_controller, booted_unit, booted_partition);
1335f7e80a8Spooka #endif
1345f7e80a8Spooka return;
1355f7e80a8Spooka }
1365f7e80a8Spooka
1375f7e80a8Spooka void
cpu_rootconf(void)1385f7e80a8Spooka cpu_rootconf(void)
1395f7e80a8Spooka {
1409dc6c88bStsutsui
1415f7e80a8Spooka printf("boot device: %s part%d\n",
1429dc6c88bStsutsui booted_device ? device_xname(booted_device) : "<unknown>",
1435f7e80a8Spooka booted_partition);
1445f7e80a8Spooka
145*8ce44338Smlelstv rootconf();
1465f7e80a8Spooka }
1475f7e80a8Spooka
1485f7e80a8Spooka /*
1495f7e80a8Spooka * Try to determine the boot device.
1505f7e80a8Spooka */
1515f7e80a8Spooka void
device_register(device_t dev,void * aux)1529dc6c88bStsutsui device_register(device_t dev, void *aux)
1535f7e80a8Spooka {
1545f7e80a8Spooka static int found, initted, netboot;
1559dc6c88bStsutsui static device_t ebusdev;
1569dc6c88bStsutsui device_t parent = device_parent(dev);
1575f7e80a8Spooka
1585f7e80a8Spooka if (found)
1595f7e80a8Spooka return;
1605f7e80a8Spooka
1615f7e80a8Spooka #if 0
1629dc6c88bStsutsui printf("\n[device_register(%s,%d) class %d]\n",
1639dc6c88bStsutsui device_xname(dev), device_unit(dev), device_class(dev));
1645f7e80a8Spooka #endif
1655f7e80a8Spooka
1665f7e80a8Spooka if (!initted) {
1675f7e80a8Spooka netboot = (strcmp(booted_controller, "BOOTP") == 0);
1685f7e80a8Spooka initted = 1;
1695f7e80a8Spooka }
1705f7e80a8Spooka
1715f7e80a8Spooka /*
1725f7e80a8Spooka * Remember the EBUS
1735f7e80a8Spooka */
1745f7e80a8Spooka if (device_is_a(dev, "ebus")) {
1755f7e80a8Spooka ebusdev = dev;
1765f7e80a8Spooka return;
1775f7e80a8Spooka }
1785f7e80a8Spooka
1795f7e80a8Spooka /*
1805f7e80a8Spooka * Check if netbooting.
1815f7e80a8Spooka */
1825f7e80a8Spooka if (netboot) {
1835f7e80a8Spooka
1845f7e80a8Spooka /* Only one Ethernet interface (on ebus). */
1859dc6c88bStsutsui if ((parent == ebusdev) &&
1869dc6c88bStsutsui device_is_a(dev, "enic")) {
1875f7e80a8Spooka booted_device = dev;
1885f7e80a8Spooka found = 1;
1895f7e80a8Spooka return;
1905f7e80a8Spooka }
1915f7e80a8Spooka
1925f7e80a8Spooka /* allow any network adapter */
1935f7e80a8Spooka if (device_class(dev) == DV_IFNET &&
1945f7e80a8Spooka device_is_a(parent, "ebus")) {
1955f7e80a8Spooka booted_device = dev;
1965f7e80a8Spooka found = 1;
1975f7e80a8Spooka return;
1985f7e80a8Spooka }
1995f7e80a8Spooka
2005f7e80a8Spooka /* The NIC might be found after the disk, so bail out here */
2015f7e80a8Spooka return;
2025f7e80a8Spooka }
2035f7e80a8Spooka
2045f7e80a8Spooka /* BUGBUG How would I get to the bus */
2059dc6c88bStsutsui if (device_is_a(dev, booted_controller) &&
2069dc6c88bStsutsui (device_unit(dev) == booted_unit)) {
2075f7e80a8Spooka booted_device = dev;
2085f7e80a8Spooka found = 1;
2095f7e80a8Spooka return;
2105f7e80a8Spooka }
2115f7e80a8Spooka }
212