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
44 return sysfs_emit(buf, format_string, pdev->field); \
64 * MSI-X, show the legacy INTx IRQ. in irq_show()
66 if (pdev->msi_enabled) in irq_show()
70 return sysfs_emit(buf, "%u\n", pdev->irq); in irq_show()
79 return sysfs_emit(buf, "%u\n", pdev->broken_parity_status); in broken_parity_status_show()
90 return -EINVAL; in broken_parity_status_store()
92 pdev->broken_parity_status = !!val; in broken_parity_status_store()
109 mask = cpumask_of_pcibus(to_pci_dev(dev)->bus); in pci_dev_show_local_cpu()
154 return sysfs_emit(buf, "%s\n", pci_power_name(pdev->current_state)); in power_state_show()
168 if (pci_dev->subordinate) in resource_show()
174 struct resource *res = &pci_dev->resource[i]; in resource_show()
179 (unsigned long long)res->flags); in resource_show()
183 static DEVICE_ATTR_RO(resource);
214 return -EINVAL; in current_link_speed_show()
231 return -EINVAL; in current_link_width_show()
247 return -EINVAL; in secondary_bus_number_show()
263 return -EINVAL; in subordinate_bus_number_show()
275 return sysfs_emit(buf, "%u\n", pci_ari_enabled(pci_dev->bus)); in ari_enabled_show()
285 pci_dev->vendor, pci_dev->device, in modalias_show()
286 pci_dev->subsystem_vendor, pci_dev->subsystem_device, in modalias_show()
287 (u8)(pci_dev->class >> 16), (u8)(pci_dev->class >> 8), in modalias_show()
288 (u8)(pci_dev->class)); in modalias_show()
301 return -EPERM; in enable_store()
304 return -EINVAL; in enable_store()
307 if (dev->driver) in enable_store()
308 result = -EBUSY; in enable_store()
314 result = -EIO; in enable_store()
326 return sysfs_emit(buf, "%u\n", atomic_read(&pdev->enable_cnt)); in enable_show()
339 return -EPERM; in numa_node_store()
342 return -EINVAL; in numa_node_store()
345 return -EINVAL; in numa_node_store()
348 return -EINVAL; in numa_node_store()
354 dev->numa_node = node; in numa_node_store()
361 return sysfs_emit(buf, "%d\n", dev->numa_node); in numa_node_show()
371 return sysfs_emit(buf, "%d\n", fls64(pdev->dma_mask)); in dma_mask_bits_show()
379 return sysfs_emit(buf, "%d\n", fls64(dev->coherent_dma_mask)); in consistent_dma_mask_bits_show()
387 struct pci_bus *subordinate = pdev->subordinate; in msi_bus_show()
390 !(subordinate->bus_flags & PCI_BUS_FLAGS_NO_MSI) in msi_bus_show()
391 : !pdev->no_msi); in msi_bus_show()
398 struct pci_bus *subordinate = pdev->subordinate; in msi_bus_store()
402 return -EPERM; in msi_bus_store()
405 return -EINVAL; in msi_bus_store()
409 * requests MSI or MSI-X. They don't affect any drivers that have in msi_bus_store()
410 * already requested MSI or MSI-X. in msi_bus_store()
413 pdev->no_msi = !val; in msi_bus_store()
414 pci_info(pdev, "MSI/MSI-X %s for future drivers\n", in msi_bus_store()
420 subordinate->bus_flags &= ~PCI_BUS_FLAGS_NO_MSI; in msi_bus_store()
422 subordinate->bus_flags |= PCI_BUS_FLAGS_NO_MSI; in msi_bus_store()
424 dev_info(&subordinate->dev, "MSI/MSI-X %s for future drivers of devices on this bus\n", in msi_bus_store()
436 return -EINVAL; in rescan_store()
470 return -EINVAL; in dev_rescan_store()
474 pci_rescan_bus(pdev->bus); in dev_rescan_store()
488 return -EINVAL; in remove_store()
505 return -EINVAL; in bus_rescan_store()
509 if (!pci_is_root_bus(bus) && list_empty(&bus->devices)) in bus_rescan_store()
510 pci_rescan_bus_bridge_resize(bus->self); in bus_rescan_store()
525 struct pci_bus *bus = pdev->subordinate; in reset_subordinate_store()
529 return -EPERM; in reset_subordinate_store()
532 return -EINVAL; in reset_subordinate_store()
554 return -EINVAL; in d3cold_allowed_store()
556 pdev->d3cold_allowed = !!val; in d3cold_allowed_store()
568 return sysfs_emit(buf, "%u\n", pdev->d3cold_allowed); in d3cold_allowed_show()
594 ret = driver_set_override(dev, &pdev->driver_override, buf, count); in driver_override_store()
608 len = sysfs_emit(buf, "%s\n", pdev->driver_override); in driver_override_show()
687 !!(pdev->resource[PCI_ROM_RESOURCE].flags & in boot_vga_show()
703 size = dev->cfg_size; in pci_read_config()
704 else if (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) in pci_read_config()
710 size -= off; in pci_read_config()
721 data[off - init_off] = val; in pci_read_config()
723 size--; in pci_read_config()
729 data[off - init_off] = val & 0xff; in pci_read_config()
730 data[off - init_off + 1] = (val >> 8) & 0xff; in pci_read_config()
732 size -= 2; in pci_read_config()
738 data[off - init_off] = val & 0xff; in pci_read_config()
739 data[off - init_off + 1] = (val >> 8) & 0xff; in pci_read_config()
740 data[off - init_off + 2] = (val >> 16) & 0xff; in pci_read_config()
741 data[off - init_off + 3] = (val >> 24) & 0xff; in pci_read_config()
743 size -= 4; in pci_read_config()
750 data[off - init_off] = val & 0xff; in pci_read_config()
751 data[off - init_off + 1] = (val >> 8) & 0xff; in pci_read_config()
753 size -= 2; in pci_read_config()
759 data[off - init_off] = val; in pci_read_config()
781 if (resource_is_exclusive(&dev->driver_exclusive_resource, off, in pci_write_config()
783 pci_warn_once(dev, "%s: Unexpected write to kernel-exclusive config offset %llx", in pci_write_config()
784 current->comm, off); in pci_write_config()
788 if (off > dev->cfg_size) in pci_write_config()
790 if (off + count > dev->cfg_size) { in pci_write_config()
791 size = dev->cfg_size - off; in pci_write_config()
798 pci_user_write_config_byte(dev, off, data[off - init_off]); in pci_write_config()
800 size--; in pci_write_config()
804 u16 val = data[off - init_off]; in pci_write_config()
805 val |= (u16) data[off - init_off + 1] << 8; in pci_write_config()
808 size -= 2; in pci_write_config()
812 u32 val = data[off - init_off]; in pci_write_config()
813 val |= (u32) data[off - init_off + 1] << 8; in pci_write_config()
814 val |= (u32) data[off - init_off + 2] << 16; in pci_write_config()
815 val |= (u32) data[off - init_off + 3] << 24; in pci_write_config()
818 size -= 4; in pci_write_config()
822 u16 val = data[off - init_off]; in pci_write_config()
823 val |= (u16) data[off - init_off + 1] << 8; in pci_write_config()
826 size -= 2; in pci_write_config()
830 pci_user_write_config_byte(dev, off, data[off - init_off]); in pci_write_config()
848 a->size = PCI_CFG_SPACE_SIZE; in pci_dev_config_attr_is_visible()
849 if (pdev->cfg_size > PCI_CFG_SPACE_SIZE) in pci_dev_config_attr_is_visible()
850 a->size = PCI_CFG_SPACE_EXP_SIZE; in pci_dev_config_attr_is_visible()
852 return a->attr.mode; in pci_dev_config_attr_is_visible()
862 * pci_read_legacy_io - read byte(s) from legacy I/O port space
881 return -EINVAL; in pci_read_legacy_io()
887 * pci_write_legacy_io - write byte(s) to legacy I/O port space
906 return -EINVAL; in pci_write_legacy_io()
912 * pci_mmap_legacy_mem - map legacy PCI memory into user memory space
932 * pci_mmap_legacy_io - map legacy PCI IO into user memory space
940 * memory space. Returns -ENOSYS if the operation isn't supported
952 * pci_adjust_legacy_attr - adjustment of legacy file attributes
953 * @b: bus to create files under
964 * pci_create_legacy_files - create legacy I/O port and memory files
965 * @b: bus to create files under
968 * a per-bus basis. This routine creates the files and ties them into
969 * their associated read, write and mmap files from pci-sysfs.c
972 * as it is ok to set up the PCI bus without these files.
981 b->legacy_io = kcalloc(2, sizeof(struct bin_attribute), in pci_create_legacy_files()
983 if (!b->legacy_io) in pci_create_legacy_files()
986 sysfs_bin_attr_init(b->legacy_io); in pci_create_legacy_files()
987 b->legacy_io->attr.name = "legacy_io"; in pci_create_legacy_files()
988 b->legacy_io->size = 0xffff; in pci_create_legacy_files()
989 b->legacy_io->attr.mode = 0600; in pci_create_legacy_files()
990 b->legacy_io->read = pci_read_legacy_io; in pci_create_legacy_files()
991 b->legacy_io->write = pci_write_legacy_io; in pci_create_legacy_files()
992 b->legacy_io->mmap = pci_mmap_legacy_io; in pci_create_legacy_files()
993 b->legacy_io->f_mapping = iomem_get_mapping; in pci_create_legacy_files()
995 error = device_create_bin_file(&b->dev, b->legacy_io); in pci_create_legacy_files()
1000 b->legacy_mem = b->legacy_io + 1; in pci_create_legacy_files()
1001 sysfs_bin_attr_init(b->legacy_mem); in pci_create_legacy_files()
1002 b->legacy_mem->attr.name = "legacy_mem"; in pci_create_legacy_files()
1003 b->legacy_mem->size = 1024*1024; in pci_create_legacy_files()
1004 b->legacy_mem->attr.mode = 0600; in pci_create_legacy_files()
1005 b->legacy_mem->mmap = pci_mmap_legacy_mem; in pci_create_legacy_files()
1006 b->legacy_mem->f_mapping = iomem_get_mapping; in pci_create_legacy_files()
1008 error = device_create_bin_file(&b->dev, b->legacy_mem); in pci_create_legacy_files()
1015 device_remove_bin_file(&b->dev, b->legacy_io); in pci_create_legacy_files()
1017 kfree(b->legacy_io); in pci_create_legacy_files()
1018 b->legacy_io = NULL; in pci_create_legacy_files()
1020 dev_warn(&b->dev, "could not create legacy I/O port and ISA memory resources in sysfs\n"); in pci_create_legacy_files()
1025 if (b->legacy_io) { in pci_remove_legacy_files()
1026 device_remove_bin_file(&b->dev, b->legacy_io); in pci_remove_legacy_files()
1027 device_remove_bin_file(&b->dev, b->legacy_mem); in pci_remove_legacy_files()
1028 kfree(b->legacy_io); /* both are allocated here */ in pci_remove_legacy_files()
1044 start = vma->vm_pgoff; in pci_mmap_fits()
1045 size = ((pci_resource_len(pdev, resno) - 1) >> PAGE_SHIFT) + 1; in pci_mmap_fits()
1047 pci_resource_to_user(pdev, resno, &pdev->resource[resno], in pci_mmap_fits()
1058 * pci_mmap_resource - map a PCI resource into user memory space
1064 * Use the regular PCI mapping routines to map a PCI resource into userspace.
1070 int bar = (unsigned long)attr->private; in pci_mmap_resource()
1072 struct resource *res = &pdev->resource[bar]; in pci_mmap_resource()
1079 if (res->flags & IORESOURCE_MEM && iomem_is_exclusive(res->start)) in pci_mmap_resource()
1080 return -EINVAL; in pci_mmap_resource()
1083 return -EINVAL; in pci_mmap_resource()
1085 mmap_type = res->flags & IORESOURCE_MEM ? pci_mmap_mem : pci_mmap_io; in pci_mmap_resource()
1110 int bar = (unsigned long)attr->private; in pci_resource_io()
1118 if (port + count - 1 > pci_resource_end(pdev, bar)) in pci_resource_io()
1119 return -EINVAL; in pci_resource_io()
1141 return -EINVAL; in pci_resource_io()
1143 return -ENXIO; in pci_resource_io()
1168 * pci_remove_resource_files - cleanup resource files
1171 * If we created resource files for @pdev, remove them from sysfs and
1181 res_attr = pdev->res_attr[i]; in pci_remove_resource_files()
1183 sysfs_remove_bin_file(&pdev->dev.kobj, res_attr); in pci_remove_resource_files()
1187 res_attr = pdev->res_attr_wc[i]; in pci_remove_resource_files()
1189 sysfs_remove_bin_file(&pdev->dev.kobj, res_attr); in pci_remove_resource_files()
1205 return -ENOMEM; in pci_create_attr()
1211 sprintf(res_attr_name, "resource%d_wc", num); in pci_create_attr()
1212 res_attr->mmap = pci_mmap_resource_wc; in pci_create_attr()
1214 sprintf(res_attr_name, "resource%d", num); in pci_create_attr()
1216 res_attr->read = pci_read_resource_io; in pci_create_attr()
1217 res_attr->write = pci_write_resource_io; in pci_create_attr()
1219 res_attr->mmap = pci_mmap_resource_uc; in pci_create_attr()
1221 res_attr->mmap = pci_mmap_resource_uc; in pci_create_attr()
1224 if (res_attr->mmap) in pci_create_attr()
1225 res_attr->f_mapping = iomem_get_mapping; in pci_create_attr()
1226 res_attr->attr.name = res_attr_name; in pci_create_attr()
1227 res_attr->attr.mode = 0600; in pci_create_attr()
1228 res_attr->size = pci_resource_len(pdev, num); in pci_create_attr()
1229 res_attr->private = (void *)(unsigned long)num; in pci_create_attr()
1230 retval = sysfs_create_bin_file(&pdev->dev.kobj, res_attr); in pci_create_attr()
1237 pdev->res_attr_wc[num] = res_attr; in pci_create_attr()
1239 pdev->res_attr[num] = res_attr; in pci_create_attr()
1245 * pci_create_resource_files - create resource files in sysfs for @dev
1248 * Walk the resources in @pdev creating files for each resource available.
1255 /* Expose the PCI resources from this device as files */ in pci_create_resource_files()
1265 pdev->resource[i].flags & IORESOURCE_PREFETCH) in pci_create_resource_files()
1280 * pci_write_rom - used to enable access to the PCI ROM display
1297 pdev->rom_attr_enabled = 0; in pci_write_rom()
1299 pdev->rom_attr_enabled = 1; in pci_write_rom()
1305 * pci_read_rom - read a PCI ROM
1324 if (!pdev->rom_attr_enabled) in pci_read_rom()
1325 return -EINVAL; in pci_read_rom()
1329 return -EIO; in pci_read_rom()
1335 count = size - off; in pci_read_rom()
1361 a->size = rom_size; in pci_dev_rom_attr_is_visible()
1363 return a->attr.mode; in pci_dev_rom_attr_is_visible()
1379 return -EINVAL; in reset_store()
1382 return -EINVAL; in reset_store()
1407 return a->mode; in pci_dev_reset_attr_is_visible()
1416 static ssize_t resource##n##_resize_show(struct device *dev, \
1433 static ssize_t resource##n##_resize_store(struct device *dev, \
1443 return -EINVAL; \
1446 if (dev->driver) { \
1447 ret = -EBUSY; \
1453 if ((pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA) { \
1476 pci_assign_unassigned_bus_resources(pdev->bus); \
1479 pci_warn(pdev, "Failed to recreate resource files after BAR resizing\n");\
1489 static DEVICE_ATTR_RW(resource##n##_resize)
1513 return pci_rebar_get_current_size(pdev, n) < 0 ? 0 : a->mode; in resource_resize_is_visible()
1524 return -EACCES; in pci_create_sysfs_dev_files()
1530 * pci_remove_sysfs_dev_files - cleanup PCI specific sysfs files
1577 if ((pdev->class >> 8) != PCI_CLASS_DISPLAY_VGA) in pci_dev_attrs_are_visible()
1580 return a->mode; in pci_dev_attrs_are_visible()
1595 if (pdev->is_virtfn) in pci_dev_hp_attrs_are_visible()
1598 return a->mode; in pci_dev_hp_attrs_are_visible()
1608 return a->mode; in pci_bridge_attrs_are_visible()
1620 return a->mode; in pcie_dev_attrs_are_visible()