diff mbox series

[v9,02/15] cxl/regs: Prepare for multiple users of register mappings

Message ID 20230825233211.3029825-3-terry.bowman@amd.com
State New, archived
Headers show
Series cxl/pci: Add support for RCH RAS error handling | expand

Commit Message

Terry Bowman Aug. 25, 2023, 11:31 p.m. UTC
From: Robert Richter <rrichter@amd.com>

The function devm_cxl_iomap_block() is used to map register mappings
of CXL component or device registers. A @dev is used to unmap the IO
regions during device removal.

Now, there are multiple devices using the register mappings. E.g. the
RAS cap of the Component Registers is used by cxl_pci, the HDM cap
used in cxl_mem. This could cause IO blocks not being freed and a
subsequent reinitialization to fail if the same device is used for
both.

To prevent that, expand cxl_map_component_regs() to pass a @dev to be
used with devm to IO unmap. This allows to pass the device that
actually is creating and using the IO region.

For symmetry also change the function i/f of cxl_map_device_regs().

Signed-off-by: Robert Richter <rrichter@amd.com>
Signed-off-by: Terry Bowman <terry.bowman@amd.com>
---
 drivers/cxl/core/hdm.c  | 3 ++-
 drivers/cxl/core/regs.c | 4 ++--
 drivers/cxl/cxl.h       | 2 ++
 drivers/cxl/pci.c       | 4 ++--
 4 files changed, 8 insertions(+), 5 deletions(-)

Comments

Jonathan Cameron Aug. 29, 2023, 1:52 p.m. UTC | #1
On Fri, 25 Aug 2023 18:31:58 -0500
Terry Bowman <terry.bowman@amd.com> wrote:

> From: Robert Richter <rrichter@amd.com>
> 
> The function devm_cxl_iomap_block() is used to map register mappings
> of CXL component or device registers. A @dev is used to unmap the IO
> regions during device removal.
> 
> Now, there are multiple devices using the register mappings. E.g. the
> RAS cap of the Component Registers is used by cxl_pci, the HDM cap
> used in cxl_mem. This could cause IO blocks not being freed and a
> subsequent reinitialization to fail if the same device is used for
> both.
> 
> To prevent that, expand cxl_map_component_regs() to pass a @dev to be
> used with devm to IO unmap. This allows to pass the device that
> actually is creating and using the IO region.
> 
> For symmetry also change the function i/f of cxl_map_device_regs().
> 
> Signed-off-by: Robert Richter <rrichter@amd.com>
> Signed-off-by: Terry Bowman <terry.bowman@amd.com>

I'm not sure we should leave map->dev around after this change
as it's not obvious where it is valid to use and where it isn't.

Perhaps we just need to pass the device into the few calls
that use it other than the ones you have here.

This patch itself looks fine to me.

Jonathan

> ---
>  drivers/cxl/core/hdm.c  | 3 ++-
>  drivers/cxl/core/regs.c | 4 ++--
>  drivers/cxl/cxl.h       | 2 ++
>  drivers/cxl/pci.c       | 4 ++--
>  4 files changed, 8 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/cxl/core/hdm.c b/drivers/cxl/core/hdm.c
> index 4449b34a80cc..17c8ba8c75e0 100644
> --- a/drivers/cxl/core/hdm.c
> +++ b/drivers/cxl/core/hdm.c
> @@ -98,7 +98,8 @@ static int map_hdm_decoder_regs(struct cxl_port *port, void __iomem *crb,
>  		return -ENODEV;
>  	}
>  
> -	return cxl_map_component_regs(&map, regs, BIT(CXL_CM_CAP_CAP_ID_HDM));
> +	return cxl_map_component_regs(&map, &port->dev, regs,
> +				      BIT(CXL_CM_CAP_CAP_ID_HDM));
>  }
>  
>  static bool should_emulate_decoders(struct cxl_endpoint_dvsec_info *info)
> diff --git a/drivers/cxl/core/regs.c b/drivers/cxl/core/regs.c
> index 6281127b3e9d..dfc3e272e7d8 100644
> --- a/drivers/cxl/core/regs.c
> +++ b/drivers/cxl/core/regs.c
> @@ -201,10 +201,10 @@ void __iomem *devm_cxl_iomap_block(struct device *dev, resource_size_t addr,
>  }
>  
>  int cxl_map_component_regs(const struct cxl_register_map *map,
> +			   struct device *dev,
>  			   struct cxl_component_regs *regs,
>  			   unsigned long map_mask)
>  {
> -	struct device *dev = map->dev;
>  	struct mapinfo {
>  		const struct cxl_reg_map *rmap;
>  		void __iomem **addr;
> @@ -235,9 +235,9 @@ int cxl_map_component_regs(const struct cxl_register_map *map,
>  EXPORT_SYMBOL_NS_GPL(cxl_map_component_regs, CXL);
>  
>  int cxl_map_device_regs(const struct cxl_register_map *map,
> +			struct device *dev,
>  			struct cxl_device_regs *regs)
>  {
> -	struct device *dev = map->dev;
>  	resource_size_t phys_addr = map->resource;
>  	struct mapinfo {
>  		const struct cxl_reg_map *rmap;
> diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h
> index 76d92561af29..ec8ba9ebcf64 100644
> --- a/drivers/cxl/cxl.h
> +++ b/drivers/cxl/cxl.h
> @@ -274,9 +274,11 @@ void cxl_probe_component_regs(struct device *dev, void __iomem *base,
>  void cxl_probe_device_regs(struct device *dev, void __iomem *base,
>  			   struct cxl_device_reg_map *map);
>  int cxl_map_component_regs(const struct cxl_register_map *map,
> +			   struct device *dev,
>  			   struct cxl_component_regs *regs,
>  			   unsigned long map_mask);
>  int cxl_map_device_regs(const struct cxl_register_map *map,
> +			struct device *dev,
>  			struct cxl_device_regs *regs);
>  int cxl_map_pmu_regs(struct pci_dev *pdev, struct cxl_pmu_regs *regs,
>  		     struct cxl_register_map *map);
> diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c
> index 48f88d96029d..88ddcff8a0b2 100644
> --- a/drivers/cxl/pci.c
> +++ b/drivers/cxl/pci.c
> @@ -827,7 +827,7 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
>  	if (rc)
>  		return rc;
>  
> -	rc = cxl_map_device_regs(&map, &cxlds->regs.device_regs);
> +	rc = cxl_map_device_regs(&map, cxlds->dev, &cxlds->regs.device_regs);
>  	if (rc)
>  		return rc;
>  
> @@ -844,7 +844,7 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
>  
>  	cxlds->component_reg_phys = map.resource;
>  
> -	rc = cxl_map_component_regs(&map, &cxlds->regs.component,
> +	rc = cxl_map_component_regs(&map, cxlds->dev, &cxlds->regs.component,
>  				    BIT(CXL_CM_CAP_CAP_ID_RAS));
>  	if (rc)
>  		dev_dbg(&pdev->dev, "Failed to map RAS capability.\n");
Robert Richter Aug. 31, 2023, 12:43 p.m. UTC | #2
On 29.08.23 14:52:54, Jonathan Cameron wrote:
> On Fri, 25 Aug 2023 18:31:58 -0500
> Terry Bowman <terry.bowman@amd.com> wrote:
> 
> > From: Robert Richter <rrichter@amd.com>
> > 
> > The function devm_cxl_iomap_block() is used to map register mappings
> > of CXL component or device registers. A @dev is used to unmap the IO
> > regions during device removal.
> > 
> > Now, there are multiple devices using the register mappings. E.g. the
> > RAS cap of the Component Registers is used by cxl_pci, the HDM cap
> > used in cxl_mem. This could cause IO blocks not being freed and a
> > subsequent reinitialization to fail if the same device is used for
> > both.
> > 
> > To prevent that, expand cxl_map_component_regs() to pass a @dev to be
> > used with devm to IO unmap. This allows to pass the device that
> > actually is creating and using the IO region.
> > 
> > For symmetry also change the function i/f of cxl_map_device_regs().
> > 
> > Signed-off-by: Robert Richter <rrichter@amd.com>
> > Signed-off-by: Terry Bowman <terry.bowman@amd.com>
> 
> I'm not sure we should leave map->dev around after this change
> as it's not obvious where it is valid to use and where it isn't.
> 
> Perhaps we just need to pass the device into the few calls
> that use it other than the ones you have here.

I have checked that and it turned out we would need to pass @dev
through multiple functions (see cxl_setup_regs()). So I left it in as
devm is a special case (mis)using it.

> 
> This patch itself looks fine to me.

I will take it as a Reviewed-by:?

Thanks,

-Robert

> 
> Jonathan
> 
> > ---
> >  drivers/cxl/core/hdm.c  | 3 ++-
> >  drivers/cxl/core/regs.c | 4 ++--
> >  drivers/cxl/cxl.h       | 2 ++
> >  drivers/cxl/pci.c       | 4 ++--
> >  4 files changed, 8 insertions(+), 5 deletions(-)
> > 
> > diff --git a/drivers/cxl/core/hdm.c b/drivers/cxl/core/hdm.c
> > index 4449b34a80cc..17c8ba8c75e0 100644
> > --- a/drivers/cxl/core/hdm.c
> > +++ b/drivers/cxl/core/hdm.c
> > @@ -98,7 +98,8 @@ static int map_hdm_decoder_regs(struct cxl_port *port, void __iomem *crb,
> >  		return -ENODEV;
> >  	}
> >  
> > -	return cxl_map_component_regs(&map, regs, BIT(CXL_CM_CAP_CAP_ID_HDM));
> > +	return cxl_map_component_regs(&map, &port->dev, regs,
> > +				      BIT(CXL_CM_CAP_CAP_ID_HDM));
> >  }
> >  
> >  static bool should_emulate_decoders(struct cxl_endpoint_dvsec_info *info)
> > diff --git a/drivers/cxl/core/regs.c b/drivers/cxl/core/regs.c
> > index 6281127b3e9d..dfc3e272e7d8 100644
> > --- a/drivers/cxl/core/regs.c
> > +++ b/drivers/cxl/core/regs.c
> > @@ -201,10 +201,10 @@ void __iomem *devm_cxl_iomap_block(struct device *dev, resource_size_t addr,
> >  }
> >  
> >  int cxl_map_component_regs(const struct cxl_register_map *map,
> > +			   struct device *dev,
> >  			   struct cxl_component_regs *regs,
> >  			   unsigned long map_mask)
> >  {
> > -	struct device *dev = map->dev;
> >  	struct mapinfo {
> >  		const struct cxl_reg_map *rmap;
> >  		void __iomem **addr;
> > @@ -235,9 +235,9 @@ int cxl_map_component_regs(const struct cxl_register_map *map,
> >  EXPORT_SYMBOL_NS_GPL(cxl_map_component_regs, CXL);
> >  
> >  int cxl_map_device_regs(const struct cxl_register_map *map,
> > +			struct device *dev,
> >  			struct cxl_device_regs *regs)
> >  {
> > -	struct device *dev = map->dev;
> >  	resource_size_t phys_addr = map->resource;
> >  	struct mapinfo {
> >  		const struct cxl_reg_map *rmap;
> > diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h
> > index 76d92561af29..ec8ba9ebcf64 100644
> > --- a/drivers/cxl/cxl.h
> > +++ b/drivers/cxl/cxl.h
> > @@ -274,9 +274,11 @@ void cxl_probe_component_regs(struct device *dev, void __iomem *base,
> >  void cxl_probe_device_regs(struct device *dev, void __iomem *base,
> >  			   struct cxl_device_reg_map *map);
> >  int cxl_map_component_regs(const struct cxl_register_map *map,
> > +			   struct device *dev,
> >  			   struct cxl_component_regs *regs,
> >  			   unsigned long map_mask);
> >  int cxl_map_device_regs(const struct cxl_register_map *map,
> > +			struct device *dev,
> >  			struct cxl_device_regs *regs);
> >  int cxl_map_pmu_regs(struct pci_dev *pdev, struct cxl_pmu_regs *regs,
> >  		     struct cxl_register_map *map);
> > diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c
> > index 48f88d96029d..88ddcff8a0b2 100644
> > --- a/drivers/cxl/pci.c
> > +++ b/drivers/cxl/pci.c
> > @@ -827,7 +827,7 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
> >  	if (rc)
> >  		return rc;
> >  
> > -	rc = cxl_map_device_regs(&map, &cxlds->regs.device_regs);
> > +	rc = cxl_map_device_regs(&map, cxlds->dev, &cxlds->regs.device_regs);
> >  	if (rc)
> >  		return rc;
> >  
> > @@ -844,7 +844,7 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
> >  
> >  	cxlds->component_reg_phys = map.resource;
> >  
> > -	rc = cxl_map_component_regs(&map, &cxlds->regs.component,
> > +	rc = cxl_map_component_regs(&map, cxlds->dev, &cxlds->regs.component,
> >  				    BIT(CXL_CM_CAP_CAP_ID_RAS));
> >  	if (rc)
> >  		dev_dbg(&pdev->dev, "Failed to map RAS capability.\n");
>
Dan Williams Aug. 31, 2023, 6:11 p.m. UTC | #3
Terry Bowman wrote:
> From: Robert Richter <rrichter@amd.com>
> 
> The function devm_cxl_iomap_block() is used to map register mappings
> of CXL component or device registers. A @dev is used to unmap the IO
> regions during device removal.
> 
> Now, there are multiple devices using the register mappings. E.g. the
> RAS cap of the Component Registers is used by cxl_pci, the HDM cap
> used in cxl_mem. This could cause IO blocks not being freed and a
> subsequent reinitialization to fail if the same device is used for
> both.
> 
> To prevent that, expand cxl_map_component_regs() to pass a @dev to be
> used with devm to IO unmap. This allows to pass the device that
> actually is creating and using the IO region.
> 
> For symmetry also change the function i/f of cxl_map_device_regs().

I think @dev is too ambiguous as a name. I.e. when does @dev refer to
the 'struct device *' instance that the registers belong, and when does
@dev refer to the 'struct device *' instance hosting the mapping for
devm operations?

One of the ways I have tried to disambiguate that distinction is using
the name @host to explicitly refer to the context of devm operations,
and @dev is only for context for dev_dbg() operations. Can you clarify
this patch by using @host everywhere that the devm context is being
handled?

This would also satisfy Jonathan's concern. I think it needs to be the
case that @map is explicit about when it is conveying some @dev context for
dev_dbg() messages and when it is conveying the @host for devm
operations because those are 2 different concepts.

It looks like @dev argument you are plumbing here is for when @map->dev
cannot be used for devm operations, so at a minimum use @host as the
variable name to make that clear...

...or always make it the case that @map carries an @host parameter which
would mean that ports would need their own copy of the comp_map versus
directly reusing the one in the cxlds since those 2 mapping instances
need different @host parameters. That feels cleaner to me then
"sometimes map->dev can be used for devm and sometimes not". @map->host
is always the devm context.
Jonathan Cameron Sept. 1, 2023, 9:08 a.m. UTC | #4
On Thu, 31 Aug 2023 14:43:53 +0200
Robert Richter <rrichter@amd.com> wrote:

> On 29.08.23 14:52:54, Jonathan Cameron wrote:
> > On Fri, 25 Aug 2023 18:31:58 -0500
> > Terry Bowman <terry.bowman@amd.com> wrote:
> >   
> > > From: Robert Richter <rrichter@amd.com>
> > > 
> > > The function devm_cxl_iomap_block() is used to map register mappings
> > > of CXL component or device registers. A @dev is used to unmap the IO
> > > regions during device removal.
> > > 
> > > Now, there are multiple devices using the register mappings. E.g. the
> > > RAS cap of the Component Registers is used by cxl_pci, the HDM cap
> > > used in cxl_mem. This could cause IO blocks not being freed and a
> > > subsequent reinitialization to fail if the same device is used for
> > > both.
> > > 
> > > To prevent that, expand cxl_map_component_regs() to pass a @dev to be
> > > used with devm to IO unmap. This allows to pass the device that
> > > actually is creating and using the IO region.
> > > 
> > > For symmetry also change the function i/f of cxl_map_device_regs().
> > > 
> > > Signed-off-by: Robert Richter <rrichter@amd.com>
> > > Signed-off-by: Terry Bowman <terry.bowman@amd.com>  
> > 
> > I'm not sure we should leave map->dev around after this change
> > as it's not obvious where it is valid to use and where it isn't.
> > 
> > Perhaps we just need to pass the device into the few calls
> > that use it other than the ones you have here.  
> 
> I have checked that and it turned out we would need to pass @dev
> through multiple functions (see cxl_setup_regs()). So I left it in as
> devm is a special case (mis)using it.
> 
> > 
> > This patch itself looks fine to me.  
> 
> I will take it as a Reviewed-by:?
> 
No.  I'm not convinced on the map->dev question even though I appreciate
that passing it around is a mess. To me it's really non obvious that
in some cases map->dev is appropriate and in others a different dev
is needed.  Maybe some naming change would make it clear what each one is for?

Jonathan

> Thanks,
> 
> -Robert
> 
> > 
> > Jonathan
> >   
> > > ---
> > >  drivers/cxl/core/hdm.c  | 3 ++-
> > >  drivers/cxl/core/regs.c | 4 ++--
> > >  drivers/cxl/cxl.h       | 2 ++
> > >  drivers/cxl/pci.c       | 4 ++--
> > >  4 files changed, 8 insertions(+), 5 deletions(-)
> > > 
> > > diff --git a/drivers/cxl/core/hdm.c b/drivers/cxl/core/hdm.c
> > > index 4449b34a80cc..17c8ba8c75e0 100644
> > > --- a/drivers/cxl/core/hdm.c
> > > +++ b/drivers/cxl/core/hdm.c
> > > @@ -98,7 +98,8 @@ static int map_hdm_decoder_regs(struct cxl_port *port, void __iomem *crb,
> > >  		return -ENODEV;
> > >  	}
> > >  
> > > -	return cxl_map_component_regs(&map, regs, BIT(CXL_CM_CAP_CAP_ID_HDM));
> > > +	return cxl_map_component_regs(&map, &port->dev, regs,
> > > +				      BIT(CXL_CM_CAP_CAP_ID_HDM));
> > >  }
> > >  
> > >  static bool should_emulate_decoders(struct cxl_endpoint_dvsec_info *info)
> > > diff --git a/drivers/cxl/core/regs.c b/drivers/cxl/core/regs.c
> > > index 6281127b3e9d..dfc3e272e7d8 100644
> > > --- a/drivers/cxl/core/regs.c
> > > +++ b/drivers/cxl/core/regs.c
> > > @@ -201,10 +201,10 @@ void __iomem *devm_cxl_iomap_block(struct device *dev, resource_size_t addr,
> > >  }
> > >  
> > >  int cxl_map_component_regs(const struct cxl_register_map *map,
> > > +			   struct device *dev,
> > >  			   struct cxl_component_regs *regs,
> > >  			   unsigned long map_mask)
> > >  {
> > > -	struct device *dev = map->dev;
> > >  	struct mapinfo {
> > >  		const struct cxl_reg_map *rmap;
> > >  		void __iomem **addr;
> > > @@ -235,9 +235,9 @@ int cxl_map_component_regs(const struct cxl_register_map *map,
> > >  EXPORT_SYMBOL_NS_GPL(cxl_map_component_regs, CXL);
> > >  
> > >  int cxl_map_device_regs(const struct cxl_register_map *map,
> > > +			struct device *dev,
> > >  			struct cxl_device_regs *regs)
> > >  {
> > > -	struct device *dev = map->dev;
> > >  	resource_size_t phys_addr = map->resource;
> > >  	struct mapinfo {
> > >  		const struct cxl_reg_map *rmap;
> > > diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h
> > > index 76d92561af29..ec8ba9ebcf64 100644
> > > --- a/drivers/cxl/cxl.h
> > > +++ b/drivers/cxl/cxl.h
> > > @@ -274,9 +274,11 @@ void cxl_probe_component_regs(struct device *dev, void __iomem *base,
> > >  void cxl_probe_device_regs(struct device *dev, void __iomem *base,
> > >  			   struct cxl_device_reg_map *map);
> > >  int cxl_map_component_regs(const struct cxl_register_map *map,
> > > +			   struct device *dev,
> > >  			   struct cxl_component_regs *regs,
> > >  			   unsigned long map_mask);
> > >  int cxl_map_device_regs(const struct cxl_register_map *map,
> > > +			struct device *dev,
> > >  			struct cxl_device_regs *regs);
> > >  int cxl_map_pmu_regs(struct pci_dev *pdev, struct cxl_pmu_regs *regs,
> > >  		     struct cxl_register_map *map);
> > > diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c
> > > index 48f88d96029d..88ddcff8a0b2 100644
> > > --- a/drivers/cxl/pci.c
> > > +++ b/drivers/cxl/pci.c
> > > @@ -827,7 +827,7 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
> > >  	if (rc)
> > >  		return rc;
> > >  
> > > -	rc = cxl_map_device_regs(&map, &cxlds->regs.device_regs);
> > > +	rc = cxl_map_device_regs(&map, cxlds->dev, &cxlds->regs.device_regs);
> > >  	if (rc)
> > >  		return rc;
> > >  
> > > @@ -844,7 +844,7 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
> > >  
> > >  	cxlds->component_reg_phys = map.resource;
> > >  
> > > -	rc = cxl_map_component_regs(&map, &cxlds->regs.component,
> > > +	rc = cxl_map_component_regs(&map, cxlds->dev, &cxlds->regs.component,
> > >  				    BIT(CXL_CM_CAP_CAP_ID_RAS));
> > >  	if (rc)
> > >  		dev_dbg(&pdev->dev, "Failed to map RAS capability.\n");  
> >
Jonathan Cameron Sept. 1, 2023, 9:10 a.m. UTC | #5
On Thu, 31 Aug 2023 11:11:40 -0700
Dan Williams <dan.j.williams@intel.com> wrote:

> Terry Bowman wrote:
> > From: Robert Richter <rrichter@amd.com>
> > 
> > The function devm_cxl_iomap_block() is used to map register mappings
> > of CXL component or device registers. A @dev is used to unmap the IO
> > regions during device removal.
> > 
> > Now, there are multiple devices using the register mappings. E.g. the
> > RAS cap of the Component Registers is used by cxl_pci, the HDM cap
> > used in cxl_mem. This could cause IO blocks not being freed and a
> > subsequent reinitialization to fail if the same device is used for
> > both.
> > 
> > To prevent that, expand cxl_map_component_regs() to pass a @dev to be
> > used with devm to IO unmap. This allows to pass the device that
> > actually is creating and using the IO region.
> > 
> > For symmetry also change the function i/f of cxl_map_device_regs().  
> 
> I think @dev is too ambiguous as a name. I.e. when does @dev refer to
> the 'struct device *' instance that the registers belong, and when does
> @dev refer to the 'struct device *' instance hosting the mapping for
> devm operations?
> 
> One of the ways I have tried to disambiguate that distinction is using
> the name @host to explicitly refer to the context of devm operations,
> and @dev is only for context for dev_dbg() operations. Can you clarify
> this patch by using @host everywhere that the devm context is being
> handled?
> 
> This would also satisfy Jonathan's concern. I think it needs to be the
> case that @map is explicit about when it is conveying some @dev context for
> dev_dbg() messages and when it is conveying the @host for devm
> operations because those are 2 different concepts.

I should read all the replies before I reply to any of them.
Agreed that renaming it would satisfy my concern over the confusion.

> 
> It looks like @dev argument you are plumbing here is for when @map->dev
> cannot be used for devm operations, so at a minimum use @host as the
> variable name to make that clear...
> 
> ...or always make it the case that @map carries an @host parameter which
> would mean that ports would need their own copy of the comp_map versus
> directly reusing the one in the cxlds since those 2 mapping instances
> need different @host parameters. That feels cleaner to me then
> "sometimes map->dev can be used for devm and sometimes not". @map->host
> is always the devm context.

Agreed that may be better still.

Jonathan
diff mbox series

Patch

diff --git a/drivers/cxl/core/hdm.c b/drivers/cxl/core/hdm.c
index 4449b34a80cc..17c8ba8c75e0 100644
--- a/drivers/cxl/core/hdm.c
+++ b/drivers/cxl/core/hdm.c
@@ -98,7 +98,8 @@  static int map_hdm_decoder_regs(struct cxl_port *port, void __iomem *crb,
 		return -ENODEV;
 	}
 
-	return cxl_map_component_regs(&map, regs, BIT(CXL_CM_CAP_CAP_ID_HDM));
+	return cxl_map_component_regs(&map, &port->dev, regs,
+				      BIT(CXL_CM_CAP_CAP_ID_HDM));
 }
 
 static bool should_emulate_decoders(struct cxl_endpoint_dvsec_info *info)
diff --git a/drivers/cxl/core/regs.c b/drivers/cxl/core/regs.c
index 6281127b3e9d..dfc3e272e7d8 100644
--- a/drivers/cxl/core/regs.c
+++ b/drivers/cxl/core/regs.c
@@ -201,10 +201,10 @@  void __iomem *devm_cxl_iomap_block(struct device *dev, resource_size_t addr,
 }
 
 int cxl_map_component_regs(const struct cxl_register_map *map,
+			   struct device *dev,
 			   struct cxl_component_regs *regs,
 			   unsigned long map_mask)
 {
-	struct device *dev = map->dev;
 	struct mapinfo {
 		const struct cxl_reg_map *rmap;
 		void __iomem **addr;
@@ -235,9 +235,9 @@  int cxl_map_component_regs(const struct cxl_register_map *map,
 EXPORT_SYMBOL_NS_GPL(cxl_map_component_regs, CXL);
 
 int cxl_map_device_regs(const struct cxl_register_map *map,
+			struct device *dev,
 			struct cxl_device_regs *regs)
 {
-	struct device *dev = map->dev;
 	resource_size_t phys_addr = map->resource;
 	struct mapinfo {
 		const struct cxl_reg_map *rmap;
diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h
index 76d92561af29..ec8ba9ebcf64 100644
--- a/drivers/cxl/cxl.h
+++ b/drivers/cxl/cxl.h
@@ -274,9 +274,11 @@  void cxl_probe_component_regs(struct device *dev, void __iomem *base,
 void cxl_probe_device_regs(struct device *dev, void __iomem *base,
 			   struct cxl_device_reg_map *map);
 int cxl_map_component_regs(const struct cxl_register_map *map,
+			   struct device *dev,
 			   struct cxl_component_regs *regs,
 			   unsigned long map_mask);
 int cxl_map_device_regs(const struct cxl_register_map *map,
+			struct device *dev,
 			struct cxl_device_regs *regs);
 int cxl_map_pmu_regs(struct pci_dev *pdev, struct cxl_pmu_regs *regs,
 		     struct cxl_register_map *map);
diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c
index 48f88d96029d..88ddcff8a0b2 100644
--- a/drivers/cxl/pci.c
+++ b/drivers/cxl/pci.c
@@ -827,7 +827,7 @@  static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	if (rc)
 		return rc;
 
-	rc = cxl_map_device_regs(&map, &cxlds->regs.device_regs);
+	rc = cxl_map_device_regs(&map, cxlds->dev, &cxlds->regs.device_regs);
 	if (rc)
 		return rc;
 
@@ -844,7 +844,7 @@  static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 
 	cxlds->component_reg_phys = map.resource;
 
-	rc = cxl_map_component_regs(&map, &cxlds->regs.component,
+	rc = cxl_map_component_regs(&map, cxlds->dev, &cxlds->regs.component,
 				    BIT(CXL_CM_CAP_CAP_ID_RAS));
 	if (rc)
 		dev_dbg(&pdev->dev, "Failed to map RAS capability.\n");