> ## Documentation Index
> Fetch the complete documentation index at: https://dragonwingdocs-staging.qualcomm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# GPR API Inline

> This file contains GPR APIs.

**Header:** `gpr/api/gpr_api_inline.h`

## Functions

### `__gpr_cmd_register`

Registers a service, by its unique service ID, with the GPR.

@datatypes gpr\_callback\_fn\_t

@codeexample @lstlisting #include "gpr\_api\_inline.h"

Example of a test client service (with service ID GPR\_TESTCLIENT\_SERVICE\_ID) trying to register with GPR. uint32\_t service\_callback\_fn(gpr\_packet\_t \*packet, void \*callback\_data); void \* callback\_data = NULL;

int main ( void )  return 0; }

Example of a callback function for a service. It is invoked by GPR every time a message is sent or received, to or from that service. static int32\_t service\_callback\_fn( gpr\_packet\_t\* packet,
void\* callback\_data )

switch ( packet->opcode )  case TEST\_CLIENT\_RSP\_FUNCTION:  case GPR\_IBASIC\_RSP\_RESULT:  default:  } return AR\_EOK; AR\_EOK tells the caller that the packet was consumed (freed). } @endlstlisting

```cpp theme={null}
uint32_t __gpr_cmd_register(uint32_t src_port, gpr_callback_fn_t callback_fn, void *callback_data)
```

**Parameters**

<ParamField path="src_port" type="uint32_t">
  Unique ID (within a domain) of the service to be registered.
</ParamField>

<ParamField path="callback_fn" type="gpr_callback_fn_t">
  Callback function of the service to be registered.
</ParamField>

<ParamField path="callback_data" type="void *">
  Pointer to the client-supplied data pointer for the callback function.
</ParamField>

**Returns**

AR\_EOK  When successful.

### `__gpr_cmd_deregister`

Deregisters a service from the GPR.

@codeexample @lstlisting #include "gpr\_api\_inline.h"

Example of a test client service (with service ID GPR\_TESTCLIENT\_SERVICE\_ID) trying to deregister from GPR. uint32\_t callback\_fn(gpr\_packet\_t \*packet, void \*callback\_data); void \* callback\_data = NULL;

int32\_t rc = \_\_gpr\_cmd\_register(GPR\_TESTCLIENT\_SERVICE\_ID,
callback\_fn,
callback\_data); if ( rc )  ... rc = \_\_gpr\_cmd\_deregister(GPR\_TESTCLIENT\_SERVICE\_ID); if ( rc )  @endlstlisting

```cpp theme={null}
uint32_t __gpr_cmd_deregister(uint32_t src_port)
```

**Parameters**

<ParamField path="src_port" type="uint32_t">
  Unique ID of the service.
</ParamField>

**Returns**

AR\_EOK  When successful.

### `__gpr_cmd_is_registered`

Called by the framework to check whether a service is registered with the GPR.

@codeexample @lstlisting #include "gpr\_api\_inline.h"

Example to check if test client service (with service ID GPR\_TESTCLIENT\_SERVICE\_ID) is registered with GPR. bool\_t is\_registered = FALSE; \_\_gpr\_cmd\_is\_registered(GPR\_TESTCLIENT\_SERVICE\_ID, \&is\_registered); if(TRUE == is\_registered)  else  @endlstlisting @newpage

```cpp theme={null}
uint32_t __gpr_cmd_is_registered(uint32_t port, bool_t *is_registered)
```

**Parameters**

<ParamField path="port" type="uint32_t">
  Unique ID of the service.
</ParamField>

<ParamField path="is_registered" type="bool_t *">
  Pointer to the client-supplied flag that returns TRUE if service is registered and FALSE if the service is not registered.
</ParamField>

**Returns**

AR\_EOK.

### `__gpr_cmd_get_host_domain_id`

Queries the GPR to get the local or host domain ID.

@codeexample @lstlisting #include "gpr\_api\_inline.h"

uint32\_t host\_domain\_id; \_\_gpr\_cmd\_host\_domain\_id( \&host\_domain\_id ); printf( "GPR is in domain ID: %d ", host\_domain\_id ); @endlstlisting

```cpp theme={null}
uint32_t __gpr_cmd_get_host_domain_id(uint32_t *host_domain_id)
```

**Parameters**

