Skip to content

Commit f56278a

Browse files
committed
Merge branch 'pci/devres'
- Remove mtip32xx use of pcim_iounmap_regions(), which is deprecated and unnecessary (Philipp Stanner) - Remove pcim_iounmap_regions() and pcim_request_region_exclusive() and related flags since all uses have been removed (Philipp Stanner) - Rework devres 'request' functions so they are no longer 'hybrid', i.e., their behavior no longer depends on whether pcim_enable_device or pci_enable_device() was used, and remove related code (Philipp Stanner) * pci/devres: PCI: Remove function pcim_intx() prototype from pci.h PCI: Remove hybrid-devres usage warnings from kernel-doc PCI: Remove redundant set of request functions PCI: Remove exclusive requests flags from _pcim_request_region() PCI: Remove pcim_request_region_exclusive() Documentation/driver-api: Update pcim_enable_device() PCI: Remove hybrid devres nature from request functions PCI: Remove pcim_iounmap_regions() mtip32xx: Remove unnecessary pcim_iounmap_regions() calls
2 parents 1acf6a5 + dfc970a commit f56278a

File tree

7 files changed

+29
-260
lines changed

7 files changed

+29
-260
lines changed

Documentation/driver-api/driver-model/devres.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,12 +391,11 @@ PCI
391391
devm_pci_remap_cfgspace() : ioremap PCI configuration space
392392
devm_pci_remap_cfg_resource() : ioremap PCI configuration space resource
393393

394-
pcim_enable_device() : after success, some PCI ops become managed
394+
pcim_enable_device() : after success, the PCI device gets disabled automatically on driver detach
395395
pcim_iomap() : do iomap() on a single BAR
396396
pcim_iomap_regions() : do request_region() and iomap() on multiple BARs
397397
pcim_iomap_table() : array of mapped addresses indexed by BAR
398398
pcim_iounmap() : do iounmap() on a single BAR
399-
pcim_iounmap_regions() : do iounmap() and release_region() on multiple BARs
400399
pcim_pin_device() : keep PCI device enabled after release
401400
pcim_set_mwi() : enable Memory-Write-Invalidate PCI transaction
402401

