Skip to contentSkip to conversation

Host1x IOMMU support + VIC support

PATCH In review Mikko Perttunen 10 participants 28 messages Dec 14, 2016 – Jan 27, 2017 10 messages not in the archive

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

v2 cover Host1x IOMMU support + VIC support

This series adds IOMMU support to Host1x and TegraDRM and adds support for the VIC (Video Image Compositor) host1x client. The series is available as a git repository at
git://github.com/cyndis/linux.git; branch vic-2.

A userspace test case for VIC can be found at
https://github.com/cyndis/drm/tree/work/tegra.
The testcase is in tests/tegra and is called submit_vic. The testcase/TRM include full headers and documentation to program the unit. The unit by itself, however, does not readily map to existing userspace library interfaces, so implementations for those are not provided.

The in-kernel firewall is not implemented for VIC; therefore, either the IOMMU must be enabled or the firewall disabled for the test to pass.

Tested with Jetson TX1 (T210). Probably works also with Jetson TK1 (T124). Note that due to hardware changes the testcase also needs to be changed to run properly on T124: this can be done by removing the topmost commit of the aforementioned test repository.

Thanks,
Mikko.

Arto Merilainen (2):
drm/tegra: Add falcon helper library
drm/tegra: Add VIC support

Mikko Perttunen (5):
drm/tegra: Add Tegra DRM allocation API
gpu: host1x: Add IOMMU support
dt-bindings: Add bindings for the Tegra VIC
arm64: tegra: Enable VIC on T210
arm64: tegra: Enable IOMMU for Host1x on Tegra210

 .../display/tegra/nvidia,tegra20-host1x.txt        |  13 +
 arch/arm64/boot/dts/nvidia/tegra210.dtsi           |  19 +-
 drivers/gpu/drm/tegra/Makefile                     |   4 +-
 drivers/gpu/drm/tegra/drm.c                        | 114 +++++-
 drivers/gpu/drm/tegra/drm.h                        |  12 +
 drivers/gpu/drm/tegra/falcon.c                     | 259 ++++++++++++++
 drivers/gpu/drm/tegra/falcon.h                     | 127 +++++++
 drivers/gpu/drm/tegra/vic.c                        | 396 +++++++++++++++++++++
 drivers/gpu/drm/tegra/vic.h                        |  31 ++
 drivers/gpu/host1x/cdma.c                          |  74 +++-
 drivers/gpu/host1x/cdma.h                          |   6 +-
 drivers/gpu/host1x/dev.c                           |  40 ++-
 drivers/gpu/host1x/dev.h                           |   6 +
 drivers/gpu/host1x/hw/cdma_hw.c                    |  16 +-
 drivers/gpu/host1x/job.c                           |  72 +++-
 drivers/gpu/host1x/job.h                           |   1 +
 include/linux/host1x.h                             |   1 +
 17 files changed, 1143 insertions(+), 48 deletions(-)
 create mode 100644 drivers/gpu/drm/tegra/falcon.c
 create mode 100644 drivers/gpu/drm/tegra/falcon.h
 create mode 100644 drivers/gpu/drm/tegra/vic.c
 create mode 100644 drivers/gpu/drm/tegra/vic.h
Signature · 1 line
2.10.2

A message that is not in the archive (sent off-list or not yet received): 20161214111617.24548-1-mperttunen-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org

#2 lore raw

PATCH v2 1/7 drm/tegra: Add Tegra DRM allocation API

Add a new IO virtual memory allocation API to allow clients to allocate non-GEM memory in the Tegra DRM IOMMU domain. This is required e.g. for loading client firmware when clients are attached to the IOMMU domain.

The allocator allocates contiguous physical pages that are then mapped contiguously to the IOMMU domain using the iova_domain library provided by the kernel. Contiguous physical pages are used so that the same allocator works also when IOMMU support is disabled and therefore devices access physical memory directly.

---
 drivers/gpu/drm/tegra/drm.c | 111 +++++++++++++++++++++++++++++++++++++++++---
 drivers/gpu/drm/tegra/drm.h |  11 +++++
 2 files changed, 115 insertions(+), 7 deletions(-)
drivers/gpu/drm/tegra/drm.c +104 -7
index b8be3ee..cf714c6 100644
@@ -1,12 +1,13 @@
 /*
  * Copyright (C) 2012 Avionic Design GmbH
- * Copyright (C) 2012-2013 NVIDIA CORPORATION.  All rights reserved.
+ * Copyright (C) 2012-2016 NVIDIA CORPORATION.  All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
  * published by the Free Software Foundation.
  */
 
+#include <linux/bitops.h>
 #include <linux/host1x.h>
 #include <linux/iommu.h>
 
@@ -23,6 +24,8 @@
 #define DRIVER_MINOR 0
 #define DRIVER_PATCHLEVEL 0
 
+#define CARVEOUT_SZ SZ_64M
+
 struct tegra_drm_file {
 	struct list_head contexts;
 };
@@ -127,7 +130,8 @@ static int tegra_drm_load(struct drm_device *drm, unsigned long flags)
 
 	if (iommu_present(&platform_bus_type)) {
 		struct iommu_domain_geometry *geometry;
-		u64 start, end;
+		unsigned long order;
+		u64 carveout_start, carveout_end, gem_start, gem_end;
 
 		tegra->domain = iommu_domain_alloc(&platform_bus_type);
 		if (!tegra->domain) {
@@ -136,12 +140,25 @@ static int tegra_drm_load(struct drm_device *drm, unsigned long flags)
 		}
 
 		geometry = &tegra->domain->geometry;
-		start = geometry->aperture_start;
-		end = geometry->aperture_end;
+		gem_start = geometry->aperture_start;
+		gem_end = geometry->aperture_end - CARVEOUT_SZ;
+		carveout_start = gem_end + 1;
+		carveout_end = geometry->aperture_end;
+
+		order = __ffs(tegra->domain->pgsize_bitmap);
+		init_iova_domain(&tegra->carveout.domain, 1UL << order,
+				 carveout_start >> order,
+				 carveout_end >> order);
+
+		tegra->carveout.shift = iova_shift(&tegra->carveout.domain);
+		tegra->carveout.limit = carveout_end >> tegra->carveout.shift;
+
+		drm_mm_init(&tegra->mm, gem_start, gem_end - gem_start + 1);
 
-		DRM_DEBUG_DRIVER("IOMMU aperture initialized (%#llx-%#llx)\n",
-				 start, end);
-		drm_mm_init(&tegra->mm, start, end - start + 1);
+		DRM_DEBUG("IOMMU apertures:\n");
+		DRM_DEBUG("  GEM: %#llx-%#llx\n", gem_start, gem_end);
+		DRM_DEBUG("  Carveout: %#llx-%#llx\n", carveout_start,
+			  carveout_end);
 	}
 
 	mutex_init(&tegra->clients_lock);
@@ -208,6 +225,7 @@ static int tegra_drm_load(struct drm_device *drm, unsigned long flags)
 	if (tegra->domain) {
 		iommu_domain_free(tegra->domain);
 		drm_mm_takedown(&tegra->mm);
+		put_iova_domain(&tegra->carveout.domain);
 	}
 free:
 	kfree(tegra);
@@ -232,6 +250,7 @@ static int tegra_drm_unload(struct drm_device *drm)
 	if (tegra->domain) {
 		iommu_domain_free(tegra->domain);
 		drm_mm_takedown(&tegra->mm);
+		put_iova_domain(&tegra->carveout.domain);
 	}
 
 	kfree(tegra);
@@ -975,6 +994,84 @@ int tegra_drm_unregister_client(struct tegra_drm *tegra,
 	return 0;
 }
 
