2

我正在将使用 IOKit 编写的 MacOS PCI 驱动程序移植到新的 PCIDriverKit 框架中。

我能够使用在 dext 内分配的连续缓冲区(使用IOBufferMemoryDescriptor::Create)执行 DMA。

但我也想对应用程序分配的缓冲区执行 DMA。

我真正想做的是:

  • 在应用程序中分配一个对齐的缓冲区(例如posix_memalign
  • 将指向此缓冲区的指针发送到 dext
  • 在 dext 中,检索页面描述符列表,以便能够在不复制到(或从)该缓冲区的情况下执行 DMA。

在 IOKit 中,我们可以使用 和 等方法IOMemoryDescriptor::withAddressRangeIODMACommand::gen64IOVMSegments映射和检索分散聚集列表,但我无法在 PCIDriverKit 框架的 dext 中找到有关如何执行此操作的任何信息。

任何人都可以帮助我如何做到这一点?

4

1 回答 1

1

It's not quite the same question as yours, but in my answer to it I go into some detail on memory descriptors in DriverKit extensions.

Basically, in DriverKit you can only access user space memory that was explicitly provided as a buffer; you can't interpret arbitrary data as pointers in the user process's address space and create memory descriptors for them.

The only way to create memory descriptors for user space buffers that I'm aware of is via "struct" arguments to IOUserClient external methods, i.e. when the user process passes them to the IOConnectCallMethod* family of functions as either an input or output "struct". If the buffer is larger than 4096 bytes, it'll show up in the dext as an IOMemoryDescriptor, and you can perform the usual DMA operations with it.

Typically, you'll want to do this in combination with async external methods, which lets you implement sensible buffer lifetime semantics, but your dext can technically hold on to user space supplied memory descriptors past the return of a synchronous external method, or past the async completion of an asynchronous one.

于 2022-01-06T22:04:24.590 回答