drivers/fpga/altera-cvp.c
Source file repositories/reference/linux-study-clean/drivers/fpga/altera-cvp.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/fpga/altera-cvp.c- Extension
.c- Size
- 19025 bytes
- Lines
- 708
- 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.
- 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.
- 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/delay.hlinux/device.hlinux/fpga/fpga-mgr.hlinux/module.hlinux/pci.hlinux/sizes.h
Detected Declarations
struct cvp_privstruct altera_cvp_confstruct cvp_privfunction altera_read_config_bytefunction altera_read_config_dwordfunction altera_write_config_dwordfunction altera_cvp_statefunction altera_cvp_write_data_iomemfunction altera_cvp_write_data_configfunction altera_cvp_dummy_writefunction altera_cvp_wait_statusfunction altera_cvp_chk_errorfunction altera_cvp_v2_clear_statefunction altera_cvp_v2_wait_for_creditfunction altera_cvp_send_blockfunction altera_cvp_teardownfunction altera_cvp_write_initfunction altera_cvp_writefunction hugefunction altera_cvp_write_completefunction chkcfg_showfunction chkcfg_storefunction altera_cvp_probefunction altera_cvp_removefunction altera_cvp_initfunction altera_cvp_exitmodule init altera_cvp_init
Annotated Snippet
static ssize_t chkcfg_show(struct device_driver *dev, char *buf)
{
return snprintf(buf, 3, "%d\n", altera_cvp_chkcfg);
}
static ssize_t chkcfg_store(struct device_driver *drv, const char *buf,
size_t count)
{
int ret;
ret = kstrtobool(buf, &altera_cvp_chkcfg);
if (ret)
return ret;
return count;
}
static DRIVER_ATTR_RW(chkcfg);
static int altera_cvp_probe(struct pci_dev *pdev,
const struct pci_device_id *dev_id);
static void altera_cvp_remove(struct pci_dev *pdev);
static struct pci_device_id altera_cvp_id_tbl[] = {
{ PCI_VDEVICE(ALTERA, PCI_ANY_ID) },
{ }
};
MODULE_DEVICE_TABLE(pci, altera_cvp_id_tbl);
static struct pci_driver altera_cvp_driver = {
.name = DRV_NAME,
.id_table = altera_cvp_id_tbl,
.probe = altera_cvp_probe,
.remove = altera_cvp_remove,
};
static int altera_cvp_probe(struct pci_dev *pdev,
const struct pci_device_id *dev_id)
{
struct altera_cvp_conf *conf;
struct fpga_manager *mgr;
u16 cmd, offset;
u32 regval;
int ret;
/*
* First check if this is the expected FPGA device. PCI config
* space access works without enabling the PCI device, memory
* space access is enabled further down.
*/
offset = pci_find_vsec_capability(pdev, PCI_VENDOR_ID_ALTERA, 0x1172);
if (!offset) {
dev_err(&pdev->dev, "Wrong VSEC ID value\n");
return -ENODEV;
}
pci_read_config_dword(pdev, offset + VSE_CVP_STATUS, ®val);
if (!(regval & VSE_CVP_STATUS_CVP_EN)) {
dev_err(&pdev->dev,
"CVP is disabled for this device: CVP_STATUS Reg 0x%x\n",
regval);
return -ENODEV;
}
conf = devm_kzalloc(&pdev->dev, sizeof(*conf), GFP_KERNEL);
if (!conf)
return -ENOMEM;
conf->vsec_offset = offset;
/*
* Enable memory BAR access. We cannot use pci_enable_device() here
* because it will make the driver unusable with FPGA devices that
* have additional big IOMEM resources (e.g. 4GiB BARs) on 32-bit
* platform. Such BARs will not have an assigned address range and
* pci_enable_device() will fail, complaining about not claimed BAR,
* even if the concerned BAR is not needed for FPGA configuration
* at all. Thus, enable the device via PCI config space command.
*/
pci_read_config_word(pdev, PCI_COMMAND, &cmd);
if (!(cmd & PCI_COMMAND_MEMORY)) {
cmd |= PCI_COMMAND_MEMORY;
pci_write_config_word(pdev, PCI_COMMAND, cmd);
}
ret = pci_request_region(pdev, CVP_BAR, "CVP");
if (ret) {
dev_err(&pdev->dev, "Requesting CVP BAR region failed\n");
goto err_disable;
}
Annotation
- Immediate include surface: `linux/delay.h`, `linux/device.h`, `linux/fpga/fpga-mgr.h`, `linux/module.h`, `linux/pci.h`, `linux/sizes.h`.
- Detected declarations: `struct cvp_priv`, `struct altera_cvp_conf`, `struct cvp_priv`, `function altera_read_config_byte`, `function altera_read_config_dword`, `function altera_write_config_dword`, `function altera_cvp_state`, `function altera_cvp_write_data_iomem`, `function altera_cvp_write_data_config`, `function altera_cvp_dummy_write`.
- Atlas domain: Driver Families / drivers/fpga.
- Implementation status: pattern implementation candidate.
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.