NVIDIA DriveOS Linux SDK API Reference

7.2.5.0 Early Access Release

Detailed Description

The NvDVMS_Client library provides an interface to set and get the VM state from the VM State Manager.

Note
QNX Implementation: The library supports fork() only on non-safety builds using pthread_atfork(). In safety builds, fork() is not supported. Shared memory deinitization APIs are called in the child process during fork() on non-safety builds. Clients must not use DVMS API's in their constructors/destructors to avoid ordering issues of constructors/destructors with shared memory deinit API.
Future API Changes: NVDVMS_SOC_OP_x power profile constants will be renamed to NVDVMS_VM_OP_x. Clients should be prepared for this naming change.

Functions

NvDvmsStatus nvdvms_set_vm_state (NvDvmsState state)
 Set VM state from application. More...
 
NvDvmsStatus nvdvms_get_vm_state (NvDvmsState *state)
 Get VM's current state. More...
 
NvDvmsStatus nvdvms_get_power_profile (NvDvmsVmOp *profile)
 Get(/Read) VM's current power profile. More...
 
NvDvmsStatus nvdvms_set_power_profile (NvDvmsVmOp profile)
 Set VM power profile as requested by application. More...
 
NvDvmsStatus nvdvms_check_init_api (void)
 Checks whether an Init Mode API can be called in the current VM state. More...
 
NvDvmsStatus nvdvms_check_deinit_api (void)
 Checks whether a DeInit Mode API can be called in the current VM state. More...
 
NvDvmsStatus nvdvms_init (void)
 Initializes NvDVMS client library. More...
 
NvDvmsStatus nvdvms_deinit (void)
 De-Initialize nvdvms client library. More...
 

NvDVMS_Client_API Access Control

Common Privileges

QNX Implementation: Description of custom abilities

1) The Nvdvms/ClientCommSetState ability provides access to the nvdvms_set_vm_state() APIs.

2) The Nvdvms/ClientCommGetState ability provides access to the nvdvms_check_init_api(), nvdvms_get_vm_state() and nvdvms_check_deinit_api() APIs.

Common privileges required for NvDVMS_Client_API (QNX):

  • Service/Group Name: nvdvms

Linux Implementation: Linux has a security configuration tool that exposes functional classes for the nvdvms_client library:

1) The NVDVMS_PRIV_CLASS functional class provides access to privileged actions:

2) The NVDVMS_UNPRIV_CLASS functional class provides access to unprivileged operations:

Clients with NVDVMS_UNPRIV_CLASS access cannot perform set_vm_state() and set_power_profile() operations.

Common privileges required for NvDVMS_Client_API (Linux):

  • Group Name: nvdvms_client

Function Documentation

◆ nvdvms_check_deinit_api()

NvDvmsStatus nvdvms_check_deinit_api ( void  )

Checks whether a DeInit Mode API can be called in the current VM state.

Returns
NvDvmsSuccess when a DeInit Mode API can be called in the current VM state.
NvDvmsStdError for uninitialized share memory and communication channel
NvDvmsInvalidState when a DeInit mode API can not be called in the current VM state
Precondition
nvdvms_init() shall be successful


Usage considerations

  • Allowed context for the API call
    • Interrupt handler: No
    • Signal handler: No
    • Thread-safe: Yes
    • Async/Sync: Sync
    • Re-entrant: Yes
  • Required privileges:
    • QNX: Custom abilites: Nvdvms/ClientCommGetState
    • Linux: Functional class: NVDVMS_UNPRIV_CLASS
  • Allowed execution state
    • Initialization: Yes
    • Operational: Yes
    • Reinit/Deinit Preparation: Yes
  • Maturity: GA

◆ nvdvms_check_init_api()

NvDvmsStatus nvdvms_check_init_api ( void  )

Checks whether an Init Mode API can be called in the current VM state.

Returns
NvDvmsSuccess when an Init Mode API can be called in the current VM state.
NvDvmsStdError for uninitialized share memory and communication channel
NvDvmsInvalidState when an Init mode API can not be called in the current VM state
Precondition
nvdvms_init() shall be successful


Usage considerations

  • Allowed context for the API call
    • Interrupt handler: No
    • Signal handler: No
    • Thread-safe: Yes
    • Async/Sync: Sync
    • Re-entrant: Yes
  • Required privileges:
    • QNX: Custom abilites: Nvdvms/ClientCommGetState
    • Linux: Functional class: NVDVMS_UNPRIV_CLASS
  • Allowed execution state
    • Initialization: Yes
    • Operational: Yes
    • Reinit/Deinit Preparation: Yes
  • Maturity: GA

