Skip to contentSkip to conversation

dmaengine: amd: Replace deprecated PCI functions

PATCH In review Philipp Stanner 3 participants 5 messages Feb 3

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dmaengine: amd: Replace deprecated PCI functions

ae4dma and ptdma make use of pcim_iomap_table(), a deprecated, problematic PCI function.

Both drivers currently request all IORESOURCE_MEM BARs, and ioremap only a single bar.

Replace the deprecated function while keeping the aforementioned behavior identical.

---
If it's deemed unnecessary to do the region requests, we could further simplify the code.

Compiled, not tested.

P.

---
 drivers/dma/amd/ae4dma/ae4dma-pci.c | 17 +++++++++++------
 drivers/dma/amd/ptdma/ptdma-pci.c   | 27 ++++++++++++---------------
 2 files changed, 23 insertions(+), 21 deletions(-)
drivers/dma/amd/ae4dma/ae4dma-pci.c +11 -6
index 2c63907db228..872011d4dd37 100644
@@ -10,6 +10,8 @@
 
 #include "ae4dma.h"
 
+#define DRIVER_NAME "ae4dma"
+
 static int ae4_get_irqs(struct ae4_device *ae4)
 {
 	struct ae4_msix *ae4_msix = ae4->ae4_msix;
@@ -75,9 +77,10 @@ static int ae4_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 {
 	struct device *dev = &pdev->dev;
 	struct ae4_device *ae4;
+	unsigned long bar_mask
 	struct pt_device *pt;
-	int bar_mask;
 	int ret = 0;
+	int bar;
 
 	ae4 = devm_kzalloc(dev, sizeof(*ae4), GFP_KERNEL);
 	if (!ae4)
@@ -92,15 +95,17 @@ static int ae4_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 		goto ae4_error;
 
 	bar_mask = pci_select_bars(pdev, IORESOURCE_MEM);
-	ret = pcim_iomap_regions(pdev, bar_mask, "ae4dma");
-	if (ret)
-		goto ae4_error;
+	for_each_set_bit(bar, &bar_mask, sizeof(bar_mask)) {
+		ret = pcim_request_region(pdev, bar, DRIVER_NAME);
+		if (ret)
+			goto ae4_error;
+	}
 
 	pt = &ae4->pt;
 	pt->dev = dev;
 	pt->ver = AE4_DMA_VERSION;
 
-	pt->io_regs = pcim_iomap_table(pdev)[0];
+	pt->io_regs = pcim_iomap(pdev, 0, 0);
 	if (!pt->io_regs) {
 		ret = -ENOMEM;
 		goto ae4_error;
@@ -144,7 +149,7 @@ static const struct pci_device_id ae4_pci_table[] = {
 MODULE_DEVICE_TABLE(pci, ae4_pci_table);
 
 static struct pci_driver ae4_pci_driver = {
-	.name = "ae4dma",
+	.name = DRIVER_NAME,
 	.id_table = ae4_pci_table,
 	.probe = ae4_pci_probe,
 	.remove = ae4_pci_remove,
drivers/dma/amd/ptdma/ptdma-pci.c +12 -15
index 22739ff0c3c5..d1c1c14b9292 100644
@@ -23,6 +23,8 @@
 
 #include "ptdma.h"
 
+#define DRIVER_NAME ptdma
+
 struct pt_msix {
 	int msix_count;
 	struct msix_entry msix_entry;
@@ -123,9 +125,9 @@ static int pt_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	struct pt_device *pt;
 	struct pt_msix *pt_msix;
 	struct device *dev = &pdev->dev;
-	void __iomem * const *iomap_table;
-	int bar_mask;
+	unsigned long bar_mask;
 	int ret = -ENOMEM;
+	int bar;
 
 	pt = pt_alloc_struct(dev);
 	if (!pt)
@@ -150,20 +152,15 @@ static int pt_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	}
 
 	bar_mask = pci_select_bars(pdev, IORESOURCE_MEM);
-	ret = pcim_iomap_regions(pdev, bar_mask, "ptdma");
-	if (ret) {
-		dev_err(dev, "pcim_iomap_regions failed (%d)\n", ret);
-		goto e_err;
+	for_each_set_bit(bar, &bar_mask, sizeof(bar_mask)) {
+		ret = pcim_request_region(pdev, bar, DRIVER_NAME);
+		if (ret) {
+			dev_err(dev, "pcim_iomap_regions failed (%d)\n", ret);
+			goto e_err;
+		}
 	}
 
-	iomap_table = pcim_iomap_table(pdev);
-	if (!iomap_table) {
-		dev_err(dev, "pcim_iomap_table failed\n");
-		ret = -ENOMEM;
-		goto e_err;
-	}
-
-	pt->io_regs = iomap_table[pt->dev_vdata->bar];
+	pt->io_regs = pcim_iomap(pdev, pt->dev_vdata->bar, 0);
 	if (!pt->io_regs) {
 		dev_err(dev, "ioremap failed\n");
 		ret = -ENOMEM;
@@ -230,7 +227,7 @@ static const struct pci_device_id pt_pci_table[] = {
 MODULE_DEVICE_TABLE(pci, pt_pci_table);
 
 static struct pci_driver pt_pci_driver = {
-	.name = "ptdma",
+	.name = DRIVER_NAME,
 	.id_table = pt_pci_table,
 	.probe = pt_pci_probe,
 	.remove = pt_pci_remove,
Signature · 1 line
2.49.0
#1 lore raw
Quoted 83 lines · Philipp Stanner

ae4dma and ptdma make use of pcim_iomap_table(), a deprecated, problematic PCI function.

Both drivers currently request all IORESOURCE_MEM BARs, and ioremap only a single bar.

Replace the deprecated function while keeping the aforementioned behavior identical.

---
If it's deemed unnecessary to do the region requests, we could further simplify the code.

Compiled, not tested.

P.
---
 drivers/dma/amd/ae4dma/ae4dma-pci.c | 17 +++++++++++------ drivers/dma/amd/ptdma/ptdma-pci.c   | 27 ++++++++++++---------------

 2 files changed, 23 insertions(+), 21 deletions(-)
drivers/dma/amd/ae4dma/ae4dma-pci.c +0 -0
index 2c63907db228..872011d4dd37 100644
@@ -10,6 +10,8 @@


 #include "ae4dma.h"

drivers/dma/amd/ae4dma/ae4dma-pci.c +2 -0
+#define DRIVER_NAME "ae4dma"
+

 static int ae4_get_irqs(struct ae4_device *ae4) {
  struct ae4_msix *ae4_msix = ae4->ae4_msix;

drivers/dma/amd/ae4dma/ae4dma-pci.c +2 -1
@@ -75,9 +77,10 @@ static int ae4_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  {
  	struct device *dev = &pdev->dev;
  	struct ae4_device *ae4;
+	unsigned long bar_mask
  	struct pt_device *pt;
-	int bar_mask;
  	int ret = 0;
+	int bar;


  ae4 = devm_kzalloc(dev, sizeof(*ae4), GFP_KERNEL); if (!ae4)

drivers/dma/amd/ae4dma/ae4dma-pci.c +0 -0
@@ -92,15 +95,17 @@ static int ae4_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  		goto ae4_error;


  bar_mask = pci_select_bars(pdev, IORESOURCE_MEM);

drivers/dma/amd/ae4dma/ae4dma-pci.c +5 -3
-	ret = pcim_iomap_regions(pdev, bar_mask, "ae4dma");
-	if (ret)
-		goto ae4_error;
+	for_each_set_bit(bar, &bar_mask, sizeof(bar_mask)) {
+		ret = pcim_request_region(pdev, bar, DRIVER_NAME);
+		if (ret)
+			goto ae4_error;
+	}


  pt = &ae4->pt;
  pt->dev = dev;
  pt->ver = AE4_DMA_VERSION;

drivers/dma/amd/ae4dma/ae4dma-pci.c +1 -1
-	pt->io_regs = pcim_iomap_table(pdev)[0];
+	pt->io_regs = pcim_iomap(pdev, 0, 0);

  if (!pt->io_regs) {
  ret = -ENOMEM;
  goto ae4_error;

drivers/dma/amd/ae4dma/ae4dma-pci.c +0 -0
@@ -144,7 +149,7 @@ static const struct pci_device_id ae4_pci_table[] = {
  MODULE_DEVICE_TABLE(pci, ae4_pci_table);


 static struct pci_driver ae4_pci_driver = {

drivers/dma/amd/ae4dma/ae4dma-pci.c +1 -1
-	.name = "ae4dma",
+	.name = DRIVER_NAME,

  .id_table = ae4_pci_table,
  .probe = ae4_pci_probe,
  .remove = ae4_pci_remove,

drivers/dma/amd/ptdma/ptdma-pci.c +0 -0
index 22739ff0c3c5..d1c1c14b9292 100644
@@ -23,6 +23,8 @@
Quoted 4 lines


 #include "ptdma.h"

+#define DRIVER_NAME ptdma

Oh, please ignore that patch – I hadn't checked the fix for this in accidentally. Will provide v2…

Sorry,
P.

Quoted 53 lines

+
 struct pt_msix {
  int msix_count;
  struct msix_entry msix_entry;

drivers/dma/amd/ptdma/ptdma-pci.c +2 -2
@@ -123,9 +125,9 @@ static int pt_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  	struct pt_device *pt;
  	struct pt_msix *pt_msix;
  	struct device *dev = &pdev->dev;
-	void __iomem * const *iomap_table;
-	int bar_mask;
+	unsigned long bar_mask;
  	int ret = -ENOMEM;
+	int bar;


  pt = pt_alloc_struct(dev);
  if (!pt)

drivers/dma/amd/ptdma/ptdma-pci.c +0 -0
@@ -150,20 +152,15 @@ static int pt_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  	}


  bar_mask = pci_select_bars(pdev, IORESOURCE_MEM);

drivers/dma/amd/ptdma/ptdma-pci.c +6 -4
-	ret = pcim_iomap_regions(pdev, bar_mask, "ptdma");
-	if (ret) {
-		dev_err(dev, "pcim_iomap_regions failed (%d)\n", ret);
-		goto e_err;
+	for_each_set_bit(bar, &bar_mask, sizeof(bar_mask)) {
+		ret = pcim_request_region(pdev, bar, DRIVER_NAME);
+		if (ret) {
+			dev_err(dev, "pcim_iomap_regions failed (%d)\n", ret);
+			goto e_err;
+		}

  }

drivers/dma/amd/ptdma/ptdma-pci.c +1 -8
-	iomap_table = pcim_iomap_table(pdev);
-	if (!iomap_table) {
-		dev_err(dev, "pcim_iomap_table failed\n");
-		ret = -ENOMEM;
-		goto e_err;
-	}
-
-	pt->io_regs = iomap_table[pt->dev_vdata->bar];
+	pt->io_regs = pcim_iomap(pdev, pt->dev_vdata->bar, 0);

  if (!pt->io_regs) {
  dev_err(dev, "ioremap failed\n");
  ret = -ENOMEM;

drivers/dma/amd/ptdma/ptdma-pci.c +0 -0
@@ -230,7 +227,7 @@ static const struct pci_device_id pt_pci_table[] = {
  MODULE_DEVICE_TABLE(pci, pt_pci_table);


 static struct pci_driver pt_pci_driver = {

drivers/dma/amd/ptdma/ptdma-pci.c +1 -1
-	.name = "ptdma",
+	.name = DRIVER_NAME,

  .id_table = pt_pci_table,
  .probe = pt_pci_probe,
  .remove = pt_pci_remove,

#2 lore raw
In reply to Philipp Stanner
kernel test robot noticed the following build errors:

Hi Philipp,

kernel test robot noticed the following build errors:

[auto build test ERROR on vkoul-dmaengine/next]
[also build test ERROR on linus/master v6.19-rc8 next-20260202] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Philipp-Stanner/dmaengine-amd-Replace-deprecated-PCI-functions/20260203-204040
base:   https://git.kernel.org/pub/scm/linux/kernel/git/vkoul/dmaengine.git next
patch link:    https://lore.kernel.org/r/20260203123238.88598-2-phasta%40kernel.org
patch subject: [PATCH] dmaengine: amd: Replace deprecated PCI functions
config: x86_64-rhel-9.4 (https://download.01.org/0day-ci/archive/20260203/[email protected]/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260203/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

drivers/dma/amd/ptdma/ptdma-pci.c: In function 'pt_pci_probe':

>> drivers/dma/amd/ptdma/ptdma-pci.c:26:21: error: 'ptdma' undeclared (first use in this function)
      26 | #define DRIVER_NAME ptdma
         |                     ^~~~~
   drivers/dma/amd/ptdma/ptdma-pci.c:156:54: note: in expansion of macro 'DRIVER_NAME'
     156 |                 ret = pcim_request_region(pdev, bar, DRIVER_NAME);
         |                                                      ^~~~~~~~~~~
   drivers/dma/amd/ptdma/ptdma-pci.c:26:21: note: each undeclared identifier is reported only once for each function it appears in
      26 | #define DRIVER_NAME ptdma
         |                     ^~~~~
   drivers/dma/amd/ptdma/ptdma-pci.c:156:54: note: in expansion of macro 'DRIVER_NAME'
     156 |                 ret = pcim_request_region(pdev, bar, DRIVER_NAME);
         |                                                      ^~~~~~~~~~~
   drivers/dma/amd/ptdma/ptdma-pci.c: At top level:
>> drivers/dma/amd/ptdma/ptdma-pci.c:26:21: error: 'ptdma' undeclared here (not in a function)

26 | #define DRIVER_NAME ptdma
| ^~~~~
drivers/dma/amd/ptdma/ptdma-pci.c:230:17: note: in expansion of macro 'DRIVER_NAME'
230 | .name = DRIVER_NAME,
| ^~~~~~~~~~~

vim +/ptdma +26 drivers/dma/amd/ptdma/ptdma-pci.c

    25	
  > 26	#define DRIVER_NAME ptdma
    27	
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#3 lore raw
In reply to Philipp Stanner
kernel test robot noticed the following build errors:

Hi Philipp,

kernel test robot noticed the following build errors:

[auto build test ERROR on vkoul-dmaengine/next]
[also build test ERROR on linus/master v6.19-rc8 next-20260202] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Philipp-Stanner/dmaengine-amd-Replace-deprecated-PCI-functions/20260203-204040
base:   https://git.kernel.org/pub/scm/linux/kernel/git/vkoul/dmaengine.git next
patch link:    https://lore.kernel.org/r/20260203123238.88598-2-phasta%40kernel.org
patch subject: [PATCH] dmaengine: amd: Replace deprecated PCI functions
config: um-allmodconfig (https://download.01.org/0day-ci/archive/20260204/[email protected]/config)
compiler: clang version 19.1.7 (https://github.com/llvm/llvm-project cd708029e0b2869e80abe31ddb175f7c35361f90)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260204/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

In file included from drivers/dma/amd/ae4dma/ae4dma-pci.c:11:
In file included from drivers/dma/amd/ae4dma/ae4dma.h:14:
In file included from include/linux/dmaengine.h:12:
In file included from include/linux/scatterlist.h:9:
In file included from arch/um/include/asm/io.h:24:
include/asm-generic/io.h:1209:55: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
1209 | return (port > MMIO_UPPER_LIMIT) ? NULL : PCI_IOBASE + port;
| ~~~~~~~~~~ ^

>> drivers/dma/amd/ae4dma/ae4dma-pci.c:80:24: error: expected ';' at end of declaration
      80 |         unsigned long bar_mask
         |                               ^
         |                               ;

1 warning and 1 error generated.

vim +80 drivers/dma/amd/ae4dma/ae4dma-pci.c

    75	
    76	static int ae4_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
    77	{
    78		struct device *dev = &pdev->dev;
    79		struct ae4_device *ae4;
  > 80		unsigned long bar_mask
    81		struct pt_device *pt;
    82		int ret = 0;
    83		int bar;
    84	
    85		ae4 = devm_kzalloc(dev, sizeof(*ae4), GFP_KERNEL);
    86		if (!ae4)
    87			return -ENOMEM;
    88	
    89		ae4->ae4_msix = devm_kzalloc(dev, sizeof(struct ae4_msix), GFP_KERNEL);
    90		if (!ae4->ae4_msix)
    91			return -ENOMEM;
    92	
    93		ret = pcim_enable_device(pdev);
    94		if (ret)
    95			goto ae4_error;
    96	
    97		bar_mask = pci_select_bars(pdev, IORESOURCE_MEM);
    98		for_each_set_bit(bar, &bar_mask, sizeof(bar_mask)) {
    99			ret = pcim_request_region(pdev, bar, DRIVER_NAME);

100 if (ret)
101 goto ae4_error;
102 }
103
104 pt = &ae4->pt;
105 pt->dev = dev;
106 pt->ver = AE4_DMA_VERSION;
107
108 pt->io_regs = pcim_iomap(pdev, 0, 0);
109 if (!pt->io_regs) {
110 ret = -ENOMEM;
111 goto ae4_error;
112 }
113
114 ret = ae4_get_irqs(ae4);
115 if (ret < 0)
116 goto ae4_error;
117
118 pci_set_master(pdev);
119
120 dma_set_mask_and_coherent(dev, DMA_BIT_MASK(48));
121
122 dev_set_drvdata(dev, ae4);
123
124 ret = ae4_core_init(ae4);
125 if (ret)
126 goto ae4_error;
127
128 return 0;
129
130 ae4_error:
131 ae4_deinit(ae4);
132
133 return ret;
134 }
135

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#4 lore raw
In reply to Philipp Stanner
kernel test robot noticed the following build errors:

Hi Philipp,

kernel test robot noticed the following build errors:

[auto build test ERROR on vkoul-dmaengine/next]
[also build test ERROR on linus/master v6.19-rc8 next-20260202] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Philipp-Stanner/dmaengine-amd-Replace-deprecated-PCI-functions/20260203-204040
base:   https://git.kernel.org/pub/scm/linux/kernel/git/vkoul/dmaengine.git next
patch link:    https://lore.kernel.org/r/20260203123238.88598-2-phasta%40kernel.org
patch subject: [PATCH] dmaengine: amd: Replace deprecated PCI functions
config: x86_64-rhel-9.4-rust (https://download.01.org/0day-ci/archive/20260204/[email protected]/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
rustc: rustc 1.88.0 (6b00bc388 2025-06-23)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260204/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> drivers/dma/amd/ptdma/ptdma-pci.c:156:40: error: use of undeclared identifier 'ptdma'
     156 |                 ret = pcim_request_region(pdev, bar, DRIVER_NAME);
         |                                                      ^

drivers/dma/amd/ptdma/ptdma-pci.c:26:21: note: expanded from macro 'DRIVER_NAME'
26 | #define DRIVER_NAME ptdma
| ^
drivers/dma/amd/ptdma/ptdma-pci.c:230:10: error: use of undeclared identifier 'ptdma'
230 | .name = DRIVER_NAME,
| ^
drivers/dma/amd/ptdma/ptdma-pci.c:26:21: note: expanded from macro 'DRIVER_NAME'
26 | #define DRIVER_NAME ptdma
| ^
2 errors generated.

vim +/ptdma +156 drivers/dma/amd/ptdma/ptdma-pci.c

122
123 static int pt_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
124 {
125 struct pt_device *pt;
126 struct pt_msix *pt_msix;
127 struct device *dev = &pdev->dev;
128 unsigned long bar_mask;
129 int ret = -ENOMEM;
130 int bar;
131
132 pt = pt_alloc_struct(dev);
133 if (!pt)
134 goto e_err;
135
136 pt_msix = devm_kzalloc(dev, sizeof(*pt_msix), GFP_KERNEL);
137 if (!pt_msix)
138 goto e_err;
139
140 pt->pt_msix = pt_msix;
141 pt->dev_vdata = (struct pt_dev_vdata *)id->driver_data;
142 if (!pt->dev_vdata) {
143 ret = -ENODEV;
144 dev_err(dev, "missing driver data\n");
145 goto e_err;
146 }
147
148 ret = pcim_enable_device(pdev);
149 if (ret) {
150 dev_err(dev, "pcim_enable_device failed (%d)\n", ret);
151 goto e_err;
152 }
153
154 bar_mask = pci_select_bars(pdev, IORESOURCE_MEM);
155 for_each_set_bit(bar, &bar_mask, sizeof(bar_mask)) {

 > 156			ret = pcim_request_region(pdev, bar, DRIVER_NAME);

157 if (ret) {
158 dev_err(dev, "pcim_iomap_regions failed (%d)\n", ret);
159 goto e_err;
160 }
161 }
162
163 pt->io_regs = pcim_iomap(pdev, pt->dev_vdata->bar, 0);
164 if (!pt->io_regs) {
165 dev_err(dev, "ioremap failed\n");
166 ret = -ENOMEM;
167 goto e_err;
168 }
169
170 ret = pt_get_irqs(pt);
171 if (ret)
172 goto e_err;
173
174 pci_set_master(pdev);
175
176 ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(48));
177 if (ret) {
178 ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32));
179 if (ret) {
180 dev_err(dev, "dma_set_mask_and_coherent failed (%d)\n",
181 ret);
182 goto e_err;
183 }
184 }
185
186 dev_set_drvdata(dev, pt);
187
188 if (pt->dev_vdata)
189 ret = pt_core_init(pt);
190
191 if (ret)
192 goto e_err;
193
194 return 0;
195
196 e_err:
197 dev_err(dev, "initialization failed ret = %d\n", ret);
198
199 return ret;
200 }
201

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki