如何在 pci 设备读取 linux 内核中的内存之前刷新内存

How to flush memory before a pci device reads memory in linux kernel

我有一个 pci 设备读取由 dma_alloc_coherent

分配的内存

内核文档中说: "You may however need to make sure to flush the processor's write buffers before telling devices to read that memory"

我该怎么做?我如何刷新内存以便设备读取正确的数据?

使用 wmb() 确保在写入设备并告诉它启动 DMA 之前完成所有内存写入。