◆ nvdvms_deinit()

NvDvmsStatus nvdvms_deinit ( void  )

De-Initialize nvdvms client library.

This API closes file descriptor and revoke Shared memory with NvDVMS resource manager.

In case multiple DeInit calls are made from the same application, only the last deinit call (with a corresponding Init call) will do the required deinit, while all previous calls just return success. Any deinit call without a corresponding init call will return failure.

Returns
NvDvmsSuccess : Success NvDvmsInvalidPerm : Access permission is denied NvDvmsStdError : Failure during SHM revoke or file descriptor close or decrementing reference counter
Precondition
nvdvms_init() shall be successful


Usage considerations

  • Allowed context for the API call
    • Interrupt handler: No
    • Signal handler: No
    • Thread-safe: No
    • Async/Sync: Sync
    • Re-entrant: No
  • Required privileges:
    • QNX: Custom abilites: Nvdvms/ClientCommGetState
    • Linux: Functional class: NVDVMS_UNPRIV_CLASS
  • Allowed execution state
    • Initialization: Yes
    • Operational: No
    • Reinit/Deinit Preparation: Yes
  • Maturity: GA

◆ nvdvms_get_power_profile()

NvDvmsStatus nvdvms_get_power_profile ( NvDvmsVmOp *  profile)

Get(/Read) VM's current power profile.

QNX Implementation: This function is used to get VM power profile. Shared Memory setup with resource manager is established in library constructor.

Linux Implementation: This function is used to get VM power profile. Shared Memory setup with nvdvms_server is established during nvdvms_init()

During boot/post successful completion of boot sequence, VM shall be in default power profile i.e 'NVDVMS_VM_OP_0' mode.

Parameters
[out]profileA pointer to hold VM's current power profile. 'profile' is updated only when the API returns NvDvmsSuccess. Valid profiles that can be returned:
NVDVMS_VM_OP_x (x ranges from 0 to 63)
Returns
NvDvmsSuccess on successful read of VM power profile
NvDvmsStdError for uninitialized shared memory and communication channel
NvDvmsInvalidParam on NULL pointer input
Precondition
nvdvms_init() shall be successful


Usage considerations

  • Allowed context for the API call
    • Interrupt handler: No
    • Signal handler: No
    • Thread-safe: Yes
    • Async/Sync: Sync
    • Re-entrant: Yes
  • Required privileges:
    • QNX: Custom abilites: Nvdvms/ClientCommGetState
    • Linux: Functional class: NVDVMS_UNPRIV_CLASS
  • Allowed execution state
    • Initialization: Yes
    • Operational: Yes
    • Reinit/Deinit Preparation: Yes
  • Maturity: GA

◆ nvdvms_get_vm_state()

NvDvmsStatus nvdvms_get_vm_state ( NvDvmsState *  state)

Get VM's current state.

QNX Implementation: This function is used to get VM state. Communication channel and shared memory setup with resource manager is established in library constructor.

Application shall use this API to implement polling for VM state, until VM transition to NVDVMS_INIT_DONE state is not completed.

During boot of DRIVEOS, VM state is NVDVMS_INIT.

Post successful completion of boot sequence of DRIVEOS,VM state is set to NVDVMS_INIT_DONE. Default timeout for setting NVDVMS_INIT_DONE is 3000ms, which can be modified from device tree.

Linux Implementation: This function is used to get VM state. Communication channel and shared memory setup with server is established during nvdvms_init()

NVDVMS_INIT state is set by nvdvms_server during DriveOS boot.

Post successful completion of nvdvms_server initialization sequence, VM state is set to NVDVMS_INIT_DONE.

Application shall use this API to implement polling for VM state, until VM transition to NVDVMS_INIT_DONE state is not completed.

Parameters
[out]stateA pointer to hold VM's current state. The value in state is set only when nvdvms_get_vm_state returns NvDvmsSuccess. Valid states that can be returned:
NVDVMS_INIT = 1
NVDVMS_INIT_DONE = 2
NVDVMS_OPERATIONAL_START = 3
NVDVMS_OPERATIONAL = 4
NVDVMS_SUSPEND_START = 5
NVDVMS_RESUME_START = 7
NVDVMS_DEINIT_PREPARE = 10
NVDVMS_DEINIT_START = 11
Returns
NvDvmsSuccess on successful read of VM state
NvDvmsStdError for uninitialized share memory and communication channel
NvDvmsInvalidParam on NULL pointer input
Precondition
nvdvms_init() shall be successful


