diff --git a/osal/android/os_allocator.c b/osal/android/os_allocator.c index 2e2e9d54..15de72a6 100644 --- a/osal/android/os_allocator.c +++ b/osal/android/os_allocator.c @@ -177,6 +177,7 @@ typedef struct { #define VPU_IOC_MAGIC 'l' #define VPU_IOC_PROBE_IOMMU_STATUS _IOR(VPU_IOC_MAGIC, 5, unsigned long) +#define VPU_IOC_PROBE_HEAP_STATUS _IOR(VPU_IOC_MAGIC, 6, unsigned long) const char *dev_ion = "/dev/ion"; const char *dev_vpu = "/dev/vpu_service"; static RK_S32 ion_heap_id = -1; @@ -214,27 +215,34 @@ MPP_RET os_allocator_ion_open(void **ctx, size_t alignment) * if there is vpu_service then check the iommu_enable status */ if (ion_heap_id < 0) { - int iommu_enabled = -2; + int use_vmalloc_heap = 0; + int vpu_fd = open(dev_vpu, O_RDWR); if (vpu_fd >= 0) { - int ret = ioctl(vpu_fd, VPU_IOC_PROBE_IOMMU_STATUS, &iommu_enabled); + int ret = ioctl(vpu_fd, VPU_IOC_PROBE_HEAP_STATUS, &use_vmalloc_heap); if (ret) { - iommu_enabled = 0; - mpp_err("can not get iommu status, disable iommu\n"); + int iommu_enabled = -1; + + mpp_err("mpp can not get heap status\n"); + + ret = ioctl(vpu_fd, VPU_IOC_PROBE_IOMMU_STATUS, &iommu_enabled); + if (ret) { + mpp_err("mpp can not get iommu status\n"); + } else { + use_vmalloc_heap = iommu_enabled; + } } close(vpu_fd); - } else { - iommu_enabled = 0; } - if (!iommu_enabled) { - ion_heap_mask = (1 << ION_HEAP_TYPE_DMA); - ion_heap_id = ION_HEAP_TYPE_DMA; - } else { + if (use_vmalloc_heap) { ion_heap_mask = (1 << ION_HEAP_TYPE_SYSTEM); ion_heap_id = ION_HEAP_TYPE_SYSTEM; + } else { + ion_heap_mask = (1 << ION_HEAP_TYPE_DMA); + ion_heap_id = ION_HEAP_TYPE_DMA; } - mpp_log("using ion heap %s\n", (ion_heap_id == ION_HEAP_TYPE_SYSTEM) ? + mpp_log("using ion heap %s\n", (use_vmalloc_heap) ? ("ION_HEAP_TYPE_SYSTEM") : ("ION_HEAP_TYPE_DMA")); } p->alignment = alignment;