autoconf.c revision 1.1
11.1Sgdamore/* $NetBSD: autoconf.c,v 1.1 2006/03/21 08:15:19 gdamore Exp $ */
21.1Sgdamore
31.1Sgdamore/*-
41.1Sgdamore * Copyright (c) 2001 The NetBSD Foundation, Inc.
51.1Sgdamore * All rights reserved.
61.1Sgdamore *
71.1Sgdamore * This code is derived from software contributed to The NetBSD Foundation
81.1Sgdamore * by Jason R. Thorpe.
91.1Sgdamore *
101.1Sgdamore * Redistribution and use in source and binary forms, with or without
111.1Sgdamore * modification, are permitted provided that the following conditions
121.1Sgdamore * are met:
131.1Sgdamore * 1. Redistributions of source code must retain the above copyright
141.1Sgdamore *    notice, this list of conditions and the following disclaimer.
151.1Sgdamore * 2. Redistributions in binary form must reproduce the above copyright
161.1Sgdamore *    notice, this list of conditions and the following disclaimer in the
171.1Sgdamore *    documentation and/or other materials provided with the distribution.
181.1Sgdamore * 3. All advertising materials mentioning features or use of this software
191.1Sgdamore *    must display the following acknowledgement:
201.1Sgdamore *	This product includes software developed by the NetBSD
211.1Sgdamore *	Foundation, Inc. and its contributors.
221.1Sgdamore * 4. Neither the name of The NetBSD Foundation nor the names of its
231.1Sgdamore *    contributors may be used to endorse or promote products derived
241.1Sgdamore *    from this software without specific prior written permission.
251.1Sgdamore *
261.1Sgdamore * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
271.1Sgdamore * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
281.1Sgdamore * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
291.1Sgdamore * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
301.1Sgdamore * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
311.1Sgdamore * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
321.1Sgdamore * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
331.1Sgdamore * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
341.1Sgdamore * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
351.1Sgdamore * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
361.1Sgdamore * POSSIBILITY OF SUCH DAMAGE.
371.1Sgdamore */
381.1Sgdamore
391.1Sgdamore#include <sys/cdefs.h>
401.1Sgdamore__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.1 2006/03/21 08:15:19 gdamore Exp $");
411.1Sgdamore
421.1Sgdamore#include <sys/param.h>
431.1Sgdamore#include <sys/systm.h>
441.1Sgdamore#include <sys/conf.h>
451.1Sgdamore
461.1Sgdamore#include <sys/socket.h>		/* these three just to get ETHER_ADDR_LEN(!) */
471.1Sgdamore#include <net/if.h>
481.1Sgdamore#include <net/if_ether.h>
491.1Sgdamore
501.1Sgdamore#include <machine/bus.h>
511.1Sgdamore
521.1Sgdamore#include <mips/atheros/include/ar531xreg.h>
531.1Sgdamore#include <mips/atheros/include/ar531xvar.h>
541.1Sgdamore#include <mips/atheros/include/arbusvar.h>
551.1Sgdamore
561.1Sgdamore/*
571.1Sgdamore * Configure all devices on system
581.1Sgdamore */
591.1Sgdamorevoid
601.1Sgdamorecpu_configure(void)
611.1Sgdamore{
621.1Sgdamore
631.1Sgdamore	intr_init();
641.1Sgdamore
651.1Sgdamore	/* Kick off autoconfiguration. */
661.1Sgdamore	(void)splhigh();
671.1Sgdamore	if (config_rootfound("mainbus", NULL) == NULL)
681.1Sgdamore		panic("no mainbus found");
691.1Sgdamore	(void)spl0();
701.1Sgdamore}
711.1Sgdamore
721.1Sgdamorevoid
731.1Sgdamorecpu_rootconf(void)
741.1Sgdamore{
751.1Sgdamore
761.1Sgdamore	setroot(booted_device, booted_partition);
771.1Sgdamore}
781.1Sgdamore
791.1Sgdamorevoid
801.1Sgdamoredevice_register(struct device *dev, void *aux)
811.1Sgdamore{
821.1Sgdamore	struct arbus_attach_args *aa = aux;
831.1Sgdamore	struct ar531x_board_info *info;
841.1Sgdamore
851.1Sgdamore	info = ar531x_board_info();
861.1Sgdamore	if (info == NULL) {
871.1Sgdamore		/* nothing known about this board! */
881.1Sgdamore		return;
891.1Sgdamore	}
901.1Sgdamore
911.1Sgdamore	/*
921.1Sgdamore	 * We don't ever know the boot device.  But that's because the
931.1Sgdamore	 * firmware only loads from the network.
941.1Sgdamore	 */
951.1Sgdamore
961.1Sgdamore	/* Fetch the MAC addresses from YAMON. */
971.1Sgdamore	if (device_is_a(dev, "ae")) {
981.1Sgdamore		uint8_t	*enet;
991.1Sgdamore
1001.1Sgdamore		if (aa->aa_addr == AR531X_ENET0_BASE)
1011.1Sgdamore			enet = info->ab_enet0_mac;
1021.1Sgdamore		else if (aa->aa_addr == AR531X_ENET1_BASE)
1031.1Sgdamore			enet = info->ab_enet1_mac;
1041.1Sgdamore		else
1051.1Sgdamore			return;
1061.1Sgdamore
1071.1Sgdamore		if (devprop_set(dev, "mac-addr", enet, 6, 0, 0) != 0) {
1081.1Sgdamore			printf("WARNING: unable to set mac-addr "
1091.1Sgdamore			    "property for %s\n", device_xname(dev));
1101.1Sgdamore		}
1111.1Sgdamore	}
1121.1Sgdamore
1131.1Sgdamore	if (device_is_a(dev, "ath")) {
1141.1Sgdamore		uint8_t	*enet;
1151.1Sgdamore
1161.1Sgdamore		if (aa->aa_addr == AR531X_WLAN0_BASE)
1171.1Sgdamore			enet = info->ab_wlan0_mac;
1181.1Sgdamore		else if (aa->aa_addr == AR531X_WLAN1_BASE)
1191.1Sgdamore			enet = info->ab_wlan1_mac;
1201.1Sgdamore		else
1211.1Sgdamore			return;
1221.1Sgdamore
1231.1Sgdamore		if (devprop_set(dev, "mac-addr", enet, 6, 0, 0) != 0) {
1241.1Sgdamore			printf("WARNING: unable to set mac-addr "
1251.1Sgdamore			    "property for %s\n", device_xname(dev));
1261.1Sgdamore		}
1271.1Sgdamore	}
1281.1Sgdamore}
129