drivers/char/ipmi/ipmb_dev_int.c
Source file repositories/reference/linux-study-clean/drivers/char/ipmi/ipmb_dev_int.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/char/ipmi/ipmb_dev_int.c- Extension
.c- Size
- 9359 bytes
- Lines
- 383
- 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.
- 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/acpi.hlinux/errno.hlinux/i2c.hlinux/miscdevice.hlinux/module.hlinux/mutex.hlinux/poll.hlinux/slab.hlinux/spinlock.hlinux/wait.h
Detected Declarations
struct ipmb_msgstruct ipmb_request_elemstruct ipmb_devfunction ipmb_readfunction ipmb_i2c_writefunction ipmb_writefunction ipmb_pollfunction ipmb_handle_requestfunction ipmb_verify_checksum1function is_ipmb_msgfunction ipmb_slave_cbfunction ipmb_probefunction ipmb_remove
Annotated Snippet
static const struct file_operations ipmb_fops = {
.owner = THIS_MODULE,
.read = ipmb_read,
.write = ipmb_write,
.poll = ipmb_poll,
};
/* Called with ipmb_dev->lock held. */
static void ipmb_handle_request(struct ipmb_dev *ipmb_dev)
{
struct ipmb_request_elem *queue_elem;
if (atomic_read(&ipmb_dev->request_queue_len) >=
REQUEST_QUEUE_MAX_LEN)
return;
queue_elem = kmalloc_obj(*queue_elem, GFP_ATOMIC);
if (!queue_elem)
return;
memcpy(&queue_elem->request, &ipmb_dev->request,
sizeof(struct ipmb_msg));
list_add(&queue_elem->list, &ipmb_dev->request_queue);
atomic_inc(&ipmb_dev->request_queue_len);
wake_up_all(&ipmb_dev->wait_queue);
}
static u8 ipmb_verify_checksum1(struct ipmb_dev *ipmb_dev, u8 rs_sa)
{
/* The 8 lsb of the sum is 0 when the checksum is valid */
return (rs_sa + ipmb_dev->request.netfn_rs_lun +
ipmb_dev->request.checksum1);
}
/*
* Verify if message has proper ipmb header with minimum length
* and correct checksum byte.
*/
static bool is_ipmb_msg(struct ipmb_dev *ipmb_dev, u8 rs_sa)
{
if ((ipmb_dev->msg_idx >= IPMB_REQUEST_LEN_MIN) &&
(!ipmb_verify_checksum1(ipmb_dev, rs_sa)))
return true;
return false;
}
/*
* The IPMB protocol only supports I2C Writes so there is no need
* to support I2C_SLAVE_READ* events.
* This i2c callback function only monitors IPMB request messages
* and adds them in a queue, so that they can be handled by
* receive_ipmb_request.
*/
static int ipmb_slave_cb(struct i2c_client *client,
enum i2c_slave_event event, u8 *val)
{
struct ipmb_dev *ipmb_dev = i2c_get_clientdata(client);
u8 *buf = (u8 *)&ipmb_dev->request;
unsigned long flags;
spin_lock_irqsave(&ipmb_dev->lock, flags);
switch (event) {
case I2C_SLAVE_WRITE_REQUESTED:
memset(&ipmb_dev->request, 0, sizeof(ipmb_dev->request));
ipmb_dev->msg_idx = 0;
/*
* At index 0, ipmb_msg stores the length of msg,
* skip it for now.
* The len will be populated once the whole
* buf is populated.
*
* The I2C bus driver's responsibility is to pass the
* data bytes to the backend driver; it does not
* forward the i2c slave address.
* Since the first byte in the IPMB message is the
* address of the responder, it is the responsibility
* of the IPMB driver to format the message properly.
* So this driver prepends the address of the responder
* to the received i2c data before the request message
* is handled in userland.
*/
buf[++ipmb_dev->msg_idx] = GET_8BIT_ADDR(client->addr);
break;
case I2C_SLAVE_WRITE_RECEIVED:
if (ipmb_dev->msg_idx >= sizeof(struct ipmb_msg) - 1)
break;
Annotation
- Immediate include surface: `linux/acpi.h`, `linux/errno.h`, `linux/i2c.h`, `linux/miscdevice.h`, `linux/module.h`, `linux/mutex.h`, `linux/poll.h`, `linux/slab.h`.
- Detected declarations: `struct ipmb_msg`, `struct ipmb_request_elem`, `struct ipmb_dev`, `function ipmb_read`, `function ipmb_i2c_write`, `function ipmb_write`, `function ipmb_poll`, `function ipmb_handle_request`, `function ipmb_verify_checksum1`, `function is_ipmb_msg`.
- 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.
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.