2 * Copyright (c) 2005 Marius Strobl <marius@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions, and the following disclaimer,
10 * without modification, immediately at the beginning of the file.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
33 #include <sys/systm.h>
35 #include <sys/errno.h>
37 #include <dev/ofw/ofw_bus_subr.h>
38 #include <dev/ofw/openfirm.h>
40 #include "ofw_bus_if.h"
43 ofw_bus_gen_setup_devinfo(struct ofw_bus_devinfo *obd, phandle_t node)
48 /* The 'name' property is considered mandatory. */
49 if ((OF_getprop_alloc(node, "name", 1, (void **)&obd->obd_name)) == -1)
51 OF_getprop_alloc(node, "compatible", 1, (void **)&obd->obd_compat);
52 OF_getprop_alloc(node, "device_type", 1, (void **)&obd->obd_type);
53 OF_getprop_alloc(node, "model", 1, (void **)&obd->obd_model);
59 ofw_bus_gen_destroy_devinfo(struct ofw_bus_devinfo *obd)
64 if (obd->obd_compat != NULL)
65 free(obd->obd_compat, M_OFWPROP);
66 if (obd->obd_model != NULL)
67 free(obd->obd_model, M_OFWPROP);
68 if (obd->obd_name != NULL)
69 free(obd->obd_name, M_OFWPROP);
70 if (obd->obd_type != NULL)
71 free(obd->obd_type, M_OFWPROP);
76 ofw_bus_gen_get_compat(device_t bus, device_t dev)
78 const struct ofw_bus_devinfo *obd;
80 obd = OFW_BUS_GET_DEVINFO(bus, dev);
83 return (obd->obd_compat);
87 ofw_bus_gen_get_model(device_t bus, device_t dev)
89 const struct ofw_bus_devinfo *obd;
91 obd = OFW_BUS_GET_DEVINFO(bus, dev);
94 return (obd->obd_model);
98 ofw_bus_gen_get_name(device_t bus, device_t dev)
100 const struct ofw_bus_devinfo *obd;
102 obd = OFW_BUS_GET_DEVINFO(bus, dev);
105 return (obd->obd_name);
109 ofw_bus_gen_get_node(device_t bus, device_t dev)
111 const struct ofw_bus_devinfo *obd;
113 obd = OFW_BUS_GET_DEVINFO(bus, dev);
116 return (obd->obd_node);
120 ofw_bus_gen_get_type(device_t bus, device_t dev)
122 const struct ofw_bus_devinfo *obd;
124 obd = OFW_BUS_GET_DEVINFO(bus, dev);
127 return (obd->obd_type);