2 * Copyright 2010 2011 Mark Nelson and Tseng-Hui (Frank) Lin, IBM Corporation
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
10 #include <linux/errno.h>
11 #include <linux/slab.h>
12 #include <linux/export.h>
13 #include <linux/irq.h>
14 #include <linux/interrupt.h>
16 #include <linux/list.h>
17 #include <linux/notifier.h>
19 #include <asm/machdep.h>
22 #include <asm/io_event_irq.h>
27 * IO event interrupt is a mechanism provided by RTAS to return
28 * information about hardware error and non-error events. Device
29 * drivers can register their event handlers to receive events.
30 * Device drivers are expected to use atomic_notifier_chain_register()
31 * and atomic_notifier_chain_unregister() to register and unregister
32 * their event handlers. Since multiple IO event types and scopes
33 * share an IO event interrupt, the event handlers are called one
34 * by one until the IO event is claimed by one of the handlers.
35 * The event handlers are expected to return NOTIFY_OK if the
36 * event is handled by the event handler or NOTIFY_DONE if the
37 * event does not belong to the handler.
42 * #include <asm/io_event_irq.h>
43 * int event_handler(struct notifier_block *nb, unsigned long val, void *data) {
44 * p = (struct pseries_io_event_sect_data *) data;
45 * if (! is_my_event(p->scope, p->event_type)) return NOTIFY_DONE;
50 * struct notifier_block event_nb = {
51 * .notifier_call = event_handler,
55 * atomic_notifier_chain_register(&pseries_ioei_notifier_list, &event_nb);
58 * atomic_notifier_chain_unregister(&pseries_ioei_notifier_list, &event_nb);
61 ATOMIC_NOTIFIER_HEAD(pseries_ioei_notifier_list
);
62 EXPORT_SYMBOL_GPL(pseries_ioei_notifier_list
);
64 static int ioei_check_exception_token
;
66 static char ioei_rtas_buf
[RTAS_DATA_BUF_SIZE
] __cacheline_aligned
;
69 * Find the data portion of an IO Event section from event log.
70 * @elog: RTAS error/event log.
73 * pointer to a valid IO event section data. NULL if not found.
75 static struct pseries_io_event
* ioei_find_event(struct rtas_error_log
*elog
)
77 struct pseries_errorlog
*sect
;
79 /* We should only ever get called for io-event interrupts, but if
80 * we do get called for another type then something went wrong so
81 * make some noise about it.
82 * RTAS_TYPE_IO only exists in extended event log version 6 or later.
83 * No need to check event log version.
85 if (unlikely(rtas_error_type(elog
) != RTAS_TYPE_IO
)) {
86 printk_once(KERN_WARNING
"io_event_irq: Unexpected event type %d",
87 rtas_error_type(elog
));
91 sect
= get_pseries_errorlog(elog
, PSERIES_ELOG_SECT_ID_IO_EVENT
);
92 if (unlikely(!sect
)) {
93 printk_once(KERN_WARNING
"io_event_irq: RTAS extended event "
94 "log does not contain an IO Event section. "
95 "Could be a bug in system firmware!\n");
98 return (struct pseries_io_event
*) §
->data
;
103 * - check-exception returns the first found error or event and clear that
104 * error or event so it is reported once.
105 * - Each interrupt returns one event. If a plateform chooses to report
106 * multiple events through a single interrupt, it must ensure that the
107 * interrupt remains asserted until check-exception has been used to
108 * process all out-standing events for that interrupt.
110 * Implementation notes:
111 * - Events must be processed in the order they are returned. Hence,
112 * sequential in nature.
113 * - The owner of an event is determined by combinations of scope,
114 * event type, and sub-type. There is no easy way to pre-sort clients
115 * by scope or event type alone. For example, Torrent ISR route change
116 * event is reported with scope 0x00 (Not Applicable) rather than
117 * 0x3B (Torrent-hub). It is better to let the clients to identify
118 * who owns the event.
121 static irqreturn_t
ioei_interrupt(int irq
, void *dev_id
)
123 struct pseries_io_event
*event
;
127 rtas_rc
= rtas_call(ioei_check_exception_token
, 6, 1, NULL
,
128 RTAS_VECTOR_EXTERNAL_INTERRUPT
,
130 RTAS_IO_EVENTS
, 1 /* Time Critical */,
136 event
= ioei_find_event((struct rtas_error_log
*)ioei_rtas_buf
);
140 atomic_notifier_call_chain(&pseries_ioei_notifier_list
,
146 static int __init
ioei_init(void)
148 struct device_node
*np
;
150 ioei_check_exception_token
= rtas_token("check-exception");
151 if (ioei_check_exception_token
== RTAS_UNKNOWN_SERVICE
)
154 np
= of_find_node_by_path("/event-sources/ibm,io-events");
156 request_event_sources_irqs(np
, ioei_interrupt
, "IO_EVENT");
157 pr_info("IBM I/O event interrupts enabled\n");
164 machine_subsys_initcall(pseries
, ioei_init
);