Skip to content

Commit e113a72

Browse files
ssuthiku-amdjoergroedel
authored andcommitted
iommu/amd: Introduce struct amd_iommu_viommu
Which stores reference to nested parent domain assigned during the call to struct iommu_ops.viommu_init(). Information in the nest parent is needed when setting up the nested translation. Note that the viommu initialization will be introduced in subsequent commit. Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Reviewed-by: Nicolin Chen <nicolinc@nvidia.com> Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com> Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
1 parent b43a29d commit e113a72

4 files changed

Lines changed: 29 additions & 0 deletions

File tree

drivers/iommu/amd/amd_iommu_types.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <linux/list.h>
1818
#include <linux/spinlock.h>
1919
#include <linux/pci.h>
20+
#include <linux/iommufd.h>
2021
#include <linux/irqreturn.h>
2122
#include <linux/generic_pt/iommu.h>
2223

@@ -495,6 +496,11 @@ struct pdom_iommu_info {
495496
u32 refcnt; /* Count of attached dev/pasid per domain/IOMMU */
496497
};
497498

499+
struct amd_iommu_viommu {
500+
struct iommufd_viommu core;
501+
struct protection_domain *parent; /* nest parent domain for this viommu */
502+
};
503+
498504
/*
499505
* This structure contains generic data for IOMMU protection domains
500506
* independent of their use.

drivers/iommu/amd/iommu.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3120,6 +3120,8 @@ const struct iommu_ops amd_iommu_ops = {
31203120
.is_attach_deferred = amd_iommu_is_attach_deferred,
31213121
.def_domain_type = amd_iommu_def_domain_type,
31223122
.page_response = amd_iommu_page_response,
3123+
.get_viommu_size = amd_iommufd_get_viommu_size,
3124+
.viommu_init = amd_iommufd_viommu_init,
31233125
};
31243126

31253127
#ifdef CONFIG_IRQ_REMAP

drivers/iommu/amd/iommufd.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,19 @@ void *amd_iommufd_hw_info(struct device *dev, u32 *length, u32 *type)
2929

3030
return hwinfo;
3131
}
32+
33+
size_t amd_iommufd_get_viommu_size(struct device *dev, enum iommu_viommu_type viommu_type)
34+
{
35+
return VIOMMU_STRUCT_SIZE(struct amd_iommu_viommu, core);
36+
}
37+
38+
int amd_iommufd_viommu_init(struct iommufd_viommu *viommu, struct iommu_domain *parent,
39+
const struct iommu_user_data *user_data)
40+
{
41+
struct protection_domain *pdom = to_pdomain(parent);
42+
struct amd_iommu_viommu *aviommu = container_of(viommu, struct amd_iommu_viommu, core);
43+
44+
aviommu->parent = pdom;
45+
46+
return 0;
47+
}

drivers/iommu/amd/iommufd.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@
88

99
#if IS_ENABLED(CONFIG_AMD_IOMMU_IOMMUFD)
1010
void *amd_iommufd_hw_info(struct device *dev, u32 *length, u32 *type);
11+
size_t amd_iommufd_get_viommu_size(struct device *dev, enum iommu_viommu_type viommu_type);
12+
int amd_iommufd_viommu_init(struct iommufd_viommu *viommu, struct iommu_domain *parent,
13+
const struct iommu_user_data *user_data);
1114
#else
1215
#define amd_iommufd_hw_info NULL
16+
#define amd_iommufd_viommu_init NULL
17+
#define amd_iommufd_get_viommu_size NULL
1318
#endif /* CONFIG_AMD_IOMMU_IOMMUFD */
1419

1520
#endif /* AMD_IOMMUFD_H */

0 commit comments

Comments
 (0)