search
HomeComputer TutorialsTroubleshootingIs there any source code for DMA Windows driver?

dma windows驱动源码吗?

The related operations of DMA are introduced on page 545 of "In-depth Understanding of the Linux Kernel". When talking about DMA, we have to mention the issue of Cache. The book cites the following example to describe the Cache consistency problem:

Assume that the device driver fills some data into the memory buffer, and then immediately instructs the hardware device to read the data using DMA transfer. If DMA accesses these physical RAM memory cells, and the contents of the corresponding hardware cache line have not yet been written to RAM, then the hardware device will only read the old value in the memory buffer.

There are now two ways to deal with DMA buffers:

Consistent DMA mapping:

The book is more abstract, and the popular term is any DMA buffer Any changes to the area will be directly updated into the memory, which is also called synchronized or consistent.

Streaming DMA mapping:

According to personal understanding, the stream here is the input and output stream. We need to specify the direction of the DMA buffer in advance, such as reading the buffer or writing. buffer zone. It is also called asynchronous or non-consistent. Please see below for details.

Because in the x86 architecture, the hardware device driver itself will snoop the accessed hardware cache, so there is no DMA consistency problem in the x86 architecture. For other architectures such as MIPS, SPARC and POWERPC (including ARM), it is necessary to ensure their DMA consistency in software.