+void *tegra_drm_alloc(struct tegra_drm *tegra, size_t size,
+			      dma_addr_t *dma)
+{
+	struct iova *alloc;
+	void *virt;
+	gfp_t gfp;
+	int err;
+
+	if (tegra->domain)
+		size = iova_align(&tegra->carveout.domain, size);
+	else
+		size = PAGE_ALIGN(size);
+
+	gfp = GFP_KERNEL | __GFP_ZERO;
+	if (!tegra->domain) {
+		/*
+		 * Many units only support 32-bit addresses, even on 64-bit
+		 * SoCs. If there is no IOMMU to translate into a 32-bit IO
+		 * virtual address space, force allocations to be in the
+		 * lower 32-bit range.
+		 */
+		gfp |= GFP_DMA;
+	}
+
+	virt = (void *)__get_free_pages(gfp, get_order(size));
+	if (!virt)
+		return ERR_PTR(-ENOMEM);
+
+	if (!tegra->domain) {
+		/*
+		 * If IOMMU is disabled, devices address physical memory
+		 * directly.
+		 */
+		*dma = virt_to_phys(virt);
+		return virt;
+	}
+
+	alloc = alloc_iova(&tegra->carveout.domain,
+			   size >> tegra->carveout.shift,
+			   tegra->carveout.limit, true);
+	if (!alloc) {
+		err = -EBUSY;
+		goto free_pages;
+	}
+
+	*dma = iova_dma_addr(&tegra->carveout.domain, alloc);
+	err = iommu_map(tegra->domain, *dma, virt_to_phys(virt),
+			size, IOMMU_READ | IOMMU_WRITE);
+	if (err < 0)
+		goto free_iova;
+
+	return virt;
+
+free_iova:
+	__free_iova(&tegra->carveout.domain, alloc);
+free_pages:
+	free_pages((unsigned long)virt, get_order(size));
+
+	return ERR_PTR(err);
+}
+
+void tegra_drm_free(struct tegra_drm *tegra, size_t size, void *virt,
+		    dma_addr_t dma)
+{
+	if (tegra->domain)
+		size = iova_align(&tegra->carveout.domain, size);
+	else
+		size = PAGE_ALIGN(size);
+
+	if (tegra->domain) {
+		iommu_unmap(tegra->domain, dma, size);
+		free_iova(&tegra->carveout.domain,
+			  iova_pfn(&tegra->carveout.domain, dma));
+	}
+
+	free_pages((unsigned long)virt, get_order(size));
+}
+
 static int host1x_drm_probe(struct host1x_device *dev)
 {
 	struct drm_driver *driver = &tegra_drm_driver;
drivers/gpu/drm/tegra/drm.h +11 -0
index 0ddcce1..7351dee 100644
@@ -12,6 +12,7 @@
 
 #include <uapi/drm/tegra_drm.h>
 #include <linux/host1x.h>
+#include <linux/iova.h>
 #include <linux/of_gpio.h>
 
 #include <drm/drmP.h>
@@ -43,6 +44,12 @@ struct tegra_drm {
 	struct iommu_domain *domain;
 	struct drm_mm mm;
 
+	struct {
+		struct iova_domain domain;
+		unsigned long shift;
+		unsigned long limit;
+	} carveout;
+
 	struct mutex clients_lock;
 	struct list_head clients;
 
@@ -104,6 +111,10 @@ int tegra_drm_unregister_client(struct tegra_drm *tegra,
 int tegra_drm_init(struct tegra_drm *tegra, struct drm_device *drm);
 int tegra_drm_exit(struct tegra_drm *tegra);
 
+void *tegra_drm_alloc(struct tegra_drm *tegra, size_t size, dma_addr_t *iova);
+void tegra_drm_free(struct tegra_drm *tegra, size_t size, void *virt,
+		    dma_addr_t iova);
+
 struct tegra_dc_soc_info;
 struct tegra_output;
 
Signature · 1 line
2.10.2
#3 lore raw

Re: [PATCH v2 1/7] drm/tegra: Add Tegra DRM allocation API

Am Mittwoch, den 14.12.2016, 13:16 +0200 schrieb Mikko Perttunen:

Quoted 11 lines

Add a new IO virtual memory allocation API to allow clients to allocate non-GEM memory in the Tegra DRM IOMMU domain. This is required e.g. for loading client firmware when clients are attached to the IOMMU domain.

The allocator allocates contiguous physical pages that are then mapped contiguously to the IOMMU domain using the iova_domain library provided by the kernel. Contiguous physical pages are used so that the same allocator works also when IOMMU support is disabled and therefore devices access physical memory directly.

Why is this needed? If you use the DMA API for those buffers you should end up with CMA memory in the !IOMMU case and normal paged memory with IOMMU enabled. From my understanding this should match the requirements.

Also how big can those firmware images get? Will __get_free_pages be able to provide this much contig memory in a long running system with fragmented memory space? Isn't CMA the better option here?

Regards,
Lucas

Quoted 202 lines
---
 drivers/gpu/drm/tegra/drm.c | 111 +++++++++++++++++++++++++++++++++++++++++---
 drivers/gpu/drm/tegra/drm.h |  11 +++++
 2 files changed, 115 insertions(+), 7 deletions(-)
drivers/gpu/drm/tegra/drm.c +104 -7
index b8be3ee..cf714c6 100644
@@ -1,12 +1,13 @@
 /*
  * Copyright (C) 2012 Avionic Design GmbH
- * Copyright (C) 2012-2013 NVIDIA CORPORATION.  All rights reserved.
+ * Copyright (C) 2012-2016 NVIDIA CORPORATION.  All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
  * published by the Free Software Foundation.
  */
 
+#include <linux/bitops.h>
 #include <linux/host1x.h>
 #include <linux/iommu.h>
 
@@ -23,6 +24,8 @@
 #define DRIVER_MINOR 0
 #define DRIVER_PATCHLEVEL 0
 
+#define CARVEOUT_SZ SZ_64M
+
 struct tegra_drm_file {
 	struct list_head contexts;
 };
@@ -127,7 +130,8 @@ static int tegra_drm_load(struct drm_device *drm, unsigned long flags)
 
 	if (iommu_present(&platform_bus_type)) {
 		struct iommu_domain_geometry *geometry;
-		u64 start, end;
+		unsigned long order;
+		u64 carveout_start, carveout_end, gem_start, gem_end;
 
 		tegra->domain = iommu_domain_alloc(&platform_bus_type);
 		if (!tegra->domain) {
@@ -136,12 +140,25 @@ static int tegra_drm_load(struct drm_device *drm, unsigned long flags)
 		}
 
 		geometry = &tegra->domain->geometry;
-		start = geometry->aperture_start;
-		end = geometry->aperture_end;
+		gem_start = geometry->aperture_start;
+		gem_end = geometry->aperture_end - CARVEOUT_SZ;
+		carveout_start = gem_end + 1;
+		carveout_end = geometry->aperture_end;
+
+		order = __ffs(tegra->domain->pgsize_bitmap);
+		init_iova_domain(&tegra->carveout.domain, 1UL << order,
+				 carveout_start >> order,
+				 carveout_end >> order);
+
+		tegra->carveout.shift = iova_shift(&tegra->carveout.domain);
+		tegra->carveout.limit = carveout_end >> tegra->carveout.shift;
+
+		drm_mm_init(&tegra->mm, gem_start, gem_end - gem_start + 1);
 
-		DRM_DEBUG_DRIVER("IOMMU aperture initialized (%#llx-%#llx)\n",
-				 start, end);
-		drm_mm_init(&tegra->mm, start, end - start + 1);
+		DRM_DEBUG("IOMMU apertures:\n");
+		DRM_DEBUG("  GEM: %#llx-%#llx\n", gem_start, gem_end);
+		DRM_DEBUG("  Carveout: %#llx-%#llx\n", carveout_start,
+			  carveout_end);
 	}
 
 	mutex_init(&tegra->clients_lock);
@@ -208,6 +225,7 @@ static int tegra_drm_load(struct drm_device *drm, unsigned long flags)
 	if (tegra->domain) {
 		iommu_domain_free(tegra->domain);
 		drm_mm_takedown(&tegra->mm);
+		put_iova_domain(&tegra->carveout.domain);
 	}
 free:
 	kfree(tegra);
@@ -232,6 +250,7 @@ static int tegra_drm_unload(struct drm_device *drm)
 	if (tegra->domain) {
 		iommu_domain_free(tegra->domain);
 		drm_mm_takedown(&tegra->mm);
+		put_iova_domain(&tegra->carveout.domain);
 	}
 
 	kfree(tegra);
@@ -975,6 +994,84 @@ int tegra_drm_unregister_client(struct tegra_drm *tegra,
 	return 0;
 }
 
+void *tegra_drm_alloc(struct tegra_drm *tegra, size_t size,
+			      dma_addr_t *dma)
+{
+	struct iova *alloc;
+	void *virt;
+	gfp_t gfp;
+	int err;
+
+	if (tegra->domain)
+		size = iova_align(&tegra->carveout.domain, size);
+	else
+		size = PAGE_ALIGN(size);
+
+	gfp = GFP_KERNEL | __GFP_ZERO;
+	if (!tegra->domain) {
+		/*
+		 * Many units only support 32-bit addresses, even on 64-bit
+		 * SoCs. If there is no IOMMU to translate into a 32-bit IO
+		 * virtual address space, force allocations to be in the
+		 * lower 32-bit range.
+		 */
+		gfp |= GFP_DMA;
+	}
+
+	virt = (void *)__get_free_pages(gfp, get_order(size));
+	if (!virt)
+		return ERR_PTR(-ENOMEM);
+
+	if (!tegra->domain) {
+		/*
+		 * If IOMMU is disabled, devices address physical memory
+		 * directly.
+		 */
+		*dma = virt_to_phys(virt);
+		return virt;
+	}
+
+	alloc = alloc_iova(&tegra->carveout.domain,
+			   size >> tegra->carveout.shift,
+			   tegra->carveout.limit, true);
+	if (!alloc) {
+		err = -EBUSY;
+		goto free_pages;
+	}
+
+	*dma = iova_dma_addr(&tegra->carveout.domain, alloc);
+	err = iommu_map(tegra->domain, *dma, virt_to_phys(virt),
+			size, IOMMU_READ | IOMMU_WRITE);
+	if (err < 0)
+		goto free_iova;
+
+	return virt;
+
+free_iova:
+	__free_iova(&tegra->carveout.domain, alloc);
+free_pages:
+	free_pages((unsigned long)virt, get_order(size));
+
+	return ERR_PTR(err);
+}
+
+void tegra_drm_free(struct tegra_drm *tegra, size_t size, void *virt,
+		    dma_addr_t dma)
+{
+	if (tegra->domain)
+		size = iova_align(&tegra->carveout.domain, size);
+	else
+		size = PAGE_ALIGN(size);
+
+	if (tegra->domain) {
+		iommu_unmap(tegra->domain, dma, size);
+		free_iova(&tegra->carveout.domain,
+			  iova_pfn(&tegra->carveout.domain, dma));
+	}
+
+	free_pages((unsigned long)virt, get_order(size));
+}
+
 static int host1x_drm_probe(struct host1x_device *dev)
 {
 	struct drm_driver *driver = &tegra_drm_driver;
drivers/gpu/drm/tegra/drm.h +7 -0
index 0ddcce1..7351dee 100644
@@ -12,6 +12,7 @@
 
 #include <uapi/drm/tegra_drm.h>
 #include <linux/host1x.h>
+#include <linux/iova.h>
 #include <linux/of_gpio.h>
 
 #include <drm/drmP.h>
@@ -43,6 +44,12 @@ struct tegra_drm {
 	struct iommu_domain *domain;
 	struct drm_mm mm;
 
+	struct {
+		struct iova_domain domain;
+		unsigned long shift;
+		unsigned long limit;
+	} carveout;
+
 	struct mutex clients_lock;
 	struct list_head clients;
 

drivers/gpu/drm/tegra/drm.h int tegra_drm_unregister_client(struct tegra_drm *tegra, · line 120

Quoted 10 lines
drivers/gpu/drm/tegra/drm.h +4 -0
@@ -104,6 +111,10 @@ int tegra_drm_unregister_client(struct tegra_drm *tegra,
 int tegra_drm_init(struct tegra_drm *tegra, struct drm_device *drm);
 int tegra_drm_exit(struct tegra_drm *tegra);
 
+void *tegra_drm_alloc(struct tegra_drm *tegra, size_t size, dma_addr_t *iova);
+void tegra_drm_free(struct tegra_drm *tegra, size_t size, void *virt,
+		    dma_addr_t iova);
+
 struct tegra_dc_soc_info;
 struct tegra_output;
 

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

A message that is not in the archive (sent off-list or not yet received): [email protected]

#5 lore raw

Re: [PATCH v2 1/7] drm/tegra: Add Tegra DRM allocation API

Quoted 12 lines · Lucas Stach

Am Mittwoch, den 14.12.2016, 13:16 +0200 schrieb Mikko Perttunen:

Quoted 11 lines

Add a new IO virtual memory allocation API to allow clients to allocate non-GEM memory in the Tegra DRM IOMMU domain. This is required e.g. for loading client firmware when clients are attached to the IOMMU domain.

The allocator allocates contiguous physical pages that are then mapped contiguously to the IOMMU domain using the iova_domain library provided by the kernel. Contiguous physical pages are used so that the same allocator works also when IOMMU support is disabled and therefore devices access physical memory directly.

Quoted 3 lines

Why is this needed? If you use the DMA API for those buffers you should end up with CMA memory in the !IOMMU case and normal paged memory with IOMMU enabled. From my understanding this should match the requirements.

Yes, memory allocated with the DMA API should work as well, but would also require passing the device pointer for the device that is allocating the memory, which isn't a problem, but this way we don't need that.

Quoted 4 lines

Also how big can those firmware images get? Will __get_free_pages be able to provide this much contig memory in a long running system with fragmented memory space? Isn't CMA the better option here?

The largest is about 140 kilobytes. The space is also allocated when the device is initialized which usually happens during boot.

Quoted 3 lines

Regards,
Lucas

Thanks,
Mikko.

Quoted 220 lines
Quoted 203 lines
---
 drivers/gpu/drm/tegra/drm.c | 111 +++++++++++++++++++++++++++++++++++++++++---
 drivers/gpu/drm/tegra/drm.h |  11 +++++
 2 files changed, 115 insertions(+), 7 deletions(-)
drivers/gpu/drm/tegra/drm.c +104 -7
index b8be3ee..cf714c6 100644
@@ -1,12 +1,13 @@
 /*
  * Copyright (C) 2012 Avionic Design GmbH
- * Copyright (C) 2012-2013 NVIDIA CORPORATION.  All rights reserved.
+ * Copyright (C) 2012-2016 NVIDIA CORPORATION.  All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
  * published by the Free Software Foundation.
  */
 
+#include <linux/bitops.h>
 #include <linux/host1x.h>
 #include <linux/iommu.h>
 
@@ -23,6 +24,8 @@
 #define DRIVER_MINOR 0
 #define DRIVER_PATCHLEVEL 0
 
+#define CARVEOUT_SZ SZ_64M
+
 struct tegra_drm_file {
 	struct list_head contexts;
 };
@@ -127,7 +130,8 @@ static int tegra_drm_load(struct drm_device *drm, unsigned long flags)
 
 	if (iommu_present(&platform_bus_type)) {
 		struct iommu_domain_geometry *geometry;
-		u64 start, end;
+		unsigned long order;
+		u64 carveout_start, carveout_end, gem_start, gem_end;
 
 		tegra->domain = iommu_domain_alloc(&platform_bus_type);
 		if (!tegra->domain) {
@@ -136,12 +140,25 @@ static int tegra_drm_load(struct drm_device *drm, unsigned long flags)
 		}
 
 		geometry = &tegra->domain->geometry;
-		start = geometry->aperture_start;
-		end = geometry->aperture_end;
+		gem_start = geometry->aperture_start;
+		gem_end = geometry->aperture_end - CARVEOUT_SZ;
+		carveout_start = gem_end + 1;
+		carveout_end = geometry->aperture_end;
+
+		order = __ffs(tegra->domain->pgsize_bitmap);
+		init_iova_domain(&tegra->carveout.domain, 1UL << order,
+				 carveout_start >> order,
+				 carveout_end >> order);
+
+		tegra->carveout.shift = iova_shift(&tegra->carveout.domain);
+		tegra->carveout.limit = carveout_end >> tegra->carveout.shift;
+
+		drm_mm_init(&tegra->mm, gem_start, gem_end - gem_start + 1);
 
-		DRM_DEBUG_DRIVER("IOMMU aperture initialized (%#llx-%#llx)\n",
-				 start, end);
-		drm_mm_init(&tegra->mm, start, end - start + 1);
+		DRM_DEBUG("IOMMU apertures:\n");
+		DRM_DEBUG("  GEM: %#llx-%#llx\n", gem_start, gem_end);
+		DRM_DEBUG("  Carveout: %#llx-%#llx\n", carveout_start,
+			  carveout_end);
 	}
 
 	mutex_init(&tegra->clients_lock);
@@ -208,6 +225,7 @@ static int tegra_drm_load(struct drm_device *drm, unsigned long flags)
 	if (tegra->domain) {
 		iommu_domain_free(tegra->domain);
 		drm_mm_takedown(&tegra->mm);
+		put_iova_domain(&tegra->carveout.domain);
 	}
 free:
 	kfree(tegra);
@@ -232,6 +250,7 @@ static int tegra_drm_unload(struct drm_device *drm)
 	if (tegra->domain) {
 		iommu_domain_free(tegra->domain);
 		drm_mm_takedown(&tegra->mm);
+		put_iova_domain(&tegra->carveout.domain);
 	}
 
 	kfree(tegra);
@@ -975,6 +994,84 @@ int tegra_drm_unregister_client(struct tegra_drm *tegra,
 	return 0;
 }
 
+void *tegra_drm_alloc(struct tegra_drm *tegra, size_t size,
+			      dma_addr_t *dma)
+{
+	struct iova *alloc;
+	void *virt;
+	gfp_t gfp;
+	int err;
+
+	if (tegra->domain)
+		size = iova_align(&tegra->carveout.domain, size);
+	else
+		size = PAGE_ALIGN(size);
+
+	gfp = GFP_KERNEL | __GFP_ZERO;
+	if (!tegra->domain) {
+		/*
+		 * Many units only support 32-bit addresses, even on 64-bit
+		 * SoCs. If there is no IOMMU to translate into a 32-bit IO
+		 * virtual address space, force allocations to be in the
+		 * lower 32-bit range.
+		 */
+		gfp |= GFP_DMA;
+	}
+
+	virt = (void *)__get_free_pages(gfp, get_order(size));
+	if (!virt)
+		return ERR_PTR(-ENOMEM);
+
+	if (!tegra->domain) {
+		/*
+		 * If IOMMU is disabled, devices address physical memory
+		 * directly.
+		 */
+		*dma = virt_to_phys(virt);
+		return virt;
+	}
+
+	alloc = alloc_iova(&tegra->carveout.domain,
+			   size >> tegra->carveout.shift,
+			   tegra->carveout.limit, true);
+	if (!alloc) {
+		err = -EBUSY;
+		goto free_pages;
+	}
+
+	*dma = iova_dma_addr(&tegra->carveout.domain, alloc);
+	err = iommu_map(tegra->domain, *dma, virt_to_phys(virt),
+			size, IOMMU_READ | IOMMU_WRITE);
+	if (err < 0)
+		goto free_iova;
+
+	return virt;
+
+free_iova:
+	__free_iova(&tegra->carveout.domain, alloc);
+free_pages:
+	free_pages((unsigned long)virt, get_order(size));
+
+	return ERR_PTR(err);
+}
+
+void tegra_drm_free(struct tegra_drm *tegra, size_t size, void *virt,
+		    dma_addr_t dma)
+{
+	if (tegra->domain)
+		size = iova_align(&tegra->carveout.domain, size);
+	else
+		size = PAGE_ALIGN(size);
+
+	if (tegra->domain) {
+		iommu_unmap(tegra->domain, dma, size);
+		free_iova(&tegra->carveout.domain,
+			  iova_pfn(&tegra->carveout.domain, dma));
+	}
+
+	free_pages((unsigned long)virt, get_order(size));
+}
+
 static int host1x_drm_probe(struct host1x_device *dev)
 {
 	struct drm_driver *driver = &tegra_drm_driver;
drivers/gpu/drm/tegra/drm.h +7 -0
index 0ddcce1..7351dee 100644
@@ -12,6 +12,7 @@
 
 #include <uapi/drm/tegra_drm.h>
 #include <linux/host1x.h>
+#include <linux/iova.h>
 #include <linux/of_gpio.h>
 
 #include <drm/drmP.h>
@@ -43,6 +44,12 @@ struct tegra_drm {
 	struct iommu_domain *domain;
 	struct drm_mm mm;
 
+	struct {
+		struct iova_domain domain;
+		unsigned long shift;
+		unsigned long limit;
+	} carveout;
+
 	struct mutex clients_lock;
 	struct list_head clients;
 

drivers/gpu/drm/tegra/drm.h int tegra_drm_unregister_client(struct tegra_drm *tegra, · line 120

Quoted 10 lines
drivers/gpu/drm/tegra/drm.h +4 -0
@@ -104,6 +111,10 @@ int tegra_drm_unregister_client(struct tegra_drm *tegra,
 int tegra_drm_init(struct tegra_drm *tegra, struct drm_device *drm);
 int tegra_drm_exit(struct tegra_drm *tegra);
 
+void *tegra_drm_alloc(struct tegra_drm *tegra, size_t size, dma_addr_t *iova);
+void tegra_drm_free(struct tegra_drm *tegra, size_t size, void *virt,
+		    dma_addr_t iova);
+
 struct tegra_dc_soc_info;
 struct tegra_output;
 

--
To unsubscribe from this list: send the line "unsubscribe linux-tegra" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#6 lore raw

Re: [PATCH v2 1/7] drm/tegra: Add Tegra DRM allocation API

Am Mittwoch, den 14.12.2016, 14:36 +0200 schrieb Mikko Perttunen:

Quoted 13 lines · Lucas Stach
Quoted 12 lines

Am Mittwoch, den 14.12.2016, 13:16 +0200 schrieb Mikko Perttunen:

Quoted 11 lines

Add a new IO virtual memory allocation API to allow clients to allocate non-GEM memory in the Tegra DRM IOMMU domain. This is required e.g. for loading client firmware when clients are attached to the IOMMU domain.

The allocator allocates contiguous physical pages that are then mapped contiguously to the IOMMU domain using the iova_domain library provided by the kernel. Contiguous physical pages are used so that the same allocator works also when IOMMU support is disabled and therefore devices access physical memory directly.

Quoted 9 lines
Quoted 3 lines

Why is this needed? If you use the DMA API for those buffers you should end up with CMA memory in the !IOMMU case and normal paged memory with IOMMU enabled. From my understanding this should match the requirements.

Yes, memory allocated with the DMA API should work as well, but would also require passing the device pointer for the device that is allocating the memory, which isn't a problem, but this way we don't need that.

Which in turn would allow you to properly describe the DMA capabilities of engines that can address more than 32 bits without the IOMMU, which was one of the comments Thierry had the last time around IIRC.

Quoted 8 lines
Quoted 4 lines

Also how big can those firmware images get? Will __get_free_pages be able to provide this much contig memory in a long running system with fragmented memory space? Isn't CMA the better option here?

The largest is about 140 kilobytes. The space is also allocated when the device is initialized which usually happens during boot.

Which is an order 6 allocation, something you almost certainly don't get in a fragmented system. I know it may work most of the time, as you are allocating those buffers early, but is most of the time really enough? What happens on module unload/load at a later time?

Quoted 227 lines
Quoted 3 lines

Regards,
Lucas

Thanks,
Mikko.

Quoted 220 lines
Quoted 203 lines
---
 drivers/gpu/drm/tegra/drm.c | 111 +++++++++++++++++++++++++++++++++++++++++---
 drivers/gpu/drm/tegra/drm.h |  11 +++++
 2 files changed, 115 insertions(+), 7 deletions(-)
drivers/gpu/drm/tegra/drm.c +104 -7
index b8be3ee..cf714c6 100644
@@ -1,12 +1,13 @@
 /*
  * Copyright (C) 2012 Avionic Design GmbH
- * Copyright (C) 2012-2013 NVIDIA CORPORATION.  All rights reserved.
+ * Copyright (C) 2012-2016 NVIDIA CORPORATION.  All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
  * published by the Free Software Foundation.
  */
 
+#include <linux/bitops.h>
 #include <linux/host1x.h>
 #include <linux/iommu.h>
 
@@ -23,6 +24,8 @@
 #define DRIVER_MINOR 0
 #define DRIVER_PATCHLEVEL 0
 
+#define CARVEOUT_SZ SZ_64M
+
 struct tegra_drm_file {
 	struct list_head contexts;
 };
@@ -127,7 +130,8 @@ static int tegra_drm_load(struct drm_device *drm, unsigned long flags)
 
 	if (iommu_present(&platform_bus_type)) {
 		struct iommu_domain_geometry *geometry;
-		u64 start, end;
+		unsigned long order;
+		u64 carveout_start, carveout_end, gem_start, gem_end;
 
 		tegra->domain = iommu_domain_alloc(&platform_bus_type);
 		if (!tegra->domain) {
@@ -136,12 +140,25 @@ static int tegra_drm_load(struct drm_device *drm, unsigned long flags)
 		}
 
 		geometry = &tegra->domain->geometry;
-		start = geometry->aperture_start;
-		end = geometry->aperture_end;
+		gem_start = geometry->aperture_start;
+		gem_end = geometry->aperture_end - CARVEOUT_SZ;
+		carveout_start = gem_end + 1;
+		carveout_end = geometry->aperture_end;
+
+		order = __ffs(tegra->domain->pgsize_bitmap);
+		init_iova_domain(&tegra->carveout.domain, 1UL << order,
+				 carveout_start >> order,
+				 carveout_end >> order);
+
+		tegra->carveout.shift = iova_shift(&tegra->carveout.domain);
+		tegra->carveout.limit = carveout_end >> tegra->carveout.shift;
+
+		drm_mm_init(&tegra->mm, gem_start, gem_end - gem_start + 1);
 
-		DRM_DEBUG_DRIVER("IOMMU aperture initialized (%#llx-%#llx)\n",
-				 start, end);
-		drm_mm_init(&tegra->mm, start, end - start + 1);
+		DRM_DEBUG("IOMMU apertures:\n");
+		DRM_DEBUG("  GEM: %#llx-%#llx\n", gem_start, gem_end);
+		DRM_DEBUG("  Carveout: %#llx-%#llx\n", carveout_start,
+			  carveout_end);
 	}
 
 	mutex_init(&tegra->clients_lock);
@@ -208,6 +225,7 @@ static int tegra_drm_load(struct drm_device *drm, unsigned long flags)
 	if (tegra->domain) {
 		iommu_domain_free(tegra->domain);
 		drm_mm_takedown(&tegra->mm);
+		put_iova_domain(&tegra->carveout.domain);
 	}
 free:
 	kfree(tegra);
@@ -232,6 +250,7 @@ static int tegra_drm_unload(struct drm_device *drm)
 	if (tegra->domain) {
 		iommu_domain_free(tegra->domain);
 		drm_mm_takedown(&tegra->mm);
+		put_iova_domain(&tegra->carveout.domain);
 	}
 
 	kfree(tegra);
@@ -975,6 +994,84 @@ int tegra_drm_unregister_client(struct tegra_drm *tegra,
 	return 0;
 }
 
+void *tegra_drm_alloc(struct tegra_drm *tegra, size_t size,
+			      dma_addr_t *dma)
+{
+	struct iova *alloc;
+	void *virt;
+	gfp_t gfp;
+	int err;
+
+	if (tegra->domain)
+		size = iova_align(&tegra->carveout.domain, size);
+	else
+		size = PAGE_ALIGN(size);
+
+	gfp = GFP_KERNEL | __GFP_ZERO;
+	if (!tegra->domain) {
+		/*
+		 * Many units only support 32-bit addresses, even on 64-bit
+		 * SoCs. If there is no IOMMU to translate into a 32-bit IO
+		 * virtual address space, force allocations to be in the
+		 * lower 32-bit range.
+		 */
+		gfp |= GFP_DMA;
+	}
+
+	virt = (void *)__get_free_pages(gfp, get_order(size));
+	if (!virt)
+		return ERR_PTR(-ENOMEM);
+
+	if (!tegra->domain) {
+		/*
+		 * If IOMMU is disabled, devices address physical memory
+		 * directly.
+		 */
+		*dma = virt_to_phys(virt);
+		return virt;
+	}
+
+	alloc = alloc_iova(&tegra->carveout.domain,
+			   size >> tegra->carveout.shift,
+			   tegra->carveout.limit, true);
+	if (!alloc) {
+		err = -EBUSY;
+		goto free_pages;
+	}
+
+	*dma = iova_dma_addr(&tegra->carveout.domain, alloc);
+	err = iommu_map(tegra->domain, *dma, virt_to_phys(virt),
+			size, IOMMU_READ | IOMMU_WRITE);
+	if (err < 0)
+		goto free_iova;
+
+	return virt;
+
+free_iova:
+	__free_iova(&tegra->carveout.domain, alloc);
+free_pages:
+	free_pages((unsigned long)virt, get_order(size));
+
+	return ERR_PTR(err);
+}
+
+void tegra_drm_free(struct tegra_drm *tegra, size_t size, void *virt,
+		    dma_addr_t dma)
+{
+	if (tegra->domain)
+		size = iova_align(&tegra->carveout.domain, size);
+	else
+		size = PAGE_ALIGN(size);
+
+	if (tegra->domain) {
+		iommu_unmap(tegra->domain, dma, size);
+		free_iova(&tegra->carveout.domain,
+			  iova_pfn(&tegra->carveout.domain, dma));
+	}
+
+	free_pages((unsigned long)virt, get_order(size));
+}
+
 static int host1x_drm_probe(struct host1x_device *dev)
 {
 	struct drm_driver *driver = &tegra_drm_driver;
drivers/gpu/drm/tegra/drm.h +7 -0
index 0ddcce1..7351dee 100644
@@ -12,6 +12,7 @@
 
 #include <uapi/drm/tegra_drm.h>
 #include <linux/host1x.h>
+#include <linux/iova.h>
 #include <linux/of_gpio.h>
 
 #include <drm/drmP.h>
@@ -43,6 +44,12 @@ struct tegra_drm {
 	struct iommu_domain *domain;
 	struct drm_mm mm;
 
+	struct {
+		struct iova_domain domain;
+		unsigned long shift;
+		unsigned long limit;
+	} carveout;
+
 	struct mutex clients_lock;
 	struct list_head clients;
 

drivers/gpu/drm/tegra/drm.h int tegra_drm_unregister_client(struct tegra_drm *tegra, · line 120

Quoted 10 lines
drivers/gpu/drm/tegra/drm.h +4 -0
@@ -104,6 +111,10 @@ int tegra_drm_unregister_client(struct tegra_drm *tegra,
 int tegra_drm_init(struct tegra_drm *tegra, struct drm_device *drm);
 int tegra_drm_exit(struct tegra_drm *tegra);
 
+void *tegra_drm_alloc(struct tegra_drm *tegra, size_t size, dma_addr_t *iova);
+void tegra_drm_free(struct tegra_drm *tegra, size_t size, void *virt,
+		    dma_addr_t iova);
+
 struct tegra_dc_soc_info;
 struct tegra_output;
 

--
To unsubscribe from this list: send the line "unsubscribe linux-tegra" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

A message that is not in the archive (sent off-list or not yet received): [email protected]

#8 lore raw

Re: [PATCH v2 1/7] drm/tegra: Add Tegra DRM allocation API

Quoted 18 lines · Lucas Stach

Am Mittwoch, den 14.12.2016, 14:36 +0200 schrieb Mikko Perttunen:

Quoted 17 lines · Lucas Stach
Quoted 15 lines

Am Mittwoch, den 14.12.2016, 13:16 +0200 schrieb Mikko Perttunen:

Quoted 11 lines

Add a new IO virtual memory allocation API to allow clients to allocate non-GEM memory in the Tegra DRM IOMMU domain. This is required e.g. for loading client firmware when clients are attached to the IOMMU domain.

The allocator allocates contiguous physical pages that are then mapped contiguously to the IOMMU domain using the iova_domain library provided by the kernel. Contiguous physical pages are used so that the same allocator works also when IOMMU support is disabled and therefore devices access physical memory directly.

Why is this needed? If you use the DMA API for those buffers you should end up with CMA memory in the !IOMMU case and normal paged memory with IOMMU enabled. From my understanding this should match the requirements.

Quoted 8 lines
Quoted 5 lines

Yes, memory allocated with the DMA API should work as well, but would also require passing the device pointer for the device that is allocating the memory, which isn't a problem, but this way we don't need that.

Which in turn would allow you to properly describe the DMA capabilities of engines that can address more than 32 bits without the IOMMU, which was one of the comments Thierry had the last time around IIRC.

In this case, just the device's DMA mask wouldn't allow that, since chips post Tegra132 do have units that support more than 32 bits generally but the firmware must still be in the lower 4G.

I guess this means that we would need to set the DMA mask to the lowest common denominator which is 32 bits, even though we want to have the full 34 bits for the GEM objects. However, this should only be an issue when the IOMMU is disabled so it isn't really that much of a problem.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

Also how big can those firmware images get? Will __get_free_pages be able to provide this much contig memory in a long running system with fragmented memory space? Isn't CMA the better option here?

Quoted 7 lines
Quoted 3 lines

The largest is about 140 kilobytes. The space is also allocated when the device is initialized which usually happens during boot.

Which is an order 6 allocation, something you almost certainly don't get in a fragmented system. I know it may work most of the time, as you are allocating those buffers early, but is most of the time really enough? What happens on module unload/load at a later time?

Yeah, it's probably worth fixing.

Thanks,
Mikko.

Quoted 230 lines
Quoted 228 lines
Quoted 4 lines

Regards,
Lucas

Thanks,
Mikko.

Quoted 220 lines
Quoted 203 lines
---
 drivers/gpu/drm/tegra/drm.c | 111 +++++++++++++++++++++++++++++++++++++++++---
 drivers/gpu/drm/tegra/drm.h |  11 +++++
 2 files changed, 115 insertions(+), 7 deletions(-)
drivers/gpu/drm/tegra/drm.c +104 -7
index b8be3ee..cf714c6 100644
@@ -1,12 +1,13 @@
 /*
  * Copyright (C) 2012 Avionic Design GmbH
- * Copyright (C) 2012-2013 NVIDIA CORPORATION.  All rights reserved.
+ * Copyright (C) 2012-2016 NVIDIA CORPORATION.  All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
  * published by the Free Software Foundation.
  */
 
+#include <linux/bitops.h>
 #include <linux/host1x.h>
 #include <linux/iommu.h>
 
@@ -23,6 +24,8 @@
 #define DRIVER_MINOR 0
 #define DRIVER_PATCHLEVEL 0
 
+#define CARVEOUT_SZ SZ_64M
+
 struct tegra_drm_file {
 	struct list_head contexts;
 };
@@ -127,7 +130,8 @@ static int tegra_drm_load(struct drm_device *drm, unsigned long flags)
 
 	if (iommu_present(&platform_bus_type)) {
 		struct iommu_domain_geometry *geometry;
-		u64 start, end;
+		unsigned long order;
+		u64 carveout_start, carveout_end, gem_start, gem_end;
 
 		tegra->domain = iommu_domain_alloc(&platform_bus_type);
 		if (!tegra->domain) {
@@ -136,12 +140,25 @@ static int tegra_drm_load(struct drm_device *drm, unsigned long flags)
 		}
 
 		geometry = &tegra->domain->geometry;
-		start = geometry->aperture_start;
-		end = geometry->aperture_end;
+		gem_start = geometry->aperture_start;
+		gem_end = geometry->aperture_end - CARVEOUT_SZ;
+		carveout_start = gem_end + 1;
+		carveout_end = geometry->aperture_end;
+
+		order = __ffs(tegra->domain->pgsize_bitmap);
+		init_iova_domain(&tegra->carveout.domain, 1UL << order,
+				 carveout_start >> order,
+				 carveout_end >> order);
+
+		tegra->carveout.shift = iova_shift(&tegra->carveout.domain);
+		tegra->carveout.limit = carveout_end >> tegra->carveout.shift;
+
+		drm_mm_init(&tegra->mm, gem_start, gem_end - gem_start + 1);
 
-		DRM_DEBUG_DRIVER("IOMMU aperture initialized (%#llx-%#llx)\n",
-				 start, end);
-		drm_mm_init(&tegra->mm, start, end - start + 1);
+		DRM_DEBUG("IOMMU apertures:\n");
+		DRM_DEBUG("  GEM: %#llx-%#llx\n", gem_start, gem_end);
+		DRM_DEBUG("  Carveout: %#llx-%#llx\n", carveout_start,
+			  carveout_end);
 	}
 
 	mutex_init(&tegra->clients_lock);
@@ -208,6 +225,7 @@ static int tegra_drm_load(struct drm_device *drm, unsigned long flags)
 	if (tegra->domain) {
 		iommu_domain_free(tegra->domain);
 		drm_mm_takedown(&tegra->mm);
+		put_iova_domain(&tegra->carveout.domain);
 	}
 free:
 	kfree(tegra);
@@ -232,6 +250,7 @@ static int tegra_drm_unload(struct drm_device *drm)
 	if (tegra->domain) {
 		iommu_domain_free(tegra->domain);
 		drm_mm_takedown(&tegra->mm);
+		put_iova_domain(&tegra->carveout.domain);
 	}
 
 	kfree(tegra);
@@ -975,6 +994,84 @@ int tegra_drm_unregister_client(struct tegra_drm *tegra,
 	return 0;
 }
 
+void *tegra_drm_alloc(struct tegra_drm *tegra, size_t size,
+			      dma_addr_t *dma)
+{
+	struct iova *alloc;
+	void *virt;
+	gfp_t gfp;
+	int err;
+
+	if (tegra->domain)
+		size = iova_align(&tegra->carveout.domain, size);
+	else
+		size = PAGE_ALIGN(size);
+
+	gfp = GFP_KERNEL | __GFP_ZERO;
+	if (!tegra->domain) {
+		/*
+		 * Many units only support 32-bit addresses, even on 64-bit
+		 * SoCs. If there is no IOMMU to translate into a 32-bit IO
+		 * virtual address space, force allocations to be in the
+		 * lower 32-bit range.
+		 */
+		gfp |= GFP_DMA;
+	}
+
+	virt = (void *)__get_free_pages(gfp, get_order(size));
+	if (!virt)
+		return ERR_PTR(-ENOMEM);
+
+	if (!tegra->domain) {
+		/*
+		 * If IOMMU is disabled, devices address physical memory
+		 * directly.
+		 */
+		*dma = virt_to_phys(virt);
+		return virt;
+	}
+
+	alloc = alloc_iova(&tegra->carveout.domain,
+			   size >> tegra->carveout.shift,
+			   tegra->carveout.limit, true);
+	if (!alloc) {
+		err = -EBUSY;
+		goto free_pages;
+	}
+
+	*dma = iova_dma_addr(&tegra->carveout.domain, alloc);
+	err = iommu_map(tegra->domain, *dma, virt_to_phys(virt),
+			size, IOMMU_READ | IOMMU_WRITE);
+	if (err < 0)
+		goto free_iova;
+
+	return virt;
+
+free_iova:
+	__free_iova(&tegra->carveout.domain, alloc);
+free_pages:
+	free_pages((unsigned long)virt, get_order(size));
+
+	return ERR_PTR(err);
+}
+
+void tegra_drm_free(struct tegra_drm *tegra, size_t size, void *virt,
+		    dma_addr_t dma)
+{
+	if (tegra->domain)
+		size = iova_align(&tegra->carveout.domain, size);
+	else
+		size = PAGE_ALIGN(size);
+
+	if (tegra->domain) {
+		iommu_unmap(tegra->domain, dma, size);
+		free_iova(&tegra->carveout.domain,
+			  iova_pfn(&tegra->carveout.domain, dma));
+	}
+
+	free_pages((unsigned long)virt, get_order(size));
+}
+
 static int host1x_drm_probe(struct host1x_device *dev)
 {
 	struct drm_driver *driver = &tegra_drm_driver;
drivers/gpu/drm/tegra/drm.h +7 -0
index 0ddcce1..7351dee 100644
@@ -12,6 +12,7 @@
 
 #include <uapi/drm/tegra_drm.h>
 #include <linux/host1x.h>
+#include <linux/iova.h>
 #include <linux/of_gpio.h>
 
 #include <drm/drmP.h>
@@ -43,6 +44,12 @@ struct tegra_drm {
 	struct iommu_domain *domain;
 	struct drm_mm mm;
 
+	struct {
+		struct iova_domain domain;
+		unsigned long shift;
+		unsigned long limit;
+	} carveout;
+
 	struct mutex clients_lock;
 	struct list_head clients;
 

drivers/gpu/drm/tegra/drm.h int tegra_drm_unregister_client(struct tegra_drm *tegra, · line 120

Quoted 10 lines
drivers/gpu/drm/tegra/drm.h +4 -0
@@ -104,6 +111,10 @@ int tegra_drm_unregister_client(struct tegra_drm *tegra,
 int tegra_drm_init(struct tegra_drm *tegra, struct drm_device *drm);
 int tegra_drm_exit(struct tegra_drm *tegra);
 
+void *tegra_drm_alloc(struct tegra_drm *tegra, size_t size, dma_addr_t *iova);
+void tegra_drm_free(struct tegra_drm *tegra, size_t size, void *virt,
+		    dma_addr_t iova);
+
 struct tegra_dc_soc_info;
 struct tegra_output;
 

--
To unsubscribe from this list: send the line "unsubscribe linux-tegra" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#9 lore raw

Re: [PATCH v2 1/7] drm/tegra: Add Tegra DRM allocation API

In reply to a message not in the archive
Quoted 12 lines · Lucas Stach

Am Mittwoch, den 14.12.2016, 13:16 +0200 schrieb Mikko Perttunen:

Quoted 11 lines

Add a new IO virtual memory allocation API to allow clients to allocate non-GEM memory in the Tegra DRM IOMMU domain. This is required e.g. for loading client firmware when clients are attached to the IOMMU domain.

The allocator allocates contiguous physical pages that are then mapped contiguously to the IOMMU domain using the iova_domain library provided by the kernel. Contiguous physical pages are used so that the same allocator works also when IOMMU support is disabled and therefore devices access physical memory directly.

Quoted 3 lines

Why is this needed? If you use the DMA API for those buffers you should end up with CMA memory in the !IOMMU case and normal paged memory with IOMMU enabled. From my understanding this should match the requirements.

We can't currently use the DMA API for these allocations because it doesn't allow (or at least didn't back when this was first implemented) us to share a mapping between two devices.

The reason why we need these patches is that when IOMMU is enabled, then the units' falcons will read memory through the IOMMU, so we must have allocations for GEM buffers and the firmware go through the same mechanism.

Thierry

A message that is not in the archive (sent off-list or not yet received): [email protected]

#11 lore raw

Re: [PATCH v2 1/7] drm/tegra: Add Tegra DRM allocation API

Am Mittwoch, den 14.12.2016, 14:48 +0100 schrieb Thierry Reding:

Quoted 13 lines · Lucas Stach
Quoted 12 lines

Am Mittwoch, den 14.12.2016, 13:16 +0200 schrieb Mikko Perttunen:

Quoted 11 lines

Add a new IO virtual memory allocation API to allow clients to allocate non-GEM memory in the Tegra DRM IOMMU domain. This is required e.g. for loading client firmware when clients are attached to the IOMMU domain.

The allocator allocates contiguous physical pages that are then mapped contiguously to the IOMMU domain using the iova_domain library provided by the kernel. Contiguous physical pages are used so that the same allocator works also when IOMMU support is disabled and therefore devices access physical memory directly.

Quoted 7 lines
Quoted 3 lines

Why is this needed? If you use the DMA API for those buffers you should end up with CMA memory in the !IOMMU case and normal paged memory with IOMMU enabled. From my understanding this should match the requirements.

We can't currently use the DMA API for these allocations because it doesn't allow (or at least didn't back when this was first implemented) us to share a mapping between two devices.

Hm, maybe I'm overlooking something, but isn't this just a matter of allocating on one device, then constructing a SG list (dma_get_sgtable) from the buffer you got and use that to dma_map_sg() the buffer on the other device?

Maybe doing the firmware buffer allocation on host1x (with a 4GB upper bound) and then sharing the SG list to the devices?

Quoted 4 lines

The reason why we need these patches is that when IOMMU is enabled, then the units' falcons will read memory through the IOMMU, so we must have allocations for GEM buffers and the firmware go through the same mechanism.

Sorry for maybe dumb questions.

Do you have any engines other than the GPU that can handle SG themselves? Wouldn't you want the GEM objects to be backed by CMA in the !MMU case? How are ordinary GEM objects different from the falcon firmware?

Regards,
Lucas

A message that is not in the archive (sent off-list or not yet received): [email protected]

#13 lore raw

Re: [PATCH v2 1/7] drm/tegra: Add Tegra DRM allocation API

Quoted 18 lines · Lucas Stach

Am Mittwoch, den 14.12.2016, 14:48 +0100 schrieb Thierry Reding:

Quoted 17 lines · Lucas Stach
Quoted 15 lines

Am Mittwoch, den 14.12.2016, 13:16 +0200 schrieb Mikko Perttunen:

Quoted 11 lines

Add a new IO virtual memory allocation API to allow clients to allocate non-GEM memory in the Tegra DRM IOMMU domain. This is required e.g. for loading client firmware when clients are attached to the IOMMU domain.

The allocator allocates contiguous physical pages that are then mapped contiguously to the IOMMU domain using the iova_domain library provided by the kernel. Contiguous physical pages are used so that the same allocator works also when IOMMU support is disabled and therefore devices access physical memory directly.

Why is this needed? If you use the DMA API for those buffers you should end up with CMA memory in the !IOMMU case and normal paged memory with IOMMU enabled. From my understanding this should match the requirements.

Quoted 8 lines
Quoted 3 lines

We can't currently use the DMA API for these allocations because it doesn't allow (or at least didn't back when this was first implemented) us to share a mapping between two devices.

Hm, maybe I'm overlooking something, but isn't this just a matter of allocating on one device, then constructing a SG list (dma_get_sgtable) from the buffer you got and use that to dma_map_sg() the buffer on the other device?

Yes, that would work. What I was referring to is sharing framebuffers between multiple CRTCs. Back at the time when IOMMU support was first added, I tried to use the DMA API. However, the problem with that was that we would've had to effectively dma_map_sg() on every page-flip since the buffer is imported into the DRM device, but there's no call that would import it for each CRTC only once. So when the framebuffer is added to a plane, you have to map it to the corresponding display controller. And the dma_map_sg() was, if I recall correctly, on the order of 5-10 ms, which is prohibitively expensive to do per frame.

It's also completely unnecessary because all CRTCs in a DRM device can simply share the same IOMMU domain. I can't think of a reason why you would want or need to use separate domains.

Back at the time this was something that the DMA API couldn't do, it would simply assign a separate IOMMU domain per device. It's possible that this has changed now given that many others must've run into the same problem meanwhile.

Quoted 2 lines

Maybe doing the firmware buffer allocation on host1x (with a 4GB upper bound) and then sharing the SG list to the devices?

That's pretty much what this API is doing. Only it's the other way
around: we don't share the SG list with other devices for mapping, we simply reuse the same mapping across multiple devices, since they're all in the same IOMMU domain.

Quoted 9 lines
Quoted 4 lines

The reason why we need these patches is that when IOMMU is enabled, then the units' falcons will read memory through the IOMMU, so we must have allocations for GEM buffers and the firmware go through the same mechanism.

Sorry for maybe dumb questions.

Do you have any engines other than the GPU that can handle SG themselves?

No, I don't think so.

Quoted 2 lines

Wouldn't you want the GEM objects to be backed by CMA in the !MMU case?

That's exactly what's happening already. If no IOMMU is available we allocate buffer objects backing store with dma_alloc_wc().

Quoted 1 line

How are ordinary GEM objects different from the falcon firmware?

They're not. I think we could probably reuse more of the BO allocation functions for the firmware as well. I think Mikko already agreed to look into that. We might have to add some special cases, or split up the helpers a little differently to avoid creating GEM objects from the firmware buffers. We wouldn't want userspace to start mmap()'ing those.

Thierry

A message that is not in the archive (sent off-list or not yet received): [email protected]

#15 lore raw

Re: [PATCH v2 1/7] drm/tegra: Add Tegra DRM allocation API

So with the userspace question resolved, only this question of memory allocation remains. I see the following options:

- Keep the current __get_free_pages-based allocation. This means that firmware loading may fail when memory is fragmented. The function can be augmented by adding vmalloc support when IOMMU is enabled, which would eliminate those failures.

- Move to doing CMA allocation using the DMA API. This way allocations would succeed more likely at least if the user has enough CMA memory.
In this case we'll need to pass an additional struct device * to the alloc/free functions. This also requires that the CMA memory is always allocated from the lower 4GB physical address range, as firmware can only be loaded from there (other operations support 34 bits); I don't know how the default CMA region is allocated, maybe I should find out.

This option would also require adding a separate path for when the IOMMU is enabled and CMA not available - AIUI, on Tegra, the DMA API always allocates from CMA, whether IOMMU is enabled or not. (Or, we could make CMA mandatory.)

For me, either option works. Also, sorry if I made some stupid mistake, my brain is currently too tired to handle multiple address spaces at the same time :)

Cheers,
Mikko.

Quoted 83 lines · Thierry Reding
Quoted 18 lines · Lucas Stach

Am Mittwoch, den 14.12.2016, 14:48 +0100 schrieb Thierry Reding:

Quoted 17 lines · Lucas Stach
Quoted 15 lines

Am Mittwoch, den 14.12.2016, 13:16 +0200 schrieb Mikko Perttunen:

Quoted 11 lines

Add a new IO virtual memory allocation API to allow clients to allocate non-GEM memory in the Tegra DRM IOMMU domain. This is required e.g. for loading client firmware when clients are attached to the IOMMU domain.

The allocator allocates contiguous physical pages that are then mapped contiguously to the IOMMU domain using the iova_domain library provided by the kernel. Contiguous physical pages are used so that the same allocator works also when IOMMU support is disabled and therefore devices access physical memory directly.

Why is this needed? If you use the DMA API for those buffers you should end up with CMA memory in the !IOMMU case and normal paged memory with IOMMU enabled. From my understanding this should match the requirements.

Quoted 8 lines
Quoted 3 lines

We can't currently use the DMA API for these allocations because it doesn't allow (or at least didn't back when this was first implemented) us to share a mapping between two devices.

Hm, maybe I'm overlooking something, but isn't this just a matter of allocating on one device, then constructing a SG list (dma_get_sgtable) from the buffer you got and use that to dma_map_sg() the buffer on the other device?

Yes, that would work. What I was referring to is sharing framebuffers between multiple CRTCs. Back at the time when IOMMU support was first added, I tried to use the DMA API. However, the problem with that was that we would've had to effectively dma_map_sg() on every page-flip since the buffer is imported into the DRM device, but there's no call that would import it for each CRTC only once. So when the framebuffer is added to a plane, you have to map it to the corresponding display controller. And the dma_map_sg() was, if I recall correctly, on the order of 5-10 ms, which is prohibitively expensive to do per frame.

It's also completely unnecessary because all CRTCs in a DRM device can simply share the same IOMMU domain. I can't think of a reason why you would want or need to use separate domains.

Back at the time this was something that the DMA API couldn't do, it would simply assign a separate IOMMU domain per device. It's possible that this has changed now given that many others must've run into the same problem meanwhile.

Quoted 2 lines

Maybe doing the firmware buffer allocation on host1x (with a 4GB upper bound) and then sharing the SG list to the devices?

That's pretty much what this API is doing. Only it's the other way
around: we don't share the SG list with other devices for mapping, we simply reuse the same mapping across multiple devices, since they're all in the same IOMMU domain.

Quoted 9 lines
Quoted 4 lines

The reason why we need these patches is that when IOMMU is enabled, then the units' falcons will read memory through the IOMMU, so we must have allocations for GEM buffers and the firmware go through the same mechanism.

Sorry for maybe dumb questions.

Do you have any engines other than the GPU that can handle SG themselves?

No, I don't think so.

Quoted 2 lines

Wouldn't you want the GEM objects to be backed by CMA in the !MMU case?

That's exactly what's happening already. If no IOMMU is available we allocate buffer objects backing store with dma_alloc_wc().

Quoted 1 line

How are ordinary GEM objects different from the falcon firmware?

They're not. I think we could probably reuse more of the BO allocation functions for the firmware as well. I think Mikko already agreed to look into that. We might have to add some special cases, or split up the helpers a little differently to avoid creating GEM objects from the firmware buffers. We wouldn't want userspace to start mmap()'ing those.

Thierry

#16 lore raw

PATCH v2 2/7 drm/tegra: Add falcon helper library

In reply to a message not in the archive

From: Arto Merilainen <[email protected]>

Add a set of falcon helper routines for use by the tegradrm client drivers of the various falcon-based engines.

The falcon is a microcontroller that acts as a frontend for the rest of a particular Tegra engine. In order to properly utilize these engines, the frontend must be booted before pushing any commands.

Based on work by Andrew Chew <[email protected]>

---
 drivers/gpu/drm/tegra/Makefile |   3 +-
 drivers/gpu/drm/tegra/falcon.c | 259 +++++++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/tegra/falcon.h | 127 ++++++++++++++++++++
 3 files changed, 388 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/tegra/falcon.c
 create mode 100644 drivers/gpu/drm/tegra/falcon.h
drivers/gpu/drm/tegra/Makefile +2 -1
index 2c66a8d..93e9a4a 100644
@@ -13,6 +13,7 @@ tegra-drm-y := \
 	sor.o \
 	dpaux.o \
 	gr2d.o \
-	gr3d.o
+	gr3d.o \
+	falcon.o
 
 obj-$(CONFIG_DRM_TEGRA) += tegra-drm.o
drivers/gpu/drm/tegra/falcon.c new file +259 -0

259 lines not on this page · raw message

drivers/gpu/drm/tegra/falcon.h new file +127 -0

127 lines not on this page · raw message

Signature · 1 line
2.10.2
#17 lore raw

PATCH v2 3/7 drm/tegra: Add VIC support

In reply to a message not in the archive

From: Arto Merilainen <[email protected]>

This patch adds support for Video Image Compositor engine which can be used for 2d operations.

---
 drivers/gpu/drm/tegra/Makefile |   3 +-
 drivers/gpu/drm/tegra/drm.c    |   3 +
 drivers/gpu/drm/tegra/drm.h    |   1 +
 drivers/gpu/drm/tegra/vic.c    | 396 +++++++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/tegra/vic.h    |  31 ++++
 include/linux/host1x.h         |   1 +
 6 files changed, 434 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/tegra/vic.c
 create mode 100644 drivers/gpu/drm/tegra/vic.h
drivers/gpu/drm/tegra/Makefile +2 -1
index 93e9a4a..6af3a9a 100644
@@ -14,6 +14,7 @@ tegra-drm-y := \
 	dpaux.o \
 	gr2d.o \
 	gr3d.o \
-	falcon.o
+	falcon.o \
+	vic.o
 
 obj-$(CONFIG_DRM_TEGRA) += tegra-drm.o
drivers/gpu/drm/tegra/drm.c +3 -0
index cf714c6..f47692e 100644
@@ -1160,11 +1160,13 @@ static const struct of_device_id host1x_drm_subdevs[] = {
 	{ .compatible = "nvidia,tegra124-sor", },
 	{ .compatible = "nvidia,tegra124-hdmi", },
 	{ .compatible = "nvidia,tegra124-dsi", },
+	{ .compatible = "nvidia,tegra124-vic", },
 	{ .compatible = "nvidia,tegra132-dsi", },
 	{ .compatible = "nvidia,tegra210-dc", },
 	{ .compatible = "nvidia,tegra210-dsi", },
 	{ .compatible = "nvidia,tegra210-sor", },
 	{ .compatible = "nvidia,tegra210-sor1", },
+	{ .compatible = "nvidia,tegra210-vic", },
 	{ /* sentinel */ }
 };
 
@@ -1186,6 +1188,7 @@ static struct platform_driver * const drivers[] = {
 	&tegra_sor_driver,
 	&tegra_gr2d_driver,
 	&tegra_gr3d_driver,
+	&tegra_vic_driver,
 };
 
 static int __init host1x_drm_init(void)
drivers/gpu/drm/tegra/drm.h +1 -0
index 7351dee..6a57e66 100644
@@ -296,5 +296,6 @@ extern struct platform_driver tegra_dpaux_driver;
 extern struct platform_driver tegra_sor_driver;
 extern struct platform_driver tegra_gr2d_driver;
 extern struct platform_driver tegra_gr3d_driver;
+extern struct platform_driver tegra_vic_driver;
 
 #endif /* HOST1X_DRM_H */
drivers/gpu/drm/tegra/vic.c new file +396 -0

396 lines not on this page · raw message

drivers/gpu/drm/tegra/vic.h new file +31 -0
new file mode 100644
index 0000000..2184481
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2015, NVIDIA Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef TEGRA_VIC_H
+#define TEGRA_VIC_H
+
+/* VIC methods */
+
+#define VIC_SET_APPLICATION_ID			0x00000200
+#define VIC_SET_FCE_UCODE_SIZE			0x0000071C
+#define VIC_SET_FCE_UCODE_OFFSET		0x0000072C
+
+/* VIC registers */
+
+#define NV_PVIC_MISC_PRI_VIC_CG			0x000016d0
+#define CG_IDLE_CG_DLY_CNT(val)			((val & 0x3f) << 0)
+#define CG_IDLE_CG_EN				(1 << 6)
+#define CG_WAKEUP_DLY_CNT(val)			((val & 0xf) << 16)
+
+/* Firmware offsets */
+
+#define VIC_UCODE_FCE_HEADER_OFFSET		(6*4)
+#define VIC_UCODE_FCE_DATA_OFFSET		(7*4)
+#define FCE_UCODE_SIZE_OFFSET			(2*4)
+
+#endif /* TEGRA_VIC_H */
include/linux/host1x.h +1 -0
index 1ffbf2a..3d04aa1 100644
@@ -26,6 +26,7 @@ enum host1x_class {
 	HOST1X_CLASS_HOST1X = 0x1,
 	HOST1X_CLASS_GR2D = 0x51,
 	HOST1X_CLASS_GR2D_SB = 0x52,
+	HOST1X_CLASS_VIC = 0x5D,
 	HOST1X_CLASS_GR3D = 0x60,
 };
 
Signature · 1 line
2.10.2
#18 lore raw

PATCH v2 4/7 gpu: host1x: Add IOMMU support

In reply to a message not in the archive

Add support for the Host1x unit to be located behind an IOMMU. This is required when gather buffers may be allocated non-contiguously in physical memory, as can be the case when TegraDRM is also using the IOMMU.

---
 drivers/gpu/host1x/cdma.c       | 74 ++++++++++++++++++++++++++++++++---------
 drivers/gpu/host1x/cdma.h       |  6 ++--
 drivers/gpu/host1x/dev.c        | 40 ++++++++++++++++++++--
 drivers/gpu/host1x/dev.h        |  6 ++++
 drivers/gpu/host1x/hw/cdma_hw.c | 16 ++++-----
 drivers/gpu/host1x/job.c        | 72 +++++++++++++++++++++++++++++++++------
 drivers/gpu/host1x/job.h        |  1 +
 7 files changed, 176 insertions(+), 39 deletions(-)
drivers/gpu/host1x/cdma.c +58 -16
index c5d82a8..28541b2 100644
@@ -51,9 +51,15 @@ static void host1x_pushbuffer_destroy(struct push_buffer *pb)
 	struct host1x_cdma *cdma = pb_to_cdma(pb);
 	struct host1x *host1x = cdma_to_host1x(cdma);
 
-	if (pb->phys != 0)
-		dma_free_wc(host1x->dev, pb->size_bytes + 4, pb->mapped,
-			    pb->phys);
+	if (!pb->phys)
+		return;
+
+	if (host1x->domain) {
+		iommu_unmap(host1x->domain, pb->dma, pb->alloc_size);
+		free_iova(&host1x->iova, iova_pfn(&host1x->iova, pb->dma));
+	}
+
+	dma_free_wc(host1x->dev, pb->alloc_size, pb->mapped, pb->phys);
 
 	pb->mapped = NULL;
 	pb->phys = 0;
@@ -66,28 +72,64 @@ static int host1x_pushbuffer_init(struct push_buffer *pb)
 {
 	struct host1x_cdma *cdma = pb_to_cdma(pb);
 	struct host1x *host1x = cdma_to_host1x(cdma);
+	struct iova *alloc;
+	u32 size;
+	int err;
 
 	pb->mapped = NULL;
 	pb->phys = 0;
-	pb->size_bytes = HOST1X_PUSHBUFFER_SLOTS * 8;
+	pb->size = HOST1X_PUSHBUFFER_SLOTS * 8;
+
+	size = pb->size + 4;
 
 	/* initialize buffer pointers */
-	pb->fence = pb->size_bytes - 8;
+	pb->fence = pb->size - 8;
 	pb->pos = 0;
 
-	/* allocate and map pushbuffer memory */
-	pb->mapped = dma_alloc_wc(host1x->dev, pb->size_bytes + 4, &pb->phys,
-				  GFP_KERNEL);
-	if (!pb->mapped)
-		goto fail;
+	if (host1x->domain) {
+		unsigned long shift;
+
+		size = iova_align(&host1x->iova, size);
+
+		pb->mapped = dma_alloc_wc(host1x->dev, size, &pb->phys,
+					  GFP_KERNEL);
+		if (!pb->mapped)
+			return -ENOMEM;
+
+		shift = iova_shift(&host1x->iova);
+		alloc = alloc_iova(&host1x->iova, size >> shift,
+				   host1x->iova_end >> shift, true);
+		if (!alloc) {
+			err = -ENOMEM;
+			goto iommu_free_mem;
+		}
+
+		pb->dma = iova_dma_addr(&host1x->iova, alloc);
+		err = iommu_map(host1x->domain, pb->dma, pb->phys, size,
+				IOMMU_READ);
+		if (err)
+			goto iommu_free_iova;
+	} else {
+		pb->mapped = dma_alloc_wc(host1x->dev, size, &pb->phys,
+					  GFP_KERNEL);
+		if (!pb->mapped)
+			return -ENOMEM;
+
+		pb->dma = pb->phys;
+	}
+
+	pb->alloc_size = size;
 
 	host1x_hw_pushbuffer_init(host1x, pb);
 
 	return 0;
 
-fail:
-	host1x_pushbuffer_destroy(pb);
-	return -ENOMEM;
+iommu_free_iova:
+	__free_iova(&host1x->iova, alloc);
+iommu_free_mem:
+	dma_free_wc(host1x->dev, pb->alloc_size, pb->mapped, pb->phys);
+
+	return err;
 }
 
 /*
@@ -101,7 +143,7 @@ static void host1x_pushbuffer_push(struct push_buffer *pb, u32 op1, u32 op2)
 	WARN_ON(pb->pos == pb->fence);
 	*(p++) = op1;
 	*(p++) = op2;
-	pb->pos = (pb->pos + 8) & (pb->size_bytes - 1);
+	pb->pos = (pb->pos + 8) & (pb->size - 1);
 }
 
 /*
@@ -111,7 +153,7 @@ static void host1x_pushbuffer_push(struct push_buffer *pb, u32 op1, u32 op2)
 static void host1x_pushbuffer_pop(struct push_buffer *pb, unsigned int slots)
 {
 	/* Advance the next write position */
-	pb->fence = (pb->fence + slots * 8) & (pb->size_bytes - 1);
+	pb->fence = (pb->fence + slots * 8) & (pb->size - 1);
 }
 
 /*
@@ -119,7 +161,7 @@ static void host1x_pushbuffer_pop(struct push_buffer *pb, unsigned int slots)
  */
 static u32 host1x_pushbuffer_space(struct push_buffer *pb)
 {
-	return ((pb->fence - pb->pos) & (pb->size_bytes - 1)) / 8;
+	return ((pb->fence - pb->pos) & (pb->size - 1)) / 8;
 }
 
 /*
drivers/gpu/host1x/cdma.h +4 -2
index 470087a..ec170a7 100644
@@ -43,10 +43,12 @@ struct host1x_job;
 
 struct push_buffer {
 	void *mapped;			/* mapped pushbuffer memory */
-	dma_addr_t phys;		/* physical address of pushbuffer */
+	dma_addr_t dma;			/* device address of pushbuffer */
+	phys_addr_t phys;		/* physical address of pushbuffer */
 	u32 fence;			/* index we've written */
 	u32 pos;			/* index to write to */
-	u32 size_bytes;
+	u32 size;
+	u32 alloc_size;
 };
 
 struct buffer_timeout {
drivers/gpu/host1x/dev.c +38 -2
index a62317a..a8234bb 100644
@@ -168,16 +168,37 @@ static int host1x_probe(struct platform_device *pdev)
 		return err;
 	}
 
+	if (iommu_present(&platform_bus_type)) {
+		struct iommu_domain_geometry *geometry;
+		unsigned long order;
+
+		host->domain = iommu_domain_alloc(&platform_bus_type);
+		if (!host->domain)
+			return -ENOMEM;
+
+		err = iommu_attach_device(host->domain, &pdev->dev);
+		if (err)
+			goto fail_free_domain;
+
+		geometry = &host->domain->geometry;
+
+		order = __ffs(host->domain->pgsize_bitmap);
+		init_iova_domain(&host->iova, 1UL << order,
+				 geometry->aperture_start >> order,
+				 geometry->aperture_end >> order);
+		host->iova_end = geometry->aperture_end;
+	}
+
 	err = host1x_channel_list_init(host);
 	if (err) {
 		dev_err(&pdev->dev, "failed to initialize channel list\n");
-		return err;
+		goto fail_detach_device;
 	}
 
 	err = clk_prepare_enable(host->clk);
 	if (err < 0) {
 		dev_err(&pdev->dev, "failed to enable clock\n");
-		return err;
+		goto fail_detach_device;
 	}
 
 	err = host1x_syncpt_init(host);
@@ -206,6 +227,15 @@ static int host1x_probe(struct platform_device *pdev)
 	host1x_syncpt_deinit(host);
 fail_unprepare_disable:
 	clk_disable_unprepare(host->clk);
+fail_detach_device:
+	if (host->domain) {
+		put_iova_domain(&host->iova);
+		iommu_detach_device(host->domain, &pdev->dev);
+	}
+fail_free_domain:
+	if (host->domain)
+		iommu_domain_free(host->domain);
+
 	return err;
 }
 
@@ -218,6 +248,12 @@ static int host1x_remove(struct platform_device *pdev)
 	host1x_syncpt_deinit(host);
 	clk_disable_unprepare(host->clk);
 
+	if (host->domain) {
+		put_iova_domain(&host->iova);
+		iommu_detach_device(host->domain, &pdev->dev);
+		iommu_domain_free(host->domain);
+	}
+
 	return 0;
 }
 
drivers/gpu/host1x/dev.h +6 -0
index 5220510..d81eb92 100644
@@ -19,6 +19,8 @@
 
 #include <linux/platform_device.h>
 #include <linux/device.h>
+#include <linux/iommu.h>
+#include <linux/iova.h>
 
 #include "channel.h"
 #include "syncpt.h"
@@ -108,6 +110,10 @@ struct host1x {
 	struct device *dev;
 	struct clk *clk;
 
+	struct iommu_domain *domain;
+	struct iova_domain iova;
+	dma_addr_t iova_end;
+
 	struct mutex intr_mutex;
 	int intr_syncpt_irq;
 
drivers/gpu/host1x/hw/cdma_hw.c +7 -9
index 659c1bb..6b23111 100644
@@ -30,7 +30,7 @@
  */
 static void push_buffer_init(struct push_buffer *pb)
 {
-	*(u32 *)(pb->mapped + pb->size_bytes) = host1x_opcode_restart(0);
+	*(u32 *)(pb->mapped + pb->size) = host1x_opcode_restart(0);
 }
 
 /*
@@ -55,8 +55,8 @@ static void cdma_timeout_cpu_incr(struct host1x_cdma *cdma, u32 getptr,
 		*(p++) = HOST1X_OPCODE_NOP;
 		*(p++) = HOST1X_OPCODE_NOP;
 		dev_dbg(host1x->dev, "%s: NOP at %pad+%#x\n", __func__,
-			&pb->phys, getptr);
-		getptr = (getptr + 8) & (pb->size_bytes - 1);
+			&pb->dma, getptr);
+		getptr = (getptr + 8) & (pb->size - 1);
 	}
 
 	wmb();
@@ -78,10 +78,9 @@ static void cdma_start(struct host1x_cdma *cdma)
 			 HOST1X_CHANNEL_DMACTRL);
 
 	/* set base, put and end pointer */
-	host1x_ch_writel(ch, cdma->push_buffer.phys, HOST1X_CHANNEL_DMASTART);
+	host1x_ch_writel(ch, cdma->push_buffer.dma, HOST1X_CHANNEL_DMASTART);
 	host1x_ch_writel(ch, cdma->push_buffer.pos, HOST1X_CHANNEL_DMAPUT);
-	host1x_ch_writel(ch, cdma->push_buffer.phys +
-			 cdma->push_buffer.size_bytes + 4,
+	host1x_ch_writel(ch, cdma->push_buffer.dma + cdma->push_buffer.size + 4,
 			 HOST1X_CHANNEL_DMAEND);
 
 	/* reset GET */
@@ -115,9 +114,8 @@ static void cdma_timeout_restart(struct host1x_cdma *cdma, u32 getptr)
 			 HOST1X_CHANNEL_DMACTRL);
 
 	/* set base, end pointer (all of memory) */
-	host1x_ch_writel(ch, cdma->push_buffer.phys, HOST1X_CHANNEL_DMASTART);
-	host1x_ch_writel(ch, cdma->push_buffer.phys +
-			 cdma->push_buffer.size_bytes,
+	host1x_ch_writel(ch, cdma->push_buffer.dma, HOST1X_CHANNEL_DMASTART);
+	host1x_ch_writel(ch, cdma->push_buffer.dma + cdma->push_buffer.size,
 			 HOST1X_CHANNEL_DMAEND);
 
 	/* set GET, by loading the value in PUT (then reset GET) */
drivers/gpu/host1x/job.c +62 -10

130 lines not on this page · raw message

drivers/gpu/host1x/job.h +1 -0
index 8b3c15d..878239c4 100644
@@ -44,6 +44,7 @@ struct host1x_waitchk {
 struct host1x_job_unpin_data {
 	struct host1x_bo *bo;
 	struct sg_table *sgt;
+	size_t size;
 };
 
 /*
Signature · 1 line
2.10.2
#19 lore raw

PATCH v2 5/7 dt-bindings: Add bindings for the Tegra VIC

In reply to a message not in the archive

The VIC (Video Image Compositor) is a Host1x client unit that can do various 2D composition and transform operations.

---
 .../bindings/display/tegra/nvidia,tegra20-host1x.txt        | 13 +++++++++++++
 1 file changed, 13 insertions(+)
Documentation/devicetree/bindings/display/tegra/nvidia,tegra20-host1x.txt +13 -0
index 0fad7ed..74e1e8a 100644
@@ -249,6 +249,19 @@ of the following host1x client modules:
   See ../pinctrl/nvidia,tegra124-dpaux-padctl.txt for information
   regarding the DPAUX pad controller bindings.
 
+- vic: Video Image Compositor
+  - compatible : "nvidia,tegra<chip>-vic"
+  - reg: Physical base address and length of the controller's registers.
+  - interrupts: The interrupt outputs from the controller.
+  - clocks: Must contain an entry for each entry in clock-names.
+    See ../clocks/clock-bindings.txt for details.
+  - clock-names: Must include the following entries:
+    - vic: clock input for the VIC hardware
+  - resets: Must contain an entry for each entry in reset-names.
+    See ../reset/reset.txt for details.
+  - reset-names: Must include the following entries:
+    - vic
+
 Example:
 
 / {
Signature · 1 line
2.10.2
#20 lore raw

PATCH v2 7/7 arm64: tegra: Enable IOMMU for Host1x on Tegra210

In reply to a message not in the archive

The Host1x driver now supports operation behind an IOMMU, so add its IOMMU domain to the device tree.

---
 arch/arm64/boot/dts/nvidia/tegra210.dtsi | 2 ++
 1 file changed, 2 insertions(+)
arch/arm64/boot/dts/nvidia/tegra210.dtsi +2 -0
index e12390f..8d229c7 100644
@@ -26,6 +26,8 @@
 
 		ranges = <0x0 0x54000000 0x0 0x54000000 0x0 0x01000000>;
 
+		iommus = <&mc TEGRA_SWGROUP_HC>;
+
 		dpaux1: dpaux@54040000 {
 			compatible = "nvidia,tegra210-dpaux";
 			reg = <0x0 0x54040000 0x0 0x00040000>;
Signature · 1 line
2.10.2
#21 lore raw
In reply to a message not in the archive
Quoted 5 lines · Mikko Perttunen

This series adds IOMMU support to Host1x and TegraDRM and adds support for the VIC (Video Image Compositor) host1x client. The series is available as a git repository at
git://github.com/cyndis/linux.git; branch vic-2.

Quoted 7 lines

A userspace test case for VIC can be found at
https://github.com/cyndis/drm/tree/work/tegra.
The testcase is in tests/tegra and is called submit_vic. The testcase/TRM include full headers and documentation to program the unit. The unit by itself, however, does not readily map to existing userspace library interfaces, so implementations for those are not provided.

Afaik libva has an entire pile of post-processing support. Pretty sure other video transcode libraries have similar interfaces, so should all be possible to implement this.

Until that exists I really think that the VIC part (and only that, since tk1/tx1 in general seems to work with nouveau and all that) should stay out of tree.
-Daniel

Quoted 51 lines

The in-kernel firewall is not implemented for VIC; therefore, either the IOMMU must be enabled or the firewall disabled for the test to pass.

Tested with Jetson TX1 (T210). Probably works also with Jetson TK1 (T124). Note that due to hardware changes the testcase also needs to be changed to run properly on T124: this can be done by removing the topmost commit of the aforementioned test repository.

Thanks,
Mikko.

Arto Merilainen (2):
drm/tegra: Add falcon helper library
drm/tegra: Add VIC support

Mikko Perttunen (5):
drm/tegra: Add Tegra DRM allocation API
gpu: host1x: Add IOMMU support
dt-bindings: Add bindings for the Tegra VIC
arm64: tegra: Enable VIC on T210
arm64: tegra: Enable IOMMU for Host1x on Tegra210

 .../display/tegra/nvidia,tegra20-host1x.txt        |  13 +
 arch/arm64/boot/dts/nvidia/tegra210.dtsi           |  19 +-
 drivers/gpu/drm/tegra/Makefile                     |   4 +-
 drivers/gpu/drm/tegra/drm.c                        | 114 +++++-
 drivers/gpu/drm/tegra/drm.h                        |  12 +
 drivers/gpu/drm/tegra/falcon.c                     | 259 ++++++++++++++
 drivers/gpu/drm/tegra/falcon.h                     | 127 +++++++
 drivers/gpu/drm/tegra/vic.c                        | 396 +++++++++++++++++++++
 drivers/gpu/drm/tegra/vic.h                        |  31 ++
 drivers/gpu/host1x/cdma.c                          |  74 +++-
 drivers/gpu/host1x/cdma.h                          |   6 +-
 drivers/gpu/host1x/dev.c                           |  40 ++-
 drivers/gpu/host1x/dev.h                           |   6 +
 drivers/gpu/host1x/hw/cdma_hw.c                    |  16 +-
 drivers/gpu/host1x/job.c                           |  72 +++-
 drivers/gpu/host1x/job.h                           |   1 +
 include/linux/host1x.h                             |   1 +
 17 files changed, 1143 insertions(+), 48 deletions(-)
 create mode 100644 drivers/gpu/drm/tegra/falcon.c
 create mode 100644 drivers/gpu/drm/tegra/falcon.h
 create mode 100644 drivers/gpu/drm/tegra/vic.c
 create mode 100644 drivers/gpu/drm/tegra/vic.h
Signature · 1 line
2.10.2
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

A message that is not in the archive (sent off-list or not yet received): 20161214123004.urnvlqarcnp5rp4a-dv86pmgwkMBes7Z6vYuT8azUEOm+Xw19@public.gmane.org

#23 lore raw
Quoted 14 lines · Daniel Vetter
Quoted 5 lines · Mikko Perttunen

This series adds IOMMU support to Host1x and TegraDRM and adds support for the VIC (Video Image Compositor) host1x client. The series is available as a git repository at
git://github.com/cyndis/linux.git; branch vic-2.

Quoted 7 lines

A userspace test case for VIC can be found at
https://github.com/cyndis/drm/tree/work/tegra.
The testcase is in tests/tegra and is called submit_vic. The testcase/TRM include full headers and documentation to program the unit. The unit by itself, however, does not readily map to existing userspace library interfaces, so implementations for those are not provided.

Quoted 3 lines

Afaik libva has an entire pile of post-processing support. Pretty sure other video transcode libraries have similar interfaces, so should all be possible to implement this.

We don't have any actual video transcoding support though, so unless it's possible to just implement a part of libva and defer the rest to some CPU implementation, I don't see how this is useful. I suppose I could implement a GStreamer plugin for colorspace conversion or resizing, since those are very modular.

Quoted 4 lines

Until that exists I really think that the VIC part (and only that, since tk1/tx1 in general seems to work with nouveau and all that) should stay out of tree.

Ok. I'll try to whip up something.

Quoted 1 line

-Daniel

Thanks,
Mikko.

Quoted 53 lines
Quoted 52 lines

The in-kernel firewall is not implemented for VIC; therefore, either the IOMMU must be enabled or the firewall disabled for the test to pass.

Tested with Jetson TX1 (T210). Probably works also with Jetson TK1 (T124). Note that due to hardware changes the testcase also needs to be changed to run properly on T124: this can be done by removing the topmost commit of the aforementioned test repository.

Thanks,
Mikko.

Arto Merilainen (2):
drm/tegra: Add falcon helper library
drm/tegra: Add VIC support

Mikko Perttunen (5):
drm/tegra: Add Tegra DRM allocation API
gpu: host1x: Add IOMMU support
dt-bindings: Add bindings for the Tegra VIC
arm64: tegra: Enable VIC on T210
arm64: tegra: Enable IOMMU for Host1x on Tegra210

 .../display/tegra/nvidia,tegra20-host1x.txt        |  13 +
 arch/arm64/boot/dts/nvidia/tegra210.dtsi           |  19 +-
 drivers/gpu/drm/tegra/Makefile                     |   4 +-
 drivers/gpu/drm/tegra/drm.c                        | 114 +++++-
 drivers/gpu/drm/tegra/drm.h                        |  12 +
 drivers/gpu/drm/tegra/falcon.c                     | 259 ++++++++++++++
 drivers/gpu/drm/tegra/falcon.h                     | 127 +++++++
 drivers/gpu/drm/tegra/vic.c                        | 396 +++++++++++++++++++++
 drivers/gpu/drm/tegra/vic.h                        |  31 ++
 drivers/gpu/host1x/cdma.c                          |  74 +++-
 drivers/gpu/host1x/cdma.h                          |   6 +-
 drivers/gpu/host1x/dev.c                           |  40 ++-
 drivers/gpu/host1x/dev.h                           |   6 +
 drivers/gpu/host1x/hw/cdma_hw.c                    |  16 +-
 drivers/gpu/host1x/job.c                           |  72 +++-
 drivers/gpu/host1x/job.h                           |   1 +
 include/linux/host1x.h                             |   1 +
 17 files changed, 1143 insertions(+), 48 deletions(-)
 create mode 100644 drivers/gpu/drm/tegra/falcon.c
 create mode 100644 drivers/gpu/drm/tegra/falcon.h
 create mode 100644 drivers/gpu/drm/tegra/vic.c
 create mode 100644 drivers/gpu/drm/tegra/vic.h

--
2.10.2

#24 lore raw
Quoted 19 lines · Mikko Perttunen
Quoted 14 lines · Daniel Vetter
Quoted 5 lines · Mikko Perttunen

This series adds IOMMU support to Host1x and TegraDRM and adds support for the VIC (Video Image Compositor) host1x client. The series is available as a git repository at
git://github.com/cyndis/linux.git; branch vic-2.

Quoted 7 lines

A userspace test case for VIC can be found at
https://github.com/cyndis/drm/tree/work/tegra.
The testcase is in tests/tegra and is called submit_vic. The testcase/TRM include full headers and documentation to program the unit. The unit by itself, however, does not readily map to existing userspace library interfaces, so implementations for those are not provided.

Quoted 3 lines

Afaik libva has an entire pile of post-processing support. Pretty sure other video transcode libraries have similar interfaces, so should all be possible to implement this.

Quoted 5 lines

We don't have any actual video transcoding support though, so unless it's possible to just implement a part of libva and defer the rest to some CPU implementation, I don't see how this is useful. I suppose I could implement a GStreamer plugin for colorspace conversion or resizing, since those are very modular.

Hm, I guess the question then is, how did that get enabled?

Quoted 5 lines
Quoted 3 lines

Until that exists I really think that the VIC part (and only that, since tk1/tx1 in general seems to work with nouveau and all that) should stay out of tree.

Ok. I'll try to whip up something.

But yeah some gstreamer thing might be doable, but not sure they take that (I don't have any contacts there). Video is a bit a mess, there's no clear go-to place for dropping some new hw support.
-Daniel

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

A message that is not in the archive (sent off-list or not yet received): 20161214130545.gfpkosyixr5lfkkf-dv86pmgwkMBes7Z6vYuT8azUEOm+Xw19@public.gmane.org

#26 lore raw
Quoted 20 lines · Daniel Vetter
Quoted 19 lines · Mikko Perttunen
Quoted 17 lines · Daniel Vetter
Quoted 5 lines · Mikko Perttunen

This series adds IOMMU support to Host1x and TegraDRM and adds support for the VIC (Video Image Compositor) host1x client. The series is available as a git repository at
git://github.com/cyndis/linux.git; branch vic-2.

Quoted 7 lines

A userspace test case for VIC can be found at
https://github.com/cyndis/drm/tree/work/tegra.
The testcase is in tests/tegra and is called submit_vic. The testcase/TRM include full headers and documentation to program the unit. The unit by itself, however, does not readily map to existing userspace library interfaces, so implementations for those are not provided.

Afaik libva has an entire pile of post-processing support. Pretty sure other video transcode libraries have similar interfaces, so should all be possible to implement this.

Quoted 7 lines
Quoted 5 lines

We don't have any actual video transcoding support though, so unless it's possible to just implement a part of libva and defer the rest to some CPU implementation, I don't see how this is useful. I suppose I could implement a GStreamer plugin for colorspace conversion or resizing, since those are very modular.

Hm, I guess the question then is, how did that get enabled?

What is "that"? I'm not exactly sure.

Our architecture is such that there's the VIC that handles colorspace conversion, rescaling, blitting and can do some 2d postprocessing effects as well.

Then there's the separate NVDEC that is a video bitstream decoder. There's no support for that at the moment. I am working on the IP side of that.

The video processing pipeline is then such that NVDEC is fed the bitstream; NVDEC outputs a YUV picture in a specific format; VIC takes that YUV picture and converts/rescales it into the desired format. Or if we are encoding video, VIC takes your RGB image, converts it into a format that NVENC understands, and so on.

So with just VIC support, I could implement some simple 2D things. I don't know if anyone would want to specifically use the VIC for those since applications already have fast CPU algorithms. For the video pipeline using VIC is nice since these units can synchronize work without CPU involvement and when you're already using NVDEC or NVENC it's barely any extra effort to involve VIC as well. It can also be useful in power usage sensitive situations, but we aren't really fit for those situations with the upstream kernel anyway :)

Thanks;
Mikko.

Quoted 12 lines
Quoted 6 lines
Quoted 4 lines

Until that exists I really think that the VIC part (and only that, since tk1/tx1 in general seems to work with nouveau and all that) should stay out of tree.

Ok. I'll try to whip up something.

But yeah some gstreamer thing might be doable, but not sure they take that (I don't have any contacts there). Video is a bit a mess, there's no clear go-to place for dropping some new hw support.
-Daniel

#27 lore raw
Quoted 44 lines · Mikko Perttunen
Quoted 20 lines · Daniel Vetter
Quoted 19 lines · Mikko Perttunen
Quoted 17 lines · Daniel Vetter
Quoted 5 lines · Mikko Perttunen

This series adds IOMMU support to Host1x and TegraDRM and adds support for the VIC (Video Image Compositor) host1x client. The series is available as a git repository at
git://github.com/cyndis/linux.git; branch vic-2.

Quoted 7 lines

A userspace test case for VIC can be found at
https://github.com/cyndis/drm/tree/work/tegra.
The testcase is in tests/tegra and is called submit_vic. The testcase/TRM include full headers and documentation to program the unit. The unit by itself, however, does not readily map to existing userspace library interfaces, so implementations for those are not provided.

Afaik libva has an entire pile of post-processing support. Pretty sure other video transcode libraries have similar interfaces, so should all be possible to implement this.

Quoted 7 lines
Quoted 5 lines

We don't have any actual video transcoding support though, so unless it's possible to just implement a part of libva and defer the rest to some CPU implementation, I don't see how this is useful. I suppose I could implement a GStreamer plugin for colorspace conversion or resizing, since those are very modular.

Hm, I guess the question then is, how did that get enabled?

What is "that"? I'm not exactly sure.

Our architecture is such that there's the VIC that handles colorspace conversion, rescaling, blitting and can do some 2d postprocessing effects as well.

Then there's the separate NVDEC that is a video bitstream decoder. There's no support for that at the moment. I am working on the IP side of that.

The video processing pipeline is then such that NVDEC is fed the bitstream; NVDEC outputs a YUV picture in a specific format; VIC takes that YUV picture and converts/rescales it into the desired format. Or if we are encoding video, VIC takes your RGB image, converts it into a format that NVENC understands, and so on.

Quoted 8 lines

So with just VIC support, I could implement some simple 2D things. I don't know if anyone would want to specifically use the VIC for those since applications already have fast CPU algorithms. For the video pipeline using VIC is nice since these units can synchronize work without CPU involvement and when you're already using NVDEC or NVENC it's barely any extra effort to involve VIC as well. It can also be useful in power usage sensitive situations, but we aren't really fit for those situations with the upstream kernel anyway :)

Ah I thought the nvdec was already enabled, since for i915 that's how we went about things (we have a pretty much exactly matching split in the various video related engines). But if that's not there yet then no worries, all fine.

Since you do seem to plan to enable everything anyway, might be worth it to go directly with something like libva or libvdpau or whatever the cool thing is. libva is my recommendation since it works on non-X11 too afaik, but I have 0 clue. And might be worth it to check out whether you can't do a super-basic libva driver that only does the post processing stuff. With libva you can import/export images, so it might be possible even ... And directly doing the full video engine support instead of a one-off in gstreamer sounds more sensible to me.
-Daniel

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

A message that is not in the archive (sent off-list or not yet received): 20161214141142.jmrofknylonhprbk-dv86pmgwkMBes7Z6vYuT8azUEOm+Xw19@public.gmane.org

#29 lore raw
Quoted 54 lines · Daniel Vetter
Quoted 44 lines · Mikko Perttunen
Quoted 20 lines · Daniel Vetter
Quoted 19 lines · Mikko Perttunen
Quoted 17 lines · Daniel Vetter
Quoted 5 lines · Mikko Perttunen

This series adds IOMMU support to Host1x and TegraDRM and adds support for the VIC (Video Image Compositor) host1x client. The series is available as a git repository at
git://github.com/cyndis/linux.git; branch vic-2.

Quoted 7 lines

A userspace test case for VIC can be found at
https://github.com/cyndis/drm/tree/work/tegra.
The testcase is in tests/tegra and is called submit_vic. The testcase/TRM include full headers and documentation to program the unit. The unit by itself, however, does not readily map to existing userspace library interfaces, so implementations for those are not provided.

Afaik libva has an entire pile of post-processing support. Pretty sure other video transcode libraries have similar interfaces, so should all be possible to implement this.

Quoted 7 lines
Quoted 5 lines

We don't have any actual video transcoding support though, so unless it's possible to just implement a part of libva and defer the rest to some CPU implementation, I don't see how this is useful. I suppose I could implement a GStreamer plugin for colorspace conversion or resizing, since those are very modular.

Hm, I guess the question then is, how did that get enabled?

What is "that"? I'm not exactly sure.

Our architecture is such that there's the VIC that handles colorspace conversion, rescaling, blitting and can do some 2d postprocessing effects as well.

Then there's the separate NVDEC that is a video bitstream decoder. There's no support for that at the moment. I am working on the IP side of that.

The video processing pipeline is then such that NVDEC is fed the bitstream; NVDEC outputs a YUV picture in a specific format; VIC takes that YUV picture and converts/rescales it into the desired format. Or if we are encoding video, VIC takes your RGB image, converts it into a format that NVENC understands, and so on.

Quoted 8 lines

So with just VIC support, I could implement some simple 2D things. I don't know if anyone would want to specifically use the VIC for those since applications already have fast CPU algorithms. For the video pipeline using VIC is nice since these units can synchronize work without CPU involvement and when you're already using NVDEC or NVENC it's barely any extra effort to involve VIC as well. It can also be useful in power usage sensitive situations, but we aren't really fit for those situations with the upstream kernel anyway :)

Quoted 4 lines

Ah I thought the nvdec was already enabled, since for i915 that's how we went about things (we have a pretty much exactly matching split in the various video related engines). But if that's not there yet then no worries, all fine.

Ah, I see :)

Yes, perhaps I should have described the situation and hardware in a bit more detail initially - sometimes I forget I'm writing to other people than Thierry as well.. something to keep in mind for future patches.

Quoted 11 lines

Since you do seem to plan to enable everything anyway, might be worth it to go directly with something like libva or libvdpau or whatever the cool thing is. libva is my recommendation since it works on non-X11 too afaik, but I have 0 clue. And might be worth it to check out whether you can't do a super-basic libva driver that only does the post processing stuff. With libva you can import/export images, so it might be possible even ... And directly doing the full video engine support instead of a one-off in gstreamer sounds more sensible to me.
-Daniel

I'll take a look at libva.

Thanks,
Mikko.

#30 lore raw
In reply to a message not in the archive
Quoted 59 lines · Daniel Vetter
Quoted 44 lines · Mikko Perttunen
Quoted 20 lines · Daniel Vetter
Quoted 19 lines · Mikko Perttunen
Quoted 17 lines · Daniel Vetter
Quoted 5 lines · Mikko Perttunen

This series adds IOMMU support to Host1x and TegraDRM and adds support for the VIC (Video Image Compositor) host1x client. The series is available as a git repository at
git://github.com/cyndis/linux.git; branch vic-2.

Quoted 7 lines

A userspace test case for VIC can be found at
https://github.com/cyndis/drm/tree/work/tegra.
The testcase is in tests/tegra and is called submit_vic. The testcase/TRM include full headers and documentation to program the unit. The unit by itself, however, does not readily map to existing userspace library interfaces, so implementations for those are not provided.

Afaik libva has an entire pile of post-processing support. Pretty sure other video transcode libraries have similar interfaces, so should all be possible to implement this.

Quoted 7 lines
Quoted 5 lines

We don't have any actual video transcoding support though, so unless it's possible to just implement a part of libva and defer the rest to some CPU implementation, I don't see how this is useful. I suppose I could implement a GStreamer plugin for colorspace conversion or resizing, since those are very modular.

Hm, I guess the question then is, how did that get enabled?

What is "that"? I'm not exactly sure.

Our architecture is such that there's the VIC that handles colorspace conversion, rescaling, blitting and can do some 2d postprocessing effects as well.

Then there's the separate NVDEC that is a video bitstream decoder. There's no support for that at the moment. I am working on the IP side of that.

The video processing pipeline is then such that NVDEC is fed the bitstream; NVDEC outputs a YUV picture in a specific format; VIC takes that YUV picture and converts/rescales it into the desired format. Or if we are encoding video, VIC takes your RGB image, converts it into a format that NVENC understands, and so on.

Quoted 8 lines

So with just VIC support, I could implement some simple 2D things. I don't know if anyone would want to specifically use the VIC for those since applications already have fast CPU algorithms. For the video pipeline using VIC is nice since these units can synchronize work without CPU involvement and when you're already using NVDEC or NVENC it's barely any extra effort to involve VIC as well. It can also be useful in power usage sensitive situations, but we aren't really fit for those situations with the upstream kernel anyway :)

Ah I thought the nvdec was already enabled, since for i915 that's how we went about things (we have a pretty much exactly matching split in the various video related engines). But if that's not there yet then no worries, all fine.

Quoted 8 lines

Since you do seem to plan to enable everything anyway, might be worth it to go directly with something like libva or libvdpau or whatever the cool thing is. libva is my recommendation since it works on non-X11 too afaik, but I have 0 clue. And might be worth it to check out whether you can't do a super-basic libva driver that only does the post processing stuff. With libva you can import/export images, so it might be possible even ... And directly doing the full video engine support instead of a one-off in gstreamer sounds more sensible to me.

Silly me forgot to add the experts, i.e. Sean (current libva maintainer) and libva mailing lists.
-Daniel

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
Libva mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/libva

A message that is not in the archive (sent off-list or not yet received): CAKMK7uGw3XwbPU798YJ-9eLbwhMWs7z_F-ro238RfFN8LFURtw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#32 lore raw

Hi,

Comments below:

Quoted 71 lines · Daniel Vetter
Quoted 59 lines · Daniel Vetter
Quoted 44 lines · Mikko Perttunen
Quoted 20 lines · Daniel Vetter
Quoted 19 lines · Mikko Perttunen
Quoted 17 lines · Daniel Vetter
Quoted 5 lines · Mikko Perttunen

This series adds IOMMU support to Host1x and TegraDRM and adds support for the VIC (Video Image Compositor) host1x client. The series is available as a git repository at
git://github.com/cyndis/linux.git; branch vic-2.

Quoted 7 lines

A userspace test case for VIC can be found at
https://github.com/cyndis/drm/tree/work/tegra.
The testcase is in tests/tegra and is called submit_vic. The testcase/TRM include full headers and documentation to program the unit. The unit by itself, however, does not readily map to existing userspace library interfaces, so implementations for those are not provided.

Afaik libva has an entire pile of post-processing support. Pretty sure other video transcode libraries have similar interfaces, so should all be possible to implement this.

Quoted 7 lines
Quoted 5 lines

We don't have any actual video transcoding support though, so unless it's possible to just implement a part of libva and defer the rest to some CPU implementation, I don't see how this is useful. I suppose I could implement a GStreamer plugin for colorspace conversion or resizing, since those are very modular.

Hm, I guess the question then is, how did that get enabled?

What is "that"? I'm not exactly sure.

Our architecture is such that there's the VIC that handles colorspace conversion, rescaling, blitting and can do some 2d postprocessing effects as well.

Then there's the separate NVDEC that is a video bitstream decoder. There's no support for that at the moment. I am working on the IP side of that.

The video processing pipeline is then such that NVDEC is fed the bitstream; NVDEC outputs a YUV picture in a specific format; VIC takes that YUV picture and converts/rescales it into the desired format. Or if we are encoding video, VIC takes your RGB image, converts it into a format that NVENC understands, and so on.

Quoted 8 lines

So with just VIC support, I could implement some simple 2D things. I don't know if anyone would want to specifically use the VIC for those since applications already have fast CPU algorithms. For the video pipeline using VIC is nice since these units can synchronize work without CPU involvement and when you're already using NVDEC or NVENC it's barely any extra effort to involve VIC as well. It can also be useful in power usage sensitive situations, but we aren't really fit for those situations with the upstream kernel anyway :)

Ah I thought the nvdec was already enabled, since for i915 that's how we went about things (we have a pretty much exactly matching split in the various video related engines). But if that's not there yet then no worries, all fine.

Quoted 8 lines

Since you do seem to plan to enable everything anyway, might be worth it to go directly with something like libva or libvdpau or whatever the cool thing is. libva is my recommendation since it works on non-X11 too afaik, but I have 0 clue. And might be worth it to check out whether you can't do a super-basic libva driver that only does the post processing stuff. With libva you can import/export images, so it might be possible even ... And directly doing the full video engine support instead of a one-off in gstreamer sounds more sensible to me.

Quoted 3 lines

Silly me forgot to add the experts, i.e. Sean (current libva maintainer) and libva mailing lists.
-Daniel

From a purely VPP standpoint libva is something that would give VIC a readily available API in user space. You don’t have to have a transcoding use case to leverage VPP with a surface with VA-API. On top of that we do support DMA but import and export to provide flexibility in sharing the memory. It’s entirely possible to support a subset of entry points (say VPP only) for VA-API through Libva and share that information in a query on the config say for your applications. We do that all the time with various backends having feature subsets such as our hybrid Intel driver, or the IMG based PVR driver. I believe there is also a Rock-Chip project experimenting with Libva for their media driver.

I’ll take a look at your link.

Sean

Intel, Corp.

Quoted 8 lines
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
Libva mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/libva

_______________________________________________
Libva mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/libva

#33 lore raw
In reply to a message not in the archive
Quoted 59 lines · Daniel Vetter
Quoted 44 lines · Mikko Perttunen
Quoted 20 lines · Daniel Vetter
Quoted 19 lines · Mikko Perttunen
Quoted 17 lines · Daniel Vetter
Quoted 5 lines · Mikko Perttunen

This series adds IOMMU support to Host1x and TegraDRM and adds support for the VIC (Video Image Compositor) host1x client. The series is available as a git repository at
git://github.com/cyndis/linux.git; branch vic-2.

Quoted 7 lines

A userspace test case for VIC can be found at
https://github.com/cyndis/drm/tree/work/tegra.
The testcase is in tests/tegra and is called submit_vic. The testcase/TRM include full headers and documentation to program the unit. The unit by itself, however, does not readily map to existing userspace library interfaces, so implementations for those are not provided.

Afaik libva has an entire pile of post-processing support. Pretty sure other video transcode libraries have similar interfaces, so should all be possible to implement this.

Quoted 7 lines
Quoted 5 lines

We don't have any actual video transcoding support though, so unless it's possible to just implement a part of libva and defer the rest to some CPU implementation, I don't see how this is useful. I suppose I could implement a GStreamer plugin for colorspace conversion or resizing, since those are very modular.

Hm, I guess the question then is, how did that get enabled?

What is "that"? I'm not exactly sure.

Our architecture is such that there's the VIC that handles colorspace conversion, rescaling, blitting and can do some 2d postprocessing effects as well.

Then there's the separate NVDEC that is a video bitstream decoder. There's no support for that at the moment. I am working on the IP side of that.

The video processing pipeline is then such that NVDEC is fed the bitstream; NVDEC outputs a YUV picture in a specific format; VIC takes that YUV picture and converts/rescales it into the desired format. Or if we are encoding video, VIC takes your RGB image, converts it into a format that NVENC understands, and so on.

Quoted 8 lines

So with just VIC support, I could implement some simple 2D things. I don't know if anyone would want to specifically use the VIC for those since applications already have fast CPU algorithms. For the video pipeline using VIC is nice since these units can synchronize work without CPU involvement and when you're already using NVDEC or NVENC it's barely any extra effort to involve VIC as well. It can also be useful in power usage sensitive situations, but we aren't really fit for those situations with the upstream kernel anyway :)

Ah I thought the nvdec was already enabled, since for i915 that's how we went about things (we have a pretty much exactly matching split in the various video related engines). But if that's not there yet then no worries, all fine.

Quoted 10 lines

Since you do seem to plan to enable everything anyway, might be worth it to go directly with something like libva or libvdpau or whatever the cool thing is. libva is my recommendation since it works on non-X11 too afaik, but I have 0 clue. And might be worth it to check out whether you can't do a super-basic libva driver that only does the post processing stuff. With libva you can import/export images, so it might be possible even ... And directly doing the full video engine support instead of a one-off in gstreamer sounds more sensible to me.
-Daniel

It took a while, but I now have a libva backend to go with this kernel driver: https://github.com/cyndis/vaapi-tegra-driver.

It is far from complete, but the libva putsurface testcase runs and its output looks correct when compared to the intel backend. Would this be suitable or should something more be implemented before merging the kernel driver?

Thanks,
Mikko.

#34 lore raw
Quoted 71 lines · Mikko Perttunen
Quoted 59 lines · Daniel Vetter
Quoted 44 lines · Mikko Perttunen
Quoted 20 lines · Daniel Vetter
Quoted 19 lines · Mikko Perttunen
Quoted 17 lines · Daniel Vetter
Quoted 5 lines · Mikko Perttunen

This series adds IOMMU support to Host1x and TegraDRM and adds support for the VIC (Video Image Compositor) host1x client. The series is available as a git repository at
git://github.com/cyndis/linux.git; branch vic-2.

Quoted 7 lines

A userspace test case for VIC can be found at
https://github.com/cyndis/drm/tree/work/tegra.
The testcase is in tests/tegra and is called submit_vic. The testcase/TRM include full headers and documentation to program the unit. The unit by itself, however, does not readily map to existing userspace library interfaces, so implementations for those are not provided.

Afaik libva has an entire pile of post-processing support. Pretty sure other video transcode libraries have similar interfaces, so should all be possible to implement this.

Quoted 7 lines
Quoted 5 lines

We don't have any actual video transcoding support though, so unless it's possible to just implement a part of libva and defer the rest to some CPU implementation, I don't see how this is useful. I suppose I could implement a GStreamer plugin for colorspace conversion or resizing, since those are very modular.

Hm, I guess the question then is, how did that get enabled?

What is "that"? I'm not exactly sure.

Our architecture is such that there's the VIC that handles colorspace conversion, rescaling, blitting and can do some 2d postprocessing effects as well.

Then there's the separate NVDEC that is a video bitstream decoder. There's no support for that at the moment. I am working on the IP side of that.

The video processing pipeline is then such that NVDEC is fed the bitstream; NVDEC outputs a YUV picture in a specific format; VIC takes that YUV picture and converts/rescales it into the desired format. Or if we are encoding video, VIC takes your RGB image, converts it into a format that NVENC understands, and so on.

Quoted 8 lines

So with just VIC support, I could implement some simple 2D things. I don't know if anyone would want to specifically use the VIC for those since applications already have fast CPU algorithms. For the video pipeline using VIC is nice since these units can synchronize work without CPU involvement and when you're already using NVDEC or NVENC it's barely any extra effort to involve VIC as well. It can also be useful in power usage sensitive situations, but we aren't really fit for those situations with the upstream kernel anyway :)

Ah I thought the nvdec was already enabled, since for i915 that's how we went about things (we have a pretty much exactly matching split in the various video related engines). But if that's not there yet then no worries, all fine.

Quoted 10 lines

Since you do seem to plan to enable everything anyway, might be worth it to go directly with something like libva or libvdpau or whatever the cool thing is. libva is my recommendation since it works on non-X11 too afaik, but I have 0 clue. And might be worth it to check out whether you can't do a super-basic libva driver that only does the post processing stuff. With libva you can import/export images, so it might be possible even ... And directly doing the full video engine support instead of a one-off in gstreamer sounds more sensible to me.
-Daniel

Quoted 7 lines

It took a while, but I now have a libva backend to go with this kernel
driver: https://github.com/cyndis/vaapi-tegra-driver.

It is far from complete, but the libva putsurface testcase runs and its output looks correct when compared to the intel backend. Would this be suitable or should something more be implemented before merging the kernel driver?

Seems all reasonable to move ahead with this. Thanks for doing it. -Daniel

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#35 lore raw
In reply to a message not in the archive
Quoted 14 lines · Daniel Vetter
Quoted 5 lines · Mikko Perttunen

This series adds IOMMU support to Host1x and TegraDRM and adds support for the VIC (Video Image Compositor) host1x client. The series is available as a git repository at
git://github.com/cyndis/linux.git; branch vic-2.

Quoted 7 lines

A userspace test case for VIC can be found at
https://github.com/cyndis/drm/tree/work/tegra.
The testcase is in tests/tegra and is called submit_vic. The testcase/TRM include full headers and documentation to program the unit. The unit by itself, however, does not readily map to existing userspace library interfaces, so implementations for those are not provided.

Quoted 7 lines

Afaik libva has an entire pile of post-processing support. Pretty sure other video transcode libraries have similar interfaces, so should all be possible to implement this.

Until that exists I really think that the VIC part (and only that, since tk1/tx1 in general seems to work with nouveau and all that) should stay out of tree.

I think the VIC is somewhat special with regard to userspace ABI. I understand and completely agree with the requirements the community has established. However, as Mikko already said, there's no use for standalone VIC at all. There aren't any APIs that map to what the hardware does (except maybe parts of X or perhaps pixman, neither of which are likely to see implementations using VIC). I'm also not aware of any of the proprietary driver stack using only VIC for any use cases.

The primary reason that I want VIC support upstream is because it makes it easier to test host1x support. Currently the only units that we can test against are gr2d and gr3d on Tegra20 through Tegra114. With Tegra124 gr2d and gr3d went away and got replaced by the gk20a GPU which doesn't use the host1x infrastructure. So on Tegra124 and later we currently have no way of exercising that code. Now, Tegra124 and Tegra210 are by far the most popular generations at this point and there are very few people running Tegra20 or Tegra30 with an upstream kernel (there are some still, and I think they're all awesome) so the host1x infrastructure is effectively untested and therefore I get very nervous whenever I have to apply patches against it because we can only validate on very old chips.

Tegra124 is also somewhat of a special case. While it has a GPU that's driven by Nouveau, it doesn't yet have NVDEC and NVENC support that the newer Tegra210 has. The video encoding, if I remember correctly, is a precursor to NVENC (MSENC?) but video decoding is the "legacy" hardware that we had on earlier chips. That involved a fairly complicated setup with firmware that needs to be loaded to a fixed address in system memory (or mapped using the IOMMU). The bottom line is that it's unlikely that we'll ever see an open-source implementation for video decoding on Tegra124 (unless somebody reverse-engineers it), and hence we'd essentially be left without any way of testisc host1x support on TK1.

All of that said, I could carry these patches out of tree and use them for testing until we've got a complete userspace ready. It's just something that I had hoped I could avoid.

Thierry

#36 lore raw
In reply to Daniel Vetter
Quoted 14 lines · Daniel Vetter
Quoted 5 lines · Mikko Perttunen

This series adds IOMMU support to Host1x and TegraDRM and adds support for the VIC (Video Image Compositor) host1x client. The series is available as a git repository at
git://github.com/cyndis/linux.git; branch vic-2.

Quoted 7 lines

A userspace test case for VIC can be found at
https://github.com/cyndis/drm/tree/work/tegra.
The testcase is in tests/tegra and is called submit_vic. The testcase/TRM include full headers and documentation to program the unit. The unit by itself, however, does not readily map to existing userspace library interfaces, so implementations for those are not provided.

Quoted 7 lines

Afaik libva has an entire pile of post-processing support. Pretty sure other video transcode libraries have similar interfaces, so should all be possible to implement this.

Until that exists I really think that the VIC part (and only that, since tk1/tx1 in general seems to work with nouveau and all that) should stay out of tree.

Related:
With render-only about to be merged soon{tm) and Alexandre already looking at tegra version of it, one should be able to wire this functionality and use it in mesa/gallium.

Note: this is not an objection against the work - be that about from quality or inclusion POV.

Emil
P.S. Goes to check on the renderonly topic.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

maintainer
#37 lore raw

PATCH v2 6/7 arm64: tegra: Enable VIC on T210

In reply to Mikko Perttunen

Enable the VIC (Video Image Compositor) host1x
unit on Tegra210 systems.

---
 arch/arm64/boot/dts/nvidia/tegra210.dtsi | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
arch/arm64/boot/dts/nvidia/tegra210.dtsi +16 -1
index 46045fe..e12390f 100644
@@ -122,7 +122,14 @@
 		vic@54340000 {
 			compatible = "nvidia,tegra210-vic";
 			reg = <0x0 0x54340000 0x0 0x00040000>;
-			status = "disabled";
+			interrupts = <GIC_SPI 72 IRQ_TYPE_LEVEL_HIGH>;
+			clocks = <&tegra_car TEGRA210_CLK_VIC03>;
+			clock-names = "vic";
+			resets = <&tegra_car 178>;
+			reset-names = "vic";
+
+			iommus = <&mc TEGRA_SWGROUP_VIC>;
+			power-domains = <&pd_vic>;
 		};
 
 		nvjpg@54380000 {
@@ -692,6 +699,14 @@
 				resets = <&tegra_car TEGRA210_CLK_XUSB_HOST>;
 				#power-domain-cells = <0>;
 			};
+
+			pd_vic: vic {
+				clocks = <&tegra_car TEGRA210_CLK_VIC03>;
+				clock-names = "vic";
+				resets = <&tegra_car TEGRA210_CLK_VIC03>;
+				reset-names = "vic";
+				#power-domain-cells = <0>;
+			};
 		};
 	};
 
Signature · 6 lines
2.10.2

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel