[PATCH v5 2/9] iommu/arm-smmu-v3: Replace s1_cfg with cdtab_cfg

Jason Gunthorpe jgg at nvidia.com
Wed Aug 9 08:08:02 PDT 2023


On Wed, Aug 09, 2023 at 03:55:43PM +0100, Will Deacon wrote:
> On Wed, Aug 09, 2023 at 10:59:33AM -0300, Jason Gunthorpe wrote:
> > On Wed, Aug 09, 2023 at 02:49:41PM +0100, Will Deacon wrote:
> > 
> > > > @@ -1360,10 +1357,14 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid,
> > > >  		    !master->stall_enabled)
> > > >  			dst[1] |= cpu_to_le64(STRTAB_STE_1_S1STALLD);
> > > >  
> > > > -		val |= (s1_cfg->cdcfg.cdtab_dma & STRTAB_STE_0_S1CTXPTR_MASK) |
> > > > -			FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_S1_TRANS) |
> > > > -			FIELD_PREP(STRTAB_STE_0_S1CDMAX, s1_cfg->s1cdmax) |
> > > > -			FIELD_PREP(STRTAB_STE_0_S1FMT, s1_cfg->s1fmt);
> > > > +		val |= (cd_table->cdtab_dma & STRTAB_STE_0_S1CTXPTR_MASK) |
> > > > +		       FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_S1_TRANS) |
> > > > +		       FIELD_PREP(STRTAB_STE_0_S1CDMAX,
> > > > +				  cd_table->max_cds_bits) |
> > > > +		       FIELD_PREP(STRTAB_STE_0_S1FMT,
> > > > +				  cd_table->l1_desc ?
> > > > +					  STRTAB_STE_0_S1FMT_64K_L2 :
> > > > +					  STRTAB_STE_0_S1FMT_LINEAR);
> > > 
> > > magically know that we're using 64k tables.
> > > 
> > > Why is this an improvement to the driver?
> > 
> > Put the above in a function 
> > 
> > arm_smmu_get_cd_ste(struct arm_smmu_ctx_desc_cfg *cdtab, void *ste)
> > 
> > And it makes more sense.
> 
> Sorry, but I'm not seeing it :/
> 
> > We don't need the driver to precompute the "s1_cfg" parameters and
> > store them in a redundant struct along side the ctx_desc_cfg when we
> > can compute those same values on the fly with no cost.
> 
> But the computation isn't happening -- the STRTAB_STE_0_S1FMT_64K_L2
> constant is hardcoded here. 

So it would be hard coded in arm_smmu_get_cd_ste() because that
reflects the current state of CD table code.

> If we want to use 4k leaf tables in some cases, how would you add
> that? Such a change shouldn't need the low-level strtab creation
> code to change.

You would modify arm_smmu_ctx_desc_cfg to teach it about the different
format. It would gain some (enum?) member that specifies the CD table
layout and geometry. arm_smmu_get_cd_ste() will interpret that member
and generate the correct STE for the specifc cd table.

It is a standard OOP sort of practice that the object self-describes
and has accessors to export its internal definition. In this case the
STE bits are part of/derived from the internal definition of the CD
table.

Jason



More information about the linux-arm-kernel mailing list