1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-or-later */
2*4882a593Smuzhiyun #ifndef _POWERPC_RTAS_H
3*4882a593Smuzhiyun #define _POWERPC_RTAS_H
4*4882a593Smuzhiyun #ifdef __KERNEL__
5*4882a593Smuzhiyun
6*4882a593Smuzhiyun #include <linux/spinlock.h>
7*4882a593Smuzhiyun #include <asm/page.h>
8*4882a593Smuzhiyun #include <asm/rtas-types.h>
9*4882a593Smuzhiyun #include <linux/time.h>
10*4882a593Smuzhiyun #include <linux/cpumask.h>
11*4882a593Smuzhiyun
12*4882a593Smuzhiyun /*
13*4882a593Smuzhiyun * Definitions for talking to the RTAS on CHRP machines.
14*4882a593Smuzhiyun *
15*4882a593Smuzhiyun * Copyright (C) 2001 Peter Bergner
16*4882a593Smuzhiyun * Copyright (C) 2001 PPC 64 Team, IBM Corp
17*4882a593Smuzhiyun */
18*4882a593Smuzhiyun
19*4882a593Smuzhiyun #define RTAS_UNKNOWN_SERVICE (-1)
20*4882a593Smuzhiyun #define RTAS_INSTANTIATE_MAX (1ULL<<30) /* Don't instantiate rtas at/above this value */
21*4882a593Smuzhiyun
22*4882a593Smuzhiyun /* Buffer size for ppc_rtas system call. */
23*4882a593Smuzhiyun #define RTAS_RMOBUF_MAX (64 * 1024)
24*4882a593Smuzhiyun
25*4882a593Smuzhiyun /* RTAS return status codes */
26*4882a593Smuzhiyun #define RTAS_NOT_SUSPENDABLE -9004
27*4882a593Smuzhiyun #define RTAS_BUSY -2 /* RTAS Busy */
28*4882a593Smuzhiyun #define RTAS_EXTENDED_DELAY_MIN 9900
29*4882a593Smuzhiyun #define RTAS_EXTENDED_DELAY_MAX 9905
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun /*
32*4882a593Smuzhiyun * In general to call RTAS use rtas_token("string") to lookup
33*4882a593Smuzhiyun * an RTAS token for the given string (e.g. "event-scan").
34*4882a593Smuzhiyun * To actually perform the call use
35*4882a593Smuzhiyun * ret = rtas_call(token, n_in, n_out, ...)
36*4882a593Smuzhiyun * Where n_in is the number of input parameters and
37*4882a593Smuzhiyun * n_out is the number of output parameters
38*4882a593Smuzhiyun *
39*4882a593Smuzhiyun * If the "string" is invalid on this system, RTAS_UNKNOWN_SERVICE
40*4882a593Smuzhiyun * will be returned as a token. rtas_call() does look for this
41*4882a593Smuzhiyun * token and error out gracefully so rtas_call(rtas_token("str"), ...)
42*4882a593Smuzhiyun * may be safely used for one-shot calls to RTAS.
43*4882a593Smuzhiyun *
44*4882a593Smuzhiyun */
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun /* RTAS event classes */
47*4882a593Smuzhiyun #define RTAS_INTERNAL_ERROR 0x80000000 /* set bit 0 */
48*4882a593Smuzhiyun #define RTAS_EPOW_WARNING 0x40000000 /* set bit 1 */
49*4882a593Smuzhiyun #define RTAS_HOTPLUG_EVENTS 0x10000000 /* set bit 3 */
50*4882a593Smuzhiyun #define RTAS_IO_EVENTS 0x08000000 /* set bit 4 */
51*4882a593Smuzhiyun #define RTAS_EVENT_SCAN_ALL_EVENTS 0xffffffff
52*4882a593Smuzhiyun
53*4882a593Smuzhiyun /* RTAS event severity */
54*4882a593Smuzhiyun #define RTAS_SEVERITY_FATAL 0x5
55*4882a593Smuzhiyun #define RTAS_SEVERITY_ERROR 0x4
56*4882a593Smuzhiyun #define RTAS_SEVERITY_ERROR_SYNC 0x3
57*4882a593Smuzhiyun #define RTAS_SEVERITY_WARNING 0x2
58*4882a593Smuzhiyun #define RTAS_SEVERITY_EVENT 0x1
59*4882a593Smuzhiyun #define RTAS_SEVERITY_NO_ERROR 0x0
60*4882a593Smuzhiyun
61*4882a593Smuzhiyun /* RTAS event disposition */
62*4882a593Smuzhiyun #define RTAS_DISP_FULLY_RECOVERED 0x0
63*4882a593Smuzhiyun #define RTAS_DISP_LIMITED_RECOVERY 0x1
64*4882a593Smuzhiyun #define RTAS_DISP_NOT_RECOVERED 0x2
65*4882a593Smuzhiyun
66*4882a593Smuzhiyun /* RTAS event initiator */
67*4882a593Smuzhiyun #define RTAS_INITIATOR_UNKNOWN 0x0
68*4882a593Smuzhiyun #define RTAS_INITIATOR_CPU 0x1
69*4882a593Smuzhiyun #define RTAS_INITIATOR_PCI 0x2
70*4882a593Smuzhiyun #define RTAS_INITIATOR_ISA 0x3
71*4882a593Smuzhiyun #define RTAS_INITIATOR_MEMORY 0x4
72*4882a593Smuzhiyun #define RTAS_INITIATOR_POWERMGM 0x5
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun /* RTAS event target */
75*4882a593Smuzhiyun #define RTAS_TARGET_UNKNOWN 0x0
76*4882a593Smuzhiyun #define RTAS_TARGET_CPU 0x1
77*4882a593Smuzhiyun #define RTAS_TARGET_PCI 0x2
78*4882a593Smuzhiyun #define RTAS_TARGET_ISA 0x3
79*4882a593Smuzhiyun #define RTAS_TARGET_MEMORY 0x4
80*4882a593Smuzhiyun #define RTAS_TARGET_POWERMGM 0x5
81*4882a593Smuzhiyun
82*4882a593Smuzhiyun /* RTAS event type */
83*4882a593Smuzhiyun #define RTAS_TYPE_RETRY 0x01
84*4882a593Smuzhiyun #define RTAS_TYPE_TCE_ERR 0x02
85*4882a593Smuzhiyun #define RTAS_TYPE_INTERN_DEV_FAIL 0x03
86*4882a593Smuzhiyun #define RTAS_TYPE_TIMEOUT 0x04
87*4882a593Smuzhiyun #define RTAS_TYPE_DATA_PARITY 0x05
88*4882a593Smuzhiyun #define RTAS_TYPE_ADDR_PARITY 0x06
89*4882a593Smuzhiyun #define RTAS_TYPE_CACHE_PARITY 0x07
90*4882a593Smuzhiyun #define RTAS_TYPE_ADDR_INVALID 0x08
91*4882a593Smuzhiyun #define RTAS_TYPE_ECC_UNCORR 0x09
92*4882a593Smuzhiyun #define RTAS_TYPE_ECC_CORR 0x0a
93*4882a593Smuzhiyun #define RTAS_TYPE_EPOW 0x40
94*4882a593Smuzhiyun #define RTAS_TYPE_PLATFORM 0xE0
95*4882a593Smuzhiyun #define RTAS_TYPE_IO 0xE1
96*4882a593Smuzhiyun #define RTAS_TYPE_INFO 0xE2
97*4882a593Smuzhiyun #define RTAS_TYPE_DEALLOC 0xE3
98*4882a593Smuzhiyun #define RTAS_TYPE_DUMP 0xE4
99*4882a593Smuzhiyun #define RTAS_TYPE_HOTPLUG 0xE5
100*4882a593Smuzhiyun /* I don't add PowerMGM events right now, this is a different topic */
101*4882a593Smuzhiyun #define RTAS_TYPE_PMGM_POWER_SW_ON 0x60
102*4882a593Smuzhiyun #define RTAS_TYPE_PMGM_POWER_SW_OFF 0x61
103*4882a593Smuzhiyun #define RTAS_TYPE_PMGM_LID_OPEN 0x62
104*4882a593Smuzhiyun #define RTAS_TYPE_PMGM_LID_CLOSE 0x63
105*4882a593Smuzhiyun #define RTAS_TYPE_PMGM_SLEEP_BTN 0x64
106*4882a593Smuzhiyun #define RTAS_TYPE_PMGM_WAKE_BTN 0x65
107*4882a593Smuzhiyun #define RTAS_TYPE_PMGM_BATTERY_WARN 0x66
108*4882a593Smuzhiyun #define RTAS_TYPE_PMGM_BATTERY_CRIT 0x67
109*4882a593Smuzhiyun #define RTAS_TYPE_PMGM_SWITCH_TO_BAT 0x68
110*4882a593Smuzhiyun #define RTAS_TYPE_PMGM_SWITCH_TO_AC 0x69
111*4882a593Smuzhiyun #define RTAS_TYPE_PMGM_KBD_OR_MOUSE 0x6a
112*4882a593Smuzhiyun #define RTAS_TYPE_PMGM_ENCLOS_OPEN 0x6b
113*4882a593Smuzhiyun #define RTAS_TYPE_PMGM_ENCLOS_CLOSED 0x6c
114*4882a593Smuzhiyun #define RTAS_TYPE_PMGM_RING_INDICATE 0x6d
115*4882a593Smuzhiyun #define RTAS_TYPE_PMGM_LAN_ATTENTION 0x6e
116*4882a593Smuzhiyun #define RTAS_TYPE_PMGM_TIME_ALARM 0x6f
117*4882a593Smuzhiyun #define RTAS_TYPE_PMGM_CONFIG_CHANGE 0x70
118*4882a593Smuzhiyun #define RTAS_TYPE_PMGM_SERVICE_PROC 0x71
119*4882a593Smuzhiyun /* Platform Resource Reassignment Notification */
120*4882a593Smuzhiyun #define RTAS_TYPE_PRRN 0xA0
121*4882a593Smuzhiyun
122*4882a593Smuzhiyun /* RTAS check-exception vector offset */
123*4882a593Smuzhiyun #define RTAS_VECTOR_EXTERNAL_INTERRUPT 0x500
124*4882a593Smuzhiyun
rtas_error_severity(const struct rtas_error_log * elog)125*4882a593Smuzhiyun static inline uint8_t rtas_error_severity(const struct rtas_error_log *elog)
126*4882a593Smuzhiyun {
127*4882a593Smuzhiyun return (elog->byte1 & 0xE0) >> 5;
128*4882a593Smuzhiyun }
129*4882a593Smuzhiyun
rtas_error_disposition(const struct rtas_error_log * elog)130*4882a593Smuzhiyun static inline uint8_t rtas_error_disposition(const struct rtas_error_log *elog)
131*4882a593Smuzhiyun {
132*4882a593Smuzhiyun return (elog->byte1 & 0x18) >> 3;
133*4882a593Smuzhiyun }
134*4882a593Smuzhiyun
135*4882a593Smuzhiyun static inline
rtas_set_disposition_recovered(struct rtas_error_log * elog)136*4882a593Smuzhiyun void rtas_set_disposition_recovered(struct rtas_error_log *elog)
137*4882a593Smuzhiyun {
138*4882a593Smuzhiyun elog->byte1 &= ~0x18;
139*4882a593Smuzhiyun elog->byte1 |= (RTAS_DISP_FULLY_RECOVERED << 3);
140*4882a593Smuzhiyun }
141*4882a593Smuzhiyun
rtas_error_extended(const struct rtas_error_log * elog)142*4882a593Smuzhiyun static inline uint8_t rtas_error_extended(const struct rtas_error_log *elog)
143*4882a593Smuzhiyun {
144*4882a593Smuzhiyun return (elog->byte1 & 0x04) >> 2;
145*4882a593Smuzhiyun }
146*4882a593Smuzhiyun
rtas_error_initiator(const struct rtas_error_log * elog)147*4882a593Smuzhiyun static inline uint8_t rtas_error_initiator(const struct rtas_error_log *elog)
148*4882a593Smuzhiyun {
149*4882a593Smuzhiyun return (elog->byte2 & 0xf0) >> 4;
150*4882a593Smuzhiyun }
151*4882a593Smuzhiyun
152*4882a593Smuzhiyun #define rtas_error_type(x) ((x)->byte3)
153*4882a593Smuzhiyun
154*4882a593Smuzhiyun static inline
rtas_error_extended_log_length(const struct rtas_error_log * elog)155*4882a593Smuzhiyun uint32_t rtas_error_extended_log_length(const struct rtas_error_log *elog)
156*4882a593Smuzhiyun {
157*4882a593Smuzhiyun return be32_to_cpu(elog->extended_log_length);
158*4882a593Smuzhiyun }
159*4882a593Smuzhiyun
160*4882a593Smuzhiyun #define RTAS_V6EXT_LOG_FORMAT_EVENT_LOG 14
161*4882a593Smuzhiyun
162*4882a593Smuzhiyun #define RTAS_V6EXT_COMPANY_ID_IBM (('I' << 24) | ('B' << 16) | ('M' << 8))
163*4882a593Smuzhiyun
164*4882a593Smuzhiyun static
rtas_ext_event_log_format(struct rtas_ext_event_log_v6 * ext_log)165*4882a593Smuzhiyun inline uint8_t rtas_ext_event_log_format(struct rtas_ext_event_log_v6 *ext_log)
166*4882a593Smuzhiyun {
167*4882a593Smuzhiyun return ext_log->byte2 & 0x0F;
168*4882a593Smuzhiyun }
169*4882a593Smuzhiyun
170*4882a593Smuzhiyun static
rtas_ext_event_company_id(struct rtas_ext_event_log_v6 * ext_log)171*4882a593Smuzhiyun inline uint32_t rtas_ext_event_company_id(struct rtas_ext_event_log_v6 *ext_log)
172*4882a593Smuzhiyun {
173*4882a593Smuzhiyun return be32_to_cpu(ext_log->company_id);
174*4882a593Smuzhiyun }
175*4882a593Smuzhiyun
176*4882a593Smuzhiyun /* pSeries event log format */
177*4882a593Smuzhiyun
178*4882a593Smuzhiyun /* Two bytes ASCII section IDs */
179*4882a593Smuzhiyun #define PSERIES_ELOG_SECT_ID_PRIV_HDR (('P' << 8) | 'H')
180*4882a593Smuzhiyun #define PSERIES_ELOG_SECT_ID_USER_HDR (('U' << 8) | 'H')
181*4882a593Smuzhiyun #define PSERIES_ELOG_SECT_ID_PRIMARY_SRC (('P' << 8) | 'S')
182*4882a593Smuzhiyun #define PSERIES_ELOG_SECT_ID_EXTENDED_UH (('E' << 8) | 'H')
183*4882a593Smuzhiyun #define PSERIES_ELOG_SECT_ID_FAILING_MTMS (('M' << 8) | 'T')
184*4882a593Smuzhiyun #define PSERIES_ELOG_SECT_ID_SECONDARY_SRC (('S' << 8) | 'S')
185*4882a593Smuzhiyun #define PSERIES_ELOG_SECT_ID_DUMP_LOCATOR (('D' << 8) | 'H')
186*4882a593Smuzhiyun #define PSERIES_ELOG_SECT_ID_FW_ERROR (('S' << 8) | 'W')
187*4882a593Smuzhiyun #define PSERIES_ELOG_SECT_ID_IMPACT_PART_ID (('L' << 8) | 'P')
188*4882a593Smuzhiyun #define PSERIES_ELOG_SECT_ID_LOGIC_RESOURCE_ID (('L' << 8) | 'R')
189*4882a593Smuzhiyun #define PSERIES_ELOG_SECT_ID_HMC_ID (('H' << 8) | 'M')
190*4882a593Smuzhiyun #define PSERIES_ELOG_SECT_ID_EPOW (('E' << 8) | 'P')
191*4882a593Smuzhiyun #define PSERIES_ELOG_SECT_ID_IO_EVENT (('I' << 8) | 'E')
192*4882a593Smuzhiyun #define PSERIES_ELOG_SECT_ID_MANUFACT_INFO (('M' << 8) | 'I')
193*4882a593Smuzhiyun #define PSERIES_ELOG_SECT_ID_CALL_HOME (('C' << 8) | 'H')
194*4882a593Smuzhiyun #define PSERIES_ELOG_SECT_ID_USER_DEF (('U' << 8) | 'D')
195*4882a593Smuzhiyun #define PSERIES_ELOG_SECT_ID_HOTPLUG (('H' << 8) | 'P')
196*4882a593Smuzhiyun #define PSERIES_ELOG_SECT_ID_MCE (('M' << 8) | 'C')
197*4882a593Smuzhiyun
198*4882a593Smuzhiyun static
pseries_errorlog_id(struct pseries_errorlog * sect)199*4882a593Smuzhiyun inline uint16_t pseries_errorlog_id(struct pseries_errorlog *sect)
200*4882a593Smuzhiyun {
201*4882a593Smuzhiyun return be16_to_cpu(sect->id);
202*4882a593Smuzhiyun }
203*4882a593Smuzhiyun
204*4882a593Smuzhiyun static
pseries_errorlog_length(struct pseries_errorlog * sect)205*4882a593Smuzhiyun inline uint16_t pseries_errorlog_length(struct pseries_errorlog *sect)
206*4882a593Smuzhiyun {
207*4882a593Smuzhiyun return be16_to_cpu(sect->length);
208*4882a593Smuzhiyun }
209*4882a593Smuzhiyun
210*4882a593Smuzhiyun #define PSERIES_HP_ELOG_RESOURCE_CPU 1
211*4882a593Smuzhiyun #define PSERIES_HP_ELOG_RESOURCE_MEM 2
212*4882a593Smuzhiyun #define PSERIES_HP_ELOG_RESOURCE_SLOT 3
213*4882a593Smuzhiyun #define PSERIES_HP_ELOG_RESOURCE_PHB 4
214*4882a593Smuzhiyun #define PSERIES_HP_ELOG_RESOURCE_PMEM 6
215*4882a593Smuzhiyun
216*4882a593Smuzhiyun #define PSERIES_HP_ELOG_ACTION_ADD 1
217*4882a593Smuzhiyun #define PSERIES_HP_ELOG_ACTION_REMOVE 2
218*4882a593Smuzhiyun
219*4882a593Smuzhiyun #define PSERIES_HP_ELOG_ID_DRC_NAME 1
220*4882a593Smuzhiyun #define PSERIES_HP_ELOG_ID_DRC_INDEX 2
221*4882a593Smuzhiyun #define PSERIES_HP_ELOG_ID_DRC_COUNT 3
222*4882a593Smuzhiyun #define PSERIES_HP_ELOG_ID_DRC_IC 4
223*4882a593Smuzhiyun
224*4882a593Smuzhiyun struct pseries_errorlog *get_pseries_errorlog(struct rtas_error_log *log,
225*4882a593Smuzhiyun uint16_t section_id);
226*4882a593Smuzhiyun
227*4882a593Smuzhiyun /*
228*4882a593Smuzhiyun * This can be set by the rtas_flash module so that it can get called
229*4882a593Smuzhiyun * as the absolutely last thing before the kernel terminates.
230*4882a593Smuzhiyun */
231*4882a593Smuzhiyun extern void (*rtas_flash_term_hook)(int);
232*4882a593Smuzhiyun
233*4882a593Smuzhiyun extern struct rtas_t rtas;
234*4882a593Smuzhiyun
235*4882a593Smuzhiyun extern int rtas_token(const char *service);
236*4882a593Smuzhiyun extern int rtas_service_present(const char *service);
237*4882a593Smuzhiyun extern int rtas_call(int token, int, int, int *, ...);
238*4882a593Smuzhiyun int rtas_call_reentrant(int token, int nargs, int nret, int *outputs, ...);
239*4882a593Smuzhiyun void rtas_call_unlocked(struct rtas_args *args, int token, int nargs,
240*4882a593Smuzhiyun int nret, ...);
241*4882a593Smuzhiyun extern void __noreturn rtas_restart(char *cmd);
242*4882a593Smuzhiyun extern void rtas_power_off(void);
243*4882a593Smuzhiyun extern void __noreturn rtas_halt(void);
244*4882a593Smuzhiyun extern void rtas_os_term(char *str);
245*4882a593Smuzhiyun extern int rtas_get_sensor(int sensor, int index, int *state);
246*4882a593Smuzhiyun extern int rtas_get_sensor_fast(int sensor, int index, int *state);
247*4882a593Smuzhiyun extern int rtas_get_power_level(int powerdomain, int *level);
248*4882a593Smuzhiyun extern int rtas_set_power_level(int powerdomain, int level, int *setlevel);
249*4882a593Smuzhiyun extern bool rtas_indicator_present(int token, int *maxindex);
250*4882a593Smuzhiyun extern int rtas_set_indicator(int indicator, int index, int new_value);
251*4882a593Smuzhiyun extern int rtas_set_indicator_fast(int indicator, int index, int new_value);
252*4882a593Smuzhiyun extern void rtas_progress(char *s, unsigned short hex);
253*4882a593Smuzhiyun extern int rtas_suspend_cpu(struct rtas_suspend_me_data *data);
254*4882a593Smuzhiyun extern int rtas_suspend_last_cpu(struct rtas_suspend_me_data *data);
255*4882a593Smuzhiyun extern int rtas_ibm_suspend_me(u64 handle);
256*4882a593Smuzhiyun
257*4882a593Smuzhiyun struct rtc_time;
258*4882a593Smuzhiyun extern time64_t rtas_get_boot_time(void);
259*4882a593Smuzhiyun extern void rtas_get_rtc_time(struct rtc_time *rtc_time);
260*4882a593Smuzhiyun extern int rtas_set_rtc_time(struct rtc_time *rtc_time);
261*4882a593Smuzhiyun
262*4882a593Smuzhiyun extern unsigned int rtas_busy_delay_time(int status);
263*4882a593Smuzhiyun extern unsigned int rtas_busy_delay(int status);
264*4882a593Smuzhiyun
265*4882a593Smuzhiyun extern int early_init_dt_scan_rtas(unsigned long node,
266*4882a593Smuzhiyun const char *uname, int depth, void *data);
267*4882a593Smuzhiyun
268*4882a593Smuzhiyun extern void pSeries_log_error(char *buf, unsigned int err_type, int fatal);
269*4882a593Smuzhiyun
270*4882a593Smuzhiyun #ifdef CONFIG_PPC_PSERIES
271*4882a593Smuzhiyun extern time64_t last_rtas_event;
272*4882a593Smuzhiyun extern int clobbering_unread_rtas_event(void);
273*4882a593Smuzhiyun extern int pseries_devicetree_update(s32 scope);
274*4882a593Smuzhiyun extern void post_mobility_fixup(void);
275*4882a593Smuzhiyun #else
clobbering_unread_rtas_event(void)276*4882a593Smuzhiyun static inline int clobbering_unread_rtas_event(void) { return 0; }
277*4882a593Smuzhiyun #endif
278*4882a593Smuzhiyun
279*4882a593Smuzhiyun #ifdef CONFIG_PPC_RTAS_DAEMON
280*4882a593Smuzhiyun extern void rtas_cancel_event_scan(void);
281*4882a593Smuzhiyun #else
rtas_cancel_event_scan(void)282*4882a593Smuzhiyun static inline void rtas_cancel_event_scan(void) { }
283*4882a593Smuzhiyun #endif
284*4882a593Smuzhiyun
285*4882a593Smuzhiyun /* Error types logged. */
286*4882a593Smuzhiyun #define ERR_FLAG_ALREADY_LOGGED 0x0
287*4882a593Smuzhiyun #define ERR_FLAG_BOOT 0x1 /* log was pulled from NVRAM on boot */
288*4882a593Smuzhiyun #define ERR_TYPE_RTAS_LOG 0x2 /* from rtas event-scan */
289*4882a593Smuzhiyun #define ERR_TYPE_KERNEL_PANIC 0x4 /* from die()/panic() */
290*4882a593Smuzhiyun #define ERR_TYPE_KERNEL_PANIC_GZ 0x8 /* ditto, compressed */
291*4882a593Smuzhiyun
292*4882a593Smuzhiyun /* All the types and not flags */
293*4882a593Smuzhiyun #define ERR_TYPE_MASK \
294*4882a593Smuzhiyun (ERR_TYPE_RTAS_LOG | ERR_TYPE_KERNEL_PANIC | ERR_TYPE_KERNEL_PANIC_GZ)
295*4882a593Smuzhiyun
296*4882a593Smuzhiyun #define RTAS_DEBUG KERN_DEBUG "RTAS: "
297*4882a593Smuzhiyun
298*4882a593Smuzhiyun #define RTAS_ERROR_LOG_MAX 2048
299*4882a593Smuzhiyun
300*4882a593Smuzhiyun /*
301*4882a593Smuzhiyun * Return the firmware-specified size of the error log buffer
302*4882a593Smuzhiyun * for all rtas calls that require an error buffer argument.
303*4882a593Smuzhiyun * This includes 'check-exception' and 'rtas-last-error'.
304*4882a593Smuzhiyun */
305*4882a593Smuzhiyun extern int rtas_get_error_log_max(void);
306*4882a593Smuzhiyun
307*4882a593Smuzhiyun /* Event Scan Parameters */
308*4882a593Smuzhiyun #define EVENT_SCAN_ALL_EVENTS 0xf0000000
309*4882a593Smuzhiyun #define SURVEILLANCE_TOKEN 9000
310*4882a593Smuzhiyun #define LOG_NUMBER 64 /* must be a power of two */
311*4882a593Smuzhiyun #define LOG_NUMBER_MASK (LOG_NUMBER-1)
312*4882a593Smuzhiyun
313*4882a593Smuzhiyun /* Some RTAS ops require a data buffer and that buffer must be < 4G.
314*4882a593Smuzhiyun * Rather than having a memory allocator, just use this buffer
315*4882a593Smuzhiyun * (get the lock first), make the RTAS call. Copy the data instead
316*4882a593Smuzhiyun * of holding the buffer for long.
317*4882a593Smuzhiyun */
318*4882a593Smuzhiyun
319*4882a593Smuzhiyun #define RTAS_DATA_BUF_SIZE 4096
320*4882a593Smuzhiyun extern spinlock_t rtas_data_buf_lock;
321*4882a593Smuzhiyun extern char rtas_data_buf[RTAS_DATA_BUF_SIZE];
322*4882a593Smuzhiyun
323*4882a593Smuzhiyun /* RMO buffer reserved for user-space RTAS use */
324*4882a593Smuzhiyun extern unsigned long rtas_rmo_buf;
325*4882a593Smuzhiyun
326*4882a593Smuzhiyun #define GLOBAL_INTERRUPT_QUEUE 9005
327*4882a593Smuzhiyun
328*4882a593Smuzhiyun /**
329*4882a593Smuzhiyun * rtas_config_addr - Format a busno, devfn and reg for RTAS.
330*4882a593Smuzhiyun * @busno: The bus number.
331*4882a593Smuzhiyun * @devfn: The device and function number as encoded by PCI_DEVFN().
332*4882a593Smuzhiyun * @reg: The register number.
333*4882a593Smuzhiyun *
334*4882a593Smuzhiyun * This function encodes the given busno, devfn and register number as
335*4882a593Smuzhiyun * required for RTAS calls that take a "config_addr" parameter.
336*4882a593Smuzhiyun * See PAPR requirement 7.3.4-1 for more info.
337*4882a593Smuzhiyun */
rtas_config_addr(int busno,int devfn,int reg)338*4882a593Smuzhiyun static inline u32 rtas_config_addr(int busno, int devfn, int reg)
339*4882a593Smuzhiyun {
340*4882a593Smuzhiyun return ((reg & 0xf00) << 20) | ((busno & 0xff) << 16) |
341*4882a593Smuzhiyun (devfn << 8) | (reg & 0xff);
342*4882a593Smuzhiyun }
343*4882a593Smuzhiyun
344*4882a593Smuzhiyun extern void rtas_give_timebase(void);
345*4882a593Smuzhiyun extern void rtas_take_timebase(void);
346*4882a593Smuzhiyun
347*4882a593Smuzhiyun #ifdef CONFIG_PPC_RTAS
page_is_rtas_user_buf(unsigned long pfn)348*4882a593Smuzhiyun static inline int page_is_rtas_user_buf(unsigned long pfn)
349*4882a593Smuzhiyun {
350*4882a593Smuzhiyun unsigned long paddr = (pfn << PAGE_SHIFT);
351*4882a593Smuzhiyun if (paddr >= rtas_rmo_buf && paddr < (rtas_rmo_buf + RTAS_RMOBUF_MAX))
352*4882a593Smuzhiyun return 1;
353*4882a593Smuzhiyun return 0;
354*4882a593Smuzhiyun }
355*4882a593Smuzhiyun
356*4882a593Smuzhiyun /* Not the best place to put pSeries_coalesce_init, will be fixed when we
357*4882a593Smuzhiyun * move some of the rtas suspend-me stuff to pseries */
358*4882a593Smuzhiyun extern void pSeries_coalesce_init(void);
359*4882a593Smuzhiyun void rtas_initialize(void);
360*4882a593Smuzhiyun #else
page_is_rtas_user_buf(unsigned long pfn)361*4882a593Smuzhiyun static inline int page_is_rtas_user_buf(unsigned long pfn) { return 0;}
pSeries_coalesce_init(void)362*4882a593Smuzhiyun static inline void pSeries_coalesce_init(void) { }
rtas_initialize(void)363*4882a593Smuzhiyun static inline void rtas_initialize(void) { };
364*4882a593Smuzhiyun #endif
365*4882a593Smuzhiyun
366*4882a593Smuzhiyun extern int call_rtas(const char *, int, int, unsigned long *, ...);
367*4882a593Smuzhiyun
368*4882a593Smuzhiyun #ifdef CONFIG_HV_PERF_CTRS
369*4882a593Smuzhiyun void read_24x7_sys_info(void);
370*4882a593Smuzhiyun #else
read_24x7_sys_info(void)371*4882a593Smuzhiyun static inline void read_24x7_sys_info(void) { }
372*4882a593Smuzhiyun #endif
373*4882a593Smuzhiyun
374*4882a593Smuzhiyun #endif /* __KERNEL__ */
375*4882a593Smuzhiyun #endif /* _POWERPC_RTAS_H */
376