Home | History | Annotate | Line # | Download | only in rmixl
autoconf.c revision 1.1.2.5
      1 /*	$NetBSD: autoconf.c,v 1.1.2.5 2011/12/24 01:44:43 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.5 2011/12/24 01:44:43 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 	intr_init();
     61 
     62 	/* Kick off autoconfiguration. */
     63 	(void)splhigh();
     64 	if (config_rootfound("mainbus", NULL) == NULL)
     65 		panic("no mainbus found");
     66 
     67 	/*
     68 	 * Hardware interrupts will be enabled in
     69 	 * sys/arch/mips/mips/mips3_clockintr.c:mips3_initclocks()
     70 	 * to avoid hardclock(9) by CPU INT5 before softclockintr is
     71 	 * initialized in initclocks().
     72 	 */
     73 }
     74 
     75 void
     76 cpu_rootconf()
     77 {
     78 	findroot();
     79 
     80 	printf("boot device: %s\n",
     81 		booted_device ? booted_device->dv_xname : "<unknown>");
     82 
     83 	setroot(booted_device, booted_partition);
     84 }
     85 
     86 extern char	bootstring[];
     87 extern int	netboot;
     88 
     89 static void
     90 findroot(void)
     91 {
     92 	if (booted_device)
     93 		return;
     94 
     95 	if ((booted_device == NULL) && netboot == 0) {
     96 		device_t dv;
     97 		deviter_t di;
     98 
     99 		for (dv = deviter_first(&di, DEVITER_F_ROOT_FIRST);
    100 		     dv != NULL;
    101 		     dv = deviter_next(&di)) {
    102 			if (device_class(dv) == DV_DISK
    103 			    && (device_is_a(dv, "wd")
    104 				|| device_is_a(dv, "sd")
    105 				|| device_is_a(dv, "ld")))
    106 				booted_device = dv;
    107 		}
    108 		deviter_release(&di);
    109 	}
    110 
    111 	/*
    112 	 * XXX Match up MBR boot specification with BSD disklabel for root?
    113 	 */
    114 	booted_partition = 0;
    115 }
    116 
    117 static void
    118 addprop_integer(device_t dev, const char *name, uint32_t val)
    119 {
    120 	prop_number_t pn;
    121 	pn = prop_number_create_integer(val);
    122 	KASSERT(pn != NULL);
    123 	if (prop_dictionary_set(device_properties(dev), name, pn) == false) {
    124 		printf("WARNING: unable to set %s property for %s",
    125 		    name, device_xname(dev));
    126 	}
    127 	prop_object_release(pn);
    128 }
    129 
    130 void
    131 device_register(device_t dev, void *aux)
    132 {
    133 
    134 	if (booted_device == NULL
    135 	    && netboot == 1
    136 	    && device_class(dev) == DV_IFNET)
    137 		booted_device = dev;
    138 
    139 	if (device_is_a(dev, "com")) {
    140 		device_t parent = device_parent(dev);
    141 		if (device_is_a(parent, "mainbus")) {
    142 			addprop_integer(dev, "frequency", 133333333);
    143 		} if (device_is_a(parent, "pci")) {
    144 			struct pci_attach_args * const pa = aux;
    145 			int bus;
    146 			pci_decompose_tag(pa->pa_pc, pa->pa_tag, &bus,
    147 			    NULL, NULL);
    148 			if (bus == 0) {
    149 				addprop_integer(dev, "frequency", 133333333);
    150 			}
    151 		} else if (device_is_a(parent, "obio")) {
    152 			addprop_integer(dev, "frequency", 66666666);
    153 		}
    154 	}
    155 }
    156 
    157 static void
    158 rmixl_bus_dma_init(void)
    159 {
    160 	struct rmixl_config * const rcp = &rmixl_configuration;
    161 	int error;
    162 
    163 	/* 64bit dmatag was staticly initialized */
    164 
    165 	/* dma space for addr < 4GB */
    166 	if (rcp->rc_dmat32 == NULL) {
    167 		error = bus_dmatag_subregion(rcp->rc_dmat64,
    168 		    0, (bus_addr_t)1 << 32, &rcp->rc_dmat32, 0);
    169 		if (error)
    170 			panic("%s: failed to create 32bit dma tag: %d",
    171 			    __func__, error);
    172 	}
    173 
    174 	/* dma space for addr < 512MB (KSEG0/1) */
    175 	if (rcp->rc_dmat29 == NULL) {
    176 		error = bus_dmatag_subregion(rcp->rc_dmat32,
    177 		    0, (bus_addr_t)1 << 29, &rcp->rc_dmat29, 0);
    178 		if (error)
    179 			panic("%s: failed to create 29bit dma tag: %d",
    180 			    __func__, error);
    181 	}
    182 }
    183