drivers/mailbox/mailbox-test.c
Source file repositories/reference/linux-study-clean/drivers/mailbox/mailbox-test.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/mailbox/mailbox-test.c- Extension
.c- Size
- 11393 bytes
- Lines
- 464
- Domain
- Driver Families
- Bucket
- drivers/mailbox
- 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/debugfs.hlinux/err.hlinux/fs.hlinux/io.hlinux/kernel.hlinux/mailbox_client.hlinux/module.hlinux/mutex.hlinux/of.hlinux/platform_device.hlinux/poll.hlinux/slab.hlinux/spinlock.hlinux/uaccess.hlinux/sched/signal.h
Detected Declarations
struct mbox_test_devicefunction mbox_test_signal_writefunction mbox_test_message_fasyncfunction mbox_test_message_writefunction mbox_test_message_data_readyfunction mbox_test_message_readfunction mbox_test_message_pollfunction mbox_test_add_debugfsfunction mbox_test_receive_messagefunction mbox_test_prepare_messagefunction mbox_test_message_sentfunction mbox_test_request_channelfunction mbox_test_probefunction mbox_test_remove
Annotated Snippet
static const struct file_operations mbox_test_signal_ops = {
.write = mbox_test_signal_write,
.open = simple_open,
.llseek = generic_file_llseek,
};
static int mbox_test_message_fasync(int fd, struct file *filp, int on)
{
struct mbox_test_device *tdev = filp->private_data;
return fasync_helper(fd, filp, on, &tdev->async_queue);
}
static ssize_t mbox_test_message_write(struct file *filp,
const char __user *userbuf,
size_t count, loff_t *ppos)
{
struct mbox_test_device *tdev = filp->private_data;
char *message;
void *data;
int ret;
if (!tdev->tx_channel) {
dev_err(tdev->dev, "Channel cannot do Tx\n");
return -EINVAL;
}
if (count > MBOX_MAX_MSG_LEN) {
dev_err(tdev->dev,
"Message length %zd greater than max allowed %d\n",
count, MBOX_MAX_MSG_LEN);
return -EINVAL;
}
message = kzalloc(MBOX_MAX_MSG_LEN, GFP_KERNEL);
if (!message)
return -ENOMEM;
mutex_lock(&tdev->mutex);
tdev->message = message;
ret = copy_from_user(tdev->message, userbuf, count);
if (ret) {
ret = -EFAULT;
goto out;
}
/*
* A separate signal is only of use if there is
* MMIO to subsequently pass the message through
*/
if (tdev->tx_mmio && tdev->signal) {
print_hex_dump_bytes("Client: Sending: Signal: ", DUMP_PREFIX_ADDRESS,
tdev->signal, MBOX_MAX_SIG_LEN);
data = tdev->signal;
} else
data = tdev->message;
print_hex_dump_bytes("Client: Sending: Message: ", DUMP_PREFIX_ADDRESS,
tdev->message, MBOX_MAX_MSG_LEN);
ret = mbox_send_message(tdev->tx_channel, data);
if (ret < 0)
dev_err(tdev->dev, "Failed to send message via mailbox\n");
out:
kfree(tdev->signal);
kfree(tdev->message);
tdev->signal = NULL;
mutex_unlock(&tdev->mutex);
return ret < 0 ? ret : count;
}
static bool mbox_test_message_data_ready(struct mbox_test_device *tdev)
{
bool data_ready;
unsigned long flags;
spin_lock_irqsave(&tdev->lock, flags);
data_ready = tdev->data_ready;
spin_unlock_irqrestore(&tdev->lock, flags);
return data_ready;
}
static ssize_t mbox_test_message_read(struct file *filp, char __user *userbuf,
size_t count, loff_t *ppos)
Annotation
- Immediate include surface: `linux/debugfs.h`, `linux/err.h`, `linux/fs.h`, `linux/io.h`, `linux/kernel.h`, `linux/mailbox_client.h`, `linux/module.h`, `linux/mutex.h`.
- Detected declarations: `struct mbox_test_device`, `function mbox_test_signal_write`, `function mbox_test_message_fasync`, `function mbox_test_message_write`, `function mbox_test_message_data_ready`, `function mbox_test_message_read`, `function mbox_test_message_poll`, `function mbox_test_add_debugfs`, `function mbox_test_receive_message`, `function mbox_test_prepare_message`.
- Atlas domain: Driver Families / drivers/mailbox.
- 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.