<ParamField path="host_domain_id" type="uint32_t *">
  Pointer to the GPR's host domain ID.
</ParamField>

**Returns**

AR\_EOK always.- Returns the host domain ID

### `__gpr_cmd_get_dest_domain_ids`

Utility to query list of destination domain ids with which GPR communication is supported from the current domain.

@codeexample @lstlisting

\#include "gpr\_api\_inline.h"

uint32\_t num\_domains = 0; uint32\_t \*dest\_domains = NULL; \_\_gpr\_cmd\_get\_dest\_domain\_ids(\&num\_domains, dest\_domains); dest\_domains = (uint32\_t *)malloc(sizeof(num\_domains*sizeof(uint32\_t))); \_\_gpr\_cmd\_get\_dest\_domain\_ids(\&num\_domains, dest\_domains);

@endlstlisting

```cpp theme={null}
uint32_t __gpr_cmd_get_dest_domain_ids(uint32_t *num_domains, uint32_t *domain_ids)
```

**Parameters**

<ParamField path="num_domains" type="uint32_t *">
  * Pointer to the num of destination domains.
</ParamField>

<ParamField path="domain_ids" type="uint32_t *">
  * Pointer to the GPR's destination domain IDs.
</ParamField>

**Returns**

AR\_EOK always.- Returns the number of destination domains on requesting first time. AR\_EOK always.- When called again with memory allocated for domain array, fills destination domain ids info.

### `__gpr_cmd_is_shared_mem_supported`

Utility to query if shared memory is supported from the current domain to a given dest\_domain\_id.

@codeexample @lstlisting #include "gpr\_api\_inline.h"

uint32\_t dest\_domain\_id = GPR\_IDS\_DOMAIN\_ID\_ADSP\_V; bool\_t supports\_shared\_mem = true; \_\_gpr\_cmd\_is\_shared\_mem\_supported(dest\_domain\_id, \&supports\_shared\_mem); if (supports\_shared\_mem) do something else do something @endlstlisting

```cpp theme={null}
uint32_t __gpr_cmd_is_shared_mem_supported(uint32_t dest_domain_id, bool_t *supports_shared_mem)
```

**Parameters**

<ParamField path="dest_domain_id" type="uint32_t">
  * Destination domain id.
</ParamField>

<ParamField path="supports_shared_mem" type="bool_t *">
  * Pointer to know if domain supports shared memory
</ParamField>

**Returns**

AR\_EOK always.- Returns if a destination domain supports shared memory.

### `__gpr_cmd_get_gpr_packet_info`

Queries for the GPR's packet pool information.

@datatypes gpr\_cmd\_gpr\_packet\_pool\_info\_t

@codeexample @lstlisting #include "gpr\_api\_inline.h"

gpr\_cmd\_gpr\_packet\_pool\_info\_t packet\_info; \_\_gpr\_cmd\_get\_gpr\_packet\_info( \&packet\_info );

