From d279bb6b9a12f073901a558bbb2cc0f0b7d41aaf Mon Sep 17 00:00:00 2001 From: "Zhao, Shirley" Date: Thu, 28 Nov 2024 14:58:06 +0800 Subject: [PATCH] dkms: optimize the dg2 kernel driver loading time 1. dkms: optimize the dg2 kernel driver loading time loaded the dGPU drvier as kernel module on boot stage, before that the driver loaded after init process lunched that took more time for driver working. 2. dkms: add module load parameters for i915_ag.ko nuclear_pageflip=1 enable_guc=0x7 max_vfs=7 modeset=1 fastboot=1 Tracked-On: OAM-127461 Signed-off-by: Zhao, Shirley Signed-off-by: yiyang.wang --- drivers/gpu/drm/i915/i915_pci.c | 46 ++++++++++++++++++++++++++++++++- kernel/module/main.c | 33 ++++++++++++++++++----- 2 files changed, 71 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_pci.c b/drivers/gpu/drm/i915/i915_pci.c index e8f814e982fa..4ab574c9c3d3 100644 --- a/drivers/gpu/drm/i915/i915_pci.c +++ b/drivers/gpu/drm/i915/i915_pci.c @@ -22,6 +22,8 @@ * */ +#include + #include #include #include @@ -1025,6 +1027,45 @@ static bool intel_mmio_bar_valid(struct pci_dev *pdev, struct intel_device_info return i915_pci_resource_valid(pdev, intel_mmio_bar(intel_info->__runtime.graphics.ip.ver)); } +extern int gfx_load_module(void *buf, int len, const char *kargs); + +static void gfx_out_of_tree_load(struct device *dev) +{ + const struct firmware *fw = NULL; + int err; + void *buf; + + err = firmware_request_nowarn(&fw, "i915/compat.ko", dev); + if (err) { + DRM_ERROR("compat load failed: %d\n", err); + return; + } + buf = __vmalloc((unsigned long)fw->size, GFP_KERNEL | __GFP_NOWARN); + memcpy(buf, fw->data, fw->size); + gfx_load_module(buf, fw->size, NULL); + DRM_INFO("compat loaded\n"); + + err = firmware_request_nowarn(&fw, "i915/intel_vsec.ko", dev); + if (err) { + DRM_ERROR("intel_vsec load failed: %d\n", err); + return; + } + buf = __vmalloc((unsigned long)fw->size, GFP_KERNEL | __GFP_NOWARN); + memcpy(buf, fw->data, fw->size); + gfx_load_module(buf, fw->size, NULL); + DRM_INFO("intel_vsec loaded\n"); + + err = firmware_request_nowarn(&fw, "i915/i915_ag.ko", dev); + if (err) { + DRM_ERROR("i915_ag load failed: %d\n", err); + return; + } + buf = __vmalloc((unsigned long)fw->size, GFP_KERNEL | __GFP_NOWARN); + memcpy(buf, fw->data, fw->size); + gfx_load_module(buf, fw->size, "nuclear_pageflip=1 enable_guc=0x7 max_vfs=7 modeset=1 fastboot=1"); + DRM_INFO("i915_ag loaded\n"); +} + static int i915_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { struct intel_device_info *intel_info = @@ -1172,7 +1213,10 @@ struct pci_dev *i915_pci_pf_get_vf_dev(struct pci_dev *pdev, unsigned int id) int i915_pci_register_driver(void) { - return pci_register_driver(&i915_pci_driver); + int ret; + ret = pci_register_driver(&i915_pci_driver); + gfx_out_of_tree_load(NULL); + return ret; } void i915_pci_unregister_driver(void) diff --git a/kernel/module/main.c b/kernel/module/main.c index 48afaf8b0d23..44260dcfdd37 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -2869,7 +2869,7 @@ static int early_mod_check(struct load_info *info, int flags) * zero, and we rely on this for optional sections. */ static int load_module(struct load_info *info, const char __user *uargs, - int flags) + const char *kargs, int flags, bool no_uargs) { struct module *mod; bool module_allocated = false; @@ -2970,10 +2970,21 @@ static int load_module(struct load_info *info, const char __user *uargs, flush_module_icache(mod); /* Now copy in args */ - mod->args = strndup_user(uargs, ~0UL >> 1); - if (IS_ERR(mod->args)) { - err = PTR_ERR(mod->args); - goto free_arch_cleanup; + if (!no_uargs) { + mod->args = strndup_user(uargs, ~0UL >> 1); + if (IS_ERR(mod->args)) { + pr_debug("%s mod->args error\n", __func__); + err = PTR_ERR(mod->args); + goto free_arch_cleanup; + } + pr_debug("%s mod->args: %llx \n", __func__, (u64)mod->args); + } else { + if (kargs) + mod->args = kmemdup(kargs, strlen(kargs) + 1, GFP_KERNEL); + else { + char *arg = ""; + mod->args = kmemdup(arg, strlen(arg) + 1, GFP_KERNEL); + } } init_build_id(mod, info); @@ -3098,7 +3109,15 @@ SYSCALL_DEFINE3(init_module, void __user *, umod, return err; } - return load_module(&info, uargs, 0); + return load_module(&info, uargs, NULL, 0, false); +} + +int gfx_load_module(void *buf, int len, const char *kargs) +{ + struct load_info info = { }; + info.hdr = buf; + info.len = len; + return load_module(&info, NULL, kargs, 0, true); } struct idempotent { @@ -3210,7 +3229,7 @@ static int init_module_from_file(struct file *f, const char __user * uargs, int info.len = len; } - return load_module(&info, uargs, flags); + return load_module(&info, uargs, NULL, flags, false); } static int idempotent_init_module(struct file *f, const char __user * uargs, int flags)