Regarding how to choose between the above two, there is a suitable suggestion in the book. If the CPU and DMA processor access a buffer in an unpredictable way, then the consistent DMA mapping method must be forced to be used (here I Unpredictable (understood as not being able to determine when they will access the buffer). In other cases, a streaming DMA mapping approach is preferable because dealing with consistent DMA mapping is cumbersome on some architectures and can lead to more Low system performance.

Here is a detailed introduction to streaming DMA:

The buffer that needs to be accessed needs to be mapped before data transmission (the mapping here means that some functions need to be called to inform the kernel that the buffer is streamed mapped), which is unmapped after transfer.

Starting a streaming DMA data transfer is divided into the following steps:

1. Allocate a DMA buffer.

When the DMA device does not use S/G (scatter/gather) mode, it must be ensured that the buffer is physically continuous. The Linux kernel has two functions for allocating continuous memory: kmalloc() and __get_free_pages(). Both functions have the maximum value for allocating continuous memory. kmalloc allocates bytes as a unit, the maximum is about 64KB, __get_free_pages() allocates pages as a unit, and can allocate a maximum of 2^order number of pages. The maximum value of the order parameter Determined by the MAX_ORDER macro in the include/linux/Mmzone.h file (in the default 2.6.18 kernel version, this macro is defined as 10. That is to say, in theory, the __get_free_pages function can apply for up to 1

## at a time #2. Establish streaming mapping.

After reading and writing access to the DMA buffer, and before starting the DMA device transfer, enable the dma_map_single() function to establish a streaming DMA mapping. These two functions accept buffers The linear address of the area is used as its parameter and the corresponding bus address is returned.

3. Release the streaming mapping.

When the DMA transfer is completed, we need to release the mapping, then call dma_unmap_single() Function.

Note:

(1). To avoid cache coherency issues, the driver should call dma_sync_single_for_device(() if necessary before starting a DMA data transfer from RAM to the device ) function refreshes the cache line corresponding to the DMA buffer.

(2). The device driver cannot access the memory buffer before a DMA data transfer from the device to RAM is completed, but if necessary If so, the driver should call the dma_sync_single_for_cpu() function to invalidate the corresponding hardware cache line before reading the buffer.

(3). Although the bottom layer of kmalloc is also implemented using __get_free_pages, the corresponding release buffer of kmalloc The area function is kfree, and the release buffer function corresponding to __get_free_pages is free_pages. Several application and release functions specifically related to __get_free_pages are as follows:

Application function:

alloc_pages(gfp_mask ,order) returns the address of the first allocated page frame descriptor, or NULL if the allocation failed. __get_free_pages(gfp_mask,order) is similar to alloc_pages(), but it returns the linear address of the first allocated page. If If you need to obtain the page frame number corresponding to the linear address, you need to call the virt_to_page(addr) macro to generate the linear address. Release function: __free_pages(page, order) The main emphasis here is that page is the page frame number free_pages where the linear first address of the buffer is to be released. (page, order) This function is similar to __free_pages(page, order), but the parameter it receives is the linear address addr

of the first page frame to be released.

The above is the detailed content of Is there any source code for DMA Windows driver?. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:系统之家重装系统. If there is any infringement, please contact admin@php.cn delete
Black Boxes on Desktop Icons: Find Powerful Tips to RemoveBlack Boxes on Desktop Icons: Find Powerful Tips to RemoveMay 12, 2025 pm 08:07 PM

Encountering black squares instead of desktop icons in Windows 11/10? This comprehensive guide offers several straightforward solutions to restore your icons to their original appearance. Quick Navigation: Black Squares on Desktop Icons Solution 1:

CapCut Project File Location: How to Find, Recover, and ShareCapCut Project File Location: How to Find, Recover, and ShareMay 12, 2025 pm 08:06 PM

This MiniTool guide offers a complete walkthrough for managing CapCut projects, covering location, recovery, and sharing. Mastering these steps ensures efficient project handling. Quick Navigation: CapCut Project File Location on PC Backing Up CapC

Persistent Fake Virus Alerts in Edge: How to Identify & AvoidPersistent Fake Virus Alerts in Edge: How to Identify & AvoidMay 12, 2025 pm 08:05 PM

Edge browser fake virus warning: a guide to identifying, handling and prevention Many users report encountering fake virus warnings in Microsoft Edge browser. These warnings usually appear in the form of pop-ups, claiming that malware or viruses are detected, attempting to induce users to download malware or take harmful actions. This article will guide you on how to identify, deal with, and prevent such false warnings. How to identify fake virus warnings in Edge browser? False virus warnings usually have the following characteristics: Use emergency and panic language: Try to force users to act by creating panic. Use fake company logos: Imitate the logo of well-known security software or Microsoft. Regular companies will not issue warnings in this way. Request to dial

Effective Ways to Fix EVERSPACE 2 Crashing/Not LaunchingEffective Ways to Fix EVERSPACE 2 Crashing/Not LaunchingMay 12, 2025 pm 08:03 PM

EVERSPACE 2 Crash Problem and Solutions Have you encountered a crash problem while playing EVERSPACE 2? If this problem bothers you, this MiniTool article will help you. This article will explain common causes and effective solutions to EVERSPACE 2 crashes. Quick navigation: EVERSPACE 2 Startup Crash How to fix EVERSPACE 2 crash Summarize EVERSPACE 2 Startup Crash The EVERSPACE 2 crash problem has always been the focus of players. Many players have reported different types of crashes, including crashes at startup, sudden exits during the game, and interactions with Unreal Engine

Apex Integrity Error 0x8000001: 3 Useful Methods HereApex Integrity Error 0x8000001: 3 Useful Methods HereMay 12, 2025 pm 08:02 PM

Encountering the Apex Legends integrity error 0x8000001, causing game crashes? This guide provides effective solutions. Let's explore the fixes. Apex Integrity Error 0x8000001: A Crashing Problem Many Apex Legends players report encountering the &quo

How to fix Windows activation error 0x803FABC3?How to fix Windows activation error 0x803FABC3?May 12, 2025 pm 06:00 PM

Windows activation is a critical process in Windows 11 that verifies your operating system copy is genuine, enabling full functionality like personalization fea

How to Use Copilot in Microsoft OneDrive? Everything You NeedHow to Use Copilot in Microsoft OneDrive? Everything You NeedMay 11, 2025 pm 08:02 PM

Unlock the Power of Microsoft OneDrive Copilot: Your AI-Powered File Assistant This MiniTool guide unveils the capabilities of Copilot in OneDrive, a revolutionary AI assistant designed to streamline your file management and boost productivity. Expl

A Guide to Fix A Supported Game Is Required to Use This FeatureA Guide to Fix A Supported Game Is Required to Use This FeatureMay 11, 2025 pm 08:01 PM

Troubleshooting the NVIDIA GeForce Experience "Supported Game Required" Error Encountering the "A supported game is required to use this feature" error in NVIDIA GeForce Experience while using game filters, screen recording, or ad

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.