drivers/misc/ibmasm/event.c
Source file repositories/reference/linux-study-clean/drivers/misc/ibmasm/event.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/misc/ibmasm/event.c- Extension
.c- Size
- 4304 bytes
- Lines
- 164
- 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 Copyrightfunction ibmasm_receive_eventfunction event_availablefunction readersfunction ibmasm_cancel_next_eventfunction ibmasm_event_reader_registerfunction ibmasm_event_reader_unregisterfunction ibmasm_event_buffer_initfunction ibmasm_event_buffer_exit
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"
/*
* ASM service processor event handling routines.
*
* Events are signalled to the device drivers through interrupts.
* They have the format of dot commands, with the type field set to
* sp_event.
* The driver does not interpret the events, it simply stores them in a
* circular buffer.
*/
static void wake_up_event_readers(struct service_processor *sp)
{
struct event_reader *reader;
list_for_each_entry(reader, &sp->event_buffer->readers, node)
wake_up_interruptible(&reader->wait);
}
/*
* receive_event
* Called by the interrupt handler when a dot command of type sp_event is
* received.
* Store the event in the circular event buffer, wake up any sleeping
* event readers.
* There is no reader marker in the buffer, therefore readers are
* responsible for keeping up with the writer, or they will lose events.
*/
void ibmasm_receive_event(struct service_processor *sp, void *data, unsigned int data_size)
{
struct event_buffer *buffer = sp->event_buffer;
struct ibmasm_event *event;
unsigned long flags;
data_size = min(data_size, IBMASM_EVENT_MAX_SIZE);
spin_lock_irqsave(&sp->lock, flags);
/* copy the event into the next slot in the circular buffer */
event = &buffer->events[buffer->next_index];
memcpy_fromio(event->data, data, data_size);
event->data_size = data_size;
event->serial_number = buffer->next_serial_number;
/* advance indices in the buffer */
buffer->next_index = (buffer->next_index + 1) % IBMASM_NUM_EVENTS;
buffer->next_serial_number++;
spin_unlock_irqrestore(&sp->lock, flags);
wake_up_event_readers(sp);
}
static inline int event_available(struct event_buffer *b, struct event_reader *r)
{
return (r->next_serial_number < b->next_serial_number);
}
/*
* get_next_event
* Called by event readers (initiated from user space through the file
* system).
* Sleeps until a new event is available.
*/
int ibmasm_get_next_event(struct service_processor *sp, struct event_reader *reader)
{
struct event_buffer *buffer = sp->event_buffer;
struct ibmasm_event *event;
unsigned int index;
unsigned long flags;
reader->cancelled = 0;
if (wait_event_interruptible(reader->wait,
event_available(buffer, reader) || reader->cancelled))
return -ERESTARTSYS;
if (!event_available(buffer, reader))
Annotation
- Immediate include surface: `linux/sched.h`, `linux/slab.h`, `ibmasm.h`, `lowlevel.h`.
- Detected declarations: `function Copyright`, `function ibmasm_receive_event`, `function event_available`, `function readers`, `function ibmasm_cancel_next_event`, `function ibmasm_event_reader_register`, `function ibmasm_event_reader_unregister`, `function ibmasm_event_buffer_init`, `function ibmasm_event_buffer_exit`.
- 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.