| .. | .. |
|---|
| 156 | 156 | { |
|---|
| 157 | 157 | struct pci_dev *pdev = to_pci_dev(dev); |
|---|
| 158 | 158 | |
|---|
| 159 | | - return sprintf(buf, "%s\n", PCIE_SPEED2STR(pcie_get_speed_cap(pdev))); |
|---|
| 159 | + return sprintf(buf, "%s\n", |
|---|
| 160 | + pci_speed_string(pcie_get_speed_cap(pdev))); |
|---|
| 160 | 161 | } |
|---|
| 161 | 162 | static DEVICE_ATTR_RO(max_link_speed); |
|---|
| 162 | 163 | |
|---|
| .. | .. |
|---|
| 175 | 176 | struct pci_dev *pci_dev = to_pci_dev(dev); |
|---|
| 176 | 177 | u16 linkstat; |
|---|
| 177 | 178 | int err; |
|---|
| 178 | | - const char *speed; |
|---|
| 179 | + enum pci_bus_speed speed; |
|---|
| 179 | 180 | |
|---|
| 180 | 181 | err = pcie_capability_read_word(pci_dev, PCI_EXP_LNKSTA, &linkstat); |
|---|
| 181 | 182 | if (err) |
|---|
| 182 | 183 | return -EINVAL; |
|---|
| 183 | 184 | |
|---|
| 184 | | - switch (linkstat & PCI_EXP_LNKSTA_CLS) { |
|---|
| 185 | | - case PCI_EXP_LNKSTA_CLS_16_0GB: |
|---|
| 186 | | - speed = "16 GT/s"; |
|---|
| 187 | | - break; |
|---|
| 188 | | - case PCI_EXP_LNKSTA_CLS_8_0GB: |
|---|
| 189 | | - speed = "8 GT/s"; |
|---|
| 190 | | - break; |
|---|
| 191 | | - case PCI_EXP_LNKSTA_CLS_5_0GB: |
|---|
| 192 | | - speed = "5 GT/s"; |
|---|
| 193 | | - break; |
|---|
| 194 | | - case PCI_EXP_LNKSTA_CLS_2_5GB: |
|---|
| 195 | | - speed = "2.5 GT/s"; |
|---|
| 196 | | - break; |
|---|
| 197 | | - default: |
|---|
| 198 | | - speed = "Unknown speed"; |
|---|
| 199 | | - } |
|---|
| 185 | + speed = pcie_link_speed[linkstat & PCI_EXP_LNKSTA_CLS]; |
|---|
| 200 | 186 | |
|---|
| 201 | | - return sprintf(buf, "%s\n", speed); |
|---|
| 187 | + return sprintf(buf, "%s\n", pci_speed_string(speed)); |
|---|
| 202 | 188 | } |
|---|
| 203 | 189 | static DEVICE_ATTR_RO(current_link_speed); |
|---|
| 204 | 190 | |
|---|
| .. | .. |
|---|
| 412 | 398 | } |
|---|
| 413 | 399 | static DEVICE_ATTR_RW(msi_bus); |
|---|
| 414 | 400 | |
|---|
| 415 | | -static ssize_t bus_rescan_store(struct bus_type *bus, const char *buf, |
|---|
| 416 | | - size_t count) |
|---|
| 401 | +static ssize_t rescan_store(struct bus_type *bus, const char *buf, size_t count) |
|---|
| 417 | 402 | { |
|---|
| 418 | 403 | unsigned long val; |
|---|
| 419 | 404 | struct pci_bus *b = NULL; |
|---|
| .. | .. |
|---|
| 429 | 414 | } |
|---|
| 430 | 415 | return count; |
|---|
| 431 | 416 | } |
|---|
| 432 | | -static BUS_ATTR(rescan, (S_IWUSR|S_IWGRP), NULL, bus_rescan_store); |
|---|
| 417 | +static BUS_ATTR_WO(rescan); |
|---|
| 433 | 418 | |
|---|
| 434 | 419 | static struct attribute *pci_bus_attrs[] = { |
|---|
| 435 | 420 | &bus_attr_rescan.attr, |
|---|
| .. | .. |
|---|
| 462 | 447 | } |
|---|
| 463 | 448 | return count; |
|---|
| 464 | 449 | } |
|---|
| 465 | | -static struct device_attribute dev_rescan_attr = __ATTR(rescan, |
|---|
| 466 | | - (S_IWUSR|S_IWGRP), |
|---|
| 467 | | - NULL, dev_rescan_store); |
|---|
| 450 | +static struct device_attribute dev_attr_dev_rescan = __ATTR(rescan, 0200, NULL, |
|---|
| 451 | + dev_rescan_store); |
|---|
| 468 | 452 | |
|---|
| 469 | 453 | static ssize_t remove_store(struct device *dev, struct device_attribute *attr, |
|---|
| 470 | 454 | const char *buf, size_t count) |
|---|
| .. | .. |
|---|
| 478 | 462 | pci_stop_and_remove_bus_device_locked(to_pci_dev(dev)); |
|---|
| 479 | 463 | return count; |
|---|
| 480 | 464 | } |
|---|
| 481 | | -static struct device_attribute dev_remove_attr = __ATTR_IGNORE_LOCKDEP(remove, |
|---|
| 482 | | - (S_IWUSR|S_IWGRP), |
|---|
| 483 | | - NULL, remove_store); |
|---|
| 465 | +static DEVICE_ATTR_IGNORE_LOCKDEP(remove, 0220, NULL, |
|---|
| 466 | + remove_store); |
|---|
| 484 | 467 | |
|---|
| 485 | | -static ssize_t dev_bus_rescan_store(struct device *dev, |
|---|
| 486 | | - struct device_attribute *attr, |
|---|
| 487 | | - const char *buf, size_t count) |
|---|
| 468 | +static ssize_t bus_rescan_store(struct device *dev, |
|---|
| 469 | + struct device_attribute *attr, |
|---|
| 470 | + const char *buf, size_t count) |
|---|
| 488 | 471 | { |
|---|
| 489 | 472 | unsigned long val; |
|---|
| 490 | 473 | struct pci_bus *bus = to_pci_bus(dev); |
|---|
| .. | .. |
|---|
| 502 | 485 | } |
|---|
| 503 | 486 | return count; |
|---|
| 504 | 487 | } |
|---|
| 505 | | -static DEVICE_ATTR(rescan, (S_IWUSR|S_IWGRP), NULL, dev_bus_rescan_store); |
|---|
| 488 | +static struct device_attribute dev_attr_bus_rescan = __ATTR(rescan, 0200, NULL, |
|---|
| 489 | + bus_rescan_store); |
|---|
| 506 | 490 | |
|---|
| 507 | 491 | #if defined(CONFIG_PM) && defined(CONFIG_ACPI) |
|---|
| 508 | 492 | static ssize_t d3cold_allowed_store(struct device *dev, |
|---|
| .. | .. |
|---|
| 549 | 533 | static DEVICE_ATTR_RO(devspec); |
|---|
| 550 | 534 | #endif |
|---|
| 551 | 535 | |
|---|
| 552 | | -#ifdef CONFIG_PCI_IOV |
|---|
| 553 | | -static ssize_t sriov_totalvfs_show(struct device *dev, |
|---|
| 554 | | - struct device_attribute *attr, |
|---|
| 555 | | - char *buf) |
|---|
| 556 | | -{ |
|---|
| 557 | | - struct pci_dev *pdev = to_pci_dev(dev); |
|---|
| 558 | | - |
|---|
| 559 | | - return sprintf(buf, "%u\n", pci_sriov_get_totalvfs(pdev)); |
|---|
| 560 | | -} |
|---|
| 561 | | - |
|---|
| 562 | | - |
|---|
| 563 | | -static ssize_t sriov_numvfs_show(struct device *dev, |
|---|
| 564 | | - struct device_attribute *attr, |
|---|
| 565 | | - char *buf) |
|---|
| 566 | | -{ |
|---|
| 567 | | - struct pci_dev *pdev = to_pci_dev(dev); |
|---|
| 568 | | - |
|---|
| 569 | | - return sprintf(buf, "%u\n", pdev->sriov->num_VFs); |
|---|
| 570 | | -} |
|---|
| 571 | | - |
|---|
| 572 | | -/* |
|---|
| 573 | | - * num_vfs > 0; number of VFs to enable |
|---|
| 574 | | - * num_vfs = 0; disable all VFs |
|---|
| 575 | | - * |
|---|
| 576 | | - * Note: SRIOV spec doesn't allow partial VF |
|---|
| 577 | | - * disable, so it's all or none. |
|---|
| 578 | | - */ |
|---|
| 579 | | -static ssize_t sriov_numvfs_store(struct device *dev, |
|---|
| 580 | | - struct device_attribute *attr, |
|---|
| 581 | | - const char *buf, size_t count) |
|---|
| 582 | | -{ |
|---|
| 583 | | - struct pci_dev *pdev = to_pci_dev(dev); |
|---|
| 584 | | - int ret; |
|---|
| 585 | | - u16 num_vfs; |
|---|
| 586 | | - |
|---|
| 587 | | - ret = kstrtou16(buf, 0, &num_vfs); |
|---|
| 588 | | - if (ret < 0) |
|---|
| 589 | | - return ret; |
|---|
| 590 | | - |
|---|
| 591 | | - if (num_vfs > pci_sriov_get_totalvfs(pdev)) |
|---|
| 592 | | - return -ERANGE; |
|---|
| 593 | | - |
|---|
| 594 | | - device_lock(&pdev->dev); |
|---|
| 595 | | - |
|---|
| 596 | | - if (num_vfs == pdev->sriov->num_VFs) |
|---|
| 597 | | - goto exit; |
|---|
| 598 | | - |
|---|
| 599 | | - /* is PF driver loaded w/callback */ |
|---|
| 600 | | - if (!pdev->driver || !pdev->driver->sriov_configure) { |
|---|
| 601 | | - pci_info(pdev, "Driver doesn't support SRIOV configuration via sysfs\n"); |
|---|
| 602 | | - ret = -ENOENT; |
|---|
| 603 | | - goto exit; |
|---|
| 604 | | - } |
|---|
| 605 | | - |
|---|
| 606 | | - if (num_vfs == 0) { |
|---|
| 607 | | - /* disable VFs */ |
|---|
| 608 | | - ret = pdev->driver->sriov_configure(pdev, 0); |
|---|
| 609 | | - goto exit; |
|---|
| 610 | | - } |
|---|
| 611 | | - |
|---|
| 612 | | - /* enable VFs */ |
|---|
| 613 | | - if (pdev->sriov->num_VFs) { |
|---|
| 614 | | - pci_warn(pdev, "%d VFs already enabled. Disable before enabling %d VFs\n", |
|---|
| 615 | | - pdev->sriov->num_VFs, num_vfs); |
|---|
| 616 | | - ret = -EBUSY; |
|---|
| 617 | | - goto exit; |
|---|
| 618 | | - } |
|---|
| 619 | | - |
|---|
| 620 | | - ret = pdev->driver->sriov_configure(pdev, num_vfs); |
|---|
| 621 | | - if (ret < 0) |
|---|
| 622 | | - goto exit; |
|---|
| 623 | | - |
|---|
| 624 | | - if (ret != num_vfs) |
|---|
| 625 | | - pci_warn(pdev, "%d VFs requested; only %d enabled\n", |
|---|
| 626 | | - num_vfs, ret); |
|---|
| 627 | | - |
|---|
| 628 | | -exit: |
|---|
| 629 | | - device_unlock(&pdev->dev); |
|---|
| 630 | | - |
|---|
| 631 | | - if (ret < 0) |
|---|
| 632 | | - return ret; |
|---|
| 633 | | - |
|---|
| 634 | | - return count; |
|---|
| 635 | | -} |
|---|
| 636 | | - |
|---|
| 637 | | -static ssize_t sriov_offset_show(struct device *dev, |
|---|
| 638 | | - struct device_attribute *attr, |
|---|
| 639 | | - char *buf) |
|---|
| 640 | | -{ |
|---|
| 641 | | - struct pci_dev *pdev = to_pci_dev(dev); |
|---|
| 642 | | - |
|---|
| 643 | | - return sprintf(buf, "%u\n", pdev->sriov->offset); |
|---|
| 644 | | -} |
|---|
| 645 | | - |
|---|
| 646 | | -static ssize_t sriov_stride_show(struct device *dev, |
|---|
| 647 | | - struct device_attribute *attr, |
|---|
| 648 | | - char *buf) |
|---|
| 649 | | -{ |
|---|
| 650 | | - struct pci_dev *pdev = to_pci_dev(dev); |
|---|
| 651 | | - |
|---|
| 652 | | - return sprintf(buf, "%u\n", pdev->sriov->stride); |
|---|
| 653 | | -} |
|---|
| 654 | | - |
|---|
| 655 | | -static ssize_t sriov_vf_device_show(struct device *dev, |
|---|
| 656 | | - struct device_attribute *attr, |
|---|
| 657 | | - char *buf) |
|---|
| 658 | | -{ |
|---|
| 659 | | - struct pci_dev *pdev = to_pci_dev(dev); |
|---|
| 660 | | - |
|---|
| 661 | | - return sprintf(buf, "%x\n", pdev->sriov->vf_device); |
|---|
| 662 | | -} |
|---|
| 663 | | - |
|---|
| 664 | | -static ssize_t sriov_drivers_autoprobe_show(struct device *dev, |
|---|
| 665 | | - struct device_attribute *attr, |
|---|
| 666 | | - char *buf) |
|---|
| 667 | | -{ |
|---|
| 668 | | - struct pci_dev *pdev = to_pci_dev(dev); |
|---|
| 669 | | - |
|---|
| 670 | | - return sprintf(buf, "%u\n", pdev->sriov->drivers_autoprobe); |
|---|
| 671 | | -} |
|---|
| 672 | | - |
|---|
| 673 | | -static ssize_t sriov_drivers_autoprobe_store(struct device *dev, |
|---|
| 674 | | - struct device_attribute *attr, |
|---|
| 675 | | - const char *buf, size_t count) |
|---|
| 676 | | -{ |
|---|
| 677 | | - struct pci_dev *pdev = to_pci_dev(dev); |
|---|
| 678 | | - bool drivers_autoprobe; |
|---|
| 679 | | - |
|---|
| 680 | | - if (kstrtobool(buf, &drivers_autoprobe) < 0) |
|---|
| 681 | | - return -EINVAL; |
|---|
| 682 | | - |
|---|
| 683 | | - pdev->sriov->drivers_autoprobe = drivers_autoprobe; |
|---|
| 684 | | - |
|---|
| 685 | | - return count; |
|---|
| 686 | | -} |
|---|
| 687 | | - |
|---|
| 688 | | -static struct device_attribute sriov_totalvfs_attr = __ATTR_RO(sriov_totalvfs); |
|---|
| 689 | | -static struct device_attribute sriov_numvfs_attr = |
|---|
| 690 | | - __ATTR(sriov_numvfs, (S_IRUGO|S_IWUSR|S_IWGRP), |
|---|
| 691 | | - sriov_numvfs_show, sriov_numvfs_store); |
|---|
| 692 | | -static struct device_attribute sriov_offset_attr = __ATTR_RO(sriov_offset); |
|---|
| 693 | | -static struct device_attribute sriov_stride_attr = __ATTR_RO(sriov_stride); |
|---|
| 694 | | -static struct device_attribute sriov_vf_device_attr = __ATTR_RO(sriov_vf_device); |
|---|
| 695 | | -static struct device_attribute sriov_drivers_autoprobe_attr = |
|---|
| 696 | | - __ATTR(sriov_drivers_autoprobe, (S_IRUGO|S_IWUSR|S_IWGRP), |
|---|
| 697 | | - sriov_drivers_autoprobe_show, sriov_drivers_autoprobe_store); |
|---|
| 698 | | -#endif /* CONFIG_PCI_IOV */ |
|---|
| 699 | | - |
|---|
| 700 | 536 | static ssize_t driver_override_store(struct device *dev, |
|---|
| 701 | 537 | struct device_attribute *attr, |
|---|
| 702 | 538 | const char *buf, size_t count) |
|---|
| .. | .. |
|---|
| 738 | 574 | ssize_t len; |
|---|
| 739 | 575 | |
|---|
| 740 | 576 | device_lock(dev); |
|---|
| 741 | | - len = snprintf(buf, PAGE_SIZE, "%s\n", pdev->driver_override); |
|---|
| 577 | + len = scnprintf(buf, PAGE_SIZE, "%s\n", pdev->driver_override); |
|---|
| 742 | 578 | device_unlock(dev); |
|---|
| 743 | 579 | return len; |
|---|
| 744 | 580 | } |
|---|
| .. | .. |
|---|
| 790 | 626 | }; |
|---|
| 791 | 627 | |
|---|
| 792 | 628 | static struct attribute *pcibus_attrs[] = { |
|---|
| 793 | | - &dev_attr_rescan.attr, |
|---|
| 629 | + &dev_attr_bus_rescan.attr, |
|---|
| 794 | 630 | &dev_attr_cpuaffinity.attr, |
|---|
| 795 | 631 | &dev_attr_cpulistaffinity.attr, |
|---|
| 796 | 632 | NULL, |
|---|
| .. | .. |
|---|
| 818 | 654 | !!(pdev->resource[PCI_ROM_RESOURCE].flags & |
|---|
| 819 | 655 | IORESOURCE_ROM_SHADOW)); |
|---|
| 820 | 656 | } |
|---|
| 821 | | -static struct device_attribute vga_attr = __ATTR_RO(boot_vga); |
|---|
| 657 | +static DEVICE_ATTR_RO(boot_vga); |
|---|
| 822 | 658 | |
|---|
| 823 | 659 | static ssize_t pci_read_config(struct file *filp, struct kobject *kobj, |
|---|
| 824 | 660 | struct bin_attribute *bin_attr, char *buf, |
|---|
| .. | .. |
|---|
| 872 | 708 | data[off - init_off + 3] = (val >> 24) & 0xff; |
|---|
| 873 | 709 | off += 4; |
|---|
| 874 | 710 | size -= 4; |
|---|
| 711 | + cond_resched(); |
|---|
| 875 | 712 | } |
|---|
| 876 | 713 | |
|---|
| 877 | 714 | if (size >= 2) { |
|---|
| .. | .. |
|---|
| 904 | 741 | unsigned int size = count; |
|---|
| 905 | 742 | loff_t init_off = off; |
|---|
| 906 | 743 | u8 *data = (u8 *) buf; |
|---|
| 744 | + int ret; |
|---|
| 745 | + |
|---|
| 746 | + ret = security_locked_down(LOCKDOWN_PCI_ACCESS); |
|---|
| 747 | + if (ret) |
|---|
| 748 | + return ret; |
|---|
| 907 | 749 | |
|---|
| 908 | 750 | if (off > dev->cfg_size) |
|---|
| 909 | 751 | return 0; |
|---|
| .. | .. |
|---|
| 1083 | 925 | sysfs_bin_attr_init(b->legacy_io); |
|---|
| 1084 | 926 | b->legacy_io->attr.name = "legacy_io"; |
|---|
| 1085 | 927 | b->legacy_io->size = 0xffff; |
|---|
| 1086 | | - b->legacy_io->attr.mode = S_IRUSR | S_IWUSR; |
|---|
| 928 | + b->legacy_io->attr.mode = 0600; |
|---|
| 1087 | 929 | b->legacy_io->read = pci_read_legacy_io; |
|---|
| 1088 | 930 | b->legacy_io->write = pci_write_legacy_io; |
|---|
| 1089 | 931 | b->legacy_io->mmap = pci_mmap_legacy_io; |
|---|
| .. | .. |
|---|
| 1097 | 939 | sysfs_bin_attr_init(b->legacy_mem); |
|---|
| 1098 | 940 | b->legacy_mem->attr.name = "legacy_mem"; |
|---|
| 1099 | 941 | b->legacy_mem->size = 1024*1024; |
|---|
| 1100 | | - b->legacy_mem->attr.mode = S_IRUSR | S_IWUSR; |
|---|
| 942 | + b->legacy_mem->attr.mode = 0600; |
|---|
| 1101 | 943 | b->legacy_mem->mmap = pci_mmap_legacy_mem; |
|---|
| 1102 | 944 | pci_adjust_legacy_attr(b, pci_mmap_mem); |
|---|
| 1103 | 945 | error = device_create_bin_file(&b->dev, b->legacy_mem); |
|---|
| .. | .. |
|---|
| 1112 | 954 | kfree(b->legacy_io); |
|---|
| 1113 | 955 | b->legacy_io = NULL; |
|---|
| 1114 | 956 | kzalloc_err: |
|---|
| 1115 | | - printk(KERN_WARNING "pci: warning: could not create legacy I/O port and ISA memory resources to sysfs\n"); |
|---|
| 1116 | | - return; |
|---|
| 957 | + dev_warn(&b->dev, "could not create legacy I/O port and ISA memory resources in sysfs\n"); |
|---|
| 1117 | 958 | } |
|---|
| 1118 | 959 | |
|---|
| 1119 | 960 | void pci_remove_legacy_files(struct pci_bus *b) |
|---|
| .. | .. |
|---|
| 1166 | 1007 | int bar = (unsigned long)attr->private; |
|---|
| 1167 | 1008 | enum pci_mmap_state mmap_type; |
|---|
| 1168 | 1009 | struct resource *res = &pdev->resource[bar]; |
|---|
| 1010 | + int ret; |
|---|
| 1011 | + |
|---|
| 1012 | + ret = security_locked_down(LOCKDOWN_PCI_ACCESS); |
|---|
| 1013 | + if (ret) |
|---|
| 1014 | + return ret; |
|---|
| 1169 | 1015 | |
|---|
| 1170 | 1016 | if (res->flags & IORESOURCE_MEM && iomem_is_exclusive(res->start)) |
|---|
| 1171 | 1017 | return -EINVAL; |
|---|
| .. | .. |
|---|
| 1242 | 1088 | struct bin_attribute *attr, char *buf, |
|---|
| 1243 | 1089 | loff_t off, size_t count) |
|---|
| 1244 | 1090 | { |
|---|
| 1091 | + int ret; |
|---|
| 1092 | + |
|---|
| 1093 | + ret = security_locked_down(LOCKDOWN_PCI_ACCESS); |
|---|
| 1094 | + if (ret) |
|---|
| 1095 | + return ret; |
|---|
| 1096 | + |
|---|
| 1245 | 1097 | return pci_resource_io(filp, kobj, attr, buf, off, count, true); |
|---|
| 1246 | 1098 | } |
|---|
| 1247 | 1099 | |
|---|
| .. | .. |
|---|
| 1256 | 1108 | { |
|---|
| 1257 | 1109 | int i; |
|---|
| 1258 | 1110 | |
|---|
| 1259 | | - for (i = 0; i < PCI_ROM_RESOURCE; i++) { |
|---|
| 1111 | + for (i = 0; i < PCI_STD_NUM_BARS; i++) { |
|---|
| 1260 | 1112 | struct bin_attribute *res_attr; |
|---|
| 1261 | 1113 | |
|---|
| 1262 | 1114 | res_attr = pdev->res_attr[i]; |
|---|
| .. | .. |
|---|
| 1305 | 1157 | } |
|---|
| 1306 | 1158 | } |
|---|
| 1307 | 1159 | res_attr->attr.name = res_attr_name; |
|---|
| 1308 | | - res_attr->attr.mode = S_IRUSR | S_IWUSR; |
|---|
| 1160 | + res_attr->attr.mode = 0600; |
|---|
| 1309 | 1161 | res_attr->size = pci_resource_len(pdev, num); |
|---|
| 1310 | 1162 | res_attr->private = (void *)(unsigned long)num; |
|---|
| 1311 | 1163 | retval = sysfs_create_bin_file(&pdev->dev.kobj, res_attr); |
|---|
| .. | .. |
|---|
| 1327 | 1179 | int retval; |
|---|
| 1328 | 1180 | |
|---|
| 1329 | 1181 | /* Expose the PCI resources from this device as files */ |
|---|
| 1330 | | - for (i = 0; i < PCI_ROM_RESOURCE; i++) { |
|---|
| 1182 | + for (i = 0; i < PCI_STD_NUM_BARS; i++) { |
|---|
| 1331 | 1183 | |
|---|
| 1332 | 1184 | /* skip empty resources */ |
|---|
| 1333 | 1185 | if (!pci_resource_len(pdev, i)) |
|---|
| .. | .. |
|---|
| 1345 | 1197 | } |
|---|
| 1346 | 1198 | return 0; |
|---|
| 1347 | 1199 | } |
|---|
| 1348 | | -#else /* !HAVE_PCI_MMAP */ |
|---|
| 1200 | +#else /* !(defined(HAVE_PCI_MMAP) || defined(ARCH_GENERIC_PCI_MMAP_RESOURCE)) */ |
|---|
| 1349 | 1201 | int __weak pci_create_resource_files(struct pci_dev *dev) { return 0; } |
|---|
| 1350 | 1202 | void __weak pci_remove_resource_files(struct pci_dev *dev) { return; } |
|---|
| 1351 | | -#endif /* HAVE_PCI_MMAP */ |
|---|
| 1203 | +#endif |
|---|
| 1352 | 1204 | |
|---|
| 1353 | 1205 | /** |
|---|
| 1354 | 1206 | * pci_write_rom - used to enable access to the PCI ROM display |
|---|
| .. | .. |
|---|
| 1418 | 1270 | static const struct bin_attribute pci_config_attr = { |
|---|
| 1419 | 1271 | .attr = { |
|---|
| 1420 | 1272 | .name = "config", |
|---|
| 1421 | | - .mode = S_IRUGO | S_IWUSR, |
|---|
| 1273 | + .mode = 0644, |
|---|
| 1422 | 1274 | }, |
|---|
| 1423 | 1275 | .size = PCI_CFG_SPACE_SIZE, |
|---|
| 1424 | 1276 | .read = pci_read_config, |
|---|
| .. | .. |
|---|
| 1428 | 1280 | static const struct bin_attribute pcie_config_attr = { |
|---|
| 1429 | 1281 | .attr = { |
|---|
| 1430 | 1282 | .name = "config", |
|---|
| 1431 | | - .mode = S_IRUGO | S_IWUSR, |
|---|
| 1283 | + .mode = 0644, |
|---|
| 1432 | 1284 | }, |
|---|
| 1433 | 1285 | .size = PCI_CFG_SPACE_EXP_SIZE, |
|---|
| 1434 | 1286 | .read = pci_read_config, |
|---|
| .. | .. |
|---|
| 1457 | 1309 | return count; |
|---|
| 1458 | 1310 | } |
|---|
| 1459 | 1311 | |
|---|
| 1460 | | -static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_store); |
|---|
| 1312 | +static DEVICE_ATTR(reset, 0200, NULL, reset_store); |
|---|
| 1461 | 1313 | |
|---|
| 1462 | 1314 | static int pci_create_capabilities_sysfs(struct pci_dev *dev) |
|---|
| 1463 | 1315 | { |
|---|
| 1464 | 1316 | int retval; |
|---|
| 1465 | 1317 | |
|---|
| 1466 | 1318 | pcie_vpd_create_sysfs_dev_files(dev); |
|---|
| 1467 | | - pcie_aspm_create_sysfs_dev_files(dev); |
|---|
| 1468 | 1319 | |
|---|
| 1469 | 1320 | if (dev->reset_fn) { |
|---|
| 1470 | | - retval = device_create_file(&dev->dev, &reset_attr); |
|---|
| 1321 | + retval = device_create_file(&dev->dev, &dev_attr_reset); |
|---|
| 1471 | 1322 | if (retval) |
|---|
| 1472 | 1323 | goto error; |
|---|
| 1473 | 1324 | } |
|---|
| 1474 | 1325 | return 0; |
|---|
| 1475 | 1326 | |
|---|
| 1476 | 1327 | error: |
|---|
| 1477 | | - pcie_aspm_remove_sysfs_dev_files(dev); |
|---|
| 1478 | 1328 | pcie_vpd_remove_sysfs_dev_files(dev); |
|---|
| 1479 | 1329 | return retval; |
|---|
| 1480 | 1330 | } |
|---|
| .. | .. |
|---|
| 1487 | 1337 | |
|---|
| 1488 | 1338 | if (!sysfs_initialized) |
|---|
| 1489 | 1339 | return -EACCES; |
|---|
| 1340 | + |
|---|
| 1341 | +#ifdef CONFIG_NO_GKI |
|---|
| 1342 | + if (atomic_cmpxchg(&pdev->sysfs_init_cnt, 0, 1) == 1) |
|---|
| 1343 | + return 0; /* already added */ |
|---|
| 1344 | +#endif |
|---|
| 1490 | 1345 | |
|---|
| 1491 | 1346 | if (pdev->cfg_size > PCI_CFG_SPACE_SIZE) |
|---|
| 1492 | 1347 | retval = sysfs_create_bin_file(&pdev->dev.kobj, &pcie_config_attr); |
|---|
| .. | .. |
|---|
| 1510 | 1365 | sysfs_bin_attr_init(attr); |
|---|
| 1511 | 1366 | attr->size = rom_size; |
|---|
| 1512 | 1367 | attr->attr.name = "rom"; |
|---|
| 1513 | | - attr->attr.mode = S_IRUSR | S_IWUSR; |
|---|
| 1368 | + attr->attr.mode = 0600; |
|---|
| 1514 | 1369 | attr->read = pci_read_rom; |
|---|
| 1515 | 1370 | attr->write = pci_write_rom; |
|---|
| 1516 | 1371 | retval = sysfs_create_bin_file(&pdev->dev.kobj, attr); |
|---|
| .. | .. |
|---|
| 1550 | 1405 | static void pci_remove_capabilities_sysfs(struct pci_dev *dev) |
|---|
| 1551 | 1406 | { |
|---|
| 1552 | 1407 | pcie_vpd_remove_sysfs_dev_files(dev); |
|---|
| 1553 | | - pcie_aspm_remove_sysfs_dev_files(dev); |
|---|
| 1554 | 1408 | if (dev->reset_fn) { |
|---|
| 1555 | | - device_remove_file(&dev->dev, &reset_attr); |
|---|
| 1409 | + device_remove_file(&dev->dev, &dev_attr_reset); |
|---|
| 1556 | 1410 | dev->reset_fn = 0; |
|---|
| 1557 | 1411 | } |
|---|
| 1558 | 1412 | } |
|---|
| .. | .. |
|---|
| 1567 | 1421 | { |
|---|
| 1568 | 1422 | if (!sysfs_initialized) |
|---|
| 1569 | 1423 | return; |
|---|
| 1424 | + |
|---|
| 1425 | +#ifdef CONFIG_NO_GKI |
|---|
| 1426 | + if (atomic_cmpxchg(&pdev->sysfs_init_cnt, 1, 0) == 0) |
|---|
| 1427 | + return; /* already removed */ |
|---|
| 1428 | +#endif |
|---|
| 1570 | 1429 | |
|---|
| 1571 | 1430 | pci_remove_capabilities_sysfs(pdev); |
|---|
| 1572 | 1431 | |
|---|
| .. | .. |
|---|
| 1605 | 1464 | late_initcall(pci_sysfs_init); |
|---|
| 1606 | 1465 | |
|---|
| 1607 | 1466 | static struct attribute *pci_dev_dev_attrs[] = { |
|---|
| 1608 | | - &vga_attr.attr, |
|---|
| 1467 | + &dev_attr_boot_vga.attr, |
|---|
| 1609 | 1468 | NULL, |
|---|
| 1610 | 1469 | }; |
|---|
| 1611 | 1470 | |
|---|
| .. | .. |
|---|
| 1615 | 1474 | struct device *dev = kobj_to_dev(kobj); |
|---|
| 1616 | 1475 | struct pci_dev *pdev = to_pci_dev(dev); |
|---|
| 1617 | 1476 | |
|---|
| 1618 | | - if (a == &vga_attr.attr) |
|---|
| 1477 | + if (a == &dev_attr_boot_vga.attr) |
|---|
| 1619 | 1478 | if ((pdev->class >> 8) != PCI_CLASS_DISPLAY_VGA) |
|---|
| 1620 | 1479 | return 0; |
|---|
| 1621 | 1480 | |
|---|
| .. | .. |
|---|
| 1623 | 1482 | } |
|---|
| 1624 | 1483 | |
|---|
| 1625 | 1484 | static struct attribute *pci_dev_hp_attrs[] = { |
|---|
| 1626 | | - &dev_remove_attr.attr, |
|---|
| 1627 | | - &dev_rescan_attr.attr, |
|---|
| 1485 | + &dev_attr_remove.attr, |
|---|
| 1486 | + &dev_attr_dev_rescan.attr, |
|---|
| 1628 | 1487 | NULL, |
|---|
| 1629 | 1488 | }; |
|---|
| 1630 | 1489 | |
|---|
| .. | .. |
|---|
| 1673 | 1532 | NULL, |
|---|
| 1674 | 1533 | }; |
|---|
| 1675 | 1534 | |
|---|
| 1676 | | -static const struct attribute_group pci_bridge_group = { |
|---|
| 1677 | | - .attrs = pci_bridge_attrs, |
|---|
| 1678 | | -}; |
|---|
| 1679 | | - |
|---|
| 1680 | | -const struct attribute_group *pci_bridge_groups[] = { |
|---|
| 1681 | | - &pci_bridge_group, |
|---|
| 1682 | | - NULL, |
|---|
| 1683 | | -}; |
|---|
| 1684 | | - |
|---|
| 1685 | | -static const struct attribute_group pcie_dev_group = { |
|---|
| 1686 | | - .attrs = pcie_dev_attrs, |
|---|
| 1687 | | -}; |
|---|
| 1688 | | - |
|---|
| 1689 | | -const struct attribute_group *pcie_dev_groups[] = { |
|---|
| 1690 | | - &pcie_dev_group, |
|---|
| 1691 | | - NULL, |
|---|
| 1692 | | -}; |
|---|
| 1693 | | - |
|---|
| 1694 | 1535 | static const struct attribute_group pci_dev_hp_attr_group = { |
|---|
| 1695 | 1536 | .attrs = pci_dev_hp_attrs, |
|---|
| 1696 | 1537 | .is_visible = pci_dev_hp_attrs_are_visible, |
|---|
| 1697 | 1538 | }; |
|---|
| 1698 | | - |
|---|
| 1699 | | -#ifdef CONFIG_PCI_IOV |
|---|
| 1700 | | -static struct attribute *sriov_dev_attrs[] = { |
|---|
| 1701 | | - &sriov_totalvfs_attr.attr, |
|---|
| 1702 | | - &sriov_numvfs_attr.attr, |
|---|
| 1703 | | - &sriov_offset_attr.attr, |
|---|
| 1704 | | - &sriov_stride_attr.attr, |
|---|
| 1705 | | - &sriov_vf_device_attr.attr, |
|---|
| 1706 | | - &sriov_drivers_autoprobe_attr.attr, |
|---|
| 1707 | | - NULL, |
|---|
| 1708 | | -}; |
|---|
| 1709 | | - |
|---|
| 1710 | | -static umode_t sriov_attrs_are_visible(struct kobject *kobj, |
|---|
| 1711 | | - struct attribute *a, int n) |
|---|
| 1712 | | -{ |
|---|
| 1713 | | - struct device *dev = kobj_to_dev(kobj); |
|---|
| 1714 | | - |
|---|
| 1715 | | - if (!dev_is_pf(dev)) |
|---|
| 1716 | | - return 0; |
|---|
| 1717 | | - |
|---|
| 1718 | | - return a->mode; |
|---|
| 1719 | | -} |
|---|
| 1720 | | - |
|---|
| 1721 | | -static const struct attribute_group sriov_dev_attr_group = { |
|---|
| 1722 | | - .attrs = sriov_dev_attrs, |
|---|
| 1723 | | - .is_visible = sriov_attrs_are_visible, |
|---|
| 1724 | | -}; |
|---|
| 1725 | | -#endif /* CONFIG_PCI_IOV */ |
|---|
| 1726 | 1539 | |
|---|
| 1727 | 1540 | static const struct attribute_group pci_dev_attr_group = { |
|---|
| 1728 | 1541 | .attrs = pci_dev_dev_attrs, |
|---|
| .. | .. |
|---|
| 1750 | 1563 | #ifdef CONFIG_PCIEAER |
|---|
| 1751 | 1564 | &aer_stats_attr_group, |
|---|
| 1752 | 1565 | #endif |
|---|
| 1566 | +#ifdef CONFIG_PCIEASPM |
|---|
| 1567 | + &aspm_ctrl_attr_group, |
|---|
| 1568 | +#endif |
|---|
| 1753 | 1569 | NULL, |
|---|
| 1754 | 1570 | }; |
|---|
| 1755 | 1571 | |
|---|