This patch for jetpack5. You may try it first.
diff --git a/kernel/nvidia/drivers/pci/endpoint/functions/pci-epf-nv-test.c b/kernel/nvidia/drivers/pci/endpoint/functions/pci-epf-nv-test.c
index 1959c8402..e21913418 100644
--- a/kernel/nvidia/drivers/pci/endpoint/functions/pci-epf-nv-test.c
+++ b/kernel/nvidia/drivers/pci/endpoint/functions/pci-epf-nv-test.c
@@ -17,7 +17,7 @@
#include <linux/pci-epf.h>
#include <linux/version.h>
-#define BAR0_SIZE SZ_64K
+#define BAR0_SIZE SZ_512M
struct pci_epf_nv_test {
struct pci_epf_header header;
@@ -47,7 +47,7 @@ static int pci_epf_nv_test_core_init(struct pci_epf *epf)
epf_bar->size = BAR0_SIZE;
epf_bar->barno = BAR_0;
epf_bar->flags |= PCI_BASE_ADDRESS_SPACE_MEMORY |
- PCI_BASE_ADDRESS_MEM_TYPE_32;
+ PCI_BASE_ADDRESS_MEM_TYPE_32;
ret = pci_epc_set_bar(epc, epf->func_no, epf_bar);
if (ret) {
@@ -92,7 +92,6 @@ static void pci_epf_nv_test_unbind(struct pci_epf *epf)
struct pci_epf_nv_test *epfnv = epf_get_drvdata(epf);
struct pci_epc *epc = epf->epc;
struct device *cdev = epc->dev.parent;
- struct iommu_domain *domain = iommu_get_domain_for_dev(cdev);
#if (LINUX_VERSION_CODE > KERNEL_VERSION(4, 15, 0))
struct pci_epf_bar *epf_bar = &epf->bar[BAR_0];
#endif
@@ -103,10 +102,8 @@ static void pci_epf_nv_test_unbind(struct pci_epf *epf)
#else
pci_epc_clear_bar(epc, BAR_0);
#endif
- vunmap(epfnv->bar0_ram_map);
- iommu_unmap(domain, epfnv->bar0_iova, PAGE_SIZE);
- iommu_dma_free_iova(cdev, epfnv->bar0_iova, BAR0_SIZE);
- __free_pages(epfnv->bar0_ram_page, 1);
+ dma_free_coherent(cdev, BAR0_SIZE, epfnv->bar0_ram_map,
+ epfnv->bar0_iova);
}
static int pci_epf_nv_test_bind(struct pci_epf *epf)
@@ -118,8 +115,8 @@ static int pci_epf_nv_test_bind(struct pci_epf *epf)
#endif
struct device *fdev = &epf->dev;
struct device *cdev = epc->dev.parent;
- struct iommu_domain *domain = iommu_get_domain_for_dev(cdev);
int ret;
#if 0
+ int i;
#endif
#if (LINUX_VERSION_CODE <= KERNEL_VERSION(4, 15, 0))
ret = pci_epc_write_header(epc, header);
@@ -129,40 +126,29 @@ static int pci_epf_nv_test_bind(struct pci_epf *epf)
}
#endif
- epfnv->bar0_ram_page = alloc_pages(GFP_KERNEL, 1);
- if (!epfnv->bar0_ram_page) {
- dev_err(fdev, "alloc_pages() failed\n");
- ret = -ENOMEM;
- goto fail;
- }
- dev_info(fdev, "BAR0 RAM phys: 0x%llx\n",
- page_to_phys(epfnv->bar0_ram_page));
+ epfnv->bar0_ram_map = dma_alloc_coherent(cdev, BAR0_SIZE,
+ &epfnv->bar0_iova, GFP_KERNEL);
- epfnv->bar0_iova = iommu_dma_alloc_iova(cdev, BAR0_SIZE,
- cdev->coherent_dma_mask);
- if (!epfnv->bar0_iova) {
- dev_err(fdev, "iommu_dma_alloc_iova() failed\n");
+ if (!epfnv->bar0_ram_map) {
+ dev_err(fdev, "dma_alloc_coherent() failed\n");
ret = -ENOMEM;
- goto fail_free_pages;
+ return ret;
}
dev_info(fdev, "BAR0 RAM IOVA: 0x%08llx\n", epfnv->bar0_iova);
-
- ret = iommu_map(domain, epfnv->bar0_iova,
- page_to_phys(epfnv->bar0_ram_page),
- PAGE_SIZE, IOMMU_READ | IOMMU_WRITE);
- if (ret) {
- dev_err(fdev, "iommu_map(RAM) failed: %d\n", ret);
- goto fail_free_iova;
- }
- epfnv->bar0_ram_map = vmap(&epfnv->bar0_ram_page, 1, VM_MAP,
- PAGE_KERNEL);
- if (!epfnv->bar0_ram_map) {
- dev_err(fdev, "vmap() failed\n");
- ret = -ENOMEM;
- goto fail_unmap_ram_iova;
+ dev_info(fdev, "BAR0 RAM VA : 0x%p\n", epfnv->bar0_ram_map);
+ dev_info(fdev, "BAR0 RAM PA : 0x%08lx\n",
+ (vmalloc_to_pfn(epfnv->bar0_ram_map) << PAGE_SHIFT));
+
+#if 0
+/* Ideally we shouldn’t use devmem on the PHY address from DRAM.
+ * modify the data in EP BAR0 using virtual address(epfnv->bar0_ram_map)
+ * in the driver and then read out using BAR0 address in RP.
+ */
+ for(i = 0; i < BAR0_SIZE; i+= PAGE_SIZE) {
+ *((unsigned long *)(epfnv->bar0_ram_map + i)) = 0x36578912;
}
- dev_info(fdev, "BAR0 RAM virt: 0x%p\n", epfnv->bar0_ram_map);
+#endif
#if (LINUX_VERSION_CODE <= KERNEL_VERSION(4, 15, 0))
ret = pci_epc_set_bar(epc, BAR_0, epfnv->bar0_iova, BAR0_SIZE,
@@ -170,7 +156,7 @@ static int pci_epf_nv_test_bind(struct pci_epf *epf)
PCI_BASE_ADDRESS_MEM_TYPE_32);
if (ret) {
dev_err(fdev, "pci_epc_set_bar() failed: %d\n", ret);
- goto fail_unmap_ram_virt;
+ goto fail_set_bar;
}
#endif
@@ -182,17 +168,11 @@ static int pci_epf_nv_test_bind(struct pci_epf *epf)
return 0;
#if (LINUX_VERSION_CODE <= KERNEL_VERSION(4, 15, 0))
-fail_unmap_ram_virt:
- vunmap(epfnv->bar0_ram_map);
-#endif
-fail_unmap_ram_iova:
- iommu_unmap(domain, epfnv->bar0_iova, PAGE_SIZE);
-fail_free_iova:
- iommu_dma_free_iova(cdev, epfnv->bar0_iova, BAR0_SIZE);
-fail_free_pages:
- __free_pages(epfnv->bar0_ram_page, 1);
-fail:
+fail_set_bar:
+ dma_free_coherent(cdev, BAR0_SIZE, epfnv->bar0_ram_map,
+ epfnv->bar0_iova);
return ret;
+#endif
}
static const struct pci_epf_device_id pci_epf_nv_test_ids[] = {
--