[PATCH v5 03/27] iommu/arm-smmu-v3: Add a type for the CD entry

Jason Gunthorpe jgg at nvidia.com
Mon Mar 18 11:02:40 PDT 2024


On Wed, Mar 13, 2024 at 05:44:35PM +0800, Michael Shavit wrote:
> On Tue, Mar 5, 2024 at 7:44 AM Jason Gunthorpe <jgg at nvidia.com> wrote:
> >
> > Instead of passing a naked __le16 * around to represent a CD table entry
> > wrap it in a "struct arm_smmu_cd" with an array of the correct size. This
> > makes it much clearer which functions will comprise the "CD API".
> >
> > Tested-by: Nicolin Chen <nicolinc at nvidia.com>
> > Signed-off-by: Jason Gunthorpe <jgg at nvidia.com>
> > ---
> >  drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 20 +++++++++++---------
> >  drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h |  7 ++++++-
> >  2 files changed, 17 insertions(+), 10 deletions(-)
> >
> > diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> > index 9e9233331c4636..c60b067c1f553e 100644
> > --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> > +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> > @@ -1219,7 +1219,8 @@ static void arm_smmu_write_cd_l1_desc(__le64 *dst,
> >         WRITE_ONCE(*dst, cpu_to_le64(val));
> >  }
> >
> > -static __le64 *arm_smmu_get_cd_ptr(struct arm_smmu_master *master, u32 ssid)
> > +static struct arm_smmu_cd *arm_smmu_get_cd_ptr(struct arm_smmu_master *master,
> > +                                              u32 ssid)
> >  {
> >         __le64 *l1ptr;
> >         unsigned int idx;
> > @@ -1228,7 +1229,8 @@ static __le64 *arm_smmu_get_cd_ptr(struct arm_smmu_master *master, u32 ssid)
> >         struct arm_smmu_ctx_desc_cfg *cd_table = &master->cd_table;
> >
> >         if (cd_table->s1fmt == STRTAB_STE_0_S1FMT_LINEAR)
> > -               return cd_table->cdtab + ssid * CTXDESC_CD_DWORDS;
> > +               return (struct arm_smmu_cd *)(cd_table->cdtab +
> > +                                             ssid * CTXDESC_CD_DWORDS);
> 
> Can we define cd_table.cdtab as a union type to avoid this cast and
> make the struct definition more explicit?

Yes, those patches are in part 3 to fix the CD and STE to be like you
suggest. In the end the above looks like:

	if (cd_table->s1fmt == STRTAB_STE_0_S1FMT_LINEAR)
		return cd_table->cdtab.linear + ssid;

Thanks,
Jason



More information about the linux-arm-kernel mailing list