Home | History | Annotate | Line # | Download | only in ev64260
autoconf.c revision 1.14
      1 /*	$NetBSD: autoconf.c,v 1.14 2010/06/02 06:44:33 kiyohara Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1990 The Regents of the University of California.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to Berkeley by
      8  * William Jolitz.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. Neither the name of the University nor the names of its contributors
     19  *    may be used to endorse or promote products derived from this software
     20  *    without specific prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  * SUCH DAMAGE.
     33  *
     34  *	@(#)autoconf.c	7.1 (Berkeley) 5/9/91
     35  */
     36 
     37 /*
     38  * Setup the system to run on the current machine.
     39  *
     40  * Configure() is called at boot time and initializes the vba
     41  * device tables and the memory controller monitoring.  Available
     42  * devices are determined (from possibilities mentioned in ioconf.c),
     43  * and the drivers are initialized.
     44  */
     45 
     46 #include <sys/cdefs.h>
     47 __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.14 2010/06/02 06:44:33 kiyohara Exp $");
     48 
     49 #include <sys/param.h>
     50 #include <sys/conf.h>
     51 #include <sys/reboot.h>
     52 #include <sys/systm.h>
     53 #include <sys/types.h>
     54 
     55 #include <net/if.h>
     56 #include <net/if_ether.h>
     57 
     58 #include <dev/pci/pcivar.h>
     59 
     60 #include <machine/pci_machdep.h>
     61 
     62 #include <dev/marvell/gtpcivar.h>
     63 #include <dev/marvell/gtreg.h>
     64 #include <dev/marvell/marvellvar.h>
     65 
     66 
     67 static void findroot(void);
     68 
     69 
     70 /*
     71  * Determine i/o configuration for a machine.
     72  */
     73 void
     74 cpu_configure(void)
     75 {
     76 
     77 	if (config_rootfound("mainbus", NULL) == NULL)
     78 		panic("configure: mainbus not configured");
     79 
     80 	aprint_normal("biomask %jx netmask %jx ttymask %jx\n",
     81 	    imask[IPL_BIO] & 0x3fffffffffffffff,
     82 	    imask[IPL_NET] & 0x3fffffffffffffff,
     83 	    imask[IPL_TTY] & 0x3fffffffffffffff);
     84 
     85 	spl0();
     86 }
     87 
     88 void
     89 cpu_rootconf(void)
     90 {
     91 	findroot();
     92 
     93 	printf("boot device: %s\n",
     94 	    booted_device ? booted_device->dv_xname : "<unknown>");
     95 
     96 	setroot(booted_device, booted_partition);
     97 }
     98 
     99 dev_t	bootdev = 0;
    100 
    101 /*
    102  * Attempt to find the device from which we were booted.
    103  * If we can do so, and not instructed not to do so,
    104  * change rootdev to correspond to the load device.
    105  */
    106 static void
    107 findroot(void)
    108 {
    109 	device_t dv;
    110 	const char *name;
    111 
    112 #if 0
    113 	printf("howto %x bootdev %x ", boothowto, bootdev);
    114 #endif
    115 
    116 	if ((bootdev & B_MAGICMASK) != (u_long)B_DEVMAGIC)
    117 		return;
    118 
    119 
    120 	name = devsw_blk2name(B_TYPE(bootdev));
    121 	if (name == NULL)
    122 		return;
    123 
    124 	if ((dv = device_find_by_driver_unit(name, B_UNIT(bootdev))) != NULL) {
    125 		booted_device = dv;
    126 		booted_partition = B_PARTITION(bootdev);
    127 	}
    128 }
    129 
    130 void
    131 device_register(struct device *dev, void *aux)
    132 {
    133 	prop_dictionary_t dict = device_properties(dev);
    134 
    135 	if (device_is_a(dev, "gfe") &&
    136 	    device_is_a(device_parent(dev), "gt") ) {
    137 		struct marvell_attach_args *mva = aux;
    138 		prop_data_t mac;
    139 		char enaddr[ETHER_ADDR_LEN] =
    140 		    { 0x02, 0x00, 0x04, 0x00, 0x00, 0x04 };
    141 
    142 		switch (mva->mva_offset) {
    143 		case ETH0_BASE:	enaddr[5] |= 0; break;
    144 		case ETH1_BASE: enaddr[5] |= 1; break;
    145 		case ETH2_BASE: enaddr[5] |= 2; break;
    146 		default:
    147 			aprint_error("WARNING: unknown mac-no. for %s\n",
    148 			    dev->dv_xname);
    149 		}
    150 
    151 		mac = prop_data_create_data_nocopy(enaddr, ETHER_ADDR_LEN);
    152 		KASSERT(mac != NULL);
    153 		if (prop_dictionary_set(dict, "mac-addr", mac) == false)
    154 			aprint_error(
    155 			    "WARNING: unable to set mac-addr property for %s\n",
    156 			    dev->dv_xname);
    157 		prop_object_release(mac);
    158 	}
    159 	if (device_is_a(dev, "gtpci")) {
    160 		extern struct gtpci_prot gtpci_prot;
    161 		extern struct powerpc_bus_space
    162 		    ev64260_pci0_io_bs_tag, ev64260_pci0_mem_bs_tag,
    163 		    ev64260_pci1_io_bs_tag, ev64260_pci1_mem_bs_tag;
    164 		extern struct genppc_pci_chipset
    165 		    genppc_gtpci0_chipset, genppc_gtpci1_chipset;
    166 
    167 		struct marvell_attach_args *mva = aux;
    168 		struct powerpc_bus_space *pci_io_bs_tag, *pci_mem_bs_tag;
    169 		struct genppc_pci_chipset *genppc_gtpci_chipset;
    170 		prop_data_t prot, io_bs_tag, mem_bs_tag, pc;
    171 
    172 		if (mva->mva_unit == 0) {
    173 			pci_io_bs_tag = &ev64260_pci0_io_bs_tag;
    174 			pci_mem_bs_tag = &ev64260_pci0_mem_bs_tag;
    175 			genppc_gtpci_chipset = &genppc_gtpci0_chipset;
    176 		} else {
    177 			pci_io_bs_tag = &ev64260_pci1_io_bs_tag;
    178 			pci_mem_bs_tag = &ev64260_pci1_mem_bs_tag;
    179 			genppc_gtpci_chipset = &genppc_gtpci1_chipset;
    180 		}
    181 
    182 		prot = prop_data_create_data_nocopy(
    183 		    &gtpci_prot, sizeof(struct gtpci_prot));
    184 		KASSERT(prot != NULL);
    185 		prop_dictionary_set(dict, "prot", prot);
    186 		prop_object_release(prot);
    187 		io_bs_tag = prop_data_create_data_nocopy(
    188 		    pci_io_bs_tag, sizeof(struct powerpc_bus_space));
    189 		KASSERT(io_bs_tag != NULL);
    190 		prop_dictionary_set(dict, "io-bus-tag", io_bs_tag);
    191 		prop_object_release(io_bs_tag);
    192 		mem_bs_tag = prop_data_create_data_nocopy(
    193 		    pci_mem_bs_tag, sizeof(struct powerpc_bus_space));
    194 		KASSERT(mem_bs_tag != NULL);
    195 		prop_dictionary_set(dict, "mem-bus-tag", mem_bs_tag);
    196 		prop_object_release(mem_bs_tag);
    197 
    198 		genppc_gtpci_chipset->pc_conf_v = device_private(dev);
    199 		pc = prop_data_create_data_nocopy(genppc_gtpci_chipset,
    200 		    sizeof(struct genppc_pci_chipset));
    201 		KASSERT(pc != NULL);
    202 		prop_dictionary_set(dict, "pci-chipset", pc);
    203 		prop_object_release(pc);
    204 
    205 		prop_dictionary_set_uint64(dict, "iostart", 0x00000600);
    206 		prop_dictionary_set_uint64(dict, "ioend", 0x0000ffff);
    207 		prop_dictionary_set_uint64(dict, "memstart",
    208 		    pci_mem_bs_tag->pbs_base);
    209 		prop_dictionary_set_uint64(dict, "memend",
    210 		    pci_mem_bs_tag->pbs_limit - 1);
    211 		prop_dictionary_set_uint32(dict, "cache-line-size", 32);
    212 	}
    213 	if (device_is_a(dev, "obio") &&
    214 	    device_is_a(device_parent(dev), "gt") ) {
    215 		extern struct powerpc_bus_space *ev64260_obio_bs_tags[5];
    216 		struct marvell_attach_args *mva = aux;
    217 		struct powerpc_bus_space *bst =
    218 		    ev64260_obio_bs_tags[mva->mva_unit];
    219 		prop_data_t bstd;
    220 
    221 		bstd =
    222 		    prop_data_create_data_nocopy(bst, sizeof(bus_space_tag_t));
    223 		KASSERT(bstd != NULL);
    224 		if (prop_dictionary_set(dict, "bus-tag", bstd) == false)
    225 			aprint_error(
    226 			    "WARNING: unable to set bus-tag property for %s\n",
    227 			    dev->dv_xname);
    228 		prop_object_release(bstd);
    229 	}
    230 }
    231