xref: /openbmc/linux/arch/powerpc/include/asm/rtas.h (revision 701ba683)
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 
19b8b572e1SStephen Rothwell #define RTAS_UNKNOWN_SERVICE (-1)
20fe333321SIngo Molnar #define RTAS_INSTANTIATE_MAX (1ULL<<30) /* Don't instantiate rtas at/above this value */
21b8b572e1SStephen Rothwell 
22b8b572e1SStephen Rothwell /* Buffer size for ppc_rtas system call. */
23b8b572e1SStephen Rothwell #define RTAS_RMOBUF_MAX (64 * 1024)
24b8b572e1SStephen Rothwell 
25b8b572e1SStephen Rothwell /* RTAS return status codes */
26b8b572e1SStephen Rothwell #define RTAS_BUSY		-2    /* RTAS Busy */
27b8b572e1SStephen Rothwell #define RTAS_EXTENDED_DELAY_MIN	9900
28b8b572e1SStephen Rothwell #define RTAS_EXTENDED_DELAY_MAX	9905
29b8b572e1SStephen Rothwell 
30970e453eSNathan Lynch /* statuses specific to ibm,suspend-me */
31970e453eSNathan Lynch #define RTAS_SUSPEND_ABORTED     9000 /* Suspension aborted */
32970e453eSNathan Lynch #define RTAS_NOT_SUSPENDABLE    -9004 /* Partition not suspendable */
33970e453eSNathan Lynch #define RTAS_THREADS_ACTIVE     -9005 /* Multiple processor threads active */
34970e453eSNathan Lynch #define RTAS_OUTSTANDING_COPROC -9006 /* Outstanding coprocessor operations */
35970e453eSNathan Lynch 
36b8b572e1SStephen Rothwell /*
37b8b572e1SStephen Rothwell  * In general to call RTAS use rtas_token("string") to lookup
38b8b572e1SStephen Rothwell  * an RTAS token for the given string (e.g. "event-scan").
39b8b572e1SStephen Rothwell  * To actually perform the call use
40b8b572e1SStephen Rothwell  *    ret = rtas_call(token, n_in, n_out, ...)
41b8b572e1SStephen Rothwell  * Where n_in is the number of input parameters and
42b8b572e1SStephen Rothwell  *       n_out is the number of output parameters
43b8b572e1SStephen Rothwell  *
44b8b572e1SStephen Rothwell  * If the "string" is invalid on this system, RTAS_UNKNOWN_SERVICE
45b8b572e1SStephen Rothwell  * will be returned as a token.  rtas_call() does look for this
46b8b572e1SStephen Rothwell  * token and error out gracefully so rtas_call(rtas_token("str"), ...)
47b8b572e1SStephen Rothwell  * may be safely used for one-shot calls to RTAS.
48b8b572e1SStephen Rothwell  *
49b8b572e1SStephen Rothwell  */
50b8b572e1SStephen Rothwell 
51b8b572e1SStephen Rothwell /* RTAS event classes */
52b8b572e1SStephen Rothwell #define RTAS_INTERNAL_ERROR		0x80000000 /* set bit 0 */
53b8b572e1SStephen Rothwell #define RTAS_EPOW_WARNING		0x40000000 /* set bit 1 */
54b8b572e1SStephen Rothwell #define RTAS_HOTPLUG_EVENTS		0x10000000 /* set bit 3 */
554a9f9506SAnton Blanchard #define RTAS_IO_EVENTS			0x08000000 /* set bit 4 */
564a9f9506SAnton Blanchard #define RTAS_EVENT_SCAN_ALL_EVENTS	0xffffffff
57b8b572e1SStephen Rothwell 
58b8b572e1SStephen Rothwell /* RTAS event severity */
59b8b572e1SStephen Rothwell #define RTAS_SEVERITY_FATAL		0x5
60b8b572e1SStephen Rothwell #define RTAS_SEVERITY_ERROR		0x4
61b8b572e1SStephen Rothwell #define RTAS_SEVERITY_ERROR_SYNC	0x3
62b8b572e1SStephen Rothwell #define RTAS_SEVERITY_WARNING		0x2
63b8b572e1SStephen Rothwell #define RTAS_SEVERITY_EVENT		0x1
64b8b572e1SStephen Rothwell #define RTAS_SEVERITY_NO_ERROR		0x0
65b8b572e1SStephen Rothwell 
66b8b572e1SStephen Rothwell /* RTAS event disposition */
67b8b572e1SStephen Rothwell #define RTAS_DISP_FULLY_RECOVERED	0x0
68b8b572e1SStephen Rothwell #define RTAS_DISP_LIMITED_RECOVERY	0x1
69b8b572e1SStephen Rothwell #define RTAS_DISP_NOT_RECOVERED		0x2
70b8b572e1SStephen Rothwell 
71b8b572e1SStephen Rothwell /* RTAS event initiator */
72b8b572e1SStephen Rothwell #define RTAS_INITIATOR_UNKNOWN		0x0
73b8b572e1SStephen Rothwell #define RTAS_INITIATOR_CPU		0x1
74b8b572e1SStephen Rothwell #define RTAS_INITIATOR_PCI		0x2
75b8b572e1SStephen Rothwell #define RTAS_INITIATOR_ISA		0x3
76b8b572e1SStephen Rothwell #define RTAS_INITIATOR_MEMORY		0x4
77b8b572e1SStephen Rothwell #define RTAS_INITIATOR_POWERMGM		0x5
78b8b572e1SStephen Rothwell 
79b8b572e1SStephen Rothwell /* RTAS event target */
80b8b572e1SStephen Rothwell #define RTAS_TARGET_UNKNOWN		0x0
81b8b572e1SStephen Rothwell #define RTAS_TARGET_CPU			0x1
82b8b572e1SStephen Rothwell #define RTAS_TARGET_PCI			0x2
83b8b572e1SStephen Rothwell #define RTAS_TARGET_ISA			0x3
84b8b572e1SStephen Rothwell #define RTAS_TARGET_MEMORY		0x4
85b8b572e1SStephen Rothwell #define RTAS_TARGET_POWERMGM		0x5
86b8b572e1SStephen Rothwell 
87b8b572e1SStephen Rothwell /* RTAS event type */
88b8b572e1SStephen Rothwell #define RTAS_TYPE_RETRY			0x01
89b8b572e1SStephen Rothwell #define RTAS_TYPE_TCE_ERR		0x02
90b8b572e1SStephen Rothwell #define RTAS_TYPE_INTERN_DEV_FAIL	0x03
91b8b572e1SStephen Rothwell #define RTAS_TYPE_TIMEOUT		0x04
92b8b572e1SStephen Rothwell #define RTAS_TYPE_DATA_PARITY		0x05
93b8b572e1SStephen Rothwell #define RTAS_TYPE_ADDR_PARITY		0x06
94b8b572e1SStephen Rothwell #define RTAS_TYPE_CACHE_PARITY		0x07
95b8b572e1SStephen Rothwell #define RTAS_TYPE_ADDR_INVALID		0x08
96b8b572e1SStephen Rothwell #define RTAS_TYPE_ECC_UNCORR		0x09
97b8b572e1SStephen Rothwell #define RTAS_TYPE_ECC_CORR		0x0a
98b8b572e1SStephen Rothwell #define RTAS_TYPE_EPOW			0x40
99b8b572e1SStephen Rothwell #define RTAS_TYPE_PLATFORM		0xE0
100b8b572e1SStephen Rothwell #define RTAS_TYPE_IO			0xE1
101b8b572e1SStephen Rothwell #define RTAS_TYPE_INFO			0xE2
102b8b572e1SStephen Rothwell #define RTAS_TYPE_DEALLOC		0xE3
103b8b572e1SStephen Rothwell #define RTAS_TYPE_DUMP			0xE4
1044c5d87dbSOliver O'Halloran #define RTAS_TYPE_HOTPLUG		0xE5
105b8b572e1SStephen Rothwell /* I don't add PowerMGM events right now, this is a different topic */
106b8b572e1SStephen Rothwell #define RTAS_TYPE_PMGM_POWER_SW_ON	0x60
107b8b572e1SStephen Rothwell #define RTAS_TYPE_PMGM_POWER_SW_OFF	0x61
108b8b572e1SStephen Rothwell #define RTAS_TYPE_PMGM_LID_OPEN		0x62
109b8b572e1SStephen Rothwell #define RTAS_TYPE_PMGM_LID_CLOSE	0x63
110b8b572e1SStephen Rothwell #define RTAS_TYPE_PMGM_SLEEP_BTN	0x64
111b8b572e1SStephen Rothwell #define RTAS_TYPE_PMGM_WAKE_BTN		0x65
112b8b572e1SStephen Rothwell #define RTAS_TYPE_PMGM_BATTERY_WARN	0x66
113b8b572e1SStephen Rothwell #define RTAS_TYPE_PMGM_BATTERY_CRIT	0x67
114b8b572e1SStephen Rothwell #define RTAS_TYPE_PMGM_SWITCH_TO_BAT	0x68
115b8b572e1SStephen Rothwell #define RTAS_TYPE_PMGM_SWITCH_TO_AC	0x69
116b8b572e1SStephen Rothwell #define RTAS_TYPE_PMGM_KBD_OR_MOUSE	0x6a
117b8b572e1SStephen Rothwell #define RTAS_TYPE_PMGM_ENCLOS_OPEN	0x6b
118b8b572e1SStephen Rothwell #define RTAS_TYPE_PMGM_ENCLOS_CLOSED	0x6c
119b8b572e1SStephen Rothwell #define RTAS_TYPE_PMGM_RING_INDICATE	0x6d
120b8b572e1SStephen Rothwell #define RTAS_TYPE_PMGM_LAN_ATTENTION	0x6e
121b8b572e1SStephen Rothwell #define RTAS_TYPE_PMGM_TIME_ALARM	0x6f
122b8b572e1SStephen Rothwell #define RTAS_TYPE_PMGM_CONFIG_CHANGE	0x70
123b8b572e1SStephen Rothwell #define RTAS_TYPE_PMGM_SERVICE_PROC	0x71
12449c68a85SJesse Larrew /* Platform Resource Reassignment Notification */
12549c68a85SJesse Larrew #define RTAS_TYPE_PRRN			0xA0
126b8b572e1SStephen Rothwell 
127b08e281bSMark Nelson /* RTAS check-exception vector offset */
128b08e281bSMark Nelson #define RTAS_VECTOR_EXTERNAL_INTERRUPT	0x500
129b08e281bSMark Nelson 
130a08a53eaSGreg Kurz static inline uint8_t rtas_error_severity(const struct rtas_error_log *elog)
131a08a53eaSGreg Kurz {
132a08a53eaSGreg Kurz 	return (elog->byte1 & 0xE0) >> 5;
133a08a53eaSGreg Kurz }
134a08a53eaSGreg Kurz 
135a08a53eaSGreg Kurz static inline uint8_t rtas_error_disposition(const struct rtas_error_log *elog)
136a08a53eaSGreg Kurz {
137a08a53eaSGreg Kurz 	return (elog->byte1 & 0x18) >> 3;
138a08a53eaSGreg Kurz }
139a08a53eaSGreg Kurz 
14004fce21cSMahesh Salgaonkar static inline
14104fce21cSMahesh Salgaonkar void rtas_set_disposition_recovered(struct rtas_error_log *elog)
14204fce21cSMahesh Salgaonkar {
14304fce21cSMahesh Salgaonkar 	elog->byte1 &= ~0x18;
14404fce21cSMahesh Salgaonkar 	elog->byte1 |= (RTAS_DISP_FULLY_RECOVERED << 3);
14504fce21cSMahesh Salgaonkar }
14604fce21cSMahesh Salgaonkar 
147a08a53eaSGreg Kurz static inline uint8_t rtas_error_extended(const struct rtas_error_log *elog)
148a08a53eaSGreg Kurz {
149a08a53eaSGreg Kurz 	return (elog->byte1 & 0x04) >> 2;
150a08a53eaSGreg Kurz }
151a08a53eaSGreg Kurz 
1528f0b8056SMahesh Salgaonkar static inline uint8_t rtas_error_initiator(const struct rtas_error_log *elog)
1538f0b8056SMahesh Salgaonkar {
1548f0b8056SMahesh Salgaonkar 	return (elog->byte2 & 0xf0) >> 4;
1558f0b8056SMahesh Salgaonkar }
1568f0b8056SMahesh Salgaonkar 
157a08a53eaSGreg Kurz #define rtas_error_type(x)	((x)->byte3)
158a08a53eaSGreg Kurz 
159a08a53eaSGreg Kurz static inline
160a08a53eaSGreg Kurz uint32_t rtas_error_extended_log_length(const struct rtas_error_log *elog)
161a08a53eaSGreg Kurz {
162a08a53eaSGreg Kurz 	return be32_to_cpu(elog->extended_log_length);
163a08a53eaSGreg Kurz }
164a08a53eaSGreg Kurz 
1654cb46380STseng-Hui (Frank) Lin #define RTAS_V6EXT_LOG_FORMAT_EVENT_LOG	14
1664cb46380STseng-Hui (Frank) Lin 
1674cb46380STseng-Hui (Frank) Lin #define RTAS_V6EXT_COMPANY_ID_IBM	(('I' << 24) | ('B' << 16) | ('M' << 8))
1684cb46380STseng-Hui (Frank) Lin 
169a08a53eaSGreg Kurz static
170a08a53eaSGreg Kurz inline uint8_t rtas_ext_event_log_format(struct rtas_ext_event_log_v6 *ext_log)
171a08a53eaSGreg Kurz {
172a08a53eaSGreg Kurz 	return ext_log->byte2 & 0x0F;
173a08a53eaSGreg Kurz }
174a08a53eaSGreg Kurz 
175a08a53eaSGreg Kurz static
176a08a53eaSGreg Kurz inline uint32_t rtas_ext_event_company_id(struct rtas_ext_event_log_v6 *ext_log)
177a08a53eaSGreg Kurz {
178a08a53eaSGreg Kurz 	return be32_to_cpu(ext_log->company_id);
179a08a53eaSGreg Kurz }
180a08a53eaSGreg Kurz 
1816431f208SAnton Blanchard /* pSeries event log format */
1826431f208SAnton Blanchard 
1836431f208SAnton Blanchard /* Two bytes ASCII section IDs */
1846431f208SAnton Blanchard #define PSERIES_ELOG_SECT_ID_PRIV_HDR		(('P' << 8) | 'H')
1856431f208SAnton Blanchard #define PSERIES_ELOG_SECT_ID_USER_HDR		(('U' << 8) | 'H')
1866431f208SAnton Blanchard #define PSERIES_ELOG_SECT_ID_PRIMARY_SRC	(('P' << 8) | 'S')
1876431f208SAnton Blanchard #define PSERIES_ELOG_SECT_ID_EXTENDED_UH	(('E' << 8) | 'H')
1886431f208SAnton Blanchard #define PSERIES_ELOG_SECT_ID_FAILING_MTMS	(('M' << 8) | 'T')
1896431f208SAnton Blanchard #define PSERIES_ELOG_SECT_ID_SECONDARY_SRC	(('S' << 8) | 'S')
1906431f208SAnton Blanchard #define PSERIES_ELOG_SECT_ID_DUMP_LOCATOR	(('D' << 8) | 'H')
1916431f208SAnton Blanchard #define PSERIES_ELOG_SECT_ID_FW_ERROR		(('S' << 8) | 'W')
1926431f208SAnton Blanchard #define PSERIES_ELOG_SECT_ID_IMPACT_PART_ID	(('L' << 8) | 'P')
1936431f208SAnton Blanchard #define PSERIES_ELOG_SECT_ID_LOGIC_RESOURCE_ID	(('L' << 8) | 'R')
1946431f208SAnton Blanchard #define PSERIES_ELOG_SECT_ID_HMC_ID		(('H' << 8) | 'M')
1956431f208SAnton Blanchard #define PSERIES_ELOG_SECT_ID_EPOW		(('E' << 8) | 'P')
1966431f208SAnton Blanchard #define PSERIES_ELOG_SECT_ID_IO_EVENT		(('I' << 8) | 'E')
1976431f208SAnton Blanchard #define PSERIES_ELOG_SECT_ID_MANUFACT_INFO	(('M' << 8) | 'I')
1986431f208SAnton Blanchard #define PSERIES_ELOG_SECT_ID_CALL_HOME		(('C' << 8) | 'H')
1996431f208SAnton Blanchard #define PSERIES_ELOG_SECT_ID_USER_DEF		(('U' << 8) | 'D')
200366d395cSNathan Fontenot #define PSERIES_ELOG_SECT_ID_HOTPLUG		(('H' << 8) | 'P')
20104fce21cSMahesh Salgaonkar #define PSERIES_ELOG_SECT_ID_MCE		(('M' << 8) | 'C')
2026431f208SAnton Blanchard 
203a08a53eaSGreg Kurz static
204a08a53eaSGreg Kurz inline uint16_t pseries_errorlog_id(struct pseries_errorlog *sect)
205a08a53eaSGreg Kurz {
206a08a53eaSGreg Kurz 	return be16_to_cpu(sect->id);
207a08a53eaSGreg Kurz }
208a08a53eaSGreg Kurz 
209a08a53eaSGreg Kurz static
210a08a53eaSGreg Kurz inline uint16_t pseries_errorlog_length(struct pseries_errorlog *sect)
211a08a53eaSGreg Kurz {
212a08a53eaSGreg Kurz 	return be16_to_cpu(sect->length);
213a08a53eaSGreg Kurz }
214a08a53eaSGreg Kurz 
215366d395cSNathan Fontenot #define PSERIES_HP_ELOG_RESOURCE_CPU	1
216366d395cSNathan Fontenot #define PSERIES_HP_ELOG_RESOURCE_MEM	2
217366d395cSNathan Fontenot #define PSERIES_HP_ELOG_RESOURCE_SLOT	3
218366d395cSNathan Fontenot #define PSERIES_HP_ELOG_RESOURCE_PHB	4
2194c5d87dbSOliver O'Halloran #define PSERIES_HP_ELOG_RESOURCE_PMEM   6
220366d395cSNathan Fontenot 
221366d395cSNathan Fontenot #define PSERIES_HP_ELOG_ACTION_ADD	1
222366d395cSNathan Fontenot #define PSERIES_HP_ELOG_ACTION_REMOVE	2
223366d395cSNathan Fontenot 
224366d395cSNathan Fontenot #define PSERIES_HP_ELOG_ID_DRC_NAME	1
225366d395cSNathan Fontenot #define PSERIES_HP_ELOG_ID_DRC_INDEX	2
226366d395cSNathan Fontenot #define PSERIES_HP_ELOG_ID_DRC_COUNT	3
227333f7b76SSahil Mehta #define PSERIES_HP_ELOG_ID_DRC_IC	4
228366d395cSNathan Fontenot 
2296431f208SAnton Blanchard struct pseries_errorlog *get_pseries_errorlog(struct rtas_error_log *log,
2306431f208SAnton Blanchard 					      uint16_t section_id);
2316431f208SAnton Blanchard 
232b8b572e1SStephen Rothwell /*
233b8b572e1SStephen Rothwell  * This can be set by the rtas_flash module so that it can get called
234b8b572e1SStephen Rothwell  * as the absolutely last thing before the kernel terminates.
235b8b572e1SStephen Rothwell  */
236b8b572e1SStephen Rothwell extern void (*rtas_flash_term_hook)(int);
237b8b572e1SStephen Rothwell 
238b8b572e1SStephen Rothwell extern struct rtas_t rtas;
239b8b572e1SStephen Rothwell 
240b8b572e1SStephen Rothwell extern int rtas_token(const char *service);
241b8b572e1SStephen Rothwell extern int rtas_service_present(const char *service);
242b8b572e1SStephen Rothwell extern int rtas_call(int token, int, int, int *, ...);
243b664db8eSLeonardo Bras int rtas_call_reentrant(int token, int nargs, int nret, int *outputs, ...);
244209eb4e5SMichael Ellerman void rtas_call_unlocked(struct rtas_args *args, int token, int nargs,
245209eb4e5SMichael Ellerman 			int nret, ...);
24695ec77c0SDaniel Axtens extern void __noreturn rtas_restart(char *cmd);
247b8b572e1SStephen Rothwell extern void rtas_power_off(void);
24895ec77c0SDaniel Axtens extern void __noreturn rtas_halt(void);
249b8b572e1SStephen Rothwell extern void rtas_os_term(char *str);
250b8b572e1SStephen Rothwell extern int rtas_get_sensor(int sensor, int index, int *state);
2511c2cb594SThomas Huth extern int rtas_get_sensor_fast(int sensor, int index, int *state);
252b8b572e1SStephen Rothwell extern int rtas_get_power_level(int powerdomain, int *level);
253b8b572e1SStephen Rothwell extern int rtas_set_power_level(int powerdomain, int level, int *setlevel);
254edc72ac4SNathan Lynch extern bool rtas_indicator_present(int token, int *maxindex);
255b8b572e1SStephen Rothwell extern int rtas_set_indicator(int indicator, int index, int new_value);
256b8b572e1SStephen Rothwell extern int rtas_set_indicator_fast(int indicator, int index, int new_value);
257b8b572e1SStephen Rothwell extern void rtas_progress(char *s, unsigned short hex);
2588fe93f8dSBrian King extern int rtas_suspend_cpu(struct rtas_suspend_me_data *data);
2598fe93f8dSBrian King extern int rtas_suspend_last_cpu(struct rtas_suspend_me_data *data);
2607049b288SNathan Lynch int rtas_ibm_suspend_me_unsafe(u64 handle);
261*701ba683SNathan Lynch int rtas_ibm_suspend_me(int *fw_status);
262b8b572e1SStephen Rothwell 
263b8b572e1SStephen Rothwell struct rtc_time;
2645bfd6435SArnd Bergmann extern time64_t rtas_get_boot_time(void);
265b8b572e1SStephen Rothwell extern void rtas_get_rtc_time(struct rtc_time *rtc_time);
266b8b572e1SStephen Rothwell extern int rtas_set_rtc_time(struct rtc_time *rtc_time);
267b8b572e1SStephen Rothwell 
268b8b572e1SStephen Rothwell extern unsigned int rtas_busy_delay_time(int status);
269b8b572e1SStephen Rothwell extern unsigned int rtas_busy_delay(int status);
270b8b572e1SStephen Rothwell 
271b8b572e1SStephen Rothwell extern int early_init_dt_scan_rtas(unsigned long node,
272b8b572e1SStephen Rothwell 		const char *uname, int depth, void *data);
273b8b572e1SStephen Rothwell 
274b8b572e1SStephen Rothwell extern void pSeries_log_error(char *buf, unsigned int err_type, int fatal);
275b8b572e1SStephen Rothwell 
276762ec157SNathan Fontenot #ifdef CONFIG_PPC_PSERIES
277e4a9616cSHari Bathini extern time64_t last_rtas_event;
27878989f0aSHari Bathini extern int clobbering_unread_rtas_event(void);
279762ec157SNathan Fontenot extern int pseries_devicetree_update(s32 scope);
2806b36ba84SHaren Myneni extern void post_mobility_fixup(void);
28178989f0aSHari Bathini #else
28278989f0aSHari Bathini static inline int clobbering_unread_rtas_event(void) { return 0; }
283762ec157SNathan Fontenot #endif
284762ec157SNathan Fontenot 
285df17f56dSRavi K. Nittala #ifdef CONFIG_PPC_RTAS_DAEMON
286df17f56dSRavi K. Nittala extern void rtas_cancel_event_scan(void);
287df17f56dSRavi K. Nittala #else
288df17f56dSRavi K. Nittala static inline void rtas_cancel_event_scan(void) { }
289df17f56dSRavi K. Nittala #endif
290df17f56dSRavi K. Nittala 
291b8b572e1SStephen Rothwell /* Error types logged.  */
292b8b572e1SStephen Rothwell #define ERR_FLAG_ALREADY_LOGGED	0x0
293b8b572e1SStephen Rothwell #define ERR_FLAG_BOOT		0x1 	/* log was pulled from NVRAM on boot */
294b8b572e1SStephen Rothwell #define ERR_TYPE_RTAS_LOG	0x2	/* from rtas event-scan */
2956c493685SJim Keniston #define ERR_TYPE_KERNEL_PANIC	0x4	/* from die()/panic() */
2966c493685SJim Keniston #define ERR_TYPE_KERNEL_PANIC_GZ 0x8	/* ditto, compressed */
297b8b572e1SStephen Rothwell 
298b8b572e1SStephen Rothwell /* All the types and not flags */
2996c493685SJim Keniston #define ERR_TYPE_MASK \
3006c493685SJim Keniston 	(ERR_TYPE_RTAS_LOG | ERR_TYPE_KERNEL_PANIC | ERR_TYPE_KERNEL_PANIC_GZ)
301b8b572e1SStephen Rothwell 
302b8b572e1SStephen Rothwell #define RTAS_DEBUG KERN_DEBUG "RTAS: "
303b8b572e1SStephen Rothwell 
304b8b572e1SStephen Rothwell #define RTAS_ERROR_LOG_MAX 2048
305b8b572e1SStephen Rothwell 
306b8b572e1SStephen Rothwell /*
307b8b572e1SStephen Rothwell  * Return the firmware-specified size of the error log buffer
308b8b572e1SStephen Rothwell  *  for all rtas calls that require an error buffer argument.
309b8b572e1SStephen Rothwell  *  This includes 'check-exception' and 'rtas-last-error'.
310b8b572e1SStephen Rothwell  */
311b8b572e1SStephen Rothwell extern int rtas_get_error_log_max(void);
312b8b572e1SStephen Rothwell 
313b8b572e1SStephen Rothwell /* Event Scan Parameters */
314b8b572e1SStephen Rothwell #define EVENT_SCAN_ALL_EVENTS	0xf0000000
315b8b572e1SStephen Rothwell #define SURVEILLANCE_TOKEN	9000
316b8b572e1SStephen Rothwell #define LOG_NUMBER		64		/* must be a power of two */
317b8b572e1SStephen Rothwell #define LOG_NUMBER_MASK		(LOG_NUMBER-1)
318b8b572e1SStephen Rothwell 
319b8b572e1SStephen Rothwell /* Some RTAS ops require a data buffer and that buffer must be < 4G.
320b8b572e1SStephen Rothwell  * Rather than having a memory allocator, just use this buffer
321b8b572e1SStephen Rothwell  * (get the lock first), make the RTAS call.  Copy the data instead
322b8b572e1SStephen Rothwell  * of holding the buffer for long.
323b8b572e1SStephen Rothwell  */
324b8b572e1SStephen Rothwell 
325b8b572e1SStephen Rothwell #define RTAS_DATA_BUF_SIZE 4096
326b8b572e1SStephen Rothwell extern spinlock_t rtas_data_buf_lock;
327b8b572e1SStephen Rothwell extern char rtas_data_buf[RTAS_DATA_BUF_SIZE];
328b8b572e1SStephen Rothwell 
329b8b572e1SStephen Rothwell /* RMO buffer reserved for user-space RTAS use */
330b8b572e1SStephen Rothwell extern unsigned long rtas_rmo_buf;
331b8b572e1SStephen Rothwell 
332b8b572e1SStephen Rothwell #define GLOBAL_INTERRUPT_QUEUE 9005
333b8b572e1SStephen Rothwell 
334b8b572e1SStephen Rothwell /**
335b8b572e1SStephen Rothwell  * rtas_config_addr - Format a busno, devfn and reg for RTAS.
336b8b572e1SStephen Rothwell  * @busno: The bus number.
337b8b572e1SStephen Rothwell  * @devfn: The device and function number as encoded by PCI_DEVFN().
338b8b572e1SStephen Rothwell  * @reg: The register number.
339b8b572e1SStephen Rothwell  *
340b8b572e1SStephen Rothwell  * This function encodes the given busno, devfn and register number as
341b8b572e1SStephen Rothwell  * required for RTAS calls that take a "config_addr" parameter.
342b8b572e1SStephen Rothwell  * See PAPR requirement 7.3.4-1 for more info.
343b8b572e1SStephen Rothwell  */
344b8b572e1SStephen Rothwell static inline u32 rtas_config_addr(int busno, int devfn, int reg)
345b8b572e1SStephen Rothwell {
346b8b572e1SStephen Rothwell 	return ((reg & 0xf00) << 20) | ((busno & 0xff) << 16) |
347b8b572e1SStephen Rothwell 			(devfn << 8) | (reg & 0xff);
348b8b572e1SStephen Rothwell }
349b8b572e1SStephen Rothwell 
350061d19f2SPaul Gortmaker extern void rtas_give_timebase(void);
351061d19f2SPaul Gortmaker extern void rtas_take_timebase(void);
352c4007a2fSBenjamin Herrenschmidt 
3538a3e3d31Ssukadev@linux.vnet.ibm.com #ifdef CONFIG_PPC_RTAS
3548a3e3d31Ssukadev@linux.vnet.ibm.com static inline int page_is_rtas_user_buf(unsigned long pfn)
3558a3e3d31Ssukadev@linux.vnet.ibm.com {
3568a3e3d31Ssukadev@linux.vnet.ibm.com 	unsigned long paddr = (pfn << PAGE_SHIFT);
3578a3e3d31Ssukadev@linux.vnet.ibm.com 	if (paddr >= rtas_rmo_buf && paddr < (rtas_rmo_buf + RTAS_RMOBUF_MAX))
3588a3e3d31Ssukadev@linux.vnet.ibm.com 		return 1;
3598a3e3d31Ssukadev@linux.vnet.ibm.com 	return 0;
3608a3e3d31Ssukadev@linux.vnet.ibm.com }
361f459d63eSNathan Fontenot 
362f459d63eSNathan Fontenot /* Not the best place to put pSeries_coalesce_init, will be fixed when we
363f459d63eSNathan Fontenot  * move some of the rtas suspend-me stuff to pseries */
364f459d63eSNathan Fontenot extern void pSeries_coalesce_init(void);
365b1923caaSBenjamin Herrenschmidt void rtas_initialize(void);
3668a3e3d31Ssukadev@linux.vnet.ibm.com #else
3678a3e3d31Ssukadev@linux.vnet.ibm.com static inline int page_is_rtas_user_buf(unsigned long pfn) { return 0;}
368f459d63eSNathan Fontenot static inline void pSeries_coalesce_init(void) { }
369b1923caaSBenjamin Herrenschmidt static inline void rtas_initialize(void) { };
3708a3e3d31Ssukadev@linux.vnet.ibm.com #endif
3718a3e3d31Ssukadev@linux.vnet.ibm.com 
372ae3a197eSDavid Howells extern int call_rtas(const char *, int, int, unsigned long *, ...);
373ae3a197eSDavid Howells 
3748ba21426SKajol Jain #ifdef CONFIG_HV_PERF_CTRS
3758ba21426SKajol Jain void read_24x7_sys_info(void);
3768ba21426SKajol Jain #else
3778ba21426SKajol Jain static inline void read_24x7_sys_info(void) { }
3788ba21426SKajol Jain #endif
3798ba21426SKajol Jain 
380b8b572e1SStephen Rothwell #endif /* __KERNEL__ */
381b8b572e1SStephen Rothwell #endif /* _POWERPC_RTAS_H */
382