SlideShare uma empresa Scribd logo
1 de 23
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!

Mais conteúdo relacionado

Mais procurados

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 NLKBshimosawa
 
Kvm and libvirt
Kvm and libvirtKvm and libvirt
Kvm and libvirtplarsen67
 
Performance Wins with eBPF: Getting Started (2021)
Performance Wins with eBPF: Getting Started (2021)Performance Wins with eBPF: Getting Started (2021)
Performance Wins with eBPF: Getting Started (2021)Brendan Gregg
 
Linux MMAP & Ioremap introduction
Linux MMAP & Ioremap introductionLinux MMAP & Ioremap introduction
Linux MMAP & Ioremap introductionGene Chang
 
Prerequisite knowledge for shared memory concurrency
Prerequisite knowledge for shared memory concurrencyPrerequisite knowledge for shared memory concurrency
Prerequisite knowledge for shared memory concurrencyViller Hsiao
 
QEMU - Binary Translation
QEMU - Binary Translation QEMU - Binary Translation
QEMU - Binary Translation Jiann-Fuh Liaw
 
malloc & vmalloc in Linux
malloc & vmalloc in Linuxmalloc & vmalloc in Linux
malloc & vmalloc in LinuxAdrian Huang
 
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 KernelAdrian Huang
 
Launch the First Process in Linux System
Launch the First Process in Linux SystemLaunch the First Process in Linux System
Launch the First Process in Linux SystemJian-Hong Pan
 
Understanding of linux kernel memory model
Understanding of linux kernel memory modelUnderstanding of linux kernel memory model
Understanding of linux kernel memory modelSeongJae Park
 
Kernel Recipes 2015: Linux Kernel IO subsystem - How it works and how can I s...
Kernel Recipes 2015: Linux Kernel IO subsystem - How it works and how can I s...Kernel Recipes 2015: Linux Kernel IO subsystem - How it works and how can I s...
Kernel Recipes 2015: Linux Kernel IO subsystem - How it works and how can I s...Anne Nicolas
 

Mais procurados (20)

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
 
Kvm and libvirt
Kvm and libvirtKvm and libvirt
Kvm and libvirt
 
Performance Wins with eBPF: Getting Started (2021)
Performance Wins with eBPF: Getting Started (2021)Performance Wins with eBPF: Getting Started (2021)
Performance Wins with eBPF: Getting Started (2021)
 
Basic Linux Internals
Basic Linux InternalsBasic Linux Internals
Basic Linux Internals
 
Embedded Linux on ARM
Embedded Linux on ARMEmbedded Linux on ARM
Embedded Linux on ARM
 
Embedded Android : System Development - Part II (Linux device drivers)
Embedded Android : System Development - Part II (Linux device drivers)Embedded Android : System Development - Part II (Linux device drivers)
Embedded Android : System Development - Part II (Linux device drivers)
 
Linux MMAP & Ioremap introduction
Linux MMAP & Ioremap introductionLinux MMAP & Ioremap introduction
Linux MMAP & Ioremap introduction
 
Embedded linux network device driver development
Embedded linux network device driver developmentEmbedded linux network device driver development
Embedded linux network device driver development
 
eBPF/XDP
eBPF/XDP eBPF/XDP
eBPF/XDP
 
Prerequisite knowledge for shared memory concurrency
Prerequisite knowledge for shared memory concurrencyPrerequisite knowledge for shared memory concurrency
Prerequisite knowledge for shared memory concurrency
 
QEMU - Binary Translation
QEMU - Binary Translation QEMU - Binary Translation
QEMU - Binary Translation
 
malloc & vmalloc in Linux
malloc & vmalloc in Linuxmalloc & vmalloc in Linux
malloc & vmalloc in Linux
 
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
 
Launch the First Process in Linux System
Launch the First Process in Linux SystemLaunch the First Process in Linux System
Launch the First Process in Linux System
 
eBPF maps 101
eBPF maps 101eBPF maps 101
eBPF maps 101
 
Understanding of linux kernel memory model
Understanding of linux kernel memory modelUnderstanding of linux kernel memory model
Understanding of linux kernel memory model
 
