Home | History | Annotate | Line # | Download | only in rmixl
autoconf.c revision 1.1.2.6
      1 /*	$NetBSD: autoconf.c,v 1.1.2.6 2012/01/04 16:17:52 matt Exp $	*/
      2 
      3 /*
      4  * Copyright 2002 Wasabi Systems, Inc.
      5  * All rights reserved.
      6  *
      7  * Written by Simon Burge for Wasabi Systems, Inc.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  * 3. All advertising materials mentioning features or use of this software
     18  *    must display the following acknowledgement:
     19  *      This product includes software developed for the NetBSD Project by
     20  *      Wasabi Systems, Inc.
     21  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22  *    or promote products derived from this software without specific prior
     23  *    written permission.
     24  *
     25  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  * POSSIBILITY OF SUCH DAMAGE.
     36  */
     37 
     38 #include <sys/cdefs.h>
     39 __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.1.2.6 2012/01/04 16:17:52 matt Exp $");
     40 
     41 #define _MIPS_BUS_DMA_PRIVATE
     42 
     43 #include <sys/param.h>
     44 #include <sys/systm.h>
     45 #include <sys/bus.h>
     46 #include <sys/conf.h>
     47 #include <sys/cpu.h>
     48 #include <sys/device.h>
     49 
     50 #include <mips/rmi/rmixlvar.h>
     51 
     52 static void	findroot(void);
     53 static void	rmixl_bus_dma_init(void);
     54 
     55 void
     56 cpu_configure()
     57 {
     58 	rmixl_bus_dma_init();
     59 
     60 	rmixl_fmn_init();
     61 
     62 	intr_init();
     63 
     64 	/* Kick off autoconfiguration. */
     65 	(void)splhigh();
     66 	if (config_rootfound("mainbus", NULL) == NULL)
     67 		panic("no mainbus found");
     68 
     69 	/*
     70 	 * Hardware interrupts will be enabled in
     71 	 * sys/arch/mips/mips/mips3_clockintr.c:mips3_initclocks()
     72 	 * to avoid hardclock(9) by CPU INT5 before softclockintr is
     73 	 * initialized in initclocks().
     74 	 */
     75 }
     76 
     77 void
     78 cpu_rootconf()
     79 {
     80 	findroot();
     81 
     82 	printf("boot device: %s\n",
     83 		booted_device ? booted_device->dv_xname : "<unknown>");
     84 
     85 	setroot(booted_device, booted_partition);
     86 }
     87 
     88 extern char	bootstring[];
     89 extern int	netboot;
     90 
     91 static void
     92 findroot(void)
     93 {
     94 	if (booted_device)
     95 		return;
     96 
     97 	if ((booted_device == NULL) && netboot == 0) {
     98 		device_t dv;
     99 		deviter_t di;
    100 
    101 		for (dv = deviter_first(&di, DEVITER_F_ROOT_FIRST);
    102 		     dv != NULL;
    103 		     dv = deviter_next(&di)) {
    104 			if (device_class(dv) == DV_DISK
    105 			    && (device_is_a(dv, "wd")
    106 				|| device_is_a(dv, "sd")
    107 				|| device_is_a(dv, "ld")))
    108 				booted_device = dv;
    109 		}
    110 		deviter_release(&di);
    111 	}
    112 
    113 	/*
    114 	 * XXX Match up MBR boot specification with BSD disklabel for root?
    115 	 */
    116 	booted_partition = 0;
    117 }
    118 
    119 static void
    120 addprop_integer(device_t dev, const char *name, uint32_t val)
    121 {
    122 	prop_number_t pn;
    123 	pn = prop_number_create_integer(val);
    124 	KASSERT(pn != NULL);
    125 	if (prop_dictionary_set(device_properties(dev), name, pn) == false) {
    126 		printf("WARNING: unable to set %s property for %s",
    127 		    name, device_xname(dev));
    128 	}
    129 	prop_object_release(pn);
    130 }
    131 
    132 void
    133 device_register(device_t dev, void *aux)
    134 {
    135 
    136 	if (booted_device == NULL
    137 	    && netboot == 1
    138 	    && device_class(dev) == DV_IFNET)
    139 		booted_device = dev;
    140 
    141 	if (device_is_a(dev, "com")) {
    142 		device_t parent = device_parent(dev);
    143 		if (device_is_a(parent, "mainbus")) {
    144 			addprop_integer(dev, "frequency", 133333333);
    145 		} if (device_is_a(parent, "pci")) {
    146 			struct pci_attach_args * const pa = aux;
    147 			int bus;
    148 			pci_decompose_tag(pa->pa_pc, pa->pa_tag, &bus,
    149 			    NULL, NULL);
    150 			if (bus == 0) {
    151 				addprop_integer(dev, "frequency", 133333333);
    152 			}
    153 		} else if (device_is_a(parent, "obio")) {
    154 			addprop_integer(dev, "frequency", 66666666);
    155 		}
    156 	}
    157 }
    158 
    159 static void
    160 rmixl_bus_dma_init(void)
    161 {
    162 	struct rmixl_config * const rcp = &rmixl_configuration;
    163 	int error;
    164 
    165 	/* 64bit dmatag was staticly initialized */
    166 
    167 	/* dma space for addr < 4GB */
    168 	if (rcp->rc_dmat32 == NULL) {
    169 		error = bus_dmatag_subregion(rcp->rc_dmat64,
    170 		    0, (bus_addr_t)1 << 32, &rcp->rc_dmat32, 0);
    171 		if (error)
    172 			panic("%s: failed to create 32bit dma tag: %d",
    173 			    __func__, error);
    174 	}
    175 
    176 	/* dma space for addr < 512MB (KSEG0/1) */
    177 	if (rcp->rc_dmat29 == NULL) {
    178 		error = bus_dmatag_subregion(rcp->rc_dmat32,
    179 		    0, (bus_addr_t)1 << 29, &rcp->rc_dmat29, 0);
    180 		if (error)
    181 			panic("%s: failed to create 29bit dma tag: %d",
    182 			    __func__, error);
    183 	}
    184 }
    185