drivers/bluetooth/virtio_bt.c
Source file repositories/reference/linux-study-clean/drivers/bluetooth/virtio_bt.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/bluetooth/virtio_bt.c- Extension
.c- Size
- 9462 bytes
- Lines
- 451
- Domain
- Driver Families
- Bucket
- drivers/bluetooth
- 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.
- 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.
- 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/virtio.hlinux/virtio_config.hlinux/skbuff.huapi/linux/virtio_ids.huapi/linux/virtio_bt.hnet/bluetooth/bluetooth.hnet/bluetooth/hci_core.h
Detected Declarations
struct virtio_bluetoothfunction virtbt_add_inbuffunction virtbt_openfunction virtbt_open_vdevfunction virtbt_closefunction virtbt_close_vdevfunction virtbt_flushfunction virtbt_send_framefunction virtbt_setup_zephyrfunction virtbt_set_bdaddr_zephyrfunction virtbt_setup_intelfunction virtbt_set_bdaddr_intelfunction virtbt_setup_realtekfunction virtbt_shutdown_genericfunction virtbt_rx_handlefunction virtbt_rx_workfunction virtbt_tx_donefunction virtbt_rx_donefunction virtbt_probefunction virtbt_remove
Annotated Snippet
struct virtio_bluetooth {
struct virtio_device *vdev;
struct virtqueue *vqs[VIRTBT_NUM_VQS];
struct work_struct rx;
struct hci_dev *hdev;
};
static int virtbt_add_inbuf(struct virtio_bluetooth *vbt)
{
struct virtqueue *vq = vbt->vqs[VIRTBT_VQ_RX];
struct scatterlist sg[1];
struct sk_buff *skb;
int err;
skb = alloc_skb(VIRTBT_RX_BUF_SIZE, GFP_KERNEL);
if (!skb)
return -ENOMEM;
sg_init_one(sg, skb->data, VIRTBT_RX_BUF_SIZE);
err = virtqueue_add_inbuf(vq, sg, 1, skb, GFP_KERNEL);
if (err < 0) {
kfree_skb(skb);
return err;
}
return 0;
}
static int virtbt_open(struct hci_dev *hdev)
{
return 0;
}
static int virtbt_open_vdev(struct virtio_bluetooth *vbt)
{
if (virtbt_add_inbuf(vbt) < 0)
return -EIO;
virtqueue_kick(vbt->vqs[VIRTBT_VQ_RX]);
return 0;
}
static int virtbt_close(struct hci_dev *hdev)
{
return 0;
}
static int virtbt_close_vdev(struct virtio_bluetooth *vbt)
{
int i;
cancel_work_sync(&vbt->rx);
for (i = 0; i < ARRAY_SIZE(vbt->vqs); i++) {
struct virtqueue *vq = vbt->vqs[i];
struct sk_buff *skb;
while ((skb = virtqueue_detach_unused_buf(vq)))
kfree_skb(skb);
cond_resched();
}
return 0;
}
static int virtbt_flush(struct hci_dev *hdev)
{
return 0;
}
static int virtbt_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
{
struct virtio_bluetooth *vbt = hci_get_drvdata(hdev);
struct scatterlist sg[1];
int err;
memcpy(skb_push(skb, 1), &hci_skb_pkt_type(skb), 1);
sg_init_one(sg, skb->data, skb->len);
err = virtqueue_add_outbuf(vbt->vqs[VIRTBT_VQ_TX], sg, 1, skb,
GFP_KERNEL);
if (err) {
kfree_skb(skb);
return err;
}
virtqueue_kick(vbt->vqs[VIRTBT_VQ_TX]);
return 0;
}
Annotation
- Immediate include surface: `linux/module.h`, `linux/virtio.h`, `linux/virtio_config.h`, `linux/skbuff.h`, `uapi/linux/virtio_ids.h`, `uapi/linux/virtio_bt.h`, `net/bluetooth/bluetooth.h`, `net/bluetooth/hci_core.h`.
- Detected declarations: `struct virtio_bluetooth`, `function virtbt_add_inbuf`, `function virtbt_open`, `function virtbt_open_vdev`, `function virtbt_close`, `function virtbt_close_vdev`, `function virtbt_flush`, `function virtbt_send_frame`, `function virtbt_setup_zephyr`, `function virtbt_set_bdaddr_zephyr`.
- Atlas domain: Driver Families / drivers/bluetooth.
- Implementation status: source 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.