liuyq / android-issues

place to write notes about investigation on android issues
0 stars 0 forks source link

master-x15-mainline: arm_dma_ops was dropped from the kernel mainline tree #15

Open liuyq opened 2 years ago

liuyq commented 2 years ago

Which caused the pvr module failed to be compiled: https://git.ti.com/cgit/android/device-ti-proprietary-open/tree/jacinto6/sgx_src/eurasia_km/services4/srvkm/env/linux/osfunc.c?h=d-oreo-mr1-core-release

static void pvr_flush_range(phys_addr_t pStart, phys_addr_t pEnd)
{
#if defined(__aarch64__)
    struct dma_map_ops *dma_ops = get_dma_ops(PVRLDMGetDevice());
    dma_ops->sync_single_for_device(NULL, pStart, pEnd - pStart, DMA_TO_DEVICE);
    dma_ops->sync_single_for_cpu(NULL, pStart, pEnd - pStart, DMA_FROM_DEVICE);
#else
    arm_dma_ops.sync_single_for_device(NULL, pStart, pEnd - pStart, DMA_TO_DEVICE);
    arm_dma_ops.sync_single_for_cpu(NULL, pStart, pEnd - pStart, DMA_FROM_DEVICE);
#endif
}

static void pvr_clean_range(phys_addr_t pStart, phys_addr_t pEnd)
{
#if defined(__aarch64__)
    struct dma_map_ops *dma_ops = get_dma_ops(PVRLDMGetDevice());
    dma_ops->sync_single_for_device(NULL, pStart, pEnd - pStart, DMA_TO_DEVICE);
#else
    arm_dma_ops.sync_single_for_device(NULL, pStart, pEnd - pStart, DMA_TO_DEVICE);
#endif

}

static void pvr_invalidate_range(phys_addr_t pStart, phys_addr_t pEnd)
{
#if defined(__aarch64__)
    struct dma_map_ops *dma_ops = get_dma_ops(PVRLDMGetDevice());
    dma_ops->sync_single_for_cpu(NULL, pStart, pEnd - pStart, DMA_FROM_DEVICE);
#else
    arm_dma_ops.sync_single_for_cpu(NULL, pStart, pEnd - pStart, DMA_FROM_DEVICE);
#endif
}

some suggestions made here: https://lore.kernel.org/linux-arm-kernel/5c617d66-f04b-df26-bf7a-7f479d081ac2@arm.com/ but there is a problem to update for the pvr_invalidate_range as suggested.

log could be checked here: http://ix.io/49gu

some git log on the change: https://git.ti.com/cgit/android/device-ti-proprietary-open/commit/jacinto6/sgx_src/eurasia_km/services4/srvkm/env/linux/osfunc.c?h=d-oreo-mr1-core-release&id=c82d194b93d36baf4772503e7ff8b8d6d9a1cc4b

linaro source file: https://android-git.linaro.org/kernel/omap-modules.git/tree/pvr/services4/srvkm/env/linux/osfunc.c?h=android-mainline#n4615

liuyq commented 2 years ago

DMA related learning links: DMA Mapping An Overview of the DMAEngine Subsystem Mastering the DMA and IOMMU APIs Linux DMA(more ARM related links) ARM DMA-Mapping Framework Redesign and IOMMU integratio ARM Dma-mapping Explained

liuyq commented 1 year ago

x15-dma-ops-work-2022-10-17-20-29.patch.gz base commit:

a602c9fc8f69 (HEAD) Revert "drm: omapdrm: Do no allocate non-scanout GEMs through DMM/TILER"
ce47e8a1d177 Revert "drm/bridge_connector: enable HPD by default if supported"
bfd43e776077 ANDROID: clang: update to 15.0.2

patch, only need to keep the arm_dma_sync_single_for_cpu function, but after 6.0.0-ebb55188f7c9, arch/arm/include/asm/dma-mapping.h was removed too, need to find how to workaround it now

