drivers/misc/bcm-vk/bcm_vk_dev.c
Source file repositories/reference/linux-study-clean/drivers/misc/bcm-vk/bcm_vk_dev.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/misc/bcm-vk/bcm_vk_dev.c- Extension
.c- Size
- 45198 bytes
- Lines
- 1653
- Domain
- Driver Families
- Bucket
- drivers/misc
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/dma-mapping.hlinux/firmware.hlinux/fs.hlinux/idr.hlinux/interrupt.hlinux/panic_notifier.hlinux/kref.hlinux/module.hlinux/mutex.hlinux/pci.hlinux/pci_regs.huapi/linux/misc/bcm_vk.hbcm_vk.h
Detected Declarations
struct load_image_entryenum soc_idxenum img_idxfunction bcm_vk_notf_irqhandlerfunction bcm_vk_intf_ver_chkfunction bcm_vk_log_notffunction bcm_vk_dump_peer_logfunction bcm_vk_handle_notffunction bcm_vk_waitfunction bcm_vk_get_card_infofunction bcm_vk_get_proc_mon_infofunction bcm_vk_sync_card_infofunction bcm_vk_blk_drv_accessfunction list_for_each_entryfunction bcm_vk_buf_notifyfunction bcm_vk_load_image_by_typefunction bcm_vk_next_boot_imagefunction get_soc_idxfunction bcm_vk_auto_load_all_imagesfunction bcm_vk_trigger_autoloadfunction bcm_vk_wq_handlerfunction bcm_vk_load_imagefunction bcm_vk_reset_successfulfunction bcm_to_v_reset_doorbellfunction bcm_vk_trigger_resetfunction bcm_vk_resetfunction bcm_vk_mmapfunction bcm_vk_ioctlfunction bcm_vk_on_panicfunction bcm_vk_probefunction bcm_vk_release_datafunction bcm_vk_removefunction bcm_vk_shutdown
Annotated Snippet
static const struct file_operations bcm_vk_fops = {
.owner = THIS_MODULE,
.open = bcm_vk_open,
.read = bcm_vk_read,
.write = bcm_vk_write,
.poll = bcm_vk_poll,
.release = bcm_vk_release,
.mmap = bcm_vk_mmap,
.unlocked_ioctl = bcm_vk_ioctl,
};
static int bcm_vk_on_panic(struct notifier_block *nb,
unsigned long e, void *p)
{
struct bcm_vk *vk = container_of(nb, struct bcm_vk, panic_nb);
bcm_to_v_reset_doorbell(vk, VK_BAR0_RESET_DB_HARD);
return 0;
}
static int bcm_vk_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
{
int err;
int i;
int id;
int irq;
char name[20];
struct bcm_vk *vk;
struct device *dev = &pdev->dev;
struct miscdevice *misc_device;
u32 boot_status;
/* allocate vk structure which is tied to kref for freeing */
vk = kzalloc_obj(*vk);
if (!vk)
return -ENOMEM;
kref_init(&vk->kref);
if (nr_ib_sgl_blk > BCM_VK_IB_SGL_BLK_MAX) {
dev_warn(dev, "Inband SGL blk %d limited to max %d\n",
nr_ib_sgl_blk, BCM_VK_IB_SGL_BLK_MAX);
nr_ib_sgl_blk = BCM_VK_IB_SGL_BLK_MAX;
}
vk->ib_sgl_size = nr_ib_sgl_blk * VK_MSGQ_BLK_SIZE;
mutex_init(&vk->mutex);
err = pci_enable_device(pdev);
if (err) {
dev_err(dev, "Cannot enable PCI device\n");
goto err_free_exit;
}
vk->pdev = pci_dev_get(pdev);
err = pci_request_regions(pdev, DRV_MODULE_NAME);
if (err) {
dev_err(dev, "Cannot obtain PCI resources\n");
goto err_disable_pdev;
}
/* make sure DMA is good */
err = dma_set_mask_and_coherent(&pdev->dev,
DMA_BIT_MASK(BCM_VK_DMA_BITS));
if (err) {
dev_err(dev, "failed to set DMA mask\n");
goto err_disable_pdev;
}
/* The tdma is a scratch area for some DMA testings. */
if (nr_scratch_pages) {
vk->tdma_vaddr = dma_alloc_coherent
(dev,
nr_scratch_pages * PAGE_SIZE,
&vk->tdma_addr, GFP_KERNEL);
if (!vk->tdma_vaddr) {
err = -ENOMEM;
goto err_disable_pdev;
}
}
pci_set_master(pdev);
pci_set_drvdata(pdev, vk);
irq = pci_alloc_irq_vectors(pdev,
VK_MSIX_IRQ_MIN_REQ,
VK_MSIX_IRQ_MAX,
PCI_IRQ_MSI | PCI_IRQ_MSIX);
if (irq < VK_MSIX_IRQ_MIN_REQ) {
dev_err(dev, "failed to get min %d MSIX interrupts, irq(%d)\n",
Annotation
- Immediate include surface: `linux/delay.h`, `linux/dma-mapping.h`, `linux/firmware.h`, `linux/fs.h`, `linux/idr.h`, `linux/interrupt.h`, `linux/panic_notifier.h`, `linux/kref.h`.
- Detected declarations: `struct load_image_entry`, `enum soc_idx`, `enum img_idx`, `function bcm_vk_notf_irqhandler`, `function bcm_vk_intf_ver_chk`, `function bcm_vk_log_notf`, `function bcm_vk_dump_peer_log`, `function bcm_vk_handle_notf`, `function bcm_vk_wait`, `function bcm_vk_get_card_info`.
- Atlas domain: Driver Families / drivers/misc.
- 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.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.