drivers/fpga/dfl-afu-main.c

Source file repositories/reference/linux-study-clean/drivers/fpga/dfl-afu-main.c

File Facts

System
Linux kernel
Corpus path
drivers/fpga/dfl-afu-main.c
Extension
.c
Size
23877 bytes
Lines
987
Domain
Driver Families
Bucket
drivers/fpga
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.

Dependency Surface

Detected Declarations

Annotated Snippet

static const struct file_operations afu_fops = {
	.owner = THIS_MODULE,
	.open = afu_open,
	.release = afu_release,
	.unlocked_ioctl = afu_ioctl,
	.mmap = afu_mmap,
};

static int afu_dev_init(struct platform_device *pdev)
{
	struct dfl_feature_dev_data *fdata = to_dfl_feature_dev_data(&pdev->dev);
	struct dfl_afu *afu;

	afu = devm_kzalloc(&pdev->dev, sizeof(*afu), GFP_KERNEL);
	if (!afu)
		return -ENOMEM;

	mutex_lock(&fdata->lock);
	dfl_fpga_fdata_set_private(fdata, afu);
	afu_mmio_region_init(fdata);
	afu_dma_region_init(fdata);
	mutex_unlock(&fdata->lock);

	return 0;
}

static int afu_dev_destroy(struct platform_device *pdev)
{
	struct dfl_feature_dev_data *fdata = to_dfl_feature_dev_data(&pdev->dev);

	mutex_lock(&fdata->lock);
	afu_mmio_region_destroy(fdata);
	afu_dma_region_destroy(fdata);
	dfl_fpga_fdata_set_private(fdata, NULL);
	mutex_unlock(&fdata->lock);

	return 0;
}

static int port_enable_set(struct dfl_feature_dev_data *fdata, bool enable)
{
	int ret;

	mutex_lock(&fdata->lock);
	if (enable)
		ret = __afu_port_enable(fdata);
	else
		ret = __afu_port_disable(fdata);
	mutex_unlock(&fdata->lock);

	return ret;
}

static struct dfl_fpga_port_ops afu_port_ops = {
	.name = DFL_FPGA_FEATURE_DEV_PORT,
	.owner = THIS_MODULE,
	.get_id = port_get_id,
	.enable_set = port_enable_set,
};

static int afu_probe(struct platform_device *pdev)
{
	int ret;

	dev_dbg(&pdev->dev, "%s\n", __func__);

	ret = afu_dev_init(pdev);
	if (ret)
		goto exit;

	ret = dfl_fpga_dev_feature_init(pdev, port_feature_drvs);
	if (ret)
		goto dev_destroy;

	ret = dfl_fpga_dev_ops_register(pdev, &afu_fops, THIS_MODULE);
	if (ret) {
		dfl_fpga_dev_feature_uinit(pdev);
		goto dev_destroy;
	}

	return 0;

dev_destroy:
	afu_dev_destroy(pdev);
exit:
	return ret;
}

static void afu_remove(struct platform_device *pdev)
{

Annotation

Implementation Notes