Usage considerations

  • Allowed context for the API call
    • Interrupt handler: No
    • Signal handler: No
    • Thread-safe: Yes
    • Async/Sync: Sync
    • Re-entrant: Yes
  • Required privileges:
    • QNX: Custom abilites: Nvdvms/ClientCommGetState
    • Linux: Functional class: NVDVMS_UNPRIV_CLASS
  • Allowed execution state
    • Initialization: Yes
    • Operational: Yes
    • Reinit/Deinit Preparation: Yes
  • Maturity: GA

◆ nvdvms_init()

NvDvmsStatus nvdvms_init ( void  )

Initializes NvDVMS client library.

This API setup the shared memory with NvDVMS resource manager.

In case multiple Init calls are made from the same application, only the first call does the required initialisation, while rest of the API calls just return success, without performing any initialisation.

Returns
NvDvmsSuccess : Success NvDvmsInvalidPerm : Access permission is denied NvDvmsStdError : Indicates failure during shm mapping, file descriptor open or incrementing reference counter.
Precondition
none


Usage considerations

  • Allowed context for the API call
    • Interrupt handler: No
    • Signal handler: No
    • Thread-safe: No
    • Async/Sync: Sync
    • Re-entrant: No
  • Required privileges:
    • QNX: Custom abilites: Nvdvms/ClientCommGetState
    • Linux: Functional class: NVDVMS_UNPRIV_CLASS
  • Allowed execution state
    • Initialization: Yes
    • Operational: No
    • Reinit/Deinit Preparation: Yes
  • Maturity: GA

◆ nvdvms_set_power_profile()

NvDvmsStatus nvdvms_set_power_profile ( NvDvmsVmOp  profile)

Set VM power profile as requested by application.

QNX Implementation: During all power profile transition, the VM must be in NVDVMS_INIT_DONE state.

Application shall switch to the default power profile configuration i.e. 'NVDVMS_VM_OP_0' before requesting to transition to a different power profile configuration i.e. transition between the non-default power profiles is rejected as invalid transition.

Linux Implementation: Currently Linux NvDVMS supports only suspend, shutdown and cold boot power profiles.

To initiate suspend power profile (NVDVMS_VM_OP_62), VM needs to be in NVDVMS_INIT_DONE state.

To initiate shutdown power profile (NVDVMS_VM_OP_63), VM needs to be in NVDVMS_DEINIT_PREPARE state.

Parallel power profile transition will be rejected, if already a state transition or power profile transition request is in progress.

Parameters
[in]profileInput VM power profile that the application is pushing Valid profiles that can be set:
NVDVMS_VM_OP_x (x ranges from 0 to 63)
Returns
NvDvmsSuccess on successful change of VM power profile
NvDvmsStdError for error during VM power profile transition
NvDvmsInvalidParam on NULL pointer input or wrong input power profile requested
NvDvmsInvalidPerm indicating that there was no permissions for the operation.
NvDvmsBusy indicating already a vm state/power profile transition is in progress.
NvDvmsInvalidPowerMode indicating wrong/invalid power profile transition requested, which is not allowed i.e. invalid transition
NvDvmsTimedout indicating that the callback executing during power profile transition is timedout.
NvDvmsInvalidState indicating that the power profile transition is requested in wrong VM state.
NvDvmsRejected indicating error due to power profile not enabled for current VM, or there was error during earlier power profile transition, or some internal error such as error during acquiring lock, Invalid internal data structure values.
Note
If the API returned 'NvDvmsStdError' then further no other state/power-profile transition is allowed except VM state transition to DEINIT i.e. from current VM state(NVDVMS_INIT_DONE) to NVDVMS_DEINIT_PREPARE to NVDVMS_DEINIT.
Precondition
VM shall be in NVDVMS_INIT_DONE state.


Usage considerations

  • Allowed context for the API call
    • Interrupt handler: No
    • Signal handler: No
    • Thread-safe: No
    • Async/Sync: Sync
    • Re-entrant: No
  • Required privileges:
    • QNX: Custom abilites: Nvdvms/ClientCommSetState
    • Linux: Functional class: NVDVMS_PRIV_CLASS
  • Allowed execution state
    • Initialization: Yes
    • Operational: No
    • Reinit/Deinit Preparation: No
  • Maturity: GA

◆ nvdvms_set_vm_state()

NvDvmsStatus nvdvms_set_vm_state ( NvDvmsState  state)