diff --git a/arch/arm/include/asm/dma-mapping.h b/arch/arm/include/asm/dma-mapping.h
new file mode 100644
index 000000000000..c7c5c87c3358
--- /dev/null
+++ b/arch/arm/include/asm/dma-mapping.h
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef ASMARM_DMA_MAPPING_H
+#define ASMARM_DMA_MAPPING_H
+
+#ifdef __KERNEL__
+
+#include <linux/mm_types.h>
+#include <linux/scatterlist.h>
+
+#include <xen/xen.h>
+#include <asm/xen/hypervisor.h>
+
+extern const struct dma_map_ops arm_dma_ops;
+
+static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus)
+{
+   if (IS_ENABLED(CONFIG_MMU) && !IS_ENABLED(CONFIG_ARM_LPAE))
+       return &arm_dma_ops;
+   return NULL;
+}
+
+#endif /* __KERNEL__ */
+#endif
diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index 089c9c644cce..e1da644d955c 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -103,6 +103,21 @@ static struct arm_dma_buffer *arm_dma_buffer_find(void *virt)
  * before transfers and delay cache invalidation until transfer completion.
  *
  */
+static void __dma_page_dev_to_cpu(struct page *, unsigned long,
+       size_t, enum dma_data_direction);
+
+static void arm_dma_sync_single_for_cpu(struct device *dev,
+       dma_addr_t handle, size_t size, enum dma_data_direction dir)
+{
+   unsigned int offset = handle & (PAGE_SIZE - 1);
+   struct page *page = phys_to_page(dma_to_phys(dev, handle-offset));
+   __dma_page_dev_to_cpu(page, offset, size, dir);
+}
+
+const struct dma_map_ops arm_dma_ops = {
+   .sync_single_for_cpu    = arm_dma_sync_single_for_cpu,
+};
+EXPORT_SYMBOL(arm_dma_ops);

 static void __dma_clear_buffer(struct page *page, size_t size, int coherent_flag)
 {

pvr/services4/srvkm/env/linux/osfunc.c

diff --git a/pvr/services4/srvkm/env/linux/osfunc.c b/pvr/services4/srvkm/env/linux/osfunc.c
index 7f99dae73a3c..49657390a3cd 100644
--- a/pvr/services4/srvkm/env/linux/osfunc.c
+++ b/pvr/services4/srvkm/env/linux/osfunc.c
@@ -4625,7 +4625,8 @@ static void pvr_invalidate_range(phys_addr_t pStart, phys_addr_t pEnd)
        const struct dma_map_ops *dma_ops = get_dma_ops(dev);
        dma_ops->sync_single_for_cpu(dev, pStart, pEnd - pStart, DMA_FROM_DEVICE);
 #else
-       arm_dma_ops.sync_single_for_cpu(NULL, pStart, pEnd - pStart, DMA_FROM_DEVICE);
+       struct device *dev = PVRLDMGetDevice();
+       arm_dma_ops.sync_single_for_cpu(dev, pStart, pEnd - pStart, DMA_FROM_DEVICE);
 #endif
 }

exception during the pvrsrvkm loading

