File: | hw/ppc/spapr_events.c |
Location: | line 298, column 9 |
Description: | Value stored to 'xinfo' is never read |
1 | /* |
2 | * QEMU PowerPC pSeries Logical Partition (aka sPAPR) hardware System Emulator |
3 | * |
4 | * RTAS events handling |
5 | * |
6 | * Copyright (c) 2012 David Gibson, IBM Corporation. |
7 | * |
8 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
9 | * of this software and associated documentation files (the "Software"), to deal |
10 | * in the Software without restriction, including without limitation the rights |
11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
12 | * copies of the Software, and to permit persons to whom the Software is |
13 | * furnished to do so, subject to the following conditions: |
14 | * |
15 | * The above copyright notice and this permission notice shall be included in |
16 | * all copies or substantial portions of the Software. |
17 | * |
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
21 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
24 | * THE SOFTWARE. |
25 | * |
26 | */ |
27 | #include "cpu.h" |
28 | #include "sysemu/sysemu.h" |
29 | #include "sysemu/char.h" |
30 | #include "hw/qdev.h" |
31 | #include "sysemu/device_tree.h" |
32 | |
33 | #include "hw/ppc/spapr.h" |
34 | #include "hw/ppc/spapr_vio.h" |
35 | |
36 | #include <libfdt.h> |
37 | |
38 | struct rtas_error_log { |
39 | uint32_t summary; |
40 | #define RTAS_LOG_VERSION_MASK0xff000000 0xff000000 |
41 | #define RTAS_LOG_VERSION_60x06000000 0x06000000 |
42 | #define RTAS_LOG_SEVERITY_MASK0x00e00000 0x00e00000 |
43 | #define RTAS_LOG_SEVERITY_ALREADY_REPORTED0x00c00000 0x00c00000 |
44 | #define RTAS_LOG_SEVERITY_FATAL0x00a00000 0x00a00000 |
45 | #define RTAS_LOG_SEVERITY_ERROR0x00800000 0x00800000 |
46 | #define RTAS_LOG_SEVERITY_ERROR_SYNC0x00600000 0x00600000 |
47 | #define RTAS_LOG_SEVERITY_WARNING0x00400000 0x00400000 |
48 | #define RTAS_LOG_SEVERITY_EVENT0x00200000 0x00200000 |
49 | #define RTAS_LOG_SEVERITY_NO_ERROR0x00000000 0x00000000 |
50 | #define RTAS_LOG_DISPOSITION_MASK0x00180000 0x00180000 |
51 | #define RTAS_LOG_DISPOSITION_FULLY_RECOVERED0x00000000 0x00000000 |
52 | #define RTAS_LOG_DISPOSITION_LIMITED_RECOVERY0x00080000 0x00080000 |
53 | #define RTAS_LOG_DISPOSITION_NOT_RECOVERED0x00100000 0x00100000 |
54 | #define RTAS_LOG_OPTIONAL_PART_PRESENT0x00040000 0x00040000 |
55 | #define RTAS_LOG_INITIATOR_MASK0x0000f000 0x0000f000 |
56 | #define RTAS_LOG_INITIATOR_UNKNOWN0x00000000 0x00000000 |
57 | #define RTAS_LOG_INITIATOR_CPU0x00001000 0x00001000 |
58 | #define RTAS_LOG_INITIATOR_PCI0x00002000 0x00002000 |
59 | #define RTAS_LOG_INITIATOR_MEMORY0x00004000 0x00004000 |
60 | #define RTAS_LOG_INITIATOR_HOTPLUG0x00006000 0x00006000 |
61 | #define RTAS_LOG_TARGET_MASK0x00000f00 0x00000f00 |
62 | #define RTAS_LOG_TARGET_UNKNOWN0x00000000 0x00000000 |
63 | #define RTAS_LOG_TARGET_CPU0x00000100 0x00000100 |
64 | #define RTAS_LOG_TARGET_PCI0x00000200 0x00000200 |
65 | #define RTAS_LOG_TARGET_MEMORY0x00000400 0x00000400 |
66 | #define RTAS_LOG_TARGET_HOTPLUG0x00000600 0x00000600 |
67 | #define RTAS_LOG_TYPE_MASK0x000000ff 0x000000ff |
68 | #define RTAS_LOG_TYPE_OTHER0x00000000 0x00000000 |
69 | #define RTAS_LOG_TYPE_RETRY0x00000001 0x00000001 |
70 | #define RTAS_LOG_TYPE_TCE_ERR0x00000002 0x00000002 |
71 | #define RTAS_LOG_TYPE_INTERN_DEV_FAIL0x00000003 0x00000003 |
72 | #define RTAS_LOG_TYPE_TIMEOUT0x00000004 0x00000004 |
73 | #define RTAS_LOG_TYPE_DATA_PARITY0x00000005 0x00000005 |
74 | #define RTAS_LOG_TYPE_ADDR_PARITY0x00000006 0x00000006 |
75 | #define RTAS_LOG_TYPE_CACHE_PARITY0x00000007 0x00000007 |
76 | #define RTAS_LOG_TYPE_ADDR_INVALID0x00000008 0x00000008 |
77 | #define RTAS_LOG_TYPE_ECC_UNCORR0x00000009 0x00000009 |
78 | #define RTAS_LOG_TYPE_ECC_CORR0x0000000a 0x0000000a |
79 | #define RTAS_LOG_TYPE_EPOW0x00000040 0x00000040 |
80 | uint32_t extended_length; |
81 | } QEMU_PACKED__attribute__((packed)); |
82 | |
83 | struct rtas_event_log_v6 { |
84 | uint8_t b0; |
85 | #define RTAS_LOG_V6_B0_VALID0x80 0x80 |
86 | #define RTAS_LOG_V6_B0_UNRECOVERABLE_ERROR0x40 0x40 |
87 | #define RTAS_LOG_V6_B0_RECOVERABLE_ERROR0x20 0x20 |
88 | #define RTAS_LOG_V6_B0_DEGRADED_OPERATION0x10 0x10 |
89 | #define RTAS_LOG_V6_B0_PREDICTIVE_ERROR0x08 0x08 |
90 | #define RTAS_LOG_V6_B0_NEW_LOG0x04 0x04 |
91 | #define RTAS_LOG_V6_B0_BIGENDIAN0x02 0x02 |
92 | uint8_t _resv1; |
93 | uint8_t b2; |
94 | #define RTAS_LOG_V6_B2_POWERPC_FORMAT0x80 0x80 |
95 | #define RTAS_LOG_V6_B2_LOG_FORMAT_MASK0x0f 0x0f |
96 | #define RTAS_LOG_V6_B2_LOG_FORMAT_PLATFORM_EVENT0x0e 0x0e |
97 | uint8_t _resv2[9]; |
98 | uint32_t company; |
99 | #define RTAS_LOG_V6_COMPANY_IBM0x49424d00 0x49424d00 /* IBM<null> */ |
100 | } QEMU_PACKED__attribute__((packed)); |
101 | |
102 | struct rtas_event_log_v6_section_header { |
103 | uint16_t section_id; |
104 | uint16_t section_length; |
105 | uint8_t section_version; |
106 | uint8_t section_subtype; |
107 | uint16_t creator_component_id; |
108 | } QEMU_PACKED__attribute__((packed)); |
109 | |
110 | struct rtas_event_log_v6_maina { |
111 | #define RTAS_LOG_V6_SECTION_ID_MAINA0x5048 0x5048 /* PH */ |
112 | struct rtas_event_log_v6_section_header hdr; |
113 | uint32_t creation_date; /* BCD: YYYYMMDD */ |
114 | uint32_t creation_time; /* BCD: HHMMSS00 */ |
115 | uint8_t _platform1[8]; |
116 | char creator_id; |
117 | uint8_t _resv1[2]; |
118 | uint8_t section_count; |
119 | uint8_t _resv2[4]; |
120 | uint8_t _platform2[8]; |
121 | uint32_t plid; |
122 | uint8_t _platform3[4]; |
123 | } QEMU_PACKED__attribute__((packed)); |
124 | |
125 | struct rtas_event_log_v6_mainb { |
126 | #define RTAS_LOG_V6_SECTION_ID_MAINB0x5548 0x5548 /* UH */ |
127 | struct rtas_event_log_v6_section_header hdr; |
128 | uint8_t subsystem_id; |
129 | uint8_t _platform1; |
130 | uint8_t event_severity; |
131 | uint8_t event_subtype; |
132 | uint8_t _platform2[4]; |
133 | uint8_t _resv1[2]; |
134 | uint16_t action_flags; |
135 | uint8_t _resv2[4]; |
136 | } QEMU_PACKED__attribute__((packed)); |
137 | |
138 | struct rtas_event_log_v6_epow { |
139 | #define RTAS_LOG_V6_SECTION_ID_EPOW0x4550 0x4550 /* EP */ |
140 | struct rtas_event_log_v6_section_header hdr; |
141 | uint8_t sensor_value; |
142 | #define RTAS_LOG_V6_EPOW_ACTION_RESET0 0 |
143 | #define RTAS_LOG_V6_EPOW_ACTION_WARN_COOLING1 1 |
144 | #define RTAS_LOG_V6_EPOW_ACTION_WARN_POWER2 2 |
145 | #define RTAS_LOG_V6_EPOW_ACTION_SYSTEM_SHUTDOWN3 3 |
146 | #define RTAS_LOG_V6_EPOW_ACTION_SYSTEM_HALT4 4 |
147 | #define RTAS_LOG_V6_EPOW_ACTION_MAIN_ENCLOSURE5 5 |
148 | #define RTAS_LOG_V6_EPOW_ACTION_POWER_OFF7 7 |
149 | uint8_t event_modifier; |
150 | #define RTAS_LOG_V6_EPOW_MODIFIER_NORMAL1 1 |
151 | #define RTAS_LOG_V6_EPOW_MODIFIER_ON_UPS2 2 |
152 | #define RTAS_LOG_V6_EPOW_MODIFIER_CRITICAL3 3 |
153 | #define RTAS_LOG_V6_EPOW_MODIFIER_TEMPERATURE4 4 |
154 | uint8_t extended_modifier; |
155 | #define RTAS_LOG_V6_EPOW_XMODIFIER_SYSTEM_WIDE0 0 |
156 | #define RTAS_LOG_V6_EPOW_XMODIFIER_PARTITION_SPECIFIC1 1 |
157 | uint8_t _resv; |
158 | uint64_t reason_code; |
159 | } QEMU_PACKED__attribute__((packed)); |
160 | |
161 | struct epow_log_full { |
162 | struct rtas_error_log hdr; |
163 | struct rtas_event_log_v6 v6hdr; |
164 | struct rtas_event_log_v6_maina maina; |
165 | struct rtas_event_log_v6_mainb mainb; |
166 | struct rtas_event_log_v6_epow epow; |
167 | } QEMU_PACKED__attribute__((packed)); |
168 | |
169 | #define EVENT_MASK_INTERNAL_ERRORS0x80000000 0x80000000 |
170 | #define EVENT_MASK_EPOW0x40000000 0x40000000 |
171 | #define EVENT_MASK_HOTPLUG0x10000000 0x10000000 |
172 | #define EVENT_MASK_IO0x08000000 0x08000000 |
173 | |
174 | #define _FDT(exp)do { int ret = (exp); if (ret < 0) { fprintf(stderr, "qemu: error creating device tree: %s: %s\n" , "exp", fdt_strerror(ret)); exit(1); } } while (0) \ |
175 | do { \ |
176 | int ret = (exp); \ |
177 | if (ret < 0) { \ |
178 | fprintf(stderrstderr, "qemu: error creating device tree: %s: %s\n", \ |
179 | #exp, fdt_strerror(ret)); \ |
180 | exit(1); \ |
181 | } \ |
182 | } while (0) |
183 | |
184 | void spapr_events_fdt_skel(void *fdt, uint32_t epow_irq) |
185 | { |
186 | uint32_t epow_irq_ranges[] = {cpu_to_be32(epow_irq), cpu_to_be32(1)}; |
187 | uint32_t epow_interrupts[] = {cpu_to_be32(epow_irq), 0}; |
188 | |
189 | _FDT((fdt_begin_node(fdt, "event-sources")))do { int ret = ((fdt_begin_node(fdt, "event-sources"))); if ( ret < 0) { fprintf(stderr, "qemu: error creating device tree: %s: %s\n" , "(fdt_begin_node(fdt, \"event-sources\"))", fdt_strerror(ret )); exit(1); } } while (0); |
190 | |
191 | _FDT((fdt_property(fdt, "interrupt-controller", NULL, 0)))do { int ret = ((fdt_property(fdt, "interrupt-controller", (( void*)0), 0))); if (ret < 0) { fprintf(stderr, "qemu: error creating device tree: %s: %s\n" , "(fdt_property(fdt, \"interrupt-controller\", NULL, 0))", fdt_strerror (ret)); exit(1); } } while (0); |
192 | _FDT((fdt_property_cell(fdt, "#interrupt-cells", 2)))do { int ret = ((fdt_property_cell(fdt, "#interrupt-cells", 2 ))); if (ret < 0) { fprintf(stderr, "qemu: error creating device tree: %s: %s\n" , "(fdt_property_cell(fdt, \"#interrupt-cells\", 2))", fdt_strerror (ret)); exit(1); } } while (0); |
193 | _FDT((fdt_property(fdt, "interrupt-ranges",do { int ret = ((fdt_property(fdt, "interrupt-ranges", epow_irq_ranges , sizeof(epow_irq_ranges)))); if (ret < 0) { fprintf(stderr , "qemu: error creating device tree: %s: %s\n", "(fdt_property(fdt, \"interrupt-ranges\", epow_irq_ranges, sizeof(epow_irq_ranges)))" , fdt_strerror(ret)); exit(1); } } while (0) |
194 | epow_irq_ranges, sizeof(epow_irq_ranges))))do { int ret = ((fdt_property(fdt, "interrupt-ranges", epow_irq_ranges , sizeof(epow_irq_ranges)))); if (ret < 0) { fprintf(stderr , "qemu: error creating device tree: %s: %s\n", "(fdt_property(fdt, \"interrupt-ranges\", epow_irq_ranges, sizeof(epow_irq_ranges)))" , fdt_strerror(ret)); exit(1); } } while (0); |
195 | |
196 | _FDT((fdt_begin_node(fdt, "epow-events")))do { int ret = ((fdt_begin_node(fdt, "epow-events"))); if (ret < 0) { fprintf(stderr, "qemu: error creating device tree: %s: %s\n" , "(fdt_begin_node(fdt, \"epow-events\"))", fdt_strerror(ret) ); exit(1); } } while (0); |
197 | _FDT((fdt_property(fdt, "interrupts",do { int ret = ((fdt_property(fdt, "interrupts", epow_interrupts , sizeof(epow_interrupts)))); if (ret < 0) { fprintf(stderr , "qemu: error creating device tree: %s: %s\n", "(fdt_property(fdt, \"interrupts\", epow_interrupts, sizeof(epow_interrupts)))" , fdt_strerror(ret)); exit(1); } } while (0) |
198 | epow_interrupts, sizeof(epow_interrupts))))do { int ret = ((fdt_property(fdt, "interrupts", epow_interrupts , sizeof(epow_interrupts)))); if (ret < 0) { fprintf(stderr , "qemu: error creating device tree: %s: %s\n", "(fdt_property(fdt, \"interrupts\", epow_interrupts, sizeof(epow_interrupts)))" , fdt_strerror(ret)); exit(1); } } while (0); |
199 | _FDT((fdt_end_node(fdt)))do { int ret = ((fdt_end_node(fdt))); if (ret < 0) { fprintf (stderr, "qemu: error creating device tree: %s: %s\n", "(fdt_end_node(fdt))" , fdt_strerror(ret)); exit(1); } } while (0); |
200 | |
201 | _FDT((fdt_end_node(fdt)))do { int ret = ((fdt_end_node(fdt))); if (ret < 0) { fprintf (stderr, "qemu: error creating device tree: %s: %s\n", "(fdt_end_node(fdt))" , fdt_strerror(ret)); exit(1); } } while (0); |
202 | } |
203 | |
204 | static struct epow_log_full *pending_epow; |
205 | static uint32_t next_plid; |
206 | |
207 | static void spapr_powerdown_req(Notifier *n, void *opaque) |
208 | { |
209 | sPAPREnvironment *spapr = container_of(n, sPAPREnvironment, epow_notifier)({ const typeof(((sPAPREnvironment *) 0)->epow_notifier) * __mptr = (n); (sPAPREnvironment *) ((char *) __mptr - __builtin_offsetof (sPAPREnvironment, epow_notifier));}); |
210 | struct rtas_error_log *hdr; |
211 | struct rtas_event_log_v6 *v6hdr; |
212 | struct rtas_event_log_v6_maina *maina; |
213 | struct rtas_event_log_v6_mainb *mainb; |
214 | struct rtas_event_log_v6_epow *epow; |
215 | struct tm tm; |
216 | int year; |
217 | |
218 | if (pending_epow) { |
219 | /* For now, we just throw away earlier events if two come |
220 | * along before any are consumed. This is sufficient for our |
221 | * powerdown messages, but we'll need more if we do more |
222 | * general error/event logging */ |
223 | g_free(pending_epow); |
224 | } |
225 | pending_epow = g_malloc0(sizeof(*pending_epow)); |
226 | hdr = &pending_epow->hdr; |
227 | v6hdr = &pending_epow->v6hdr; |
228 | maina = &pending_epow->maina; |
229 | mainb = &pending_epow->mainb; |
230 | epow = &pending_epow->epow; |
231 | |
232 | hdr->summary = cpu_to_be32(RTAS_LOG_VERSION_60x06000000 |
233 | | RTAS_LOG_SEVERITY_EVENT0x00200000 |
234 | | RTAS_LOG_DISPOSITION_NOT_RECOVERED0x00100000 |
235 | | RTAS_LOG_OPTIONAL_PART_PRESENT0x00040000 |
236 | | RTAS_LOG_TYPE_EPOW0x00000040); |
237 | hdr->extended_length = cpu_to_be32(sizeof(*pending_epow) |
238 | - sizeof(pending_epow->hdr)); |
239 | |
240 | v6hdr->b0 = RTAS_LOG_V6_B0_VALID0x80 | RTAS_LOG_V6_B0_NEW_LOG0x04 |
241 | | RTAS_LOG_V6_B0_BIGENDIAN0x02; |
242 | v6hdr->b2 = RTAS_LOG_V6_B2_POWERPC_FORMAT0x80 |
243 | | RTAS_LOG_V6_B2_LOG_FORMAT_PLATFORM_EVENT0x0e; |
244 | v6hdr->company = cpu_to_be32(RTAS_LOG_V6_COMPANY_IBM0x49424d00); |
245 | |
246 | maina->hdr.section_id = cpu_to_be16(RTAS_LOG_V6_SECTION_ID_MAINA0x5048); |
247 | maina->hdr.section_length = cpu_to_be16(sizeof(*maina)); |
248 | /* FIXME: section version, subtype and creator id? */ |
249 | qemu_get_timedate(&tm, spapr->rtc_offset); |
250 | year = tm.tm_year + 1900; |
251 | maina->creation_date = cpu_to_be32((to_bcd(year / 100) << 24) |
252 | | (to_bcd(year % 100) << 16) |
253 | | (to_bcd(tm.tm_mon + 1) << 8) |
254 | | to_bcd(tm.tm_mday)); |
255 | maina->creation_time = cpu_to_be32((to_bcd(tm.tm_hour) << 24) |
256 | | (to_bcd(tm.tm_min) << 16) |
257 | | (to_bcd(tm.tm_sec) << 8)); |
258 | maina->creator_id = 'H'; /* Hypervisor */ |
259 | maina->section_count = 3; /* Main-A, Main-B and EPOW */ |
260 | maina->plid = next_plid++; |
261 | |
262 | mainb->hdr.section_id = cpu_to_be16(RTAS_LOG_V6_SECTION_ID_MAINB0x5548); |
263 | mainb->hdr.section_length = cpu_to_be16(sizeof(*mainb)); |
264 | /* FIXME: section version, subtype and creator id? */ |
265 | mainb->subsystem_id = 0xa0; /* External environment */ |
266 | mainb->event_severity = 0x00; /* Informational / non-error */ |
267 | mainb->event_subtype = 0xd0; /* Normal shutdown */ |
268 | |
269 | epow->hdr.section_id = cpu_to_be16(RTAS_LOG_V6_SECTION_ID_EPOW0x4550); |
270 | epow->hdr.section_length = cpu_to_be16(sizeof(*epow)); |
271 | epow->hdr.section_version = 2; /* includes extended modifier */ |
272 | /* FIXME: section subtype and creator id? */ |
273 | epow->sensor_value = RTAS_LOG_V6_EPOW_ACTION_SYSTEM_SHUTDOWN3; |
274 | epow->event_modifier = RTAS_LOG_V6_EPOW_MODIFIER_NORMAL1; |
275 | epow->extended_modifier = RTAS_LOG_V6_EPOW_XMODIFIER_PARTITION_SPECIFIC1; |
276 | |
277 | qemu_irq_pulse(xics_get_qirq(spapr->icp, spapr->epow_irq)); |
278 | } |
279 | |
280 | static void check_exception(PowerPCCPU *cpu, sPAPREnvironment *spapr, |
281 | uint32_t token, uint32_t nargs, |
282 | target_ulong args, |
283 | uint32_t nret, target_ulong rets) |
284 | { |
285 | uint32_t mask, buf, len; |
286 | uint64_t xinfo; |
287 | |
288 | if ((nargs < 6) || (nargs > 7) || nret != 1) { |
289 | rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR-3); |
290 | return; |
291 | } |
292 | |
293 | xinfo = rtas_ld(args, 1); |
294 | mask = rtas_ld(args, 2); |
295 | buf = rtas_ld(args, 4); |
296 | len = rtas_ld(args, 5); |
297 | if (nargs == 7) { |
298 | xinfo |= (uint64_t)rtas_ld(args, 6) << 32; |
Value stored to 'xinfo' is never read | |
299 | } |
300 | |
301 | if ((mask & EVENT_MASK_EPOW0x40000000) && pending_epow) { |
302 | if (sizeof(*pending_epow) < len) { |
303 | len = sizeof(*pending_epow); |
304 | } |
305 | |
306 | cpu_physical_memory_write(buf, pending_epow, len); |
307 | g_free(pending_epow); |
308 | pending_epow = NULL((void*)0); |
309 | rtas_st(rets, 0, RTAS_OUT_SUCCESS0); |
310 | } else { |
311 | rtas_st(rets, 0, RTAS_OUT_NO_ERRORS_FOUND1); |
312 | } |
313 | } |
314 | |
315 | void spapr_events_init(sPAPREnvironment *spapr) |
316 | { |
317 | spapr->epow_irq = spapr_allocate_msi(0); |
318 | spapr->epow_notifier.notify = spapr_powerdown_req; |
319 | qemu_register_powerdown_notifier(&spapr->epow_notifier); |
320 | spapr_rtas_register("check-exception", check_exception); |
321 | } |