1
0
forked from pool/virtualbox
virtualbox/fixes_for_4.16.patch

159 lines
4.6 KiB
Diff

Index: VirtualBox-5.2.8/src/VBox/Additions/linux/drm/vbox_ttm.c
===================================================================
--- VirtualBox-5.2.8.orig/src/VBox/Additions/linux/drm/vbox_ttm.c
+++ VirtualBox-5.2.8/src/VBox/Additions/linux/drm/vbox_ttm.c
@@ -198,6 +198,17 @@ static void vbox_ttm_io_mem_free(struct
{
}
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0)
+static int vbox_bo_move(struct ttm_buffer_object *bo, bool evict,
+ struct ttm_operation_ctx *ctx,
+ struct ttm_mem_reg *new_mem)
+{
+ int r;
+
+ r = ttm_bo_move_memcpy(bo, ctx, new_mem);
+ return r;
+}
+#else
static int vbox_bo_move(struct ttm_buffer_object *bo,
bool evict, bool interruptible,
bool no_wait_gpu, struct ttm_mem_reg *new_mem)
@@ -213,6 +224,7 @@ static int vbox_bo_move(struct ttm_buffe
#endif
return r;
}
+#endif
static void vbox_ttm_backend_destroy(struct ttm_tt *tt)
{
@@ -244,16 +256,48 @@ static struct ttm_tt *vbox_ttm_tt_create
return tt;
}
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0)
+static int vbox_ttm_tt_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
+{
+ return ttm_pool_populate(ttm, ctx);
+}
+#else
static int vbox_ttm_tt_populate(struct ttm_tt *ttm)
{
return ttm_pool_populate(ttm);
}
+#endif
static void vbox_ttm_tt_unpopulate(struct ttm_tt *ttm)
{
ttm_pool_unpopulate(ttm);
}
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0)
+static struct drm_mm_node *vbox_find_mm_node(struct ttm_mem_reg *mem,
+ unsigned long *offset)
+{
+ struct drm_mm_node *mm_node = mem->mm_node;
+
+ while (*offset >= (mm_node->size << PAGE_SHIFT)) {
+ *offset -= (mm_node->size << PAGE_SHIFT);
+ ++mm_node;
+ }
+ return mm_node;
+}
+
+static unsigned long vbox_ttm_io_mem_pfn(struct ttm_buffer_object *bo,
+ unsigned long page_offset)
+{
+ struct drm_mm_node *mm;
+ unsigned long offset = (page_offset << PAGE_SHIFT);
+
+ mm = vbox_find_mm_node(&bo->mem, &offset);
+ return (bo->mem.bus.base >> PAGE_SHIFT) + mm->start +
+ (offset >> PAGE_SHIFT);
+}
+#endif
+
struct ttm_bo_driver vbox_bo_driver = {
.ttm_tt_create = vbox_ttm_tt_create,
.ttm_tt_populate = vbox_ttm_tt_populate,
@@ -268,8 +312,12 @@ struct ttm_bo_driver vbox_bo_driver = {
.io_mem_reserve = &vbox_ttm_io_mem_reserve,
.io_mem_free = &vbox_ttm_io_mem_free,
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0)
+ .io_mem_pfn = vbox_ttm_io_mem_pfn,
+#else
.io_mem_pfn = ttm_bo_default_io_mem_pfn,
#endif
+#endif
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0) && LINUX_VERSION_CODE < KERNEL_VERSION(4, 11, 0)) \
|| defined(RHEL_74)
.lru_tail = &ttm_bo_default_lru_tail,
@@ -422,6 +470,9 @@ static inline u64 vbox_bo_gpu_offset(str
int vbox_bo_pin(struct vbox_bo *bo, u32 pl_flag, u64 *gpu_addr)
{
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0)
+ struct ttm_operation_ctx ctx = {false, false};
+#endif
int i, ret;
if (bo->pin_count) {
@@ -437,7 +488,11 @@ int vbox_bo_pin(struct vbox_bo *bo, u32
for (i = 0; i < bo->placement.num_placement; i++)
PLACEMENT_FLAGS(bo->placements[i]) |= TTM_PL_FLAG_NO_EVICT;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0)
+ ret = ttm_bo_validate(&bo->bo, &bo->placement, &ctx);
+#else
ret = ttm_bo_validate(&bo->bo, &bo->placement, false, false);
+#endif
if (ret)
return ret;
@@ -451,6 +506,9 @@ int vbox_bo_pin(struct vbox_bo *bo, u32
int vbox_bo_unpin(struct vbox_bo *bo)
{
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0)
+ struct ttm_operation_ctx ctx = {false, false};
+#endif
int i, ret;
if (!bo->pin_count) {
@@ -464,7 +522,11 @@ int vbox_bo_unpin(struct vbox_bo *bo)
for (i = 0; i < bo->placement.num_placement; i++)
PLACEMENT_FLAGS(bo->placements[i]) &= ~TTM_PL_FLAG_NO_EVICT;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0)
+ ret = ttm_bo_validate(&bo->bo, &bo->placement, &ctx);
+#else
ret = ttm_bo_validate(&bo->bo, &bo->placement, false, false);
+#endif
if (ret)
return ret;
@@ -478,6 +540,9 @@ int vbox_bo_unpin(struct vbox_bo *bo)
*/
int vbox_bo_push_sysram(struct vbox_bo *bo)
{
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0)
+ struct ttm_operation_ctx ctx = {false, false};
+#endif
int i, ret;
if (!bo->pin_count) {
@@ -496,7 +561,11 @@ int vbox_bo_push_sysram(struct vbox_bo *
for (i = 0; i < bo->placement.num_placement; i++)
PLACEMENT_FLAGS(bo->placements[i]) |= TTM_PL_FLAG_NO_EVICT;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0)
+ ret = ttm_bo_validate(&bo->bo, &bo->placement, &ctx);
+#else
ret = ttm_bo_validate(&bo->bo, &bo->placement, false, false);
+#endif
if (ret) {
DRM_ERROR("pushing to VRAM failed\n");
return ret;