@@ -1022,29 +1022,6 @@ void pci_remove_legacy_files(struct pci_bus *b)
1022
1022
#endif /* HAVE_PCI_LEGACY */
1023
1023
1024
1024
#if defined(HAVE_PCI_MMAP ) || defined(ARCH_GENERIC_PCI_MMAP_RESOURCE )
1025
-
1026
- int pci_mmap_fits (struct pci_dev * pdev , int resno , struct vm_area_struct * vma ,
1027
- enum pci_mmap_api mmap_api )
1028
- {
1029
- unsigned long nr , start , size ;
1030
- resource_size_t pci_start = 0 , pci_end ;
1031
-
1032
- if (pci_resource_len (pdev , resno ) == 0 )
1033
- return 0 ;
1034
- nr = vma_pages (vma );
1035
- start = vma -> vm_pgoff ;
1036
- size = ((pci_resource_len (pdev , resno ) - 1 ) >> PAGE_SHIFT ) + 1 ;
1037
- if (mmap_api == PCI_MMAP_PROCFS ) {
1038
- pci_resource_to_user (pdev , resno , & pdev -> resource [resno ],
1039
- & pci_start , & pci_end );
1040
- pci_start >>= PAGE_SHIFT ;
1041
- }
1042
- if (start >= pci_start && start < pci_start + size &&
1043
- start + nr <= pci_start + size )
1044
- return 1 ;
1045
- return 0 ;
1046
- }
1047
-
1048
1025
/**
1049
1026
* pci_mmap_resource - map a PCI resource into user memory space
1050
1027
* @kobj: kobject for mapping
@@ -1410,79 +1387,89 @@ static const struct attribute_group pci_dev_reset_attr_group = {
1410
1387
.is_visible = pci_dev_reset_attr_is_visible ,
1411
1388
};
1412
1389
1390
+ static ssize_t __resource_resize_show (struct device * dev , int n , char * buf )
1391
+ {
1392
+ struct pci_dev * pdev = to_pci_dev (dev );
1393
+ ssize_t ret ;
1394
+
1395
+ pci_config_pm_runtime_get (pdev );
1396
+
1397
+ ret = sysfs_emit (buf , "%016llx\n" ,
1398
+ (u64 )pci_rebar_get_possible_sizes (pdev , n ));
1399
+
1400
+ pci_config_pm_runtime_put (pdev );
1401
+
1402
+ return ret ;
1403
+ }
1404
+
1405
+ static ssize_t __resource_resize_store (struct device * dev , int n ,
1406
+ const char * buf , size_t count )
1407
+ {
1408
+ struct pci_dev * pdev = to_pci_dev (dev );
1409
+ unsigned long size , flags ;
1410
+ int ret , i ;
1411
+ u16 cmd ;
1412
+
1413
+ if (kstrtoul (buf , 0 , & size ) < 0 )
1414
+ return - EINVAL ;
1415
+
1416
+ device_lock (dev );
1417
+ if (dev -> driver ) {
1418
+ ret = - EBUSY ;
1419
+ goto unlock ;
1420
+ }
1421
+
1422
+ pci_config_pm_runtime_get (pdev );
1423
+
1424
+ if ((pdev -> class >> 8 ) == PCI_CLASS_DISPLAY_VGA ) {
1425
+ ret = aperture_remove_conflicting_pci_devices (pdev ,
1426
+ "resourceN_resize" );
1427
+ if (ret )
1428
+ goto pm_put ;
1429
+ }
1430
+
1431
+ pci_read_config_word (pdev , PCI_COMMAND , & cmd );
1432
+ pci_write_config_word (pdev , PCI_COMMAND ,
1433
+ cmd & ~PCI_COMMAND_MEMORY );
1434
+
1435
+ flags = pci_resource_flags (pdev , n );
1436
+
1437
+ pci_remove_resource_files (pdev );
1438
+
1439
+ for (i = 0 ; i < PCI_STD_NUM_BARS ; i ++ ) {
1440
+ if (pci_resource_len (pdev , i ) &&
1441
+ pci_resource_flags (pdev , i ) == flags )
1442
+ pci_release_resource (pdev , i );
1443
+ }
1444
+
1445
+ ret = pci_resize_resource (pdev , n , size );
1446
+
1447
+ pci_assign_unassigned_bus_resources (pdev -> bus );
1448
+
1449
+ if (pci_create_resource_files (pdev ))
1450
+ pci_warn (pdev , "Failed to recreate resource files after BAR resizing\n" );
1451
+
1452
+ pci_write_config_word (pdev , PCI_COMMAND , cmd );
1453
+ pm_put :
1454
+ pci_config_pm_runtime_put (pdev );
1455
+ unlock :
1456
+ device_unlock (dev );
1457
+
1458
+ return ret ? ret : count ;
1459
+ }
1460
+
1413
1461
#define pci_dev_resource_resize_attr (n ) \
1414
1462
static ssize_t resource##n##_resize_show(struct device *dev, \
1415
1463
struct device_attribute *attr, \
1416
- char * buf) \
1464
+ char *buf) \
1417
1465
{ \
1418
- struct pci_dev *pdev = to_pci_dev(dev); \
1419
- ssize_t ret; \
1420
- \
1421
- pci_config_pm_runtime_get(pdev); \
1422
- \
1423
- ret = sysfs_emit(buf, "%016llx\n", \
1424
- (u64)pci_rebar_get_possible_sizes(pdev, n)); \
1425
- \
1426
- pci_config_pm_runtime_put(pdev); \
1427
- \
1428
- return ret; \
1466
+ return __resource_resize_show(dev, n, buf); \
1429
1467
} \
1430
- \
1431
1468
static ssize_t resource##n##_resize_store(struct device *dev, \
1432
1469
struct device_attribute *attr,\
1433
1470
const char *buf, size_t count)\
1434
1471
{ \
1435
- struct pci_dev *pdev = to_pci_dev(dev); \
1436
- unsigned long size, flags; \
1437
- int ret, i; \
1438
- u16 cmd; \
1439
- \
1440
- if (kstrtoul(buf, 0, &size) < 0) \
1441
- return -EINVAL; \
1442
- \
1443
- device_lock(dev); \
1444
- if (dev->driver) { \
1445
- ret = -EBUSY; \
1446
- goto unlock; \
1447
- } \
1448
- \
1449
- pci_config_pm_runtime_get(pdev); \
1450
- \
1451
- if ((pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA) { \
1452
- ret = aperture_remove_conflicting_pci_devices(pdev, \
1453
- "resourceN_resize"); \
1454
- if (ret) \
1455
- goto pm_put; \
1456
- } \
1457
- \
1458
- pci_read_config_word(pdev, PCI_COMMAND, &cmd); \
1459
- pci_write_config_word(pdev, PCI_COMMAND, \
1460
- cmd & ~PCI_COMMAND_MEMORY); \
1461
- \
1462
- flags = pci_resource_flags(pdev, n); \
1463
- \
1464
- pci_remove_resource_files(pdev); \
1465
- \
1466
- for (i = 0; i < PCI_STD_NUM_BARS; i++) { \
1467
- if (pci_resource_len(pdev, i) && \
1468
- pci_resource_flags(pdev, i) == flags) \
1469
- pci_release_resource(pdev, i); \
1470
- } \
1471
- \
1472
- ret = pci_resize_resource(pdev, n, size); \
1473
- \
1474
- pci_assign_unassigned_bus_resources(pdev->bus); \
1475
- \
1476
- if (pci_create_resource_files(pdev)) \
1477
- pci_warn(pdev, "Failed to recreate resource files after BAR resizing\n");\
1478
- \
1479
- pci_write_config_word(pdev, PCI_COMMAND, cmd); \
1480
- pm_put: \
1481
- pci_config_pm_runtime_put(pdev); \
1482
- unlock: \
1483
- device_unlock(dev); \
1484
- \
1485
- return ret ? ret : count; \
1472
+ return __resource_resize_store(dev, n, buf, count); \
1486
1473
} \
1487
1474
static DEVICE_ATTR_RW(resource##n##_resize)
1488
1475
@@ -1660,7 +1647,7 @@ static const struct attribute_group pcie_dev_attr_group = {
1660
1647
.is_visible = pcie_dev_attrs_are_visible ,
1661
1648
};
1662
1649
1663
- static const struct attribute_group * pci_dev_attr_groups [] = {
1650
+ const struct attribute_group * pci_dev_attr_groups [] = {
1664
1651
& pci_dev_attr_group ,
1665
1652
& pci_dev_hp_attr_group ,
1666
1653
#ifdef CONFIG_PCI_IOV
@@ -1677,7 +1664,3 @@ static const struct attribute_group *pci_dev_attr_groups[] = {
1677
1664
#endif
1678
1665
NULL ,
1679
1666
};
1680
-
1681
- const struct device_type pci_dev_type = {
1682
- .groups = pci_dev_attr_groups ,
1683
- };
0 commit comments