drivers/char/ipmi/bt-bmc.c
Source file repositories/reference/linux-study-clean/drivers/char/ipmi/bt-bmc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/char/ipmi/bt-bmc.c- Extension
.c- Size
- 10742 bytes
- Lines
- 493
- 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.
- 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/atomic.hlinux/bt-bmc.hlinux/errno.hlinux/interrupt.hlinux/io.hlinux/miscdevice.hlinux/module.hlinux/of.hlinux/platform_device.hlinux/poll.hlinux/sched.hlinux/timer.h
Detected Declarations
struct bt_bmcfunction bt_inbfunction bt_outbfunction clr_rd_ptrfunction clr_wr_ptrfunction clr_h2b_atnfunction set_b_busyfunction clr_b_busyfunction set_b2h_atnfunction bt_readfunction bt_readnfunction bt_writefunction bt_writenfunction set_sms_atnfunction bt_bmc_openfunction BTfunction bt_bmc_writefunction bt_bmc_ioctlfunction bt_bmc_releasefunction bt_bmc_pollfunction poll_timerfunction bt_bmc_irqfunction bt_bmc_config_irqfunction bt_bmc_probefunction bt_bmc_remove
Annotated Snippet
static const struct file_operations bt_bmc_fops = {
.owner = THIS_MODULE,
.open = bt_bmc_open,
.read = bt_bmc_read,
.write = bt_bmc_write,
.release = bt_bmc_release,
.poll = bt_bmc_poll,
.unlocked_ioctl = bt_bmc_ioctl,
};
static void poll_timer(struct timer_list *t)
{
struct bt_bmc *bt_bmc = timer_container_of(bt_bmc, t, poll_timer);
bt_bmc->poll_timer.expires += msecs_to_jiffies(500);
wake_up(&bt_bmc->queue);
add_timer(&bt_bmc->poll_timer);
}
static irqreturn_t bt_bmc_irq(int irq, void *arg)
{
struct bt_bmc *bt_bmc = arg;
u32 reg;
reg = readl(bt_bmc->base + BT_CR2);
reg &= BT_CR2_IRQ_H2B | BT_CR2_IRQ_HBUSY;
if (!reg)
return IRQ_NONE;
/* ack pending IRQs */
writel(reg, bt_bmc->base + BT_CR2);
wake_up(&bt_bmc->queue);
return IRQ_HANDLED;
}
static int bt_bmc_config_irq(struct bt_bmc *bt_bmc,
struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
int rc;
u32 reg;
bt_bmc->irq = platform_get_irq_optional(pdev, 0);
if (bt_bmc->irq < 0)
return bt_bmc->irq;
rc = devm_request_irq(dev, bt_bmc->irq, bt_bmc_irq, IRQF_SHARED,
DEVICE_NAME, bt_bmc);
if (rc < 0) {
dev_warn(dev, "Unable to request IRQ %d\n", bt_bmc->irq);
bt_bmc->irq = rc;
return rc;
}
/*
* Configure IRQs on the bmc clearing the H2B and HBUSY bits;
* H2B will be asserted when the bmc has data for us; HBUSY
* will be cleared (along with B2H) when we can write the next
* message to the BT buffer
*/
reg = readl(bt_bmc->base + BT_CR1);
reg |= BT_CR1_IRQ_H2B | BT_CR1_IRQ_HBUSY;
writel(reg, bt_bmc->base + BT_CR1);
return 0;
}
static int bt_bmc_probe(struct platform_device *pdev)
{
struct bt_bmc *bt_bmc;
struct device *dev;
int rc;
dev = &pdev->dev;
dev_info(dev, "Found bt bmc device\n");
bt_bmc = devm_kzalloc(dev, sizeof(*bt_bmc), GFP_KERNEL);
if (!bt_bmc)
return -ENOMEM;
dev_set_drvdata(&pdev->dev, bt_bmc);
bt_bmc->base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(bt_bmc->base))
return PTR_ERR(bt_bmc->base);
mutex_init(&bt_bmc->mutex);
init_waitqueue_head(&bt_bmc->queue);
Annotation
- Immediate include surface: `linux/atomic.h`, `linux/bt-bmc.h`, `linux/errno.h`, `linux/interrupt.h`, `linux/io.h`, `linux/miscdevice.h`, `linux/module.h`, `linux/of.h`.
- Detected declarations: `struct bt_bmc`, `function bt_inb`, `function bt_outb`, `function clr_rd_ptr`, `function clr_wr_ptr`, `function clr_h2b_atn`, `function set_b_busy`, `function clr_b_busy`, `function set_b2h_atn`, `function bt_read`.
- 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.
- 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.