rsrcdbmgr_create()

Updated: April 19, 2023

Create a system resource

Synopsis:

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

int rsrcdbmgr_create( rsrc_alloc_t *item,
                      int count );

Arguments:

item
An array of rsrc_alloc_t structures that describe the resources that you want to create; see below.
count
The number of entries in the array.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The rsrcdbmgr_create() function creates the system resources specified in the item array.

Note: In order to successfully use the rsrcdbmgr_*() functions to modify the resource database, your process must have the PROCMGR_AID_RSRCDBMGR ability enabled. For more information, see procmgr_ability().

rsrc_alloc_t structure

The structure of a basic resource request looks like this:

typedef struct _rsrc_alloc {
	uint64_t	start;
	uint64_t	end;
	uint32_t	flags;
	const char	*name;
} rsrc_alloc_t;

The members include:

start, end
The resource range.
flags
The type of the resource, as well as flags that affect the request. You must set this member to be one of the following resource types (defined in <sys/rsrcdbmgr.h>):
  • RSRCDBMGR_DMA_CHANNEL — DMA channel
  • RSRCDBMGR_IO_PORT — I/O port address
  • RSRCDBMGR_IRQ — interrupt address
  • RSRCDBMGR_MEMORY — Memory address
  • RSRCDBMGR_PCI_MEMORY — PCI memory address

You can OR in the following bits (also defined in <sys/rsrcdbmgr.h>):

  • RSRCDBMGR_FLAG_NAME — the name field is valid, and is a system name.
  • RSRCDBMGR_FLAG_NOREMOVE — don't remove this resource when the process dies.
  • RSRCDBMGR_FLAG_RSVP — create and reserve a resource with a higher priority than other resources. The resource is given out only when there are no other valid ranges available.
name
NULL, or a pointer to the name of the resource class. This field is used only if you set RSRCDBMGR_FLAG_NAME in the flags field. For more information, see rsrcdbmgr_attach().

You must set all the members.

Returns:

0 on success, or -1 if an error occurred (errno is set).

Errors:

EAGAIN
The resource request can't be created.
EINTR
The call was interrupted by a signal.
EINVAL
Invalid argument.
ENOMEM
Insufficient memory to allocate internal data structures.
EPERM
The calling process doesn't have the required permission; see procmgr_ability().

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 Neutrino

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