PCI: Deprecate pcim_iomap_regions() in favor of pcim_iomap_region()
Subsystems (4)
PATCH 1/2 PCI: Deprecate pcim_iomap_regions() in favor of pcim_iomap_region()
pcim_iomap_regions() is a complicated function that uses a bit mask to determine the BARs the user wishes to request and ioremap. Almost all users only ever set a single bit in that mask, making that mechanism questionable.
pcim_iomap_region() is now available as a more simple replacement.
Make pcim_iomap_region() a public function.
Mark pcim_iomap_regions() as deprecated.
--- drivers/pci/devres.c | 8 ++++++-- include/linux/pci.h | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-)
drivers/pci/devres.c +6 -2
@@ -728,7 +728,7 @@ EXPORT_SYMBOL(pcim_iounmap);* Mapping and region will get automatically released on driver detach. If * desired, release manually only with pcim_iounmap_region(). */ -static void __iomem *pcim_iomap_region (struct pci_dev *pdev,int bar, +void __iomem *pcim_iomap_region (struct pci_dev *pdev,int bar,const char *name) {int ret;
@@ -761,6 +761,7 @@ static void __iomem *pcim_iomap_region(struct pci_dev *pdev, int bar,return IOMEM_ERR_PTR (ret); } +EXPORT_SYMBOL (pcim_iomap_region);/** * pcim_iounmap_region - Unmap and release a PCI BAR
@@ -783,7 +784,7 @@ static void pcim_iounmap_region(struct pci_dev *pdev, int bar) }/** -* pcim_iomap_regions - Request and iomap PCI BARs +* pcim_iomap_regions - Request and iomap PCI BARs (DEPRECATED) * @pdev: PCI device to map IO resources for * @mask: Mask of BARs to request and iomap * @name: Name associated with the requests
@@ -791,6 +792,9 @@ static void pcim_iounmap_region(struct pci_dev *pdev, int bar)* Returns: 0 on success, negative error code on failure. * * Request and iomap regions specified by @mask. +* +* This function is DEPRECATED. Do not use it in new code. +* Use pcim_iomap_region() instead. */ int pcim_iomap_regions (struct pci_dev *pdev,int mask,const char *name) {
include/linux/pci.h +2 -0
@@ -2292,6 +2292,8 @@ static inline void pci_fixup_device(enum pci_fixup_pass pass,void __iomem *pcim_iomap (struct pci_dev *pdev,int bar,unsigned long maxlen);void pcim_iounmap (struct pci_dev *pdev,void __iomem *addr);void __iomem *const *pcim_iomap_table (struct pci_dev *pdev); +void __iomem *pcim_iomap_region (struct pci_dev *pdev,int bar, +const char *name);int pcim_iomap_regions (struct pci_dev *pdev,int mask,const char *name);int pcim_iomap_regions_request_all (struct pci_dev *pdev,int mask,const char *name);
Signature · 1 line
2.45.2
PATCH 2/2 drm/ast: Request PCI BAR with devres
ast currently ioremaps two PCI BARs using pcim_iomap(). It does not perform a request on the regions, however, which would make the driver a bit more robust.
PCI now offers pcim_iomap_region(), a managed function which both requests and ioremaps a BAR.
Replace pcim_iomap() with pcim_iomap_region().
--- drivers/gpu/drm/ast/ast_drv.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/gpu/drm/ast/ast_drv.c +6 -6
@@ -287,9 +287,9 @@ static int ast_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)if (ret)return ret; - regs =pcim_iomap (pdev,1 ,0 ); -if (!regs) -return -EIO ; + regs =pcim_iomap_region (pdev,1 ,"ast" ); +if (IS_ERR (regs)) +return PTR_ERR (regs);if (pdev->revision >=0x40 ) {/*
@@ -311,9 +311,9 @@ static int ast_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)if (len <AST_IO_MM_LENGTH )return -EIO ; - ioregs =pcim_iomap (pdev,2 ,0 ); -if (!ioregs) -return -EIO ; + ioregs =pcim_iomap_region (pdev,2 ,"ast" ); +if (IS_ERR (ioregs)) +return PTR_ERR (ioregs); }else {/* * Anything else is best effort.
Signature · 1 line
2.45.2
Re: [PATCH 2/2] drm/ast: Request PCI BAR with devres
Am 07.08.24 um 10:30 schrieb Philipp Stanner:
Quoted 11 lines
ast currently ioremaps two PCI BARs using
pcim_iomap(). It does not perform a request on the regions, however, which would make the driver a bit more robust.PCI now offers
pcim_iomap_region(), a managed function which both requests and ioremaps a BAR.Replace
pcim_iomap()withpcim_iomap_region().Suggested-by Thomas Zimmermann <[email protected]>Signed-off-by Philipp Stanner <[email protected]>
Quoted 34 lines
--- drivers/gpu/drm/ast/ast_drv.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)drivers/gpu/drm/ast/ast_drv.c +6
-6@@ -287,9 +287,9 @@ static int ast_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)if (ret)return ret; - regs =pcim_iomap (pdev,1 ,0 ); -if (!regs) -return -EIO ; + regs =pcim_iomap_region (pdev,1 ,"ast" ); +if (IS_ERR (regs)) +return PTR_ERR (regs);if (pdev->revision >=0x40 ) {/* @@ -311,9 +311,9 @@ static int ast_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)if (len <AST_IO_MM_LENGTH )return -EIO ; - ioregs =pcim_iomap (pdev,2 ,0 ); -if (!ioregs) -return -EIO ; + ioregs =pcim_iomap_region (pdev,2 ,"ast" ); +if (IS_ERR (ioregs)) +return PTR_ERR (ioregs); }else {/* * Anything else is best effort.
Signature · 7 lines
-- Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Frankenstrasse 146, 90461 Nuernberg, Germany GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman HRB 36809 (AG Nuernberg)
Quoted 5 lines · Philipp Stanner
pcim_iomap_regions()is a complicated function that uses a bit mask to determine the BARs the user wishes to request and ioremap. Almost all users only ever set a single bit in that mask, making that mechanism questionable.
Quoted 7 lines
pcim_iomap_region()is now available as a more simple replacement.Make
pcim_iomap_region()a public function.Mark
pcim_iomap_regions()as deprecated.Signed-off-by Philipp Stanner <[email protected]>
The interesting part of this little series is in ast_drv.c, but there may be similar conversions for other drivers coming as well.
To avoid races during the merge window, I propose merging this via the PCI tree so I can ensure that any other conversions happen after pcim_iomap_region() becomes public.
That would require an ack from Dave. But if you'd rather take this yourself, Dave, here's my ack for the PCI piece:
Quoted 61 lines
--- drivers/pci/devres.c | 8 ++++++-- include/linux/pci.h | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-)drivers/pci/devres.c +6
-2@@ -728,7 +728,7 @@ EXPORT_SYMBOL(pcim_iounmap);* Mapping and region will get automatically released on driver detach. If * desired, release manually only with pcim_iounmap_region(). */ -static void __iomem *pcim_iomap_region (struct pci_dev *pdev,int bar, +void __iomem *pcim_iomap_region (struct pci_dev *pdev,int bar,const char *name) {int ret;@@ -761,6 +761,7 @@ static void __iomem *pcim_iomap_region(struct pci_dev *pdev, int bar,return IOMEM_ERR_PTR (ret); } +EXPORT_SYMBOL (pcim_iomap_region);/** * pcim_iounmap_region - Unmap and release a PCI BAR @@ -783,7 +784,7 @@ static void pcim_iounmap_region(struct pci_dev *pdev, int bar) }/** -* pcim_iomap_regions - Request and iomap PCI BARs +* pcim_iomap_regions - Request and iomap PCI BARs (DEPRECATED) * @pdev: PCI device to map IO resources for * @mask: Mask of BARs to request and iomap * @name: Name associated with the requests @@ -791,6 +792,9 @@ static void pcim_iounmap_region(struct pci_dev *pdev, int bar)* Returns: 0 on success, negative error code on failure. * * Request and iomap regions specified by @mask. +* +* This function is DEPRECATED. Do not use it in new code. +* Use pcim_iomap_region() instead. */ int pcim_iomap_regions (struct pci_dev *pdev,int mask,const char *name) {include/linux/pci.h +2
-0@@ -2292,6 +2292,8 @@ static inline void pci_fixup_device(enum pci_fixup_pass pass,void __iomem *pcim_iomap (struct pci_dev *pdev,int bar,unsigned long maxlen);void pcim_iounmap (struct pci_dev *pdev,void __iomem *addr);void __iomem *const *pcim_iomap_table (struct pci_dev *pdev); +void __iomem *pcim_iomap_region (struct pci_dev *pdev,int bar, +const char *name);int pcim_iomap_regions (struct pci_dev *pdev,int mask,const char *name);int pcim_iomap_regions_request_all (struct pci_dev *pdev,int mask,const char *name);Signature · 1 line
2.45.2
Quoted 18 lines · Bjorn Helgaas
Quoted 5 lines · Philipp Stanner
pcim_iomap_regions()is a complicated function that uses a bit mask to determine the BARs the user wishes to request and ioremap. Almost all users only ever set a single bit in that mask, making that mechanism questionable.Quoted 7 lines
pcim_iomap_region()is now available as a more simple replacement.Make
pcim_iomap_region()a public function.Mark
pcim_iomap_regions()as deprecated.Signed-off-by Philipp Stanner <[email protected]>The interesting part of this little series is in
ast_drv.c, but there may be similar conversions for other drivers coming as well.
Quoted 8 lines
To avoid races during the merge window, I propose merging this via the PCI tree so I can ensure that any other conversions happen after
pcim_iomap_region()becomes public.That would require an ack from Dave. But if you'd rather take this yourself, Dave, here's my ack for the PCI piece:
Acked-by Bjorn Helgaas <[email protected]>
I'm fine with it going in via pci.
Dave.
Quoted 63 lines
Quoted 62 lines
--- drivers/pci/devres.c | 8 ++++++-- include/linux/pci.h | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-)drivers/pci/devres.c +6
-2@@ -728,7 +728,7 @@ EXPORT_SYMBOL(pcim_iounmap);* Mapping and region will get automatically released on driver detach. If * desired, release manually only with pcim_iounmap_region(). */ -static void __iomem *pcim_iomap_region (struct pci_dev *pdev,int bar, +void __iomem *pcim_iomap_region (struct pci_dev *pdev,int bar,const char *name) {int ret;@@ -761,6 +761,7 @@ static void __iomem *pcim_iomap_region(struct pci_dev *pdev, int bar,return IOMEM_ERR_PTR (ret); } +EXPORT_SYMBOL (pcim_iomap_region);/** * pcim_iounmap_region - Unmap and release a PCI BAR @@ -783,7 +784,7 @@ static void pcim_iounmap_region(struct pci_dev *pdev, int bar) }/** -* pcim_iomap_regions - Request and iomap PCI BARs +* pcim_iomap_regions - Request and iomap PCI BARs (DEPRECATED) * @pdev: PCI device to map IO resources for * @mask: Mask of BARs to request and iomap * @name: Name associated with the requests @@ -791,6 +792,9 @@ static void pcim_iounmap_region(struct pci_dev *pdev, int bar)* Returns: 0 on success, negative error code on failure. * * Request and iomap regions specified by @mask. +* +* This function is DEPRECATED. Do not use it in new code. +* Use pcim_iomap_region() instead. */ int pcim_iomap_regions (struct pci_dev *pdev,int mask,const char *name) {include/linux/pci.h +2
-1@@ -2292,6 +2292,8 @@ static inline void pci_fixup_device(enum pci_fixup_pass pass,void __iomem *pcim_iomap (struct pci_dev *pdev,int bar,unsigned long maxlen);void pcim_iounmap (struct pci_dev *pdev,void __iomem *addr);void __iomem *const *pcim_iomap_table (struct pci_dev *pdev); +void __iomem *pcim_iomap_region (struct pci_dev *pdev,int bar, +const char *name);int pcim_iomap_regions (struct pci_dev *pdev,int mask,const char *name);int pcim_iomap_regions_request_all (struct pci_dev *pdev,int mask,const char *name); --2.45.2
Quoted 5 lines · Philipp Stanner
pcim_iomap_regions()is a complicated function that uses a bit mask to determine the BARs the user wishes to request and ioremap. Almost all users only ever set a single bit in that mask, making that mechanism questionable.
Quoted 7 lines
pcim_iomap_region()is now available as a more simple replacement.Make
pcim_iomap_region()a public function.Mark
pcim_iomap_regions()as deprecated.Signed-off-by Philipp Stanner <[email protected]>
Both applied (second with Thomas' reviewed-by and Dave's ack) to pci/devres for v6.12, thanks!
Quoted 61 lines
--- drivers/pci/devres.c | 8 ++++++-- include/linux/pci.h | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-)drivers/pci/devres.c +6
-2@@ -728,7 +728,7 @@ EXPORT_SYMBOL(pcim_iounmap);* Mapping and region will get automatically released on driver detach. If * desired, release manually only with pcim_iounmap_region(). */ -static void __iomem *pcim_iomap_region (struct pci_dev *pdev,int bar, +void __iomem *pcim_iomap_region (struct pci_dev *pdev,int bar,const char *name) {int ret;@@ -761,6 +761,7 @@ static void __iomem *pcim_iomap_region(struct pci_dev *pdev, int bar,return IOMEM_ERR_PTR (ret); } +EXPORT_SYMBOL (pcim_iomap_region);/** * pcim_iounmap_region - Unmap and release a PCI BAR @@ -783,7 +784,7 @@ static void pcim_iounmap_region(struct pci_dev *pdev, int bar) }/** -* pcim_iomap_regions - Request and iomap PCI BARs +* pcim_iomap_regions - Request and iomap PCI BARs (DEPRECATED) * @pdev: PCI device to map IO resources for * @mask: Mask of BARs to request and iomap * @name: Name associated with the requests @@ -791,6 +792,9 @@ static void pcim_iounmap_region(struct pci_dev *pdev, int bar)* Returns: 0 on success, negative error code on failure. * * Request and iomap regions specified by @mask. +* +* This function is DEPRECATED. Do not use it in new code. +* Use pcim_iomap_region() instead. */ int pcim_iomap_regions (struct pci_dev *pdev,int mask,const char *name) {include/linux/pci.h +2
-0@@ -2292,6 +2292,8 @@ static inline void pci_fixup_device(enum pci_fixup_pass pass,void __iomem *pcim_iomap (struct pci_dev *pdev,int bar,unsigned long maxlen);void pcim_iounmap (struct pci_dev *pdev,void __iomem *addr);void __iomem *const *pcim_iomap_table (struct pci_dev *pdev); +void __iomem *pcim_iomap_region (struct pci_dev *pdev,int bar, +const char *name);int pcim_iomap_regions (struct pci_dev *pdev,int mask,const char *name);int pcim_iomap_regions_request_all (struct pci_dev *pdev,int mask,const char *name);Signature · 1 line
2.45.2