mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-08-18 19:18:57 +00:00

- DEBUGFS - Remove unneeded debugfs_file_{get,put}() instances - Remove last remnants of debugfs_real_fops() - Allow storing non-const void * in struct debugfs_inode_info::aux - SYSFS - Switch back to attribute_group::bin_attrs (treewide) - Switch back to bin_attribute::read()/write() (treewide) - Constify internal references to 'struct bin_attribute' - Support cache-ids for device-tree systems - Add arch hook arch_compact_of_hwid() - Use arch_compact_of_hwid() to compact MPIDR values on arm64 - Rust - Device - Introduce CoreInternal device context (for bus internal methods) - Provide generic drvdata accessors for bus devices - Provide Driver::unbind() callbacks - Use the infrastructure above for auxiliary, PCI and platform - Implement Device::as_bound() - Rename Device::as_ref() to Device::from_raw() (treewide) - Implement fwnode and device property abstractions - Implement example usage in the Rust platform sample driver - Devres - Remove the inner reference count (Arc) and use pin-init instead - Replace Devres::new_foreign_owned() with devres::register() - Require T to be Send in Devres<T> - Initialize the data kept inside a Devres last - Provide an accessor for the Devres associated Device - Device ID - Add support for ACPI device IDs and driver match tables - Split up generic device ID infrastructure - Use generic device ID infrastructure in net::phy - DMA - Implement the dma::Device trait - Add DMA mask accessors to dma::Device - Implement dma::Device for PCI and platform devices - Use DMA masks from the DMA sample module - I/O - Implement abstraction for resource regions (struct resource) - Implement resource-based ioremap() abstractions - Provide platform device accessors for I/O (remap) requests - Misc - Support fallible PinInit types in Revocable - Implement Wrapper<T> for Opaque<T> - Merge pin-init blanket dependencies (for Devres) - Misc - Fix OF node leak in auxiliary_device_create() - Use util macros in device property iterators - Improve kobject sample code - Add device_link_test() for testing device link flags - Fix typo in Documentation/ABI/testing/sysfs-kernel-address_bits - Hint to prefer container_of_const() over container_of() -----BEGIN PGP SIGNATURE----- iHQEABYKAB0WIQS2q/xV6QjXAdC7k+1FlHeO1qrKLgUCaIjkhwAKCRBFlHeO1qrK LpXuAP9RWwfD9ZGgQZ9OsMk/0pZ2mDclaK97jcmI9TAeSxeZMgD1FHnOMTY7oSIi iG7Muq0yLD+A5gk9HUnMUnFNrngWCg== =jgRj -----END PGP SIGNATURE----- Merge tag 'driver-core-6.17-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core Pull driver core updates from Danilo Krummrich: "debugfs: - Remove unneeded debugfs_file_{get,put}() instances - Remove last remnants of debugfs_real_fops() - Allow storing non-const void * in struct debugfs_inode_info::aux sysfs: - Switch back to attribute_group::bin_attrs (treewide) - Switch back to bin_attribute::read()/write() (treewide) - Constify internal references to 'struct bin_attribute' Support cache-ids for device-tree systems: - Add arch hook arch_compact_of_hwid() - Use arch_compact_of_hwid() to compact MPIDR values on arm64 Rust: - Device: - Introduce CoreInternal device context (for bus internal methods) - Provide generic drvdata accessors for bus devices - Provide Driver::unbind() callbacks - Use the infrastructure above for auxiliary, PCI and platform - Implement Device::as_bound() - Rename Device::as_ref() to Device::from_raw() (treewide) - Implement fwnode and device property abstractions - Implement example usage in the Rust platform sample driver - Devres: - Remove the inner reference count (Arc) and use pin-init instead - Replace Devres::new_foreign_owned() with devres::register() - Require T to be Send in Devres<T> - Initialize the data kept inside a Devres last - Provide an accessor for the Devres associated Device - Device ID: - Add support for ACPI device IDs and driver match tables - Split up generic device ID infrastructure - Use generic device ID infrastructure in net::phy - DMA: - Implement the dma::Device trait - Add DMA mask accessors to dma::Device - Implement dma::Device for PCI and platform devices - Use DMA masks from the DMA sample module - I/O: - Implement abstraction for resource regions (struct resource) - Implement resource-based ioremap() abstractions - Provide platform device accessors for I/O (remap) requests - Misc: - Support fallible PinInit types in Revocable - Implement Wrapper<T> for Opaque<T> - Merge pin-init blanket dependencies (for Devres) Misc: - Fix OF node leak in auxiliary_device_create() - Use util macros in device property iterators - Improve kobject sample code - Add device_link_test() for testing device link flags - Fix typo in Documentation/ABI/testing/sysfs-kernel-address_bits - Hint to prefer container_of_const() over container_of()" * tag 'driver-core-6.17-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core: (84 commits) rust: io: fix broken intra-doc links to `platform::Device` rust: io: fix broken intra-doc link to missing `flags` module rust: io: mem: enable IoRequest doc-tests rust: platform: add resource accessors rust: io: mem: add a generic iomem abstraction rust: io: add resource abstraction rust: samples: dma: set DMA mask rust: platform: implement the `dma::Device` trait rust: pci: implement the `dma::Device` trait rust: dma: add DMA addressing capabilities rust: dma: implement `dma::Device` trait rust: net::phy Change module_phy_driver macro to use module_device_table macro rust: net::phy represent DeviceId as transparent wrapper over mdio_device_id rust: device_id: split out index support into a separate trait device: rust: rename Device::as_ref() to Device::from_raw() arm64: cacheinfo: Provide helper to compress MPIDR value into u32 cacheinfo: Add arch hook to compress CPU h/w id into 32 bits for cache-id cacheinfo: Set cache 'id' based on DT data container_of: Document container_of() is not to be used in new code driver core: auxiliary bus: fix OF node leak ...
187 lines
4.6 KiB
C
187 lines
4.6 KiB
C
// SPDX-License-Identifier: GPL-2.0+
|
|
// Copyright 2017 IBM Corp.
|
|
#include <linux/sysfs.h>
|
|
#include "ocxl_internal.h"
|
|
|
|
static inline struct ocxl_afu *to_afu(struct device *device)
|
|
{
|
|
struct ocxl_file_info *info = container_of(device, struct ocxl_file_info, dev);
|
|
|
|
return info->afu;
|
|
}
|
|
|
|
static ssize_t global_mmio_size_show(struct device *device,
|
|
struct device_attribute *attr,
|
|
char *buf)
|
|
{
|
|
struct ocxl_afu *afu = to_afu(device);
|
|
|
|
return sysfs_emit(buf, "%d\n",
|
|
afu->config.global_mmio_size);
|
|
}
|
|
|
|
static ssize_t pp_mmio_size_show(struct device *device,
|
|
struct device_attribute *attr,
|
|
char *buf)
|
|
{
|
|
struct ocxl_afu *afu = to_afu(device);
|
|
|
|
return sysfs_emit(buf, "%d\n",
|
|
afu->config.pp_mmio_stride);
|
|
}
|
|
|
|
static ssize_t afu_version_show(struct device *device,
|
|
struct device_attribute *attr,
|
|
char *buf)
|
|
{
|
|
struct ocxl_afu *afu = to_afu(device);
|
|
|
|
return sysfs_emit(buf, "%hhu:%hhu\n",
|
|
afu->config.version_major,
|
|
afu->config.version_minor);
|
|
}
|
|
|
|
static ssize_t contexts_show(struct device *device,
|
|
struct device_attribute *attr,
|
|
char *buf)
|
|
{
|
|
struct ocxl_afu *afu = to_afu(device);
|
|
|
|
return sysfs_emit(buf, "%d/%d\n",
|
|
afu->pasid_count, afu->pasid_max);
|
|
}
|
|
|
|
static ssize_t reload_on_reset_show(struct device *device,
|
|
struct device_attribute *attr,
|
|
char *buf)
|
|
{
|
|
struct ocxl_afu *afu = to_afu(device);
|
|
struct ocxl_fn *fn = afu->fn;
|
|
struct pci_dev *pci_dev = to_pci_dev(fn->dev.parent);
|
|
int val;
|
|
|
|
if (ocxl_config_get_reset_reload(pci_dev, &val))
|
|
return sysfs_emit(buf, "unavailable\n");
|
|
|
|
return sysfs_emit(buf, "%d\n", val);
|
|
}
|
|
|
|
static ssize_t reload_on_reset_store(struct device *device,
|
|
struct device_attribute *attr,
|
|
const char *buf, size_t count)
|
|
{
|
|
struct ocxl_afu *afu = to_afu(device);
|
|
struct ocxl_fn *fn = afu->fn;
|
|
struct pci_dev *pci_dev = to_pci_dev(fn->dev.parent);
|
|
int rc, val;
|
|
|
|
rc = kstrtoint(buf, 0, &val);
|
|
if (rc || (val != 0 && val != 1))
|
|
return -EINVAL;
|
|
|
|
if (ocxl_config_set_reset_reload(pci_dev, val))
|
|
return -ENODEV;
|
|
|
|
return count;
|
|
}
|
|
|
|
static struct device_attribute afu_attrs[] = {
|
|
__ATTR_RO(global_mmio_size),
|
|
__ATTR_RO(pp_mmio_size),
|
|
__ATTR_RO(afu_version),
|
|
__ATTR_RO(contexts),
|
|
__ATTR_RW(reload_on_reset),
|
|
};
|
|
|
|
static ssize_t global_mmio_read(struct file *filp, struct kobject *kobj,
|
|
const struct bin_attribute *bin_attr, char *buf,
|
|
loff_t off, size_t count)
|
|
{
|
|
struct ocxl_afu *afu = to_afu(kobj_to_dev(kobj));
|
|
|
|
if (count == 0 || off < 0 ||
|
|
off >= afu->config.global_mmio_size)
|
|
return 0;
|
|
memcpy_fromio(buf, afu->global_mmio_ptr + off, count);
|
|
return count;
|
|
}
|
|
|
|
static vm_fault_t global_mmio_fault(struct vm_fault *vmf)
|
|
{
|
|
struct vm_area_struct *vma = vmf->vma;
|
|
struct ocxl_afu *afu = vma->vm_private_data;
|
|
unsigned long offset;
|
|
|
|
if (vmf->pgoff >= (afu->config.global_mmio_size >> PAGE_SHIFT))
|
|
return VM_FAULT_SIGBUS;
|
|
|
|
offset = vmf->pgoff;
|
|
offset += (afu->global_mmio_start >> PAGE_SHIFT);
|
|
return vmf_insert_pfn(vma, vmf->address, offset);
|
|
}
|
|
|
|
static const struct vm_operations_struct global_mmio_vmops = {
|
|
.fault = global_mmio_fault,
|
|
};
|
|
|
|
static int global_mmio_mmap(struct file *filp, struct kobject *kobj,
|
|
const struct bin_attribute *bin_attr,
|
|
struct vm_area_struct *vma)
|
|
{
|
|
struct ocxl_afu *afu = to_afu(kobj_to_dev(kobj));
|
|
|
|
if ((vma_pages(vma) + vma->vm_pgoff) >
|
|
(afu->config.global_mmio_size >> PAGE_SHIFT))
|
|
return -EINVAL;
|
|
|
|
vm_flags_set(vma, VM_IO | VM_PFNMAP);
|
|
vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
|
|
vma->vm_ops = &global_mmio_vmops;
|
|
vma->vm_private_data = afu;
|
|
return 0;
|
|
}
|
|
|
|
int ocxl_sysfs_register_afu(struct ocxl_file_info *info)
|
|
{
|
|
int i, rc;
|
|
|
|
for (i = 0; i < ARRAY_SIZE(afu_attrs); i++) {
|
|
rc = device_create_file(&info->dev, &afu_attrs[i]);
|
|
if (rc)
|
|
goto err;
|
|
}
|
|
|
|
sysfs_attr_init(&info->attr_global_mmio.attr);
|
|
info->attr_global_mmio.attr.name = "global_mmio_area";
|
|
info->attr_global_mmio.attr.mode = 0600;
|
|
info->attr_global_mmio.size = info->afu->config.global_mmio_size;
|
|
info->attr_global_mmio.read = global_mmio_read;
|
|
info->attr_global_mmio.mmap = global_mmio_mmap;
|
|
rc = device_create_bin_file(&info->dev, &info->attr_global_mmio);
|
|
if (rc) {
|
|
dev_err(&info->dev, "Unable to create global mmio attr for afu: %d\n", rc);
|
|
goto err;
|
|
}
|
|
|
|
return 0;
|
|
|
|
err:
|
|
for (i--; i >= 0; i--)
|
|
device_remove_file(&info->dev, &afu_attrs[i]);
|
|
|
|
return rc;
|
|
}
|
|
|
|
void ocxl_sysfs_unregister_afu(struct ocxl_file_info *info)
|
|
{
|
|
int i;
|
|
|
|
/*
|
|
* device_remove_bin_file is safe to call if the file is not added as
|
|
* the files are removed by name, and early exit if not found
|
|
*/
|
|
for (i = 0; i < ARRAY_SIZE(afu_attrs); i++)
|
|
device_remove_file(&info->dev, &afu_attrs[i]);
|
|
device_remove_bin_file(&info->dev, &info->attr_global_mmio);
|
|
}
|