drivers/block/mtip32xx/mtip32xx.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3717,7 +3717,7 @@ static int mtip_pci_probe(struct pci_dev *pdev,
37173717
rv = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
37183718
if (rv) {
37193719
dev_warn(&pdev->dev, "64-bit DMA enable failed\n");
3720-
goto setmask_err;
3720+
goto iomap_err;
37213721
}
37223722

37233723
/* Copy the info we may need later into the private data structure. */
@@ -3733,7 +3733,7 @@ static int mtip_pci_probe(struct pci_dev *pdev,
37333733
if (!dd->isr_workq) {
37343734
dev_warn(&pdev->dev, "Can't create wq %d\n", dd->instance);
37353735
rv = -ENOMEM;
3736-
goto setmask_err;
3736+
goto iomap_err;
37373737
}
37383738

37393739
memset(cpu_list, 0, sizeof(cpu_list));
@@ -3830,8 +3830,6 @@ static int mtip_pci_probe(struct pci_dev *pdev,
38303830
drop_cpu(dd->work[1].cpu_binding);
38313831
drop_cpu(dd->work[2].cpu_binding);
38323832
}
3833-
setmask_err:
3834-
pcim_iounmap_regions(pdev, 1 << MTIP_ABAR);
38353833

38363834
iomap_err:
38373835
kfree(dd);
@@ -3907,7 +3905,6 @@ static void mtip_pci_remove(struct pci_dev *pdev)
39073905

39083906
pci_disable_msi(pdev);
39093907

3910-
pcim_iounmap_regions(pdev, 1 << MTIP_ABAR);
39113908
pci_set_drvdata(pdev, NULL);
39123909

39133910
put_disk(dd->disk);

drivers/pci/devres.c

Lines changed: 26 additions & 189 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,13 @@
66
/*
77
* On the state of PCI's devres implementation:
88
*
9-
* The older devres API for PCI has two significant problems:
9+
* The older PCI devres API has one significant problem:
1010
*
11-
* 1. It is very strongly tied to the statically allocated mapping table in
12-
* struct pcim_iomap_devres below. This is mostly solved in the sense of the
13-
* pcim_ functions in this file providing things like ranged mapping by
14-
* bypassing this table, whereas the functions that were present in the old
15-
* API still enter the mapping addresses into the table for users of the old
16-
* API.
17-
*
18-
* 2. The region-request-functions in pci.c do become managed IF the device has
19-
* been enabled with pcim_enable_device() instead of pci_enable_device().
20-
* This resulted in the API becoming inconsistent: Some functions have an
21-
* obviously managed counter-part (e.g., pci_iomap() <-> pcim_iomap()),
22-
* whereas some don't and are never managed, while others don't and are
23-
* _sometimes_ managed (e.g. pci_request_region()).
24-
*
25-
* Consequently, in the new API, region requests performed by the pcim_
26-
* functions are automatically cleaned up through the devres callback
27-
* pcim_addr_resource_release().
28-
*
29-
* Users of pcim_enable_device() + pci_*region*() are redirected in
30-
* pci.c to the managed functions here in this file. This isn't exactly
31-
* perfect, but the only alternative way would be to port ALL drivers
32-
* using said combination to pcim_ functions.
11+
* It is very strongly tied to the statically allocated mapping table in struct
12+
* pcim_iomap_devres below. This is mostly solved in the sense of the pcim_
13+
* functions in this file providing things like ranged mapping by bypassing
14+
* this table, whereas the functions that were present in the old API still
15+
* enter the mapping addresses into the table for users of the old API.
3316
*
3417
* TODO:
3518
* Remove the legacy table entirely once all calls to pcim_iomap_table() in
@@ -87,116 +70,18 @@ static inline void pcim_addr_devres_clear(struct pcim_addr_devres *res)
8770
res->bar = -1;
8871
}
8972

90-
/*
91-
* The following functions, __pcim_*_region*, exist as counterparts to the
92-
* versions from pci.c - which, unfortunately, can be in "hybrid mode", i.e.,
93-
* sometimes managed, sometimes not.
94-
*
95-
* To separate the APIs cleanly, we define our own, simplified versions here.
96-
*/
97-
98-
/**
99-
* __pcim_request_region_range - Request a ranged region
100-
* @pdev: PCI device the region belongs to
101-
* @bar: BAR the range is within
102-
* @offset: offset from the BAR's start address
103-
* @maxlen: length in bytes, beginning at @offset
104-
* @name: name of the driver requesting the resource
105-
* @req_flags: flags for the request, e.g., for kernel-exclusive requests
106-
*
107-
* Returns: 0 on success, a negative error code on failure.
108-
*
109-
* Request a range within a device's PCI BAR. Sanity check the input.
110-
*/
111-
static int __pcim_request_region_range(struct pci_dev *pdev, int bar,
112-
unsigned long offset,
113-
unsigned long maxlen,
114-
const char *name, int req_flags)
115-
{
116-
resource_size_t start = pci_resource_start(pdev, bar);
117-
resource_size_t len = pci_resource_len(pdev, bar);
118-
unsigned long dev_flags = pci_resource_flags(pdev, bar);
119-
120-
if (start == 0 || len == 0) /* Unused BAR. */
121-
return 0;
122-
if (len <= offset)
123-
return -EINVAL;
124-
125-
start += offset;
126-
len -= offset;
127-
128-
if (len > maxlen && maxlen != 0)
129-
len = maxlen;
130-
131-
if (dev_flags & IORESOURCE_IO) {
132-
if (!request_region(start, len, name))
133-
return -EBUSY;
134-
} else if (dev_flags & IORESOURCE_MEM) {
135-
if (!__request_mem_region(start, len, name, req_flags))
136-
return -EBUSY;
137-
} else {
138-
/* That's not a device we can request anything on. */
139-
return -ENODEV;
140-
}
141-
142-
return 0;
143-
}
144-
145-
static void __pcim_release_region_range(struct pci_dev *pdev, int bar,
146-
unsigned long offset,
147-
unsigned long maxlen)
148-
{
149-
resource_size_t start = pci_resource_start(pdev, bar);
150-
resource_size_t len = pci_resource_len(pdev, bar);
151-
unsigned long flags = pci_resource_flags(pdev, bar);
152-
153-
if (len <= offset || start == 0)
154-
return;
155-
156-
if (len == 0 || maxlen == 0) /* This an unused BAR. Do nothing. */
157-
return;
158-
159-
start += offset;
160-
len -= offset;
161-
162-
if (len > maxlen)
163-
len = maxlen;
164-
165-
if (flags & IORESOURCE_IO)
166-
release_region(start, len);
167-
else if (flags & IORESOURCE_MEM)
168-
release_mem_region(start, len);
169-
}
170-
171-
static int __pcim_request_region(struct pci_dev *pdev, int bar,
172-
const char *name, int flags)
173-
{
174-
unsigned long offset = 0;
175-
unsigned long len = pci_resource_len(pdev, bar);
176-
177-
return __pcim_request_region_range(pdev, bar, offset, len, name, flags);
178-
}
179-
180-
static void __pcim_release_region(struct pci_dev *pdev, int bar)
181-
{
182-
unsigned long offset = 0;
183-
unsigned long len = pci_resource_len(pdev, bar);
184-
185-
__pcim_release_region_range(pdev, bar, offset, len);
186-
}
187-
18873
static void pcim_addr_resource_release(struct device *dev, void *resource_raw)
18974
{
19075
struct pci_dev *pdev = to_pci_dev(dev);
19176
struct pcim_addr_devres *res = resource_raw;
19277

19378
switch (res->type) {
19479
case PCIM_ADDR_DEVRES_TYPE_REGION:
195-
__pcim_release_region(pdev, res->bar);
80+
pci_release_region(pdev, res->bar);
19681
break;
19782
case PCIM_ADDR_DEVRES_TYPE_REGION_MAPPING:
19883
pci_iounmap(pdev, res->baseaddr);
199-
__pcim_release_region(pdev, res->bar);
84+
pci_release_region(pdev, res->bar);
20085
break;
20186
case PCIM_ADDR_DEVRES_TYPE_MAPPING:
20287
pci_iounmap(pdev, res->baseaddr);
@@ -735,7 +620,7 @@ void __iomem *pcim_iomap_region(struct pci_dev *pdev, int bar,
735620
res->type = PCIM_ADDR_DEVRES_TYPE_REGION_MAPPING;
736621
res->bar = bar;
737622

738-
ret = __pcim_request_region(pdev, bar, name, 0);
623+
ret = pci_request_region(pdev, bar, name);
739624
if (ret != 0)
740625
goto err_region;
741626

@@ -749,7 +634,7 @@ void __iomem *pcim_iomap_region(struct pci_dev *pdev, int bar,
749634
return res->baseaddr;
750635

751636
err_iomap:
752-
__pcim_release_region(pdev, bar);
637+
pci_release_region(pdev, bar);
753638
err_region:
754639
pcim_addr_devres_free(res);
755640

@@ -823,8 +708,20 @@ int pcim_iomap_regions(struct pci_dev *pdev, int mask, const char *name)
823708
}
824709
EXPORT_SYMBOL(pcim_iomap_regions);
825710

826-
static int _pcim_request_region(struct pci_dev *pdev, int bar, const char *name,
827-
int request_flags)
711+
/**
712+
* pcim_request_region - Request a PCI BAR
713+
* @pdev: PCI device to request region for
714+
* @bar: Index of BAR to request
715+
* @name: Name of the driver requesting the resource
716+
*
717+
* Returns: 0 on success, a negative error code on failure.
718+
*
719+
* Request region specified by @bar.
720+
*
721+
* The region will automatically be released on driver detach. If desired,
722+
* release manually only with pcim_release_region().
723+
*/
724+
int pcim_request_region(struct pci_dev *pdev, int bar, const char *name)
828725
{
829726
int ret;
830727
struct pcim_addr_devres *res;
@@ -838,7 +735,7 @@ static int _pcim_request_region(struct pci_dev *pdev, int bar, const char *name,
838735
res->type = PCIM_ADDR_DEVRES_TYPE_REGION;
839736
res->bar = bar;
840737

841-
ret = __pcim_request_region(pdev, bar, name, request_flags);
738+
ret = pci_request_region(pdev, bar, name);
842739
if (ret != 0) {
843740
pcim_addr_devres_free(res);
844741
return ret;
@@ -847,44 +744,8 @@ static int _pcim_request_region(struct pci_dev *pdev, int bar, const char *name,
847744
devres_add(&pdev->dev, res);
848745
return 0;
849746
}
850-
851-
/**
852-
* pcim_request_region - Request a PCI BAR
853-
* @pdev: PCI device to request region for
854-
* @bar: Index of BAR to request
855-
* @name: Name of the driver requesting the resource
856-
*
857-
* Returns: 0 on success, a negative error code on failure.
858-
*
859-
* Request region specified by @bar.
860-
*
861-
* The region will automatically be released on driver detach. If desired,
862-
* release manually only with pcim_release_region().
863-
*/
864-
int pcim_request_region(struct pci_dev *pdev, int bar, const char *name)
865-
{
866-
return _pcim_request_region(pdev, bar, name, 0);
867-
}
868747
EXPORT_SYMBOL(pcim_request_region);
869748

870-
/**
871-
* pcim_request_region_exclusive - Request a PCI BAR exclusively
872-
* @pdev: PCI device to request region for
873-
* @bar: Index of BAR to request
874-
* @name: Name of the driver requesting the resource
875-
*
876-
* Returns: 0 on success, a negative error code on failure.
877-
*
878-
* Request region specified by @bar exclusively.
879-
*
880-
* The region will automatically be released on driver detach. If desired,
881-
* release manually only with pcim_release_region().
882-
*/
883-
int pcim_request_region_exclusive(struct pci_dev *pdev, int bar, const char *name)
884-
{
885-
return _pcim_request_region(pdev, bar, name, IORESOURCE_EXCLUSIVE);
886-
}
887-
888749
/**
889750
* pcim_release_region - Release a PCI BAR
890751
* @pdev: PCI device to operate on
@@ -893,7 +754,7 @@ int pcim_request_region_exclusive(struct pci_dev *pdev, int bar, const char *nam
893754
* Release a region manually that was previously requested by
894755
* pcim_request_region().
895756
*/
896-
void pcim_release_region(struct pci_dev *pdev, int bar)
757+
static void pcim_release_region(struct pci_dev *pdev, int bar)
897758
{
898759
struct pcim_addr_devres res_searched;
899760

@@ -955,30 +816,6 @@ int pcim_request_all_regions(struct pci_dev *pdev, const char *name)
955816
}
956817
EXPORT_SYMBOL(pcim_request_all_regions);
957818

958-
/**
959-
* pcim_iounmap_regions - Unmap and release PCI BARs (DEPRECATED)
960-
* @pdev: PCI device to map IO resources for
961-
* @mask: Mask of BARs to unmap and release
962-
*
963-
* Unmap and release regions specified by @mask.
964-
*
965-
* This function is DEPRECATED. Do not use it in new code.
966-
* Use pcim_iounmap_region() instead.
967-
*/
968-
void pcim_iounmap_regions(struct pci_dev *pdev, int mask)
969-
{
970-
int i;
971-
972-
for (i = 0; i < PCI_STD_NUM_BARS; i++) {
973-
if (!mask_contains_bar(mask, i))
974-
continue;
975-
976-
pcim_iounmap_region(pdev, i);
977-
pcim_remove_bar_from_legacy_table(pdev, i);
978-
}
979-
}
980-
EXPORT_SYMBOL(pcim_iounmap_regions);
981-
982819
/**
983820
* pcim_iomap_range - Create a ranged __iomap mapping within a PCI BAR
984821
* @pdev: PCI device to map IO resources for

drivers/pci/iomap.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@
2525
*
2626
* @maxlen specifies the maximum length to map. If you want to get access to
2727
* the complete BAR from offset to the end, pass %0 here.
28-
*
29-
* NOTE:
30-
* This function is never managed, even if you initialized with
31-
* pcim_enable_device().
3228
* */
3329
void __iomem *pci_iomap_range(struct pci_dev *dev,
3430
int bar,
@@ -76,10 +72,6 @@ EXPORT_SYMBOL(pci_iomap_range);
7672
*
7773
* @maxlen specifies the maximum length to map. If you want to get access to
7874
* the complete BAR from offset to the end, pass %0 here.
79-
*
80-
* NOTE:
81-
* This function is never managed, even if you initialized with
82-
* pcim_enable_device().
8375
* */
8476
void __iomem *pci_iomap_wc_range(struct pci_dev *dev,
8577
int bar,
@@ -127,10 +119,6 @@ EXPORT_SYMBOL_GPL(pci_iomap_wc_range);
127119
*
128120
* @maxlen specifies the maximum length to map. If you want to get access to
129121
* the complete BAR without checking for its length first, pass %0 here.
130-
*
131-
* NOTE:
132-
* This function is never managed, even if you initialized with
133-
* pcim_enable_device(). If you need automatic cleanup, use pcim_iomap().
134122
* */
135123
void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
136124
{
@@ -152,10 +140,6 @@ EXPORT_SYMBOL(pci_iomap);
152140
*
153141
* @maxlen specifies the maximum length to map. If you want to get access to
154142
* the complete BAR without checking for its length first, pass %0 here.
155-
*
156-
* NOTE:
157-
* This function is never managed, even if you initialized with
158-
* pcim_enable_device().
159143
* */
160144
void __iomem *pci_iomap_wc(struct pci_dev *dev, int bar, unsigned long maxlen)
161145
{

0 commit comments

Comments
 (0)