Commit 6ce54f02 authored by Bjorn Helgaas's avatar Bjorn Helgaas

Merge branch 'pci/misc'

  - Use devm_add_action_or_reset() helper (Fuqian Huang)

  - Mark expected switch fall-through (Gustavo A. R. Silva)

  - Convert sysfs device attributes from __ATTR() to DEVICE_ATTR() (Kelsey
    Skunberg)

  - Convert sysfs file permissions from S_IRUSR etc to octal (Kelsey
    Skunberg)

  - Move SR-IOV sysfs functions to iov.c (Kelsey Skunberg)

  - Add pci_info_ratelimited() to ratelimit PCI messages separately
    (Krzysztof Wilczynski)

  - Fix "'static' not at beginning of declaration" warnings (Krzysztof
    Wilczynski)

  - Clean up resource_alignment parameter to not require static buffer
    (Logan Gunthorpe)

  - Add ACS quirk for iProc PAXB (Abhinav Ratna)

  - Add pci_irq_vector() and other stubs for !CONFIG_PCI (Herbert Xu)

* pci/misc:
  PCI: Add pci_irq_vector() and other stubs when !CONFIG_PCI
  PCI: Add ACS quirk for iProc PAXB
  PCI: Force trailing new line to resource_alignment_param in sysfs
  PCI: Move pci_[get|set]_resource_alignment_param() into their callers
  PCI: Clean up resource_alignment parameter to not require static buffer
  PCI: Use static const struct, not const static struct
  PCI: Add pci_info_ratelimited() to ratelimit PCI separately
  PCI/IOV: Remove group write permission from sriov_numvfs, sriov_drivers_autoprobe
  PCI/IOV: Move sysfs SR-IOV functions to iov.c
  PCI: sysfs: Change permissions from symbolic to octal
  PCI: sysfs: Change DEVICE_ATTR() to DEVICE_ATTR_WO()
  PCI: sysfs: Define device attributes with DEVICE_ATTR*()
  PCI: Mark expected switch fall-through
  PCI: Use devm_add_action_or_reset()
