Gralloc ION DMABUF in Camera & Display

目录

Background knowledge

Introduction ia pa va and memory addressing

Memory Addressing

Page Frame Management

Memory area management

DMA

IOVA and IOMMU

Introduce DMABUF

What is DMABUF

DMABUF 关键概念

DMABUF APIS –The Exporter

DMABUF APIS –The Importer

DMABUF APIS

DMABUF usage flow

代码和调试

Introduce ION

What is ION

ION Overview

ION关键概念

ION 配置

ION APIS

ION changes

ION与DMABUF的关联

代码和调试

Introduce Gralloc

What is gralloc

Gralloc 和 ION的关联

代码和调试

Gralloc ion DMABUF in Camera & display

相机架构简述

相机smmu

相机DMABUF调用栈分析

相机驱动内存管理实例分析

Display DMABUF调用栈分析

总结1

总结2


Background knowledge

Introduction ia pa va and memory addressing

ia(Intermediate Address):CPU指令构造的地址空间,指令的演进具有滞后性,分段需求诞生。中间地址,也称为物理中间地址(Physical Intermediate Address),是指 CPU 访问内存时使用的地址。IA 是 CPU 通过地址转换机制将 VA 转换为 PA 的中间步骤。

pa(Physical Address):物理地址总线发出的地址构成的地址空间。物理地址,是指 CPU 访问内存时实际使用的地址。PA 是 CPU 通过地址转换机制将 VA 转换为 PA 的最终结果。

va(Virtual Address):pa的空间过大后,引入页表,经过分页处理ia和pa不再一一对应,ia由此之后可称为va。虚拟地址,是指程序在运行时使用的地址。VA 是程序中使用的地址,与物理内存地址没有直接关系。

Memory Addressing

Gralloc ION DMABUF in Camera & Display_第1张图片

Gralloc ION DMABUF in Camera & Display_第2张图片

Page Frame Management

Gralloc ION DMABUF in Camera & Display_第3张图片

Memory area management

Gralloc ION DMABUF in Camera & Display_第4张图片

DMA

  1. DMA(Direct Memory Access,直接内存存取) 它允许不同速度的硬件装置来沟通,而不需要依赖于 CPU 的大量中断负载 。
  2. DMA 传输将数据从一个地址空间复制到另外一个地址空间。
  3. Reference : http://www.wowotech.net/memory_management/DMA-Mapping-api.html

IOVA and IOMMU

  1. DMA 最初只接受物理地址,设备地址长度比CPU总线长度短,分配低地址给设备使用
  2. 设备增强后可以自带页表将DMA地址转换为同等长度的物理地址
  3. 设备自带页表转换可以认为在IO上做了mmu转换,硬件上有了IOMMU的概念,arm上称为SMMU
  4. IOMMU 作用是连接DMA-capable I/O总线(Direct Memory Access-capable I/O Bus)和主存(main memory)
  5. DMA地址可以由此可称为IOVA

Gralloc ION DMABUF in Camera & Display_第5张图片

Introduce DMABUF

What is DMABUF

  1. A generic kernel level framework to share buffers.
  2. Defines a new buffer object, which provides mechanism for exporting and using shared buffers.
  3. Provides uniform APIs that allow various operations related to buffer sharing.

DMABUF 关键概念

  1. The exporter
  2. implements and manages operations in struct dma_buf_ops for the buffer,
  3. allows other users to share the buffer by using dma_buf sharing APIs,
  4. manages the details of buffer allocation, wrapped int a struct dma_buf,
  5. decides about the actual backing storage where this allocation happens,
  6. and takes care of any migration of scatterlist - for all (shared) users of this buffer.

  1. The buffer-user
  2. is one of (many) sharing users of the buffer.
  3. doesn’t need to worry about how the buffer is allocated, or where.
  4. and needs a mechanism to get access to the scatterlist that makes up this buffer in memory, mapped into its own address space, so it can access the same area of memory. This interface is provided by struct dma_buf_attachment.

DMABUF APIS –The Exporter

1、dma_buf_export()  Used to export a buffer,Connects the exporter's private metadata for the buffer, an implementation of buffer operations for this buffer, and flags for the associated file. Returns a handle to the dma_buf object with all the above associated information.  

2、dma_buf_fd() Returns a FD associated with the dma_buf object. Userspace then passes the FD to other devices & sub-systems participating in sharing this dma_buf object.

3、dma_buf_get() Used by importing device to get the dma_buf object associated with the FD

