1 /*- 2 * Copyright (c) 2005 Marius Strobl <marius@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 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 14 * distribution. 15 * 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 26 * SUCH DAMAGE. 27 */ 28 29 #include <sys/cdefs.h> 30 __FBSDID("$FreeBSD$"); 31 32 #include <sys/param.h> 33 #include <sys/systm.h> 34 #include <sys/bus.h> 35 #include <sys/errno.h> 36 37 #include <dev/ofw/ofw_bus_subr.h> 38 #include <dev/ofw/openfirm.h> 39 40 #include "ofw_bus_if.h" 41 42 int 43 ofw_bus_gen_setup_devinfo(struct ofw_bus_devinfo *obd, phandle_t node) 44 { 45 46 if (obd == NULL) 47 return (ENOMEM); 48 /* The 'name' property is considered mandatory. */ 49 if ((OF_getprop_alloc(node, "name", 1, (void **)&obd->obd_name)) == -1) 50 return (EINVAL); 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); 54 obd->obd_node = node; 55 return (0); 56 } 57 58 void 59 ofw_bus_gen_destroy_devinfo(struct ofw_bus_devinfo *obd) 60 { 61 62 if (obd == NULL) 63 return; 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); 72 } 73 74 75 const char * 76 ofw_bus_gen_get_compat(device_t bus, device_t dev) 77 { 78 const struct ofw_bus_devinfo *obd; 79 80 obd = OFW_BUS_GET_DEVINFO(bus, dev); 81 if (obd == NULL) 82 return (NULL); 83 return (obd->obd_compat); 84 } 85 86 const char * 87 ofw_bus_gen_get_model(device_t bus, device_t dev) 88 { 89 const struct ofw_bus_devinfo *obd; 90 91 obd = OFW_BUS_GET_DEVINFO(bus, dev); 92 if (obd == NULL) 93 return (NULL); 94 return (obd->obd_model); 95 } 96 97 const char * 98 ofw_bus_gen_get_name(device_t bus, device_t dev) 99 { 100 const struct ofw_bus_devinfo *obd; 101 102 obd = OFW_BUS_GET_DEVINFO(bus, dev); 103 if (obd == NULL) 104 return (NULL); 105 return (obd->obd_name); 106 } 107 108 phandle_t 109 ofw_bus_gen_get_node(device_t bus, device_t dev) 110 { 111 const struct ofw_bus_devinfo *obd; 112 113 obd = OFW_BUS_GET_DEVINFO(bus, dev); 114 if (obd == NULL) 115 return (0); 116 return (obd->obd_node); 117 } 118 119 const char * 120 ofw_bus_gen_get_type(device_t bus, device_t dev) 121 { 122 const struct ofw_bus_devinfo *obd; 123 124 obd = OFW_BUS_GET_DEVINFO(bus, dev); 125 if (obd == NULL) 126 return (NULL); 127 return (obd->obd_type); 128 } 129