xref: /spdk/lib/env_dpdk/env_internal.h (revision de21d8f4e45b732c13ce5c7aa1872f73bffd38aa)
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright (c) Intel Corporation.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #ifndef SPDK_ENV_INTERNAL_H
35 #define SPDK_ENV_INTERNAL_H
36 
37 #include "spdk/stdinc.h"
38 
39 #include "spdk/env.h"
40 
41 #include <rte_config.h>
42 #include <rte_version.h>
43 #include <rte_eal.h>
44 #include <rte_bus.h>
45 #include <rte_pci.h>
46 #include <rte_bus_pci.h>
47 #include <rte_dev.h>
48 
49 #if RTE_VERSION < RTE_VERSION_NUM(19, 11, 0, 0)
50 #error RTE_VERSION is too old! Minimum 19.11 is required.
51 #endif
52 
53 extern __thread bool g_spdk_mem_do_not_notify;
54 extern struct spdk_mem_region_head g_spdk_mem_regions;
55 extern pthread_mutex_t g_spdk_mem_region_mutex;
56 
57 struct spdk_mem_region {
58 	void *addr;
59 	size_t len;
60 	TAILQ_ENTRY(spdk_mem_region) tailq;
61 };
62 
63 TAILQ_HEAD(spdk_mem_region_head, spdk_mem_region);
64 
65 /* x86-64 and ARM userspace virtual addresses use only the low 48 bits [0..47],
66  * which is enough to cover 256 TB.
67  */
68 #define SHIFT_256TB	48 /* (1 << 48) == 256 TB */
69 #define MASK_256TB	((1ULL << SHIFT_256TB) - 1)
70 
71 #define SHIFT_1GB	30 /* (1 << 30) == 1 GB */
72 #define MASK_1GB	((1ULL << SHIFT_1GB) - 1)
73 
74 #define SPDK_PCI_DRIVER_MAX_NAME_LEN 32
75 struct spdk_pci_driver {
76 	struct rte_pci_driver		driver;
77 
78 	const char                      *name;
79 	const struct spdk_pci_id	*id_table;
80 	uint32_t			drv_flags;
81 
82 	spdk_pci_enum_cb		cb_fn;
83 	void				*cb_arg;
84 	TAILQ_ENTRY(spdk_pci_driver)	tailq;
85 };
86 
87 int pci_device_init(struct rte_pci_driver *driver, struct rte_pci_device *device);
88 int pci_device_fini(struct rte_pci_device *device);
89 
90 void pci_env_init(void);
91 void pci_env_reinit(void);
92 void pci_env_fini(void);
93 int mem_map_init(bool legacy_mem);
94 int vtophys_init(void);
95 void vtophys_fini(void);
96 
97 /**
98  * Report a DMA-capable PCI device to the vtophys translation code.
99  * Increases the refcount of active DMA-capable devices managed by SPDK.
100  * This must be called after a `rte_pci_device` is created.
101  */
102 void vtophys_pci_device_added(struct rte_pci_device *pci_device);
103 
104 /**
105  * Report the removal of a DMA-capable PCI device to the vtophys translation code.
106  * Decreases the refcount of active DMA-capable devices managed by SPDK.
107  * This must be called before a `rte_pci_device` is destroyed.
108  */
109 void vtophys_pci_device_removed(struct rte_pci_device *pci_device);
110 
111 #endif
112