File fixes_for_4.16.patch of Package virtualbox.openSUSE_Leap_42.3_Update
Index: VirtualBox-5.1.34/src/VBox/Additions/linux/drm/vbox_ttm.c
===================================================================
--- VirtualBox-5.1.34.orig/src/VBox/Additions/linux/drm/vbox_ttm.c
+++ VirtualBox-5.1.34/src/VBox/Additions/linux/drm/vbox_ttm.c
@@ -215,6 +215,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,
@@ -230,6 +241,7 @@ static int vbox_bo_move(struct ttm_buffe
#endif
return r;
}
+#endif
static void vbox_ttm_backend_destroy(struct ttm_tt *tt)
{
@@ -259,16 +271,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);
+ 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,
@@ -281,10 +325,15 @@ struct ttm_bo_driver vbox_bo_driver = {
.move = vbox_bo_move,
.verify_access = vbox_bo_verify_access,
.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,
@@ -432,6 +481,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) {
@@ -444,9 +496,14 @@ int vbox_bo_pin(struct vbox_bo *bo, u32
vbox_ttm_placement(bo, pl_flag);
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);
- if (ret)
- return ret;
+#endif
+ if (ret)
+ return ret;
bo->pin_count = 1;
if (gpu_addr)
@@ -456,6 +513,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) {
DRM_ERROR("unpin bad %p\n", bo);
@@ -467,7 +527,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;
@@ -479,6 +543,9 @@ int vbox_bo_unpin(struct vbox_bo *bo)
* release the caller's pin. */
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) {
DRM_ERROR("unpin bad %p\n", bo);
@@ -495,7 +562,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;