Set VM state from application.

QNX Implementation: This function is used to set VM state by making devctl calls to VM state manager device.

During boot of DriveOS, VM state is NVDVMS_INIT.

Post successful completion of boot sequence of DriveOS, VM state is set to NVDVMS_INIT_DONE. Default timeout for setting NVDVMS_INIT_DONE is 3000ms, which can be modified from device tree.

Linux Implementation: This function is used to set VM state by sending messages to the VM state manager(nvdvms_server).

NVDVMS_INIT state is set by nvdvms_server during DriveOS boot.

Post successful init sequence of nvdvms_server, VM state is updated to NVDVMS_INIT_DONE.

Linux Implementation Restrictions The Linux implementation disallows transitions to the following states using nvdvms_set_vm_state():

  • NVDVMS_SUSPEND_START
  • NVDVMS_SUSPEND
  • NVDVMS_DEINIT_START
  • NVDVMS_DEINIT

Common Implementation Behavior: Parallel state transition will be rejected, if already a state transition or power profile transition request is in progress.

Allowed state transitions from application

QNX Implementation:
1. NVDVMS_INIT_DONE --> NVDVMS_OPERATIONAL
    For NVDVMS_OPERATIONAL, If any error is encountered during
    transition to NVDVMS_OPERATIONAL state, this API returns with
    an error code. The error during state transition is also
    reported to FSI.
    Error code reported:
        nvdvms_transition_failure_pid = 0x1a
2. NVDVMS_INIT_DONE --> NVDVMS_SUSPEND
    For NVDVMS_SUSPEND state, this is a blocking API which returns
    only when the VM resumes due to wakeup events. If any generic
    error is encountered with VM state machine, API returns with
    error code. Once suspend/resume transition starts, any error
    encountered is reported to FSI.
    Error code reported are:
        nvdvms_suspend_drivers_failure = 0x1
        nvdvms_suspend_get_shm_failure = 0x2
        nvdvms_suspend_transition_start_failure = 0x3
        nvdvms_suspend_userspace_failure = 0x4
        nvdvms_suspend_system_failure = 0x5
        nvdvms_resume_drivers_failure = 0x6
        nvdvms_resume_userspace_failure = 0x7
        nvdvms_resume_done_failure = 0x8
        nvdvms_resume_init_done_failure = 0x9
        nvdvms_resume_sem_failure = 0xa
        nvdvms_set_suspend_state_failure = 0x14
        nvdvms_set_resume_start_state_failure = 0x15
        nvdvms_set_resume_state_failure = 0x16
        nvdvms_set_suspend_start_state_failure = 0x17
        nvdvms_transition_failure_pid = 0x1a
        nvdvms_resume_stop_init_done_failure = 0x1b
        nvdvms_resume_error_state_failure = 0x1c
        nvdvms_mutex_api_failure = 0x1d
        nvdvms_resume_get_power_profile_failure = 0x21
        nvdvms_resume_update_vm_state_to_sysmgr_failure = 0x22
3. NVDVMS_INIT_DONE --> NVDVMS_DEINIT_PREPARE
4. NVDVMS_OPERATIONAL --> NVDVMS_DEINIT_PREPARE
    NVDVMS_DEINIT_PREPARE is a best effort delivery transition.
    Even if failure is encountered, progress will continue to set
    VM state to NVDVMS_DEINIT_PREPARE. Error will be reported back
    to application. Application should log the error (non-fatal)
    and proceed with NVDVMS_DEINIT transition. During this state
    transition error is reported to FSI as well.
    Error code reported:
        nvdvms_transition_failure_pid = 0x1a
5. NVDVMS_DEINIT_PREPARE --> NVDVMS_INIT_DONE
    This state transition is to support Runtime SC7.
    This is required in cases where we would require transition to
    Suspend from Operational state. The sequence to be followed is
    described below:
        a. Transition from NVDVMS_OPERATIONAL to NVDVMS_DEINIT_PREPARE
        b. Transition from NVDVMS_DEINIT_PREPARE to NVDVMS_INIT_DONE
    At this point when all processes have moved to NVDVMS_REINIT_DONE
    state, DVMS will set state to NVDVMS_INIT_DONE from where we
    could transition to all states allowed.
    Error code reported:
        nvdvms_transition_failure_pid = 0x1a
        nvdvms_process_reinit_failure = 0x1e
