Skip to content

Commit 5524339

Browse files
yiliu1765jgunthorpe
authored andcommitted
iommu/vt-d: Implement hw_info for iommu capability query
Add intel_iommu_hw_info() to report cap_reg and ecap_reg information. Link: https://lore.kernel.org/r/20230818101033.4100-6-yi.l.liu@intel.com Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com> Acked-by: Lu Baolu <baolu.lu@linux.intel.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Signed-off-by: Nicolin Chen <nicolinc@nvidia.com> Signed-off-by: Yi Liu <yi.l.liu@intel.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent af4fde9 commit 5524339

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

drivers/iommu/intel/iommu.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <linux/spinlock.h>
2323
#include <linux/syscore_ops.h>
2424
#include <linux/tboot.h>
25+
#include <uapi/linux/iommufd.h>
2526

2627
#include "iommu.h"
2728
#include "../dma-iommu.h"
@@ -4732,8 +4733,26 @@ static void intel_iommu_remove_dev_pasid(struct device *dev, ioasid_t pasid)
47324733
intel_pasid_tear_down_entry(iommu, dev, pasid, false);
47334734
}
47344735

4736+
static void *intel_iommu_hw_info(struct device *dev, u32 *length, u32 *type)
4737+
{
4738+
struct device_domain_info *info = dev_iommu_priv_get(dev);
4739+
struct intel_iommu *iommu = info->iommu;
4740+
struct iommu_hw_info_vtd *vtd;
4741+
4742+
vtd = kzalloc(sizeof(*vtd), GFP_KERNEL);
4743+
if (!vtd)
4744+
return ERR_PTR(-ENOMEM);
4745+
4746+
vtd->cap_reg = iommu->cap;
4747+
vtd->ecap_reg = iommu->ecap;
4748+
*length = sizeof(*vtd);
4749+
*type = IOMMU_HW_INFO_TYPE_INTEL_VTD;
4750+
return vtd;
4751+
}
4752+
47354753
const struct iommu_ops intel_iommu_ops = {
47364754
.capable = intel_iommu_capable,
4755+
.hw_info = intel_iommu_hw_info,
47374756
.domain_alloc = intel_iommu_domain_alloc,
47384757
.probe_device = intel_iommu_probe_device,
47394758
.probe_finalize = intel_iommu_probe_finalize,

include/uapi/linux/iommufd.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,13 +372,36 @@ struct iommu_hwpt_alloc {
372372
};
373373
#define IOMMU_HWPT_ALLOC _IO(IOMMUFD_TYPE, IOMMUFD_CMD_HWPT_ALLOC)
374374

375+
/**
376+
* struct iommu_hw_info_vtd - Intel VT-d hardware information
377+
*
378+
* @flags: Must be 0
379+
* @__reserved: Must be 0
380+
*
381+
* @cap_reg: Value of Intel VT-d capability register defined in VT-d spec
382+
* section 11.4.2 Capability Register.
383+
* @ecap_reg: Value of Intel VT-d capability register defined in VT-d spec
384+
* section 11.4.3 Extended Capability Register.
385+
*
386+
* User needs to understand the Intel VT-d specification to decode the
387+
* register value.
388+
*/
389+
struct iommu_hw_info_vtd {
390+
__u32 flags;
391+
__u32 __reserved;
392+
__aligned_u64 cap_reg;
393+
__aligned_u64 ecap_reg;
394+
};
395+
375396
/**
376397
* enum iommu_hw_info_type - IOMMU Hardware Info Types
377398
* @IOMMU_HW_INFO_TYPE_NONE: Used by the drivers that do not report hardware
378399
* info
400+
* @IOMMU_HW_INFO_TYPE_INTEL_VTD: Intel VT-d iommu info type
379401
*/
380402
enum iommu_hw_info_type {
381403
IOMMU_HW_INFO_TYPE_NONE,
404+
IOMMU_HW_INFO_TYPE_INTEL_VTD,
382405
};
383406

384407
/**

0 commit comments

Comments
 (0)