Home | History | Annotate | Line # | Download | only in ev64260
autoconf.c revision 1.17
      1  1.17   mlelstv /*	$NetBSD: autoconf.c,v 1.17 2012/07/29 18:05:42 mlelstv 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.13  kiyohara  * 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.17   mlelstv __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.17 2012/07/29 18:05:42 mlelstv Exp $");
     48   1.5     lukem 
     49   1.1      matt #include <sys/param.h>
     50   1.1      matt #include <sys/conf.h>
     51  1.15      matt #include <sys/device_if.h>
     52   1.1      matt #include <sys/reboot.h>
     53  1.13  kiyohara #include <sys/systm.h>
     54  1.13  kiyohara 
     55  1.13  kiyohara #include <net/if.h>
     56  1.13  kiyohara #include <net/if_ether.h>
     57  1.13  kiyohara 
     58  1.13  kiyohara #include <dev/pci/pcivar.h>
     59  1.13  kiyohara 
     60  1.13  kiyohara #include <machine/pci_machdep.h>
     61  1.13  kiyohara 
     62  1.14  kiyohara #include <dev/marvell/gtpcivar.h>
     63  1.13  kiyohara #include <dev/marvell/gtreg.h>
     64  1.13  kiyohara #include <dev/marvell/marvellvar.h>
     65  1.13  kiyohara 
     66  1.13  kiyohara 
     67  1.13  kiyohara 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.12    cegger 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.1      matt 	spl0();
     81   1.1      matt }
     82   1.1      matt 
     83   1.1      matt void
     84  1.12    cegger cpu_rootconf(void)
     85   1.1      matt {
     86   1.1      matt 	findroot();
     87   1.1      matt 
     88   1.1      matt 	printf("boot device: %s\n",
     89  1.15      matt 	    booted_device ? device_xname(booted_device) : "<unknown>");
     90   1.1      matt 
     91  1.17   mlelstv 	rootconf();
     92   1.1      matt }
     93   1.1      matt 
     94   1.1      matt dev_t	bootdev = 0;
     95   1.1      matt 
     96   1.1      matt /*
     97   1.1      matt  * Attempt to find the device from which we were booted.
     98   1.1      matt  * If we can do so, and not instructed not to do so,
     99   1.1      matt  * change rootdev to correspond to the load device.
    100   1.1      matt  */
    101  1.13  kiyohara static void
    102   1.1      matt findroot(void)
    103   1.1      matt {
    104  1.10     joerg 	device_t dv;
    105   1.1      matt 	const char *name;
    106   1.1      matt 
    107   1.1      matt #if 0
    108   1.1      matt 	printf("howto %x bootdev %x ", boothowto, bootdev);
    109   1.1      matt #endif
    110   1.1      matt 
    111   1.1      matt 	if ((bootdev & B_MAGICMASK) != (u_long)B_DEVMAGIC)
    112   1.1      matt 		return;
    113   1.1      matt 
    114   1.1      matt 
    115   1.1      matt 	name = devsw_blk2name(B_TYPE(bootdev));
    116   1.1      matt 	if (name == NULL)
    117   1.1      matt 		return;
    118   1.1      matt 
    119  1.10     joerg 	if ((dv = device_find_by_driver_unit(name, B_UNIT(bootdev))) != NULL) {
    120  1.10     joerg 		booted_device = dv;
    121  1.10     joerg 		booted_partition = B_PARTITION(bootdev);
    122   1.1      matt 	}
    123   1.4   thorpej }
    124   1.4   thorpej 
    125   1.4   thorpej void
    126  1.15      matt device_register(device_t dev, void *aux)
    127   1.4   thorpej {
    128  1.13  kiyohara 	prop_dictionary_t dict = device_properties(dev);
    129  1.13  kiyohara 
    130  1.13  kiyohara 	if (device_is_a(dev, "gfe") &&
    131  1.13  kiyohara 	    device_is_a(device_parent(dev), "gt") ) {
    132  1.13  kiyohara 		struct marvell_attach_args *mva = aux;
    133  1.13  kiyohara 		prop_data_t mac;
    134  1.13  kiyohara 		char enaddr[ETHER_ADDR_LEN] =
    135  1.13  kiyohara 		    { 0x02, 0x00, 0x04, 0x00, 0x00, 0x04 };
    136  1.13  kiyohara 
    137  1.13  kiyohara 		switch (mva->mva_offset) {
    138  1.13  kiyohara 		case ETH0_BASE:	enaddr[5] |= 0; break;
    139  1.13  kiyohara 		case ETH1_BASE: enaddr[5] |= 1; break;
    140  1.13  kiyohara 		case ETH2_BASE: enaddr[5] |= 2; break;
    141  1.13  kiyohara 		default:
    142  1.13  kiyohara 			aprint_error("WARNING: unknown mac-no. for %s\n",
    143  1.16      matt 			    device_xname(dev));
    144  1.13  kiyohara 		}
    145  1.13  kiyohara 
    146  1.13  kiyohara 		mac = prop_data_create_data_nocopy(enaddr, ETHER_ADDR_LEN);
    147  1.13  kiyohara 		KASSERT(mac != NULL);
    148  1.13  kiyohara 		if (prop_dictionary_set(dict, "mac-addr", mac) == false)
    149  1.13  kiyohara 			aprint_error(
    150  1.13  kiyohara 			    "WARNING: unable to set mac-addr property for %s\n",
    151  1.16      matt 			    device_xname(dev));
    152  1.13  kiyohara 		prop_object_release(mac);
    153  1.13  kiyohara 	}
    154  1.13  kiyohara 	if (device_is_a(dev, "gtpci")) {
    155  1.14  kiyohara 		extern struct gtpci_prot gtpci_prot;
    156  1.13  kiyohara 		extern struct powerpc_bus_space
    157  1.13  kiyohara 		    ev64260_pci0_io_bs_tag, ev64260_pci0_mem_bs_tag,
    158  1.13  kiyohara 		    ev64260_pci1_io_bs_tag, ev64260_pci1_mem_bs_tag;
    159  1.13  kiyohara 		extern struct genppc_pci_chipset
    160  1.13  kiyohara 		    genppc_gtpci0_chipset, genppc_gtpci1_chipset;
    161  1.13  kiyohara 
    162  1.13  kiyohara 		struct marvell_attach_args *mva = aux;
    163  1.13  kiyohara 		struct powerpc_bus_space *pci_io_bs_tag, *pci_mem_bs_tag;
    164  1.13  kiyohara 		struct genppc_pci_chipset *genppc_gtpci_chipset;
    165  1.14  kiyohara 		prop_data_t prot, io_bs_tag, mem_bs_tag, pc;
    166  1.13  kiyohara 
    167  1.13  kiyohara 		if (mva->mva_unit == 0) {
    168  1.13  kiyohara 			pci_io_bs_tag = &ev64260_pci0_io_bs_tag;
    169  1.13  kiyohara 			pci_mem_bs_tag = &ev64260_pci0_mem_bs_tag;
    170  1.13  kiyohara 			genppc_gtpci_chipset = &genppc_gtpci0_chipset;
    171  1.13  kiyohara 		} else {
    172  1.13  kiyohara 			pci_io_bs_tag = &ev64260_pci1_io_bs_tag;
    173  1.13  kiyohara 			pci_mem_bs_tag = &ev64260_pci1_mem_bs_tag;
    174  1.13  kiyohara 			genppc_gtpci_chipset = &genppc_gtpci1_chipset;
    175  1.13  kiyohara 		}
    176  1.13  kiyohara 
    177  1.14  kiyohara 		prot = prop_data_create_data_nocopy(
    178  1.14  kiyohara 		    &gtpci_prot, sizeof(struct gtpci_prot));
    179  1.14  kiyohara 		KASSERT(prot != NULL);
    180  1.14  kiyohara 		prop_dictionary_set(dict, "prot", prot);
    181  1.14  kiyohara 		prop_object_release(prot);
    182  1.13  kiyohara 		io_bs_tag = prop_data_create_data_nocopy(
    183  1.13  kiyohara 		    pci_io_bs_tag, sizeof(struct powerpc_bus_space));
    184  1.13  kiyohara 		KASSERT(io_bs_tag != NULL);
    185  1.13  kiyohara 		prop_dictionary_set(dict, "io-bus-tag", io_bs_tag);
    186  1.13  kiyohara 		prop_object_release(io_bs_tag);
    187  1.13  kiyohara 		mem_bs_tag = prop_data_create_data_nocopy(
    188  1.13  kiyohara 		    pci_mem_bs_tag, sizeof(struct powerpc_bus_space));
    189  1.13  kiyohara 		KASSERT(mem_bs_tag != NULL);
    190  1.13  kiyohara 		prop_dictionary_set(dict, "mem-bus-tag", mem_bs_tag);
    191  1.13  kiyohara 		prop_object_release(mem_bs_tag);
    192  1.13  kiyohara 
    193  1.13  kiyohara 		genppc_gtpci_chipset->pc_conf_v = device_private(dev);
    194  1.13  kiyohara 		pc = prop_data_create_data_nocopy(genppc_gtpci_chipset,
    195  1.13  kiyohara 		    sizeof(struct genppc_pci_chipset));
    196  1.13  kiyohara 		KASSERT(pc != NULL);
    197  1.13  kiyohara 		prop_dictionary_set(dict, "pci-chipset", pc);
    198  1.13  kiyohara 		prop_object_release(pc);
    199  1.13  kiyohara 
    200  1.13  kiyohara 		prop_dictionary_set_uint64(dict, "iostart", 0x00000600);
    201  1.13  kiyohara 		prop_dictionary_set_uint64(dict, "ioend", 0x0000ffff);
    202  1.13  kiyohara 		prop_dictionary_set_uint64(dict, "memstart",
    203  1.13  kiyohara 		    pci_mem_bs_tag->pbs_base);
    204  1.13  kiyohara 		prop_dictionary_set_uint64(dict, "memend",
    205  1.13  kiyohara 		    pci_mem_bs_tag->pbs_limit - 1);
    206  1.13  kiyohara 		prop_dictionary_set_uint32(dict, "cache-line-size", 32);
    207  1.13  kiyohara 	}
    208  1.13  kiyohara 	if (device_is_a(dev, "obio") &&
    209  1.13  kiyohara 	    device_is_a(device_parent(dev), "gt") ) {
    210  1.13  kiyohara 		extern struct powerpc_bus_space *ev64260_obio_bs_tags[5];
    211  1.13  kiyohara 		struct marvell_attach_args *mva = aux;
    212  1.13  kiyohara 		struct powerpc_bus_space *bst =
    213  1.13  kiyohara 		    ev64260_obio_bs_tags[mva->mva_unit];
    214  1.13  kiyohara 		prop_data_t bstd;
    215  1.13  kiyohara 
    216  1.13  kiyohara 		bstd =
    217  1.13  kiyohara 		    prop_data_create_data_nocopy(bst, sizeof(bus_space_tag_t));
    218  1.13  kiyohara 		KASSERT(bstd != NULL);
    219  1.13  kiyohara 		if (prop_dictionary_set(dict, "bus-tag", bstd) == false)
    220  1.13  kiyohara 			aprint_error(
    221  1.13  kiyohara 			    "WARNING: unable to set bus-tag property for %s\n",
    222  1.16      matt 			    device_xname(dev));
    223  1.13  kiyohara 		prop_object_release(bstd);
    224  1.13  kiyohara 	}
    225   1.1      matt }
    226