drivers/misc/ibmasm/command.c
Source file repositories/reference/linux-study-clean/drivers/misc/ibmasm/command.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/misc/ibmasm/command.c- Extension
.c- Size
- 4162 bytes
- Lines
- 174
- Domain
- Driver Families
- Bucket
- drivers/misc
- 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.
- 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/sched.hlinux/slab.hibmasm.hlowlevel.h
Detected Declarations
function ibmasm_free_commandfunction enqueue_commandfunction do_exec_commandfunction ibmasm_exec_commandfunction exec_next_commandfunction ibmasm_wait_for_responsefunction ibmasm_receive_command_response
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* IBM ASM Service Processor Device Driver
*
* Copyright (C) IBM Corporation, 2004
*
* Author: Max Asböck <amax@us.ibm.com>
*/
#include <linux/sched.h>
#include <linux/slab.h>
#include "ibmasm.h"
#include "lowlevel.h"
static void exec_next_command(struct service_processor *sp);
static atomic_t command_count = ATOMIC_INIT(0);
struct command *ibmasm_new_command(struct service_processor *sp, size_t buffer_size)
{
struct command *cmd;
if (buffer_size > IBMASM_CMD_MAX_BUFFER_SIZE)
return NULL;
cmd = kzalloc_obj(struct command);
if (cmd == NULL)
return NULL;
cmd->buffer = kzalloc(buffer_size, GFP_KERNEL);
if (cmd->buffer == NULL) {
kfree(cmd);
return NULL;
}
cmd->buffer_size = buffer_size;
kref_init(&cmd->kref);
cmd->lock = &sp->lock;
cmd->status = IBMASM_CMD_PENDING;
init_waitqueue_head(&cmd->wait);
INIT_LIST_HEAD(&cmd->queue_node);
atomic_inc(&command_count);
dbg("command count: %d\n", atomic_read(&command_count));
return cmd;
}
void ibmasm_free_command(struct kref *kref)
{
struct command *cmd = to_command(kref);
list_del(&cmd->queue_node);
atomic_dec(&command_count);
dbg("command count: %d\n", atomic_read(&command_count));
kfree(cmd->buffer);
kfree(cmd);
}
static void enqueue_command(struct service_processor *sp, struct command *cmd)
{
list_add_tail(&cmd->queue_node, &sp->command_queue);
}
static struct command *dequeue_command(struct service_processor *sp)
{
struct command *cmd;
struct list_head *next;
if (list_empty(&sp->command_queue))
return NULL;
next = sp->command_queue.next;
list_del_init(next);
cmd = list_entry(next, struct command, queue_node);
return cmd;
}
static inline void do_exec_command(struct service_processor *sp)
{
char tsbuf[32];
dbg("%s:%d at %s\n", __func__, __LINE__, get_timestamp(tsbuf));
if (ibmasm_send_i2o_message(sp)) {
sp->current_command->status = IBMASM_CMD_FAILED;
Annotation
- Immediate include surface: `linux/sched.h`, `linux/slab.h`, `ibmasm.h`, `lowlevel.h`.
- Detected declarations: `function ibmasm_free_command`, `function enqueue_command`, `function do_exec_command`, `function ibmasm_exec_command`, `function exec_next_command`, `function ibmasm_wait_for_response`, `function ibmasm_receive_command_response`.
- Atlas domain: Driver Families / drivers/misc.
- Implementation status: source implementation candidate.
- 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.