Home | History | Annotate | Line # | Download | only in ews4800mips
      1 /*	$NetBSD: autoconf.c,v 1.9 2012/07/29 18:05:43 mlelstv Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2001, 2004 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26  * POSSIBILITY OF SUCH DAMAGE.
     27  */
     28 
     29 #include <sys/cdefs.h>
     30 __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.9 2012/07/29 18:05:43 mlelstv Exp $");
     31 
     32 #include "opt_sbd.h"
     33 
     34 #include <sys/param.h>
     35 #include <sys/systm.h>
     36 #include <sys/conf.h>
     37 #include <sys/device.h>
     38 #include <sys/intr.h>
     39 
     40 #include <machine/sbdvar.h>
     41 #include <machine/disklabel.h>
     42 
     43 char __boot_kernel_name[64];
     44 
     45 void
     46 cpu_configure(void)
     47 {
     48 
     49 	intr_init();
     50 
     51 	splhigh();
     52 	if (config_rootfound("mainbus", NULL) == NULL)
     53 		panic("no mainbus found");
     54 	spl0();
     55 }
     56 
     57 void
     58 cpu_rootconf(void)
     59 {
     60 	device_t dv;
     61 	char *p;
     62 	const char *bootdev_name, *netdev_name;
     63 	int unit, partition;
     64 
     65 	/* Extract boot device */
     66 	for (p = __boot_kernel_name; *p; p++) {
     67 		if (*p == ':') {
     68 			*p = '\0';
     69 			break;
     70 		}
     71 	}
     72 	p = __boot_kernel_name;
     73 
     74 	bootdev_name = 0;
     75 	unit = 0;
     76 
     77 	switch (SBD_INFO->machine) {
     78 #ifdef EWS4800_TR2
     79 	case MACHINE_TR2:
     80 		netdev_name = "iee0";
     81 		break;
     82 #endif
     83 #ifdef EWS4800_TR2A
     84 	case MACHINE_TR2A:
     85 		netdev_name = "le0";
     86 		break;
     87 #endif
     88 	default:
     89 		netdev_name = NULL;
     90 	}
     91 	partition = 0;
     92 
     93 	if (strncmp(p, "sd", 2) == 0) {
     94 		unit = p[2] - '0';
     95 		partition = p[3] - 'a';
     96 		if (unit >= 0 && unit <= 9 && partition >= 0 &&
     97 		    partition < MAXPARTITIONS) {
     98 			p[3] = '\0';
     99 			bootdev_name = __boot_kernel_name;
    100 		}
    101 	} else if (strncmp(p, "nfs", 3) == 0) {
    102 		bootdev_name = netdev_name;
    103 	} else if (strncmp(p, "mem", 3) == 0) {
    104 		int bootdev = (*platform.ipl_bootdev)();
    105 		if (bootdev == NVSRAM_BOOTDEV_HARDDISK)
    106 			bootdev_name = "sd0";
    107 		else if (bootdev == NVSRAM_BOOTDEV_NETWORK)
    108 			bootdev_name = netdev_name;
    109 		else
    110 			bootdev_name = 0;
    111 	}
    112 
    113 	if (bootdev_name &&
    114 	    (dv = device_find_by_xname(bootdev_name)) != NULL) {
    115 		booted_device = dv;
    116 		booted_partition = partition;
    117 	}
    118 	rootconf();
    119 }
    120