Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

amd_iommu: Support IOMMU groups

Add IOMMU group support to AMD-Vi device init and uninit code.
Existing notifiers make sure this gets called for each device.

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>

authored by

Alex Williamson and committed by
Joerg Roedel
9dcd6130 d72e31c9

+23 -1
+23 -1
drivers/iommu/amd_iommu.c
··· 256 256 257 257 static int iommu_init_device(struct device *dev) 258 258 { 259 - struct pci_dev *pdev = to_pci_dev(dev); 259 + struct pci_dev *dma_pdev, *pdev = to_pci_dev(dev); 260 260 struct iommu_dev_data *dev_data; 261 + struct iommu_group *group; 261 262 u16 alias; 263 + int ret; 262 264 263 265 if (dev->archdata.iommu) 264 266 return 0; ··· 281 279 return -ENOTSUPP; 282 280 } 283 281 dev_data->alias_data = alias_data; 282 + 283 + dma_pdev = pci_get_bus_and_slot(alias >> 8, alias & 0xff); 284 + } else 285 + dma_pdev = pci_dev_get(pdev); 286 + 287 + group = iommu_group_get(&dma_pdev->dev); 288 + pci_dev_put(dma_pdev); 289 + if (!group) { 290 + group = iommu_group_alloc(); 291 + if (IS_ERR(group)) 292 + return PTR_ERR(group); 284 293 } 294 + 295 + ret = iommu_group_add_device(group, dev); 296 + 297 + iommu_group_put(group); 298 + 299 + if (ret) 300 + return ret; 285 301 286 302 if (pci_iommuv2_capable(pdev)) { 287 303 struct amd_iommu *iommu; ··· 329 309 330 310 static void iommu_uninit_device(struct device *dev) 331 311 { 312 + iommu_group_remove_device(dev); 313 + 332 314 /* 333 315 * Nothing to do here - we keep dev_data around for unplugged devices 334 316 * and reuse it when the device is re-plugged - not doing so would