drivers/misc/ocxl/sysfs.c

Source file repositories/reference/linux-study-clean/drivers/misc/ocxl/sysfs.c

File Facts

System
Linux kernel
Corpus path
drivers/misc/ocxl/sysfs.c
Extension
.c
Size
4707 bytes
Lines
187
Domain
Driver Families
Bucket
drivers/misc
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

// 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),

Annotation

Implementation Notes