NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
devemu_pci_host_common.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2024 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 #ifndef DEVEMU_PCI_HOST_COMMON_H_
27 #define DEVEMU_PCI_HOST_COMMON_H_
28 
29 #include <stdbool.h>
30 
31 #include <doca_error.h>
32 #include <doca_argp.h>
33 
34 #include "devemu_pci_type_config.h"
35 
37  uint64_t size;
38  uint8_t *mem;
39 };
40 
41 struct mapped_memory {
42  uint64_t size;
43  uint8_t *mem;
44 };
45 
48  int group_fd;
49  int device_fd;
53  struct mapped_memory dma_mem;
54 };
55 
56 /*
57  * Initialize VFIO device
58  *
59  * @resources [in]: The sample resources
60  * @vfio_group [in]: The VFIO group ID
61  * @pci_address [in]: The PCI address of the VFIO device
62  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
63  */
64 doca_error_t init_vfio_device(struct devemu_host_resources *resources, int vfio_group, const char *pci_address);
65 
66 /*
67  * Map bar region to virtual memory
68  *
69  * @resources [in]: The sample resources
70  * @bar_region_config [in]: The bar region to map
71  * @mapped_mem [out]: The virtual memory of the mapped region
72  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
73  */
76  struct bar_mapped_region *mapped_mem);
77 
78 /*
79  * Cleanup resources of the sample
80  *
81  * @resources [in]: The resources of the sample
82  */
84 
85 /*
86  * Parse pci address of emulated device taken from command line
87  *
88  * @addr [in]: Input parameter received from command line
89  * @parsed_addr [out]: Used to store parsed address
90  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
91  */
92 doca_error_t parse_emulated_pci_address(const char *addr, char *parsed_addr);
93 
94 /*
95  * Register PCI address command line parameter
96  *
97  * @pci_callback [in]: Callback called for parsing the PCI address command line param
98  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
99  */
101 
102 /*
103  * Register VFIO group ID command line parameter
104  *
105  * @vfio_group_callback [in]: Callback called for parsing the VFIO group ID command line param
106  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
107  */
109 
110 /*
111  * Register region index command line parameter
112  *
113  * @description [in]: Description displayed in help message
114  * @region_callback [in]: Callback called for parsing the region index command line param
115  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
116  */
118 
119 #endif // DEVEMU_PCI_HOST_COMMON_H_
static doca_error_t pci_callback(void *param, void *config)
static doca_error_t vfio_group_callback(void *param, void *config)
void devemu_host_resources_cleanup(struct devemu_host_resources *resources)
doca_error_t register_vfio_group_param(doca_argp_param_cb_t vfio_group_callback)
doca_error_t register_region_index_param(const char *description, doca_argp_param_cb_t region_callback)
doca_error_t register_emulated_pci_address_param(doca_argp_param_cb_t pci_callback)
doca_error_t parse_emulated_pci_address(const char *addr, char *parsed_addr)
doca_error_t map_bar_region_memory(struct devemu_host_resources *resources, const struct bar_region_config *bar_region_config, struct bar_mapped_region *mapped_mem)
doca_error_t init_vfio_device(struct devemu_host_resources *resources, int vfio_group, const char *pci_address)
uintptr_t addr
struct rdma_resources resources
doca_error_t(* doca_argp_param_cb_t)(void *, void *)
Flag callback function type.
Definition: doca_argp.h:37
enum doca_error doca_error_t
DOCA API return codes.
type description
struct bar_mapped_region db_region
struct bar_mapped_region stateful_region
struct mapped_memory dma_mem