Home | History | Annotate | Line # | Download | only in cavium
autoconf.c revision 1.3
      1 /*	$NetBSD: autoconf.c,v 1.3 2015/06/06 22:23:31 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.3 2015/06/06 22:23:31 matt Exp $");
     40 
     41 #include <sys/param.h>
     42 #include <sys/systm.h>
     43 #include <sys/buf.h>
     44 #include <sys/conf.h>
     45 #include <sys/device.h>
     46 
     47 #include <net/if_ether.h>
     48 
     49 #include <mips/cpu.h>
     50 #include <mips/locore.h>
     51 
     52 #include <evbmips/cavium/octeon_uboot.h>
     53 
     54 static void	findroot(void);
     55 
     56 void
     57 cpu_configure(void)
     58 {
     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 	/* XXX need this? */
     68 	(void)spl0();
     69 	KDASSERT(mips_cp0_status_read() & MIPS_SR_INT_IE);
     70 }
     71 
     72 void
     73 cpu_rootconf(void)
     74 {
     75 	findroot();
     76 
     77 	printf("boot device: %s\n",
     78 		booted_device ? booted_device->dv_xname : "<unknown>");
     79 
     80 	rootconf();
     81 }
     82 
     83 extern char	bootstring[];
     84 extern int	netboot;
     85 
     86 static void
     87 findroot(void)
     88 {
     89 	device_t dv;
     90 	deviter_t di;
     91 
     92 	if (booted_device)
     93 		return;
     94 
     95 	if ((booted_device == NULL) && netboot == 0) {
     96 		for (dv = deviter_first(&di, DEVITER_F_ROOT_FIRST); dv != NULL;
     97 		     dv = deviter_next(&di)) {
     98 			if (device_class(dv) == DV_DISK &&
     99 			    device_is_a(dv, "sd"))
    100 				    booted_device = dv;
    101 		}
    102 		deviter_release(&di);
    103 	}
    104 
    105 	/*
    106 	 * XXX Match up MBR boot specification with BSD disklabel for root?
    107 	 */
    108 	booted_partition = 0;
    109 
    110 	return;
    111 }
    112 
    113 static void
    114 prop_set_cnmac(device_t dev)
    115 {
    116 	prop_dictionary_t dict = device_properties(dev);
    117 	prop_data_t pd;
    118 	prop_number_t pn;
    119 	uint8_t enaddr[ETHER_ADDR_LEN];
    120 	uint32_t mac_lo;
    121 	int unit = device_unit(dev);
    122 
    123 	/* ethernet mac address */
    124 	memcpy(enaddr, octeon_btinfo.obt_mac_addr_base,
    125 	    sizeof(enaddr));
    126 	mac_lo = enaddr[3] << 16;
    127 	mac_lo += enaddr[4] << 8;
    128 	mac_lo += enaddr[5];
    129 	KASSERT(unit < octeon_btinfo.obt_mac_addr_count);
    130 	mac_lo += unit;
    131 	enaddr[3] = (mac_lo >> 16) & 0xff;
    132 	enaddr[4] = (mac_lo >> 8) & 0xff;
    133 	enaddr[5] = mac_lo & 0xff;
    134 	pd = prop_data_create_data(enaddr, ETHER_ADDR_LEN);
    135 	KASSERT(pd != NULL);
    136 	prop_dictionary_set_and_rel(dict, "mac-address", pd);
    137 
    138 	/* ethernet phy adddress */
    139 	switch (octeon_btinfo.obt_board_type) {
    140 	case BOARD_TYPE_UBIQUITI_E100:
    141 		pn = prop_number_create_integer(0x07 - unit);
    142 		break;
    143 	default:
    144 		pn = prop_number_create_integer(-1);
    145 		break;
    146 	}
    147 	KASSERT(pn != NULL);
    148 	prop_dictionary_set_and_rel(dict, "phy-addr", pn);
    149 }
    150 
    151 static void
    152 prop_set_octeon_gmx(device_t dev)
    153 {
    154 	prop_dictionary_t dict = device_properties(dev);
    155 	prop_number_t tx, rx;
    156 
    157 	/* ethernet rgmii phy dependent timing parameter. */
    158 	switch (octeon_btinfo.obt_board_type) {
    159 	case BOARD_TYPE_UBIQUITI_E100:
    160 		tx = prop_number_create_integer(16);
    161 		rx = prop_number_create_integer(0);
    162 		break;
    163 	default:
    164 		tx = prop_number_create_integer(0);
    165 		rx = prop_number_create_integer(0);
    166 		break;
    167 	}
    168 	KASSERT(tx != NULL);
    169 	KASSERT(rx != NULL);
    170 	prop_dictionary_set_and_rel(dict, "rgmii-tx", tx);
    171 	prop_dictionary_set_and_rel(dict, "rgmii-rx", rx);
    172 }
    173 
    174 void
    175 device_register(device_t dev, void *aux)
    176 {
    177 	if ((booted_device == NULL) && (netboot == 1))
    178 		if (device_class(dev) == DV_IFNET)
    179 			booted_device = dev;
    180 
    181 	if (device_is_a(dev, "cnmac")) {
    182 		prop_set_cnmac(dev);
    183 	} else if (device_is_a(dev, "octeon_gmx")) {
    184 		prop_set_octeon_gmx(dev);
    185 	}
    186 }
    187