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.

Dependency Surface

Detected Declarations

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

Implementation Notes