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