DMABUF APIS –The Importer

4、dma_buf_attach(): The importing device can attach itself with the dma_buf object. Called once at beginning of dma_buf object sharing.

5、dma_buf_map_attachment() Used by importing device to request access to the buffer so it can do DMA. Returns an sg_table, containing the scatterlist mapped in the importing device's address space.

6、dma_buf_unmap_attachment() Once the DMA access is done, the device tells the exporter that the currently requested access is completed by calling this API.

DMABUF APIS

7、dma_buf_detach() At the end of need to access this dma_buf object, the importer device tells the exporter of its intent to 'detach' from the current sharing.

8、dma_buf_put() After dma_buf_detach() is called, the reference count of this buffer is decremented by calling dma_buf_put().

DMABUF usage flow

Gralloc ION DMABUF in Camera & Display_第6张图片

代码和调试

  1. 代码路径:kernel/msm-4.14/drivers/dma-buf
  2. Debug:/sys/kernel/debug/dma_buf
  3. Reference: https://www.kernel.org/doc/html/latest/driver-api/dma-buf.html

Introduce ION

What is ION

  1. ION is a generalized memory manager that Google introduced in the Android 4.0 ICS (Ice Cream Sandwich) release to address the issue of fragmented memory management interfaces across different Android devices.
  2. 内存池管理器

ION Overview

Gralloc ION DMABUF in Camera & Display_第7张图片

ION关键概念

  1. ION device : metadata of the ion device node
  2. ION heap ops : ops to operate on a given heap
  3. ION heap : represents a heap in the system
  4. ION page pool: ION memory pool in heap
  5. ION buffer : metadata for a particular buffer

ION 配置

path: msm-4.14/arch/arm/boot/dts/qcom/sm8150-ion.dtsi

msm_ion_probe

        Ion_device_create

        Ion_heap_create

        Ion_device_add_heap

Gralloc ION DMABUF in Camera & Display_第8张图片

ION APIS

  1. Ion_alloc_fd()
  2. ion_ioctl()
  3. Ion_map()
  4. Ion_free()

ION changes

Gralloc ION DMABUF in Camera & Display_第9张图片

ION与DMABUF的关联

Gralloc ION DMABUF in Camera & Display_第10张图片

代码和调试

Code :

  1. system/core/libion/
  2. kernel/msm-4.14/drivers/staging/android/ion/

Debug:

  1. /sys/kernel/debug/dma_buf

Introduce Gralloc

What is gralloc

  1. Gralloc is a vendor-supplied library, at run-time in /system/lib/hw/gralloc.[product name].so
  2. allocates graphic buffers
  3. gralloc allocates all graphic buffers using a kernel memory manager, typically ION  
  4. Selects appropriate ION heap based on the buffer usage flags

Gralloc 和 ION的关联

Gralloc ION DMABUF in Camera & Display_第11张图片

Gralloc ION DMABUF in Camera & Display_第12张图片

Gralloc ION DMABUF in Camera & Display_第13张图片

代码和调试

code

gralloc0 gralloc1

hardware/libhardware/include/hardware/gralloc.h libhardware/modules/gralloc/

gralloc2

hardware/interfaces/graphics/allocator/ hardware/qcom/display/gralloc/​

Gralloc ion DMABUF in Camera & display

相机架构简述

Gralloc ION DMABUF in Camera & Display_第14张图片

Gralloc ION DMABUF in Camera & Display_第15张图片

Gralloc ION DMABUF in Camera & Display_第16张图片

Gralloc ION DMABUF in Camera & Display_第17张图片

相机smmu

Gralloc ION DMABUF in Camera & Display_第18张图片

Gralloc ION DMABUF in Camera & Display_第19张图片

相机DMABUF调用栈分析

Gralloc ION DMABUF in Camera & Display_第20张图片

Gralloc ION DMABUF in Camera & Display_第21张图片

Gralloc ION DMABUF in Camera & Display_第22张图片

相机驱动内存管理实例分析

Gralloc ION DMABUF in Camera & Display_第23张图片

Display DMABUF调用栈分析

Gralloc ION DMABUF in Camera & Display_第24张图片

Gralloc ION DMABUF in Camera & Display_第25张图片

Gralloc ION DMABUF in Camera & Display_第26张图片

总结1

Gralloc ION DMABUF in Camera & Display_第27张图片

总结2

Gralloc ION DMABUF in Camera & Display_第28张图片

你可能感兴趣的:(#,camera软件,Gralloc,DMABUF)