powerpc/powernv: Sync OpalPciResetScope with firmware
[firefly-linux-kernel-4.4.55.git] / arch / powerpc / include / asm / opal.h
1 /*
2  * PowerNV OPAL definitions.
3  *
4  * Copyright 2011 IBM Corp.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version
9  * 2 of the License, or (at your option) any later version.
10  */
11
12 #ifndef __OPAL_H
13 #define __OPAL_H
14
15 #ifndef __ASSEMBLY__
16 /*
17  * SG entry
18  *
19  * WARNING: The current implementation requires each entry
20  * to represent a block that is 4k aligned *and* each block
21  * size except the last one in the list to be as well.
22  */
23 struct opal_sg_entry {
24         __be64 data;
25         __be64 length;
26 };
27
28 /* SG list */
29 struct opal_sg_list {
30         __be64 length;
31         __be64 next;
32         struct opal_sg_entry entry[];
33 };
34
35 /* We calculate number of sg entries based on PAGE_SIZE */
36 #define SG_ENTRIES_PER_NODE ((PAGE_SIZE - 16) / sizeof(struct opal_sg_entry))
37
38 #endif /* __ASSEMBLY__ */
39
40 /****** OPAL APIs ******/
41
42 /* Return codes */
43 #define OPAL_SUCCESS            0
44 #define OPAL_PARAMETER          -1
45 #define OPAL_BUSY               -2
46 #define OPAL_PARTIAL            -3
47 #define OPAL_CONSTRAINED        -4
48 #define OPAL_CLOSED             -5
49 #define OPAL_HARDWARE           -6
50 #define OPAL_UNSUPPORTED        -7
51 #define OPAL_PERMISSION         -8
52 #define OPAL_NO_MEM             -9
53 #define OPAL_RESOURCE           -10
54 #define OPAL_INTERNAL_ERROR     -11
55 #define OPAL_BUSY_EVENT         -12
56 #define OPAL_HARDWARE_FROZEN    -13
57 #define OPAL_WRONG_STATE        -14
58 #define OPAL_ASYNC_COMPLETION   -15
59
60 /* API Tokens (in r0) */
61 #define OPAL_INVALID_CALL                       -1
62 #define OPAL_CONSOLE_WRITE                      1
63 #define OPAL_CONSOLE_READ                       2
64 #define OPAL_RTC_READ                           3
65 #define OPAL_RTC_WRITE                          4
66 #define OPAL_CEC_POWER_DOWN                     5
67 #define OPAL_CEC_REBOOT                         6
68 #define OPAL_READ_NVRAM                         7
69 #define OPAL_WRITE_NVRAM                        8
70 #define OPAL_HANDLE_INTERRUPT                   9
71 #define OPAL_POLL_EVENTS                        10
72 #define OPAL_PCI_SET_HUB_TCE_MEMORY             11
73 #define OPAL_PCI_SET_PHB_TCE_MEMORY             12
74 #define OPAL_PCI_CONFIG_READ_BYTE               13
75 #define OPAL_PCI_CONFIG_READ_HALF_WORD          14
76 #define OPAL_PCI_CONFIG_READ_WORD               15
77 #define OPAL_PCI_CONFIG_WRITE_BYTE              16
78 #define OPAL_PCI_CONFIG_WRITE_HALF_WORD         17
79 #define OPAL_PCI_CONFIG_WRITE_WORD              18
80 #define OPAL_SET_XIVE                           19
81 #define OPAL_GET_XIVE                           20
82 #define OPAL_GET_COMPLETION_TOKEN_STATUS        21 /* obsolete */
83 #define OPAL_REGISTER_OPAL_EXCEPTION_HANDLER    22
84 #define OPAL_PCI_EEH_FREEZE_STATUS              23
85 #define OPAL_PCI_SHPC                           24
86 #define OPAL_CONSOLE_WRITE_BUFFER_SPACE         25
87 #define OPAL_PCI_EEH_FREEZE_CLEAR               26
88 #define OPAL_PCI_PHB_MMIO_ENABLE                27
89 #define OPAL_PCI_SET_PHB_MEM_WINDOW             28
90 #define OPAL_PCI_MAP_PE_MMIO_WINDOW             29
91 #define OPAL_PCI_SET_PHB_TABLE_MEMORY           30
92 #define OPAL_PCI_SET_PE                         31
93 #define OPAL_PCI_SET_PELTV                      32
94 #define OPAL_PCI_SET_MVE                        33
95 #define OPAL_PCI_SET_MVE_ENABLE                 34
96 #define OPAL_PCI_GET_XIVE_REISSUE               35
97 #define OPAL_PCI_SET_XIVE_REISSUE               36
98 #define OPAL_PCI_SET_XIVE_PE                    37
99 #define OPAL_GET_XIVE_SOURCE                    38
100 #define OPAL_GET_MSI_32                         39
101 #define OPAL_GET_MSI_64                         40
102 #define OPAL_START_CPU                          41
103 #define OPAL_QUERY_CPU_STATUS                   42
104 #define OPAL_WRITE_OPPANEL                      43
105 #define OPAL_PCI_MAP_PE_DMA_WINDOW              44
106 #define OPAL_PCI_MAP_PE_DMA_WINDOW_REAL         45
107 #define OPAL_PCI_RESET                          49
108 #define OPAL_PCI_GET_HUB_DIAG_DATA              50
109 #define OPAL_PCI_GET_PHB_DIAG_DATA              51
110 #define OPAL_PCI_FENCE_PHB                      52
111 #define OPAL_PCI_REINIT                         53
112 #define OPAL_PCI_MASK_PE_ERROR                  54
113 #define OPAL_SET_SLOT_LED_STATUS                55
114 #define OPAL_GET_EPOW_STATUS                    56
115 #define OPAL_SET_SYSTEM_ATTENTION_LED           57
116 #define OPAL_RESERVED1                          58
117 #define OPAL_RESERVED2                          59
118 #define OPAL_PCI_NEXT_ERROR                     60
119 #define OPAL_PCI_EEH_FREEZE_STATUS2             61
120 #define OPAL_PCI_POLL                           62
121 #define OPAL_PCI_MSI_EOI                        63
122 #define OPAL_PCI_GET_PHB_DIAG_DATA2             64
123 #define OPAL_XSCOM_READ                         65
124 #define OPAL_XSCOM_WRITE                        66
125 #define OPAL_LPC_READ                           67
126 #define OPAL_LPC_WRITE                          68
127 #define OPAL_RETURN_CPU                         69
128 #define OPAL_REINIT_CPUS                        70
129 #define OPAL_ELOG_READ                          71
130 #define OPAL_ELOG_WRITE                         72
131 #define OPAL_ELOG_ACK                           73
132 #define OPAL_ELOG_RESEND                        74
133 #define OPAL_ELOG_SIZE                          75
134 #define OPAL_FLASH_VALIDATE                     76
135 #define OPAL_FLASH_MANAGE                       77
136 #define OPAL_FLASH_UPDATE                       78
137 #define OPAL_RESYNC_TIMEBASE                    79
138 #define OPAL_CHECK_TOKEN                        80
139 #define OPAL_DUMP_INIT                          81
140 #define OPAL_DUMP_INFO                          82
141 #define OPAL_DUMP_READ                          83
142 #define OPAL_DUMP_ACK                           84
143 #define OPAL_GET_MSG                            85
144 #define OPAL_CHECK_ASYNC_COMPLETION             86
145 #define OPAL_SYNC_HOST_REBOOT                   87
146 #define OPAL_SENSOR_READ                        88
147 #define OPAL_GET_PARAM                          89
148 #define OPAL_SET_PARAM                          90
149 #define OPAL_DUMP_RESEND                        91
150 #define OPAL_DUMP_INFO2                         94
151 #define OPAL_PCI_ERR_INJECT                     96
152 #define OPAL_PCI_EEH_FREEZE_SET                 97
153 #define OPAL_HANDLE_HMI                         98
154 #define OPAL_REGISTER_DUMP_REGION               101
155 #define OPAL_UNREGISTER_DUMP_REGION             102
156
157 #ifndef __ASSEMBLY__
158
159 #include <linux/notifier.h>
160
161 /* Other enums */
162 enum OpalVendorApiTokens {
163         OPAL_START_VENDOR_API_RANGE = 1000, OPAL_END_VENDOR_API_RANGE = 1999
164 };
165
166 enum OpalFreezeState {
167         OPAL_EEH_STOPPED_NOT_FROZEN = 0,
168         OPAL_EEH_STOPPED_MMIO_FREEZE = 1,
169         OPAL_EEH_STOPPED_DMA_FREEZE = 2,
170         OPAL_EEH_STOPPED_MMIO_DMA_FREEZE = 3,
171         OPAL_EEH_STOPPED_RESET = 4,
172         OPAL_EEH_STOPPED_TEMP_UNAVAIL = 5,
173         OPAL_EEH_STOPPED_PERM_UNAVAIL = 6
174 };
175
176 enum OpalEehFreezeActionToken {
177         OPAL_EEH_ACTION_CLEAR_FREEZE_MMIO = 1,
178         OPAL_EEH_ACTION_CLEAR_FREEZE_DMA = 2,
179         OPAL_EEH_ACTION_CLEAR_FREEZE_ALL = 3,
180
181         OPAL_EEH_ACTION_SET_FREEZE_MMIO = 1,
182         OPAL_EEH_ACTION_SET_FREEZE_DMA  = 2,
183         OPAL_EEH_ACTION_SET_FREEZE_ALL  = 3
184 };
185
186 enum OpalPciStatusToken {
187         OPAL_EEH_NO_ERROR       = 0,
188         OPAL_EEH_IOC_ERROR      = 1,
189         OPAL_EEH_PHB_ERROR      = 2,
190         OPAL_EEH_PE_ERROR       = 3,
191         OPAL_EEH_PE_MMIO_ERROR  = 4,
192         OPAL_EEH_PE_DMA_ERROR   = 5
193 };
194
195 enum OpalPciErrorSeverity {
196         OPAL_EEH_SEV_NO_ERROR   = 0,
197         OPAL_EEH_SEV_IOC_DEAD   = 1,
198         OPAL_EEH_SEV_PHB_DEAD   = 2,
199         OPAL_EEH_SEV_PHB_FENCED = 3,
200         OPAL_EEH_SEV_PE_ER      = 4,
201         OPAL_EEH_SEV_INF        = 5
202 };
203
204 enum OpalErrinjectType {
205         OPAL_ERR_INJECT_TYPE_IOA_BUS_ERR        = 0,
206         OPAL_ERR_INJECT_TYPE_IOA_BUS_ERR64      = 1,
207 };
208
209 enum OpalErrinjectFunc {
210         /* IOA bus specific errors */
211         OPAL_ERR_INJECT_FUNC_IOA_LD_MEM_ADDR    = 0,
212         OPAL_ERR_INJECT_FUNC_IOA_LD_MEM_DATA    = 1,
213         OPAL_ERR_INJECT_FUNC_IOA_LD_IO_ADDR     = 2,
214         OPAL_ERR_INJECT_FUNC_IOA_LD_IO_DATA     = 3,
215         OPAL_ERR_INJECT_FUNC_IOA_LD_CFG_ADDR    = 4,
216         OPAL_ERR_INJECT_FUNC_IOA_LD_CFG_DATA    = 5,
217         OPAL_ERR_INJECT_FUNC_IOA_ST_MEM_ADDR    = 6,
218         OPAL_ERR_INJECT_FUNC_IOA_ST_MEM_DATA    = 7,
219         OPAL_ERR_INJECT_FUNC_IOA_ST_IO_ADDR     = 8,
220         OPAL_ERR_INJECT_FUNC_IOA_ST_IO_DATA     = 9,
221         OPAL_ERR_INJECT_FUNC_IOA_ST_CFG_ADDR    = 10,
222         OPAL_ERR_INJECT_FUNC_IOA_ST_CFG_DATA    = 11,
223         OPAL_ERR_INJECT_FUNC_IOA_DMA_RD_ADDR    = 12,
224         OPAL_ERR_INJECT_FUNC_IOA_DMA_RD_DATA    = 13,
225         OPAL_ERR_INJECT_FUNC_IOA_DMA_RD_MASTER  = 14,
226         OPAL_ERR_INJECT_FUNC_IOA_DMA_RD_TARGET  = 15,
227         OPAL_ERR_INJECT_FUNC_IOA_DMA_WR_ADDR    = 16,
228         OPAL_ERR_INJECT_FUNC_IOA_DMA_WR_DATA    = 17,
229         OPAL_ERR_INJECT_FUNC_IOA_DMA_WR_MASTER  = 18,
230         OPAL_ERR_INJECT_FUNC_IOA_DMA_WR_TARGET  = 19,
231 };
232
233 enum OpalShpcAction {
234         OPAL_SHPC_GET_LINK_STATE = 0,
235         OPAL_SHPC_GET_SLOT_STATE = 1
236 };
237
238 enum OpalShpcLinkState {
239         OPAL_SHPC_LINK_DOWN = 0,
240         OPAL_SHPC_LINK_UP = 1
241 };
242
243 enum OpalMmioWindowType {
244         OPAL_M32_WINDOW_TYPE = 1,
245         OPAL_M64_WINDOW_TYPE = 2,
246         OPAL_IO_WINDOW_TYPE = 3
247 };
248
249 enum OpalShpcSlotState {
250         OPAL_SHPC_DEV_NOT_PRESENT = 0,
251         OPAL_SHPC_DEV_PRESENT = 1
252 };
253
254 enum OpalExceptionHandler {
255         OPAL_MACHINE_CHECK_HANDLER = 1,
256         OPAL_HYPERVISOR_MAINTENANCE_HANDLER = 2,
257         OPAL_SOFTPATCH_HANDLER = 3
258 };
259
260 enum OpalPendingState {
261         OPAL_EVENT_OPAL_INTERNAL        = 0x1,
262         OPAL_EVENT_NVRAM                = 0x2,
263         OPAL_EVENT_RTC                  = 0x4,
264         OPAL_EVENT_CONSOLE_OUTPUT       = 0x8,
265         OPAL_EVENT_CONSOLE_INPUT        = 0x10,
266         OPAL_EVENT_ERROR_LOG_AVAIL      = 0x20,
267         OPAL_EVENT_ERROR_LOG            = 0x40,
268         OPAL_EVENT_EPOW                 = 0x80,
269         OPAL_EVENT_LED_STATUS           = 0x100,
270         OPAL_EVENT_PCI_ERROR            = 0x200,
271         OPAL_EVENT_DUMP_AVAIL           = 0x400,
272         OPAL_EVENT_MSG_PENDING          = 0x800,
273 };
274
275 enum OpalMessageType {
276         OPAL_MSG_ASYNC_COMP = 0,        /* params[0] = token, params[1] = rc,
277                                          * additional params function-specific
278                                          */
279         OPAL_MSG_MEM_ERR,
280         OPAL_MSG_EPOW,
281         OPAL_MSG_SHUTDOWN,
282         OPAL_MSG_HMI_EVT,
283         OPAL_MSG_TYPE_MAX,
284 };
285
286 /* Machine check related definitions */
287 enum OpalMCE_Version {
288         OpalMCE_V1 = 1,
289 };
290
291 enum OpalMCE_Severity {
292         OpalMCE_SEV_NO_ERROR = 0,
293         OpalMCE_SEV_WARNING = 1,
294         OpalMCE_SEV_ERROR_SYNC = 2,
295         OpalMCE_SEV_FATAL = 3,
296 };
297
298 enum OpalMCE_Disposition {
299         OpalMCE_DISPOSITION_RECOVERED = 0,
300         OpalMCE_DISPOSITION_NOT_RECOVERED = 1,
301 };
302
303 enum OpalMCE_Initiator {
304         OpalMCE_INITIATOR_UNKNOWN = 0,
305         OpalMCE_INITIATOR_CPU = 1,
306 };
307
308 enum OpalMCE_ErrorType {
309         OpalMCE_ERROR_TYPE_UNKNOWN = 0,
310         OpalMCE_ERROR_TYPE_UE = 1,
311         OpalMCE_ERROR_TYPE_SLB = 2,
312         OpalMCE_ERROR_TYPE_ERAT = 3,
313         OpalMCE_ERROR_TYPE_TLB = 4,
314 };
315
316 enum OpalMCE_UeErrorType {
317         OpalMCE_UE_ERROR_INDETERMINATE = 0,
318         OpalMCE_UE_ERROR_IFETCH = 1,
319         OpalMCE_UE_ERROR_PAGE_TABLE_WALK_IFETCH = 2,
320         OpalMCE_UE_ERROR_LOAD_STORE = 3,
321         OpalMCE_UE_ERROR_PAGE_TABLE_WALK_LOAD_STORE = 4,
322 };
323
324 enum OpalMCE_SlbErrorType {
325         OpalMCE_SLB_ERROR_INDETERMINATE = 0,
326         OpalMCE_SLB_ERROR_PARITY = 1,
327         OpalMCE_SLB_ERROR_MULTIHIT = 2,
328 };
329
330 enum OpalMCE_EratErrorType {
331         OpalMCE_ERAT_ERROR_INDETERMINATE = 0,
332         OpalMCE_ERAT_ERROR_PARITY = 1,
333         OpalMCE_ERAT_ERROR_MULTIHIT = 2,
334 };
335
336 enum OpalMCE_TlbErrorType {
337         OpalMCE_TLB_ERROR_INDETERMINATE = 0,
338         OpalMCE_TLB_ERROR_PARITY = 1,
339         OpalMCE_TLB_ERROR_MULTIHIT = 2,
340 };
341
342 enum OpalThreadStatus {
343         OPAL_THREAD_INACTIVE = 0x0,
344         OPAL_THREAD_STARTED = 0x1,
345         OPAL_THREAD_UNAVAILABLE = 0x2 /* opal-v3 */
346 };
347
348 enum OpalPciBusCompare {
349         OpalPciBusAny   = 0,    /* Any bus number match */
350         OpalPciBus3Bits = 2,    /* Match top 3 bits of bus number */
351         OpalPciBus4Bits = 3,    /* Match top 4 bits of bus number */
352         OpalPciBus5Bits = 4,    /* Match top 5 bits of bus number */
353         OpalPciBus6Bits = 5,    /* Match top 6 bits of bus number */
354         OpalPciBus7Bits = 6,    /* Match top 7 bits of bus number */
355         OpalPciBusAll   = 7,    /* Match bus number exactly */
356 };
357
358 enum OpalDeviceCompare {
359         OPAL_IGNORE_RID_DEVICE_NUMBER = 0,
360         OPAL_COMPARE_RID_DEVICE_NUMBER = 1
361 };
362
363 enum OpalFuncCompare {
364         OPAL_IGNORE_RID_FUNCTION_NUMBER = 0,
365         OPAL_COMPARE_RID_FUNCTION_NUMBER = 1
366 };
367
368 enum OpalPeAction {
369         OPAL_UNMAP_PE = 0,
370         OPAL_MAP_PE = 1
371 };
372
373 enum OpalPeltvAction {
374         OPAL_REMOVE_PE_FROM_DOMAIN = 0,
375         OPAL_ADD_PE_TO_DOMAIN = 1
376 };
377
378 enum OpalMveEnableAction {
379         OPAL_DISABLE_MVE = 0,
380         OPAL_ENABLE_MVE = 1
381 };
382
383 enum OpalM64EnableAction {
384         OPAL_DISABLE_M64 = 0,
385         OPAL_ENABLE_M64_SPLIT = 1,
386         OPAL_ENABLE_M64_NON_SPLIT = 2
387 };
388
389 enum OpalPciResetScope {
390         OPAL_RESET_PHB_COMPLETE         = 1,
391         OPAL_RESET_PCI_LINK             = 2,
392         OPAL_RESET_PHB_ERROR            = 3,
393         OPAL_RESET_PCI_HOT              = 4,
394         OPAL_RESET_PCI_FUNDAMENTAL      = 5,
395         OPAL_RESET_PCI_IODA_TABLE       = 6
396 };
397
398 enum OpalPciReinitScope {
399         OPAL_REINIT_PCI_DEV = 1000
400 };
401
402 enum OpalPciResetState {
403         OPAL_DEASSERT_RESET = 0,
404         OPAL_ASSERT_RESET = 1
405 };
406
407 enum OpalPciMaskAction {
408         OPAL_UNMASK_ERROR_TYPE = 0,
409         OPAL_MASK_ERROR_TYPE = 1
410 };
411
412 enum OpalSlotLedType {
413         OPAL_SLOT_LED_ID_TYPE = 0,
414         OPAL_SLOT_LED_FAULT_TYPE = 1
415 };
416
417 enum OpalLedAction {
418         OPAL_TURN_OFF_LED = 0,
419         OPAL_TURN_ON_LED = 1,
420         OPAL_QUERY_LED_STATE_AFTER_BUSY = 2
421 };
422
423 enum OpalEpowStatus {
424         OPAL_EPOW_NONE = 0,
425         OPAL_EPOW_UPS = 1,
426         OPAL_EPOW_OVER_AMBIENT_TEMP = 2,
427         OPAL_EPOW_OVER_INTERNAL_TEMP = 3
428 };
429
430 /*
431  * Address cycle types for LPC accesses. These also correspond
432  * to the content of the first cell of the "reg" property for
433  * device nodes on the LPC bus
434  */
435 enum OpalLPCAddressType {
436         OPAL_LPC_MEM    = 0,
437         OPAL_LPC_IO     = 1,
438         OPAL_LPC_FW     = 2,
439 };
440
441 /* System parameter permission */
442 enum OpalSysparamPerm {
443         OPAL_SYSPARAM_READ      = 0x1,
444         OPAL_SYSPARAM_WRITE     = 0x2,
445         OPAL_SYSPARAM_RW        = (OPAL_SYSPARAM_READ | OPAL_SYSPARAM_WRITE),
446 };
447
448 struct opal_msg {
449         __be32 msg_type;
450         __be32 reserved;
451         __be64 params[8];
452 };
453
454 struct opal_machine_check_event {
455         enum OpalMCE_Version    version:8;      /* 0x00 */
456         uint8_t                 in_use;         /* 0x01 */
457         enum OpalMCE_Severity   severity:8;     /* 0x02 */
458         enum OpalMCE_Initiator  initiator:8;    /* 0x03 */
459         enum OpalMCE_ErrorType  error_type:8;   /* 0x04 */
460         enum OpalMCE_Disposition disposition:8; /* 0x05 */
461         uint8_t                 reserved_1[2];  /* 0x06 */
462         uint64_t                gpr3;           /* 0x08 */
463         uint64_t                srr0;           /* 0x10 */
464         uint64_t                srr1;           /* 0x18 */
465         union {                                 /* 0x20 */
466                 struct {
467                         enum OpalMCE_UeErrorType ue_error_type:8;
468                         uint8_t         effective_address_provided;
469                         uint8_t         physical_address_provided;
470                         uint8_t         reserved_1[5];
471                         uint64_t        effective_address;
472                         uint64_t        physical_address;
473                         uint8_t         reserved_2[8];
474                 } ue_error;
475
476                 struct {
477                         enum OpalMCE_SlbErrorType slb_error_type:8;
478                         uint8_t         effective_address_provided;
479                         uint8_t         reserved_1[6];
480                         uint64_t        effective_address;
481                         uint8_t         reserved_2[16];
482                 } slb_error;
483
484                 struct {
485                         enum OpalMCE_EratErrorType erat_error_type:8;
486                         uint8_t         effective_address_provided;
487                         uint8_t         reserved_1[6];
488                         uint64_t        effective_address;
489                         uint8_t         reserved_2[16];
490                 } erat_error;
491
492                 struct {
493                         enum OpalMCE_TlbErrorType tlb_error_type:8;
494                         uint8_t         effective_address_provided;
495                         uint8_t         reserved_1[6];
496                         uint64_t        effective_address;
497                         uint8_t         reserved_2[16];
498                 } tlb_error;
499         } u;
500 };
501
502 /* FSP memory errors handling */
503 enum OpalMemErr_Version {
504         OpalMemErr_V1 = 1,
505 };
506
507 enum OpalMemErrType {
508         OPAL_MEM_ERR_TYPE_RESILIENCE    = 0,
509         OPAL_MEM_ERR_TYPE_DYN_DALLOC,
510         OPAL_MEM_ERR_TYPE_SCRUB,
511 };
512
513 /* Memory Reilience error type */
514 enum OpalMemErr_ResilErrType {
515         OPAL_MEM_RESILIENCE_CE          = 0,
516         OPAL_MEM_RESILIENCE_UE,
517         OPAL_MEM_RESILIENCE_UE_SCRUB,
518 };
519
520 /* Dynamic Memory Deallocation type */
521 enum OpalMemErr_DynErrType {
522         OPAL_MEM_DYNAMIC_DEALLOC        = 0,
523 };
524
525 /* OpalMemoryErrorData->flags */
526 #define OPAL_MEM_CORRECTED_ERROR        0x0001
527 #define OPAL_MEM_THRESHOLD_EXCEEDED     0x0002
528 #define OPAL_MEM_ACK_REQUIRED           0x8000
529
530 struct OpalMemoryErrorData {
531         enum OpalMemErr_Version version:8;      /* 0x00 */
532         enum OpalMemErrType     type:8;         /* 0x01 */
533         __be16                  flags;          /* 0x02 */
534         uint8_t                 reserved_1[4];  /* 0x04 */
535
536         union {
537                 /* Memory Resilience corrected/uncorrected error info */
538                 struct {
539                         enum OpalMemErr_ResilErrType resil_err_type:8;
540                         uint8_t         reserved_1[7];
541                         __be64          physical_address_start;
542                         __be64          physical_address_end;
543                 } resilience;
544                 /* Dynamic memory deallocation error info */
545                 struct {
546                         enum OpalMemErr_DynErrType dyn_err_type:8;
547                         uint8_t         reserved_1[7];
548                         __be64          physical_address_start;
549                         __be64          physical_address_end;
550                 } dyn_dealloc;
551         } u;
552 };
553
554 /* HMI interrupt event */
555 enum OpalHMI_Version {
556         OpalHMIEvt_V1 = 1,
557 };
558
559 enum OpalHMI_Severity {
560         OpalHMI_SEV_NO_ERROR = 0,
561         OpalHMI_SEV_WARNING = 1,
562         OpalHMI_SEV_ERROR_SYNC = 2,
563         OpalHMI_SEV_FATAL = 3,
564 };
565
566 enum OpalHMI_Disposition {
567         OpalHMI_DISPOSITION_RECOVERED = 0,
568         OpalHMI_DISPOSITION_NOT_RECOVERED = 1,
569 };
570
571 enum OpalHMI_ErrType {
572         OpalHMI_ERROR_MALFUNC_ALERT     = 0,
573         OpalHMI_ERROR_PROC_RECOV_DONE,
574         OpalHMI_ERROR_PROC_RECOV_DONE_AGAIN,
575         OpalHMI_ERROR_PROC_RECOV_MASKED,
576         OpalHMI_ERROR_TFAC,
577         OpalHMI_ERROR_TFMR_PARITY,
578         OpalHMI_ERROR_HA_OVERFLOW_WARN,
579         OpalHMI_ERROR_XSCOM_FAIL,
580         OpalHMI_ERROR_XSCOM_DONE,
581         OpalHMI_ERROR_SCOM_FIR,
582         OpalHMI_ERROR_DEBUG_TRIG_FIR,
583         OpalHMI_ERROR_HYP_RESOURCE,
584 };
585
586 struct OpalHMIEvent {
587         uint8_t         version;        /* 0x00 */
588         uint8_t         severity;       /* 0x01 */
589         uint8_t         type;           /* 0x02 */
590         uint8_t         disposition;    /* 0x03 */
591         uint8_t         reserved_1[4];  /* 0x04 */
592
593         __be64          hmer;
594         /* TFMR register. Valid only for TFAC and TFMR_PARITY error type. */
595         __be64          tfmr;
596 };
597
598 enum {
599         OPAL_P7IOC_DIAG_TYPE_NONE       = 0,
600         OPAL_P7IOC_DIAG_TYPE_RGC        = 1,
601         OPAL_P7IOC_DIAG_TYPE_BI         = 2,
602         OPAL_P7IOC_DIAG_TYPE_CI         = 3,
603         OPAL_P7IOC_DIAG_TYPE_MISC       = 4,
604         OPAL_P7IOC_DIAG_TYPE_I2C        = 5,
605         OPAL_P7IOC_DIAG_TYPE_LAST       = 6
606 };
607
608 struct OpalIoP7IOCErrorData {
609         __be16 type;
610
611         /* GEM */
612         __be64 gemXfir;
613         __be64 gemRfir;
614         __be64 gemRirqfir;
615         __be64 gemMask;
616         __be64 gemRwof;
617
618         /* LEM */
619         __be64 lemFir;
620         __be64 lemErrMask;
621         __be64 lemAction0;
622         __be64 lemAction1;
623         __be64 lemWof;
624
625         union {
626                 struct OpalIoP7IOCRgcErrorData {
627                         __be64 rgcStatus;       /* 3E1C10 */
628                         __be64 rgcLdcp;         /* 3E1C18 */
629                 }rgc;
630                 struct OpalIoP7IOCBiErrorData {
631                         __be64 biLdcp0;         /* 3C0100, 3C0118 */
632                         __be64 biLdcp1;         /* 3C0108, 3C0120 */
633                         __be64 biLdcp2;         /* 3C0110, 3C0128 */
634                         __be64 biFenceStatus;   /* 3C0130, 3C0130 */
635
636                             u8 biDownbound;     /* BI Downbound or Upbound */
637                 }bi;
638                 struct OpalIoP7IOCCiErrorData {
639                         __be64 ciPortStatus;    /* 3Dn008 */
640                         __be64 ciPortLdcp;      /* 3Dn010 */
641
642                             u8 ciPort;          /* Index of CI port: 0/1 */
643                 }ci;
644         };
645 };
646
647 /**
648  * This structure defines the overlay which will be used to store PHB error
649  * data upon request.
650  */
651 enum {
652         OPAL_PHB_ERROR_DATA_VERSION_1 = 1,
653 };
654
655 enum {
656         OPAL_PHB_ERROR_DATA_TYPE_P7IOC = 1,
657         OPAL_PHB_ERROR_DATA_TYPE_PHB3 = 2
658 };
659
660 enum {
661         OPAL_P7IOC_NUM_PEST_REGS = 128,
662         OPAL_PHB3_NUM_PEST_REGS = 256
663 };
664
665 struct OpalIoPhbErrorCommon {
666         __be32 version;
667         __be32 ioType;
668         __be32 len;
669 };
670
671 struct OpalIoP7IOCPhbErrorData {
672         struct OpalIoPhbErrorCommon common;
673
674         __be32 brdgCtl;
675
676         // P7IOC utl regs
677         __be32 portStatusReg;
678         __be32 rootCmplxStatus;
679         __be32 busAgentStatus;
680
681         // P7IOC cfg regs
682         __be32 deviceStatus;
683         __be32 slotStatus;
684         __be32 linkStatus;
685         __be32 devCmdStatus;
686         __be32 devSecStatus;
687
688         // cfg AER regs
689         __be32 rootErrorStatus;
690         __be32 uncorrErrorStatus;
691         __be32 corrErrorStatus;
692         __be32 tlpHdr1;
693         __be32 tlpHdr2;
694         __be32 tlpHdr3;
695         __be32 tlpHdr4;
696         __be32 sourceId;
697
698         __be32 rsv3;
699
700         // Record data about the call to allocate a buffer.
701         __be64 errorClass;
702         __be64 correlator;
703
704         //P7IOC MMIO Error Regs
705         __be64 p7iocPlssr;                // n120
706         __be64 p7iocCsr;                  // n110
707         __be64 lemFir;                    // nC00
708         __be64 lemErrorMask;              // nC18
709         __be64 lemWOF;                    // nC40
710         __be64 phbErrorStatus;            // nC80
711         __be64 phbFirstErrorStatus;       // nC88
712         __be64 phbErrorLog0;              // nCC0
713         __be64 phbErrorLog1;              // nCC8
714         __be64 mmioErrorStatus;           // nD00
715         __be64 mmioFirstErrorStatus;      // nD08
716         __be64 mmioErrorLog0;             // nD40
717         __be64 mmioErrorLog1;             // nD48
718         __be64 dma0ErrorStatus;           // nD80
719         __be64 dma0FirstErrorStatus;      // nD88
720         __be64 dma0ErrorLog0;             // nDC0
721         __be64 dma0ErrorLog1;             // nDC8
722         __be64 dma1ErrorStatus;           // nE00
723         __be64 dma1FirstErrorStatus;      // nE08
724         __be64 dma1ErrorLog0;             // nE40
725         __be64 dma1ErrorLog1;             // nE48
726         __be64 pestA[OPAL_P7IOC_NUM_PEST_REGS];
727         __be64 pestB[OPAL_P7IOC_NUM_PEST_REGS];
728 };
729
730 struct OpalIoPhb3ErrorData {
731         struct OpalIoPhbErrorCommon common;
732
733         __be32 brdgCtl;
734
735         /* PHB3 UTL regs */
736         __be32 portStatusReg;
737         __be32 rootCmplxStatus;
738         __be32 busAgentStatus;
739
740         /* PHB3 cfg regs */
741         __be32 deviceStatus;
742         __be32 slotStatus;
743         __be32 linkStatus;
744         __be32 devCmdStatus;
745         __be32 devSecStatus;
746
747         /* cfg AER regs */
748         __be32 rootErrorStatus;
749         __be32 uncorrErrorStatus;
750         __be32 corrErrorStatus;
751         __be32 tlpHdr1;
752         __be32 tlpHdr2;
753         __be32 tlpHdr3;
754         __be32 tlpHdr4;
755         __be32 sourceId;
756
757         __be32 rsv3;
758
759         /* Record data about the call to allocate a buffer */
760         __be64 errorClass;
761         __be64 correlator;
762
763         __be64 nFir;                    /* 000 */
764         __be64 nFirMask;                /* 003 */
765         __be64 nFirWOF;         /* 008 */
766
767         /* PHB3 MMIO Error Regs */
768         __be64 phbPlssr;                /* 120 */
769         __be64 phbCsr;          /* 110 */
770         __be64 lemFir;          /* C00 */
771         __be64 lemErrorMask;            /* C18 */
772         __be64 lemWOF;          /* C40 */
773         __be64 phbErrorStatus;  /* C80 */
774         __be64 phbFirstErrorStatus;     /* C88 */
775         __be64 phbErrorLog0;            /* CC0 */
776         __be64 phbErrorLog1;            /* CC8 */
777         __be64 mmioErrorStatus; /* D00 */
778         __be64 mmioFirstErrorStatus;    /* D08 */
779         __be64 mmioErrorLog0;           /* D40 */
780         __be64 mmioErrorLog1;           /* D48 */
781         __be64 dma0ErrorStatus; /* D80 */
782         __be64 dma0FirstErrorStatus;    /* D88 */
783         __be64 dma0ErrorLog0;           /* DC0 */
784         __be64 dma0ErrorLog1;           /* DC8 */
785         __be64 dma1ErrorStatus; /* E00 */
786         __be64 dma1FirstErrorStatus;    /* E08 */
787         __be64 dma1ErrorLog0;           /* E40 */
788         __be64 dma1ErrorLog1;           /* E48 */
789         __be64 pestA[OPAL_PHB3_NUM_PEST_REGS];
790         __be64 pestB[OPAL_PHB3_NUM_PEST_REGS];
791 };
792
793 enum {
794         OPAL_REINIT_CPUS_HILE_BE        = (1 << 0),
795         OPAL_REINIT_CPUS_HILE_LE        = (1 << 1),
796 };
797
798 typedef struct oppanel_line {
799         const char *    line;
800         uint64_t        line_len;
801 } oppanel_line_t;
802
803 /* /sys/firmware/opal */
804 extern struct kobject *opal_kobj;
805
806 /* /ibm,opal */
807 extern struct device_node *opal_node;
808
809 /* API functions */
810 int64_t opal_invalid_call(void);
811 int64_t opal_console_write(int64_t term_number, __be64 *length,
812                            const uint8_t *buffer);
813 int64_t opal_console_read(int64_t term_number, __be64 *length,
814                           uint8_t *buffer);
815 int64_t opal_console_write_buffer_space(int64_t term_number,
816                                         __be64 *length);
817 int64_t opal_rtc_read(__be32 *year_month_day,
818                       __be64 *hour_minute_second_millisecond);
819 int64_t opal_rtc_write(uint32_t year_month_day,
820                        uint64_t hour_minute_second_millisecond);
821 int64_t opal_cec_power_down(uint64_t request);
822 int64_t opal_cec_reboot(void);
823 int64_t opal_read_nvram(uint64_t buffer, uint64_t size, uint64_t offset);
824 int64_t opal_write_nvram(uint64_t buffer, uint64_t size, uint64_t offset);
825 int64_t opal_handle_interrupt(uint64_t isn, __be64 *outstanding_event_mask);
826 int64_t opal_poll_events(__be64 *outstanding_event_mask);
827 int64_t opal_pci_set_hub_tce_memory(uint64_t hub_id, uint64_t tce_mem_addr,
828                                     uint64_t tce_mem_size);
829 int64_t opal_pci_set_phb_tce_memory(uint64_t phb_id, uint64_t tce_mem_addr,
830                                     uint64_t tce_mem_size);
831 int64_t opal_pci_config_read_byte(uint64_t phb_id, uint64_t bus_dev_func,
832                                   uint64_t offset, uint8_t *data);
833 int64_t opal_pci_config_read_half_word(uint64_t phb_id, uint64_t bus_dev_func,
834                                        uint64_t offset, __be16 *data);
835 int64_t opal_pci_config_read_word(uint64_t phb_id, uint64_t bus_dev_func,
836                                   uint64_t offset, __be32 *data);
837 int64_t opal_pci_config_write_byte(uint64_t phb_id, uint64_t bus_dev_func,
838                                    uint64_t offset, uint8_t data);
839 int64_t opal_pci_config_write_half_word(uint64_t phb_id, uint64_t bus_dev_func,
840                                         uint64_t offset, uint16_t data);
841 int64_t opal_pci_config_write_word(uint64_t phb_id, uint64_t bus_dev_func,
842                                    uint64_t offset, uint32_t data);
843 int64_t opal_set_xive(uint32_t isn, uint16_t server, uint8_t priority);
844 int64_t opal_get_xive(uint32_t isn, __be16 *server, uint8_t *priority);
845 int64_t opal_register_exception_handler(uint64_t opal_exception,
846                                         uint64_t handler_address,
847                                         uint64_t glue_cache_line);
848 int64_t opal_pci_eeh_freeze_status(uint64_t phb_id, uint64_t pe_number,
849                                    uint8_t *freeze_state,
850                                    __be16 *pci_error_type,
851                                    __be64 *phb_status);
852 int64_t opal_pci_eeh_freeze_clear(uint64_t phb_id, uint64_t pe_number,
853                                   uint64_t eeh_action_token);
854 int64_t opal_pci_eeh_freeze_set(uint64_t phb_id, uint64_t pe_number,
855                                 uint64_t eeh_action_token);
856 int64_t opal_pci_err_inject(uint64_t phb_id, uint32_t pe_no, uint32_t type,
857                             uint32_t func, uint64_t addr, uint64_t mask);
858 int64_t opal_pci_shpc(uint64_t phb_id, uint64_t shpc_action, uint8_t *state);
859
860
861
862 int64_t opal_pci_phb_mmio_enable(uint64_t phb_id, uint16_t window_type,
863                                  uint16_t window_num, uint16_t enable);
864 int64_t opal_pci_set_phb_mem_window(uint64_t phb_id, uint16_t window_type,
865                                     uint16_t window_num,
866                                     uint64_t starting_real_address,
867                                     uint64_t starting_pci_address,
868                                     uint64_t size);
869 int64_t opal_pci_map_pe_mmio_window(uint64_t phb_id, uint16_t pe_number,
870                                     uint16_t window_type, uint16_t window_num,
871                                     uint16_t segment_num);
872 int64_t opal_pci_set_phb_table_memory(uint64_t phb_id, uint64_t rtt_addr,
873                                       uint64_t ivt_addr, uint64_t ivt_len,
874                                       uint64_t reject_array_addr,
875                                       uint64_t peltv_addr);
876 int64_t opal_pci_set_pe(uint64_t phb_id, uint64_t pe_number, uint64_t bus_dev_func,
877                         uint8_t bus_compare, uint8_t dev_compare, uint8_t func_compare,
878                         uint8_t pe_action);
879 int64_t opal_pci_set_peltv(uint64_t phb_id, uint32_t parent_pe, uint32_t child_pe,
880                            uint8_t state);
881 int64_t opal_pci_set_mve(uint64_t phb_id, uint32_t mve_number, uint32_t pe_number);
882 int64_t opal_pci_set_mve_enable(uint64_t phb_id, uint32_t mve_number,
883                                 uint32_t state);
884 int64_t opal_pci_get_xive_reissue(uint64_t phb_id, uint32_t xive_number,
885                                   uint8_t *p_bit, uint8_t *q_bit);
886 int64_t opal_pci_set_xive_reissue(uint64_t phb_id, uint32_t xive_number,
887                                   uint8_t p_bit, uint8_t q_bit);
888 int64_t opal_pci_msi_eoi(uint64_t phb_id, uint32_t hw_irq);
889 int64_t opal_pci_set_xive_pe(uint64_t phb_id, uint32_t pe_number,
890                              uint32_t xive_num);
891 int64_t opal_get_xive_source(uint64_t phb_id, uint32_t xive_num,
892                              __be32 *interrupt_source_number);
893 int64_t opal_get_msi_32(uint64_t phb_id, uint32_t mve_number, uint32_t xive_num,
894                         uint8_t msi_range, __be32 *msi_address,
895                         __be32 *message_data);
896 int64_t opal_get_msi_64(uint64_t phb_id, uint32_t mve_number,
897                         uint32_t xive_num, uint8_t msi_range,
898                         __be64 *msi_address, __be32 *message_data);
899 int64_t opal_start_cpu(uint64_t thread_number, uint64_t start_address);
900 int64_t opal_query_cpu_status(uint64_t thread_number, uint8_t *thread_status);
901 int64_t opal_write_oppanel(oppanel_line_t *lines, uint64_t num_lines);
902 int64_t opal_pci_map_pe_dma_window(uint64_t phb_id, uint16_t pe_number, uint16_t window_id,
903                                    uint16_t tce_levels, uint64_t tce_table_addr,
904                                    uint64_t tce_table_size, uint64_t tce_page_size);
905 int64_t opal_pci_map_pe_dma_window_real(uint64_t phb_id, uint16_t pe_number,
906                                         uint16_t dma_window_number, uint64_t pci_start_addr,
907                                         uint64_t pci_mem_size);
908 int64_t opal_pci_reset(uint64_t phb_id, uint8_t reset_scope, uint8_t assert_state);
909
910 int64_t opal_pci_get_hub_diag_data(uint64_t hub_id, void *diag_buffer,
911                                    uint64_t diag_buffer_len);
912 int64_t opal_pci_get_phb_diag_data(uint64_t phb_id, void *diag_buffer,
913                                    uint64_t diag_buffer_len);
914 int64_t opal_pci_get_phb_diag_data2(uint64_t phb_id, void *diag_buffer,
915                                     uint64_t diag_buffer_len);
916 int64_t opal_pci_fence_phb(uint64_t phb_id);
917 int64_t opal_pci_reinit(uint64_t phb_id, uint64_t reinit_scope, uint64_t data);
918 int64_t opal_pci_mask_pe_error(uint64_t phb_id, uint16_t pe_number, uint8_t error_type, uint8_t mask_action);
919 int64_t opal_set_slot_led_status(uint64_t phb_id, uint64_t slot_id, uint8_t led_type, uint8_t led_action);
920 int64_t opal_get_epow_status(__be64 *status);
921 int64_t opal_set_system_attention_led(uint8_t led_action);
922 int64_t opal_pci_next_error(uint64_t phb_id, __be64 *first_frozen_pe,
923                             __be16 *pci_error_type, __be16 *severity);
924 int64_t opal_pci_poll(uint64_t phb_id);
925 int64_t opal_return_cpu(void);
926 int64_t opal_check_token(uint64_t token);
927 int64_t opal_reinit_cpus(uint64_t flags);
928
929 int64_t opal_xscom_read(uint32_t gcid, uint64_t pcb_addr, __be64 *val);
930 int64_t opal_xscom_write(uint32_t gcid, uint64_t pcb_addr, uint64_t val);
931
932 int64_t opal_lpc_write(uint32_t chip_id, enum OpalLPCAddressType addr_type,
933                        uint32_t addr, uint32_t data, uint32_t sz);
934 int64_t opal_lpc_read(uint32_t chip_id, enum OpalLPCAddressType addr_type,
935                       uint32_t addr, __be32 *data, uint32_t sz);
936
937 int64_t opal_read_elog(uint64_t buffer, uint64_t size, uint64_t log_id);
938 int64_t opal_get_elog_size(__be64 *log_id, __be64 *size, __be64 *elog_type);
939 int64_t opal_write_elog(uint64_t buffer, uint64_t size, uint64_t offset);
940 int64_t opal_send_ack_elog(uint64_t log_id);
941 void opal_resend_pending_logs(void);
942
943 int64_t opal_validate_flash(uint64_t buffer, uint32_t *size, uint32_t *result);
944 int64_t opal_manage_flash(uint8_t op);
945 int64_t opal_update_flash(uint64_t blk_list);
946 int64_t opal_dump_init(uint8_t dump_type);
947 int64_t opal_dump_info(__be32 *dump_id, __be32 *dump_size);
948 int64_t opal_dump_info2(__be32 *dump_id, __be32 *dump_size, __be32 *dump_type);
949 int64_t opal_dump_read(uint32_t dump_id, uint64_t buffer);
950 int64_t opal_dump_ack(uint32_t dump_id);
951 int64_t opal_dump_resend_notification(void);
952
953 int64_t opal_get_msg(uint64_t buffer, uint64_t size);
954 int64_t opal_check_completion(uint64_t buffer, uint64_t size, uint64_t token);
955 int64_t opal_sync_host_reboot(void);
956 int64_t opal_get_param(uint64_t token, uint32_t param_id, uint64_t buffer,
957                 uint64_t length);
958 int64_t opal_set_param(uint64_t token, uint32_t param_id, uint64_t buffer,
959                 uint64_t length);
960 int64_t opal_sensor_read(uint32_t sensor_hndl, int token, __be32 *sensor_data);
961 int64_t opal_handle_hmi(void);
962 int64_t opal_register_dump_region(uint32_t id, uint64_t start, uint64_t end);
963 int64_t opal_unregister_dump_region(uint32_t id);
964
965 /* Internal functions */
966 extern int early_init_dt_scan_opal(unsigned long node, const char *uname,
967                                    int depth, void *data);
968 extern int early_init_dt_scan_recoverable_ranges(unsigned long node,
969                                  const char *uname, int depth, void *data);
970
971 extern int opal_get_chars(uint32_t vtermno, char *buf, int count);
972 extern int opal_put_chars(uint32_t vtermno, const char *buf, int total_len);
973
974 extern void hvc_opal_init_early(void);
975
976 extern int opal_notifier_register(struct notifier_block *nb);
977 extern int opal_notifier_unregister(struct notifier_block *nb);
978
979 extern int opal_message_notifier_register(enum OpalMessageType msg_type,
980                                                 struct notifier_block *nb);
981 extern void opal_notifier_enable(void);
982 extern void opal_notifier_disable(void);
983 extern void opal_notifier_update_evt(uint64_t evt_mask, uint64_t evt_val);
984
985 extern int __opal_async_get_token(void);
986 extern int opal_async_get_token_interruptible(void);
987 extern int __opal_async_release_token(int token);
988 extern int opal_async_release_token(int token);
989 extern int opal_async_wait_response(uint64_t token, struct opal_msg *msg);
990 extern int opal_get_sensor_data(u32 sensor_hndl, u32 *sensor_data);
991
992 struct rtc_time;
993 extern int opal_set_rtc_time(struct rtc_time *tm);
994 extern void opal_get_rtc_time(struct rtc_time *tm);
995 extern unsigned long opal_get_boot_time(void);
996 extern void opal_nvram_init(void);
997 extern void opal_flash_init(void);
998 extern void opal_flash_term_callback(void);
999 extern int opal_elog_init(void);
1000 extern void opal_platform_dump_init(void);
1001 extern void opal_sys_param_init(void);
1002 extern void opal_msglog_init(void);
1003
1004 extern int opal_machine_check(struct pt_regs *regs);
1005 extern bool opal_mce_check_early_recovery(struct pt_regs *regs);
1006 extern int opal_hmi_exception_early(struct pt_regs *regs);
1007 extern int opal_handle_hmi_exception(struct pt_regs *regs);
1008
1009 extern void opal_shutdown(void);
1010 extern int opal_resync_timebase(void);
1011
1012 extern void opal_lpc_init(void);
1013
1014 struct opal_sg_list *opal_vmalloc_to_sg_list(void *vmalloc_addr,
1015                                              unsigned long vmalloc_size);
1016 void opal_free_sg_list(struct opal_sg_list *sg);
1017
1018 /*
1019  * Dump region ID range usable by the OS
1020  */
1021 #define OPAL_DUMP_REGION_HOST_START             0x80
1022 #define OPAL_DUMP_REGION_LOG_BUF                0x80
1023 #define OPAL_DUMP_REGION_HOST_END               0xFF
1024
1025 #endif /* __ASSEMBLY__ */
1026
1027 #endif /* __OPAL_H */