GVM User Suite
User tools for the GVM open source project.
Macros | Functions
api.h File Reference
#include <stdio.h>
#include <stdint.h>
#include <gpu/nvidia/resources.h>
Include dependency graph for api.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define RM_CTRL(fd, res, cmd, data)   rm_ctrl_res(fd, res->client, res->object, cmd, &data, sizeof(data))
 Controls a RM Resource. More...
 
#define _RM_CTRL(fd, client, object, cmd, data)   rm_ctrl_res(fd, client, object, cmd, &data, sizeof(data))
 Controls a RM Resource. More...
 

Functions

uint8_t rm_version_check (int ctl_fd, uint8_t ignore_version, const char *version)
 Version check for the RM API. More...
 
struct NvResourcerm_alloc_res (int fd, struct NvResource *parent, uint32_t object, uint32_t rm_class, void *data)
 Allocates a Node for a resource. More...
 
uint8_t rm_free_res (int fd, struct NvResource *object)
 Frees a Node for a Resource. More...
 
void rm_free_tree (int fd, struct NvResource *root)
 Frees a resource tree for the system. More...
 
uint8_t rm_alloc_os_event (int fd, uint32_t client_id, uint32_t device_id)
 Allocates an Operating System Event. More...
 
void * rm_ctrl_res (int fd, uint32_t client, uint32_t device, uint32_t command, void *data, uint32_t size)
 Control resource command. More...
 

Macro Definition Documentation

◆ _RM_CTRL

#define _RM_CTRL (   fd,
  client,
  object,
  cmd,
  data 
)    rm_ctrl_res(fd, client, object, cmd, &data, sizeof(data))

Controls a RM Resource.

This is a macro to simplify code for controlling resources.

Side Effect:
Macro for rm_ctrl_res
Parameters
fd- File for controlling object on.
client- Client id.
object- Object id.
cmd- Command to run.
data- Data to use.
Returns
Pointer to the command data, NULL in terms of failure.

Definition at line 148 of file api.h.

◆ RM_CTRL

#define RM_CTRL (   fd,
  res,
  cmd,
  data 
)    rm_ctrl_res(fd, res->client, res->object, cmd, &data, sizeof(data))

Controls a RM Resource.

This is a macro to simplify code for controlling resources.

Side Effect:
Macro for rm_ctrl_res
Parameters
fd- File for controlling object on.
res- Resource pointer.
cmd- Command to run.
data- Data to use.
Returns
Pointer to the command data, NULL in terms of failure.

Definition at line 133 of file api.h.

Function Documentation

◆ rm_alloc_os_event()

uint8_t rm_alloc_os_event ( int  fd,
uint32_t  client_id,
uint32_t  device_id 
)

Allocates an Operating System Event.

This is how we can create an operating system event.

Parameters
fd- File descriptor to allocate on the OS.
client_id- Client ID.
device_id- Device ID.
Returns
Allocated an operating system event.
Todo:
Proper logging if a failure occurs.

Definition at line 208 of file api.c.

Here is the caller graph for this function:

◆ rm_alloc_res()

struct NvResource* rm_alloc_res ( int  fd,
struct NvResource parent,
uint32_t  object,
uint32_t  rm_class,
void *  data 
)

Allocates a Node for a resource.

The RM Core uses an object oriented paradigm which forces us to create nodes and pass them into new regions.

Side Effect:

RM Side Effect: Allocates an object with a specific class in the RM Core, for safety purposes we should call a free res for all resources available on the system. However it is not strictly necessary as there is a garbage collector inside the RM Core.

State Side Effect: Parent node is modified, to have a new child.

Parameters
fd- File for allocating the device on.
parent- Parent node to allocate the device on.
object- Object id.
rm_class- Class of the new object.
data- Pointer for allocation data.
Returns
New object resource, or NULL in a case of a failure.
Possible Failures:

Invalid File Descriptor - Occurs when fd is -1.

Incorrect File Descriptor - Occurs when fd is an incorrect descriptor.

Todo:
Inform user of status error if there is an error.

Definition at line 65 of file api.c.

Here is the caller graph for this function:

◆ rm_ctrl_res()

void* rm_ctrl_res ( int  fd,
uint32_t  client,
uint32_t  device,
uint32_t  command,
void *  data,
uint32_t  size 
)

Control resource command.

The RM Core uses an object oriented paradigm which forces us to use this generic function to apply methods onto the node in question. This specifically is a method application call for an arbitrary resource.

Side Effect:

RM Side Effect: Performs a potentially unsafe method on an object in the kernel.

Log Side Effect: Logs incorrect information.

Parameters
fd- File for controlling object on.
client- Client id to use.
device- Object id to use.
command- Command to use on the object.
data- Command data.
size- Size of the data.
Returns
Pointer to the command data, NULL in terms of failure.
Possible Failures:

Invalid File Descriptor - Occurs when fd is -1.

Incorrect File Descriptor - Occurs when the fd is an incorrect file descriptor.

RM Failure - Occurs when incorrect information is placed.

Todo:
Update to use proper logging mechanism (ERROR).

Definition at line 164 of file api.c.

Here is the caller graph for this function:

◆ rm_free_res()

uint8_t rm_free_res ( int  fd,
struct NvResource object 
)

Frees a Node for a Resource.

The RM Core uses an object oriented paradigm which forces us to free nodes when we are finished. This specifically is a deconstructor call for an arbitrary resource.

Side Effect:
RM Side Effect: Deallocates an object with a specific id in the RM Core.
Parameters
fd- File for deallocating the device on.
object- Object we are deallocating.
Returns
Boolean value if we could free or not free the object in question.
Possible Failures:

Invalid File Descriptor - Occurs when fd is -1.

Incorrect File Descriptor - Occurs when the fd is an incorrect file descriptor.

Definition at line 124 of file api.c.

Here is the caller graph for this function:

◆ rm_free_tree()

void rm_free_tree ( int  fd,
struct NvResource root 
)

Frees a resource tree for the system.

This is a mechanism by which we can free an entire tree.

Side Effect:
RM Side Effect: Deallocates an object with a specific root in the RM Core.
Parameters
fd- File for deallocating the device on.
root- Root we are deallocating from.

Definition at line 138 of file api.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rm_version_check()

uint8_t rm_version_check ( int  ctl_fd,
uint8_t  ignore_version,
const char *  version 
)

Version check for the RM API.

RM API version check must be performed before running code.

Side Effect:
RM Side Effect: Enables the file descriptor to connect to the device.
Parameters
ctl_fd- The RM version check can only be performed on the ctl file.
ignore_version- If we ignore the version of the RM API.
version- Version we use for the RMCore.
Returns
If we were successfully version checked or not.
Possible Failures:

Invalid File Descriptor - This occurs when ctl_fd is -1.

Invalid RM Version - This will occur when there is a mismatch on the driver and the user suite.

Seg Fault - This occurs if version is not pointing to NULL but is pointing to a previously allocated memory address.

Definition at line 39 of file api.c.

Here is the caller graph for this function: