[Previous] [Contents] [Next]

rsrcdbmgr_create()

Create a system resource

Synopsis:

#include <sys/rsrcdbmgr.h>
#include <sys/rsrcdbmsg.h>

int rsrcdbmgr_create( rsrc_alloc_t *item,
                      int count );

Library:

libc

Description:

The rsrcdbmgr_create() function creates one or more system resources. If the function completes successfully, count resources are returned in item.

The structure of a basic resource request looks like this:

typedef struct _rsrc_alloc {
   uint64_t   start;   /* Start of resource range */
   uint64_t   end;     /* End of resource range */
   uint32_t   flags;   /* Resource type | Resource flags */
} rsrc_alloc_t;

You must specify all fields.

Resource types

Valid resource types (defined in <sys/rsrcdbmgr.h>) are:

RSRCDBMGR_DMA_CHANNEL
DMA channel
RSRMGR_IO_PORT
I/O port address
RSRCMGR_IRQ or RSRCDBMGR_IRQ
interrupt address
RSRCDBMGR_MEMORY
memory address
RSRCDBMGR_PCI_MEMORY
PCI memory address

Flags

Valid flags (defined in <sys/rsrcdbmgr.h>) are:

RSRCDBMGR_FLAG_RSVP
Creates and reserves a resource with a higher priority than other resources. The resource is only given out when there are no other valid ranges available.

Returns:

EOK, or -1 if an error occurred (errno is set).

Errors:

EAGAIN
The resource request can't be created.
EINVAL
Invalid argument.
ENOMEM
Insufficient memory to allocate internal data structures.

Examples:

/*
 * Create two resources:
 * 0-4K memory allocation and 5 DMA channels.
 */
#include <stdio.h>
#include <sys/rsrcdbmgr.h>
#include <sys/rsrcdbmsg.h>

int main(int argc, char **argv) {
	rsrc_alloc_t alloc[2];

	memset(alloc, 0, 2* sizeof(*alloc));
	alloc[0].start = 0;
	alloc[0].end = 4*1024; 
	alloc[0].flags = RSRCDBMGR_MEMORY;

	alloc[1].start = 1;
	alloc[1].end = 5;
	alloc[1].flags = RSRCDBMGR_DMA_CHANNEL;

	/* Allocate resources to the system. */
	if (rsrcdbmgr_create( alloc, 2 ) == -1) {
		perror("Problem creating resources \n");
		exit(1);
	}

    ...
	/* Do something with the created resource */
    ...

	/* Remove the allocated resources. */
	rsrcdbmgr_destroy ( alloc, 2 );

	return(0);
}

Classification:

QNX 6

Safety:
Cancellation point Yes
Interrupt handler No
Signal handler Yes
Thread Yes

See also:

rsrcdbmgr_attach(), rsrcdbmgr_destroy()


[Previous] [Contents] [Next]