* Allocate a resource on behalf of child. NB: child is usually going to be a * child of one of our descendants, not a direct child of nexus0. * (Exceptions include footbridge.) */
| 215 | * (Exceptions include footbridge.) |
| 216 | */ |
| 217 | static struct resource * |
| 218 | nexus_alloc_resource(device_t bus, device_t child, int type, int *rid, |
| 219 | rman_res_t start, rman_res_t end, rman_res_t count, u_int flags) |
| 220 | { |
| 221 | struct nexus_device *ndev = DEVTONX(child); |
| 222 | struct resource *rv; |
| 223 | struct resource_list_entry *rle; |
| 224 | struct rman *rm; |
| 225 | int needactivate = flags & RF_ACTIVE; |
| 226 | |
| 227 | /* |
| 228 | * If this is an allocation of the "default" range for a given |
| 229 | * RID, and we know what the resources for this device are |
| 230 | * (ie. they aren't maintained by a child bus), then work out |
| 231 | * the start/end values. |
| 232 | */ |
| 233 | if (RMAN_IS_DEFAULT_RANGE(start, end) && (count == 1)) { |
| 234 | if (device_get_parent(child) != bus || ndev == NULL) |
| 235 | return(NULL); |
| 236 | rle = resource_list_find(&ndev->nx_resources, type, *rid); |
| 237 | if (rle == NULL) |
| 238 | return(NULL); |
| 239 | start = rle->start; |
| 240 | end = rle->end; |
| 241 | count = rle->count; |
| 242 | } |
| 243 | |
| 244 | switch (type) { |
| 245 | case SYS_RES_IRQ: |
| 246 | rm = &irq_rman; |
| 247 | break; |
| 248 | |
| 249 | case SYS_RES_MEMORY: |
| 250 | case SYS_RES_IOPORT: |
| 251 | rm = &mem_rman; |
| 252 | break; |
| 253 | |
| 254 | default: |
| 255 | return (NULL); |
| 256 | } |
| 257 | |
| 258 | rv = rman_reserve_resource(rm, start, end, count, flags, child); |
| 259 | if (rv == NULL) |
| 260 | return (NULL); |
| 261 | |
| 262 | rman_set_rid(rv, *rid); |
| 263 | rman_set_bushandle(rv, rman_get_start(rv)); |
| 264 | |
| 265 | if (needactivate) { |
| 266 | if (bus_activate_resource(child, type, *rid, rv)) { |
| 267 | rman_release_resource(rv); |
| 268 | return (NULL); |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | return (rv); |
| 273 | } |
| 274 |
nothing calls this directly
no test coverage detected