6
6
/*
7
7
* On the state of PCI's devres implementation:
8
8
*
9
- * The older devres API for PCI has two significant problems :
9
+ * The older PCI devres API has one significant problem :
10
10
*
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.
33
16
*
34
17
* TODO:
35
18
* 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)
87
70
res -> bar = -1 ;
88
71
}
89
72
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
-
188
73
static void pcim_addr_resource_release (struct device * dev , void * resource_raw )
189
74
{
190
75
struct pci_dev * pdev = to_pci_dev (dev );
191
76
struct pcim_addr_devres * res = resource_raw ;
192
77
193
78
switch (res -> type ) {
194
79
case PCIM_ADDR_DEVRES_TYPE_REGION :
195
- __pcim_release_region (pdev , res -> bar );
80
+ pci_release_region (pdev , res -> bar );
196
81
break ;
197
82
case PCIM_ADDR_DEVRES_TYPE_REGION_MAPPING :
198
83
pci_iounmap (pdev , res -> baseaddr );
199
- __pcim_release_region (pdev , res -> bar );
84
+ pci_release_region (pdev , res -> bar );
200
85
break ;
201
86
case PCIM_ADDR_DEVRES_TYPE_MAPPING :
202
87
pci_iounmap (pdev , res -> baseaddr );
@@ -735,7 +620,7 @@ void __iomem *pcim_iomap_region(struct pci_dev *pdev, int bar,
735
620
res -> type = PCIM_ADDR_DEVRES_TYPE_REGION_MAPPING ;
736
621
res -> bar = bar ;
737
622
738
- ret = __pcim_request_region (pdev , bar , name , 0 );
623
+ ret = pci_request_region (pdev , bar , name );
739
624
if (ret != 0 )
740
625
goto err_region ;
741
626
@@ -749,7 +634,7 @@ void __iomem *pcim_iomap_region(struct pci_dev *pdev, int bar,
749
634
return res -> baseaddr ;
750
635
751
636
err_iomap :
752
- __pcim_release_region (pdev , bar );
637
+ pci_release_region (pdev , bar );
753
638
err_region :
754
639
pcim_addr_devres_free (res );
755
640
@@ -823,8 +708,20 @@ int pcim_iomap_regions(struct pci_dev *pdev, int mask, const char *name)
823
708
}
824
709
EXPORT_SYMBOL (pcim_iomap_regions );
825
710
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 )
828
725
{
829
726
int ret ;
830
727
struct pcim_addr_devres * res ;
@@ -838,7 +735,7 @@ static int _pcim_request_region(struct pci_dev *pdev, int bar, const char *name,
838
735
res -> type = PCIM_ADDR_DEVRES_TYPE_REGION ;
839
736
res -> bar = bar ;
840
737
841
- ret = __pcim_request_region (pdev , bar , name , request_flags );
738
+ ret = pci_request_region (pdev , bar , name );
842
739
if (ret != 0 ) {
843
740
pcim_addr_devres_free (res );
844
741
return ret ;
@@ -847,44 +744,8 @@ static int _pcim_request_region(struct pci_dev *pdev, int bar, const char *name,
847
744
devres_add (& pdev -> dev , res );
848
745
return 0 ;
849
746
}
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
- }
868
747
EXPORT_SYMBOL (pcim_request_region );
869
748
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
-
888
749
/**
889
750
* pcim_release_region - Release a PCI BAR
890
751
* @pdev: PCI device to operate on
@@ -893,7 +754,7 @@ int pcim_request_region_exclusive(struct pci_dev *pdev, int bar, const char *nam
893
754
* Release a region manually that was previously requested by
894
755
* pcim_request_region().
895
756
*/
896
- void pcim_release_region (struct pci_dev * pdev , int bar )
757
+ static void pcim_release_region (struct pci_dev * pdev , int bar )
897
758
{
898
759
struct pcim_addr_devres res_searched ;
899
760
@@ -955,30 +816,6 @@ int pcim_request_all_regions(struct pci_dev *pdev, const char *name)
955
816
}
956
817
EXPORT_SYMBOL (pcim_request_all_regions );
957
818
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
-
982
819
/**
983
820
* pcim_iomap_range - Create a ranged __iomap mapping within a PCI BAR
984
821
* @pdev: PCI device to map IO resources for
0 commit comments