Tegra GPUs from GV11B onwards are CPU coherent as described in the
device tree. Move the cpu_coherent flag into nvkm_device so it's not a
compile time constant, and add code to Tegra initialization to set it
based on the device's DMA attributes.

Other platforms keep existing logic.

Signed-off-by: Mikko Perttunen <[email protected]>
---
 drivers/gpu/drm/nouveau/include/nvkm/core/device.h | 2 +-
 drivers/gpu/drm/nouveau/nvkm/engine/device/pci.c   | 2 +-
 drivers/gpu/drm/nouveau/nvkm/engine/device/tegra.c | 6 +++++-
 drivers/gpu/drm/nouveau/nvkm/subdev/mmu/base.c     | 2 +-
 4 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/include/nvkm/core/device.h 
b/drivers/gpu/drm/nouveau/include/nvkm/core/device.h
index 954a89d43bad..a880e8ee7bc6 100644
--- a/drivers/gpu/drm/nouveau/include/nvkm/core/device.h
+++ b/drivers/gpu/drm/nouveau/include/nvkm/core/device.h
@@ -18,6 +18,7 @@ struct nvkm_device {
        const struct nvkm_device_quirk *quirk;
        struct device *dev;
        enum nvkm_device_type type;
+       bool cpu_coherent;
        u64 handle;
        const char *name;
        const char *cfgopt;
@@ -98,7 +99,6 @@ struct nvkm_device_func {
        int (*irq)(struct nvkm_device *);
        resource_size_t (*resource_addr)(struct nvkm_device *, enum 
nvkm_bar_id);
        resource_size_t (*resource_size)(struct nvkm_device *, enum 
nvkm_bar_id);
-       bool cpu_coherent;
 };
 
 struct nvkm_device_quirk {
diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/device/pci.c 
b/drivers/gpu/drm/nouveau/nvkm/engine/device/pci.c
index 248623b91e29..96f66285555f 100644
--- a/drivers/gpu/drm/nouveau/nvkm/engine/device/pci.c
+++ b/drivers/gpu/drm/nouveau/nvkm/engine/device/pci.c
@@ -1645,7 +1645,6 @@ nvkm_device_pci_func = {
        .irq = nvkm_device_pci_irq,
        .resource_addr = nvkm_device_pci_resource_addr,
        .resource_size = nvkm_device_pci_resource_size,
-       .cpu_coherent = !IS_ENABLED(CONFIG_ARM),
 };
 
 int
@@ -1694,6 +1693,7 @@ nvkm_device_pci_new(struct pci_dev *pci_dev, const char 
*cfg, const char *dbg,
        }
        *pdevice = &pdev->device;
        pdev->pdev = pci_dev;
+       pdev->device.cpu_coherent = !IS_ENABLED(CONFIG_ARM);
 
        ret = nvkm_device_ctor(&nvkm_device_pci_func, quirk, &pci_dev->dev,
                               pci_is_pcie(pci_dev) ? NVKM_DEVICE_PCIE :
diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/device/tegra.c 
b/drivers/gpu/drm/nouveau/nvkm/engine/device/tegra.c
index 74b292659ee9..c04006d38c64 100644
--- a/drivers/gpu/drm/nouveau/nvkm/engine/device/tegra.c
+++ b/drivers/gpu/drm/nouveau/nvkm/engine/device/tegra.c
@@ -23,6 +23,8 @@
 #ifdef CONFIG_NOUVEAU_PLATFORM_DRIVER
 #include "priv.h"
 
+#include <linux/property.h>
+
 #if IS_ENABLED(CONFIG_ARM_DMA_USE_IOMMU)
 #include <asm/dma-iommu.h>
 #endif
@@ -245,7 +247,6 @@ nvkm_device_tegra_func = {
        .irq = nvkm_device_tegra_irq,
        .resource_addr = nvkm_device_tegra_resource_addr,
        .resource_size = nvkm_device_tegra_resource_size,
-       .cpu_coherent = false,
 };
 
 int
@@ -339,6 +340,9 @@ nvkm_device_tegra_new(const struct nvkm_device_tegra_func 
*func,
 
        tdev->gpu_speedo = tegra_sku_info.gpu_speedo_value;
        tdev->gpu_speedo_id = tegra_sku_info.gpu_speedo_id;
+       tdev->device.cpu_coherent =
+               device_get_dma_attr(&pdev->dev) == DEV_DMA_COHERENT;
+
        ret = nvkm_device_ctor(&nvkm_device_tegra_func, NULL, &pdev->dev,
                               NVKM_DEVICE_TEGRA, pdev->id, NULL,
                               cfg, dbg, &tdev->device);
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/base.c 
b/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/base.c
index df86214183cc..7c45efdf3952 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/base.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/base.c
@@ -304,7 +304,7 @@ nvkm_mmu_host(struct nvkm_mmu *mmu)
         * done through BAR1.
         */
        type |= NVKM_MEM_COHERENT;
-       if (device->func->cpu_coherent)
+       if (device->cpu_coherent)
                nvkm_mmu_type(mmu, heap, type & ~NVKM_MEM_KIND);
 
        /* Uncached system memory. */

-- 
2.56.1

Reply via email to