Skip to content

Instantly share code, notes, and snippets.

@joanbm
Last active July 24, 2023 11:46
Show Gist options
  • Save joanbm/d702049df1220a77e13175b018ea6bea to your computer and use it in GitHub Desktop.
Save joanbm/d702049df1220a77e13175b018ea6bea to your computer and use it in GitHub Desktop.
Tentative fix for NVIDIA 470.141.03 driver for Linux 6.1-rc1
From 5cadf6866eaf76a87aa4fe39bb7821655d5280f2 Mon Sep 17 00:00:00 2001
From: Joan Bruguera <joanbrugueram@gmail.com>
Date: Mon, 29 Aug 2022 15:01:53 +0200
Subject: [PATCH] Tentative fix for NVIDIA 470.141.03 driver for Linux 6.1-rc1
---
nvidia/os-interface.c | 35 ++++++++++++++++++++++++++++++++++-
1 file changed, 34 insertions(+), 1 deletion(-)
diff --git a/nvidia/os-interface.c b/nvidia/os-interface.c
index 89f256f..01b3ffc 100644
--- a/nvidia/os-interface.c
+++ b/nvidia/os-interface.c
@@ -1105,7 +1105,40 @@ void NV_API_CALL os_get_screen_info(
NvU64 consoleBar2Address
)
{
-#if defined(CONFIG_FB)
+#if defined(CONFIG_FB) && LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0)
+ // Rel. commit "fbdev: Make registered_fb[] private to fbmem.c" (Daniel Vetter, Mon Jul 25)
+ // (This works for the usual x86-64 single EFI Framebuffer scenario, at least)
+ // The orig_video_isVGA and ext_lfb_base checks are backported from the NVIDIA 520xx driver
+ // (which is MIT licensed, copyright NVIDIA CORPORATION & AFFILIATES)
+ *pPhysicalAddress = 0;
+ *pFbWidth = *pFbHeight = *pFbDepth = *pFbPitch = 0;
+
+ /*
+ * If there is not a framebuffer console, return 0 size.
+ *
+ * orig_video_isVGA is set to 1 during early Linux kernel
+ * initialization, and then will be set to a value, such as
+ * VIDEO_TYPE_VLFB or VIDEO_TYPE_EFI if an fbdev console is used.
+ */
+ if (screen_info.orig_video_isVGA > 1)
+ {
+ NvU64 physAddr = screen_info.lfb_base;
+#if defined(VIDEO_CAPABILITY_64BIT_BASE)
+ physAddr |= (NvU64)screen_info.ext_lfb_base << 32;
+#endif
+
+ /* Make sure base address is mapped to GPU BAR */
+ if ((physAddr == consoleBar1Address) ||
+ (physAddr == consoleBar2Address))
+ {
+ *pPhysicalAddress = physAddr;
+ *pFbWidth = screen_info.lfb_width;
+ *pFbHeight = screen_info.lfb_height;
+ *pFbDepth = screen_info.lfb_depth;
+ *pFbPitch = screen_info.lfb_linelength;
+ }
+ }
+#elif defined(CONFIG_FB)
int i;
*pPhysicalAddress = 0;
*pFbWidth = *pFbHeight = *pFbDepth = *pFbPitch = 0;
--
2.38.1
@Fjodor42
Copy link

Fjodor42 commented Oct 18, 2022

Thank you immensely!

It would seem that for 520, the patch could be rewritten as below and still compile - whether it also works, I will find out as soon as possible.

diff -aurp a/nvidia/os-interface.c b/nvidia/os-interface.c
--- a/nvidia/os-interface.c	2022-09-29 08:11:52.000000000 +0200
+++ b/nvidia/os-interface.c	2022-10-18 18:37:32.555561524 +0200
@@ -1115,6 +1115,21 @@ void NV_API_CALL os_get_screen_info(
 #if defined(CONFIG_FB) && defined(NV_NUM_REGISTERED_FB_PRESENT)
     if (num_registered_fb > 0)
     {
+#  if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0)
+    // Rel. commit "fbdev: Make registered_fb[] private to fbmem.c" (Daniel Vetter, Mon Jul 25)
+    // (This works for the usual x86-64 single EFI Framebuffer scenario, at least)
+
+    /* Make sure base address is mapped to GPU BAR */
+    if ((screen_info.lfb_base == consoleBar1Address) ||
+        (screen_info.lfb_base == consoleBar2Address))
+    {
+        *pPhysicalAddress = screen_info.lfb_base;
+        *pFbWidth = screen_info.lfb_width;
+        *pFbHeight = screen_info.lfb_height;
+        *pFbDepth = screen_info.lfb_depth;
+        *pFbPitch = screen_info.lfb_linelength;
+    }
+#  endif
         int i;
 
         for (i = 0; i < num_registered_fb; i++)

@Fjodor42
Copy link

  • whether it also works, I will find out as soon as possible

At least on a GUI-less system, there is text, and computation with CUDA works...

@joanbm
Copy link
Author

joanbm commented Oct 19, 2022

Hi @Fjodor42! I took a look and at first glance, I believe that the latest version of the NVIDIA 520xx driver (i.e. 520.56.06) already supports Linux 6.1-rc1 out of the box. (I publish patches for 470xx because that's the hardware I have).

Also, it looks like they came up with the same approach, but they handle some cases better in their implementation - I'll backport those to the 470xx patch. So thanks for bringing this to my attention!

@Fjodor42
Copy link

Fjodor42 commented Oct 20, 2022

Thank you @joanbm :-)

If they support 6.1-rc1, then the version that does has not hit the repos yet, as I got compilation errors.

If I get the time, I will try to port your revised patch to 520, but I promise nothing, and other people are most welcome to beat me to it :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment