NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
devemu_pci_device_db_dpu_kernels_dev.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022 NVIDIA CORPORATION AND AFFILIATES. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, are permitted
5  * provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright notice, this list of
7  * conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright notice, this list of
9  * conditions and the following disclaimer in the documentation and/or other materials
10  * provided with the distribution.
11  * * Neither the name of the NVIDIA CORPORATION nor the names of its contributors may be used
12  * to endorse or promote products derived from this software without specific prior written
13  * permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21  * STRICT LIABILITY, OR TOR (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  *
24  */
25 
26 #include <doca_dpa_dev.h>
28 
29 struct {
32 
33 /*
34  * RPC function for initializing the DPA app context
35  *
36  * @db_comp [in]: The Doorbell completion context
37  * @db [in]: The Doorbell object
38  * @return: 0 in case of success, and 1 otherwise
39  */
41 {
42  app_ctx.db_comp = db_comp;
43 
45  DOCA_DPA_DEV_LOG_INFO("Failed to bind DB to completion \n");
46  return 1;
47  }
48 
49  return 0;
50 }
51 
52 /*
53  * RPC function for uninitializing the DPA app context
54  *
55  * @db_comp [in]: The Doorbell completion context
56  * @db [in]: The Doorbell object
57  * @return: 0 in case of success, and 1 otherwise
58  */
61 {
63  DOCA_DPA_DEV_LOG_INFO("Failed to unbind DB from completion \n");
64  return 1;
65  }
66 
67  app_ctx.db_comp = 0;
68 
69  return 0;
70 }
71 
72 /*
73  * Doorbell handler wakes up everytime a DB is rang from Host
74  *
75  * @thread_arg [in]: Value provided on setup of DPA thread
76  */
77 __dpa_global__ void db_handler(uint64_t __attribute__((__unused__)) thread_arg)
78 {
80 
82  if (doca_dpa_dev_devemu_pci_get_db_completion(db_comp, &comp_element) != 1) {
83  DOCA_DPA_DEV_LOG_INFO("No completion found\n");
85  }
86 
87  uint32_t dbr_value;
89  doca_dpa_dev_uintptr_t user_data;
91 
94 
96 
98  DOCA_DPA_DEV_LOG_INFO("Received Doorbell value is %u\n", dbr_value);
99 
101 }
__dpa_rpc__ uint64_t init_app_ctx_rpc(doca_dpa_dev_devemu_pci_db_completion_t db_comp, doca_dpa_dev_devemu_pci_db_t db)
__dpa_rpc__ uint64_t uninit_app_ctx_rpc(doca_dpa_dev_devemu_pci_db_completion_t db_comp, doca_dpa_dev_devemu_pci_db_t db)
__dpa_global__ void db_handler(uint64_t __attribute__((__unused__)) thread_arg)
doca_dpa_dev_devemu_pci_db_completion_t db_comp
struct @165 app_ctx
uint64_t db
struct dpa_thread_arg __dpa_global__
#define __attribute__(_x_)
To allow compiling functions and structs that are using GCC attributes using attribute() in compilers...
Definition: doca_compat.h:81
uint64_t doca_dpa_dev_devemu_pci_db_completion_t
DPA handle for emulated PCI device doorbell completion context.
uint64_t doca_dpa_dev_devemu_pci_db_t
DPA handle for emulated PCI device doorbell.
__dpa_global__ typedef uint64_t doca_dpa_dev_devemu_pci_db_completion_element_t
DPA Devemu PCI Device DB Completion Element handle type definition.
DOCA_EXPERIMENTAL void doca_dpa_dev_devemu_pci_db_completion_request_notification(doca_dpa_dev_devemu_pci_db_completion_t comp)
Request notification on the Devemu PCI Device DB completion context.
DOCA_EXPERIMENTAL uint32_t doca_dpa_dev_devemu_pci_db_get_value(doca_dpa_dev_devemu_pci_db_t db)
Get value written to the doorbell.
DOCA_EXPERIMENTAL int doca_dpa_dev_devemu_pci_db_completion_bind_db(doca_dpa_dev_devemu_pci_db_completion_t comp, doca_dpa_dev_devemu_pci_db_t db)
Bind Devemu PCI Device DB handle to the Devemu PCI Device DB completion context.
DOCA_EXPERIMENTAL void doca_dpa_dev_devemu_pci_db_completion_ack(doca_dpa_dev_devemu_pci_db_completion_t comp, uint64_t num_comp)
Acknowledge that the completions have been read on the Devemu PCI Device DB completion context.
DOCA_EXPERIMENTAL void doca_dpa_dev_devemu_pci_db_completion_element_get_db_properties(doca_dpa_dev_devemu_pci_db_completion_t comp, doca_dpa_dev_devemu_pci_db_completion_element_t comp_element, doca_dpa_dev_devemu_pci_db_t *db, doca_dpa_dev_uintptr_t *db_user_data)
Get Devemu PCI Device DB properties from DB completion element.
DOCA_EXPERIMENTAL void doca_dpa_dev_devemu_pci_db_request_notification(doca_dpa_dev_devemu_pci_db_t db)
Request notification on the Devemu PCI Device DB context.
DOCA_EXPERIMENTAL int doca_dpa_dev_devemu_pci_db_completion_unbind_db(doca_dpa_dev_devemu_pci_db_completion_t comp, doca_dpa_dev_devemu_pci_db_t db)
Unbind Devemu PCI Device DB handle from the Devemu PCI Device DB completion context.
DOCA_EXPERIMENTAL int doca_dpa_dev_devemu_pci_get_db_completion(doca_dpa_dev_devemu_pci_db_completion_t comp, doca_dpa_dev_devemu_pci_db_completion_element_t *comp_element)
Get Devemu PCI Device DB completion element.
DOCA_EXPERIMENTAL void doca_dpa_dev_thread_reschedule(void)
Reschedule a DPA thread.
#define DOCA_DPA_DEV_LOG_INFO(...)
Generate a DOCA DPA device INFO log message.
Definition: doca_dpa_dev.h:287
uint64_t doca_dpa_dev_uintptr_t
DPA pointer type definition.
Definition: doca_dpa.h:78