Skip to content

Commit 22d2c7a

Browse files
LuBaolujoergroedel
authored andcommitted
iommu: Add max_pasids field in struct dev_iommu
Use this field to save the number of PASIDs that a device is able to consume. It is a generic attribute of a device and lifting it into the per-device dev_iommu struct could help to avoid the boilerplate code in various IOMMU drivers. Signed-off-by: Lu Baolu <[email protected]> Reviewed-by: Kevin Tian <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Reviewed-by: Yi Liu <[email protected]> Tested-by: Zhangfei Gao <[email protected]> Tested-by: Tony Zhu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 1adf3cc commit 22d2c7a

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

drivers/iommu/iommu.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/idr.h>
2222
#include <linux/err.h>
2323
#include <linux/pci.h>
24+
#include <linux/pci-ats.h>
2425
#include <linux/bitops.h>
2526
#include <linux/platform_device.h>
2627
#include <linux/property.h>
@@ -278,6 +279,24 @@ static void dev_iommu_free(struct device *dev)
278279
kfree(param);
279280
}
280281

282+
static u32 dev_iommu_get_max_pasids(struct device *dev)
283+
{
284+
u32 max_pasids = 0, bits = 0;
285+
int ret;
286+
287+
if (dev_is_pci(dev)) {
288+
ret = pci_max_pasids(to_pci_dev(dev));
289+
if (ret > 0)
290+
max_pasids = ret;
291+
} else {
292+
ret = device_property_read_u32(dev, "pasid-num-bits", &bits);
293+
if (!ret)
294+
max_pasids = 1UL << bits;
295+
}
296+
297+
return min_t(u32, max_pasids, dev->iommu->iommu_dev->max_pasids);
298+
}
299+
281300
static int __iommu_probe_device(struct device *dev, struct list_head *group_list)
282301
{
283302
const struct iommu_ops *ops = dev->bus->iommu_ops;
@@ -303,6 +322,7 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list
303322
}
304323

305324
dev->iommu->iommu_dev = iommu_dev;
325+
dev->iommu->max_pasids = dev_iommu_get_max_pasids(dev);
306326

307327
group = iommu_group_get_for_dev(dev);
308328
if (IS_ERR(group)) {

include/linux/iommu.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ struct iommu_fault_param {
368368
* @fwspec: IOMMU fwspec data
369369
* @iommu_dev: IOMMU device this device is linked to
370370
* @priv: IOMMU Driver private data
371+
* @max_pasids: number of PASIDs this device can consume
371372
*
372373
* TODO: migrate other per device data pointers under iommu_dev_data, e.g.
373374
* struct iommu_group *iommu_group;
@@ -379,6 +380,7 @@ struct dev_iommu {
379380
struct iommu_fwspec *fwspec;
380381
struct iommu_device *iommu_dev;
381382
void *priv;
383+
u32 max_pasids;
382384
};
383385

384386
int iommu_device_register(struct iommu_device *iommu,

0 commit comments

Comments
 (0)