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/module.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 /* pSeries event log format */
68 /* Two bytes ASCII section IDs */
69 #define PSERIES_ELOG_SECT_ID_PRIV_HDR (('P' << 8) | 'H')
70 #define PSERIES_ELOG_SECT_ID_USER_HDR (('U' << 8) | 'H')
71 #define PSERIES_ELOG_SECT_ID_PRIMARY_SRC (('P' << 8) | 'S')
72 #define PSERIES_ELOG_SECT_ID_EXTENDED_UH (('E' << 8) | 'H')
73 #define PSERIES_ELOG_SECT_ID_FAILING_MTMS (('M' << 8) | 'T')
74 #define PSERIES_ELOG_SECT_ID_SECONDARY_SRC (('S' << 8) | 'S')
75 #define PSERIES_ELOG_SECT_ID_DUMP_LOCATOR (('D' << 8) | 'H')
76 #define PSERIES_ELOG_SECT_ID_FW_ERROR (('S' << 8) | 'W')
77 #define PSERIES_ELOG_SECT_ID_IMPACT_PART_ID (('L' << 8) | 'P')
78 #define PSERIES_ELOG_SECT_ID_LOGIC_RESOURCE_ID (('L' << 8) | 'R')
79 #define PSERIES_ELOG_SECT_ID_HMC_ID (('H' << 8) | 'M')
80 #define PSERIES_ELOG_SECT_ID_EPOW (('E' << 8) | 'P')
81 #define PSERIES_ELOG_SECT_ID_IO_EVENT (('I' << 8) | 'E')
82 #define PSERIES_ELOG_SECT_ID_MANUFACT_INFO (('M' << 8) | 'I')
83 #define PSERIES_ELOG_SECT_ID_CALL_HOME (('C' << 8) | 'H')
84 #define PSERIES_ELOG_SECT_ID_USER_DEF (('U' << 8) | 'D')
86 /* Vendor specific Platform Event Log Format, Version 6, section header */
87 struct pseries_elog_section
{
88 uint16_t id
; /* 0x00 2-byte ASCII section ID */
89 uint16_t length
; /* 0x02 Section length in bytes */
90 uint8_t version
; /* 0x04 Section version */
91 uint8_t subtype
; /* 0x05 Section subtype */
92 uint16_t creator_component
; /* 0x06 Creator component ID */
93 uint8_t data
[]; /* 0x08 Start of section data */
96 static char ioei_rtas_buf
[RTAS_DATA_BUF_SIZE
] __cacheline_aligned
;
99 * Find data portion of a specific section in RTAS extended event log.
100 * @elog: RTAS error/event log.
101 * @sect_id: secsion ID.
104 * pointer to the section data of the specified section
107 static struct pseries_elog_section
*find_xelog_section(struct rtas_error_log
*elog
,
110 struct rtas_ext_event_log_v6
*xelog
=
111 (struct rtas_ext_event_log_v6
*) elog
->buffer
;
112 struct pseries_elog_section
*sect
;
113 unsigned char *p
, *log_end
;
115 /* Check that we understand the format */
116 if (elog
->extended_log_length
< sizeof(struct rtas_ext_event_log_v6
) ||
117 xelog
->log_format
!= RTAS_V6EXT_LOG_FORMAT_EVENT_LOG
||
118 xelog
->company_id
!= RTAS_V6EXT_COMPANY_ID_IBM
)
121 log_end
= elog
->buffer
+ elog
->extended_log_length
;
122 p
= xelog
->vendor_log
;
123 while (p
< log_end
) {
124 sect
= (struct pseries_elog_section
*)p
;
125 if (sect
->id
== sect_id
)
133 * Find the data portion of an IO Event section from event log.
134 * @elog: RTAS error/event log.
137 * pointer to a valid IO event section data. NULL if not found.
139 static struct pseries_io_event
* ioei_find_event(struct rtas_error_log
*elog
)
141 struct pseries_elog_section
*sect
;
143 /* We should only ever get called for io-event interrupts, but if
144 * we do get called for another type then something went wrong so
145 * make some noise about it.
146 * RTAS_TYPE_IO only exists in extended event log version 6 or later.
147 * No need to check event log version.
149 if (unlikely(elog
->type
!= RTAS_TYPE_IO
)) {
150 printk_once(KERN_WARNING
"io_event_irq: Unexpected event type %d",
155 sect
= find_xelog_section(elog
, PSERIES_ELOG_SECT_ID_IO_EVENT
);
156 if (unlikely(!sect
)) {
157 printk_once(KERN_WARNING
"io_event_irq: RTAS extended event "
158 "log does not contain an IO Event section. "
159 "Could be a bug in system firmware!\n");
162 return (struct pseries_io_event
*) §
->data
;
167 * - check-exception returns the first found error or event and clear that
168 * error or event so it is reported once.
169 * - Each interrupt returns one event. If a plateform chooses to report
170 * multiple events through a single interrupt, it must ensure that the
171 * interrupt remains asserted until check-exception has been used to
172 * process all out-standing events for that interrupt.
174 * Implementation notes:
175 * - Events must be processed in the order they are returned. Hence,
176 * sequential in nature.
177 * - The owner of an event is determined by combinations of scope,
178 * event type, and sub-type. There is no easy way to pre-sort clients
179 * by scope or event type alone. For example, Torrent ISR route change
180 * event is reported with scope 0x00 (Not Applicatable) rather than
181 * 0x3B (Torrent-hub). It is better to let the clients to identify
182 * who owns the the event.
185 static irqreturn_t
ioei_interrupt(int irq
, void *dev_id
)
187 struct pseries_io_event
*event
;
191 rtas_rc
= rtas_call(ioei_check_exception_token
, 6, 1, NULL
,
192 RTAS_VECTOR_EXTERNAL_INTERRUPT
,
194 RTAS_IO_EVENTS
, 1 /* Time Critical */,
200 event
= ioei_find_event((struct rtas_error_log
*)ioei_rtas_buf
);
204 atomic_notifier_call_chain(&pseries_ioei_notifier_list
,
210 static int __init
ioei_init(void)
212 struct device_node
*np
;
214 ioei_check_exception_token
= rtas_token("check-exception");
215 if (ioei_check_exception_token
== RTAS_UNKNOWN_SERVICE
) {
216 pr_warning("IO Event IRQ not supported on this system !\n");
219 np
= of_find_node_by_path("/event-sources/ibm,io-events");
221 request_event_sources_irqs(np
, ioei_interrupt
, "IO_EVENT");
224 pr_err("io_event_irq: No ibm,io-events on system! "
225 "IO Event interrupt disabled.\n");
230 machine_subsys_initcall(pseries
, ioei_init
);