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
36
struct
bar_mapped_region
{
37
uint64_t
size
;
38
uint8_t *
mem
;
39
};
40
41
struct
mapped_memory
{
42
uint64_t
size
;
43
uint8_t *
mem
;
44
};
45
46
struct
devemu_host_resources
{
47
int
container_fd
;
48
int
group_fd
;
49
int
device_fd
;
50
struct
bar_mapped_region
stateful_region
;
51
struct
bar_mapped_region
db_region
;
52
int
*
msix_vector_to_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
*/
74
doca_error_t
map_bar_region_memory
(
struct
devemu_host_resources
*
resources
,
75
const
struct
bar_region_config
*
bar_region_config
,
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
*/
83
void
devemu_host_resources_cleanup
(
struct
devemu_host_resources
*
resources
);
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
*/
100
doca_error_t
register_emulated_pci_address_param
(
doca_argp_param_cb_t
pci_callback
);
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
*/
108
doca_error_t
register_vfio_group_param
(
doca_argp_param_cb_t
vfio_group_callback
);
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
*/
117
doca_error_t
register_region_index_param
(
const
char
*
description
,
doca_argp_param_cb_t
region_callback);
118
119
#endif
// DEVEMU_PCI_HOST_COMMON_H_
pci_callback
static doca_error_t pci_callback(void *param, void *config)
Definition:
devemu_pci_device_db_host_main.c:63
vfio_group_callback
static doca_error_t vfio_group_callback(void *param, void *config)
Definition:
devemu_pci_device_db_host_main.c:78
devemu_host_resources_cleanup
void devemu_host_resources_cleanup(struct devemu_host_resources *resources)
Definition:
devemu_pci_host_common.c:216
register_vfio_group_param
doca_error_t register_vfio_group_param(doca_argp_param_cb_t vfio_group_callback)
Definition:
devemu_pci_host_common.c:282
register_region_index_param
doca_error_t register_region_index_param(const char *description, doca_argp_param_cb_t region_callback)
Definition:
devemu_pci_host_common.c:307
register_emulated_pci_address_param
doca_error_t register_emulated_pci_address_param(doca_argp_param_cb_t pci_callback)
Definition:
devemu_pci_host_common.c:257
parse_emulated_pci_address
doca_error_t parse_emulated_pci_address(const char *addr, char *parsed_addr)
Definition:
devemu_pci_host_common.c:235
map_bar_region_memory
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)
Definition:
devemu_pci_host_common.c:171
init_vfio_device
doca_error_t init_vfio_device(struct devemu_host_resources *resources, int vfio_group, const char *pci_address)
Definition:
devemu_pci_host_common.c:135
devemu_pci_type_config.h
doca_argp.h
addr
uintptr_t addr
Definition:
doca_dpa_dev_buf.h:0
doca_error.h
resources
struct rdma_resources resources
Definition:
gpunetio_rdma_client_server_write_sample.c:43
doca_argp_param_cb_t
doca_error_t(* doca_argp_param_cb_t)(void *, void *)
Flag callback function type.
Definition:
doca_argp.h:37
doca_error_t
enum doca_error doca_error_t
DOCA API return codes.
description
type description
Definition:
meson_options.txt:31
stdbool.h
bar_mapped_region
Definition:
devemu_pci_host_common.h:36
bar_mapped_region::size
uint64_t size
Definition:
devemu_pci_host_common.h:37
bar_mapped_region::mem
uint8_t * mem
Definition:
devemu_pci_host_common.h:38
bar_region_config
Definition:
nvme_pci_type_config.h:47
devemu_host_resources
Definition:
devemu_pci_host_common.h:46
devemu_host_resources::db_region
struct bar_mapped_region db_region
Definition:
devemu_pci_host_common.h:51
devemu_host_resources::msix_vector_to_fd
int * msix_vector_to_fd
Definition:
devemu_pci_host_common.h:52
devemu_host_resources::stateful_region
struct bar_mapped_region stateful_region
Definition:
devemu_pci_host_common.h:50
devemu_host_resources::dma_mem
struct mapped_memory dma_mem
Definition:
devemu_pci_host_common.h:53
devemu_host_resources::device_fd
int device_fd
Definition:
devemu_pci_host_common.h:49
devemu_host_resources::group_fd
int group_fd
Definition:
devemu_pci_host_common.h:48
devemu_host_resources::container_fd
int container_fd
Definition:
devemu_pci_host_common.h:47
mapped_memory
Definition:
devemu_pci_host_common.h:41
mapped_memory::size
uint64_t size
Definition:
devemu_pci_host_common.h:42
mapped_memory::mem
uint8_t * mem
Definition:
devemu_pci_host_common.h:43
samples
doca_devemu
devemu_pci_host_common.h
Generated on Wed Aug 13 2025 09:23:36 for NVIDIA DOCA SDK by
1.9.1