-
-
Save joanbm/c00f9e19731d80269a4badc595f63b68 to your computer and use it in GitHub Desktop.
From 0ec02378bcc0d35d713fd93ba42c3848bc8b1077 Mon Sep 17 00:00:00 2001 | |
From: Joan Bruguera <[email protected]> | |
Date: Sat, 12 Mar 2022 08:37:32 +0100 | |
Subject: [PATCH 1/2] Buildfix NVIDIA 470.103.01 for Linux 5.18-rc1 (part 1) | |
--- | |
common/inc/nv-linux.h | 7 +++++++ | |
nvidia-drm/nvidia-drm-drv.c | 4 ++++ | |
nvidia-drm/nvidia-drm-gem.c | 6 ++++++ | |
3 files changed, 17 insertions(+) | |
diff --git a/common/inc/nv-linux.h b/common/inc/nv-linux.h | |
index 82e19d6..58e66c7 100644 | |
--- a/common/inc/nv-linux.h | |
+++ b/common/inc/nv-linux.h | |
@@ -11,6 +11,8 @@ | |
#ifndef _NV_LINUX_H_ | |
#define _NV_LINUX_H_ | |
+#warning Do not buy NVIDIA for your next GPU! | |
+#include <linux/version.h> | |
#include "nvstatus.h" | |
#include "nv.h" | |
#include "nv-ioctl-numa.h" | |
@@ -958,7 +960,12 @@ static inline pgprot_t nv_adjust_pgprot(pgprot_t vm_prot, NvU32 extra) | |
* When AMD memory encryption is enabled, device memory mappings with the | |
* C-bit set read as 0xFF, so ensure the bit is cleared for user mappings. | |
*/ | |
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 18, 0) && defined(_ASM_X86_PGTABLE_H)) | |
+ // Rel. commit "x86/coco: Add API to handle encryption mask" (Kirill A. Shutemov, 22 Feb 2022) | |
+ prot = __pgprot(__sme_clr(pgprot_val(prot))); | |
+#else | |
prot = pgprot_decrypted(prot); | |
+#endif | |
#endif | |
return prot; | |
} | |
diff --git a/nvidia-drm/nvidia-drm-drv.c b/nvidia-drm/nvidia-drm-drv.c | |
index d7067a4..f57cbc8 100644 | |
--- a/nvidia-drm/nvidia-drm-drv.c | |
+++ b/nvidia-drm/nvidia-drm-drv.c | |
@@ -20,6 +20,7 @@ | |
* DEALINGS IN THE SOFTWARE. | |
*/ | |
+#include <linux/version.h> | |
#include "nvidia-drm-conftest.h" /* NV_DRM_AVAILABLE and NV_DRM_DRM_GEM_H_PRESENT */ | |
#include "nvidia-drm-priv.h" | |
@@ -254,7 +255,10 @@ nv_drm_init_mode_config(struct nv_drm_device *nv_dev, | |
#if defined(NV_DRM_FORMAT_MODIFIERS_PRESENT) | |
/* Allow clients to define framebuffer layouts using DRM format modifiers */ | |
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0)) | |
+ // Rel. commit "drm: remove allow_fb_modifiers" (Tomohito Esaki, 28 Jan 2022) | |
dev->mode_config.allow_fb_modifiers = true; | |
+#endif | |
#endif | |
/* Initialize output polling support */ | |
diff --git a/nvidia-drm/nvidia-drm-gem.c b/nvidia-drm/nvidia-drm-gem.c | |
index 82de645..8cd3f76 100644 | |
--- a/nvidia-drm/nvidia-drm-gem.c | |
+++ b/nvidia-drm/nvidia-drm-gem.c | |
@@ -49,6 +49,12 @@ | |
#include "nv-mm.h" | |
+#include <linux/version.h> | |
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 18, 0)) | |
+// Rel. commit "dma-buf-map: Rename to iosys-map" (Lucas De Marchi, 4 Feb 2022) | |
+#define dma_buf_map iosys_map | |
+#endif | |
+ | |
void nv_drm_gem_free(struct drm_gem_object *gem) | |
{ | |
struct nv_drm_gem_object *nv_gem = to_nv_gem_object(gem); | |
-- | |
2.35.1 | |
From 6b934e829fb942d1735e2371320ddbec089c6900 Mon Sep 17 00:00:00 2001 | |
From: Joan Bruguera <[email protected]> | |
Date: Mon, 4 Apr 2022 19:59:51 +0200 | |
Subject: [PATCH 2/2] Buildfix NVIDIA 470.103.01 for Linux 5.18-rc1 (part 2) | |
See also: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d56baf6efaf14e2910610216c581ca71d6940012 | |
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=7968778914e53788a01c2dee2692cab157de9ac0 | |
--- | |
nvidia-uvm/uvm_gpu.c | 8 ++++---- | |
nvidia/linux_nvswitch.c | 18 +++++++++--------- | |
nvidia/nv.c | 18 +++++++++--------- | |
3 files changed, 22 insertions(+), 22 deletions(-) | |
diff --git a/nvidia-uvm/uvm_gpu.c b/nvidia-uvm/uvm_gpu.c | |
index f58c00b..c9607a8 100644 | |
--- a/nvidia-uvm/uvm_gpu.c | |
+++ b/nvidia-uvm/uvm_gpu.c | |
@@ -3059,16 +3059,16 @@ out: | |
NV_STATUS uvm_gpu_map_cpu_pages(uvm_gpu_t *gpu, struct page *page, size_t size, NvU64 *dma_addr_out) | |
{ | |
- NvU64 dma_addr = pci_map_page(gpu->parent->pci_dev, page, 0, size, PCI_DMA_BIDIRECTIONAL); | |
+ NvU64 dma_addr = dma_map_page(&gpu->parent->pci_dev->dev, page, 0, size, DMA_BIDIRECTIONAL); | |
UVM_ASSERT(PAGE_ALIGNED(size)); | |
- if (pci_dma_mapping_error(gpu->parent->pci_dev, dma_addr)) | |
+ if (dma_mapping_error(&gpu->parent->pci_dev->dev, dma_addr)) | |
return NV_ERR_OPERATING_SYSTEM; | |
if (dma_addr < gpu->parent->dma_addressable_start || | |
dma_addr + size - 1 > gpu->parent->dma_addressable_limit) { | |
- pci_unmap_page(gpu->parent->pci_dev, dma_addr, size, PCI_DMA_BIDIRECTIONAL); | |
+ dma_unmap_page(&gpu->parent->pci_dev->dev, dma_addr, size, DMA_BIDIRECTIONAL); | |
UVM_ERR_PRINT_RL("PCI mapped range [0x%llx, 0x%llx) not in the addressable range [0x%llx, 0x%llx), GPU %s\n", | |
dma_addr, | |
dma_addr + (NvU64)size, | |
@@ -3102,7 +3102,7 @@ void uvm_gpu_unmap_cpu_pages(uvm_gpu_t *gpu, NvU64 dma_address, size_t size) | |
if (gpu->parent->npu) | |
dma_address = nv_expand_nvlink_addr(dma_address); | |
dma_address += gpu->parent->dma_addressable_start; | |
- pci_unmap_page(gpu->parent->pci_dev, dma_address, size, PCI_DMA_BIDIRECTIONAL); | |
+ dma_unmap_page(&gpu->parent->pci_dev->dev, dma_address, size, DMA_BIDIRECTIONAL); | |
atomic64_sub(size, &gpu->parent->mapped_cpu_pages_size); | |
} | |
diff --git a/nvidia/linux_nvswitch.c b/nvidia/linux_nvswitch.c | |
index ddfc53c..714b9eb 100644 | |
--- a/nvidia/linux_nvswitch.c | |
+++ b/nvidia/linux_nvswitch.c | |
@@ -2139,11 +2139,11 @@ _nvswitch_to_pci_dma_direction | |
) | |
{ | |
if (direction == NVSWITCH_DMA_DIR_TO_SYSMEM) | |
- return PCI_DMA_FROMDEVICE; | |
+ return DMA_FROM_DEVICE; | |
else if (direction == NVSWITCH_DMA_DIR_FROM_SYSMEM) | |
- return PCI_DMA_TODEVICE; | |
+ return DMA_TO_DEVICE; | |
else | |
- return PCI_DMA_BIDIRECTIONAL; | |
+ return DMA_BIDIRECTIONAL; | |
} | |
NvlStatus | |
@@ -2164,9 +2164,9 @@ nvswitch_os_map_dma_region | |
dma_dir = _nvswitch_to_pci_dma_direction(direction); | |
- *dma_handle = (NvU64)pci_map_single(pdev, cpu_addr, size, dma_dir); | |
+ *dma_handle = (NvU64) dma_map_single(&pdev->dev, cpu_addr, size, dma_dir); | |
- if (pci_dma_mapping_error(pdev, *dma_handle)) | |
+ if (dma_mapping_error(&pdev->dev, *dma_handle)) | |
{ | |
pr_err("nvidia-nvswitch: unable to create PCI DMA mapping\n"); | |
return -NVL_ERR_GENERIC; | |
@@ -2193,7 +2193,7 @@ nvswitch_os_unmap_dma_region | |
dma_dir = _nvswitch_to_pci_dma_direction(direction); | |
- pci_unmap_single(pdev, dma_handle, size, dma_dir); | |
+ dma_unmap_single(&pdev->dev, dma_handle, size, dma_dir); | |
return NVL_SUCCESS; | |
} | |
@@ -2210,7 +2210,7 @@ nvswitch_os_set_dma_mask | |
if (!pdev) | |
return -NVL_BAD_ARGS; | |
- if (pci_set_dma_mask(pdev, DMA_BIT_MASK(dma_addr_width))) | |
+ if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(dma_addr_width))) | |
return -NVL_ERR_GENERIC; | |
return NVL_SUCCESS; | |
@@ -2233,7 +2233,7 @@ nvswitch_os_sync_dma_region_for_cpu | |
dma_dir = _nvswitch_to_pci_dma_direction(direction); | |
- pci_dma_sync_single_for_cpu(pdev, dma_handle, size, dma_dir); | |
+ dma_sync_single_for_cpu(&pdev->dev, dma_handle, size, dma_dir); | |
return NVL_SUCCESS; | |
} | |
@@ -2255,7 +2255,7 @@ nvswitch_os_sync_dma_region_for_device | |
dma_dir = _nvswitch_to_pci_dma_direction(direction); | |
- pci_dma_sync_single_for_device(pdev, dma_handle, size, dma_dir); | |
+ dma_sync_single_for_device(&pdev->dev, dma_handle, size, dma_dir); | |
return NVL_SUCCESS; | |
} | |
diff --git a/nvidia/nv.c b/nvidia/nv.c | |
index 92a7dc6..5065158 100644 | |
--- a/nvidia/nv.c | |
+++ b/nvidia/nv.c | |
@@ -2821,13 +2821,13 @@ nv_set_dma_address_size( | |
*/ | |
if (!nvl->tce_bypass_enabled) | |
{ | |
- pci_set_dma_mask(nvl->pci_dev, new_mask); | |
+ dma_set_mask(&nvl->pci_dev->dev, new_mask); | |
/* Certain kernels have a bug which causes pci_set_consistent_dma_mask | |
* to call GPL sme_active symbol, this bug has already been fixed in a | |
* minor release update but detect the failure scenario here to prevent | |
* an installation regression */ | |
#if !NV_IS_EXPORT_SYMBOL_GPL_sme_active | |
- pci_set_consistent_dma_mask(nvl->pci_dev, new_mask); | |
+ dma_set_coherent_mask(&nvl->pci_dev->dev, new_mask); | |
#endif | |
} | |
} | |
@@ -4524,19 +4524,19 @@ NvU64 NV_API_CALL nv_get_dma_start_address( | |
* as the starting address for all DMA mappings. | |
*/ | |
saved_dma_mask = pci_dev->dma_mask; | |
- if (pci_set_dma_mask(pci_dev, DMA_BIT_MASK(64)) != 0) | |
+ if (dma_set_mask(&pci_dev->dev, DMA_BIT_MASK(64)) != 0) | |
{ | |
goto done; | |
} | |
- dma_addr = pci_map_single(pci_dev, NULL, 1, DMA_BIDIRECTIONAL); | |
- if (pci_dma_mapping_error(pci_dev, dma_addr)) | |
+ dma_addr = dma_map_single(&pci_dev->dev, NULL, 1, DMA_BIDIRECTIONAL); | |
+ if (dma_mapping_error(&pci_dev->dev, dma_addr)) | |
{ | |
- pci_set_dma_mask(pci_dev, saved_dma_mask); | |
+ dma_set_mask(&pci_dev->dev, saved_dma_mask); | |
goto done; | |
} | |
- pci_unmap_single(pci_dev, dma_addr, 1, DMA_BIDIRECTIONAL); | |
+ dma_unmap_single(&pci_dev->dev, dma_addr, 1, DMA_BIDIRECTIONAL); | |
/* | |
* From IBM: "For IODA2, native DMA bypass or KVM TCE-based implementation | |
@@ -4568,7 +4568,7 @@ NvU64 NV_API_CALL nv_get_dma_start_address( | |
*/ | |
nv_printf(NV_DBG_WARNINGS, | |
"NVRM: DMA window limited by platform\n"); | |
- pci_set_dma_mask(pci_dev, saved_dma_mask); | |
+ dma_set_mask(&pci_dev->dev, saved_dma_mask); | |
goto done; | |
} | |
else if ((dma_addr & saved_dma_mask) != 0) | |
@@ -4587,7 +4587,7 @@ NvU64 NV_API_CALL nv_get_dma_start_address( | |
*/ | |
nv_printf(NV_DBG_WARNINGS, | |
"NVRM: DMA window limited by memory size\n"); | |
- pci_set_dma_mask(pci_dev, saved_dma_mask); | |
+ dma_set_mask(&pci_dev->dev, saved_dma_mask); | |
goto done; | |
} | |
} | |
-- | |
2.35.1 | |
From 689ede6109d1b8aef914809f290e75632c338b9f Mon Sep 17 00:00:00 2001 | |
From: Joan Bruguera <[email protected]> | |
Date: Sat, 9 Apr 2022 19:42:24 +0200 | |
Subject: [PATCH] Buildfix NVIDIA 470.103.01 for Linux 5.18-rc2 | |
acpi_bus_get_device was removed and its trivial replacement acpi_fetch_acpi_dev | |
is GPL-exported, so just disable ACPI support as I don't want to deal with it. | |
--- | |
nvidia/nv-acpi.c | 3 ++- | |
1 file changed, 2 insertions(+), 1 deletion(-) | |
diff --git a/nvidia/nv-acpi.c b/nvidia/nv-acpi.c | |
index faf8b44..22a9152 100644 | |
--- a/nvidia/nv-acpi.c | |
+++ b/nvidia/nv-acpi.c | |
@@ -16,7 +16,8 @@ | |
#include <linux/acpi.h> | |
-#if defined(NV_LINUX_ACPI_EVENTS_SUPPORTED) | |
+#include <linux/version.h> | |
+#if defined(NV_LINUX_ACPI_EVENTS_SUPPORTED) && (LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0)) | |
static NV_STATUS nv_acpi_extract_integer (const union acpi_object *, void *, NvU32, NvU32 *); | |
static NV_STATUS nv_acpi_extract_buffer (const union acpi_object *, void *, NvU32, NvU32 *); | |
static NV_STATUS nv_acpi_extract_package (const union acpi_object *, void *, NvU32, NvU32 *); | |
-- | |
2.35.1 | |
it can work on nvidia 510.68?
I haven't got nvidia 510.68. Is that a beta version?
Is the last nvidia versión, downloadnable from website https://www.nvidia.it/Download/driverResults.aspx/187177/it
I can't with dkms, i take error
I don't use dkms with nvidia. I've never found it satisfactory. I can't promise but show me the exact error you get and I'll see if there's anything I can do.
I use 5.18-rc2 with last nvidia driver buy It can load dkms when install driver.
It possibile without dkms?
I don't have any NVIDIA hardware other than the 470xx one so I can't test it over 510xx, but at least 510.60.02 builds fine after patching, so it may work (the nvidia-uvm.c part seems missing from the newer driver so you can ignore that - but make sure dkms is not failing because of it).
If you're having trouble with dkms you can try to use this manual steps:
https://gist.github.com/joanbm/144a965c36fc1dc0d1f1b9be3438a368?permalink_comment_id=3914496#gistcomment-3914496
I have patched no-compat32 nvidia folder and now i had can install driver and has install dkms for kernel module then Xorg no load
without the kernel module the xorg server could not be started and therefore I stayed in a terminal interface, I used your patch and it worked, great job, thank you very much for the work done
I've made some tweaks to your code for nvidia-510.60x and it works a treat. Thanks very much for your work.