ofw_bus_subr.c (186728) | ofw_bus_subr.c (194138) |
---|---|
1/*- 2 * Copyright (c) 2001 - 2003 by Thomas Moestl <tmm@FreeBSD.org>. 3 * Copyright (c) 2005 Marius Strobl <marius@FreeBSD.org> 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 14 unchanged lines hidden (view full) --- 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2001 - 2003 by Thomas Moestl <tmm@FreeBSD.org>. 3 * Copyright (c) 2005 Marius Strobl <marius@FreeBSD.org> 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 14 unchanged lines hidden (view full) --- 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30#include <sys/cdefs.h> |
31__FBSDID("$FreeBSD: head/sys/dev/ofw/ofw_bus_subr.c 186728 2009-01-03 19:38:47Z nwhitehorn $"); | 31__FBSDID("$FreeBSD: head/sys/dev/ofw/ofw_bus_subr.c 194138 2009-06-14 00:05:38Z marius $"); |
32 33#include <sys/param.h> 34#include <sys/systm.h> 35#include <sys/bus.h> 36#include <sys/errno.h> 37#include <sys/libkern.h> 38 39#include <dev/ofw/ofw_bus.h> --- 29 unchanged lines hidden (view full) --- 69 if (obd->obd_model != NULL) 70 free(obd->obd_model, M_OFWPROP); 71 if (obd->obd_name != NULL) 72 free(obd->obd_name, M_OFWPROP); 73 if (obd->obd_type != NULL) 74 free(obd->obd_type, M_OFWPROP); 75} 76 | 32 33#include <sys/param.h> 34#include <sys/systm.h> 35#include <sys/bus.h> 36#include <sys/errno.h> 37#include <sys/libkern.h> 38 39#include <dev/ofw/ofw_bus.h> --- 29 unchanged lines hidden (view full) --- 69 if (obd->obd_model != NULL) 70 free(obd->obd_model, M_OFWPROP); 71 if (obd->obd_name != NULL) 72 free(obd->obd_name, M_OFWPROP); 73 if (obd->obd_type != NULL) 74 free(obd->obd_type, M_OFWPROP); 75} 76 |
77int | 77int |
78ofw_bus_gen_child_pnpinfo_str(device_t cbdev, device_t child, char *buf, 79 size_t buflen) 80{ | 78ofw_bus_gen_child_pnpinfo_str(device_t cbdev, device_t child, char *buf, 79 size_t buflen) 80{ |
81 |
|
81 if (ofw_bus_get_name(child) != NULL) { 82 strlcat(buf, "name=", buflen); 83 strlcat(buf, ofw_bus_get_name(child), buflen); 84 } 85 86 if (ofw_bus_get_compat(child) != NULL) { 87 strlcat(buf, " compat=", buflen); 88 strlcat(buf, ofw_bus_get_compat(child), buflen); 89 } | 82 if (ofw_bus_get_name(child) != NULL) { 83 strlcat(buf, "name=", buflen); 84 strlcat(buf, ofw_bus_get_name(child), buflen); 85 } 86 87 if (ofw_bus_get_compat(child) != NULL) { 88 strlcat(buf, " compat=", buflen); 89 strlcat(buf, ofw_bus_get_compat(child), buflen); 90 } |
90 | |
91 return (0); 92}; 93 94const char * 95ofw_bus_gen_get_compat(device_t bus, device_t dev) 96{ 97 const struct ofw_bus_devinfo *obd; | 91 return (0); 92}; 93 94const char * 95ofw_bus_gen_get_compat(device_t bus, device_t dev) 96{ 97 const struct ofw_bus_devinfo *obd; |
98 99 obd = OFW_BUS_GET_DEVINFO(bus, dev); | 98 99 obd = OFW_BUS_GET_DEVINFO(bus, dev); |
100 if (obd == NULL) 101 return (NULL); 102 return (obd->obd_compat); 103} | 100 if (obd == NULL) 101 return (NULL); 102 return (obd->obd_compat); 103} |
104 | 104 |
105const char * 106ofw_bus_gen_get_model(device_t bus, device_t dev) 107{ 108 const struct ofw_bus_devinfo *obd; 109 | 105const char * 106ofw_bus_gen_get_model(device_t bus, device_t dev) 107{ 108 const struct ofw_bus_devinfo *obd; 109 |
110 obd = OFW_BUS_GET_DEVINFO(bus, dev); | 110 obd = OFW_BUS_GET_DEVINFO(bus, dev); |
111 if (obd == NULL) 112 return (NULL); 113 return (obd->obd_model); 114} 115 116const char * 117ofw_bus_gen_get_name(device_t bus, device_t dev) 118{ 119 const struct ofw_bus_devinfo *obd; 120 | 111 if (obd == NULL) 112 return (NULL); 113 return (obd->obd_model); 114} 115 116const char * 117ofw_bus_gen_get_name(device_t bus, device_t dev) 118{ 119 const struct ofw_bus_devinfo *obd; 120 |
121 obd = OFW_BUS_GET_DEVINFO(bus, dev); | 121 obd = OFW_BUS_GET_DEVINFO(bus, dev); |
122 if (obd == NULL) 123 return (NULL); 124 return (obd->obd_name); 125} 126 127phandle_t 128ofw_bus_gen_get_node(device_t bus, device_t dev) 129{ 130 const struct ofw_bus_devinfo *obd; 131 | 122 if (obd == NULL) 123 return (NULL); 124 return (obd->obd_name); 125} 126 127phandle_t 128ofw_bus_gen_get_node(device_t bus, device_t dev) 129{ 130 const struct ofw_bus_devinfo *obd; 131 |
132 obd = OFW_BUS_GET_DEVINFO(bus, dev); | 132 obd = OFW_BUS_GET_DEVINFO(bus, dev); |
133 if (obd == NULL) 134 return (0); 135 return (obd->obd_node); 136} 137 138const char * 139ofw_bus_gen_get_type(device_t bus, device_t dev) 140{ 141 const struct ofw_bus_devinfo *obd; 142 | 133 if (obd == NULL) 134 return (0); 135 return (obd->obd_node); 136} 137 138const char * 139ofw_bus_gen_get_type(device_t bus, device_t dev) 140{ 141 const struct ofw_bus_devinfo *obd; 142 |
143 obd = OFW_BUS_GET_DEVINFO(bus, dev); | 143 obd = OFW_BUS_GET_DEVINFO(bus, dev); |
144 if (obd == NULL) 145 return (NULL); 146 return (obd->obd_type); 147} 148 149void 150ofw_bus_setup_iinfo(phandle_t node, struct ofw_bus_iinfo *ii, int intrsz) 151{ --- 5 unchanged lines hidden (view full) --- 157 ii->opi_addrc = addrc * sizeof(pcell_t); 158 159 ii->opi_imapsz = OF_getprop_alloc(node, "interrupt-map", 1, 160 (void **)&ii->opi_imap); 161 if (ii->opi_imapsz > 0) { 162 msksz = OF_getprop_alloc(node, "interrupt-map-mask", 1, 163 (void **)&ii->opi_imapmsk); 164 /* | 144 if (obd == NULL) 145 return (NULL); 146 return (obd->obd_type); 147} 148 149void 150ofw_bus_setup_iinfo(phandle_t node, struct ofw_bus_iinfo *ii, int intrsz) 151{ --- 5 unchanged lines hidden (view full) --- 157 ii->opi_addrc = addrc * sizeof(pcell_t); 158 159 ii->opi_imapsz = OF_getprop_alloc(node, "interrupt-map", 1, 160 (void **)&ii->opi_imap); 161 if (ii->opi_imapsz > 0) { 162 msksz = OF_getprop_alloc(node, "interrupt-map-mask", 1, 163 (void **)&ii->opi_imapmsk); 164 /* |
165 * Failure to get the mask is ignored; a full mask is used then. 166 * Barf on bad mask sizes, however. | 165 * Failure to get the mask is ignored; a full mask is used 166 * then. We barf on bad mask sizes, however. |
167 */ | 167 */ |
168 if (msksz != -1 && msksz != ii->opi_addrc + intrsz) { | 168 if (msksz != -1 && msksz != ii->opi_addrc + intrsz) |
169 panic("ofw_bus_setup_iinfo: bad interrupt-map-mask " 170 "property!"); | 169 panic("ofw_bus_setup_iinfo: bad interrupt-map-mask " 170 "property!"); |
171 } | |
172 } | 171 } |
173 | |
174} 175 176int 177ofw_bus_lookup_imap(phandle_t node, struct ofw_bus_iinfo *ii, void *reg, 178 int regsz, void *pintr, int pintrsz, void *mintr, int mintrsz, 179 void *maskbuf) 180{ 181 int rv; --- 10 unchanged lines hidden (view full) --- 192 ii->opi_imap, ii->opi_imapsz, ii->opi_imapmsk, maskbuf, mintr, 193 mintrsz)); 194} 195 196/* 197 * Map an interrupt using the firmware reg, interrupt-map and 198 * interrupt-map-mask properties. 199 * The interrupt property to be mapped must be of size intrsz, and pointed to | 172} 173 174int 175ofw_bus_lookup_imap(phandle_t node, struct ofw_bus_iinfo *ii, void *reg, 176 int regsz, void *pintr, int pintrsz, void *mintr, int mintrsz, 177 void *maskbuf) 178{ 179 int rv; --- 10 unchanged lines hidden (view full) --- 190 ii->opi_imap, ii->opi_imapsz, ii->opi_imapmsk, maskbuf, mintr, 191 mintrsz)); 192} 193 194/* 195 * Map an interrupt using the firmware reg, interrupt-map and 196 * interrupt-map-mask properties. 197 * The interrupt property to be mapped must be of size intrsz, and pointed to |
200 * by intr. The regs property of the node for which the mapping is done must | 198 * by intr. The regs property of the node for which the mapping is done must |
201 * be passed as regs. This property is an array of register specifications; 202 * the size of the address part of such a specification must be passed as | 199 * be passed as regs. This property is an array of register specifications; 200 * the size of the address part of such a specification must be passed as |
203 * physsz. Only the first element of the property is used. | 201 * physsz. Only the first element of the property is used. |
204 * imap and imapsz hold the interrupt mask and it's size. 205 * imapmsk is a pointer to the interrupt-map-mask property, which must have 206 * a size of physsz + intrsz; it may be NULL, in which case a full mask is 207 * assumed. 208 * maskbuf must point to a buffer of length physsz + intrsz. 209 * The interrupt is returned in result, which must point to a buffer of length 210 * rintrsz (which gives the expected size of the mapped interrupt). 211 * Returns 1 if a mapping was found, 0 otherwise. 212 */ 213int 214ofw_bus_search_intrmap(void *intr, int intrsz, void *regs, int physsz, 215 void *imap, int imapsz, void *imapmsk, void *maskbuf, void *result, 216 int rintrsz) 217{ 218 phandle_t parent; | 202 * imap and imapsz hold the interrupt mask and it's size. 203 * imapmsk is a pointer to the interrupt-map-mask property, which must have 204 * a size of physsz + intrsz; it may be NULL, in which case a full mask is 205 * assumed. 206 * maskbuf must point to a buffer of length physsz + intrsz. 207 * The interrupt is returned in result, which must point to a buffer of length 208 * rintrsz (which gives the expected size of the mapped interrupt). 209 * Returns 1 if a mapping was found, 0 otherwise. 210 */ 211int 212ofw_bus_search_intrmap(void *intr, int intrsz, void *regs, int physsz, 213 void *imap, int imapsz, void *imapmsk, void *maskbuf, void *result, 214 int rintrsz) 215{ 216 phandle_t parent; |
219 u_int8_t *ref = maskbuf; 220 u_int8_t *uiintr = intr; 221 u_int8_t *uiregs = regs; 222 u_int8_t *uiimapmsk = imapmsk; 223 u_int8_t *mptr; | 217 uint8_t *ref = maskbuf; 218 uint8_t *uiintr = intr; 219 uint8_t *uiregs = regs; 220 uint8_t *uiimapmsk = imapmsk; 221 uint8_t *mptr; |
224 pcell_t pintrsz; 225 int i, rsz, tsz; 226 227 rsz = -1; 228 if (imapmsk != NULL) { 229 for (i = 0; i < physsz; i++) 230 ref[i] = uiregs[i] & uiimapmsk[i]; 231 for (i = 0; i < intrsz; i++) --- 7 unchanged lines hidden (view full) --- 239 i = imapsz; 240 while (i > 0) { 241 bcopy(mptr + physsz + intrsz, &parent, sizeof(parent)); 242 if (OF_searchprop(parent, "#interrupt-cells", 243 &pintrsz, sizeof(pintrsz)) == -1) 244 pintrsz = 1; /* default */ 245 pintrsz *= sizeof(pcell_t); 246 | 222 pcell_t pintrsz; 223 int i, rsz, tsz; 224 225 rsz = -1; 226 if (imapmsk != NULL) { 227 for (i = 0; i < physsz; i++) 228 ref[i] = uiregs[i] & uiimapmsk[i]; 229 for (i = 0; i < intrsz; i++) --- 7 unchanged lines hidden (view full) --- 237 i = imapsz; 238 while (i > 0) { 239 bcopy(mptr + physsz + intrsz, &parent, sizeof(parent)); 240 if (OF_searchprop(parent, "#interrupt-cells", 241 &pintrsz, sizeof(pintrsz)) == -1) 242 pintrsz = 1; /* default */ 243 pintrsz *= sizeof(pcell_t); 244 |
247 /* Compute the map stride size */ | 245 /* Compute the map stride size. */ |
248 tsz = physsz + intrsz + sizeof(phandle_t) + pintrsz; 249 KASSERT(i >= tsz, ("ofw_bus_search_intrmap: truncated map")); | 246 tsz = physsz + intrsz + sizeof(phandle_t) + pintrsz; 247 KASSERT(i >= tsz, ("ofw_bus_search_intrmap: truncated map")); |
250 | 248 |
251 /* 252 * XXX: Apple hardware uses a second cell to set information | 249 /* 250 * XXX: Apple hardware uses a second cell to set information |
253 * on the interrupt trigger type. This information should | 251 * on the interrupt trigger type. This information should |
254 * be used somewhere to program the PIC. 255 */ 256 257 if (bcmp(ref, mptr, physsz + intrsz) == 0) { 258 bcopy(mptr + physsz + intrsz + sizeof(parent), 259 result, rintrsz); 260 return (1); 261 } 262 mptr += tsz; 263 i -= tsz; 264 } 265 return (0); 266} | 252 * be used somewhere to program the PIC. 253 */ 254 255 if (bcmp(ref, mptr, physsz + intrsz) == 0) { 256 bcopy(mptr + physsz + intrsz + sizeof(parent), 257 result, rintrsz); 258 return (1); 259 } 260 mptr += tsz; 261 i -= tsz; 262 } 263 return (0); 264} |