Requesting Resources

The kernel provides the_request_resource function to request a resource area.17 The function expects a series of parameters including a pointer to the parent element, the start and end address of the resource area, and a string to hold the name of the area.

kernel/resource.c static struct resource * request_resource(struct resource *root, struct resource *new);

The purpose of the function is to allocate a request instance and fill it with the data passed. Checks are also performed to detect obvious errors (start address bigger than the end address, for example) that would render the request useless and would abort the action. request_resource is responsible only for the requisite locking. The heavy work is delegated to_request_resource. It scans the existing resources consecutively to add the new resource at the correct position or to reveal conflicts with areas already allocated. It does this by running through the list of siblings. The new resource instance is inserted if the required resource area is free, thus reserving the resource. Reservation fails if the area is not free.

The children of a specific parent are scanned on one sibling level only. The kernel does not scan the list of children downward.

If a resource cannot be reserved, the driver automatically knows that it is already in use and is therefore not available at the moment.

Continue reading here: Releasing Resources

Was this article helpful?

0 0