12874c5fdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */ 2b8b572e1SStephen Rothwell #ifndef _POWERPC_RTAS_H 3b8b572e1SStephen Rothwell #define _POWERPC_RTAS_H 4b8b572e1SStephen Rothwell #ifdef __KERNEL__ 5b8b572e1SStephen Rothwell 6b8b572e1SStephen Rothwell #include <linux/spinlock.h> 7b8b572e1SStephen Rothwell #include <asm/page.h> 8783a015bSLeonardo Bras #include <asm/rtas-types.h> 9e4a9616cSHari Bathini #include <linux/time.h> 108dce6b22STyrel Datwyler #include <linux/cpumask.h> 11b8b572e1SStephen Rothwell 12b8b572e1SStephen Rothwell /* 13b8b572e1SStephen Rothwell * Definitions for talking to the RTAS on CHRP machines. 14b8b572e1SStephen Rothwell * 15b8b572e1SStephen Rothwell * Copyright (C) 2001 Peter Bergner 16b8b572e1SStephen Rothwell * Copyright (C) 2001 PPC 64 Team, IBM Corp 17b8b572e1SStephen Rothwell */ 18b8b572e1SStephen Rothwell 19*8252b882SNathan Lynch enum rtas_function_index { 20*8252b882SNathan Lynch RTAS_FNIDX__CHECK_EXCEPTION, 21*8252b882SNathan Lynch RTAS_FNIDX__DISPLAY_CHARACTER, 22*8252b882SNathan Lynch RTAS_FNIDX__EVENT_SCAN, 23*8252b882SNathan Lynch RTAS_FNIDX__FREEZE_TIME_BASE, 24*8252b882SNathan Lynch RTAS_FNIDX__GET_POWER_LEVEL, 25*8252b882SNathan Lynch RTAS_FNIDX__GET_SENSOR_STATE, 26*8252b882SNathan Lynch RTAS_FNIDX__GET_TERM_CHAR, 27*8252b882SNathan Lynch RTAS_FNIDX__GET_TIME_OF_DAY, 28*8252b882SNathan Lynch RTAS_FNIDX__IBM_ACTIVATE_FIRMWARE, 29*8252b882SNathan Lynch RTAS_FNIDX__IBM_CBE_START_PTCAL, 30*8252b882SNathan Lynch RTAS_FNIDX__IBM_CBE_STOP_PTCAL, 31*8252b882SNathan Lynch RTAS_FNIDX__IBM_CHANGE_MSI, 32*8252b882SNathan Lynch RTAS_FNIDX__IBM_CLOSE_ERRINJCT, 33*8252b882SNathan Lynch RTAS_FNIDX__IBM_CONFIGURE_BRIDGE, 34*8252b882SNathan Lynch RTAS_FNIDX__IBM_CONFIGURE_CONNECTOR, 35*8252b882SNathan Lynch RTAS_FNIDX__IBM_CONFIGURE_KERNEL_DUMP, 36*8252b882SNathan Lynch RTAS_FNIDX__IBM_CONFIGURE_PE, 37*8252b882SNathan Lynch RTAS_FNIDX__IBM_CREATE_PE_DMA_WINDOW, 38*8252b882SNathan Lynch RTAS_FNIDX__IBM_DISPLAY_MESSAGE, 39*8252b882SNathan Lynch RTAS_FNIDX__IBM_ERRINJCT, 40*8252b882SNathan Lynch RTAS_FNIDX__IBM_EXTI2C, 41*8252b882SNathan Lynch RTAS_FNIDX__IBM_GET_CONFIG_ADDR_INFO, 42*8252b882SNathan Lynch RTAS_FNIDX__IBM_GET_CONFIG_ADDR_INFO2, 43*8252b882SNathan Lynch RTAS_FNIDX__IBM_GET_DYNAMIC_SENSOR_STATE, 44*8252b882SNathan Lynch RTAS_FNIDX__IBM_GET_INDICES, 45*8252b882SNathan Lynch RTAS_FNIDX__IBM_GET_RIO_TOPOLOGY, 46*8252b882SNathan Lynch RTAS_FNIDX__IBM_GET_SYSTEM_PARAMETER, 47*8252b882SNathan Lynch RTAS_FNIDX__IBM_GET_VPD, 48*8252b882SNathan Lynch RTAS_FNIDX__IBM_GET_XIVE, 49*8252b882SNathan Lynch RTAS_FNIDX__IBM_INT_OFF, 50*8252b882SNathan Lynch RTAS_FNIDX__IBM_INT_ON, 51*8252b882SNathan Lynch RTAS_FNIDX__IBM_IO_QUIESCE_ACK, 52*8252b882SNathan Lynch RTAS_FNIDX__IBM_LPAR_PERFTOOLS, 53*8252b882SNathan Lynch RTAS_FNIDX__IBM_MANAGE_FLASH_IMAGE, 54*8252b882SNathan Lynch RTAS_FNIDX__IBM_MANAGE_STORAGE_PRESERVATION, 55*8252b882SNathan Lynch RTAS_FNIDX__IBM_NMI_INTERLOCK, 56*8252b882SNathan Lynch RTAS_FNIDX__IBM_NMI_REGISTER, 57*8252b882SNathan Lynch RTAS_FNIDX__IBM_OPEN_ERRINJCT, 58*8252b882SNathan Lynch RTAS_FNIDX__IBM_OPEN_SRIOV_ALLOW_UNFREEZE, 59*8252b882SNathan Lynch RTAS_FNIDX__IBM_OPEN_SRIOV_MAP_PE_NUMBER, 60*8252b882SNathan Lynch RTAS_FNIDX__IBM_OS_TERM, 61*8252b882SNathan Lynch RTAS_FNIDX__IBM_PARTNER_CONTROL, 62*8252b882SNathan Lynch RTAS_FNIDX__IBM_PHYSICAL_ATTESTATION, 63*8252b882SNathan Lynch RTAS_FNIDX__IBM_PLATFORM_DUMP, 64*8252b882SNathan Lynch RTAS_FNIDX__IBM_POWER_OFF_UPS, 65*8252b882SNathan Lynch RTAS_FNIDX__IBM_QUERY_INTERRUPT_SOURCE_NUMBER, 66*8252b882SNathan Lynch RTAS_FNIDX__IBM_QUERY_PE_DMA_WINDOW, 67*8252b882SNathan Lynch RTAS_FNIDX__IBM_READ_PCI_CONFIG, 68*8252b882SNathan Lynch RTAS_FNIDX__IBM_READ_SLOT_RESET_STATE, 69*8252b882SNathan Lynch RTAS_FNIDX__IBM_READ_SLOT_RESET_STATE2, 70*8252b882SNathan Lynch RTAS_FNIDX__IBM_REMOVE_PE_DMA_WINDOW, 71*8252b882SNathan Lynch RTAS_FNIDX__IBM_RESET_PE_DMA_WINDOWS, 72*8252b882SNathan Lynch RTAS_FNIDX__IBM_SCAN_LOG_DUMP, 73*8252b882SNathan Lynch RTAS_FNIDX__IBM_SET_DYNAMIC_INDICATOR, 74*8252b882SNathan Lynch RTAS_FNIDX__IBM_SET_EEH_OPTION, 75*8252b882SNathan Lynch RTAS_FNIDX__IBM_SET_SLOT_RESET, 76*8252b882SNathan Lynch RTAS_FNIDX__IBM_SET_SYSTEM_PARAMETER, 77*8252b882SNathan Lynch RTAS_FNIDX__IBM_SET_XIVE, 78*8252b882SNathan Lynch RTAS_FNIDX__IBM_SLOT_ERROR_DETAIL, 79*8252b882SNathan Lynch RTAS_FNIDX__IBM_SUSPEND_ME, 80*8252b882SNathan Lynch RTAS_FNIDX__IBM_TUNE_DMA_PARMS, 81*8252b882SNathan Lynch RTAS_FNIDX__IBM_UPDATE_FLASH_64_AND_REBOOT, 82*8252b882SNathan Lynch RTAS_FNIDX__IBM_UPDATE_NODES, 83*8252b882SNathan Lynch RTAS_FNIDX__IBM_UPDATE_PROPERTIES, 84*8252b882SNathan Lynch RTAS_FNIDX__IBM_VALIDATE_FLASH_IMAGE, 85*8252b882SNathan Lynch RTAS_FNIDX__IBM_WRITE_PCI_CONFIG, 86*8252b882SNathan Lynch RTAS_FNIDX__NVRAM_FETCH, 87*8252b882SNathan Lynch RTAS_FNIDX__NVRAM_STORE, 88*8252b882SNathan Lynch RTAS_FNIDX__POWER_OFF, 89*8252b882SNathan Lynch RTAS_FNIDX__PUT_TERM_CHAR, 90*8252b882SNathan Lynch RTAS_FNIDX__QUERY_CPU_STOPPED_STATE, 91*8252b882SNathan Lynch RTAS_FNIDX__READ_PCI_CONFIG, 92*8252b882SNathan Lynch RTAS_FNIDX__RTAS_LAST_ERROR, 93*8252b882SNathan Lynch RTAS_FNIDX__SET_INDICATOR, 94*8252b882SNathan Lynch RTAS_FNIDX__SET_POWER_LEVEL, 95*8252b882SNathan Lynch RTAS_FNIDX__SET_TIME_FOR_POWER_ON, 96*8252b882SNathan Lynch RTAS_FNIDX__SET_TIME_OF_DAY, 97*8252b882SNathan Lynch RTAS_FNIDX__START_CPU, 98*8252b882SNathan Lynch RTAS_FNIDX__STOP_SELF, 99*8252b882SNathan Lynch RTAS_FNIDX__SYSTEM_REBOOT, 100*8252b882SNathan Lynch RTAS_FNIDX__THAW_TIME_BASE, 101*8252b882SNathan Lynch RTAS_FNIDX__WRITE_PCI_CONFIG, 102*8252b882SNathan Lynch }; 103*8252b882SNathan Lynch 104b8b572e1SStephen Rothwell #define RTAS_UNKNOWN_SERVICE (-1) 105fe333321SIngo Molnar #define RTAS_INSTANTIATE_MAX (1ULL<<30) /* Don't instantiate rtas at/above this value */ 106b8b572e1SStephen Rothwell 107e5d56763SNathan Lynch /* Memory set aside for sys_rtas to use with calls that need a work area. */ 108e5d56763SNathan Lynch #define RTAS_USER_REGION_SIZE (64 * 1024) 109b8b572e1SStephen Rothwell 110b8b572e1SStephen Rothwell /* RTAS return status codes */ 111b8b572e1SStephen Rothwell #define RTAS_BUSY -2 /* RTAS Busy */ 112b8b572e1SStephen Rothwell #define RTAS_EXTENDED_DELAY_MIN 9900 113b8b572e1SStephen Rothwell #define RTAS_EXTENDED_DELAY_MAX 9905 114b8b572e1SStephen Rothwell 115970e453eSNathan Lynch /* statuses specific to ibm,suspend-me */ 116970e453eSNathan Lynch #define RTAS_SUSPEND_ABORTED 9000 /* Suspension aborted */ 117970e453eSNathan Lynch #define RTAS_NOT_SUSPENDABLE -9004 /* Partition not suspendable */ 118970e453eSNathan Lynch #define RTAS_THREADS_ACTIVE -9005 /* Multiple processor threads active */ 119970e453eSNathan Lynch #define RTAS_OUTSTANDING_COPROC -9006 /* Outstanding coprocessor operations */ 120970e453eSNathan Lynch 121b8b572e1SStephen Rothwell /* RTAS event classes */ 122b8b572e1SStephen Rothwell #define RTAS_INTERNAL_ERROR 0x80000000 /* set bit 0 */ 123b8b572e1SStephen Rothwell #define RTAS_EPOW_WARNING 0x40000000 /* set bit 1 */ 124b8b572e1SStephen Rothwell #define RTAS_HOTPLUG_EVENTS 0x10000000 /* set bit 3 */ 1254a9f9506SAnton Blanchard #define RTAS_IO_EVENTS 0x08000000 /* set bit 4 */ 1264a9f9506SAnton Blanchard #define RTAS_EVENT_SCAN_ALL_EVENTS 0xffffffff 127b8b572e1SStephen Rothwell 128b8b572e1SStephen Rothwell /* RTAS event severity */ 129b8b572e1SStephen Rothwell #define RTAS_SEVERITY_FATAL 0x5 130b8b572e1SStephen Rothwell #define RTAS_SEVERITY_ERROR 0x4 131b8b572e1SStephen Rothwell #define RTAS_SEVERITY_ERROR_SYNC 0x3 132b8b572e1SStephen Rothwell #define RTAS_SEVERITY_WARNING 0x2 133b8b572e1SStephen Rothwell #define RTAS_SEVERITY_EVENT 0x1 134b8b572e1SStephen Rothwell #define RTAS_SEVERITY_NO_ERROR 0x0 135b8b572e1SStephen Rothwell 136b8b572e1SStephen Rothwell /* RTAS event disposition */ 137b8b572e1SStephen Rothwell #define RTAS_DISP_FULLY_RECOVERED 0x0 138b8b572e1SStephen Rothwell #define RTAS_DISP_LIMITED_RECOVERY 0x1 139b8b572e1SStephen Rothwell #define RTAS_DISP_NOT_RECOVERED 0x2 140b8b572e1SStephen Rothwell 141b8b572e1SStephen Rothwell /* RTAS event initiator */ 142b8b572e1SStephen Rothwell #define RTAS_INITIATOR_UNKNOWN 0x0 143b8b572e1SStephen Rothwell #define RTAS_INITIATOR_CPU 0x1 144b8b572e1SStephen Rothwell #define RTAS_INITIATOR_PCI 0x2 145b8b572e1SStephen Rothwell #define RTAS_INITIATOR_ISA 0x3 146b8b572e1SStephen Rothwell #define RTAS_INITIATOR_MEMORY 0x4 147b8b572e1SStephen Rothwell #define RTAS_INITIATOR_POWERMGM 0x5 148b8b572e1SStephen Rothwell 149b8b572e1SStephen Rothwell /* RTAS event target */ 150b8b572e1SStephen Rothwell #define RTAS_TARGET_UNKNOWN 0x0 151b8b572e1SStephen Rothwell #define RTAS_TARGET_CPU 0x1 152b8b572e1SStephen Rothwell #define RTAS_TARGET_PCI 0x2 153b8b572e1SStephen Rothwell #define RTAS_TARGET_ISA 0x3 154b8b572e1SStephen Rothwell #define RTAS_TARGET_MEMORY 0x4 155b8b572e1SStephen Rothwell #define RTAS_TARGET_POWERMGM 0x5 156b8b572e1SStephen Rothwell 157b8b572e1SStephen Rothwell /* RTAS event type */ 158b8b572e1SStephen Rothwell #define RTAS_TYPE_RETRY 0x01 159b8b572e1SStephen Rothwell #define RTAS_TYPE_TCE_ERR 0x02 160b8b572e1SStephen Rothwell #define RTAS_TYPE_INTERN_DEV_FAIL 0x03 161b8b572e1SStephen Rothwell #define RTAS_TYPE_TIMEOUT 0x04 162b8b572e1SStephen Rothwell #define RTAS_TYPE_DATA_PARITY 0x05 163b8b572e1SStephen Rothwell #define RTAS_TYPE_ADDR_PARITY 0x06 164b8b572e1SStephen Rothwell #define RTAS_TYPE_CACHE_PARITY 0x07 165b8b572e1SStephen Rothwell #define RTAS_TYPE_ADDR_INVALID 0x08 166b8b572e1SStephen Rothwell #define RTAS_TYPE_ECC_UNCORR 0x09 167b8b572e1SStephen Rothwell #define RTAS_TYPE_ECC_CORR 0x0a 168b8b572e1SStephen Rothwell #define RTAS_TYPE_EPOW 0x40 169b8b572e1SStephen Rothwell #define RTAS_TYPE_PLATFORM 0xE0 170b8b572e1SStephen Rothwell #define RTAS_TYPE_IO 0xE1 171b8b572e1SStephen Rothwell #define RTAS_TYPE_INFO 0xE2 172b8b572e1SStephen Rothwell #define RTAS_TYPE_DEALLOC 0xE3 173b8b572e1SStephen Rothwell #define RTAS_TYPE_DUMP 0xE4 1744c5d87dbSOliver O'Halloran #define RTAS_TYPE_HOTPLUG 0xE5 175b8b572e1SStephen Rothwell /* I don't add PowerMGM events right now, this is a different topic */ 176b8b572e1SStephen Rothwell #define RTAS_TYPE_PMGM_POWER_SW_ON 0x60 177b8b572e1SStephen Rothwell #define RTAS_TYPE_PMGM_POWER_SW_OFF 0x61 178b8b572e1SStephen Rothwell #define RTAS_TYPE_PMGM_LID_OPEN 0x62 179b8b572e1SStephen Rothwell #define RTAS_TYPE_PMGM_LID_CLOSE 0x63 180b8b572e1SStephen Rothwell #define RTAS_TYPE_PMGM_SLEEP_BTN 0x64 181b8b572e1SStephen Rothwell #define RTAS_TYPE_PMGM_WAKE_BTN 0x65 182b8b572e1SStephen Rothwell #define RTAS_TYPE_PMGM_BATTERY_WARN 0x66 183b8b572e1SStephen Rothwell #define RTAS_TYPE_PMGM_BATTERY_CRIT 0x67 184b8b572e1SStephen Rothwell #define RTAS_TYPE_PMGM_SWITCH_TO_BAT 0x68 185b8b572e1SStephen Rothwell #define RTAS_TYPE_PMGM_SWITCH_TO_AC 0x69 186b8b572e1SStephen Rothwell #define RTAS_TYPE_PMGM_KBD_OR_MOUSE 0x6a 187b8b572e1SStephen Rothwell #define RTAS_TYPE_PMGM_ENCLOS_OPEN 0x6b 188b8b572e1SStephen Rothwell #define RTAS_TYPE_PMGM_ENCLOS_CLOSED 0x6c 189b8b572e1SStephen Rothwell #define RTAS_TYPE_PMGM_RING_INDICATE 0x6d 190b8b572e1SStephen Rothwell #define RTAS_TYPE_PMGM_LAN_ATTENTION 0x6e 191b8b572e1SStephen Rothwell #define RTAS_TYPE_PMGM_TIME_ALARM 0x6f 192b8b572e1SStephen Rothwell #define RTAS_TYPE_PMGM_CONFIG_CHANGE 0x70 193b8b572e1SStephen Rothwell #define RTAS_TYPE_PMGM_SERVICE_PROC 0x71 19449c68a85SJesse Larrew /* Platform Resource Reassignment Notification */ 19549c68a85SJesse Larrew #define RTAS_TYPE_PRRN 0xA0 196b8b572e1SStephen Rothwell 197b08e281bSMark Nelson /* RTAS check-exception vector offset */ 198b08e281bSMark Nelson #define RTAS_VECTOR_EXTERNAL_INTERRUPT 0x500 199b08e281bSMark Nelson 200a08a53eaSGreg Kurz static inline uint8_t rtas_error_severity(const struct rtas_error_log *elog) 201a08a53eaSGreg Kurz { 202a08a53eaSGreg Kurz return (elog->byte1 & 0xE0) >> 5; 203a08a53eaSGreg Kurz } 204a08a53eaSGreg Kurz 205a08a53eaSGreg Kurz static inline uint8_t rtas_error_disposition(const struct rtas_error_log *elog) 206a08a53eaSGreg Kurz { 207a08a53eaSGreg Kurz return (elog->byte1 & 0x18) >> 3; 208a08a53eaSGreg Kurz } 209a08a53eaSGreg Kurz 21004fce21cSMahesh Salgaonkar static inline 21104fce21cSMahesh Salgaonkar void rtas_set_disposition_recovered(struct rtas_error_log *elog) 21204fce21cSMahesh Salgaonkar { 21304fce21cSMahesh Salgaonkar elog->byte1 &= ~0x18; 21404fce21cSMahesh Salgaonkar elog->byte1 |= (RTAS_DISP_FULLY_RECOVERED << 3); 21504fce21cSMahesh Salgaonkar } 21604fce21cSMahesh Salgaonkar 217a08a53eaSGreg Kurz static inline uint8_t rtas_error_extended(const struct rtas_error_log *elog) 218a08a53eaSGreg Kurz { 219a08a53eaSGreg Kurz return (elog->byte1 & 0x04) >> 2; 220a08a53eaSGreg Kurz } 221a08a53eaSGreg Kurz 2228f0b8056SMahesh Salgaonkar static inline uint8_t rtas_error_initiator(const struct rtas_error_log *elog) 2238f0b8056SMahesh Salgaonkar { 2248f0b8056SMahesh Salgaonkar return (elog->byte2 & 0xf0) >> 4; 2258f0b8056SMahesh Salgaonkar } 2268f0b8056SMahesh Salgaonkar 227a08a53eaSGreg Kurz #define rtas_error_type(x) ((x)->byte3) 228a08a53eaSGreg Kurz 229a08a53eaSGreg Kurz static inline 230a08a53eaSGreg Kurz uint32_t rtas_error_extended_log_length(const struct rtas_error_log *elog) 231a08a53eaSGreg Kurz { 232a08a53eaSGreg Kurz return be32_to_cpu(elog->extended_log_length); 233a08a53eaSGreg Kurz } 234a08a53eaSGreg Kurz 2354cb46380STseng-Hui (Frank) Lin #define RTAS_V6EXT_LOG_FORMAT_EVENT_LOG 14 2364cb46380STseng-Hui (Frank) Lin 2374cb46380STseng-Hui (Frank) Lin #define RTAS_V6EXT_COMPANY_ID_IBM (('I' << 24) | ('B' << 16) | ('M' << 8)) 2384cb46380STseng-Hui (Frank) Lin 239a08a53eaSGreg Kurz static 240a08a53eaSGreg Kurz inline uint8_t rtas_ext_event_log_format(struct rtas_ext_event_log_v6 *ext_log) 241a08a53eaSGreg Kurz { 242a08a53eaSGreg Kurz return ext_log->byte2 & 0x0F; 243a08a53eaSGreg Kurz } 244a08a53eaSGreg Kurz 245a08a53eaSGreg Kurz static 246a08a53eaSGreg Kurz inline uint32_t rtas_ext_event_company_id(struct rtas_ext_event_log_v6 *ext_log) 247a08a53eaSGreg Kurz { 248a08a53eaSGreg Kurz return be32_to_cpu(ext_log->company_id); 249a08a53eaSGreg Kurz } 250a08a53eaSGreg Kurz 2516431f208SAnton Blanchard /* pSeries event log format */ 2526431f208SAnton Blanchard 2536431f208SAnton Blanchard /* Two bytes ASCII section IDs */ 2546431f208SAnton Blanchard #define PSERIES_ELOG_SECT_ID_PRIV_HDR (('P' << 8) | 'H') 2556431f208SAnton Blanchard #define PSERIES_ELOG_SECT_ID_USER_HDR (('U' << 8) | 'H') 2566431f208SAnton Blanchard #define PSERIES_ELOG_SECT_ID_PRIMARY_SRC (('P' << 8) | 'S') 2576431f208SAnton Blanchard #define PSERIES_ELOG_SECT_ID_EXTENDED_UH (('E' << 8) | 'H') 2586431f208SAnton Blanchard #define PSERIES_ELOG_SECT_ID_FAILING_MTMS (('M' << 8) | 'T') 2596431f208SAnton Blanchard #define PSERIES_ELOG_SECT_ID_SECONDARY_SRC (('S' << 8) | 'S') 2606431f208SAnton Blanchard #define PSERIES_ELOG_SECT_ID_DUMP_LOCATOR (('D' << 8) | 'H') 2616431f208SAnton Blanchard #define PSERIES_ELOG_SECT_ID_FW_ERROR (('S' << 8) | 'W') 2626431f208SAnton Blanchard #define PSERIES_ELOG_SECT_ID_IMPACT_PART_ID (('L' << 8) | 'P') 2636431f208SAnton Blanchard #define PSERIES_ELOG_SECT_ID_LOGIC_RESOURCE_ID (('L' << 8) | 'R') 2646431f208SAnton Blanchard #define PSERIES_ELOG_SECT_ID_HMC_ID (('H' << 8) | 'M') 2656431f208SAnton Blanchard #define PSERIES_ELOG_SECT_ID_EPOW (('E' << 8) | 'P') 2666431f208SAnton Blanchard #define PSERIES_ELOG_SECT_ID_IO_EVENT (('I' << 8) | 'E') 2676431f208SAnton Blanchard #define PSERIES_ELOG_SECT_ID_MANUFACT_INFO (('M' << 8) | 'I') 2686431f208SAnton Blanchard #define PSERIES_ELOG_SECT_ID_CALL_HOME (('C' << 8) | 'H') 2696431f208SAnton Blanchard #define PSERIES_ELOG_SECT_ID_USER_DEF (('U' << 8) | 'D') 270366d395cSNathan Fontenot #define PSERIES_ELOG_SECT_ID_HOTPLUG (('H' << 8) | 'P') 27104fce21cSMahesh Salgaonkar #define PSERIES_ELOG_SECT_ID_MCE (('M' << 8) | 'C') 2726431f208SAnton Blanchard 273a08a53eaSGreg Kurz static 274a08a53eaSGreg Kurz inline uint16_t pseries_errorlog_id(struct pseries_errorlog *sect) 275a08a53eaSGreg Kurz { 276a08a53eaSGreg Kurz return be16_to_cpu(sect->id); 277a08a53eaSGreg Kurz } 278a08a53eaSGreg Kurz 279a08a53eaSGreg Kurz static 280a08a53eaSGreg Kurz inline uint16_t pseries_errorlog_length(struct pseries_errorlog *sect) 281a08a53eaSGreg Kurz { 282a08a53eaSGreg Kurz return be16_to_cpu(sect->length); 283a08a53eaSGreg Kurz } 284a08a53eaSGreg Kurz 285366d395cSNathan Fontenot #define PSERIES_HP_ELOG_RESOURCE_CPU 1 286366d395cSNathan Fontenot #define PSERIES_HP_ELOG_RESOURCE_MEM 2 287366d395cSNathan Fontenot #define PSERIES_HP_ELOG_RESOURCE_SLOT 3 288366d395cSNathan Fontenot #define PSERIES_HP_ELOG_RESOURCE_PHB 4 2894c5d87dbSOliver O'Halloran #define PSERIES_HP_ELOG_RESOURCE_PMEM 6 290366d395cSNathan Fontenot 291366d395cSNathan Fontenot #define PSERIES_HP_ELOG_ACTION_ADD 1 292366d395cSNathan Fontenot #define PSERIES_HP_ELOG_ACTION_REMOVE 2 293366d395cSNathan Fontenot 294366d395cSNathan Fontenot #define PSERIES_HP_ELOG_ID_DRC_NAME 1 295366d395cSNathan Fontenot #define PSERIES_HP_ELOG_ID_DRC_INDEX 2 296366d395cSNathan Fontenot #define PSERIES_HP_ELOG_ID_DRC_COUNT 3 297333f7b76SSahil Mehta #define PSERIES_HP_ELOG_ID_DRC_IC 4 298366d395cSNathan Fontenot 2996431f208SAnton Blanchard struct pseries_errorlog *get_pseries_errorlog(struct rtas_error_log *log, 3006431f208SAnton Blanchard uint16_t section_id); 3016431f208SAnton Blanchard 302b8b572e1SStephen Rothwell /* 303b8b572e1SStephen Rothwell * This can be set by the rtas_flash module so that it can get called 304b8b572e1SStephen Rothwell * as the absolutely last thing before the kernel terminates. 305b8b572e1SStephen Rothwell */ 306b8b572e1SStephen Rothwell extern void (*rtas_flash_term_hook)(int); 307b8b572e1SStephen Rothwell 308b8b572e1SStephen Rothwell extern struct rtas_t rtas; 309b8b572e1SStephen Rothwell 310b8b572e1SStephen Rothwell extern int rtas_token(const char *service); 311b8b572e1SStephen Rothwell extern int rtas_service_present(const char *service); 312b8b572e1SStephen Rothwell extern int rtas_call(int token, int, int, int *, ...); 313209eb4e5SMichael Ellerman void rtas_call_unlocked(struct rtas_args *args, int token, int nargs, 314209eb4e5SMichael Ellerman int nret, ...); 31595ec77c0SDaniel Axtens extern void __noreturn rtas_restart(char *cmd); 316b8b572e1SStephen Rothwell extern void rtas_power_off(void); 31795ec77c0SDaniel Axtens extern void __noreturn rtas_halt(void); 318b8b572e1SStephen Rothwell extern void rtas_os_term(char *str); 3195f485a66SNathan Lynch void rtas_activate_firmware(void); 320b8b572e1SStephen Rothwell extern int rtas_get_sensor(int sensor, int index, int *state); 3211c2cb594SThomas Huth extern int rtas_get_sensor_fast(int sensor, int index, int *state); 322b8b572e1SStephen Rothwell extern int rtas_get_power_level(int powerdomain, int *level); 323b8b572e1SStephen Rothwell extern int rtas_set_power_level(int powerdomain, int level, int *setlevel); 324edc72ac4SNathan Lynch extern bool rtas_indicator_present(int token, int *maxindex); 325b8b572e1SStephen Rothwell extern int rtas_set_indicator(int indicator, int index, int new_value); 326b8b572e1SStephen Rothwell extern int rtas_set_indicator_fast(int indicator, int index, int new_value); 327b8b572e1SStephen Rothwell extern void rtas_progress(char *s, unsigned short hex); 328701ba683SNathan Lynch int rtas_ibm_suspend_me(int *fw_status); 329b8b572e1SStephen Rothwell 330b8b572e1SStephen Rothwell struct rtc_time; 3315bfd6435SArnd Bergmann extern time64_t rtas_get_boot_time(void); 332b8b572e1SStephen Rothwell extern void rtas_get_rtc_time(struct rtc_time *rtc_time); 333b8b572e1SStephen Rothwell extern int rtas_set_rtc_time(struct rtc_time *rtc_time); 334b8b572e1SStephen Rothwell 335b8b572e1SStephen Rothwell extern unsigned int rtas_busy_delay_time(int status); 33638f7b706SNathan Lynch bool rtas_busy_delay(int status); 337b8b572e1SStephen Rothwell 338b8b572e1SStephen Rothwell extern int early_init_dt_scan_rtas(unsigned long node, 339b8b572e1SStephen Rothwell const char *uname, int depth, void *data); 340b8b572e1SStephen Rothwell 341b8b572e1SStephen Rothwell extern void pSeries_log_error(char *buf, unsigned int err_type, int fatal); 342b8b572e1SStephen Rothwell 343762ec157SNathan Fontenot #ifdef CONFIG_PPC_PSERIES 344e4a9616cSHari Bathini extern time64_t last_rtas_event; 34578989f0aSHari Bathini extern int clobbering_unread_rtas_event(void); 3466b36ba84SHaren Myneni extern void post_mobility_fixup(void); 3474d756894SNathan Lynch int rtas_syscall_dispatch_ibm_suspend_me(u64 handle); 34878989f0aSHari Bathini #else 34978989f0aSHari Bathini static inline int clobbering_unread_rtas_event(void) { return 0; } 3504d756894SNathan Lynch static inline int rtas_syscall_dispatch_ibm_suspend_me(u64 handle) 3514d756894SNathan Lynch { 3524d756894SNathan Lynch return -EINVAL; 3534d756894SNathan Lynch } 354762ec157SNathan Fontenot #endif 355762ec157SNathan Fontenot 356df17f56dSRavi K. Nittala #ifdef CONFIG_PPC_RTAS_DAEMON 357df17f56dSRavi K. Nittala extern void rtas_cancel_event_scan(void); 358df17f56dSRavi K. Nittala #else 359df17f56dSRavi K. Nittala static inline void rtas_cancel_event_scan(void) { } 360df17f56dSRavi K. Nittala #endif 361df17f56dSRavi K. Nittala 362b8b572e1SStephen Rothwell /* Error types logged. */ 363b8b572e1SStephen Rothwell #define ERR_FLAG_ALREADY_LOGGED 0x0 364b8b572e1SStephen Rothwell #define ERR_FLAG_BOOT 0x1 /* log was pulled from NVRAM on boot */ 365b8b572e1SStephen Rothwell #define ERR_TYPE_RTAS_LOG 0x2 /* from rtas event-scan */ 3666c493685SJim Keniston #define ERR_TYPE_KERNEL_PANIC 0x4 /* from die()/panic() */ 3676c493685SJim Keniston #define ERR_TYPE_KERNEL_PANIC_GZ 0x8 /* ditto, compressed */ 368b8b572e1SStephen Rothwell 369b8b572e1SStephen Rothwell /* All the types and not flags */ 3706c493685SJim Keniston #define ERR_TYPE_MASK \ 3716c493685SJim Keniston (ERR_TYPE_RTAS_LOG | ERR_TYPE_KERNEL_PANIC | ERR_TYPE_KERNEL_PANIC_GZ) 372b8b572e1SStephen Rothwell 373b8b572e1SStephen Rothwell #define RTAS_DEBUG KERN_DEBUG "RTAS: " 374b8b572e1SStephen Rothwell 375b8b572e1SStephen Rothwell #define RTAS_ERROR_LOG_MAX 2048 376b8b572e1SStephen Rothwell 377b8b572e1SStephen Rothwell /* 378b8b572e1SStephen Rothwell * Return the firmware-specified size of the error log buffer 379b8b572e1SStephen Rothwell * for all rtas calls that require an error buffer argument. 380b8b572e1SStephen Rothwell * This includes 'check-exception' and 'rtas-last-error'. 381b8b572e1SStephen Rothwell */ 382b8b572e1SStephen Rothwell extern int rtas_get_error_log_max(void); 383b8b572e1SStephen Rothwell 384b8b572e1SStephen Rothwell /* Event Scan Parameters */ 385b8b572e1SStephen Rothwell #define EVENT_SCAN_ALL_EVENTS 0xf0000000 386b8b572e1SStephen Rothwell #define SURVEILLANCE_TOKEN 9000 387b8b572e1SStephen Rothwell #define LOG_NUMBER 64 /* must be a power of two */ 388b8b572e1SStephen Rothwell #define LOG_NUMBER_MASK (LOG_NUMBER-1) 389b8b572e1SStephen Rothwell 390b8b572e1SStephen Rothwell /* Some RTAS ops require a data buffer and that buffer must be < 4G. 391b8b572e1SStephen Rothwell * Rather than having a memory allocator, just use this buffer 392b8b572e1SStephen Rothwell * (get the lock first), make the RTAS call. Copy the data instead 393b8b572e1SStephen Rothwell * of holding the buffer for long. 394b8b572e1SStephen Rothwell */ 395b8b572e1SStephen Rothwell 396b8b572e1SStephen Rothwell #define RTAS_DATA_BUF_SIZE 4096 397b8b572e1SStephen Rothwell extern spinlock_t rtas_data_buf_lock; 398b8b572e1SStephen Rothwell extern char rtas_data_buf[RTAS_DATA_BUF_SIZE]; 399b8b572e1SStephen Rothwell 400b8b572e1SStephen Rothwell /* RMO buffer reserved for user-space RTAS use */ 401b8b572e1SStephen Rothwell extern unsigned long rtas_rmo_buf; 402b8b572e1SStephen Rothwell 403b8b572e1SStephen Rothwell #define GLOBAL_INTERRUPT_QUEUE 9005 404b8b572e1SStephen Rothwell 405b8b572e1SStephen Rothwell /** 406b8b572e1SStephen Rothwell * rtas_config_addr - Format a busno, devfn and reg for RTAS. 407b8b572e1SStephen Rothwell * @busno: The bus number. 408b8b572e1SStephen Rothwell * @devfn: The device and function number as encoded by PCI_DEVFN(). 409b8b572e1SStephen Rothwell * @reg: The register number. 410b8b572e1SStephen Rothwell * 411b8b572e1SStephen Rothwell * This function encodes the given busno, devfn and register number as 412b8b572e1SStephen Rothwell * required for RTAS calls that take a "config_addr" parameter. 413b8b572e1SStephen Rothwell * See PAPR requirement 7.3.4-1 for more info. 414b8b572e1SStephen Rothwell */ 415b8b572e1SStephen Rothwell static inline u32 rtas_config_addr(int busno, int devfn, int reg) 416b8b572e1SStephen Rothwell { 417b8b572e1SStephen Rothwell return ((reg & 0xf00) << 20) | ((busno & 0xff) << 16) | 418b8b572e1SStephen Rothwell (devfn << 8) | (reg & 0xff); 419b8b572e1SStephen Rothwell } 420b8b572e1SStephen Rothwell 421061d19f2SPaul Gortmaker extern void rtas_give_timebase(void); 422061d19f2SPaul Gortmaker extern void rtas_take_timebase(void); 423c4007a2fSBenjamin Herrenschmidt 4248a3e3d31Ssukadev@linux.vnet.ibm.com #ifdef CONFIG_PPC_RTAS 4258a3e3d31Ssukadev@linux.vnet.ibm.com static inline int page_is_rtas_user_buf(unsigned long pfn) 4268a3e3d31Ssukadev@linux.vnet.ibm.com { 4278a3e3d31Ssukadev@linux.vnet.ibm.com unsigned long paddr = (pfn << PAGE_SHIFT); 428e5d56763SNathan Lynch if (paddr >= rtas_rmo_buf && paddr < (rtas_rmo_buf + RTAS_USER_REGION_SIZE)) 4298a3e3d31Ssukadev@linux.vnet.ibm.com return 1; 4308a3e3d31Ssukadev@linux.vnet.ibm.com return 0; 4318a3e3d31Ssukadev@linux.vnet.ibm.com } 432f459d63eSNathan Fontenot 433f459d63eSNathan Fontenot /* Not the best place to put pSeries_coalesce_init, will be fixed when we 434f459d63eSNathan Fontenot * move some of the rtas suspend-me stuff to pseries */ 435f459d63eSNathan Fontenot extern void pSeries_coalesce_init(void); 436b1923caaSBenjamin Herrenschmidt void rtas_initialize(void); 4378a3e3d31Ssukadev@linux.vnet.ibm.com #else 4388a3e3d31Ssukadev@linux.vnet.ibm.com static inline int page_is_rtas_user_buf(unsigned long pfn) { return 0;} 439f459d63eSNathan Fontenot static inline void pSeries_coalesce_init(void) { } 4406c6fdbb2SChengyang Fan static inline void rtas_initialize(void) { } 4418a3e3d31Ssukadev@linux.vnet.ibm.com #endif 4428a3e3d31Ssukadev@linux.vnet.ibm.com 443ae3a197eSDavid Howells extern int call_rtas(const char *, int, int, unsigned long *, ...); 444ae3a197eSDavid Howells 4458ba21426SKajol Jain #ifdef CONFIG_HV_PERF_CTRS 4468ba21426SKajol Jain void read_24x7_sys_info(void); 4478ba21426SKajol Jain #else 4488ba21426SKajol Jain static inline void read_24x7_sys_info(void) { } 4498ba21426SKajol Jain #endif 4508ba21426SKajol Jain 451b8b572e1SStephen Rothwell #endif /* __KERNEL__ */ 452b8b572e1SStephen Rothwell #endif /* _POWERPC_RTAS_H */ 453