1*036ca983Smatt /* $NetBSD: booke_autoconf.c,v 1.3 2011/06/17 19:03:03 matt Exp $ */
2b8ea2c8cSmatt /*-
3b8ea2c8cSmatt * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
4b8ea2c8cSmatt * All rights reserved.
5b8ea2c8cSmatt *
6b8ea2c8cSmatt * This code is derived from software contributed to The NetBSD Foundation
7b8ea2c8cSmatt * by Raytheon BBN Technologies Corp and Defense Advanced Research Projects
8b8ea2c8cSmatt * Agency and which was developed by Matt Thomas of 3am Software Foundry.
9b8ea2c8cSmatt *
10b8ea2c8cSmatt * This material is based upon work supported by the Defense Advanced Research
11b8ea2c8cSmatt * Projects Agency and Space and Naval Warfare Systems Center, Pacific, under
12b8ea2c8cSmatt * Contract No. N66001-09-C-2073.
13b8ea2c8cSmatt * Approved for Public Release, Distribution Unlimited
14b8ea2c8cSmatt *
15b8ea2c8cSmatt * Redistribution and use in source and binary forms, with or without
16b8ea2c8cSmatt * modification, are permitted provided that the following conditions
17b8ea2c8cSmatt * are met:
18b8ea2c8cSmatt * 1. Redistributions of source code must retain the above copyright
19b8ea2c8cSmatt * notice, this list of conditions and the following disclaimer.
20b8ea2c8cSmatt * 2. Redistributions in binary form must reproduce the above copyright
21b8ea2c8cSmatt * notice, this list of conditions and the following disclaimer in the
22b8ea2c8cSmatt * documentation and/or other materials provided with the distribution.
23b8ea2c8cSmatt *
24b8ea2c8cSmatt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
25b8ea2c8cSmatt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26b8ea2c8cSmatt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27b8ea2c8cSmatt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
28b8ea2c8cSmatt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29b8ea2c8cSmatt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30b8ea2c8cSmatt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31b8ea2c8cSmatt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32b8ea2c8cSmatt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33b8ea2c8cSmatt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34b8ea2c8cSmatt * POSSIBILITY OF SUCH DAMAGE.
35b8ea2c8cSmatt */
36b8ea2c8cSmatt
37b8ea2c8cSmatt #include <sys/cdefs.h>
38*036ca983Smatt __KERNEL_RCSID(0, "$NetBSD: booke_autoconf.c,v 1.3 2011/06/17 19:03:03 matt Exp $");
39b8ea2c8cSmatt
40b8ea2c8cSmatt #include <sys/param.h>
41b8ea2c8cSmatt #include <sys/conf.h>
42b8ea2c8cSmatt #include <sys/cpu.h>
43b8ea2c8cSmatt #include <sys/device.h>
44b8ea2c8cSmatt #include <sys/systm.h>
45b8ea2c8cSmatt
46b8ea2c8cSmatt #include <net/if.h>
47b8ea2c8cSmatt #include <net/if_ether.h>
48b8ea2c8cSmatt
49b8ea2c8cSmatt #include <powerpc/booke/cpuvar.h>
50b8ea2c8cSmatt
51b8ea2c8cSmatt void
e500_device_register(device_t dev,void * aux)52b8ea2c8cSmatt e500_device_register(device_t dev, void *aux)
53b8ea2c8cSmatt {
54b8ea2c8cSmatt device_t parent = device_parent(dev);
55b8ea2c8cSmatt
56b8ea2c8cSmatt if (device_is_a(dev, "etsec") && device_is_a(parent, "cpunode")) {
57b8ea2c8cSmatt /* Set the mac-addr of the on-chip Ethernet. */
58b8ea2c8cSmatt struct cpunode_attach_args *cna = aux;
59b8ea2c8cSmatt
60b8ea2c8cSmatt if (cna->cna_locs.cnl_instance < 4) {
61b8ea2c8cSmatt prop_data_t pd;
62b8ea2c8cSmatt char prop_name[15];
63b8ea2c8cSmatt
64b8ea2c8cSmatt snprintf(prop_name, sizeof(prop_name),
65b8ea2c8cSmatt "etsec%d-mac-addr", cna->cna_locs.cnl_instance);
66b8ea2c8cSmatt
67b8ea2c8cSmatt pd = prop_dictionary_get(board_properties, prop_name);
68b8ea2c8cSmatt if (pd == NULL) {
69b8ea2c8cSmatt printf("WARNING: unable to get mac-addr "
70b8ea2c8cSmatt "property from board properties\n");
71b8ea2c8cSmatt return;
72b8ea2c8cSmatt }
73b8ea2c8cSmatt if (prop_dictionary_set(device_properties(dev),
74b8ea2c8cSmatt "mac-address", pd) == false) {
75b8ea2c8cSmatt printf("WARNING: unable to set mac-addr "
76*036ca983Smatt "property for %s\n", device_xname(dev));
77b8ea2c8cSmatt }
78b8ea2c8cSmatt }
79b8ea2c8cSmatt return;
80b8ea2c8cSmatt }
81b8ea2c8cSmatt }
82