Path: blob/master/arch/powerpc/platforms/pseries/io_event_irq.c
26481 views
// SPDX-License-Identifier: GPL-2.0-or-later1/*2* Copyright 2010 2011 Mark Nelson and Tseng-Hui (Frank) Lin, IBM Corporation3*/45#include <linux/errno.h>6#include <linux/slab.h>7#include <linux/export.h>8#include <linux/irq.h>9#include <linux/interrupt.h>10#include <linux/of.h>11#include <linux/list.h>12#include <linux/notifier.h>1314#include <asm/machdep.h>15#include <asm/rtas.h>16#include <asm/irq.h>17#include <asm/io_event_irq.h>1819#include "pseries.h"2021/*22* IO event interrupt is a mechanism provided by RTAS to return23* information about hardware error and non-error events. Device24* drivers can register their event handlers to receive events.25* Device drivers are expected to use atomic_notifier_chain_register()26* and atomic_notifier_chain_unregister() to register and unregister27* their event handlers. Since multiple IO event types and scopes28* share an IO event interrupt, the event handlers are called one29* by one until the IO event is claimed by one of the handlers.30* The event handlers are expected to return NOTIFY_OK if the31* event is handled by the event handler or NOTIFY_DONE if the32* event does not belong to the handler.33*34* Usage:35*36* Notifier function:37* #include <asm/io_event_irq.h>38* int event_handler(struct notifier_block *nb, unsigned long val, void *data) {39* p = (struct pseries_io_event_sect_data *) data;40* if (! is_my_event(p->scope, p->event_type)) return NOTIFY_DONE;41* :42* :43* return NOTIFY_OK;44* }45* struct notifier_block event_nb = {46* .notifier_call = event_handler,47* }48*49* Registration:50* atomic_notifier_chain_register(&pseries_ioei_notifier_list, &event_nb);51*52* Unregistration:53* atomic_notifier_chain_unregister(&pseries_ioei_notifier_list, &event_nb);54*/5556ATOMIC_NOTIFIER_HEAD(pseries_ioei_notifier_list);57EXPORT_SYMBOL_GPL(pseries_ioei_notifier_list);5859static int ioei_check_exception_token;6061static char ioei_rtas_buf[RTAS_DATA_BUF_SIZE] __cacheline_aligned;6263/**64* Find the data portion of an IO Event section from event log.65* @elog: RTAS error/event log.66*67* Return:68* pointer to a valid IO event section data. NULL if not found.69*/70static struct pseries_io_event * ioei_find_event(struct rtas_error_log *elog)71{72struct pseries_errorlog *sect;7374/* We should only ever get called for io-event interrupts, but if75* we do get called for another type then something went wrong so76* make some noise about it.77* RTAS_TYPE_IO only exists in extended event log version 6 or later.78* No need to check event log version.79*/80if (unlikely(rtas_error_type(elog) != RTAS_TYPE_IO)) {81printk_once(KERN_WARNING"io_event_irq: Unexpected event type %d",82rtas_error_type(elog));83return NULL;84}8586sect = get_pseries_errorlog(elog, PSERIES_ELOG_SECT_ID_IO_EVENT);87if (unlikely(!sect)) {88printk_once(KERN_WARNING "io_event_irq: RTAS extended event "89"log does not contain an IO Event section. "90"Could be a bug in system firmware!\n");91return NULL;92}93return (struct pseries_io_event *) §->data;94}9596/*97* PAPR:98* - check-exception returns the first found error or event and clear that99* error or event so it is reported once.100* - Each interrupt returns one event. If a plateform chooses to report101* multiple events through a single interrupt, it must ensure that the102* interrupt remains asserted until check-exception has been used to103* process all out-standing events for that interrupt.104*105* Implementation notes:106* - Events must be processed in the order they are returned. Hence,107* sequential in nature.108* - The owner of an event is determined by combinations of scope,109* event type, and sub-type. There is no easy way to pre-sort clients110* by scope or event type alone. For example, Torrent ISR route change111* event is reported with scope 0x00 (Not Applicable) rather than112* 0x3B (Torrent-hub). It is better to let the clients to identify113* who owns the event.114*/115116static irqreturn_t ioei_interrupt(int irq, void *dev_id)117{118struct pseries_io_event *event;119int rtas_rc;120121for (;;) {122rtas_rc = rtas_call(ioei_check_exception_token, 6, 1, NULL,123RTAS_VECTOR_EXTERNAL_INTERRUPT,124virq_to_hw(irq),125RTAS_IO_EVENTS, 1 /* Time Critical */,126__pa(ioei_rtas_buf),127RTAS_DATA_BUF_SIZE);128if (rtas_rc != 0)129break;130131event = ioei_find_event((struct rtas_error_log *)ioei_rtas_buf);132if (!event)133continue;134135atomic_notifier_call_chain(&pseries_ioei_notifier_list,1360, event);137}138return IRQ_HANDLED;139}140141static int __init ioei_init(void)142{143struct device_node *np;144145ioei_check_exception_token = rtas_function_token(RTAS_FN_CHECK_EXCEPTION);146if (ioei_check_exception_token == RTAS_UNKNOWN_SERVICE)147return -ENODEV;148149np = of_find_node_by_path("/event-sources/ibm,io-events");150if (np) {151request_event_sources_irqs(np, ioei_interrupt, "IO_EVENT");152pr_info("IBM I/O event interrupts enabled\n");153of_node_put(np);154} else {155return -ENODEV;156}157return 0;158}159machine_subsys_initcall(pseries, ioei_init);160161162163