Message ID | 163379786922.692348.2318044990911111834.stgit@dwillia2-desk3.amr.corp.intel.com |
---|---|
State | New, archived |
Headers | show |
Series | cxl_pci refactor for reusability | expand |
On Sat, Oct 09, 2021 at 09:44:29AM -0700, Dan Williams wrote: > In addition to carrying @barno, @block_offset, and @reg_type, add @base > to keep all map/unmap parameters in one object. The helpers > cxl_{map,unmap}_regblock() handle adjusting @base to the @block_offset > at map and unmap time. > > Signed-off-by: Dan Williams <dan.j.williams@intel.com> > --- > drivers/cxl/cxl.h | 1 + > drivers/cxl/pci.c | 31 ++++++++++++++++--------------- > 2 files changed, 17 insertions(+), 15 deletions(-) > > diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h > index a6687e7fd598..7cd16ef144dd 100644 > --- a/drivers/cxl/cxl.h > +++ b/drivers/cxl/cxl.h > @@ -140,6 +140,7 @@ struct cxl_device_reg_map { > }; > > struct cxl_register_map { > + void __iomem *base; > u64 block_offset; > u8 reg_type; > u8 barno; > diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c > index 9f006299a0e3..b42407d067ac 100644 > --- a/drivers/cxl/pci.c > +++ b/drivers/cxl/pci.c > @@ -306,8 +306,7 @@ static int cxl_pci_setup_mailbox(struct cxl_mem *cxlm) > return 0; > } > > -static void __iomem *cxl_pci_map_regblock(struct pci_dev *pdev, > - struct cxl_register_map *map) > +static int cxl_map_regblock(struct pci_dev *pdev, struct cxl_register_map *map) > { > void __iomem *addr; > int bar = map->barno; > @@ -318,24 +317,27 @@ static void __iomem *cxl_pci_map_regblock(struct pci_dev *pdev, > if (pci_resource_len(pdev, bar) < offset) { > dev_err(dev, "BAR%d: %pr: too small (offset: %#llx)\n", bar, > &pdev->resource[bar], (unsigned long long)offset); > - return NULL; > + return -ENXIO; > } > > addr = pci_iomap(pdev, bar, 0); > if (!addr) { > dev_err(dev, "failed to map registers\n"); > - return addr; > + return -ENOMEM; > } > > dev_dbg(dev, "Mapped CXL Memory Device resource bar %u @ %#llx\n", > bar, offset); > > - return addr; > + map->base = addr + map->block_offset; > + return 0; > } > > -static void cxl_pci_unmap_regblock(struct pci_dev *pdev, void __iomem *base) > +static void cxl_unmap_regblock(struct pci_dev *pdev, > + struct cxl_register_map *map) > { > - pci_iounmap(pdev, base); > + pci_iounmap(pdev, map->base - map->block_offset); I know we need to get these in soon. But I think map->base should be 'base' and map->block_offset should be handled in cxl_probe_regs() rather than subtract it here.. Either way this is cleaner than what it was. Reviewed-by: Ira Weiny <ira.weiny@intel.com> > + map->base = NULL; > } > > static int cxl_pci_dvsec(struct pci_dev *pdev, int dvsec) > @@ -361,12 +363,12 @@ static int cxl_pci_dvsec(struct pci_dev *pdev, int dvsec) > return 0; > } > > -static int cxl_probe_regs(struct pci_dev *pdev, void __iomem *base, > - struct cxl_register_map *map) > +static int cxl_probe_regs(struct pci_dev *pdev, struct cxl_register_map *map) > { > struct cxl_component_reg_map *comp_map; > struct cxl_device_reg_map *dev_map; > struct device *dev = &pdev->dev; > + void __iomem *base = map->base; > > switch (map->reg_type) { > case CXL_REGLOC_RBI_COMPONENT: > @@ -442,7 +444,6 @@ static void cxl_decode_regblock(u32 reg_lo, u32 reg_hi, > */ > static int cxl_pci_setup_regs(struct cxl_mem *cxlm) > { > - void __iomem *base; > u32 regloc_size, regblocks; > int regloc, i, n_maps, ret = 0; > struct device *dev = cxlm->dev; > @@ -475,12 +476,12 @@ static int cxl_pci_setup_regs(struct cxl_mem *cxlm) > if (map->reg_type > CXL_REGLOC_RBI_MEMDEV) > continue; > > - base = cxl_pci_map_regblock(pdev, map); > - if (!base) > - return -ENOMEM; > + ret = cxl_map_regblock(pdev, map); > + if (ret) > + return ret; > > - ret = cxl_probe_regs(pdev, base + map->block_offset, map); > - cxl_pci_unmap_regblock(pdev, base); > + ret = cxl_probe_regs(pdev, map); > + cxl_unmap_regblock(pdev, map); > if (ret) > return ret; > >
On Sat, Oct 9, 2021 at 9:21 PM Ira Weiny <ira.weiny@intel.com> wrote: > > On Sat, Oct 09, 2021 at 09:44:29AM -0700, Dan Williams wrote: > > In addition to carrying @barno, @block_offset, and @reg_type, add @base > > to keep all map/unmap parameters in one object. The helpers > > cxl_{map,unmap}_regblock() handle adjusting @base to the @block_offset > > at map and unmap time. > > > > Signed-off-by: Dan Williams <dan.j.williams@intel.com> > > --- > > drivers/cxl/cxl.h | 1 + > > drivers/cxl/pci.c | 31 ++++++++++++++++--------------- > > 2 files changed, 17 insertions(+), 15 deletions(-) > > > > diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h > > index a6687e7fd598..7cd16ef144dd 100644 > > --- a/drivers/cxl/cxl.h > > +++ b/drivers/cxl/cxl.h > > @@ -140,6 +140,7 @@ struct cxl_device_reg_map { > > }; > > > > struct cxl_register_map { > > + void __iomem *base; > > u64 block_offset; > > u8 reg_type; > > u8 barno; > > diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c > > index 9f006299a0e3..b42407d067ac 100644 > > --- a/drivers/cxl/pci.c > > +++ b/drivers/cxl/pci.c > > @@ -306,8 +306,7 @@ static int cxl_pci_setup_mailbox(struct cxl_mem *cxlm) > > return 0; > > } > > > > -static void __iomem *cxl_pci_map_regblock(struct pci_dev *pdev, > > - struct cxl_register_map *map) > > +static int cxl_map_regblock(struct pci_dev *pdev, struct cxl_register_map *map) > > { > > void __iomem *addr; > > int bar = map->barno; > > @@ -318,24 +317,27 @@ static void __iomem *cxl_pci_map_regblock(struct pci_dev *pdev, > > if (pci_resource_len(pdev, bar) < offset) { > > dev_err(dev, "BAR%d: %pr: too small (offset: %#llx)\n", bar, > > &pdev->resource[bar], (unsigned long long)offset); > > - return NULL; > > + return -ENXIO; > > } > > > > addr = pci_iomap(pdev, bar, 0); > > if (!addr) { > > dev_err(dev, "failed to map registers\n"); > > - return addr; > > + return -ENOMEM; > > } > > > > dev_dbg(dev, "Mapped CXL Memory Device resource bar %u @ %#llx\n", > > bar, offset); > > > > - return addr; > > + map->base = addr + map->block_offset; > > + return 0; > > } > > > > -static void cxl_pci_unmap_regblock(struct pci_dev *pdev, void __iomem *base) > > +static void cxl_unmap_regblock(struct pci_dev *pdev, > > + struct cxl_register_map *map) > > { > > - pci_iounmap(pdev, base); > > + pci_iounmap(pdev, map->base - map->block_offset); > > I know we need to get these in soon. But I think map->base should be 'base' > and map->block_offset should be handled in cxl_probe_regs() rather than > subtract it here.. But why? The goal of the cxl_register_map cleanups is to reduce the open-coding for details that can just be passed around in a @map instance. Once cxl_map_regblock() sets up @base there's little reason to consider the hardware regblock details. > Either way this is cleaner than what it was. > > Reviewed-by: Ira Weiny <ira.weiny@intel.com> Thanks!
On Sat, 9 Oct 2021 09:44:29 -0700 Dan Williams <dan.j.williams@intel.com> wrote: > In addition to carrying @barno, @block_offset, and @reg_type, add @base > to keep all map/unmap parameters in one object. The helpers > cxl_{map,unmap}_regblock() handle adjusting @base to the @block_offset > at map and unmap time. > > Signed-off-by: Dan Williams <dan.j.williams@intel.com> I don't really mind them, but why the renames from cxl_pci_* to cxl_* ? Jonathan > --- > drivers/cxl/cxl.h | 1 + > drivers/cxl/pci.c | 31 ++++++++++++++++--------------- > 2 files changed, 17 insertions(+), 15 deletions(-) > > diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h > index a6687e7fd598..7cd16ef144dd 100644 > --- a/drivers/cxl/cxl.h > +++ b/drivers/cxl/cxl.h > @@ -140,6 +140,7 @@ struct cxl_device_reg_map { > }; > > struct cxl_register_map { > + void __iomem *base; > u64 block_offset; > u8 reg_type; > u8 barno; > diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c > index 9f006299a0e3..b42407d067ac 100644 > --- a/drivers/cxl/pci.c > +++ b/drivers/cxl/pci.c > @@ -306,8 +306,7 @@ static int cxl_pci_setup_mailbox(struct cxl_mem *cxlm) > return 0; > } > > -static void __iomem *cxl_pci_map_regblock(struct pci_dev *pdev, > - struct cxl_register_map *map) > +static int cxl_map_regblock(struct pci_dev *pdev, struct cxl_register_map *map) > { > void __iomem *addr; > int bar = map->barno; > @@ -318,24 +317,27 @@ static void __iomem *cxl_pci_map_regblock(struct pci_dev *pdev, > if (pci_resource_len(pdev, bar) < offset) { > dev_err(dev, "BAR%d: %pr: too small (offset: %#llx)\n", bar, > &pdev->resource[bar], (unsigned long long)offset); > - return NULL; > + return -ENXIO; > } > > addr = pci_iomap(pdev, bar, 0); > if (!addr) { > dev_err(dev, "failed to map registers\n"); > - return addr; > + return -ENOMEM; > } > > dev_dbg(dev, "Mapped CXL Memory Device resource bar %u @ %#llx\n", > bar, offset); > > - return addr; > + map->base = addr + map->block_offset; > + return 0; > } > > -static void cxl_pci_unmap_regblock(struct pci_dev *pdev, void __iomem *base) > +static void cxl_unmap_regblock(struct pci_dev *pdev, > + struct cxl_register_map *map) > { > - pci_iounmap(pdev, base); > + pci_iounmap(pdev, map->base - map->block_offset); > + map->base = NULL; > } > > static int cxl_pci_dvsec(struct pci_dev *pdev, int dvsec) > @@ -361,12 +363,12 @@ static int cxl_pci_dvsec(struct pci_dev *pdev, int dvsec) > return 0; > } > > -static int cxl_probe_regs(struct pci_dev *pdev, void __iomem *base, > - struct cxl_register_map *map) > +static int cxl_probe_regs(struct pci_dev *pdev, struct cxl_register_map *map) > { > struct cxl_component_reg_map *comp_map; > struct cxl_device_reg_map *dev_map; > struct device *dev = &pdev->dev; > + void __iomem *base = map->base; > > switch (map->reg_type) { > case CXL_REGLOC_RBI_COMPONENT: > @@ -442,7 +444,6 @@ static void cxl_decode_regblock(u32 reg_lo, u32 reg_hi, > */ > static int cxl_pci_setup_regs(struct cxl_mem *cxlm) > { > - void __iomem *base; > u32 regloc_size, regblocks; > int regloc, i, n_maps, ret = 0; > struct device *dev = cxlm->dev; > @@ -475,12 +476,12 @@ static int cxl_pci_setup_regs(struct cxl_mem *cxlm) > if (map->reg_type > CXL_REGLOC_RBI_MEMDEV) > continue; > > - base = cxl_pci_map_regblock(pdev, map); > - if (!base) > - return -ENOMEM; > + ret = cxl_map_regblock(pdev, map); > + if (ret) > + return ret; > > - ret = cxl_probe_regs(pdev, base + map->block_offset, map); > - cxl_pci_unmap_regblock(pdev, base); > + ret = cxl_probe_regs(pdev, map); > + cxl_unmap_regblock(pdev, map); > if (ret) > return ret; > >
On Wed, 13 Oct 2021 15:53:20 -0700 Dan Williams <dan.j.williams@intel.com> wrote: > On Sat, Oct 9, 2021 at 9:21 PM Ira Weiny <ira.weiny@intel.com> wrote: > > > > On Sat, Oct 09, 2021 at 09:44:29AM -0700, Dan Williams wrote: > > > In addition to carrying @barno, @block_offset, and @reg_type, add @base > > > to keep all map/unmap parameters in one object. The helpers > > > cxl_{map,unmap}_regblock() handle adjusting @base to the @block_offset > > > at map and unmap time. > > > > > > Signed-off-by: Dan Williams <dan.j.williams@intel.com> > > > --- > > > drivers/cxl/cxl.h | 1 + > > > drivers/cxl/pci.c | 31 ++++++++++++++++--------------- > > > 2 files changed, 17 insertions(+), 15 deletions(-) > > > > > > diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h > > > index a6687e7fd598..7cd16ef144dd 100644 > > > --- a/drivers/cxl/cxl.h > > > +++ b/drivers/cxl/cxl.h > > > @@ -140,6 +140,7 @@ struct cxl_device_reg_map { > > > }; > > > > > > struct cxl_register_map { > > > + void __iomem *base; > > > u64 block_offset; > > > u8 reg_type; > > > u8 barno; > > > diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c > > > index 9f006299a0e3..b42407d067ac 100644 > > > --- a/drivers/cxl/pci.c > > > +++ b/drivers/cxl/pci.c > > > @@ -306,8 +306,7 @@ static int cxl_pci_setup_mailbox(struct cxl_mem *cxlm) > > > return 0; > > > } > > > > > > -static void __iomem *cxl_pci_map_regblock(struct pci_dev *pdev, > > > - struct cxl_register_map *map) > > > +static int cxl_map_regblock(struct pci_dev *pdev, struct cxl_register_map *map) > > > { > > > void __iomem *addr; > > > int bar = map->barno; > > > @@ -318,24 +317,27 @@ static void __iomem *cxl_pci_map_regblock(struct pci_dev *pdev, > > > if (pci_resource_len(pdev, bar) < offset) { > > > dev_err(dev, "BAR%d: %pr: too small (offset: %#llx)\n", bar, > > > &pdev->resource[bar], (unsigned long long)offset); > > > - return NULL; > > > + return -ENXIO; > > > } > > > > > > addr = pci_iomap(pdev, bar, 0); > > > if (!addr) { > > > dev_err(dev, "failed to map registers\n"); > > > - return addr; > > > + return -ENOMEM; > > > } > > > > > > dev_dbg(dev, "Mapped CXL Memory Device resource bar %u @ %#llx\n", > > > bar, offset); > > > > > > - return addr; > > > + map->base = addr + map->block_offset; > > > + return 0; > > > } > > > > > > -static void cxl_pci_unmap_regblock(struct pci_dev *pdev, void __iomem *base) > > > +static void cxl_unmap_regblock(struct pci_dev *pdev, > > > + struct cxl_register_map *map) > > > { > > > - pci_iounmap(pdev, base); > > > + pci_iounmap(pdev, map->base - map->block_offset); > > > > I know we need to get these in soon. But I think map->base should be 'base' > > and map->block_offset should be handled in cxl_probe_regs() rather than > > subtract it here.. > > But why? The goal of the cxl_register_map cleanups is to reduce the > open-coding for details that can just be passed around in a @map > instance. Once cxl_map_regblock() sets up @base there's little reason > to consider the hardware regblock details. I agree with Ira to the extent that this was a little confusing. Perhaps it is worth a comment at the structure definition to make the relationship of block_offset and base clear? Jonathan > > > Either way this is cleaner than what it was. > > > > Reviewed-by: Ira Weiny <ira.weiny@intel.com> > > Thanks!
On Fri, Oct 15, 2021 at 9:27 AM Jonathan Cameron <Jonathan.Cameron@huawei.com> wrote: > > On Sat, 9 Oct 2021 09:44:29 -0700 > Dan Williams <dan.j.williams@intel.com> wrote: > > > In addition to carrying @barno, @block_offset, and @reg_type, add @base > > to keep all map/unmap parameters in one object. The helpers > > cxl_{map,unmap}_regblock() handle adjusting @base to the @block_offset > > at map and unmap time. > > > > Signed-off-by: Dan Williams <dan.j.williams@intel.com> > > I don't really mind them, but why the renames > from cxl_pci_* to cxl_* ? Primarily because we had a mix of some functions including the _pci and some not, and I steered towards just dropping it. I think the "PCI" aspect of the function is clear by its function signature, and that was being muddied by passing @cxlm unnecessarily. So instead of: cxl_pci_$foo(struct cxl_mem *cxlm...) ...I went with: cxl_$foo(struct pci_dev *pdev...) ...concerns?
On Fri, Oct 15, 2021 at 9:29 AM Jonathan Cameron <Jonathan.Cameron@huawei.com> wrote: > > On Wed, 13 Oct 2021 15:53:20 -0700 > Dan Williams <dan.j.williams@intel.com> wrote: > > > On Sat, Oct 9, 2021 at 9:21 PM Ira Weiny <ira.weiny@intel.com> wrote: > > > > > > On Sat, Oct 09, 2021 at 09:44:29AM -0700, Dan Williams wrote: > > > > In addition to carrying @barno, @block_offset, and @reg_type, add @base > > > > to keep all map/unmap parameters in one object. The helpers > > > > cxl_{map,unmap}_regblock() handle adjusting @base to the @block_offset > > > > at map and unmap time. > > > > > > > > Signed-off-by: Dan Williams <dan.j.williams@intel.com> > > > > --- > > > > drivers/cxl/cxl.h | 1 + > > > > drivers/cxl/pci.c | 31 ++++++++++++++++--------------- > > > > 2 files changed, 17 insertions(+), 15 deletions(-) > > > > > > > > diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h > > > > index a6687e7fd598..7cd16ef144dd 100644 > > > > --- a/drivers/cxl/cxl.h > > > > +++ b/drivers/cxl/cxl.h > > > > @@ -140,6 +140,7 @@ struct cxl_device_reg_map { > > > > }; > > > > > > > > struct cxl_register_map { > > > > + void __iomem *base; > > > > u64 block_offset; > > > > u8 reg_type; > > > > u8 barno; > > > > diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c > > > > index 9f006299a0e3..b42407d067ac 100644 > > > > --- a/drivers/cxl/pci.c > > > > +++ b/drivers/cxl/pci.c > > > > @@ -306,8 +306,7 @@ static int cxl_pci_setup_mailbox(struct cxl_mem *cxlm) > > > > return 0; > > > > } > > > > > > > > -static void __iomem *cxl_pci_map_regblock(struct pci_dev *pdev, > > > > - struct cxl_register_map *map) > > > > +static int cxl_map_regblock(struct pci_dev *pdev, struct cxl_register_map *map) > > > > { > > > > void __iomem *addr; > > > > int bar = map->barno; > > > > @@ -318,24 +317,27 @@ static void __iomem *cxl_pci_map_regblock(struct pci_dev *pdev, > > > > if (pci_resource_len(pdev, bar) < offset) { > > > > dev_err(dev, "BAR%d: %pr: too small (offset: %#llx)\n", bar, > > > > &pdev->resource[bar], (unsigned long long)offset); > > > > - return NULL; > > > > + return -ENXIO; > > > > } > > > > > > > > addr = pci_iomap(pdev, bar, 0); > > > > if (!addr) { > > > > dev_err(dev, "failed to map registers\n"); > > > > - return addr; > > > > + return -ENOMEM; > > > > } > > > > > > > > dev_dbg(dev, "Mapped CXL Memory Device resource bar %u @ %#llx\n", > > > > bar, offset); > > > > > > > > - return addr; > > > > + map->base = addr + map->block_offset; > > > > + return 0; > > > > } > > > > > > > > -static void cxl_pci_unmap_regblock(struct pci_dev *pdev, void __iomem *base) > > > > +static void cxl_unmap_regblock(struct pci_dev *pdev, > > > > + struct cxl_register_map *map) > > > > { > > > > - pci_iounmap(pdev, base); > > > > + pci_iounmap(pdev, map->base - map->block_offset); > > > > > > I know we need to get these in soon. But I think map->base should be 'base' > > > and map->block_offset should be handled in cxl_probe_regs() rather than > > > subtract it here.. > > > > But why? The goal of the cxl_register_map cleanups is to reduce the > > open-coding for details that can just be passed around in a @map > > instance. Once cxl_map_regblock() sets up @base there's little reason > > to consider the hardware regblock details. > > I agree with Ira to the extent that this was a little confusing. Perhaps it is worth > a comment at the structure definition to make the relationship of block_offset > and base clear? > I can add that, sure.
On Fri, 15 Oct 2021 09:55:57 -0700 Dan Williams <dan.j.williams@intel.com> wrote: > On Fri, Oct 15, 2021 at 9:27 AM Jonathan Cameron > <Jonathan.Cameron@huawei.com> wrote: > > > > On Sat, 9 Oct 2021 09:44:29 -0700 > > Dan Williams <dan.j.williams@intel.com> wrote: > > > > > In addition to carrying @barno, @block_offset, and @reg_type, add @base > > > to keep all map/unmap parameters in one object. The helpers > > > cxl_{map,unmap}_regblock() handle adjusting @base to the @block_offset > > > at map and unmap time. > > > > > > Signed-off-by: Dan Williams <dan.j.williams@intel.com> > > > > I don't really mind them, but why the renames > > from cxl_pci_* to cxl_* ? > > Primarily because we had a mix of some functions including the _pci > and some not, and I steered towards just dropping it. I think the > "PCI" aspect of the function is clear by its function signature, and > that was being muddied by passing @cxlm unnecessarily. So instead of: > > cxl_pci_$foo(struct cxl_mem *cxlm...) > > ...I went with: > > cxl_$foo(struct pci_dev *pdev...) > > ...concerns? That's fine, J
diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h index a6687e7fd598..7cd16ef144dd 100644 --- a/drivers/cxl/cxl.h +++ b/drivers/cxl/cxl.h @@ -140,6 +140,7 @@ struct cxl_device_reg_map { }; struct cxl_register_map { + void __iomem *base; u64 block_offset; u8 reg_type; u8 barno; diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c index 9f006299a0e3..b42407d067ac 100644 --- a/drivers/cxl/pci.c +++ b/drivers/cxl/pci.c @@ -306,8 +306,7 @@ static int cxl_pci_setup_mailbox(struct cxl_mem *cxlm) return 0; } -static void __iomem *cxl_pci_map_regblock(struct pci_dev *pdev, - struct cxl_register_map *map) +static int cxl_map_regblock(struct pci_dev *pdev, struct cxl_register_map *map) { void __iomem *addr; int bar = map->barno; @@ -318,24 +317,27 @@ static void __iomem *cxl_pci_map_regblock(struct pci_dev *pdev, if (pci_resource_len(pdev, bar) < offset) { dev_err(dev, "BAR%d: %pr: too small (offset: %#llx)\n", bar, &pdev->resource[bar], (unsigned long long)offset); - return NULL; + return -ENXIO; } addr = pci_iomap(pdev, bar, 0); if (!addr) { dev_err(dev, "failed to map registers\n"); - return addr; + return -ENOMEM; } dev_dbg(dev, "Mapped CXL Memory Device resource bar %u @ %#llx\n", bar, offset); - return addr; + map->base = addr + map->block_offset; + return 0; } -static void cxl_pci_unmap_regblock(struct pci_dev *pdev, void __iomem *base) +static void cxl_unmap_regblock(struct pci_dev *pdev, + struct cxl_register_map *map) { - pci_iounmap(pdev, base); + pci_iounmap(pdev, map->base - map->block_offset); + map->base = NULL; } static int cxl_pci_dvsec(struct pci_dev *pdev, int dvsec) @@ -361,12 +363,12 @@ static int cxl_pci_dvsec(struct pci_dev *pdev, int dvsec) return 0; } -static int cxl_probe_regs(struct pci_dev *pdev, void __iomem *base, - struct cxl_register_map *map) +static int cxl_probe_regs(struct pci_dev *pdev, struct cxl_register_map *map) { struct cxl_component_reg_map *comp_map; struct cxl_device_reg_map *dev_map; struct device *dev = &pdev->dev; + void __iomem *base = map->base; switch (map->reg_type) { case CXL_REGLOC_RBI_COMPONENT: @@ -442,7 +444,6 @@ static void cxl_decode_regblock(u32 reg_lo, u32 reg_hi, */ static int cxl_pci_setup_regs(struct cxl_mem *cxlm) { - void __iomem *base; u32 regloc_size, regblocks; int regloc, i, n_maps, ret = 0; struct device *dev = cxlm->dev; @@ -475,12 +476,12 @@ static int cxl_pci_setup_regs(struct cxl_mem *cxlm) if (map->reg_type > CXL_REGLOC_RBI_MEMDEV) continue; - base = cxl_pci_map_regblock(pdev, map); - if (!base) - return -ENOMEM; + ret = cxl_map_regblock(pdev, map); + if (ret) + return ret; - ret = cxl_probe_regs(pdev, base + map->block_offset, map); - cxl_pci_unmap_regblock(pdev, base); + ret = cxl_probe_regs(pdev, map); + cxl_unmap_regblock(pdev, map); if (ret) return ret;
In addition to carrying @barno, @block_offset, and @reg_type, add @base to keep all map/unmap parameters in one object. The helpers cxl_{map,unmap}_regblock() handle adjusting @base to the @block_offset at map and unmap time. Signed-off-by: Dan Williams <dan.j.williams@intel.com> --- drivers/cxl/cxl.h | 1 + drivers/cxl/pci.c | 31 ++++++++++++++++--------------- 2 files changed, 17 insertions(+), 15 deletions(-)