[    9.411468] pvrsrvkm: loading out-of-tree module taints kernel.
[    9.421203] ueventd: LoadWithAliases was unable to load of:Ntarget-moduleT(null)Cti,sysc-omap2Cti,sysc
[    9.436553] ueventd: LoadWithAliases was unable to load of:Ntarget-moduleT(null)Cti,sysc-omap4Cti,sysc
[    9.446075] ueventd: LoadWithAliases was unable to load of:NmmuT(null)Cti,dra7-dsp-iommu
[    9.446899] ------------[ cut here ]------------
[    9.454498] ueventd: Loading module /vendor/lib/modules/display-connector.ko with args ''
[    9.458862] WARNING: CPU: 1 PID: 144 at mm/vmalloc.c:2825 vmap+0x160/0x168
[    9.474151] Modules linked in: pvrsrvkm(O+)
[    9.478363] CPU: 1 PID: 144 Comm: ueventd Tainted: G           O       6.0.0-02961-ga602c9fc8f69-dirty #1
[    9.478363] Hardware name: Generic DRA74X (Flattened Device Tree)
[    9.478393]  unwind_backtrace from show_stack+0x10/0x14
[    9.495849]  show_stack from dump_stack_lvl+0x48/0x54
[    9.495880]  dump_stack_lvl from __warn+0x94/0x184
[    9.495880]  __warn from warn_slowpath_fmt+0xac/0xc8
[    9.495880]  warn_slowpath_fmt from vmap+0x160/0x168
[    9.507263]  vmap from NewVMallocLinuxMemArea+0x170/0x268 [pvrsrvkm]
[    9.520111]  NewVMallocLinuxMemArea [pvrsrvkm] from OSAllocPages_Impl+0x34/0xe4 [pvrsrvkm]
[    9.529907]  OSAllocPages_Impl [pvrsrvkm] from MMU_Initialise+0x15c/0x290 [pvrsrvkm]
[    9.541625]  MMU_Initialise [pvrsrvkm] from BM_CreateContext+0x100/0x284 [pvrsrvkm]
[    9.553680]  BM_CreateContext [pvrsrvkm] from DevInitSGXPart1+0xd4/0x178 [pvrsrvkm]
[    9.568450]  DevInitSGXPart1 [pvrsrvkm] from PVRSRVInitialiseDevice+0x7c/0xac [pvrsrvkm]
[    9.581665]  PVRSRVInitialiseDevice [pvrsrvkm] from SysInitialise+0x4f4/0x52c [pvrsrvkm]
[    9.595764]  SysInitialise [pvrsrvkm] from PVRSRVDriverProbe+0x30/0x44 [pvrsrvkm]
[    9.647308]  PVRSRVDriverProbe [pvrsrvkm] from platform_probe+0x98/0xc0
[    9.654052]  platform_probe from really_probe+0x134/0x33c
[    9.659484]  really_probe from __driver_probe_device+0xb0/0xe4
[    9.665344]  __driver_probe_device from driver_probe_device+0x40/0x1b8
[    9.671905]  driver_probe_device from __driver_attach+0x134/0x1dc
[    9.678039]  __driver_attach from bus_for_each_dev+0x80/0xb4
[    9.683715]  bus_for_each_dev from bus_add_driver+0x10c/0x200
[    9.689514]  bus_add_driver from driver_register+0x84/0x12c
[    9.695098]  driver_register from init_module+0x7c/0xf00 [pvrsrvkm]
[    9.701477]  init_module [pvrsrvkm] from do_one_initcall+0xbc/0x2a0
[    9.707885]  do_one_initcall from do_init_module+0x4c/0x1c4
[    9.713470]  do_init_module from load_module+0x181c/0x19f4
[    9.718994]  load_module from sys_finit_module+0xcc/0xf8
[    9.724334]  sys_finit_module from ret_fast_syscall+0x0/0x4c
[    9.730010] Exception stack(0xe726dfa8 to 0xe726dff0)
[    9.735107] dfa0:                   ffffffff 00000000 00000005 beb11b41 00000000 00000000
[    9.743316] dfc0: ffffffff 00000000 00000000 0000017b b58c04e4 00000000 b6c0eea8 beb11b41
[    9.751525] dfe0: beb11b38 beb11b28 005efe47 b63be60c
[    9.756713] ---[ end trace 0000000000000000 ]---
liuyq commented 1 year ago

arch/arm/include/asm/dma-mapping.h -> #ifdef CONFIG_DMA_OPS ./include/linux/dma-map-ops.h --> arch/arm/mm/dma-mapping.c

arch/arm/include/asm/memory.h -> arch/arm/include/asm/dma-direct.h -->#ifdef CONFIG_ARCH_HAS_PHYS_TO_DMA ./include/linux/dma-direct.h ---> arch/arm/mm/dma-mapping.c

liuyq commented 1 year ago

17:23:20 P15v:common$ grep -rn PHYS_PFN include/ include/asm-generic/memory_model.h:49:#define __phys_to_pfn(paddr) PHYS_PFN(paddr) include/linux/pfn.h:22:#define PHYS_PFN(x) ((unsigned long)((x) >> PAGE_SHIFT)) 17:23:25 P15v:common$ arch/arm/include/asm/memory.h:382:#define bus_to_pfn(x) phys_to_pfn(x) arch/arm/include/asm/dma-direct.h:31: return pfn_to_dma(dev, __phys_to_pfn(paddr)) + offset;

include/asm-generic/memory_model.h
/*
 * Convert a physical address to a Page Frame Number and back
 */
#define __phys_to_pfn(paddr)    PHYS_PFN(paddr)