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

Page Frame Management

Memory area management

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

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

代码和调试

  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

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

ION APIS

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

ION changes

ION与DMABUF的关联

代码和调试

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的关联

代码和调试

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

相机架构简述

相机smmu

相机DMABUF调用栈分析

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

Display DMABUF调用栈分析

总结1

总结2

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

repinkply

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值