@@ -132,33 +132,6 @@ virtiovf_pci_bar0_rw(struct virtiovf_pci_core_device *virtvdev,
132
132
return ret ? ret : count ;
133
133
}
134
134
135
- static bool range_intersect_range (loff_t range1_start , size_t count1 ,
136
- loff_t range2_start , size_t count2 ,
137
- loff_t * start_offset ,
138
- size_t * intersect_count ,
139
- size_t * register_offset )
140
- {
141
- if (range1_start <= range2_start &&
142
- range1_start + count1 > range2_start ) {
143
- * start_offset = range2_start - range1_start ;
144
- * intersect_count = min_t (size_t , count2 ,
145
- range1_start + count1 - range2_start );
146
- * register_offset = 0 ;
147
- return true;
148
- }
149
-
150
- if (range1_start > range2_start &&
151
- range1_start < range2_start + count2 ) {
152
- * start_offset = 0 ;
153
- * intersect_count = min_t (size_t , count1 ,
154
- range2_start + count2 - range1_start );
155
- * register_offset = range1_start - range2_start ;
156
- return true;
157
- }
158
-
159
- return false;
160
- }
161
-
162
135
static ssize_t virtiovf_pci_read_config (struct vfio_device * core_vdev ,
163
136
char __user * buf , size_t count ,
164
137
loff_t * ppos )
@@ -178,16 +151,18 @@ static ssize_t virtiovf_pci_read_config(struct vfio_device *core_vdev,
178
151
if (ret < 0 )
179
152
return ret ;
180
153
181
- if (range_intersect_range (pos , count , PCI_DEVICE_ID , sizeof (val16 ),
182
- & copy_offset , & copy_count , & register_offset )) {
154
+ if (vfio_pci_core_range_intersect_range (pos , count , PCI_DEVICE_ID ,
155
+ sizeof (val16 ), & copy_offset ,
156
+ & copy_count , & register_offset )) {
183
157
val16 = cpu_to_le16 (VIRTIO_TRANS_ID_NET );
184
158
if (copy_to_user (buf + copy_offset , (void * )& val16 + register_offset , copy_count ))
185
159
return - EFAULT ;
186
160
}
187
161
188
162
if ((le16_to_cpu (virtvdev -> pci_cmd ) & PCI_COMMAND_IO ) &&
189
- range_intersect_range (pos , count , PCI_COMMAND , sizeof (val16 ),
190
- & copy_offset , & copy_count , & register_offset )) {
163
+ vfio_pci_core_range_intersect_range (pos , count , PCI_COMMAND ,
164
+ sizeof (val16 ), & copy_offset ,
165
+ & copy_count , & register_offset )) {
191
166
if (copy_from_user ((void * )& val16 + register_offset , buf + copy_offset ,
192
167
copy_count ))
193
168
return - EFAULT ;
@@ -197,16 +172,18 @@ static ssize_t virtiovf_pci_read_config(struct vfio_device *core_vdev,
197
172
return - EFAULT ;
198
173
}
199
174
200
- if (range_intersect_range (pos , count , PCI_REVISION_ID , sizeof (val8 ),
201
- & copy_offset , & copy_count , & register_offset )) {
175
+ if (vfio_pci_core_range_intersect_range (pos , count , PCI_REVISION_ID ,
176
+ sizeof (val8 ), & copy_offset ,
177
+ & copy_count , & register_offset )) {
202
178
/* Transional needs to have revision 0 */
203
179
val8 = 0 ;
204
180
if (copy_to_user (buf + copy_offset , & val8 , copy_count ))
205
181
return - EFAULT ;
206
182
}
207
183
208
- if (range_intersect_range (pos , count , PCI_BASE_ADDRESS_0 , sizeof (val32 ),
209
- & copy_offset , & copy_count , & register_offset )) {
184
+ if (vfio_pci_core_range_intersect_range (pos , count , PCI_BASE_ADDRESS_0 ,
185
+ sizeof (val32 ), & copy_offset ,
186
+ & copy_count , & register_offset )) {
210
187
u32 bar_mask = ~(virtvdev -> bar0_virtual_buf_size - 1 );
211
188
u32 pci_base_addr_0 = le32_to_cpu (virtvdev -> pci_base_addr_0 );
212
189
@@ -215,8 +192,9 @@ static ssize_t virtiovf_pci_read_config(struct vfio_device *core_vdev,
215
192
return - EFAULT ;
216
193
}
217
194
218
- if (range_intersect_range (pos , count , PCI_SUBSYSTEM_ID , sizeof (val16 ),
219
- & copy_offset , & copy_count , & register_offset )) {
195
+ if (vfio_pci_core_range_intersect_range (pos , count , PCI_SUBSYSTEM_ID ,
196
+ sizeof (val16 ), & copy_offset ,
197
+ & copy_count , & register_offset )) {
220
198
/*
221
199
* Transitional devices use the PCI subsystem device id as
222
200
* virtio device id, same as legacy driver always did.
@@ -227,8 +205,9 @@ static ssize_t virtiovf_pci_read_config(struct vfio_device *core_vdev,
227
205
return - EFAULT ;
228
206
}
229
207
230
- if (range_intersect_range (pos , count , PCI_SUBSYSTEM_VENDOR_ID , sizeof (val16 ),
231
- & copy_offset , & copy_count , & register_offset )) {
208
+ if (vfio_pci_core_range_intersect_range (pos , count , PCI_SUBSYSTEM_VENDOR_ID ,
209
+ sizeof (val16 ), & copy_offset ,
210
+ & copy_count , & register_offset )) {
232
211
val16 = cpu_to_le16 (PCI_VENDOR_ID_REDHAT_QUMRANET );
233
212
if (copy_to_user (buf + copy_offset , (void * )& val16 + register_offset ,
234
213
copy_count ))
@@ -270,19 +249,20 @@ static ssize_t virtiovf_pci_write_config(struct vfio_device *core_vdev,
270
249
loff_t copy_offset ;
271
250
size_t copy_count ;
272
251
273
- if (range_intersect_range (pos , count , PCI_COMMAND , sizeof (virtvdev -> pci_cmd ),
274
- & copy_offset , & copy_count ,
275
- & register_offset )) {
252
+ if (vfio_pci_core_range_intersect_range (pos , count , PCI_COMMAND ,
253
+ sizeof (virtvdev -> pci_cmd ),
254
+ & copy_offset , & copy_count ,
255
+ & register_offset )) {
276
256
if (copy_from_user ((void * )& virtvdev -> pci_cmd + register_offset ,
277
257
buf + copy_offset ,
278
258
copy_count ))
279
259
return - EFAULT ;
280
260
}
281
261
282
- if (range_intersect_range (pos , count , PCI_BASE_ADDRESS_0 ,
283
- sizeof (virtvdev -> pci_base_addr_0 ),
284
- & copy_offset , & copy_count ,
285
- & register_offset )) {
262
+ if (vfio_pci_core_range_intersect_range (pos , count , PCI_BASE_ADDRESS_0 ,
263
+ sizeof (virtvdev -> pci_base_addr_0 ),
264
+ & copy_offset , & copy_count ,
265
+ & register_offset )) {
286
266
if (copy_from_user ((void * )& virtvdev -> pci_base_addr_0 + register_offset ,
287
267
buf + copy_offset ,
288
268
copy_count ))
0 commit comments