parents a10a1f60 0d8006dd
...@@ -43,9 +43,8 @@ static struct pci_config_window *gen_pci_init(struct device *dev, ...@@ -43,9 +43,8 @@ static struct pci_config_window *gen_pci_init(struct device *dev,
goto err_out; goto err_out;
} }
err = devm_add_action(dev, gen_pci_unmap_cfg, cfg); err = devm_add_action_or_reset(dev, gen_pci_unmap_cfg, cfg);
if (err) { if (err) {
gen_pci_unmap_cfg(cfg);
goto err_out; goto err_out;
} }
return cfg; return cfg;
......
...@@ -1941,6 +1941,7 @@ static int __init update_bridge_ranges(struct bus_node **bus) ...@@ -1941,6 +1941,7 @@ static int __init update_bridge_ranges(struct bus_node **bus)
break; break;
case PCI_HEADER_TYPE_BRIDGE: case PCI_HEADER_TYPE_BRIDGE:
function = 0x8; function = 0x8;
/* fall through */
case PCI_HEADER_TYPE_MULTIBRIDGE: case PCI_HEADER_TYPE_MULTIBRIDGE:
/* We assume here that only 1 bus behind the bridge /* We assume here that only 1 bus behind the bridge
TO DO: add functionality for several: TO DO: add functionality for several:
......
...@@ -240,6 +240,173 @@ void pci_iov_remove_virtfn(struct pci_dev *dev, int id) ...@@ -240,6 +240,173 @@ void pci_iov_remove_virtfn(struct pci_dev *dev, int id)
pci_dev_put(dev); pci_dev_put(dev);
} }
static ssize_t sriov_totalvfs_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct pci_dev *pdev = to_pci_dev(dev);
return sprintf(buf, "%u\n", pci_sriov_get_totalvfs(pdev));
}
static ssize_t sriov_numvfs_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct pci_dev *pdev = to_pci_dev(dev);
return sprintf(buf, "%u\n", pdev->sriov->num_VFs);
}
/*
* num_vfs > 0; number of VFs to enable
* num_vfs = 0; disable all VFs
*
* Note: SRIOV spec does not allow partial VF
* disable, so it's all or none.
*/
static ssize_t sriov_numvfs_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct pci_dev *pdev = to_pci_dev(dev);
int ret;
u16 num_vfs;
ret = kstrtou16(buf, 0, &num_vfs);
if (ret < 0)
return ret;
if (num_vfs > pci_sriov_get_totalvfs(pdev))
return -ERANGE;
device_lock(&pdev->dev);
if (num_vfs == pdev->sriov->num_VFs)
goto exit;
/* is PF driver loaded w/callback */
if (!pdev->driver || !pdev->driver->sriov_configure) {
pci_info(pdev, "Driver does not support SRIOV configuration via sysfs\n");
ret = -ENOENT;
goto exit;
}
if (num_vfs == 0) {
/* disable VFs */
ret = pdev->driver->sriov_configure(pdev, 0);
goto exit;
}
/* enable VFs */
if (pdev->sriov->num_VFs) {
pci_warn(pdev, "%d VFs already enabled. Disable before enabling %d VFs\n",
pdev->sriov->num_VFs, num_vfs);
ret = -EBUSY;
goto exit;
}
ret = pdev->driver->sriov_configure(pdev, num_vfs);
if (ret < 0)
goto exit;
if (ret != num_vfs)
pci_warn(pdev, "%d VFs requested; only %d enabled\n",
num_vfs, ret);
exit:
device_unlock(&pdev->dev);
if (ret < 0)
return ret;
return count;
}
static ssize_t sriov_offset_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct pci_dev *pdev = to_pci_dev(dev);
return sprintf(buf, "%u\n", pdev->sriov->offset);
}
static ssize_t sriov_stride_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct pci_dev *pdev = to_pci_dev(dev);
return sprintf(buf, "%u\n", pdev->sriov->stride);
}
static ssize_t sriov_vf_device_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct pci_dev *pdev = to_pci_dev(dev);
return sprintf(buf, "%x\n", pdev->sriov->vf_device);
}
static ssize_t sriov_drivers_autoprobe_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct pci_dev *pdev = to_pci_dev(dev);
return sprintf(buf, "%u\n", pdev->sriov->drivers_autoprobe);
}
static ssize_t sriov_drivers_autoprobe_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct pci_dev *pdev = to_pci_dev(dev);
bool drivers_autoprobe;
if (kstrtobool(buf, &drivers_autoprobe) < 0)
return -EINVAL;
pdev->sriov->drivers_autoprobe = drivers_autoprobe;
return count;
}
static DEVICE_ATTR_RO(sriov_totalvfs);
static DEVICE_ATTR_RW(sriov_numvfs);
static DEVICE_ATTR_RO(sriov_offset);
static DEVICE_ATTR_RO(sriov_stride);
static DEVICE_ATTR_RO(sriov_vf_device);
static DEVICE_ATTR_RW(sriov_drivers_autoprobe);
static struct attribute *sriov_dev_attrs[] = {
&dev_attr_sriov_totalvfs.attr,
&dev_attr_sriov_numvfs.attr,
&dev_attr_sriov_offset.attr,
&dev_attr_sriov_stride.attr,
&dev_attr_sriov_vf_device.attr,
&dev_attr_sriov_drivers_autoprobe.attr,
NULL,
};
static umode_t sriov_attrs_are_visible(struct kobject *kobj,
struct attribute *a, int n)
{
struct device *dev = kobj_to_dev(kobj);
if (!dev_is_pf(dev))
return 0;
return a->mode;
}
const struct attribute_group sriov_dev_attr_group = {
.attrs = sriov_dev_attrs,
.is_visible = sriov_attrs_are_visible,
};
int __weak pcibios_sriov_enable(struct pci_dev *pdev, u16 num_vfs) int __weak pcibios_sriov_enable(struct pci_dev *pdev, u16 num_vfs)
{ {
return 0; return 0;
......
...@@ -38,7 +38,7 @@ struct pci_bridge_reg_behavior { ...@@ -38,7 +38,7 @@ struct pci_bridge_reg_behavior {
u32 rsvd; u32 rsvd;
}; };
const static struct pci_bridge_reg_behavior pci_regs_behavior[] = { static const struct pci_bridge_reg_behavior pci_regs_behavior[] = {
[PCI_VENDOR_ID / 4] = { .ro = ~0 }, [PCI_VENDOR_ID / 4] = { .ro = ~0 },
[PCI_COMMAND / 4] = { [PCI_COMMAND / 4] = {
.rw = (PCI_COMMAND_IO | PCI_COMMAND_MEMORY | .rw = (PCI_COMMAND_IO | PCI_COMMAND_MEMORY |
...@@ -173,7 +173,7 @@ const static struct pci_bridge_reg_behavior pci_regs_behavior[] = { ...@@ -173,7 +173,7 @@ const static struct pci_bridge_reg_behavior pci_regs_behavior[] = {
}, },
}; };
const static struct pci_bridge_reg_behavior pcie_cap_regs_behavior[] = { static const struct pci_bridge_reg_behavior pcie_cap_regs_behavior[] = {
[PCI_CAP_LIST_ID / 4] = { [PCI_CAP_LIST_ID / 4] = {
/* /*
* Capability ID, Next Capability Pointer and * Capability ID, Next Capability Pointer and
......
...@@ -464,9 +464,7 @@ static ssize_t dev_rescan_store(struct device *dev, ...@@ -464,9 +464,7 @@ static ssize_t dev_rescan_store(struct device *dev,
} }
return count; return count;
} }
static struct device_attribute dev_rescan_attr = __ATTR(rescan, static DEVICE_ATTR_WO(dev_rescan);
(S_IWUSR|S_IWGRP),
NULL, dev_rescan_store);
static ssize_t remove_store(struct device *dev, struct device_attribute *attr, static ssize_t remove_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count) const char *buf, size_t count)
...@@ -480,11 +478,10 @@ static ssize_t remove_store(struct device *dev, struct device_attribute *attr, ...@@ -480,11 +478,10 @@ static ssize_t remove_store(struct device *dev, struct device_attribute *attr,
pci_stop_and_remove_bus_device_locked(to_pci_dev(dev)); pci_stop_and_remove_bus_device_locked(to_pci_dev(dev));
return count; return count;
} }
static struct device_attribute dev_remove_attr = __ATTR_IGNORE_LOCKDEP(remove, static DEVICE_ATTR_IGNORE_LOCKDEP(remove, 0220, NULL,
(S_IWUSR|S_IWGRP), remove_store);
NULL, remove_store);
static ssize_t dev_bus_rescan_store(struct device *dev, static ssize_t bus_rescan_store(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr,
const char *buf, size_t count) const char *buf, size_t count)
{ {
...@@ -504,7 +501,7 @@ static ssize_t dev_bus_rescan_store(struct device *dev, ...@@ -504,7 +501,7 @@ static ssize_t dev_bus_rescan_store(struct device *dev,
} }
return count; return count;
} }
static DEVICE_ATTR(rescan, (S_IWUSR|S_IWGRP), NULL, dev_bus_rescan_store); static DEVICE_ATTR_WO(bus_rescan);
#if defined(CONFIG_PM) && defined(CONFIG_ACPI) #if defined(CONFIG_PM) && defined(CONFIG_ACPI)
static ssize_t d3cold_allowed_store(struct device *dev, static ssize_t d3cold_allowed_store(struct device *dev,
...@@ -551,154 +548,6 @@ static ssize_t devspec_show(struct device *dev, ...@@ -551,154 +548,6 @@ static ssize_t devspec_show(struct device *dev,
static DEVICE_ATTR_RO(devspec); static DEVICE_ATTR_RO(devspec);
#endif #endif
#ifdef CONFIG_PCI_IOV
static ssize_t sriov_totalvfs_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct pci_dev *pdev = to_pci_dev(dev);
return sprintf(buf, "%u\n", pci_sriov_get_totalvfs(pdev));
}
static ssize_t sriov_numvfs_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct pci_dev *pdev = to_pci_dev(dev);
return sprintf(buf, "%u\n", pdev->sriov->num_VFs);
}
/*
* num_vfs > 0; number of VFs to enable
* num_vfs = 0; disable all VFs
*
* Note: SRIOV spec doesn't allow partial VF
* disable, so it's all or none.
*/
static ssize_t sriov_numvfs_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct pci_dev *pdev = to_pci_dev(dev);
int ret;
u16 num_vfs;
ret = kstrtou16(buf, 0, &num_vfs);
if (ret < 0)
return ret;
if (num_vfs > pci_sriov_get_totalvfs(pdev))
return -ERANGE;
device_lock(&pdev->dev);
if (num_vfs == pdev->sriov->num_VFs)
goto exit;
/* is PF driver loaded w/callback */
if (!pdev->driver || !pdev->driver->sriov_configure) {
pci_info(pdev, "Driver doesn't support SRIOV configuration via sysfs\n");
ret = -ENOENT;
goto exit;
}
if (num_vfs == 0) {
/* disable VFs */
ret = pdev->driver->sriov_configure(pdev, 0);
goto exit;
}
/* enable VFs */
if (pdev->sriov->num_VFs) {
pci_warn(pdev, "%d VFs already enabled. Disable before enabling %d VFs\n",
pdev->sriov->num_VFs, num_vfs);
ret = -EBUSY;
goto exit;
}
ret = pdev->driver->sriov_configure(pdev, num_vfs);
if (ret < 0)
goto exit;
if (ret != num_vfs)
pci_warn(pdev, "%d VFs requested; only %d enabled\n",
num_vfs, ret);
exit:
device_unlock(&pdev->dev);
if (ret < 0)
return ret;
return count;
}
static ssize_t sriov_offset_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct pci_dev *pdev = to_pci_dev(dev);
return sprintf(buf, "%u\n", pdev->sriov->offset);
}
static ssize_t sriov_stride_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct pci_dev *pdev = to_pci_dev(dev);
return sprintf(buf, "%u\n", pdev->sriov->stride);
}
static ssize_t sriov_vf_device_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct pci_dev *pdev = to_pci_dev(dev);
return sprintf(buf, "%x\n", pdev->sriov->vf_device);
}
static ssize_t sriov_drivers_autoprobe_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct pci_dev *pdev = to_pci_dev(dev);
return sprintf(buf, "%u\n", pdev->sriov->drivers_autoprobe);
}
static ssize_t sriov_drivers_autoprobe_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct pci_dev *pdev = to_pci_dev(dev);
bool drivers_autoprobe;
if (kstrtobool(buf, &drivers_autoprobe) < 0)
return -EINVAL;
pdev->sriov->drivers_autoprobe = drivers_autoprobe;
return count;
}
static struct device_attribute sriov_totalvfs_attr = __ATTR_RO(sriov_totalvfs);
static struct device_attribute sriov_numvfs_attr =
__ATTR(sriov_numvfs, (S_IRUGO|S_IWUSR|S_IWGRP),
sriov_numvfs_show, sriov_numvfs_store);
static struct device_attribute sriov_offset_attr = __ATTR_RO(sriov_offset);
static struct device_attribute sriov_stride_attr = __ATTR_RO(sriov_stride);
static struct device_attribute sriov_vf_device_attr = __ATTR_RO(sriov_vf_device);
static struct device_attribute sriov_drivers_autoprobe_attr =
__ATTR(sriov_drivers_autoprobe, (S_IRUGO|S_IWUSR|S_IWGRP),
sriov_drivers_autoprobe_show, sriov_drivers_autoprobe_store);
#endif /* CONFIG_PCI_IOV */
static ssize_t driver_override_store(struct device *dev, static ssize_t driver_override_store(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr,
const char *buf, size_t count) const char *buf, size_t count)
...@@ -792,7 +641,7 @@ static struct attribute *pcie_dev_attrs[] = { ...@@ -792,7 +641,7 @@ static struct attribute *pcie_dev_attrs[] = {
}; };
static struct attribute *pcibus_attrs[] = { static struct attribute *pcibus_attrs[] = {
&dev_attr_rescan.attr, &dev_attr_bus_rescan.attr,
&dev_attr_cpuaffinity.attr, &dev_attr_cpuaffinity.attr,
&dev_attr_cpulistaffinity.attr, &dev_attr_cpulistaffinity.attr,
NULL, NULL,
...@@ -820,7 +669,7 @@ static ssize_t boot_vga_show(struct device *dev, struct device_attribute *attr, ...@@ -820,7 +669,7 @@ static ssize_t boot_vga_show(struct device *dev, struct device_attribute *attr,
!!(pdev->resource[PCI_ROM_RESOURCE].flags & !!(pdev->resource[PCI_ROM_RESOURCE].flags &
IORESOURCE_ROM_SHADOW)); IORESOURCE_ROM_SHADOW));
} }
static struct device_attribute vga_attr = __ATTR_RO(boot_vga); static DEVICE_ATTR_RO(boot_vga);
static ssize_t pci_read_config(struct file *filp, struct kobject *kobj, static ssize_t pci_read_config(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr, char *buf, struct bin_attribute *bin_attr, char *buf,
...@@ -1085,7 +934,7 @@ void pci_create_legacy_files(struct pci_bus *b) ...@@ -1085,7 +934,7 @@ void pci_create_legacy_files(struct pci_bus *b)
sysfs_bin_attr_init(b->legacy_io); sysfs_bin_attr_init(b->legacy_io);
b->legacy_io->attr.name = "legacy_io"; b->legacy_io->attr.name = "legacy_io";
b->legacy_io->size = 0xffff; b->legacy_io->size = 0xffff;
b->legacy_io->attr.mode = S_IRUSR | S_IWUSR; b->legacy_io->attr.mode = 0600;
b->legacy_io->read = pci_read_legacy_io; b->legacy_io->read = pci_read_legacy_io;
b->legacy_io->write = pci_write_legacy_io; b->legacy_io->write = pci_write_legacy_io;
b->legacy_io->mmap = pci_mmap_legacy_io; b->legacy_io->mmap = pci_mmap_legacy_io;
...@@ -1099,7 +948,7 @@ void pci_create_legacy_files(struct pci_bus *b) ...@@ -1099,7 +948,7 @@ void pci_create_legacy_files(struct pci_bus *b)
sysfs_bin_attr_init(b->legacy_mem); sysfs_bin_attr_init(b->legacy_mem);
b->legacy_mem->attr.name = "legacy_mem"; b->legacy_mem->attr.name = "legacy_mem";
b->legacy_mem->size = 1024*1024; b->legacy_mem->size = 1024*1024;
b->legacy_mem->attr.mode = S_IRUSR | S_IWUSR; b->legacy_mem->attr.mode = 0600;
b->legacy_mem->mmap = pci_mmap_legacy_mem; b->legacy_mem->mmap = pci_mmap_legacy_mem;
pci_adjust_legacy_attr(b, pci_mmap_mem); pci_adjust_legacy_attr(b, pci_mmap_mem);
error = device_create_bin_file(&b->dev, b->legacy_mem); error = device_create_bin_file(&b->dev, b->legacy_mem);
...@@ -1306,7 +1155,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine) ...@@ -1306,7 +1155,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
} }
} }
res_attr->attr.name = res_attr_name; res_attr->attr.name = res_attr_name;
res_attr->attr.mode = S_IRUSR | S_IWUSR; res_attr->attr.mode = 0600;
res_attr->size = pci_resource_len(pdev, num); res_attr->size = pci_resource_len(pdev, num);
res_attr->private = (void *)(unsigned long)num; res_attr->private = (void *)(unsigned long)num;
retval = sysfs_create_bin_file(&pdev->dev.kobj, res_attr); retval = sysfs_create_bin_file(&pdev->dev.kobj, res_attr);
...@@ -1419,7 +1268,7 @@ static ssize_t pci_read_rom(struct file *filp, struct kobject *kobj, ...@@ -1419,7 +1268,7 @@ static ssize_t pci_read_rom(struct file *filp, struct kobject *kobj,
static const struct bin_attribute pci_config_attr = { static const struct bin_attribute pci_config_attr = {
.attr = { .attr = {
.name = "config", .name = "config",
.mode = S_IRUGO | S_IWUSR, .mode = 0644,
}, },
.size = PCI_CFG_SPACE_SIZE, .size = PCI_CFG_SPACE_SIZE,
.read = pci_read_config, .read = pci_read_config,
...@@ -1429,7 +1278,7 @@ static const struct bin_attribute pci_config_attr = { ...@@ -1429,7 +1278,7 @@ static const struct bin_attribute pci_config_attr = {
static const struct bin_attribute pcie_config_attr = { static const struct bin_attribute pcie_config_attr = {
.attr = { .attr = {
.name = "config", .name = "config",
.mode = S_IRUGO | S_IWUSR, .mode = 0644,
}, },
.size = PCI_CFG_SPACE_EXP_SIZE, .size = PCI_CFG_SPACE_EXP_SIZE,
.read = pci_read_config, .read = pci_read_config,
...@@ -1458,7 +1307,7 @@ static ssize_t reset_store(struct device *dev, struct device_attribute *attr, ...@@ -1458,7 +1307,7 @@ static ssize_t reset_store(struct device *dev, struct device_attribute *attr,
return count; return count;
} }
static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_store); static DEVICE_ATTR(reset, 0200, NULL, reset_store);
static int pci_create_capabilities_sysfs(struct pci_dev *dev) static int pci_create_capabilities_sysfs(struct pci_dev *dev)
{ {
...@@ -1468,7 +1317,7 @@ static int pci_create_capabilities_sysfs(struct pci_dev *dev) ...@@ -1468,7 +1317,7 @@ static int pci_create_capabilities_sysfs(struct pci_dev *dev)
pcie_aspm_create_sysfs_dev_files(dev); pcie_aspm_create_sysfs_dev_files(dev);
if (dev->reset_fn) { if (dev->reset_fn) {
retval = device_create_file(&dev->dev, &reset_attr); retval = device_create_file(&dev->dev, &dev_attr_reset);
if (retval) if (retval)
goto error; goto error;
} }
...@@ -1511,7 +1360,7 @@ int __must_check pci_create_sysfs_dev_files(struct pci_dev *pdev) ...@@ -1511,7 +1360,7 @@ int __must_check pci_create_sysfs_dev_files(struct pci_dev *pdev)
sysfs_bin_attr_init(attr); sysfs_bin_attr_init(attr);
attr->size = rom_size; attr->size = rom_size;
attr->attr.name = "rom"; attr->attr.name = "rom";
attr->attr.mode = S_IRUSR | S_IWUSR; attr->attr.mode = 0600;
attr->read = pci_read_rom; attr->read = pci_read_rom;
attr->write = pci_write_rom; attr->write = pci_write_rom;
retval = sysfs_create_bin_file(&pdev->dev.kobj, attr); retval = sysfs_create_bin_file(&pdev->dev.kobj, attr);
...@@ -1553,7 +1402,7 @@ static void pci_remove_capabilities_sysfs(struct pci_dev *dev) ...@@ -1553,7 +1402,7 @@ static void pci_remove_capabilities_sysfs(struct pci_dev *dev)
pcie_vpd_remove_sysfs_dev_files(dev); pcie_vpd_remove_sysfs_dev_files(dev);
pcie_aspm_remove_sysfs_dev_files(dev); pcie_aspm_remove_sysfs_dev_files(dev);
if (dev->reset_fn) { if (dev->reset_fn) {
device_remove_file(&dev->dev, &reset_attr); device_remove_file(&dev->dev, &dev_attr_reset);
dev->reset_fn = 0; dev->reset_fn = 0;
} }
} }
...@@ -1606,7 +1455,7 @@ static int __init pci_sysfs_init(void) ...@@ -1606,7 +1455,7 @@ static int __init pci_sysfs_init(void)
late_initcall(pci_sysfs_init); late_initcall(pci_sysfs_init);
static struct attribute *pci_dev_dev_attrs[] = { static struct attribute *pci_dev_dev_attrs[] = {
&vga_attr.attr, &dev_attr_boot_vga.attr,
NULL, NULL,
}; };
...@@ -1616,7 +1465,7 @@ static umode_t pci_dev_attrs_are_visible(struct kobject *kobj, ...@@ -1616,7 +1465,7 @@ static umode_t pci_dev_attrs_are_visible(struct kobject *kobj,
struct device *dev = kobj_to_dev(kobj); struct device *dev = kobj_to_dev(kobj);
struct pci_dev *pdev = to_pci_dev(dev); struct pci_dev *pdev = to_pci_dev(dev);
if (a == &vga_attr.attr) if (a == &dev_attr_boot_vga.attr)
if ((pdev->class >> 8) != PCI_CLASS_DISPLAY_VGA) if ((pdev->class >> 8) != PCI_CLASS_DISPLAY_VGA)
return 0; return 0;
...@@ -1624,8 +1473,8 @@ static umode_t pci_dev_attrs_are_visible(struct kobject *kobj, ...@@ -1624,8 +1473,8 @@ static umode_t pci_dev_attrs_are_visible(struct kobject *kobj,
} }
static struct attribute *pci_dev_hp_attrs[] = { static struct attribute *pci_dev_hp_attrs[] = {
&dev_remove_attr.attr, &dev_attr_remove.attr,
&dev_rescan_attr.attr, &dev_attr_dev_rescan.attr,
NULL, NULL,
}; };
...@@ -1697,34 +1546,6 @@ static const struct attribute_group pci_dev_hp_attr_group = { ...@@ -1697,34 +1546,6 @@ static const struct attribute_group pci_dev_hp_attr_group = {
.is_visible = pci_dev_hp_attrs_are_visible, .is_visible = pci_dev_hp_attrs_are_visible,
}; };
#ifdef CONFIG_PCI_IOV
static struct attribute *sriov_dev_attrs[] = {
&sriov_totalvfs_attr.attr,
&sriov_numvfs_attr.attr,
&sriov_offset_attr.attr,
&sriov_stride_attr.attr,
&sriov_vf_device_attr.attr,
&sriov_drivers_autoprobe_attr.attr,
NULL,
};
static umode_t sriov_attrs_are_visible(struct kobject *kobj,
struct attribute *a, int n)
{
struct device *dev = kobj_to_dev(kobj);
if (!dev_is_pf(dev))
return 0;
return a->mode;
}
static const struct attribute_group sriov_dev_attr_group = {
.attrs = sriov_dev_attrs,
.is_visible = sriov_attrs_are_visible,
};
#endif /* CONFIG_PCI_IOV */
static const struct attribute_group pci_dev_attr_group = { static const struct attribute_group pci_dev_attr_group = {
.attrs = pci_dev_dev_attrs, .attrs = pci_dev_dev_attrs,
.is_visible = pci_dev_attrs_are_visible, .is_visible = pci_dev_attrs_are_visible,
......
...@@ -890,8 +890,8 @@ static int pci_raw_set_power_state(struct pci_dev *dev, pci_power_t state) ...@@ -890,8 +890,8 @@ static int pci_raw_set_power_state(struct pci_dev *dev, pci_power_t state)
pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr); pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
dev->current_state = (pmcsr & PCI_PM_CTRL_STATE_MASK); dev->current_state = (pmcsr & PCI_PM_CTRL_STATE_MASK);
if (dev->current_state != state && printk_ratelimit()) if (dev->current_state != state)
pci_info(dev, "Refused to change power state, currently in D%d\n", pci_info_ratelimited(dev, "Refused to change power state, currently in D%d\n",
dev->current_state); dev->current_state);
/* /*
...@@ -5932,8 +5932,7 @@ resource_size_t __weak pcibios_default_alignment(void) ...@@ -5932,8 +5932,7 @@ resource_size_t __weak pcibios_default_alignment(void)
return 0; return 0;
} }
#define RESOURCE_ALIGNMENT_PARAM_SIZE COMMAND_LINE_SIZE static char *resource_alignment_param;
static char resource_alignment_param[RESOURCE_ALIGNMENT_PARAM_SIZE] = {0};
static DEFINE_SPINLOCK(resource_alignment_lock); static DEFINE_SPINLOCK(resource_alignment_lock);
/** /**
...@@ -5954,7 +5953,7 @@ static resource_size_t pci_specified_resource_alignment(struct pci_dev *dev, ...@@ -5954,7 +5953,7 @@ static resource_size_t pci_specified_resource_alignment(struct pci_dev *dev,
spin_lock(&resource_alignment_lock); spin_lock(&resource_alignment_lock);
p = resource_alignment_param; p = resource_alignment_param;
if (!*p && !align) if (!p || !*p)
goto out; goto out;
if (pci_has_flag(PCI_PROBE_ONLY)) { if (pci_has_flag(PCI_PROBE_ONLY)) {
align = 0; align = 0;
...@@ -6118,35 +6117,41 @@ void pci_reassigndev_resource_alignment(struct pci_dev *dev) ...@@ -6118,35 +6117,41 @@ void pci_reassigndev_resource_alignment(struct pci_dev *dev)
} }
} }
static ssize_t pci_set_resource_alignment_param(const char *buf, size_t count) static ssize_t resource_alignment_show(struct bus_type *bus, char *buf)
{ {
if (count > RESOURCE_ALIGNMENT_PARAM_SIZE - 1) size_t count = 0;
count = RESOURCE_ALIGNMENT_PARAM_SIZE - 1;
spin_lock(&resource_alignment_lock);
strncpy(resource_alignment_param, buf, count);
resource_alignment_param[count] = '\0';
spin_unlock(&resource_alignment_lock);
return count;
}
static ssize_t pci_get_resource_alignment_param(char *buf, size_t size)
{
size_t count;
spin_lock(&resource_alignment_lock); spin_lock(&resource_alignment_lock);
count = snprintf(buf, size, "%s", resource_alignment_param); if (resource_alignment_param)
count = snprintf(buf, PAGE_SIZE, "%s", resource_alignment_param);
spin_unlock(&resource_alignment_lock); spin_unlock(&resource_alignment_lock);
return count;
}
static ssize_t resource_alignment_show(struct bus_type *bus, char *buf) /*
{ * When set by the command line, resource_alignment_param will not
return pci_get_resource_alignment_param(buf, PAGE_SIZE); * have a trailing line feed, which is ugly. So conditionally add
* it here.
*/
if (count >= 2 && buf[count - 2] != '\n' && count < PAGE_SIZE - 1) {
buf[count - 1] = '\n';
buf[count++] = 0;
}
return count;
} }
static ssize_t resource_alignment_store(struct bus_type *bus, static ssize_t resource_alignment_store(struct bus_type *bus,
const char *buf, size_t count) const char *buf, size_t count)
{ {
return pci_set_resource_alignment_param(buf, count); char *param = kstrndup(buf, count, GFP_KERNEL);
if (!param)
return -ENOMEM;
spin_lock(&resource_alignment_lock);
kfree(resource_alignment_param);
resource_alignment_param = param;
spin_unlock(&resource_alignment_lock);
return count;
} }
static BUS_ATTR_RW(resource_alignment); static BUS_ATTR_RW(resource_alignment);
...@@ -6275,8 +6280,7 @@ static int __init pci_setup(char *str) ...@@ -6275,8 +6280,7 @@ static int __init pci_setup(char *str)
} else if (!strncmp(str, "cbmemsize=", 10)) { } else if (!strncmp(str, "cbmemsize=", 10)) {
pci_cardbus_mem_size = memparse(str + 10, &str); pci_cardbus_mem_size = memparse(str + 10, &str);
} else if (!strncmp(str, "resource_alignment=", 19)) { } else if (!strncmp(str, "resource_alignment=", 19)) {
pci_set_resource_alignment_param(str + 19, resource_alignment_param = str + 19;
strlen(str + 19));
} else if (!strncmp(str, "ecrc=", 5)) { } else if (!strncmp(str, "ecrc=", 5)) {
pcie_ecrc_get_policy(str + 5); pcie_ecrc_get_policy(str + 5);
} else if (!strncmp(str, "hpiosize=", 9)) { } else if (!strncmp(str, "hpiosize=", 9)) {
...@@ -6311,15 +6315,18 @@ static int __init pci_setup(char *str) ...@@ -6311,15 +6315,18 @@ static int __init pci_setup(char *str)
early_param("pci", pci_setup); early_param("pci", pci_setup);
/* /*
* 'disable_acs_redir_param' is initialized in pci_setup(), above, to point * 'resource_alignment_param' and 'disable_acs_redir_param' are initialized
* to data in the __initdata section which will be freed after the init * in pci_setup(), above, to point to data in the __initdata section which
* sequence is complete. We can't allocate memory in pci_setup() because some * will be freed after the init sequence is complete. We can't allocate memory
* architectures do not have any memory allocation service available during * in pci_setup() because some architectures do not have any memory allocation
* an early_param() call. So we allocate memory and copy the variable here * service available during an early_param() call. So we allocate memory and
* before the init section is freed. * copy the variable here before the init section is freed.
*
*/ */
static int __init pci_realloc_setup_params(void) static int __init pci_realloc_setup_params(void)
{ {
resource_alignment_param = kstrdup(resource_alignment_param,
GFP_KERNEL);
disable_acs_redir_param = kstrdup(disable_acs_redir_param, GFP_KERNEL); disable_acs_redir_param = kstrdup(disable_acs_redir_param, GFP_KERNEL);
return 0; return 0;
......
...@@ -464,7 +464,7 @@ void pci_iov_update_resource(struct pci_dev *dev, int resno); ...@@ -464,7 +464,7 @@ void pci_iov_update_resource(struct pci_dev *dev, int resno);
resource_size_t pci_sriov_resource_alignment(struct pci_dev *dev, int resno); resource_size_t pci_sriov_resource_alignment(struct pci_dev *dev, int resno);
void pci_restore_iov_state(struct pci_dev *dev); void pci_restore_iov_state(struct pci_dev *dev);
int pci_iov_bus_range(struct pci_bus *bus); int pci_iov_bus_range(struct pci_bus *bus);
extern const struct attribute_group sriov_dev_attr_group;
#else #else
static inline int pci_iov_init(struct pci_dev *dev) static inline int pci_iov_init(struct pci_dev *dev)
{ {
......
...@@ -4465,6 +4465,19 @@ static int pci_quirk_mf_endpoint_acs(struct pci_dev *dev, u16 acs_flags) ...@@ -4465,6 +4465,19 @@ static int pci_quirk_mf_endpoint_acs(struct pci_dev *dev, u16 acs_flags)
return acs_flags ? 0 : 1; return acs_flags ? 0 : 1;
} }
static int pci_quirk_brcm_acs(struct pci_dev *dev, u16 acs_flags)
{
/*
* iProc PAXB Root Ports don't advertise an ACS capability, but
* they do not allow peer-to-peer transactions between Root Ports.
* Allow each Root Port to be in a separate IOMMU group by masking
* SV/RR/CR/UF bits.
*/
acs_flags &= ~(PCI_ACS_SV | PCI_ACS_RR | PCI_ACS_CR | PCI_ACS_UF);
return acs_flags ? 0 : 1;
}
static const struct pci_dev_acs_enabled { static const struct pci_dev_acs_enabled {
u16 vendor; u16 vendor;
u16 device; u16 device;
...@@ -4558,6 +4571,7 @@ static const struct pci_dev_acs_enabled { ...@@ -4558,6 +4571,7 @@ static const struct pci_dev_acs_enabled {
{ PCI_VENDOR_ID_AMPERE, 0xE00A, pci_quirk_xgene_acs }, { PCI_VENDOR_ID_AMPERE, 0xE00A, pci_quirk_xgene_acs },
{ PCI_VENDOR_ID_AMPERE, 0xE00B, pci_quirk_xgene_acs }, { PCI_VENDOR_ID_AMPERE, 0xE00B, pci_quirk_xgene_acs },
{ PCI_VENDOR_ID_AMPERE, 0xE00C, pci_quirk_xgene_acs }, { PCI_VENDOR_ID_AMPERE, 0xE00C, pci_quirk_xgene_acs },
{ PCI_VENDOR_ID_BROADCOM, 0xD714, pci_quirk_brcm_acs },
{ 0 } { 0 }
}; };
......
...@@ -922,6 +922,11 @@ enum { ...@@ -922,6 +922,11 @@ enum {
PCI_SCAN_ALL_PCIE_DEVS = 0x00000040, /* Scan all, not just dev 0 */ PCI_SCAN_ALL_PCIE_DEVS = 0x00000040, /* Scan all, not just dev 0 */
}; };
#define PCI_IRQ_LEGACY (1 << 0) /* Allow legacy interrupts */
#define PCI_IRQ_MSI (1 << 1) /* Allow MSI interrupts */
#define PCI_IRQ_MSIX (1 << 2) /* Allow MSI-X interrupts */
#define PCI_IRQ_AFFINITY (1 << 3) /* Auto-assign affinity */
/* These external functions are only available when PCI support is enabled */ /* These external functions are only available when PCI support is enabled */
#ifdef CONFIG_PCI #ifdef CONFIG_PCI
...@@ -1395,11 +1400,6 @@ resource_size_t pcibios_window_alignment(struct pci_bus *bus, ...@@ -1395,11 +1400,6 @@ resource_size_t pcibios_window_alignment(struct pci_bus *bus,
int pci_set_vga_state(struct pci_dev *pdev, bool decode, int pci_set_vga_state(struct pci_dev *pdev, bool decode,
unsigned int command_bits, u32 flags); unsigned int command_bits, u32 flags);
#define PCI_IRQ_LEGACY (1 << 0) /* Allow legacy interrupts */
#define PCI_IRQ_MSI (1 << 1) /* Allow MSI interrupts */
#define PCI_IRQ_MSIX (1 << 2) /* Allow MSI-X interrupts */
#define PCI_IRQ_AFFINITY (1 << 3) /* Auto-assign affinity */
/* /*
* Virtual interrupts allow for more interrupts to be allocated * Virtual interrupts allow for more interrupts to be allocated
* than the device has interrupts for. These are not programmed * than the device has interrupts for. These are not programmed
...@@ -1504,14 +1504,6 @@ static inline int pci_irq_get_node(struct pci_dev *pdev, int vec) ...@@ -1504,14 +1504,6 @@ static inline int pci_irq_get_node(struct pci_dev *pdev, int vec)
} }
#endif #endif
static inline int
pci_alloc_irq_vectors(struct pci_dev *dev, unsigned int min_vecs,
unsigned int max_vecs, unsigned int flags)
{
return pci_alloc_irq_vectors_affinity(dev, min_vecs, max_vecs, flags,
NULL);
}
/** /**
* pci_irqd_intx_xlate() - Translate PCI INTx value to an IRQ domain hwirq * pci_irqd_intx_xlate() - Translate PCI INTx value to an IRQ domain hwirq
* @d: the INTx IRQ domain * @d: the INTx IRQ domain
...@@ -1759,8 +1751,29 @@ static inline const struct pci_device_id *pci_match_id(const struct pci_device_i ...@@ -1759,8 +1751,29 @@ static inline const struct pci_device_id *pci_match_id(const struct pci_device_i
struct pci_dev *dev) struct pci_dev *dev)
{ return NULL; } { return NULL; }
static inline bool pci_ats_disabled(void) { return true; } static inline bool pci_ats_disabled(void) { return true; }
static inline int pci_irq_vector(struct pci_dev *dev, unsigned int nr)
{
return -EINVAL;
}
static inline int
pci_alloc_irq_vectors_affinity(struct pci_dev *dev, unsigned int min_vecs,
unsigned int max_vecs, unsigned int flags,
struct irq_affinity *aff_desc)
{
return -ENOSPC;
}
#endif /* CONFIG_PCI */ #endif /* CONFIG_PCI */
static inline int
pci_alloc_irq_vectors(struct pci_dev *dev, unsigned int min_vecs,
unsigned int max_vecs, unsigned int flags)
{
return pci_alloc_irq_vectors_affinity(dev, min_vecs, max_vecs, flags,
NULL);
}
#ifdef CONFIG_PCI_ATS #ifdef CONFIG_PCI_ATS
/* Address Translation Service */ /* Address Translation Service */
int pci_enable_ats(struct pci_dev *dev, int ps); int pci_enable_ats(struct pci_dev *dev, int ps);
...@@ -2398,4 +2411,7 @@ void pci_uevent_ers(struct pci_dev *pdev, enum pci_ers_result err_type); ...@@ -2398,4 +2411,7 @@ void pci_uevent_ers(struct pci_dev *pdev, enum pci_ers_result err_type);
#define pci_notice_ratelimited(pdev, fmt, arg...) \ #define pci_notice_ratelimited(pdev, fmt, arg...) \
dev_notice_ratelimited(&(pdev)->dev, fmt, ##arg) dev_notice_ratelimited(&(pdev)->dev, fmt, ##arg)
#define pci_info_ratelimited(pdev, fmt, arg...) \
dev_info_ratelimited(&(pdev)->dev, fmt, ##arg)
#endif /* LINUX_PCI_H */ #endif /* LINUX_PCI_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment