I'm adding IOMMU support in my linux driver and notice the IOMMU groups are assigned to the device during boot:
[ 0.942274] iommu: Adding device 0000:03:00.0 to group 28
Although, when I try to iommu_attach_device()
inside the driver, it fails. I found it's failing when it calls iommu_group_get()
for my device.
How do I get the assigned group for my device and use it inside my driver?
I'm using Ubuntu 4.15.0-45-generic kernel.
Edit:
iommu_group_get()
fails when struct device
field iommu_group
is not initialized. Also, I'm manually loading the driver after boot.
Edit2: I do see the device added to group 28 in dmesg output. I've the following sequence in my driver probe routine which I got by referring to existing kernel driver sources:
if iommu_present()
iommu_domain_alloc(&pci_bus_type)
iommu_set_fault_handler()
group = iommu_group_get();
// added group check since iommu_attach_device is failing
// group is NULL, was expecting group_28
iommu_attach_device()
init_iova_domain()
I've IOCTL calls for pinning the userspace virtual address (get_user_pages_fast
) and performing iommu_map
. Is this valid for enabling DMA to the device using userspace region?