Lines Matching +full:resource +full:- +full:files

1 // SPDX-License-Identifier: GPL-2.0
3 * (C) Copyright 2002-2004 Greg Kroah-Hartman <greg@kroah.com>
4 * (C) Copyright 2002-2004 IBM Corp.
6 * (C) Copyright 2003 Hewlett-Packard
48 return sysfs_emit(buf, format_string, pdev->field); \
68 * MSI-X, show the legacy INTx IRQ. in irq_show()
70 if (pdev->msi_enabled) in irq_show()
74 return sysfs_emit(buf, "%u\n", pdev->irq); in irq_show()
83 return sysfs_emit(buf, "%u\n", pdev->broken_parity_status); in broken_parity_status_show()
94 return -EINVAL; in broken_parity_status_store()
96 pdev->broken_parity_status = !!val; in broken_parity_status_store()
113 mask = cpumask_of_pcibus(to_pci_dev(dev)->bus); in pci_dev_show_local_cpu()
158 return sysfs_emit(buf, "%s\n", pci_power_name(pdev->current_state)); in power_state_show()
172 if (pci_dev->subordinate) in resource_show()
178 struct resource *res = &pci_dev->resource[i]; in resource_show()
183 (unsigned long long)res->flags); in resource_show()
187 static DEVICE_ATTR_RO(resource);
218 return -EINVAL; in current_link_speed_show()
235 return -EINVAL; in current_link_width_show()
251 return -EINVAL; in secondary_bus_number_show()
267 return -EINVAL; in subordinate_bus_number_show()
279 return sysfs_emit(buf, "%u\n", pci_ari_enabled(pci_dev->bus)); in ari_enabled_show()
289 pci_dev->vendor, pci_dev->device, in modalias_show()
290 pci_dev->subsystem_vendor, pci_dev->subsystem_device, in modalias_show()
291 (u8)(pci_dev->class >> 16), (u8)(pci_dev->class >> 8), in modalias_show()
292 (u8)(pci_dev->class)); in modalias_show()
305 return -EPERM; in enable_store()
308 return -EINVAL; in enable_store()
311 if (dev->driver) in enable_store()
312 result = -EBUSY; in enable_store()
318 result = -EIO; in enable_store()
330 return sysfs_emit(buf, "%u\n", atomic_read(&pdev->enable_cnt)); in enable_show()
343 return -EPERM; in numa_node_store()
346 return -EINVAL; in numa_node_store()
349 return -EINVAL; in numa_node_store()
352 return -EINVAL; in numa_node_store()
358 dev->numa_node = node; in numa_node_store()
365 return sysfs_emit(buf, "%d\n", dev->numa_node); in numa_node_show()
375 return sysfs_emit(buf, "%d\n", fls64(pdev->dma_mask)); in dma_mask_bits_show()
383 return sysfs_emit(buf, "%d\n", fls64(dev->coherent_dma_mask)); in consistent_dma_mask_bits_show()
391 struct pci_bus *subordinate = pdev->subordinate; in msi_bus_show()
394 !(subordinate->bus_flags & PCI_BUS_FLAGS_NO_MSI) in msi_bus_show()
395 : !pdev->no_msi); in msi_bus_show()
402 struct pci_bus *subordinate = pdev->subordinate; in msi_bus_store()
406 return -EPERM; in msi_bus_store()
409 return -EINVAL; in msi_bus_store()
413 * requests MSI or MSI-X. They don't affect any drivers that have in msi_bus_store()
414 * already requested MSI or MSI-X. in msi_bus_store()
417 pdev->no_msi = !val; in msi_bus_store()
418 pci_info(pdev, "MSI/MSI-X %s for future drivers\n", in msi_bus_store()
424 subordinate->bus_flags &= ~PCI_BUS_FLAGS_NO_MSI; in msi_bus_store()
426 subordinate->bus_flags |= PCI_BUS_FLAGS_NO_MSI; in msi_bus_store()
428 dev_info(&subordinate->dev, "MSI/MSI-X %s for future drivers of devices on this bus\n", in msi_bus_store()
440 return -EINVAL; in rescan_store()
474 return -EINVAL; in dev_rescan_store()
478 pci_rescan_bus(pdev->bus); in dev_rescan_store()
492 return -EINVAL; in remove_store()
509 return -EINVAL; in bus_rescan_store()
513 if (!pci_is_root_bus(bus) && list_empty(&bus->devices)) in bus_rescan_store()
514 pci_rescan_bus_bridge_resize(bus->self); in bus_rescan_store()
533 return -EINVAL; in d3cold_allowed_store()
535 pdev->d3cold_allowed = !!val; in d3cold_allowed_store()
547 return sysfs_emit(buf, "%u\n", pdev->d3cold_allowed); in d3cold_allowed_show()
573 ret = driver_set_override(dev, &pdev->driver_override, buf, count); in driver_override_store()
587 len = sysfs_emit(buf, "%s\n", pdev->driver_override); in driver_override_show()
665 !!(pdev->resource[PCI_ROM_RESOURCE].flags & in boot_vga_show()
681 size = dev->cfg_size; in pci_read_config()
682 else if (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) in pci_read_config()
688 size -= off; in pci_read_config()
699 data[off - init_off] = val; in pci_read_config()
701 size--; in pci_read_config()
707 data[off - init_off] = val & 0xff; in pci_read_config()
708 data[off - init_off + 1] = (val >> 8) & 0xff; in pci_read_config()
710 size -= 2; in pci_read_config()
716 data[off - init_off] = val & 0xff; in pci_read_config()
717 data[off - init_off + 1] = (val >> 8) & 0xff; in pci_read_config()
718 data[off - init_off + 2] = (val >> 16) & 0xff; in pci_read_config()
719 data[off - init_off + 3] = (val >> 24) & 0xff; in pci_read_config()
721 size -= 4; in pci_read_config()
728 data[off - init_off] = val & 0xff; in pci_read_config()
729 data[off - init_off + 1] = (val >> 8) & 0xff; in pci_read_config()
731 size -= 2; in pci_read_config()
737 data[off - init_off] = val; in pci_read_config()
759 if (resource_is_exclusive(&dev->driver_exclusive_resource, off, in pci_write_config()
761 pci_warn_once(dev, "%s: Unexpected write to kernel-exclusive config offset %llx", in pci_write_config()
762 current->comm, off); in pci_write_config()
766 if (off > dev->cfg_size) in pci_write_config()
768 if (off + count > dev->cfg_size) { in pci_write_config()
769 size = dev->cfg_size - off; in pci_write_config()
776 pci_user_write_config_byte(dev, off, data[off - init_off]); in pci_write_config()
778 size--; in pci_write_config()
782 u16 val = data[off - init_off]; in pci_write_config()
783 val |= (u16) data[off - init_off + 1] << 8; in pci_write_config()
786 size -= 2; in pci_write_config()
790 u32 val = data[off - init_off]; in pci_write_config()
791 val |= (u32) data[off - init_off + 1] << 8; in pci_write_config()
792 val |= (u32) data[off - init_off + 2] << 16; in pci_write_config()
793 val |= (u32) data[off - init_off + 3] << 24; in pci_write_config()
796 size -= 4; in pci_write_config()
800 u16 val = data[off - init_off]; in pci_write_config()
801 val |= (u16) data[off - init_off + 1] << 8; in pci_write_config()
804 size -= 2; in pci_write_config()
808 pci_user_write_config_byte(dev, off, data[off - init_off]); in pci_write_config()
826 a->size = PCI_CFG_SPACE_SIZE; in pci_dev_config_attr_is_visible()
827 if (pdev->cfg_size > PCI_CFG_SPACE_SIZE) in pci_dev_config_attr_is_visible()
828 a->size = PCI_CFG_SPACE_EXP_SIZE; in pci_dev_config_attr_is_visible()
830 return a->attr.mode; in pci_dev_config_attr_is_visible()
848 return fixed_size_llseek(filep, offset, whence, attr->size); in pci_llseek_resource()
853 * pci_read_legacy_io - read byte(s) from legacy I/O port space
872 return -EINVAL; in pci_read_legacy_io()
878 * pci_write_legacy_io - write byte(s) to legacy I/O port space
897 return -EINVAL; in pci_write_legacy_io()
903 * pci_mmap_legacy_mem - map legacy PCI memory into user memory space
923 * pci_mmap_legacy_io - map legacy PCI IO into user memory space
931 * memory space. Returns -ENOSYS if the operation isn't supported
943 * pci_adjust_legacy_attr - adjustment of legacy file attributes
944 * @b: bus to create files under
955 * pci_create_legacy_files - create legacy I/O port and memory files
956 * @b: bus to create files under
959 * a per-bus basis. This routine creates the files and ties them into
960 * their associated read, write and mmap files from pci-sysfs.c
963 * as it is ok to set up the PCI bus without these files.
972 b->legacy_io = kcalloc(2, sizeof(struct bin_attribute), in pci_create_legacy_files()
974 if (!b->legacy_io) in pci_create_legacy_files()
977 sysfs_bin_attr_init(b->legacy_io); in pci_create_legacy_files()
978 b->legacy_io->attr.name = "legacy_io"; in pci_create_legacy_files()
979 b->legacy_io->size = 0xffff; in pci_create_legacy_files()
980 b->legacy_io->attr.mode = 0600; in pci_create_legacy_files()
981 b->legacy_io->read = pci_read_legacy_io; in pci_create_legacy_files()
982 b->legacy_io->write = pci_write_legacy_io; in pci_create_legacy_files()
984 b->legacy_io->llseek = pci_llseek_resource; in pci_create_legacy_files()
985 b->legacy_io->mmap = pci_mmap_legacy_io; in pci_create_legacy_files()
986 b->legacy_io->f_mapping = iomem_get_mapping; in pci_create_legacy_files()
988 error = device_create_bin_file(&b->dev, b->legacy_io); in pci_create_legacy_files()
993 b->legacy_mem = b->legacy_io + 1; in pci_create_legacy_files()
994 sysfs_bin_attr_init(b->legacy_mem); in pci_create_legacy_files()
995 b->legacy_mem->attr.name = "legacy_mem"; in pci_create_legacy_files()
996 b->legacy_mem->size = 1024*1024; in pci_create_legacy_files()
997 b->legacy_mem->attr.mode = 0600; in pci_create_legacy_files()
998 b->legacy_mem->mmap = pci_mmap_legacy_mem; in pci_create_legacy_files()
1000 b->legacy_mem->llseek = pci_llseek_resource; in pci_create_legacy_files()
1001 b->legacy_mem->f_mapping = iomem_get_mapping; in pci_create_legacy_files()
1003 error = device_create_bin_file(&b->dev, b->legacy_mem); in pci_create_legacy_files()
1010 device_remove_bin_file(&b->dev, b->legacy_io); in pci_create_legacy_files()
1012 kfree(b->legacy_io); in pci_create_legacy_files()
1013 b->legacy_io = NULL; in pci_create_legacy_files()
1015 dev_warn(&b->dev, "could not create legacy I/O port and ISA memory resources in sysfs\n"); in pci_create_legacy_files()
1020 if (b->legacy_io) { in pci_remove_legacy_files()
1021 device_remove_bin_file(&b->dev, b->legacy_io); in pci_remove_legacy_files()
1022 device_remove_bin_file(&b->dev, b->legacy_mem); in pci_remove_legacy_files()
1023 kfree(b->legacy_io); /* both are allocated here */ in pci_remove_legacy_files()
1030 * pci_mmap_resource - map a PCI resource into user memory space
1036 * Use the regular PCI mapping routines to map a PCI resource into userspace.
1042 int bar = (unsigned long)attr->private; in pci_mmap_resource()
1044 struct resource *res = &pdev->resource[bar]; in pci_mmap_resource()
1051 if (res->flags & IORESOURCE_MEM && iomem_is_exclusive(res->start)) in pci_mmap_resource()
1052 return -EINVAL; in pci_mmap_resource()
1055 return -EINVAL; in pci_mmap_resource()
1057 mmap_type = res->flags & IORESOURCE_MEM ? pci_mmap_mem : pci_mmap_io; in pci_mmap_resource()
1082 int bar = (unsigned long)attr->private; in pci_resource_io()
1090 if (port + count - 1 > pci_resource_end(pdev, bar)) in pci_resource_io()
1091 return -EINVAL; in pci_resource_io()
1113 return -EINVAL; in pci_resource_io()
1115 return -ENXIO; in pci_resource_io()
1140 * pci_remove_resource_files - cleanup resource files
1143 * If we created resource files for @pdev, remove them from sysfs and
1153 res_attr = pdev->res_attr[i]; in pci_remove_resource_files()
1155 sysfs_remove_bin_file(&pdev->dev.kobj, res_attr); in pci_remove_resource_files()
1159 res_attr = pdev->res_attr_wc[i]; in pci_remove_resource_files()
1161 sysfs_remove_bin_file(&pdev->dev.kobj, res_attr); in pci_remove_resource_files()
1177 return -ENOMEM; in pci_create_attr()
1183 sprintf(res_attr_name, "resource%d_wc", num); in pci_create_attr()
1184 res_attr->mmap = pci_mmap_resource_wc; in pci_create_attr()
1186 sprintf(res_attr_name, "resource%d", num); in pci_create_attr()
1188 res_attr->read = pci_read_resource_io; in pci_create_attr()
1189 res_attr->write = pci_write_resource_io; in pci_create_attr()
1191 res_attr->mmap = pci_mmap_resource_uc; in pci_create_attr()
1193 res_attr->mmap = pci_mmap_resource_uc; in pci_create_attr()
1196 if (res_attr->mmap) { in pci_create_attr()
1197 res_attr->f_mapping = iomem_get_mapping; in pci_create_attr()
1199 * generic_file_llseek() consults f_mapping->host to determine in pci_create_attr()
1203 res_attr->llseek = pci_llseek_resource; in pci_create_attr()
1205 res_attr->attr.name = res_attr_name; in pci_create_attr()
1206 res_attr->attr.mode = 0600; in pci_create_attr()
1207 res_attr->size = pci_resource_len(pdev, num); in pci_create_attr()
1208 res_attr->private = (void *)(unsigned long)num; in pci_create_attr()
1209 retval = sysfs_create_bin_file(&pdev->dev.kobj, res_attr); in pci_create_attr()
1216 pdev->res_attr_wc[num] = res_attr; in pci_create_attr()
1218 pdev->res_attr[num] = res_attr; in pci_create_attr()
1224 * pci_create_resource_files - create resource files in sysfs for @dev
1227 * Walk the resources in @pdev creating files for each resource available.
1234 /* Expose the PCI resources from this device as files */ in pci_create_resource_files()
1244 pdev->resource[i].flags & IORESOURCE_PREFETCH) in pci_create_resource_files()
1259 * pci_write_rom - used to enable access to the PCI ROM display
1276 pdev->rom_attr_enabled = 0; in pci_write_rom()
1278 pdev->rom_attr_enabled = 1; in pci_write_rom()
1284 * pci_read_rom - read a PCI ROM
1303 if (!pdev->rom_attr_enabled) in pci_read_rom()
1304 return -EINVAL; in pci_read_rom()
1308 return -EIO; in pci_read_rom()
1314 count = size - off; in pci_read_rom()
1340 a->size = rom_size; in pci_dev_rom_attr_is_visible()
1342 return a->attr.mode; in pci_dev_rom_attr_is_visible()
1358 return -EINVAL; in reset_store()
1361 return -EINVAL; in reset_store()
1386 return a->mode; in pci_dev_reset_attr_is_visible()
1418 return -EINVAL; in __resource_resize_store()
1421 if (dev->driver) { in __resource_resize_store()
1422 ret = -EBUSY; in __resource_resize_store()
1428 if ((pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA) { in __resource_resize_store()
1451 pci_assign_unassigned_bus_resources(pdev->bus); in __resource_resize_store()
1454 pci_warn(pdev, "Failed to recreate resource files after BAR resizing\n"); in __resource_resize_store()
1466 static ssize_t resource##n##_resize_show(struct device *dev, \
1472 static ssize_t resource##n##_resize_store(struct device *dev, \
1478 static DEVICE_ATTR_RW(resource##n##_resize)
1502 return pci_rebar_get_current_size(pdev, n) < 0 ? 0 : a->mode; in resource_resize_is_visible()
1513 return -EACCES; in pci_create_sysfs_dev_files()
1519 * pci_remove_sysfs_dev_files - cleanup PCI specific sysfs files
1566 return a->mode; in pci_dev_attrs_are_visible()
1583 if (pdev->is_virtfn) in pci_dev_hp_attrs_are_visible()
1586 return a->mode; in pci_dev_hp_attrs_are_visible()
1596 return a->mode; in pci_bridge_attrs_are_visible()
1608 return a->mode; in pcie_dev_attrs_are_visible()