SlideShare a Scribd company logo
Whenwe’redone, it’sdone!
DMA Survival Guide
Property of Tandem Group
Whenwe’redone, it’sdone!
Ramon Fried
 Developer and hacker since 1983
 B.sc in computer science
 Expertise in Embedded systems and Linux
system and kernel development.
 Currently Embedded Linux Team Leader in
TandemG
Property of Tandem Group
Whenwe’redone, it’sdone!
TandemG
 TandemG is Israel’s leading Software, Hardware and Systems R&D
center, acting as a one-stop-shop for our range of partners, from
prominent start-ups through to market leaders
 In the embedded domain, TandemG tailors solutions spanning
across RTOS, Embedded Linux, low-level Android and DSP.
 For the second year in a row, TandemG has been selected to
Delloite’s Israel Technology Fast50 list in the 23rd place
 Visit us at www.tandemG.com, for additional details.
Property of Tandem Group
Whenwe’redone, it’sdone!
Agenda
 What is DMA
 DMA Buffer allocation
— Coherent
— Streaming
 Scatter Gather mapping
 DMA pools
 DMA Triggering
— PCI
— dmaengine
Property of Tandem Group
Whenwe’redone, it’sdone!
What is DMA
 Direct memory access
 Feature of computer systems that allows
certain hardware subsystems to access main
system memory (RAM), independent of the
central processing unit (CPU).
 CPU can be notified on the end of operation by
IRQ.
Property of Tandem Group
Whenwe’redone, it’sdone!
What is DMA
Photo from: http://encyclopedia2.thefreedictionary.com/DMA
Property of Tandem Group
Whenwe’redone, it’sdone!
DMA Buffer allocation
 DMA controller works on physical addresses
 Physical memory needs to be accessible by
DMA controller
 Memory must be continuous
Property of Tandem Group
Whenwe’redone, it’sdone!
DMA Buffer allocation
 Coherent DMA mapping
— Usually long lasting.
— Can be accessed by both ends.
— No-caching *
— At least page sized.
 Streaming DMA mapping
— Usually singly used and freed.
— Architecture/Platform optimized.
— direction must be defined explicitly.
Property of Tandem Group
Whenwe’redone, it’sdone!
DMA access mask
#include <linux/dma-mapping.h>
int dma_set_mask_and_coherent(struct device
*dev, u64 mask);
int dma_set_mask (struct device *dev, u64
mask);
int dma_set_coherent_mask(struct device *dev,
u64 mask);
Property of Tandem Group
Whenwe’redone, it’sdone!
Coherent DMA mapping
#include <linux/dma-mapping.h>
void *dma_alloc_coherent(struct device *dev,
size_t size, dma_addr_t
*dma_handle, gfp_t flag);
void dma_free_coherent(struct device *dev,
size_t size, void *cpu_addr,
dma_addr_t dma_handle);
Property of Tandem Group
Whenwe’redone, it’sdone!
Streaming DMA mapping
#include <linux/dma-mapping.h>
dma_addr_t dma_map_single(struct device
*dev, void *ptr,size_t size,
enum dma_data_direction dir);
void dma_unmap_single(struct device
*dev, dma_addr_t addr,
size_t size,
enum dma_data_direction dir);
Property of Tandem Group
Whenwe’redone, it’sdone!
Streaming DMA mapping (cont’d)
 enum dma_data_direction
— DMA_TO_DEVICE
— DMA_FROM_DEVICE
— DMA_BIDIRECTIONAL
Property of Tandem Group
Whenwe’redone, it’sdone!
Streaming DMA usage
 Buffer Ownership
— Buffer is owned by the device.
— Altering the buffer can be done only after acquiring
ownership
 dma_sync_single_for_cpu()
— After altering the buffer, the ownership needs to be
returned to the device.
 dma_sync_single_for_device()
Property of Tandem Group
Whenwe’redone, it’sdone!
Scatter gather buffers
 Special type of streaming DMA
 writev, readv, clustered buffers (YUV plannar,
non continuous memory, etc.)
Property of Tandem Group
Whenwe’redone, it’sdone!
Scatter/Gather API
#include linux/dma-mapping.h
int dma_map_sg( struct device *dev,
struct scatterlist *sg,
int nents,
enum dma_data_direction dir);
void dma_unmap_sg(struct device *dev,
struct scatterlist *list,
int nents,
enum dma_data_direction dir);
Property of Tandem Group
Whenwe’redone, it’sdone!
Don’t forget to sync
#include linux/dma-mapping.h
void dma_sync_sg_for_cpu(struct device *dev,
struct scatterlist *sg,
int nelems,
enum dma_data_direction dir);
void dma_sync_sg_for_device(struct device *dev,
struct scatterlist *sg,
int nelems,
enum dma_data_direction dir);
Property of Tandem Group
Whenwe’redone, it’sdone!
DMA Pools
 DMA Pools
— Coherent
— Used to allocate buffers smaller than a page.
— dma_pool_create()
— dma_pool_destroy()
— dma_pool_alloc()
— dma_pool_free()
Property of Tandem Group
Whenwe’redone, it’sdone!
Start the DMA operation
Property of Tandem Group
Whenwe’redone, it’sdone!
Triggering the DMA operation
 PCI
 dmaengine
Property of Tandem Group
Whenwe’redone, it’sdone!
PCI Wrappers
 PCI wrappers
— pci_alloc_consistent()
— pci_free_consistent()
— pci_set_dma_mask()
— pci_pool_create()
— …
Property of Tandem Group
Whenwe’redone, it’sdone!
PCI DMA transaction example
dma_addr_t bus_addr;
bus_addr = dma_map_single(&dev->pci_dev->dev, buffer, count, DMA_TO_DEVICE);
writeb(dev->registers.command, DAD_CMD_DISABLEDMA);
writeb(dev->registers.command, DAD_CMD_WR);
writel(dev->registers.addr, cpu_to_le32(bus_addr));
writel(dev->registers.len, cpu_to_le32(count));
writeb(dev->registers.command, DAD_CMD_ENABLEDMA);
Property of Tandem Group
Whenwe’redone, it’sdone!
DMA Engine
 Subsystem to handle memory-to-device
transfers
 Exists since 2.6.18 (2006)
 Code in “drivers/dma”
 Documentation in “dmaengine/*”
 Poorly documented
THANK YOU!

More Related Content

What's hot

Dpdk applications
Dpdk applicationsDpdk applications
Dpdk applications
Vipin Varghese
 
Slab Allocator in Linux Kernel
Slab Allocator in Linux KernelSlab Allocator in Linux Kernel
Slab Allocator in Linux Kernel
Adrian Huang
 
Linux Initialization Process (2)
Linux Initialization Process (2)Linux Initialization Process (2)
Linux Initialization Process (2)
shimosawa
 
Memory Mapping Implementation (mmap) in Linux Kernel
Memory Mapping Implementation (mmap) in Linux KernelMemory Mapping Implementation (mmap) in Linux Kernel
Memory Mapping Implementation (mmap) in Linux Kernel
Adrian Huang
 
Let's trace Linux Lernel with KGDB @ COSCUP 2021
Let's trace Linux Lernel with KGDB @ COSCUP 2021Let's trace Linux Lernel with KGDB @ COSCUP 2021
Let's trace Linux Lernel with KGDB @ COSCUP 2021
Jian-Hong Pan
 
Linux device drivers
Linux device drivers Linux device drivers
Part 02 Linux Kernel Module Programming
Part 02 Linux Kernel Module ProgrammingPart 02 Linux Kernel Module Programming
Part 02 Linux Kernel Module Programming
Tushar B Kute
 
malloc & vmalloc in Linux
malloc & vmalloc in Linuxmalloc & vmalloc in Linux
malloc & vmalloc in Linux
Adrian Huang
 
Linux MMAP & Ioremap introduction
Linux MMAP & Ioremap introductionLinux MMAP & Ioremap introduction
Linux MMAP & Ioremap introduction
Gene Chang
 
Linux Network Stack
Linux Network StackLinux Network Stack
Linux Network Stack
Adrien Mahieux
 
Overlayfs and VFS
Overlayfs and VFSOverlayfs and VFS
Overlayfs and VFS
Hao(Robin) Dong
 
Linux Performance Profiling and Monitoring
Linux Performance Profiling and MonitoringLinux Performance Profiling and Monitoring
Linux Performance Profiling and Monitoring
Georg Schönberger
 
COSCUP 2020 RISC-V 32 bit linux highmem porting
COSCUP 2020 RISC-V 32 bit linux highmem portingCOSCUP 2020 RISC-V 32 bit linux highmem porting
COSCUP 2020 RISC-V 32 bit linux highmem porting
Eric Lin
 
Arm device tree and linux device drivers
Arm device tree and linux device driversArm device tree and linux device drivers
Arm device tree and linux device drivers
Houcheng Lin
 
Understanding DPDK
Understanding DPDKUnderstanding DPDK
Understanding DPDK
Denys Haryachyy
 
Linux Kernel Booting Process (1) - For NLKB
Linux Kernel Booting Process (1) - For NLKBLinux Kernel Booting Process (1) - For NLKB
Linux Kernel Booting Process (1) - For NLKB
shimosawa
 
Page cache in Linux kernel
Page cache in Linux kernelPage cache in Linux kernel
Page cache in Linux kernel
Adrian Huang
 
Intel DPDK Step by Step instructions
Intel DPDK Step by Step instructionsIntel DPDK Step by Step instructions
Intel DPDK Step by Step instructions
Hisaki Ohara
 
BPF Internals (eBPF)
BPF Internals (eBPF)BPF Internals (eBPF)
BPF Internals (eBPF)
Brendan Gregg
 

What's hot (20)

Dpdk applications
Dpdk applicationsDpdk applications
Dpdk applications
 
Slab Allocator in Linux Kernel
Slab Allocator in Linux KernelSlab Allocator in Linux Kernel
Slab Allocator in Linux Kernel
 
Linux Initialization Process (2)
Linux Initialization Process (2)Linux Initialization Process (2)
Linux Initialization Process (2)
 
Memory Mapping Implementation (mmap) in Linux Kernel
Memory Mapping Implementation (mmap) in Linux KernelMemory Mapping Implementation (mmap) in Linux Kernel
Memory Mapping Implementation (mmap) in Linux Kernel
 
Let's trace Linux Lernel with KGDB @ COSCUP 2021
Let's trace Linux Lernel with KGDB @ COSCUP 2021Let's trace Linux Lernel with KGDB @ COSCUP 2021
Let's trace Linux Lernel with KGDB @ COSCUP 2021
 
Linux device drivers
Linux device drivers Linux device drivers
Linux device drivers
 
Part 02 Linux Kernel Module Programming
Part 02 Linux Kernel Module ProgrammingPart 02 Linux Kernel Module Programming
Part 02 Linux Kernel Module Programming
 
malloc & vmalloc in Linux
malloc & vmalloc in Linuxmalloc & vmalloc in Linux
malloc & vmalloc in Linux
 
Linux MMAP & Ioremap introduction
Linux MMAP & Ioremap introductionLinux MMAP & Ioremap introduction
Linux MMAP & Ioremap introduction
 
Linux Network Stack
Linux Network StackLinux Network Stack
Linux Network Stack
 
Overlayfs and VFS
Overlayfs and VFSOverlayfs and VFS
Overlayfs and VFS
 
Linux Performance Profiling and Monitoring
Linux Performance Profiling and MonitoringLinux Performance Profiling and Monitoring
Linux Performance Profiling and Monitoring
 
COSCUP 2020 RISC-V 32 bit linux highmem porting
COSCUP 2020 RISC-V 32 bit linux highmem portingCOSCUP 2020 RISC-V 32 bit linux highmem porting
COSCUP 2020 RISC-V 32 bit linux highmem porting
 
Arm device tree and linux device drivers
Arm device tree and linux device driversArm device tree and linux device drivers
Arm device tree and linux device drivers
 
Understanding DPDK
Understanding DPDKUnderstanding DPDK
Understanding DPDK
 
Linux Kernel Booting Process (1) - For NLKB
Linux Kernel Booting Process (1) - For NLKBLinux Kernel Booting Process (1) - For NLKB
Linux Kernel Booting Process (1) - For NLKB
 
Page cache in Linux kernel
Page cache in Linux kernelPage cache in Linux kernel
Page cache in Linux kernel
 
Intel DPDK Step by Step instructions
Intel DPDK Step by Step instructionsIntel DPDK Step by Step instructions
Intel DPDK Step by Step instructions
 
淺談探索 Linux 系統設計之道
淺談探索 Linux 系統設計之道 淺談探索 Linux 系統設計之道
淺談探索 Linux 系統設計之道
 
BPF Internals (eBPF)
BPF Internals (eBPF)BPF Internals (eBPF)
BPF Internals (eBPF)
 

Similar to DMA Survival Guide

Best practices for long-term support and security of the device-tree
Best practices for long-term support and security of the device-treeBest practices for long-term support and security of the device-tree
Best practices for long-term support and security of the device-tree
Alison Chaiken
 
OpenNebulaConf 2016 - The DRBD SDS for OpenNebula by Philipp Reisner, LINBIT
OpenNebulaConf 2016 - The DRBD SDS for OpenNebula by Philipp Reisner, LINBITOpenNebulaConf 2016 - The DRBD SDS for OpenNebula by Philipp Reisner, LINBIT
OpenNebulaConf 2016 - The DRBD SDS for OpenNebula by Philipp Reisner, LINBIT
OpenNebula Project
 
Droidcon London 2021 - Full Stack Dart
Droidcon London 2021   - Full Stack DartDroidcon London 2021   - Full Stack Dart
Droidcon London 2021 - Full Stack Dart
Chris Swan
 
Data compression in Modern Application
Data compression in Modern ApplicationData compression in Modern Application
Data compression in Modern Application
LivePerson
 
The rainbow treasure map: Advanced color management on Linux with AMD/Steam D...
The rainbow treasure map: Advanced color management on Linux with AMD/Steam D...The rainbow treasure map: Advanced color management on Linux with AMD/Steam D...
The rainbow treasure map: Advanced color management on Linux with AMD/Steam D...
Igalia
 
Overview of Spark for HPC
Overview of Spark for HPCOverview of Spark for HPC
Overview of Spark for HPC
Glenn K. Lockwood
 
Managed DirectX
Managed DirectXManaged DirectX
Managed DirectX
A. LE
 
Monitoring MySQL with DTrace/SystemTap
Monitoring MySQL with DTrace/SystemTapMonitoring MySQL with DTrace/SystemTap
Monitoring MySQL with DTrace/SystemTap
Padraig O'Sullivan
 
FOSDEM'17: Disaster Recovery Management with ReaR (relax-and-recover) & DRLM ...
FOSDEM'17: Disaster Recovery Management with ReaR (relax-and-recover) & DRLM ...FOSDEM'17: Disaster Recovery Management with ReaR (relax-and-recover) & DRLM ...
FOSDEM'17: Disaster Recovery Management with ReaR (relax-and-recover) & DRLM ...
Didac Oliveira
 
HDX 3D
HDX 3DHDX 3D
Fall of a domain | From local admin to Domain user hashes
Fall of a domain | From local admin to Domain user hashesFall of a domain | From local admin to Domain user hashes
Fall of a domain | From local admin to Domain user hashes
n|u - The Open Security Community
 
DevOpSec_DockerNPodMan-20230220.pdf
DevOpSec_DockerNPodMan-20230220.pdfDevOpSec_DockerNPodMan-20230220.pdf
DevOpSec_DockerNPodMan-20230220.pdf
kanedafromparis
 
the productive programer: mechanics
the productive programer: mechanicsthe productive programer: mechanics
the productive programer: mechanicselliando dias
 
UGIF 12 2010 - features11.70
UGIF 12 2010 - features11.70UGIF 12 2010 - features11.70
UGIF 12 2010 - features11.70UGIF
 
Informix User Group France - 30/11/2010 - Fonctionalités IDS 11.7
Informix User Group France - 30/11/2010 - Fonctionalités IDS 11.7Informix User Group France - 30/11/2010 - Fonctionalités IDS 11.7
Informix User Group France - 30/11/2010 - Fonctionalités IDS 11.7Nicolas Desachy
 
Ugif 04 2011 déployer informix
Ugif 04 2011   déployer informixUgif 04 2011   déployer informix
Ugif 04 2011 déployer informixUGIF
 
DYNAmore Ecosystem, News on DYNAmore's LS-DYNA-Tools_S_Mattern.pdf
DYNAmore Ecosystem, News on DYNAmore's LS-DYNA-Tools_S_Mattern.pdfDYNAmore Ecosystem, News on DYNAmore's LS-DYNA-Tools_S_Mattern.pdf
DYNAmore Ecosystem, News on DYNAmore's LS-DYNA-Tools_S_Mattern.pdf
BharathChannappa1
 

Similar to DMA Survival Guide (20)

Best practices for long-term support and security of the device-tree
Best practices for long-term support and security of the device-treeBest practices for long-term support and security of the device-tree
Best practices for long-term support and security of the device-tree
 
KIRANKUMAR_MV
KIRANKUMAR_MVKIRANKUMAR_MV
KIRANKUMAR_MV
 
OpenNebulaConf 2016 - The DRBD SDS for OpenNebula by Philipp Reisner, LINBIT
OpenNebulaConf 2016 - The DRBD SDS for OpenNebula by Philipp Reisner, LINBITOpenNebulaConf 2016 - The DRBD SDS for OpenNebula by Philipp Reisner, LINBIT
OpenNebulaConf 2016 - The DRBD SDS for OpenNebula by Philipp Reisner, LINBIT
 
Droidcon London 2021 - Full Stack Dart
Droidcon London 2021   - Full Stack DartDroidcon London 2021   - Full Stack Dart
Droidcon London 2021 - Full Stack Dart
 
Data compression in Modern Application
Data compression in Modern ApplicationData compression in Modern Application
Data compression in Modern Application
 
The rainbow treasure map: Advanced color management on Linux with AMD/Steam D...
The rainbow treasure map: Advanced color management on Linux with AMD/Steam D...The rainbow treasure map: Advanced color management on Linux with AMD/Steam D...
The rainbow treasure map: Advanced color management on Linux with AMD/Steam D...
 
Deft
DeftDeft
Deft
 
Overview of Spark for HPC
Overview of Spark for HPCOverview of Spark for HPC
Overview of Spark for HPC
 
DinakaraPandian_9+
DinakaraPandian_9+DinakaraPandian_9+
DinakaraPandian_9+
 
Managed DirectX
Managed DirectXManaged DirectX
Managed DirectX
 
Monitoring MySQL with DTrace/SystemTap
Monitoring MySQL with DTrace/SystemTapMonitoring MySQL with DTrace/SystemTap
Monitoring MySQL with DTrace/SystemTap
 
FOSDEM'17: Disaster Recovery Management with ReaR (relax-and-recover) & DRLM ...
FOSDEM'17: Disaster Recovery Management with ReaR (relax-and-recover) & DRLM ...FOSDEM'17: Disaster Recovery Management with ReaR (relax-and-recover) & DRLM ...
FOSDEM'17: Disaster Recovery Management with ReaR (relax-and-recover) & DRLM ...
 
HDX 3D
HDX 3DHDX 3D
HDX 3D
 
Fall of a domain | From local admin to Domain user hashes
Fall of a domain | From local admin to Domain user hashesFall of a domain | From local admin to Domain user hashes
Fall of a domain | From local admin to Domain user hashes
 
DevOpSec_DockerNPodMan-20230220.pdf
DevOpSec_DockerNPodMan-20230220.pdfDevOpSec_DockerNPodMan-20230220.pdf
DevOpSec_DockerNPodMan-20230220.pdf
 
the productive programer: mechanics
the productive programer: mechanicsthe productive programer: mechanics
the productive programer: mechanics
 
UGIF 12 2010 - features11.70
UGIF 12 2010 - features11.70UGIF 12 2010 - features11.70
UGIF 12 2010 - features11.70
 
Informix User Group France - 30/11/2010 - Fonctionalités IDS 11.7
Informix User Group France - 30/11/2010 - Fonctionalités IDS 11.7Informix User Group France - 30/11/2010 - Fonctionalités IDS 11.7
Informix User Group France - 30/11/2010 - Fonctionalités IDS 11.7
 
Ugif 04 2011 déployer informix
Ugif 04 2011   déployer informixUgif 04 2011   déployer informix
Ugif 04 2011 déployer informix
 
DYNAmore Ecosystem, News on DYNAmore's LS-DYNA-Tools_S_Mattern.pdf
DYNAmore Ecosystem, News on DYNAmore's LS-DYNA-Tools_S_Mattern.pdfDYNAmore Ecosystem, News on DYNAmore's LS-DYNA-Tools_S_Mattern.pdf
DYNAmore Ecosystem, News on DYNAmore's LS-DYNA-Tools_S_Mattern.pdf
 

More from Kernel TLV

DPDK In Depth
DPDK In DepthDPDK In Depth
DPDK In Depth
Kernel TLV
 
Building Network Functions with eBPF & BCC
Building Network Functions with eBPF & BCCBuilding Network Functions with eBPF & BCC
Building Network Functions with eBPF & BCC
Kernel TLV
 
SGX Trusted Execution Environment
SGX Trusted Execution EnvironmentSGX Trusted Execution Environment
SGX Trusted Execution Environment
Kernel TLV
 
Fun with FUSE
Fun with FUSEFun with FUSE
Fun with FUSE
Kernel TLV
 
Kernel Proc Connector and Containers
Kernel Proc Connector and ContainersKernel Proc Connector and Containers
Kernel Proc Connector and Containers
Kernel TLV
 
Bypassing ASLR Exploiting CVE 2015-7545
Bypassing ASLR Exploiting CVE 2015-7545Bypassing ASLR Exploiting CVE 2015-7545
Bypassing ASLR Exploiting CVE 2015-7545
Kernel TLV
 
Present Absence of Linux Filesystem Security
Present Absence of Linux Filesystem SecurityPresent Absence of Linux Filesystem Security
Present Absence of Linux Filesystem Security
Kernel TLV
 
OpenWrt From Top to Bottom
OpenWrt From Top to BottomOpenWrt From Top to Bottom
OpenWrt From Top to Bottom
Kernel TLV
 
Make Your Containers Faster: Linux Container Performance Tools
Make Your Containers Faster: Linux Container Performance ToolsMake Your Containers Faster: Linux Container Performance Tools
Make Your Containers Faster: Linux Container Performance Tools
Kernel TLV
 
Emerging Persistent Memory Hardware and ZUFS - PM-based File Systems in User ...
Emerging Persistent Memory Hardware and ZUFS - PM-based File Systems in User ...Emerging Persistent Memory Hardware and ZUFS - PM-based File Systems in User ...
Emerging Persistent Memory Hardware and ZUFS - PM-based File Systems in User ...
Kernel TLV
 
File Systems: Why, How and Where
File Systems: Why, How and WhereFile Systems: Why, How and Where
File Systems: Why, How and Where
Kernel TLV
 
netfilter and iptables
netfilter and iptablesnetfilter and iptables
netfilter and iptables
Kernel TLV
 
KernelTLV Speaker Guidelines
KernelTLV Speaker GuidelinesKernelTLV Speaker Guidelines
KernelTLV Speaker Guidelines
Kernel TLV
 
Userfaultfd: Current Features, Limitations and Future Development
Userfaultfd: Current Features, Limitations and Future DevelopmentUserfaultfd: Current Features, Limitations and Future Development
Userfaultfd: Current Features, Limitations and Future Development
Kernel TLV
 
Linux Kernel Cryptographic API and Use Cases
Linux Kernel Cryptographic API and Use CasesLinux Kernel Cryptographic API and Use Cases
Linux Kernel Cryptographic API and Use Cases
Kernel TLV
 
FD.IO Vector Packet Processing
FD.IO Vector Packet ProcessingFD.IO Vector Packet Processing
FD.IO Vector Packet Processing
Kernel TLV
 
WiFi and the Beast
WiFi and the BeastWiFi and the Beast
WiFi and the Beast
Kernel TLV
 
Introduction to DPDK
Introduction to DPDKIntroduction to DPDK
Introduction to DPDK
Kernel TLV
 
FreeBSD and Drivers
FreeBSD and DriversFreeBSD and Drivers
FreeBSD and Drivers
Kernel TLV
 
Specializing the Data Path - Hooking into the Linux Network Stack
Specializing the Data Path - Hooking into the Linux Network StackSpecializing the Data Path - Hooking into the Linux Network Stack
Specializing the Data Path - Hooking into the Linux Network Stack
Kernel TLV
 

More from Kernel TLV (20)

DPDK In Depth
DPDK In DepthDPDK In Depth
DPDK In Depth
 
Building Network Functions with eBPF & BCC
Building Network Functions with eBPF & BCCBuilding Network Functions with eBPF & BCC
Building Network Functions with eBPF & BCC
 
SGX Trusted Execution Environment
SGX Trusted Execution EnvironmentSGX Trusted Execution Environment
SGX Trusted Execution Environment
 
Fun with FUSE
Fun with FUSEFun with FUSE
Fun with FUSE
 
Kernel Proc Connector and Containers
Kernel Proc Connector and ContainersKernel Proc Connector and Containers
Kernel Proc Connector and Containers
 
Bypassing ASLR Exploiting CVE 2015-7545
Bypassing ASLR Exploiting CVE 2015-7545Bypassing ASLR Exploiting CVE 2015-7545
Bypassing ASLR Exploiting CVE 2015-7545
 
Present Absence of Linux Filesystem Security
Present Absence of Linux Filesystem SecurityPresent Absence of Linux Filesystem Security
Present Absence of Linux Filesystem Security
 
OpenWrt From Top to Bottom
OpenWrt From Top to BottomOpenWrt From Top to Bottom
OpenWrt From Top to Bottom
 
Make Your Containers Faster: Linux Container Performance Tools
Make Your Containers Faster: Linux Container Performance ToolsMake Your Containers Faster: Linux Container Performance Tools
Make Your Containers Faster: Linux Container Performance Tools
 
Emerging Persistent Memory Hardware and ZUFS - PM-based File Systems in User ...
Emerging Persistent Memory Hardware and ZUFS - PM-based File Systems in User ...Emerging Persistent Memory Hardware and ZUFS - PM-based File Systems in User ...
Emerging Persistent Memory Hardware and ZUFS - PM-based File Systems in User ...
 
File Systems: Why, How and Where
File Systems: Why, How and WhereFile Systems: Why, How and Where
File Systems: Why, How and Where
 
netfilter and iptables
netfilter and iptablesnetfilter and iptables
netfilter and iptables
 
KernelTLV Speaker Guidelines
KernelTLV Speaker GuidelinesKernelTLV Speaker Guidelines
KernelTLV Speaker Guidelines
 
Userfaultfd: Current Features, Limitations and Future Development
Userfaultfd: Current Features, Limitations and Future DevelopmentUserfaultfd: Current Features, Limitations and Future Development
Userfaultfd: Current Features, Limitations and Future Development
 
Linux Kernel Cryptographic API and Use Cases
Linux Kernel Cryptographic API and Use CasesLinux Kernel Cryptographic API and Use Cases
Linux Kernel Cryptographic API and Use Cases
 
FD.IO Vector Packet Processing
FD.IO Vector Packet ProcessingFD.IO Vector Packet Processing
FD.IO Vector Packet Processing
 
WiFi and the Beast
WiFi and the BeastWiFi and the Beast
WiFi and the Beast
 
Introduction to DPDK
Introduction to DPDKIntroduction to DPDK
Introduction to DPDK
 
FreeBSD and Drivers
FreeBSD and DriversFreeBSD and Drivers
FreeBSD and Drivers
 
Specializing the Data Path - Hooking into the Linux Network Stack
Specializing the Data Path - Hooking into the Linux Network StackSpecializing the Data Path - Hooking into the Linux Network Stack
Specializing the Data Path - Hooking into the Linux Network Stack
 

Recently uploaded

Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Anthony Dahanne
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
e20449
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 

Recently uploaded (20)

Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 

DMA Survival Guide

  • 2. Property of Tandem Group Whenwe’redone, it’sdone! Ramon Fried  Developer and hacker since 1983  B.sc in computer science  Expertise in Embedded systems and Linux system and kernel development.  Currently Embedded Linux Team Leader in TandemG
  • 3. Property of Tandem Group Whenwe’redone, it’sdone! TandemG  TandemG is Israel’s leading Software, Hardware and Systems R&D center, acting as a one-stop-shop for our range of partners, from prominent start-ups through to market leaders  In the embedded domain, TandemG tailors solutions spanning across RTOS, Embedded Linux, low-level Android and DSP.  For the second year in a row, TandemG has been selected to Delloite’s Israel Technology Fast50 list in the 23rd place  Visit us at www.tandemG.com, for additional details.
  • 4. Property of Tandem Group Whenwe’redone, it’sdone! Agenda  What is DMA  DMA Buffer allocation — Coherent — Streaming  Scatter Gather mapping  DMA pools  DMA Triggering — PCI — dmaengine
  • 5. Property of Tandem Group Whenwe’redone, it’sdone! What is DMA  Direct memory access  Feature of computer systems that allows certain hardware subsystems to access main system memory (RAM), independent of the central processing unit (CPU).  CPU can be notified on the end of operation by IRQ.
  • 6. Property of Tandem Group Whenwe’redone, it’sdone! What is DMA Photo from: http://encyclopedia2.thefreedictionary.com/DMA
  • 7. Property of Tandem Group Whenwe’redone, it’sdone! DMA Buffer allocation  DMA controller works on physical addresses  Physical memory needs to be accessible by DMA controller  Memory must be continuous
  • 8. Property of Tandem Group Whenwe’redone, it’sdone! DMA Buffer allocation  Coherent DMA mapping — Usually long lasting. — Can be accessed by both ends. — No-caching * — At least page sized.  Streaming DMA mapping — Usually singly used and freed. — Architecture/Platform optimized. — direction must be defined explicitly.
  • 9. Property of Tandem Group Whenwe’redone, it’sdone! DMA access mask #include <linux/dma-mapping.h> int dma_set_mask_and_coherent(struct device *dev, u64 mask); int dma_set_mask (struct device *dev, u64 mask); int dma_set_coherent_mask(struct device *dev, u64 mask);
  • 10. Property of Tandem Group Whenwe’redone, it’sdone! Coherent DMA mapping #include <linux/dma-mapping.h> void *dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle, gfp_t flag); void dma_free_coherent(struct device *dev, size_t size, void *cpu_addr, dma_addr_t dma_handle);
  • 11. Property of Tandem Group Whenwe’redone, it’sdone! Streaming DMA mapping #include <linux/dma-mapping.h> dma_addr_t dma_map_single(struct device *dev, void *ptr,size_t size, enum dma_data_direction dir); void dma_unmap_single(struct device *dev, dma_addr_t addr, size_t size, enum dma_data_direction dir);
  • 12. Property of Tandem Group Whenwe’redone, it’sdone! Streaming DMA mapping (cont’d)  enum dma_data_direction — DMA_TO_DEVICE — DMA_FROM_DEVICE — DMA_BIDIRECTIONAL
  • 13. Property of Tandem Group Whenwe’redone, it’sdone! Streaming DMA usage  Buffer Ownership — Buffer is owned by the device. — Altering the buffer can be done only after acquiring ownership  dma_sync_single_for_cpu() — After altering the buffer, the ownership needs to be returned to the device.  dma_sync_single_for_device()
  • 14. Property of Tandem Group Whenwe’redone, it’sdone! Scatter gather buffers  Special type of streaming DMA  writev, readv, clustered buffers (YUV plannar, non continuous memory, etc.)
  • 15. Property of Tandem Group Whenwe’redone, it’sdone! Scatter/Gather API #include linux/dma-mapping.h int dma_map_sg( struct device *dev, struct scatterlist *sg, int nents, enum dma_data_direction dir); void dma_unmap_sg(struct device *dev, struct scatterlist *list, int nents, enum dma_data_direction dir);
  • 16. Property of Tandem Group Whenwe’redone, it’sdone! Don’t forget to sync #include linux/dma-mapping.h void dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, int nelems, enum dma_data_direction dir); void dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, int nelems, enum dma_data_direction dir);
  • 17. Property of Tandem Group Whenwe’redone, it’sdone! DMA Pools  DMA Pools — Coherent — Used to allocate buffers smaller than a page. — dma_pool_create() — dma_pool_destroy() — dma_pool_alloc() — dma_pool_free()
  • 18. Property of Tandem Group Whenwe’redone, it’sdone! Start the DMA operation
  • 19. Property of Tandem Group Whenwe’redone, it’sdone! Triggering the DMA operation  PCI  dmaengine
  • 20. Property of Tandem Group Whenwe’redone, it’sdone! PCI Wrappers  PCI wrappers — pci_alloc_consistent() — pci_free_consistent() — pci_set_dma_mask() — pci_pool_create() — …
  • 21. Property of Tandem Group Whenwe’redone, it’sdone! PCI DMA transaction example dma_addr_t bus_addr; bus_addr = dma_map_single(&dev->pci_dev->dev, buffer, count, DMA_TO_DEVICE); writeb(dev->registers.command, DAD_CMD_DISABLEDMA); writeb(dev->registers.command, DAD_CMD_WR); writel(dev->registers.addr, cpu_to_le32(bus_addr)); writel(dev->registers.len, cpu_to_le32(count)); writeb(dev->registers.command, DAD_CMD_ENABLEDMA);
  • 22. Property of Tandem Group Whenwe’redone, it’sdone! DMA Engine  Subsystem to handle memory-to-device transfers  Exists since 2.6.18 (2006)  Code in “drivers/dma”  Documentation in “dmaengine/*”  Poorly documented

Editor's Notes

  1. DMA Controller work with physical memory. It doesn’t understands CPU’s virtual. It can access only the physical memory that is actually connected to it in the interconnect,. This memory is called bus addresses and usually is the same as CPU’s physical memory. ----- Virtual memory is not always continuous. The underling physical memory must be continuous. Basically kmalloc returns continuous, vmalloc not.
  2. Coherent examples: ring buffers, messages queues, mailboxes, etc. However, Reordering can occur. * We’ll see soon a way of allocating smaller chunks. Streaming examples: file systems buffers, network buffers
  3. Returns 0 on fail. Dma_handle is output param
  4. The buffer is given in ptr. Mapping can fail of course. Check return value using: dma_mapping_error()