MCPcopy Create free account
hub / github.com/F-Stack/f-stack / nexus_alloc_resource

Function nexus_alloc_resource

freebsd/mips/mips/nexus.c:278–345  ·  view source on GitHub ↗

* 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.) */

Source from the content-addressed store, hash-verified

276 * (Exceptions include footbridge.)
277 */
278static struct resource *
279nexus_alloc_resource(device_t bus, device_t child, int type, int *rid,
280 rman_res_t start, rman_res_t end, rman_res_t count, u_int flags)
281{
282 struct nexus_device *ndev = DEVTONX(child);
283 struct resource *rv;
284 struct resource_list_entry *rle;
285 struct rman *rm;
286 int isdefault, needactivate, passthrough;
287
288 dprintf("%s: entry (%p, %p, %d, %p, %p, %p, %jd, %d)\n",
289 __func__, bus, child, type, rid, (void *)(intptr_t)start,
290 (void *)(intptr_t)end, count, flags);
291 dprintf("%s: requested rid is %d\n", __func__, *rid);
292
293 isdefault = (RMAN_IS_DEFAULT_RANGE(start, end) && count == 1);
294 needactivate = flags & RF_ACTIVE;
295 passthrough = (device_get_parent(child) != bus);
296 rle = NULL;
297
298 /*
299 * If this is an allocation of the "default" range for a given RID,
300 * and we know what the resources for this device are (ie. they aren't
301 * maintained by a child bus), then work out the start/end values.
302 */
303 if (!passthrough && isdefault) {
304 rle = resource_list_find(&ndev->nx_resources, type, *rid);
305 if (rle == NULL)
306 return (NULL);
307 if (rle->res != NULL) {
308 panic("%s: resource entry is busy", __func__);
309 }
310 start = rle->start;
311 end = rle->end;
312 count = rle->count;
313 }
314
315 switch (type) {
316 case SYS_RES_IRQ:
317 rm = &irq_rman;
318 break;
319 case SYS_RES_MEMORY:
320 rm = &mem_rman;
321 break;
322 default:
323 printf("%s: unknown resource type %d\n", __func__, type);
324 return (0);
325 }
326
327 rv = rman_reserve_resource(rm, start, end, count, flags, child);
328 if (rv == NULL) {
329 printf("%s: could not reserve resource for %s\n", __func__,
330 device_get_nameunit(child));
331 return (0);
332 }
333
334 rman_set_rid(rv, *rid);
335

Callers

nothing calls this directly

Calls 9

device_get_parentFunction · 0.85
resource_list_findFunction · 0.85
rman_reserve_resourceFunction · 0.85
device_get_nameunitFunction · 0.85
rman_set_ridFunction · 0.85
bus_activate_resourceFunction · 0.85
rman_release_resourceFunction · 0.85
panicFunction · 0.50
printfFunction · 0.50

Tested by

no test coverage detected