Andrew Geissler | 72956ed | 2021-01-08 16:11:14 -0600 | [diff] [blame] | 1 | From b6c765d693a0833b94cb2e91b32842570c3458d2 Mon Sep 17 00:00:00 2001 |
| 2 | From: vboxsync <vboxsync@cfe28804-0f27-0410-a406-dd0f0b0b656f> |
| 3 | Date: Tue, 15 Dec 2020 22:29:56 +0000 |
| 4 | Subject: [PATCH] Additions/linux/drm: Adjustment for Linux 5.10. |
| 5 | |
| 6 | Upstream-Status: Backport |
| 7 | |
| 8 | git-svn-id: http://www.virtualbox.org/svn/vbox@87092 cfe28804-0f27-0410-a406-dd0f0b0b656f |
| 9 | |
| 10 | Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com> |
| 11 | |
| 12 | --- |
| 13 | src/VBox/Additions/linux/drm/vbox_drv.h | 10 +- |
| 14 | src/VBox/Additions/linux/drm/vbox_fb.c | 2 +- |
| 15 | .../src/VBox/Additions/linux/drm/vbox_mode.c | 2 +- |
| 16 | src/VBox/Additions/linux/drm/vbox_ttm.c | 99 +++++++++++++++++-- |
| 17 | 4 files changed, 99 insertions(+), 14 deletions(-) |
| 18 | |
| 19 | diff --git a/src/VBox/Additions/linux/drm/vbox_drv.h b/src/VBox/Additions/linux/drm/vbox_drv.h |
| 20 | index 8c85371749..7937f2f2d2 100644 |
| 21 | --- a/src/VBox/Additions/linux/drm/vbox_drv.h |
| 22 | +++ b/src/VBox/Additions/linux/drm/vbox_drv.h |
| 23 | @@ -175,6 +175,9 @@ |
| 24 | #include <drm/ttm/ttm_placement.h> |
| 25 | #include <drm/ttm/ttm_memory.h> |
| 26 | #include <drm/ttm/ttm_module.h> |
| 27 | +#if RTLNX_VER_MIN(5,10,0) |
| 28 | +# include <drm/ttm/ttm_resource.h> |
| 29 | +#endif |
| 30 | |
| 31 | #include "vboxvideo_guest.h" |
| 32 | #include "vboxvideo_vbe.h" |
| 33 | @@ -444,7 +447,10 @@ int vbox_bo_create(struct drm_device *dev, int size, int align, |
| 34 | int vbox_gem_create(struct drm_device *dev, |
| 35 | u32 size, bool iskernel, struct drm_gem_object **obj); |
| 36 | |
| 37 | -int vbox_bo_pin(struct vbox_bo *bo, u32 pl_flag, u64 *gpu_addr); |
| 38 | +#define VBOX_MEM_TYPE_VRAM 0x1 |
| 39 | +#define VBOX_MEM_TYPE_SYSTEM 0x2 |
| 40 | + |
| 41 | +int vbox_bo_pin(struct vbox_bo *bo, u32 mem_type, u64 *gpu_addr); |
| 42 | int vbox_bo_unpin(struct vbox_bo *bo); |
| 43 | |
| 44 | static inline int vbox_bo_reserve(struct vbox_bo *bo, bool no_wait) |
| 45 | @@ -469,7 +475,7 @@ static inline void vbox_bo_unreserve(struct vbox_bo *bo) |
| 46 | ttm_bo_unreserve(&bo->bo); |
| 47 | } |
| 48 | |
| 49 | -void vbox_ttm_placement(struct vbox_bo *bo, int domain); |
| 50 | +void vbox_ttm_placement(struct vbox_bo *bo, u32 mem_type); |
| 51 | int vbox_bo_push_sysram(struct vbox_bo *bo); |
| 52 | int vbox_mmap(struct file *filp, struct vm_area_struct *vma); |
| 53 | |
| 54 | diff --git a/src/VBox/Additions/linux/drm/vbox_fb.c b/src/VBox/Additions/linux/drm/vbox_fb.c |
| 55 | index adead98d3d..7182d9da1a 100644 |
| 56 | --- a/src/VBox/Additions/linux/drm/vbox_fb.c |
| 57 | +++ b/src/VBox/Additions/linux/drm/vbox_fb.c |
| 58 | @@ -295,7 +295,7 @@ static int vboxfb_create(struct drm_fb_helper *helper, |
| 59 | if (ret) |
| 60 | return ret; |
| 61 | |
| 62 | - ret = vbox_bo_pin(bo, TTM_PL_FLAG_VRAM, NULL); |
| 63 | + ret = vbox_bo_pin(bo, VBOX_MEM_TYPE_VRAM, NULL); |
| 64 | if (ret) { |
| 65 | vbox_bo_unreserve(bo); |
| 66 | return ret; |
| 67 | diff --git a/src/VBox/Additions/linux/drm/vbox_mode.c b/src/VBox/Additions/linux/drm/vbox_mode.c |
| 68 | index ce7d135cb6..5557db5ef8 100644 |
| 69 | --- a/src/VBox/Additions/linux/drm/vbox_mode.c |
| 70 | +++ b/src/VBox/Additions/linux/drm/vbox_mode.c |
| 71 | @@ -227,7 +227,7 @@ static int vbox_crtc_set_base(struct drm_crtc *crtc, |
| 72 | if (ret) |
| 73 | return ret; |
| 74 | |
| 75 | - ret = vbox_bo_pin(bo, TTM_PL_FLAG_VRAM, &gpu_addr); |
| 76 | + ret = vbox_bo_pin(bo, VBOX_MEM_TYPE_VRAM, &gpu_addr); |
| 77 | vbox_bo_unreserve(bo); |
| 78 | if (ret) |
| 79 | return ret; |
| 80 | diff --git a/src/VBox/Additions/linux/drm/vbox_ttm.c b/src/VBox/Additions/linux/drm/vbox_ttm.c |
| 81 | index bf87aabc05..5eac926a42 100644 |
| 82 | --- a/src/VBox/Additions/linux/drm/vbox_ttm.c |
| 83 | +++ b/src/VBox/Additions/linux/drm/vbox_ttm.c |
| 84 | @@ -41,6 +41,7 @@ |
| 85 | #define PLACEMENT_FLAGS(placement) ((placement).flags) |
| 86 | #endif |
| 87 | |
| 88 | + |
| 89 | static inline struct vbox_private *vbox_bdev(struct ttm_bo_device *bd) |
| 90 | { |
| 91 | return container_of(bd, struct vbox_private, ttm.bdev); |
| 92 | @@ -125,6 +126,7 @@ static bool vbox_ttm_bo_is_vbox_bo(struct ttm_buffer_object *bo) |
| 93 | return false; |
| 94 | } |
| 95 | |
| 96 | +#if RTLNX_VER_MAX(5,10,0) |
| 97 | static int |
| 98 | vbox_bo_init_mem_type(struct ttm_bo_device *bdev, u32 type, |
| 99 | struct ttm_mem_type_manager *man) |
| 100 | @@ -148,6 +150,7 @@ vbox_bo_init_mem_type(struct ttm_bo_device *bdev, u32 type, |
| 101 | |
| 102 | return 0; |
| 103 | } |
| 104 | +#endif |
| 105 | |
| 106 | static void |
| 107 | vbox_bo_evict_flags(struct ttm_buffer_object *bo, struct ttm_placement *pl) |
| 108 | @@ -157,7 +160,7 @@ vbox_bo_evict_flags(struct ttm_buffer_object *bo, struct ttm_placement *pl) |
| 109 | if (!vbox_ttm_bo_is_vbox_bo(bo)) |
| 110 | return; |
| 111 | |
| 112 | - vbox_ttm_placement(vboxbo, TTM_PL_FLAG_SYSTEM); |
| 113 | + vbox_ttm_placement(vboxbo, VBOX_MEM_TYPE_SYSTEM); |
| 114 | *pl = vboxbo->placement; |
| 115 | } |
| 116 | |
| 117 | @@ -167,11 +170,12 @@ static int vbox_bo_verify_access(struct ttm_buffer_object *bo, |
| 118 | return 0; |
| 119 | } |
| 120 | |
| 121 | +#if RTLNX_VER_MAX(5,10,0) |
| 122 | static int vbox_ttm_io_mem_reserve(struct ttm_bo_device *bdev, |
| 123 | struct ttm_mem_reg *mem) |
| 124 | { |
| 125 | - struct ttm_mem_type_manager *man = &bdev->man[mem->mem_type]; |
| 126 | struct vbox_private *vbox = vbox_bdev(bdev); |
| 127 | + struct ttm_mem_type_manager *man = &bdev->man[mem->mem_type]; |
| 128 | |
| 129 | mem->bus.addr = NULL; |
| 130 | mem->bus.offset = 0; |
| 131 | @@ -194,12 +198,53 @@ static int vbox_ttm_io_mem_reserve(struct ttm_bo_device *bdev, |
| 132 | } |
| 133 | return 0; |
| 134 | } |
| 135 | +#else |
| 136 | +static int vbox_ttm_io_mem_reserve(struct ttm_bo_device *bdev, |
| 137 | + struct ttm_resource *mem) |
| 138 | +{ |
| 139 | + struct vbox_private *vbox = vbox_bdev(bdev); |
| 140 | + mem->bus.addr = NULL; |
| 141 | + mem->bus.offset = 0; |
| 142 | + mem->size = mem->num_pages << PAGE_SHIFT; |
| 143 | + mem->start = 0; |
| 144 | + mem->bus.is_iomem = false; |
| 145 | + switch (mem->mem_type) { |
| 146 | + case TTM_PL_SYSTEM: |
| 147 | + /* system memory */ |
| 148 | + return 0; |
| 149 | + case TTM_PL_VRAM: |
| 150 | + mem->bus.offset = mem->start << PAGE_SHIFT; |
| 151 | + mem->start = pci_resource_start(vbox->dev->pdev, 0); |
| 152 | + mem->bus.is_iomem = true; |
| 153 | + break; |
| 154 | + default: |
| 155 | + return -EINVAL; |
| 156 | + } |
| 157 | + return 0; |
| 158 | +} |
| 159 | +#endif |
| 160 | |
| 161 | + |
| 162 | + |
| 163 | +#if RTLNX_VER_MIN(5,10,0) |
| 164 | +static void vbox_ttm_io_mem_free(struct ttm_bo_device *bdev, |
| 165 | + struct ttm_resource *mem) |
| 166 | +{ |
| 167 | +} |
| 168 | +#else |
| 169 | static void vbox_ttm_io_mem_free(struct ttm_bo_device *bdev, |
| 170 | struct ttm_mem_reg *mem) |
| 171 | { |
| 172 | } |
| 173 | +#endif |
| 174 | |
| 175 | +#if RTLNX_VER_MIN(5,10,0) |
| 176 | +static void vbox_ttm_tt_destroy(struct ttm_bo_device *bdev, struct ttm_tt *tt) |
| 177 | +{ |
| 178 | + ttm_tt_fini(tt); |
| 179 | + kfree(tt); |
| 180 | +} |
| 181 | +#else |
| 182 | static void vbox_ttm_backend_destroy(struct ttm_tt *tt) |
| 183 | { |
| 184 | ttm_tt_fini(tt); |
| 185 | @@ -209,6 +254,7 @@ static void vbox_ttm_backend_destroy(struct ttm_tt *tt) |
| 186 | static struct ttm_backend_func vbox_tt_backend_func = { |
| 187 | .destroy = &vbox_ttm_backend_destroy, |
| 188 | }; |
| 189 | +#endif |
| 190 | |
| 191 | #if RTLNX_VER_MAX(4,17,0) && !RTLNX_RHEL_MAJ_PREREQ(7,6) && !RTLNX_SUSE_MAJ_PREREQ(15,1) && !RTLNX_SUSE_MAJ_PREREQ(12,5) |
| 192 | static struct ttm_tt *vbox_ttm_tt_create(struct ttm_bo_device *bdev, |
| 193 | @@ -226,7 +272,9 @@ static struct ttm_tt *vbox_ttm_tt_create(struct ttm_buffer_object *bo, |
| 194 | if (!tt) |
| 195 | return NULL; |
| 196 | |
| 197 | +#if RTLNX_VER_MAX(5,10,0) |
| 198 | tt->func = &vbox_tt_backend_func; |
| 199 | +#endif |
| 200 | #if RTLNX_VER_MAX(4,17,0) && !RTLNX_RHEL_MAJ_PREREQ(7,6) && !RTLNX_SUSE_MAJ_PREREQ(15,1) && !RTLNX_SUSE_MAJ_PREREQ(12,5) |
| 201 | if (ttm_tt_init(tt, bdev, size, page_flags, dummy_read_page)) { |
| 202 | #else |
| 203 | @@ -261,11 +309,16 @@ static void vbox_ttm_tt_unpopulate(struct ttm_tt *ttm) |
| 204 | |
| 205 | static struct ttm_bo_driver vbox_bo_driver = { |
| 206 | .ttm_tt_create = vbox_ttm_tt_create, |
| 207 | +#if RTLNX_VER_MIN(5,10,0) |
| 208 | + .ttm_tt_destroy = vbox_ttm_tt_destroy, |
| 209 | +#endif |
| 210 | #if RTLNX_VER_MAX(4,17,0) |
| 211 | .ttm_tt_populate = vbox_ttm_tt_populate, |
| 212 | .ttm_tt_unpopulate = vbox_ttm_tt_unpopulate, |
| 213 | #endif |
| 214 | +#if RTLNX_VER_MAX(5,10,0) |
| 215 | .init_mem_type = vbox_bo_init_mem_type, |
| 216 | +#endif |
| 217 | #if RTLNX_VER_MIN(4,10,0) || RTLNX_RHEL_MAJ_PREREQ(7,4) |
| 218 | .eviction_valuable = ttm_bo_eviction_valuable, |
| 219 | #endif |
| 220 | @@ -318,8 +371,13 @@ int vbox_mm_init(struct vbox_private *vbox) |
| 221 | #endif |
| 222 | } |
| 223 | |
| 224 | +#if RTLNX_VER_MIN(5,10,0) |
| 225 | + ret = ttm_range_man_init(bdev, TTM_PL_VRAM, false, |
| 226 | + vbox->available_vram_size >> PAGE_SHIFT); |
| 227 | +#else |
| 228 | ret = ttm_bo_init_mm(bdev, TTM_PL_VRAM, |
| 229 | vbox->available_vram_size >> PAGE_SHIFT); |
| 230 | +#endif |
| 231 | if (ret) { |
| 232 | DRM_ERROR("Failed ttm VRAM init: %d\n", ret); |
| 233 | goto err_device_release; |
| 234 | @@ -359,7 +417,7 @@ void vbox_mm_fini(struct vbox_private *vbox) |
| 235 | #endif |
| 236 | } |
| 237 | |
| 238 | -void vbox_ttm_placement(struct vbox_bo *bo, int domain) |
| 239 | +void vbox_ttm_placement(struct vbox_bo *bo, u32 mem_type) |
| 240 | { |
| 241 | u32 c = 0; |
| 242 | #if RTLNX_VER_MAX(3,18,0) && !RTLNX_RHEL_MAJ_PREREQ(7,2) |
| 243 | @@ -372,15 +430,36 @@ void vbox_ttm_placement(struct vbox_bo *bo, int domain) |
| 244 | bo->placement.placement = bo->placements; |
| 245 | bo->placement.busy_placement = bo->placements; |
| 246 | |
| 247 | - if (domain & TTM_PL_FLAG_VRAM) |
| 248 | + if (mem_type & VBOX_MEM_TYPE_VRAM) { |
| 249 | +#if RTLNX_VER_MIN(5,10,0) |
| 250 | + bo->placements[c].mem_type = TTM_PL_VRAM; |
| 251 | + PLACEMENT_FLAGS(bo->placements[c++]) = |
| 252 | + TTM_PL_FLAG_WC | TTM_PL_FLAG_UNCACHED; |
| 253 | +#else |
| 254 | PLACEMENT_FLAGS(bo->placements[c++]) = |
| 255 | TTM_PL_FLAG_WC | TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_VRAM; |
| 256 | - if (domain & TTM_PL_FLAG_SYSTEM) |
| 257 | +#endif |
| 258 | + } |
| 259 | + if (mem_type & VBOX_MEM_TYPE_SYSTEM) { |
| 260 | +#if RTLNX_VER_MIN(5,10,0) |
| 261 | + bo->placements[c].mem_type = TTM_PL_SYSTEM; |
| 262 | + PLACEMENT_FLAGS(bo->placements[c++]) = |
| 263 | + TTM_PL_MASK_CACHING; |
| 264 | +#else |
| 265 | PLACEMENT_FLAGS(bo->placements[c++]) = |
| 266 | TTM_PL_MASK_CACHING | TTM_PL_FLAG_SYSTEM; |
| 267 | - if (!c) |
| 268 | +#endif |
| 269 | + } |
| 270 | + if (!c) { |
| 271 | +#if RTLNX_VER_MIN(5,10,0) |
| 272 | + bo->placements[c].mem_type = TTM_PL_SYSTEM; |
| 273 | + PLACEMENT_FLAGS(bo->placements[c++]) = |
| 274 | + TTM_PL_MASK_CACHING; |
| 275 | +#else |
| 276 | PLACEMENT_FLAGS(bo->placements[c++]) = |
| 277 | TTM_PL_MASK_CACHING | TTM_PL_FLAG_SYSTEM; |
| 278 | +#endif |
| 279 | + } |
| 280 | |
| 281 | bo->placement.num_placement = c; |
| 282 | bo->placement.num_busy_placement = c; |
| 283 | @@ -414,7 +493,7 @@ int vbox_bo_create(struct drm_device *dev, int size, int align, |
| 284 | vboxbo->bo.bdev->dev_mapping = dev->dev_mapping; |
| 285 | #endif |
| 286 | |
| 287 | - vbox_ttm_placement(vboxbo, TTM_PL_FLAG_VRAM | TTM_PL_FLAG_SYSTEM); |
| 288 | + vbox_ttm_placement(vboxbo, VBOX_MEM_TYPE_VRAM | VBOX_MEM_TYPE_SYSTEM); |
| 289 | |
| 290 | acc_size = ttm_bo_dma_acc_size(&vbox->ttm.bdev, size, |
| 291 | sizeof(struct vbox_bo)); |
| 292 | @@ -452,7 +531,7 @@ static inline u64 vbox_bo_gpu_offset(struct vbox_bo *bo) |
| 293 | #endif |
| 294 | } |
| 295 | |
| 296 | -int vbox_bo_pin(struct vbox_bo *bo, u32 pl_flag, u64 *gpu_addr) |
| 297 | +int vbox_bo_pin(struct vbox_bo *bo, u32 mem_type, u64 *gpu_addr) |
| 298 | { |
| 299 | #if RTLNX_VER_MIN(4,16,0) || RTLNX_RHEL_MAJ_PREREQ(7,6) || RTLNX_SUSE_MAJ_PREREQ(15,1) || RTLNX_SUSE_MAJ_PREREQ(12,5) |
| 300 | struct ttm_operation_ctx ctx = { false, false }; |
| 301 | @@ -467,7 +546,7 @@ int vbox_bo_pin(struct vbox_bo *bo, u32 pl_flag, u64 *gpu_addr) |
| 302 | return 0; |
| 303 | } |
| 304 | |
| 305 | - vbox_ttm_placement(bo, pl_flag); |
| 306 | + vbox_ttm_placement(bo, mem_type); |
| 307 | |
| 308 | for (i = 0; i < bo->placement.num_placement; i++) |
| 309 | PLACEMENT_FLAGS(bo->placements[i]) |= TTM_PL_FLAG_NO_EVICT; |
| 310 | @@ -540,7 +619,7 @@ int vbox_bo_push_sysram(struct vbox_bo *bo) |
| 311 | if (bo->kmap.virtual) |
| 312 | ttm_bo_kunmap(&bo->kmap); |
| 313 | |
| 314 | - vbox_ttm_placement(bo, TTM_PL_FLAG_SYSTEM); |
| 315 | + vbox_ttm_placement(bo, VBOX_MEM_TYPE_SYSTEM); |
| 316 | |
| 317 | for (i = 0; i < bo->placement.num_placement; i++) |
| 318 | PLACEMENT_FLAGS(bo->placements[i]) |= TTM_PL_FLAG_NO_EVICT; |
| 319 | -- |
| 320 | 2.19.1 |
| 321 | |