Kernel Recipes 2015: Linux Kernel IO subsystem - How it works and how can I s...
Kernel Recipes 2015: Linux Kernel IO subsystem - How it works and how can I s...Kernel Recipes 2015: Linux Kernel IO subsystem - How it works and how can I s...
Kernel Recipes 2015: Linux Kernel IO subsystem - How it works and how can I s...
 
Linux dma engine
Linux dma engineLinux dma engine
Linux dma engine
 
Linux Internals - Part I
Linux Internals - Part ILinux Internals - Part I
Linux Internals - Part I
 
Ixgbe internals
Ixgbe internalsIxgbe internals
Ixgbe internals
 

Semelhante a 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-treeAlison 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, LINBITOpenNebula Project
 
Droidcon London 2021 - Full Stack Dart
Droidcon London 2021   - Full Stack DartDroidcon London 2021   - Full Stack Dart
Droidcon London 2021 - Full Stack DartChris Swan
 
Data compression in Modern Application
Data compression in Modern ApplicationData compression in Modern Application
Data compression in Modern ApplicationLivePerson
 
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
 
Managed DirectX
Managed DirectXManaged DirectX
Managed DirectXA. LE
 
Monitoring MySQL with DTrace/SystemTap
Monitoring MySQL with DTrace/SystemTapMonitoring MySQL with DTrace/SystemTap
Monitoring MySQL with DTrace/SystemTapPadraig 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
 
DevOpSec_DockerNPodMan-20230220.pdf
DevOpSec_DockerNPodMan-20230220.pdfDevOpSec_DockerNPodMan-20230220.pdf
DevOpSec_DockerNPodMan-20230220.pdfkanedafromparis
 
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.pdfBharathChannappa1
 

Semelhante a 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
 

Mais de Kernel TLV

Building Network Functions with eBPF & BCC
Building Network Functions with eBPF & BCCBuilding Network Functions with eBPF & BCC
Building Network Functions with eBPF & BCCKernel TLV
 
SGX Trusted Execution Environment
SGX Trusted Execution EnvironmentSGX Trusted Execution Environment
SGX Trusted Execution EnvironmentKernel TLV
 
Kernel Proc Connector and Containers
Kernel Proc Connector and ContainersKernel Proc Connector and Containers
Kernel Proc Connector and ContainersKernel TLV
 
Bypassing ASLR Exploiting CVE 2015-7545
Bypassing ASLR Exploiting CVE 2015-7545Bypassing ASLR Exploiting CVE 2015-7545
Bypassing ASLR Exploiting CVE 2015-7545Kernel TLV
 
Present Absence of Linux Filesystem Security
Present Absence of Linux Filesystem SecurityPresent Absence of Linux Filesystem Security
Present Absence of Linux Filesystem SecurityKernel TLV
 
OpenWrt From Top to Bottom
OpenWrt From Top to BottomOpenWrt From Top to Bottom
OpenWrt From Top to BottomKernel 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 ToolsKernel 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 WhereKernel TLV
 
netfilter and iptables
netfilter and iptablesnetfilter and iptables
netfilter and iptablesKernel TLV
 
KernelTLV Speaker Guidelines
KernelTLV Speaker GuidelinesKernelTLV Speaker Guidelines
KernelTLV Speaker GuidelinesKernel 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 DevelopmentKernel TLV
 
The Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast StorageThe Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast StorageKernel 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 CasesKernel TLV
 
FD.IO Vector Packet Processing
FD.IO Vector Packet ProcessingFD.IO Vector Packet Processing
FD.IO Vector Packet ProcessingKernel TLV
 
WiFi and the Beast
WiFi and the BeastWiFi and the Beast
WiFi and the BeastKernel TLV
 
Introduction to DPDK
Introduction to DPDKIntroduction to DPDK
Introduction to DPDKKernel TLV
 
FreeBSD and Drivers
FreeBSD and DriversFreeBSD and Drivers
FreeBSD and DriversKernel TLV
 

Mais de 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
 
The Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast StorageThe Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast Storage
 
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
 

Último

WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
tonesoftg
tonesoftgtonesoftg
tonesoftglanshi9
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxAnnaArtyushina1
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benonimasabamasaba
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 

Último (20)

WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 

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

Notas do Editor

  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()