This version of this document is no longer maintained. For the latest documentation, see http://www.qnx.com/developers/docs. |
Reserve a system resource for a process
#include <sys/rsrcdbmgr.h> #include <sys/rsrcdbmsg.h> int rsrcdbmgr_attach( rsrc_request_t * list, int count );
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The resource database manager allocates and keeps track of system resources i.e. it manages these resources. The system resources currently tracked are:
Major and minor device numbers are handled with separate rsrcdbmgr_devno_attach() and rsrcdbmgr_devno_detach() functions.
There are two main functions that drivers can use to communicate with the resource database:
The rsrcdbmgr_attach() function reserves a resource range(s) from the database of available resources for a process. Other processes can't reserve this resource range until the resource is returned to the system (usually with the rsrcdbmgr_detach() call). The requested resources are returned in a list of _rsrc_request structures with the start and end fields filled in. The number of resources requested is specified in count.
Reserving the resources doesn't give you access to them; you still have to use mmap(), InterruptAttach(), or another means. |
When you're finished with the resource, you must return it to the system. The easiest way to return the resource is to call rsrcdbmgr_detach() with the same start, end, and type (via the flags field) that were issued for the resource.
The resource requests structure looks like this:
typedef struct _rsrc_request { uint64_t length; uint64_t align; uint64_t start; uint64_t end; uint32_t flags; uint32_t zero[3]; /* Reserved */ } rsrc_request_t;
The members include:
You can OR in the following flags (also defined in <sys/rsrcdbmgr.h>):
EOK, or -1 if an error occurred (errno is set).
When you start the system, the startup code and special programs that know how to probe the hardware call rsrcdbmgr_create() to register the hardware in the resource database. The following examples don't do this seeding, so they'll fail with an error code of EINVAL. |
/* * Request one DMA Channel, with length 1, from the * entire range of available DMA channel resources. */ #include <stdio.h> #include <sys/rsrcdbmgr.h> #include <sys/rsrcdbmsg.h> int main(int argc, char **argv) { int count; rsrc_request_t req; memset(&req, 0, sizeof(req)); req.length = 1; req.flags = RSRCDBMGR_DMA_CHANNEL; count = 1; if (rsrcdbmgr_attach( &req, count) == -1) { perror("Problem attaching to resource "); exit(1); } printf("You can use DMA channel 0x%llx \n", req.start); ... /* Do something with the acquired resource */ ... /* To return the resource to the database: */ if (rsrcdbmgr_detach( &req, count) == -1) { perror("Problem detaching resource \n"); exit(1); } return(0); }
/* * Request memory that's 4-byte aligned * and has a length of 50. */ #include <stdio.h> #include <sys/rsrcdbmgr.h> #include <sys/rsrcdbmsg.h> int main(int argc, char **argv) { int count; rsrc_request_t req; memset(&req, 0, sizeof(req)); req.align = 4; req.length = 50; req.flags = RSRCDBMGR_FLAG_ALIGN | RSRCDBMGR_MEMORY; count = 1; if (rsrcdbmgr_attach(&req, count) == -1) { perror("Problem attaching to resource "); exit(1); } printf("You can use memory from 0x%llx 0x%llx inclusive. \n", req.start, req.end ); ... /* Do something with the acquired resource */ ... /* To return the resource to the database: */ if (rsrcdbmgr_detach( &req, count) == -1) { perror("Problem detaching resource \n"); exit(1); } return(0); }
/* * Request two resources: * I/O port 0 and an IRQ in the range 10-12 * from the available resources. */ #include <stdio.h> #include <sys/rsrcdbmgr.h> #include <sys/rsrcdbmsg.h> int main(int argc, char **argv) { int count; rsrc_request_t req[2]; memset(req, 0, 2*sizeof(*req)); req[0].start = 0; req[0].end = 0; req[0].length = 1; req[0].flags = RSRCDBMGR_FLAG_RANGE | RSRCDBMGR_IO_PORT; req[1].start = 10; req[1].end = 12; req[1].length = 1; req[1].flags = RSRCDBMGR_FLAG_RANGE | RSRCDBMGR_IRQ; count = 2; if (rsrcdbmgr_attach(req, count) == -1) { perror("Problem attaching to resource "); exit(1); } printf("You can use io-port 0x%llx \n", req[0].start); printf("You can use irq 0x%llx \n", req[1].start); ... /* Do something with the acquired resource */ ... /* To return the resource to the database: */ if (rsrcdbmgr_detach(req, count) == -1) { perror("Problem detaching resource \n"); exit(1); } return(0); }
Safety: | |
---|---|
Cancellation point | Yes |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |
rsrcdbmgr_create(), rsrcdbmgr_detach(), rsrcdbmgr_destroy(), rsrcdbmgr_devno_attach(), rsrcdbmgr_devno_detach(), rsrcdbmgr_query()