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-
18873static 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
751636err_iomap :
752- __pcim_release_region (pdev , bar );
637+ pci_release_region (pdev , bar );
753638err_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}
824709EXPORT_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- }
868747EXPORT_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}
956817EXPORT_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
0 commit comments