I am porting a MacOS PCI driver written with IOKit to the new PCIDriverKit framework.
I am able to perform DMA with a contiguous buffer allocated inside the dext (with IOBufferMemoryDescriptor::Create
).
But I would also like to perform DMA to and from a buffer allocated by an application.
What I exactly want to do is:
posix_memalign
)In IOKit, we could use methods such IOMemoryDescriptor::withAddressRange
and IODMACommand::gen64IOVMSegments
to map and retrieve the scatter gather list but I cannot find any information on how to do this in a dext with the PCIDriverKit framework.
Can anybody help me on how to do that?
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.