6. NVDVMS_INIT --> NVDVMS_DEINIT_PREPARE
    This state transition should be used when application detects
    NVDVMS_INIT_DONE is not reached. NVDVMS_DEINIT_PREPARE is a
    best effort delivery transition. Even if failure is encountered,
    progress will continue to set VM state to NVDVMS_DEINIT_PREPARE.
    Error will be reported back to application. Application should
    log the error (non-fatal) and proceed with NVDVMS_DEINIT
    transition. During this state transition error is reported to
    FSI as well.
    Error code reported:
        nvdvms_transition_failure_pid = 0x1a
7. NVDVMS_DEINIT_PREPARE --> NVDVMS_DEINIT
    For NVDVMS_DEINIT state, this API never returns.
    NVDVMS_DEINIT state transition means control will never reach
    to application. Once NVDVMS_DEINIT transition starts, any error
    encountered is reported to FSI.
    Error code reported are:
        nvdvms_deinit_reg_process_failure = 0xb
        nvdvms_deinit_user_process_failure = 0xc
        nvdvms_deinit_get_pid_failure = 0xd
        nvdvms_deinit_callback_failure = 0xe
        nvdvms_deinit_ack_failure = 0xf
        nvdvms_deinit_get_shm_failure = 0x10
        nvdvms_deinit_transition_start_failure = 0x11
        nvdvms_set_deinit_start_state_failure = 0x18
        nvdvms_set_deinit_state_failure = 0x19
        nvdvms_transition_failure_pid = 0x1a
Linux Implementation:
1. NVDVMS_INIT_DONE --> NVDVMS_OPERATIONAL
    nvdvms_server updates the VM state to NVDVMS_OPERATIONAL
    state.
2. NVDVMS_INIT_DONE --> NVDVMS_DEINIT_PREPARE
    nvdvms_server updates the VM state to NVDVMS_DEINIT_PREPARE
    state.
3. NVDVMS_OPERATIONAL --> NVDVMS_DEINIT_PREPARE
    nvdvms_server updates the VM state to NVDVMS_DEINIT_PREPARE
    state.
4. NVDVMS_DEINIT_PREPARE --> NVDVMS_INIT_DONE
    nvdvms_server updates the VM state to NVDVMS_INIT_DONE state.
 
Parameters
[in]stateInput VM state transition which application is pushing.
Valid states that can be requested are:
NVDVMS_OPERATIONAL = 4
NVDVMS_SUSPEND = 6 (QNX only)
NVDVMS_DEINIT_PREPARE = 10
NVDVMS_DEINIT = 12 (QNX only)
NVDVMS_REINIT = 15
Returns
NvDvmsSuccess indicating the successful transition of the VM state.
NvDvmsStdError indicating an internal error was detected during a VM state transition.
NvDvmsInvalidState indicating that the requested state transition was invalid.
NvDvmsTimedout indicating that the state transition to NVDVMS_OPERATIONAL, NVDVMS_DEINIT_PREPARE timed out.
NvDvmsInvalidParam indicating that the requested state was unrecognized.
NvDvmsInvalidPerm indicating that there was no permissions for the operation.
NvDvmsRejected indicating that the requested state transition was rejected (Linux only, for restricted states).
Note
If a nvdvms monitored process terminates, The following FSI error code is reported:
nvdvms_process_ungraceful_termination = 0x20
nvdvms_process_graceful_termination = 0x1f
Error attribute contains the PID of the terminated process. set_vm_state API will return failure.
Precondition
To transition to NVDVMS_OPERATIONAL, the VM state must be NVDVMS_INIT_DONE.
To transition to NVDVMS_SUSPEND, the VM state must be NVDVMS_INIT_DONE (QNX only).
To transition to NVDVMS_DEINIT_PREPARE, the VM state must be either NVDVMS_INIT_DONE or NVDVMS_OPERATIONAL or NVDVMS_INIT.
To transition to NVDVMS_DEINIT, the VM state must be NVDVMS_DEINIT_PREPARE (QNX only).
To transition to NVDVMS_INIT_DONE, the VM state must be either NVDVMS_INIT or NVDVMS_DEINIT_PREPARE


Usage considerations

  • Allowed context for the API call
    • Interrupt handler: No
    • Signal handler: No
    • Thread-safe: No
    • Async/Sync: Sync
    • Re-entrant: No
  • Required privileges:
    • QNX: Custom abilites: Nvdvms/ClientCommSetState
    • Linux: Functional class: NVDVMS_PRIV_CLASS
  • Allowed execution state
    • Initialization: Yes
    • Operational: Yes
    • Reinit/Deinit Preparation: Yes
  • Maturity: GA