diff options
Diffstat (limited to 'drivers/gpu')
-rw-r--r-- | drivers/gpu/nvgpu/include/nvgpu/linux/nvidia_p2p.h | 196 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/os/linux/nvidia_p2p.c | 2 |
2 files changed, 1 insertions, 197 deletions
diff --git a/drivers/gpu/nvgpu/include/nvgpu/linux/nvidia_p2p.h b/drivers/gpu/nvgpu/include/nvgpu/linux/nvidia_p2p.h deleted file mode 100644 index c1dee7cf..00000000 --- a/drivers/gpu/nvgpu/include/nvgpu/linux/nvidia_p2p.h +++ /dev/null | |||
@@ -1,196 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. | ||
3 | * | ||
4 | * Permission is hereby granted, free of charge, to any person obtaining a | ||
5 | * copy of this software and associated documentation files (the "Software"), | ||
6 | * to deal in the Software without restriction, including without limitation | ||
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
8 | * and/or sell copies of the Software, and to permit persons to whom the | ||
9 | * Software is furnished to do so, subject to the following conditions: | ||
10 | * | ||
11 | * The above copyright notice and this permission notice shall be included in | ||
12 | * all copies or substantial portions of the Software. | ||
13 | * | ||
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
20 | * DEALINGS IN THE SOFTWARE. | ||
21 | */ | ||
22 | |||
23 | #ifndef __NVIDIA_P2P_H__ | ||
24 | #define __NVIDIA_P2P_H__ | ||
25 | |||
26 | #include <linux/dma-mapping.h> | ||
27 | #include <linux/module.h> | ||
28 | #include <linux/kernel.h> | ||
29 | #include <linux/init.h> | ||
30 | #include <linux/miscdevice.h> | ||
31 | #include <linux/fs.h> | ||
32 | #include <linux/mm.h> | ||
33 | #include <linux/mman.h> | ||
34 | #include <linux/mmu_notifier.h> | ||
35 | #include <linux/types.h> | ||
36 | #include <linux/uaccess.h> | ||
37 | #include <linux/sched.h> | ||
38 | #include <linux/spinlock.h> | ||
39 | #include <linux/slab.h> | ||
40 | #include <linux/highmem.h> | ||
41 | #include <linux/mutex.h> | ||
42 | #include <linux/spinlock.h> | ||
43 | #include <nvgpu/linux/lock.h> | ||
44 | |||
45 | #define NVIDIA_P2P_UNINITIALIZED 0x0 | ||
46 | #define NVIDIA_P2P_PINNED 0x1 | ||
47 | #define NVIDIA_P2P_MAPPED 0x2 | ||
48 | |||
49 | enum nvidia_p2p_page_size_type { | ||
50 | NVIDIA_P2P_PAGE_SIZE_4KB = 0, | ||
51 | NVIDIA_P2P_PAGE_SIZE_64KB, | ||
52 | NVIDIA_P2P_PAGE_SIZE_128KB, | ||
53 | NVIDIA_P2P_PAGE_SIZE_COUNT | ||
54 | }; | ||
55 | |||
56 | struct nvidia_p2p_page_table { | ||
57 | u32 page_size; | ||
58 | u64 size; | ||
59 | u32 entries; | ||
60 | struct page **pages; | ||
61 | |||
62 | u64 vaddr; | ||
63 | u32 mapped; | ||
64 | |||
65 | struct mm_struct *mm; | ||
66 | struct mmu_notifier mn; | ||
67 | struct nvgpu_mutex lock; | ||
68 | void (*free_callback)(void *data); | ||
69 | void *data; | ||
70 | }; | ||
71 | |||
72 | struct nvidia_p2p_dma_mapping { | ||
73 | dma_addr_t *hw_address; | ||
74 | u32 *hw_len; | ||
75 | u32 entries; | ||
76 | |||
77 | struct sg_table *sgt; | ||
78 | struct device *dev; | ||
79 | struct nvidia_p2p_page_table *page_table; | ||
80 | enum dma_data_direction direction; | ||
81 | }; | ||
82 | |||
83 | /* | ||
84 | * @brief | ||
85 | * Make the pages underlying a range of GPU virtual memory | ||
86 | * accessible to a third-party device. | ||
87 | * | ||
88 | * @param[in] vaddr | ||
89 | * A GPU Virtual Address | ||
90 | * @param[in] size | ||
91 | * The size of the requested mapping. | ||
92 | * Size must be a multiple of Page size. | ||
93 | * @param[out] **page_table | ||
94 | * A pointer to struct nvidia_p2p_page_table | ||
95 | * @param[in] free_callback | ||
96 | * A non-NULL pointer to the function to be invoked when the pages | ||
97 | * underlying the virtual address range are freed | ||
98 | * implicitly. Must be non NULL. | ||
99 | * @param[in] data | ||
100 | * A non-NULL opaque pointer to private data to be passed to the | ||
101 | * callback function. | ||
102 | * | ||
103 | * @return | ||
104 | * 0 upon successful completion. | ||
105 | * Negative number if any error | ||
106 | */ | ||
107 | int nvidia_p2p_get_pages(u64 vaddr, u64 size, | ||
108 | struct nvidia_p2p_page_table **page_table, | ||
109 | void (*free_callback)(void *data), void *data); | ||
110 | /* | ||
111 | * @brief | ||
112 | * Release the pages previously made accessible to | ||
113 | * a third-party device. | ||
114 | * | ||
115 | * @param[in] *page_table | ||
116 | * A pointer to struct nvidia_p2p_page_table | ||
117 | * | ||
118 | * @return | ||
119 | * 0 upon successful completion. | ||
120 | * -ENOMEM if the driver failed to allocate memory or if | ||
121 | * insufficient resources were available to complete the operation. | ||
122 | * Negative number if any other error | ||
123 | */ | ||
124 | int nvidia_p2p_put_pages(struct nvidia_p2p_page_table *page_table); | ||
125 | |||
126 | /* | ||
127 | * @brief | ||
128 | * Release the pages previously made accessible to | ||
129 | * a third-party device. This is called during the | ||
130 | * execution of the free_callback(). | ||
131 | * | ||
132 | * @param[in] *page_table | ||
133 | * A pointer to struct nvidia_p2p_page_table | ||
134 | * | ||
135 | * @return | ||
136 | * 0 upon successful completion. | ||
137 | * -ENOMEM if the driver failed to allocate memory or if | ||
138 | * insufficient resources were available to complete the operation. | ||
139 | * Negative number if any other error | ||
140 | */ | ||
141 | int nvidia_p2p_free_page_table(struct nvidia_p2p_page_table *page_table); | ||
142 | |||
143 | /* | ||
144 | * @brief | ||
145 | * Map the pages retrieved using nvidia_p2p_get_pages and | ||
146 | * pass the dma address to a third-party device. | ||
147 | * | ||
148 | * @param[in] *dev | ||
149 | * The peer device that needs to DMA to/from the | ||
150 | * mapping. | ||
151 | * @param[in] *page_table | ||
152 | * A pointer to struct nvidia_p2p_page_table | ||
153 | * @param[out] **map | ||
154 | * A pointer to struct nvidia_p2p_dma_mapping. | ||
155 | * The DMA mapping containing the DMA addresses to use. | ||
156 | * @param[in] direction | ||
157 | * DMA direction | ||
158 | * | ||
159 | * @return | ||
160 | * 0 upon successful completion. | ||
161 | * Negative number if any other error | ||
162 | */ | ||
163 | int nvidia_p2p_map_pages(struct device *dev, | ||
164 | struct nvidia_p2p_page_table *page_table, | ||
165 | struct nvidia_p2p_dma_mapping **map, | ||
166 | enum dma_data_direction direction); | ||
167 | /* | ||
168 | * @brief | ||
169 | * Unmap the pages previously mapped using nvidia_p2p_map_pages | ||
170 | * | ||
171 | * @param[in] *map | ||
172 | * A pointer to struct nvidia_p2p_dma_mapping. | ||
173 | * The DMA mapping containing the DMA addresses to use. | ||
174 | * | ||
175 | * @return | ||
176 | * 0 upon successful completion. | ||
177 | * Negative number if any other error | ||
178 | */ | ||
179 | int nvidia_p2p_unmap_pages(struct nvidia_p2p_dma_mapping *map); | ||
180 | |||
181 | /* | ||
182 | * @brief | ||
183 | * Unmap the pages previously mapped using nvidia_p2p_map_pages. | ||
184 | * This is called during the execution of the free_callback(). | ||
185 | * | ||
186 | * @param[in] *map | ||
187 | * A pointer to struct nvidia_p2p_dma_mapping. | ||
188 | * The DMA mapping containing the DMA addresses to use. | ||
189 | * | ||
190 | * @return | ||
191 | * 0 upon successful completion. | ||
192 | * Negative number if any other error | ||
193 | */ | ||
194 | int nvidia_p2p_free_dma_mapping(struct nvidia_p2p_dma_mapping *dma_mapping); | ||
195 | |||
196 | #endif | ||
diff --git a/drivers/gpu/nvgpu/os/linux/nvidia_p2p.c b/drivers/gpu/nvgpu/os/linux/nvidia_p2p.c index dcd37bee..7289f311 100644 --- a/drivers/gpu/nvgpu/os/linux/nvidia_p2p.c +++ b/drivers/gpu/nvgpu/os/linux/nvidia_p2p.c | |||
@@ -21,7 +21,7 @@ | |||
21 | */ | 21 | */ |
22 | 22 | ||
23 | #include <linux/slab.h> | 23 | #include <linux/slab.h> |
24 | #include <nvgpu/linux/nvidia_p2p.h> | 24 | #include <linux/nv-p2p.h> |
25 | 25 | ||
26 | static void nvidia_p2p_mn_release(struct mmu_notifier *mn, | 26 | static void nvidia_p2p_mn_release(struct mmu_notifier *mn, |
27 | struct mm_struct *mm) | 27 | struct mm_struct *mm) |