当前位置:网站首页>Copy mode DMA
Copy mode DMA
2022-07-05 16:53:00 【Four seasons sail】
1. DMA Principle and implementation of
DMA The principle is CPU Tell DMA, Include source address , The destination address and the length to be migrated , Then start DMA equipment ,DMA After the device receives the command , Just complete the corresponding operation , Finally, give feedback to the boss through interruption CPU, end .
In the realization of DMA When transmitting , yes DMA The controller controls the bus , in other words , There will be a problem of transfer of control , Of course we do , The largest in the computer BOSS Namely CPU, This DMA The bus control temporarily in charge is also CPU Given to , stay DMA After transmission , Will be notified by interruption CPU Take back control of the bus .
2. DMA Transmission process
A complete DMA The transmission process has to go through DMA request 、DMA Respond to 、DMA transmission 、DMA End these four stages .
DMA request :CPU Yes DMA Controller initialization , And to I/O Interface sends operation commands ,I/O Interface proposal DMA request
DMA Respond to :DMA The controller is right DMA Request discrimination priority and mask bit , Make a bus request to the bus arbitration logic , When CPU After the current bus cycle is completed, the bus control can be released . here , Bus arbitration logic outputs bus response , Express DMA Already in place , adopt DMA Controller notification I/O Interface start DMA transmission .
DMA transmission : stay DMA Under the guidance of the controller , Data transfer between memory and peripherals , There is no need to CPU Participation
DMA end : When the given operation is completed ,DMA The controller releases bus control , And to I/O The interface sends an end signal , When I/O After the interface receives the end signal , On the one hand, stop I/O The work of the equipment , On the other hand CPU Make an interrupt request , send CPU Never intervene in the state of liberation , And perform a period of inspection DMA Code for the correctness of transmission operation . Finally, continue to execute the original program with the result and status of this operation .
Peripherals can be used DMA Move data . Such as MMC, When it receives data , Will store the data in its own register , Either through CPU Loop through the registers to get these data ( Take up at this time CPU Time ); You can also use DMA Move the data of register to memory , When a certain amount is moved , notice CPU, then CPU Then read it from memory at one time (DMA In the process of moving ,CPU You can do other things ).
DMA Working hours , from DMA The controller sends address and control signals to memory , Make address changes , Make statistics on the transmitted data , And notify in the form of interruption CPU Data transmission completed .
3. DMA Resulting problems
DMA It will not only improve efficiency , Again , It also brings some problems , The most obvious problem is cache consistency . Imagine , modern CPU They all have their own L1 cache 、 L2 cache or even L3 cache , When CPU When accessing an address in memory , For now, write the new value into the cache , But the data in external memory is not updated , Suppose this happens DMA What is requested and operated is the memory address that is updated in the cache but not updated in the external memory , such DMA What you read is the non latest data ; same , If the external device passes DMA Write the new value to memory , however CPU Access the data in the actual cache , This will also result in not getting the latest data .
In order to do it correctly DMA operation , Necessary Cache operation ,Cache The operation of is mainly divided into invalidate( To void ) and writeback( Write back ), Sometimes they are used together . If DMA Used Cache, that Cache Consistency must be considered , The simplest solution is to prohibit DMA Of the target address range Cache function , But this will sacrifice some performance . therefore , stay DMA Whether to use cache On the issue of , According to DMA The expected retention time of the buffer is determined .DMA Be divided into : Uniformity DMA Mapping and streaming DMA mapping .
4. Solve cache consistency
Uniformity DMA , Because it adopts a section reserved by the system DMA Memory is used for DMA operation , This section of kernel has been reserved in the system startup stage , stay DMA In the process of memory application , You can directly disable this section of the memory reserved cache . Start with a ioremap_nocache Mapping , And then call the function. dma_cache_wback_inv Ensure that the cache has been flushed in place , When this memory is used later, there is no L2 cache ;
streaming DMA , Cache cannot be directly disabled , Because streaming DMA You can use any address range in the system ,CPU Never disable caching of all address spaces in the system , This is not scientific. , In order to achieve cache consistency , streaming DMA The cache needs to be invalidated constantly , tell CPU This cache is not trusted , It must be retrieved from memory . Uniformity DMA That is to disable the cache directly , And flow DMA Is to refresh the cache invalidation .
5. DMA channels
One DMA controller Can be done at the same time DMA The number of transmissions is limited , This is called DMA channels. It's just a logical concept , Because in view of the conflict of bus access , And memory consistency considerations , these Channels It is impossible to really work in parallel , Only time-sharing multiplexing ,DMA The controller acts as an arbiter . Since it is time-sharing multiplexing , Then we can also be based on a certain physics Channel, Abstract out multiple virtual Channel, The software is responsible for arbitration , To decide which virtual at a certain moment Channel To use physics Channel.
6. DMA request line
DMA Transmission is made by CPU Sponsored :CPU tell DMA controller , Help will xxx Local data moved to xxx place .CPU After giving the order , Just do something else . and DMA controller , Besides being responsible for how to move , Also decide when to start data handling .
because CPU launch DMA During transmission , I don't know whether the current transmission conditions are available , for example source Whether the equipment has data 、dest The equipment FIFO Are you free... Etc . Only the device knows when to start transmission , Therefore need DMA Transmission equipment and DMA Between controllers , There will be several physical connections ( namely DMA request,DRQ), Used to inform DMA The controller can start transmission .
7. To write DMA The general steps of equipment driving are as follows
/* 1. apply DMA passageway */
struct dma_chan *dma_request_channel(dma_cap_mask_t mask, dma_filter_fn filter_fn, void *filter_param);
/* 2. DMA Channel configuration , Can pass config Structure settings DMA The width of the passage 、 Data transmission broadband 、 Source address, destination address and other information . */
int dmaengine_slave_config(struct dma_chan *chan, struct dma_slave_config *config);
/* 3. Get the transport descriptor */
adopt device_prep_slave_sg() perhaps device_prep_dma_cyclic() perhaps device_prep_dma_memcpy() obtain desc, Then pass the callback function pointer to desc->callback
/* 4. Submit transmission */
call dmaengine_submit((struct dma_async_tx_descriptor *)desc), take desc Submitted to the DMA Waiting in line
/* 5. Start transmission */
dmaengine_issue_pending The call starts with the first descriptor . If DMA If the device driver has a callback function , It will be executed after the transmission is completed .
8. DMA framework
stay drivers/dma Under the table of contents , There is one dmaengine.c file , The document is DMA The core of the framework , Provide registration down DMA host driver The interface of (dma_async_device_register), Provide operations up DMA The interface of ( apply DMA passageway 、 Start transmission, etc ).
边栏推荐
- [deep learning] how does deep learning affect operations research?
- Spring Festival Limited "forget trouble in the year of the ox" gift bag waiting for you to pick it up~
- Sentinel-流量防卫兵
- [es6] 模板字符串内添加if判断或添加三元运算符判断
- [729. My Schedule i]
- 【729. 我的日程安排表 I】
- Single merchant v4.4 has the same original intention and strength!
- Learnopongl notes (I)
- 【机器人坐标系第一讲】
- Get ready for the pre-season card game MotoGP ignition champions!
猜你喜欢
Pspnet | semantic segmentation and scene analysis
Single merchant v4.4 has the same original intention and strength!
Learnopongl notes (II) - Lighting
SQL injection of cisp-pte (Application of secondary injection)
【刷題篇】鹅廠文化衫問題
WSL2.0安装
File operation --i/o
If you can't afford a real cat, you can use code to suck cats -unity particles to draw cats
[729. My schedule I]
Android privacy sandbox developer preview 3: privacy, security and personalized experience
随机推荐
Accès aux données - intégration du cadre d'entité
Google Earth engine (GEE) -- a brief introduction to kernel kernel functions and gray level co-occurrence matrix
You should have your own persistence
DeSci:去中心化科学是Web3.0的新趋势?
Iphone14 with pill screen may trigger a rush for Chinese consumers
Pspnet | semantic segmentation and scene analysis
外盘期货平台如何辨别正规安全?
WSL2.0安装
[echart] resize lodash to realize chart adaptation when window is zoomed
scratch五彩糖葫芦 电子学会图形化编程scratch等级考试三级真题和答案解析2022年6月
中间表是如何被消灭的?
C# TCP如何限制单个客户端的访问流量
[deep learning] [original] let yolov6-0.1.0 support the txt reading dataset mode of yolov5
What is the difference between EDI license and ICP business license
[61dctf]fm
Oneforall installation and use
Google Earth Engine(GEE)——Kernel核函数简单介绍以及灰度共生矩阵
Android privacy sandbox developer preview 3: privacy, security and personalized experience
How was the middle table destroyed?
普洛斯数据中心发布DC Brain系统,科技赋能智慧化运营管理