Skip to content

Instantly share code, notes, and snippets.

@pimlie
Last active December 27, 2017 17:49
Show Gist options
  • Save pimlie/e0415b49d57a22e91d376ebd66f614ea to your computer and use it in GitHub Desktop.
Save pimlie/e0415b49d57a22e91d376ebd66f614ea to your computer and use it in GitHub Desktop.
Patch to run amdgpu-pro 17.50 on a v4.14 Ubuntu mainline kernel ** not perfect, runs but crashes on drm_object_property_(g|s)et_value **
diff --git a/amd/amdgpu/amdgpu_drv.c b/amd/amdgpu/amdgpu_drv.c
index e55a293..64f9090 100644
--- a/amd/amdgpu/amdgpu_drv.c
+++ b/amd/amdgpu/amdgpu_drv.c
@@ -826,7 +826,9 @@ static struct drm_driver kms_driver = {
.open = amdgpu_driver_open_kms,
.postclose = amdgpu_driver_postclose_kms,
.lastclose = amdgpu_driver_lastclose_kms,
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0)
.set_busid = drm_pci_set_busid,
+#endif
.unload = amdgpu_driver_unload_kms,
.get_vblank_counter = kcl_amdgpu_get_vblank_counter_kms,
.enable_vblank = kcl_amdgpu_enable_vblank_kms,
diff --git a/amd/amdgpu/amdgpu_fb.c b/amd/amdgpu/amdgpu_fb.c
index b81ba88..0635b2f 100644
--- a/amd/amdgpu/amdgpu_fb.c
+++ b/amd/amdgpu/amdgpu_fb.c
@@ -334,6 +334,7 @@ static int amdgpu_fbdev_destroy(struct drm_device *dev, struct amdgpu_fbdev *rfb
return 0;
}
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0)
/** Sets the color ramps on behalf of fbcon */
static void amdgpu_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
u16 blue, int regno)
@@ -355,10 +356,13 @@ static void amdgpu_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green
*green = amdgpu_crtc->lut_g[regno] << 6;
*blue = amdgpu_crtc->lut_b[regno] << 6;
}
+#endif
static const struct drm_fb_helper_funcs amdgpu_fb_helper_funcs = {
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0)
.gamma_set = amdgpu_crtc_fb_gamma_set,
.gamma_get = amdgpu_crtc_fb_gamma_get,
+#endif
.fb_probe = amdgpufb_create,
};
diff --git a/amd/amdgpu/amdgpu_irq.c b/amd/amdgpu/amdgpu_irq.c
index e1cbe19..4af88b5 100644
--- a/amd/amdgpu/amdgpu_irq.c
+++ b/amd/amdgpu/amdgpu_irq.c
@@ -277,7 +277,9 @@ void amdgpu_irq_fini(struct amdgpu_device *adev)
{
unsigned i, j;
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0)
drm_vblank_cleanup(adev->ddev);
+#endif
if (adev->irq.installed) {
drm_irq_uninstall(adev->ddev);
adev->irq.installed = false;
diff --git a/amd/amdgpu/amdgpu_mn.c b/amd/amdgpu/amdgpu_mn.c
index 2824dcb..c14a7fd 100644
--- a/amd/amdgpu/amdgpu_mn.c
+++ b/amd/amdgpu/amdgpu_mn.c
@@ -53,7 +53,7 @@ struct amdgpu_mn {
/* objects protected by lock */
struct rw_semaphore lock;
- struct rb_root objects;
+ struct rb_root_cached objects;
struct mutex read_lock;
atomic_t recursion;
};
@@ -80,8 +80,8 @@ static void amdgpu_mn_destroy(struct work_struct *work)
mutex_lock(&adev->mn_lock);
down_write(&rmn->lock);
hash_del(&rmn->node);
- rbtree_postorder_for_each_entry_safe(node, next_node, &rmn->objects,
- it.rb) {
+ rbtree_postorder_for_each_entry_safe(node, next_node,
+ &rmn->objects.rb_root, it.rb) {
list_for_each_entry_safe(bo, next_bo, &node->bos, mn_list) {
bo->mn = NULL;
list_del_init(&bo->mn_list);
@@ -429,7 +429,7 @@ struct amdgpu_mn *amdgpu_mn_get(struct amdgpu_device *adev,
rmn->type = type;
rmn->mn.ops = &amdgpu_mn_ops[type];
init_rwsem(&rmn->lock);
- rmn->objects = RB_ROOT;
+ rmn->objects = RB_ROOT_CACHED;
mutex_init(&rmn->read_lock);
atomic_set(&rmn->recursion, 0);
diff --git a/amd/amdgpu/amdgpu_sa.c b/amd/amdgpu/amdgpu_sa.c
index 7206b34..c8a6221 100644
--- a/amd/amdgpu/amdgpu_sa.c
+++ b/amd/amdgpu/amdgpu_sa.c
@@ -428,7 +428,8 @@ void amdgpu_sa_bo_dump_debug_info(struct amdgpu_sa_manager *sa_manager,
soffset, eoffset, eoffset - soffset);
if (i->fence)
-#if defined(BUILD_AS_DKMS)
+#if defined(BUILD_AS_DKMS) && \
+ LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0)
seq_printf(m, " protected by 0x%08x on context %d",
i->fence->seqno, i->fence->context);
#else
diff --git a/amd/amdgpu/amdgpu_vm.c b/amd/amdgpu/amdgpu_vm.c
index e339b15..6d570d6 100644
--- a/amd/amdgpu/amdgpu_vm.c
+++ b/amd/amdgpu/amdgpu_vm.c
@@ -2588,7 +2588,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
u64 flags;
uint64_t init_pde_value = 0;
- vm->va = RB_ROOT;
+ vm->va = RB_ROOT_CACHED;
vm->client_id = atomic64_inc_return(&adev->vm_manager.client_counter);
for (i = 0; i < AMDGPU_MAX_VMHUBS; i++)
vm->reserved_vmid[i] = NULL;
@@ -2752,10 +2752,11 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)
amd_sched_entity_fini(vm->entity.sched, &vm->entity);
- if (!RB_EMPTY_ROOT(&vm->va)) {
+ if (!RB_EMPTY_ROOT(&vm->va.rb_root)) {
dev_err(adev->dev, "still active bo inside vm\n");
}
- rbtree_postorder_for_each_entry_safe(mapping, tmp, &vm->va, rb) {
+ rbtree_postorder_for_each_entry_safe(mapping, tmp,
+ &vm->va.rb_root, rb) {
list_del(&mapping->list);
amdgpu_vm_it_remove(mapping, &vm->va);
kfree(mapping);
diff --git a/amd/amdgpu/amdgpu_vm.h b/amd/amdgpu/amdgpu_vm.h
index b6f1dd1..415e659 100644
--- a/amd/amdgpu/amdgpu_vm.h
+++ b/amd/amdgpu/amdgpu_vm.h
@@ -121,7 +121,7 @@ struct amdgpu_vm_pt {
struct amdgpu_vm {
/* tree of virtual addresses mapped */
- struct rb_root va;
+ struct rb_root_cached va;
/* protecting invalidated */
spinlock_t status_lock;
diff --git a/amd/amdgpu/dce_v10_0.c b/amd/amdgpu/dce_v10_0.c
index a0d77df..abd5a84 100644
--- a/amd/amdgpu/dce_v10_0.c
+++ b/amd/amdgpu/dce_v10_0.c
@@ -1739,7 +1739,11 @@ static void dce_v10_0_afmt_setmode(struct drm_encoder *encoder,
dce_v10_0_audio_write_sad_regs(encoder);
dce_v10_0_audio_write_latency_fields(encoder, mode);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0)
err = drm_hdmi_avi_infoframe_from_display_mode(&frame, mode);
+#else
+ err = drm_hdmi_avi_infoframe_from_display_mode(&frame, mode, false);
+#endif
if (err < 0) {
DRM_ERROR("failed to setup AVI infoframe: %zd\n", err);
return;
@@ -2754,7 +2758,9 @@ static const struct drm_crtc_helper_funcs dce_v10_0_crtc_helper_funcs = {
.mode_set_base_atomic = dce_v10_0_crtc_set_base_atomic,
.prepare = dce_v10_0_crtc_prepare,
.commit = dce_v10_0_crtc_commit,
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0)
.load_lut = dce_v10_0_crtc_load_lut,
+#endif
.disable = dce_v10_0_crtc_disable,
};
diff --git a/amd/amdgpu/dce_v11_0.c b/amd/amdgpu/dce_v11_0.c
index f02165d..1392a92 100644
--- a/amd/amdgpu/dce_v11_0.c
+++ b/amd/amdgpu/dce_v11_0.c
@@ -1778,7 +1778,11 @@ static void dce_v11_0_afmt_setmode(struct drm_encoder *encoder,
dce_v11_0_audio_write_sad_regs(encoder);
dce_v11_0_audio_write_latency_fields(encoder, mode);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0)
err = drm_hdmi_avi_infoframe_from_display_mode(&frame, mode);
+#else
+ err = drm_hdmi_avi_infoframe_from_display_mode(&frame, mode, false);
+#endif
if (err < 0) {
DRM_ERROR("failed to setup AVI infoframe: %zd\n", err);
return;
@@ -2857,7 +2861,9 @@ static const struct drm_crtc_helper_funcs dce_v11_0_crtc_helper_funcs = {
.mode_set_base_atomic = dce_v11_0_crtc_set_base_atomic,
.prepare = dce_v11_0_crtc_prepare,
.commit = dce_v11_0_crtc_commit,
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0)
.load_lut = dce_v11_0_crtc_load_lut,
+#endif
.disable = dce_v11_0_crtc_disable,
};
diff --git a/amd/amdgpu/dce_v6_0.c b/amd/amdgpu/dce_v6_0.c
index 270bb2a..bd76438 100644
--- a/amd/amdgpu/dce_v6_0.c
+++ b/amd/amdgpu/dce_v6_0.c
@@ -1487,7 +1487,11 @@ static void dce_v6_0_audio_set_avi_infoframe(struct drm_encoder *encoder,
ssize_t err;
u32 tmp;
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0)
err = drm_hdmi_avi_infoframe_from_display_mode(&frame, mode);
+#else
+ err = drm_hdmi_avi_infoframe_from_display_mode(&frame, mode, false);
+#endif
if (err < 0) {
DRM_ERROR("failed to setup AVI infoframe: %zd\n", err);
return;
@@ -2640,7 +2644,9 @@ static const struct drm_crtc_helper_funcs dce_v6_0_crtc_helper_funcs = {
.mode_set_base_atomic = dce_v6_0_crtc_set_base_atomic,
.prepare = dce_v6_0_crtc_prepare,
.commit = dce_v6_0_crtc_commit,
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0)
.load_lut = dce_v6_0_crtc_load_lut,
+#endif
.disable = dce_v6_0_crtc_disable,
};
diff --git a/amd/amdgpu/dce_v8_0.c b/amd/amdgpu/dce_v8_0.c
index d2f68bd..b35d1c9 100644
--- a/amd/amdgpu/dce_v8_0.c
+++ b/amd/amdgpu/dce_v8_0.c
@@ -1675,7 +1675,11 @@ static void dce_v8_0_afmt_setmode(struct drm_encoder *encoder,
dce_v8_0_audio_write_sad_regs(encoder);
dce_v8_0_audio_write_latency_fields(encoder, mode);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0)
err = drm_hdmi_avi_infoframe_from_display_mode(&frame, mode);
+#else
+ err = drm_hdmi_avi_infoframe_from_display_mode(&frame, mode, false);
+#endif
if (err < 0) {
DRM_ERROR("failed to setup AVI infoframe: %zd\n", err);
return;
@@ -2665,7 +2669,9 @@ static const struct drm_crtc_helper_funcs dce_v8_0_crtc_helper_funcs = {
.mode_set_base_atomic = dce_v8_0_crtc_set_base_atomic,
.prepare = dce_v8_0_crtc_prepare,
.commit = dce_v8_0_crtc_commit,
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0)
.load_lut = dce_v8_0_crtc_load_lut,
+#endif
.disable = dce_v8_0_crtc_disable,
};
diff --git a/amd/amdgpu/dce_virtual.c b/amd/amdgpu/dce_virtual.c
index d0c940e..9d7949f 100644
--- a/amd/amdgpu/dce_virtual.c
+++ b/amd/amdgpu/dce_virtual.c
@@ -278,7 +278,9 @@ static const struct drm_crtc_helper_funcs dce_virtual_crtc_helper_funcs = {
.mode_set_base_atomic = dce_virtual_crtc_set_base_atomic,
.prepare = dce_virtual_crtc_prepare,
.commit = dce_virtual_crtc_commit,
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0)
.load_lut = dce_virtual_crtc_load_lut,
+#endif
.disable = dce_virtual_crtc_disable,
};
diff --git a/amd/amdkfd/kfd_priv.h b/amd/amdkfd/kfd_priv.h
index fc2936b..2b3370b 100644
--- a/amd/amdkfd/kfd_priv.h
+++ b/amd/amdkfd/kfd_priv.h
@@ -726,7 +726,7 @@ struct kfd_process {
size_t signal_event_count;
bool signal_event_limit_reached;
- struct rb_root bo_interval_tree;
+ struct rb_root_cached bo_interval_tree;
/* Information used for memory eviction */
void *process_info;
diff --git a/amd/amdkfd/kfd_process.c b/amd/amdkfd/kfd_process.c
index 4080ac0..b9f7e9a 100644
--- a/amd/amdkfd/kfd_process.c
+++ b/amd/amdkfd/kfd_process.c
@@ -584,7 +584,7 @@ static struct kfd_process *create_process(const struct task_struct *thread,
if (!process)
goto err_alloc_process;
- process->bo_interval_tree = RB_ROOT;
+ process->bo_interval_tree = RB_ROOT_CACHED;
process->pasid = kfd_pasid_alloc();
if (process->pasid == 0)
diff --git a/amd/display/amdgpu_dm/amdgpu_dm.c b/amd/display/amdgpu_dm/amdgpu_dm.c
index 837bb24..5802ba9 100644
--- a/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -244,7 +244,11 @@ static void dm_pflip_high_irq(void *interrupt_params)
/* wakeup usersapce */
if (amdgpu_crtc->event) {
/* Update to correct count/ts if racing with vblank irq */
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0)
+ drm_crtc_accurate_vblank_count(&amdgpu_crtc->base);
+#else
drm_accurate_vblank_count(&amdgpu_crtc->base);
+#endif
drm_crtc_send_vblank_event(&amdgpu_crtc->base, amdgpu_crtc->event);
@@ -2685,7 +2689,9 @@ static const struct drm_crtc_funcs amdgpu_dm_crtc_funcs = {
.destroy = amdgpu_dm_crtc_destroy,
.gamma_set = drm_atomic_helper_legacy_gamma_set,
.set_config = drm_atomic_helper_set_config,
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0)
.set_property = drm_atomic_helper_crtc_set_property,
+#endif
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 11, 0)
.page_flip = amdgpu_atomic_helper_page_flip,
#else
@@ -2955,11 +2961,13 @@ struct drm_connector_state *amdgpu_dm_connector_atomic_duplicate_state(
}
static const struct drm_connector_funcs amdgpu_dm_connector_funcs = {
- .dpms = drm_atomic_helper_connector_dpms,
.reset = amdgpu_dm_connector_funcs_reset,
.detect = amdgpu_dm_connector_detect,
.fill_modes = drm_helper_probe_single_connector_modes,
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0)
+ .dpms = drm_atomic_helper_connector_dpms,
.set_property = drm_atomic_helper_connector_set_property,
+#endif
.destroy = amdgpu_dm_connector_destroy,
.atomic_duplicate_state = amdgpu_dm_connector_atomic_duplicate_state,
.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
@@ -3222,7 +3230,9 @@ static const struct drm_plane_funcs dm_plane_funcs = {
.update_plane = drm_atomic_helper_update_plane,
.disable_plane = drm_atomic_helper_disable_plane,
.destroy = drm_plane_cleanup,
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0)
.set_property = drm_atomic_helper_plane_set_property,
+#endif
.reset = dm_drm_plane_reset,
.atomic_duplicate_state = dm_drm_plane_duplicate_state,
.atomic_destroy_state = dm_drm_plane_destroy_state,
@@ -3453,7 +3463,10 @@ int amdgpu_dm_plane_init(struct amdgpu_display_manager *dm,
&dm_plane_funcs,
rgb_formats,
ARRAY_SIZE(rgb_formats),
- aplane->base.type, NULL);
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0)
+ NULL,
+#endif
+ aplane->base.type, NULL);
break;
case DRM_PLANE_TYPE_OVERLAY:
res = kcl_drm_universal_plane_init(
@@ -3463,6 +3476,9 @@ int amdgpu_dm_plane_init(struct amdgpu_display_manager *dm,
&dm_plane_funcs,
yuv_formats,
ARRAY_SIZE(yuv_formats),
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0)
+ NULL,
+#endif
aplane->base.type, NULL);
break;
case DRM_PLANE_TYPE_CURSOR:
@@ -3473,7 +3489,10 @@ int amdgpu_dm_plane_init(struct amdgpu_display_manager *dm,
&dm_plane_funcs,
cursor_formats,
ARRAY_SIZE(cursor_formats),
- aplane->base.type, NULL);
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0)
+ NULL,
+#endif
+ aplane->base.type, NULL);
break;
}
diff --git a/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c b/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c
index 84323f6..3b710a5 100644
--- a/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c
+++ b/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c
@@ -164,12 +164,14 @@ dm_dp_mst_connector_destroy(struct drm_connector *connector)
}
static const struct drm_connector_funcs dm_dp_mst_connector_funcs = {
- .dpms = drm_atomic_helper_connector_dpms,
.detect = dm_dp_mst_detect,
.fill_modes = drm_helper_probe_single_connector_modes,
.destroy = dm_dp_mst_connector_destroy,
.reset = amdgpu_dm_connector_funcs_reset,
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0)
+ .dpms = drm_atomic_helper_connector_dpms,
.set_property = drm_atomic_helper_connector_set_property,
+#endif
.atomic_duplicate_state = amdgpu_dm_connector_atomic_duplicate_state,
.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
.atomic_set_property = amdgpu_dm_connector_atomic_set_property,
diff --git a/include/kcl/kcl_drm.h b/include/kcl/kcl_drm.h
index 61100e5..d350d22 100644
--- a/include/kcl/kcl_drm.h
+++ b/include/kcl/kcl_drm.h
@@ -274,10 +274,14 @@ static inline int kcl_drm_universal_plane_init(struct drm_device *dev, struct dr
unsigned long possible_crtcs,
const struct drm_plane_funcs *funcs,
const uint32_t *formats, unsigned int format_count,
+ const uint64_t *format_modifiers,
enum drm_plane_type type,
const char *name, ...)
{
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 5, 0) || \
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0)
+ return drm_universal_plane_init(dev, plane, possible_crtcs, funcs,
+ formats, format_count, format_modifiers, type, name);
+#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 5, 0) || \
defined(OS_NAME_RHEL_7_3) || \
defined(OS_NAME_RHEL_7_4)
return drm_universal_plane_init(dev, plane, possible_crtcs, funcs,
diff --git a/include/kcl/kcl_interval_tree_generic.h b/include/kcl/kcl_interval_tree_generic.h
index c9570f7..c404ef4 100644
--- a/include/kcl/kcl_interval_tree_generic.h
+++ b/include/kcl/kcl_interval_tree_generic.h
@@ -65,7 +65,7 @@ RB_DECLARE_CALLBACKS(static, ITPREFIX ## _augment, ITSTRUCT, ITRB, \
\
/* Insert / remove interval nodes from the tree */ \
\
-ITSTATIC void ITPREFIX ## _insert(ITSTRUCT *node, struct rb_root *root) \
+ITSTATIC void ITPREFIX ## _insert(ITSTRUCT *node, struct rb_root_cached *root) \
{ \
struct rb_node **link = &root->rb_node, *rb_parent = NULL; \
ITTYPE start = ITSTART(node), last = ITLAST(node); \
@@ -87,7 +87,7 @@ ITSTATIC void ITPREFIX ## _insert(ITSTRUCT *node, struct rb_root *root) \
rb_insert_augmented(&node->ITRB, root, &ITPREFIX ## _augment); \
} \
\
-ITSTATIC void ITPREFIX ## _remove(ITSTRUCT *node, struct rb_root *root) \
+ITSTATIC void ITPREFIX ## _remove(ITSTRUCT *node, struct rb_root_cached *root) \
{ \
rb_erase_augmented(&node->ITRB, root, &ITPREFIX ## _augment); \
} \
@@ -140,7 +140,7 @@ ITPREFIX ## _subtree_search(ITSTRUCT *node, ITTYPE start, ITTYPE last) \
} \
\
ITSTATIC ITSTRUCT * \
-ITPREFIX ## _iter_first(struct rb_root *root, ITTYPE start, ITTYPE last) \
+ITPREFIX ## _iter_first(struct rb_root_cached *root, ITTYPE start, ITTYPE last) \
{ \
ITSTRUCT *node; \
\
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment