drivers/char/xilinx_hwicap/xilinx_hwicap.c
Source file repositories/reference/linux-study-clean/drivers/char/xilinx_hwicap/xilinx_hwicap.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/char/xilinx_hwicap/xilinx_hwicap.c- Extension
.c- Size
- 20215 bytes
- Lines
- 794
- Domain
- Driver Families
- Bucket
- drivers/char
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/kernel.hlinux/types.hlinux/ioport.hlinux/interrupt.hlinux/fcntl.hlinux/init.hlinux/poll.hlinux/proc_fs.hlinux/mutex.hlinux/sysctl.hlinux/fs.hlinux/cdev.hlinux/of.hlinux/platform_device.hlinux/property.hlinux/slab.hlinux/io.hlinux/uaccess.hxilinx_hwicap.hbuffer_icap.hfifo_icap.h
Detected Declarations
function hwicap_command_desyncfunction hwicap_get_configuration_registerfunction hwicap_initialize_hwicapfunction hwicap_readfunction hwicap_writefunction hwicap_openfunction hwicap_releasefunction hwicap_setupfunction hwicap_drv_probefunction hwicap_drv_removefunction hwicap_module_initfunction hwicap_module_cleanupmodule init hwicap_module_init
Annotated Snippet
static const struct file_operations hwicap_fops = {
.owner = THIS_MODULE,
.write = hwicap_write,
.read = hwicap_read,
.open = hwicap_open,
.release = hwicap_release,
.llseek = noop_llseek,
};
static int hwicap_setup(struct platform_device *pdev, int id,
const struct hwicap_driver_config *config,
const struct config_registers *config_regs)
{
dev_t devt;
struct hwicap_drvdata *drvdata = NULL;
struct device *dev = &pdev->dev;
int retval;
dev_info(dev, "Xilinx icap port driver\n");
mutex_lock(&icap_sem);
if (id < 0) {
for (id = 0; id < HWICAP_DEVICES; id++)
if (!probed_devices[id])
break;
}
if (id < 0 || id >= HWICAP_DEVICES) {
mutex_unlock(&icap_sem);
dev_err(dev, "%s%i too large\n", DRIVER_NAME, id);
return -EINVAL;
}
if (probed_devices[id]) {
mutex_unlock(&icap_sem);
dev_err(dev, "cannot assign to %s%i; it is already in use\n",
DRIVER_NAME, id);
return -EBUSY;
}
probed_devices[id] = 1;
mutex_unlock(&icap_sem);
devt = MKDEV(XHWICAP_MAJOR, XHWICAP_MINOR + id);
drvdata = devm_kzalloc(dev, sizeof(struct hwicap_drvdata), GFP_KERNEL);
if (!drvdata) {
retval = -ENOMEM;
goto failed;
}
dev_set_drvdata(dev, drvdata);
drvdata->base_address = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(drvdata->base_address)) {
retval = PTR_ERR(drvdata->base_address);
goto failed;
}
drvdata->devt = devt;
drvdata->dev = dev;
drvdata->config = config;
drvdata->config_regs = config_regs;
mutex_init(&drvdata->sem);
drvdata->is_open = 0;
cdev_init(&drvdata->cdev, &hwicap_fops);
drvdata->cdev.owner = THIS_MODULE;
retval = cdev_add(&drvdata->cdev, devt, 1);
if (retval) {
dev_err(dev, "cdev_add() failed\n");
goto failed;
}
device_create(&icap_class, dev, devt, NULL, "%s%d", DRIVER_NAME, id);
return 0; /* success */
failed:
mutex_lock(&icap_sem);
probed_devices[id] = 0;
mutex_unlock(&icap_sem);
return retval;
}
static struct hwicap_driver_config buffer_icap_config = {
.get_configuration = buffer_icap_get_configuration,
.set_configuration = buffer_icap_set_configuration,
.get_status = buffer_icap_get_status,
.reset = buffer_icap_reset,
};
Annotation
- Immediate include surface: `linux/module.h`, `linux/kernel.h`, `linux/types.h`, `linux/ioport.h`, `linux/interrupt.h`, `linux/fcntl.h`, `linux/init.h`, `linux/poll.h`.
- Detected declarations: `function hwicap_command_desync`, `function hwicap_get_configuration_register`, `function hwicap_initialize_hwicap`, `function hwicap_read`, `function hwicap_write`, `function hwicap_open`, `function hwicap_release`, `function hwicap_setup`, `function hwicap_drv_probe`, `function hwicap_drv_remove`.
- Atlas domain: Driver Families / drivers/char.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.