printf( "GPR packet pool information:
Bytes in minimum-sized gpr packet: %d,
Number of minimum-sized gpr packets allocated at initialization: %d,
Bytes in maximum-sized gpr packet: %d,
Number of maximum-sized gpr packets allocated at initialization: %d ", packet\_info.bytes\_per\_min\_size\_packet, packet\_info.num\_min\_size\_packets, packet\_info.bytes\_per\_max\_size\_packet, packet\_info.num\_max\_size\_packets); @endlstlisting

@inputfile

```cpp theme={null}
uint32_t __gpr_cmd_get_gpr_packet_info(gpr_cmd_gpr_packet_pool_info_t *args)
```

**Parameters**

<ParamField path="args" type="gpr_cmd_gpr_packet_pool_info_t *">
  Pointer to the packet pool information, such as the number and sizes of the packets.
</ParamField>

**Returns**

AR\_EOK  Returns the GPR packet pool information.

### `__gpr_cmd_get_gpr_packet_info_v2`

Queries for the GPR's V2 packet pool information.

@datatypes gpr\_packet\_pool\_info\_v2\_t

@codeexample @lstlisting #include "gpr\_api\_inline.h"

gpr\_packet\_pool\_info\_v2\_t \*packet\_pool\_info\_arr = NULL; uint32\_t num\_packet\_pools = 0;

Calling first time, to gets number of packet pools and allocates the array accordingly. \_\_gpr\_cmd\_get\_gpr\_packet\_info\_v2( \&num\_packet\_pools, packet\_pool\_info\_arr ); packet\_pool\_info\_arr = (gpr\_packet\_pool\_info\_v2\_t *)malloc(sizeof(num\_packet\_pools*sizeof(gpr\_packet\_pool\_info\_v2\_t)));

Calling second time to the get the populated packet\_pool\_info\_arr \_\_gpr\_cmd\_get\_gpr\_packet\_info\_v2( \&num\_packet\_pools, packet\_pool\_info\_arr );

@endlstlisting

@inputfile

```cpp theme={null}
uint32_t __gpr_cmd_get_gpr_packet_info_v2(uint32_t *num_packet_pools, gpr_packet_pool_info_v2_t *packet_pool_info_arr)
```

**Parameters**

<ParamField path="num_packet_pools" type="uint32_t *">
  Number of packet pools that are created.
</ParamField>

<ParamField path="packet_pool_info_arr" type="gpr_packet_pool_info_v2_t *">
  Packet pool info array, with each element in array containing pool related info like number of packets, packet size, heap index and if the packets are dynamically/statically allocated.
</ParamField>

**Returns**

AR\_EOK always.- Returns the number of packet pools on requesting first time. AR\_EOK always.- When called again with memory allocated for Packet pool info array, fills the array elements with the pool info.

### `__gpr_cmd_async_send`

Sends an asynchronous message to other services.

@datatypes gpr\_packet\_t

int32\_t rc; gpr\_packet\_t\* packet\_ptr; uint32\_t payload\_size; uint32\_t packet\_size;

Example of a payload structure that needs to be populated and sent. test\_client\_cmd\_function\_t payload; payload\_size = sizeof( test\_client\_cmd\_function\_t ); packet\_size = payload\_size + GPR\_PKT\_HEADER\_WORD\_SIZE\_V;

Allocate a free packet. rc = \_\_gpr\_cmd\_alloc( payload\_size, \&packet ); if ( rc )

Fill in the packet details. packet->header GPR\_SET\_FIELD(GPR\_PKT\_VERSION, GPR\_PKT\_VERSION\_V) | GPR\_SET\_FIELD(GPR\_PKT\_HEADER\_SIZE, GPR\_PKT\_HEADER\_WORD\_SIZE\_V) | GPR\_SET\_FIELD(GPR\_PKT\_PACKET\_SIZE, packet\_size); packet->dst\_domain = GPR\_CLIENT\_SERVICE\_DOMAIN\_ID\_DESTINATION; packet->src\_domain = GPR\_CLIENT\_SERVICE\_DOMAIN\_ID\_SOURCE; packet->dst\_port = GPR\_CLIENT\_SERVICE\_PORT\_ID\_DESTINATION; packet->src\_port = GPR\_CLIENT\_SERVICE\_PORT\_ID\_SOURCE; packet->token = 0x12345678; packet->opcode = TEST\_CLIENT\_CMD\_FUNCTION;

Fill in the payload. payload.param1 = 1; payload.param2 = 2; memscpy( GPR\_PKT\_GET\_PAYLOAD( void, packet ), payload\_size, payload, payload\_size );

Send the packet. rc = \_\_gpr\_cmd\_async\_send( packet\_ptr ); if ( rc )  @endlstlisting

```cpp theme={null}
uint32_t __gpr_cmd_async_send(gpr_packet_t *packet)
```

**Parameters**

<ParamField path="packet" type="gpr_packet_t *">
  Pointer to the packet (message) to send.
</ParamField>

**Returns**

AR\_EOK  When successful.

### `__gpr_cmd_alloc`

Allocates a free message for delivery.

@datatypes gpr\_packet\_t

@codeexample See the code example for \_\_gpr\_cmd\_async\_send().

```cpp theme={null}
uint32_t __gpr_cmd_alloc(uint32_t alloc_size, gpr_packet_t **ret_packet)
```

**Parameters**

<ParamField path="alloc_size" type="uint32_t">
  Amount of memory (in bytes) required for allocation.
</ParamField>

<ParamField path="ret_packet" type="gpr_packet_t **">
  Double pointer to the allocated packet that is returned by this function.
</ParamField>

**Returns**

AR\_EOK  When successful.

### `__gpr_cmd_alloc_v2`

Allocates a free message for delivery from a specified heap.

@datatypes gpr\_packet\_t

@codeexample See the code example for \_\_gpr\_cmd\_async\_send().

```cpp theme={null}
uint32_t __gpr_cmd_alloc_v2(uint32_t alloc_size, gpr_heap_index_t heap_index, gpr_packet_t **ret_packet)
```

**Parameters**

<ParamField path="alloc_size" type="uint32_t">
  Amount of memory (in bytes) required for allocation.
</ParamField>

<ParamField path="heap_index" type="gpr_heap_index_t">
  Heap index of the packet pool.
</ParamField>

<ParamField path="ret_packet" type="gpr_packet_t **">
  Double pointer to the allocated packet that is returned by this function.
</ParamField>

**Returns**

AR\_EOK  When successful.

### `__gpr_cmd_free`

Frees a specified GPR packet and returns it to the owner.

@datatypes gpr\_packet\_t

@codeexample See the code example for \_\_gpr\_cmd\_async\_send().

```cpp theme={null}
uint32_t __gpr_cmd_free(gpr_packet_t *packet)
```

**Parameters**

<ParamField path="packet" type="gpr_packet_t *">
  Pointer to the GPR packet to be freed.
</ParamField>

**Returns**

AR\_EOK  When successful.

### `__gpr_cmd_alloc_ext`

Allocates a formatted free packet for delivery.

@datatypes gpr\_cmd\_alloc\_ext\_t

int32\_t rc; gpr\_packet\_t\* packet\_ptr; uint32\_t payload\_size;

Example payload required to be sent. test\_client\_cmd\_function\_t \* payload;

gpr\_cmd\_alloc\_ext\_t alloc\_args; alloc\_args.src\_domain\_id = GPR\_CLIENT\_SERVICE\_DOMAIN\_ID\_SOURCE; alloc\_args.src\_port = GPR\_CLIENT\_SERVICE\_PORT\_ID\_SOURCE; alloc\_args.dst\_domain\_id = GPR\_CLIENT\_SERVICE\_DOMAIN\_ID\_DESTINATION; alloc\_args.dst\_port = GPR\_CLIENT\_SERVICE\_PORT\_ID\_DESTINATION; alloc\_args.token = 0x12345678; alloc\_args.opcode = TEST\_CLIENT\_CMD\_FUNCTION; alloc\_args.payload\_size = sizeof( test\_client\_cmd\_function\_t ); alloc\_args.ret\_packet = \&packet\_ptr;

Allocate memory for the packet. rc = \_\_gpr\_cmd\_alloc\_ext(alloc\_args); if ( rc )

Fill in the payload. payload = GPR\_PKT\_GET\_PAYLOAD( test\_client\_cmd\_function\_t, packet\_ptr ); payload->param1 = 1; payload->param2 = 2;

Send the packet. rc = \_\_gpr\_cmd\_async\_send( packet\_ptr ); if ( rc )  @endlstlisting

@inputfile

```cpp theme={null}
uint32_t __gpr_cmd_alloc_ext(gpr_cmd_alloc_ext_t *args)
```

**Parameters**

<ParamField path="args" type="gpr_cmd_alloc_ext_t *">
  Pointer to the allocated packet information, such as domain and port IDs, token and opcode values, and payload size.
</ParamField>

**Returns**

AR\_EOK  When successful.

### `__gpr_cmd_alloc_ext_v2`

Allocates a formatted free packet for delivery from a specified heap.

@datatypes #gpr\_cmd\_alloc\_ext\_v2

int32\_t rc; gpr\_packet\_t\* packet\_ptr; uint32\_t payload\_size;

Example payload required to be sent. test\_client\_cmd\_function\_t \* payload;

gpr\_cmd\_alloc\_ext\_v2\_t alloc\_args; alloc\_args.src\_domain\_id = GPR\_CLIENT\_SERVICE\_DOMAIN\_ID\_SOURCE; alloc\_args.src\_port = GPR\_CLIENT\_SERVICE\_PORT\_ID\_SOURCE; alloc\_args.dst\_domain\_id = GPR\_CLIENT\_SERVICE\_DOMAIN\_ID\_DESTINATION; alloc\_args.dst\_port = GPR\_CLIENT\_SERVICE\_PORT\_ID\_DESTINATION; alloc\_args.token = 0x12345678; alloc\_args.heap\_index = GPR\_HEAP\_INDEX\_DEFAULT; alloc\_args.opcode = TEST\_CLIENT\_CMD\_FUNCTION; alloc\_args.payload\_size = sizeof( test\_client\_cmd\_function\_t ); alloc\_args.ret\_packet = \&packet\_ptr;

Allocate memory for the packet. rc = \_\_gpr\_cmd\_alloc\_ext\_v2(alloc\_args); if ( rc )

Fill in the payload. payload = GPR\_PKT\_GET\_PAYLOAD( test\_client\_cmd\_function\_t, packet\_ptr ); payload->param1 = 1; payload->param2 = 2;

Send the packet. rc = \_\_gpr\_cmd\_async\_send( packet\_ptr ); if ( rc )  @endlstlisting

@inputfile

```cpp theme={null}
uint32_t __gpr_cmd_alloc_ext_v2(gpr_cmd_alloc_ext_v2_t *args)
```

**Parameters**

<ParamField path="args" type="gpr_cmd_alloc_ext_v2_t *">
  Pointer to the allocated packet information, such as domain and port IDs, token and opcode values, heap\_index and payload size.
</ParamField>

**Returns**

AR\_EOK  When successful.

### `__gpr_cmd_alloc_send`

Allocates and sends a formatted free packet.

@datatypes gpr\_cmd\_alloc\_send\_t

int32\_t rc; gpr\_packet\_t\* packet\_ptr; uint32\_t payload\_size;

Example payload required to be sent. test\_client\_cmd\_function\_t payload;

Fill in the payload. payload.param1 = 1; payload.param2 = 2;

gpr\_cmd\_alloc\_send\_t alloc\_send\_args; alloc\_send\_args.src\_domain\_id = GPR\_CLIENT\_SERVICE\_DOMAIN\_ID\_SOURCE; alloc\_send\_args.src\_port = GPR\_CLIENT\_SERVICE\_PORT\_ID\_SOURCE; alloc\_send\_args.dst\_domain\_id = GPR\_CLIENT\_SERVICE\_DOMAIN\_ID\_DESTINATION; alloc\_send\_args.dst\_port = GPR\_CLIENT\_SERVICE\_PORT\_ID\_DESTINATION; alloc\_send\_args.token = 0x12345678; alloc\_send\_args.opcode = TEST\_CLIENT\_CMD\_FUNCTION; alloc\_send\_args.payload\_size = sizeof( test\_client\_cmd\_function\_t ); alloc\_send\_args.payload = \&payload;

Create and send packet. rc = \_\_gpr\_cmd\_alloc\_send(alloc\_send\_args); if ( rc )  @endlstlisting

@inputfile

```cpp theme={null}
uint32_t __gpr_cmd_alloc_send(gpr_cmd_alloc_send_t *args)
```

**Parameters**

<ParamField path="args" type="gpr_cmd_alloc_send_t *">
  Pointer to the allocated packet information, such as domain and port IDs, token and opcode values, and payload size.
</ParamField>

**Returns**

AR\_EOK  When successful.

### `__gpr_cmd_accept_command`

Accepts a command packet by replying with a GPR\_IBASIC\_EVT\_ACCEPTED message to the sender.

@datatypes gpr\_packet\_t

```cpp theme={null}
uint32_t __gpr_cmd_accept_command(gpr_packet_t *packet)
```

**Parameters**

<ParamField path="packet" type="gpr_packet_t *">
  Pointer to the command packet to be accepted.
</ParamField>

**Returns**

AR\_EOK  When successful.

### `__gpr_cmd_end_command`

Completes a command message by replying with a GPR\_IBASIC\_RSP\_RESULT command response message to the sender.

The indicated packet is then freed.

@datatypes gpr\_packet\_t

```cpp theme={null}
uint32_t __gpr_cmd_end_command(gpr_packet_t *packet, uint32_t status)
```

**Parameters**

<ParamField path="packet" type="gpr_packet_t *">
  Pointer to the command message to complete.
</ParamField>

<ParamField path="status" type="uint32_t">
  Completion or error status to respond to the client (see Section\@xref).
</ParamField>

**Returns**

AR\_EOK  When successful.
