1#ifndef _PPC64_RTAS_H
2#define _PPC64_RTAS_H
3
4#include <linux/spinlock.h>
5#include <asm/page.h>
6
7/*
8 * Definitions for talking to the RTAS on CHRP machines.
9 *
10 * Copyright (C) 2001 Peter Bergner
11 * Copyright (C) 2001 PPC 64 Team, IBM Corp
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version
16 * 2 of the License, or (at your option) any later version.
17 */
18
19#define RTAS_UNKNOWN_SERVICE (-1)
20#define RTAS_INSTANTIATE_MAX (1UL<<30) /* Don't instantiate rtas at/above this value */
21
22/*
23 * In general to call RTAS use rtas_token("string") to lookup
24 * an RTAS token for the given string (e.g. "event-scan").
25 * To actually perform the call use
26 *    ret = rtas_call(token, n_in, n_out, ...)
27 * Where n_in is the number of input parameters and
28 *       n_out is the number of output parameters
29 *
30 * If the "string" is invalid on this system, RTAS_UNKOWN_SERVICE
31 * will be returned as a token.  rtas_call() does look for this
32 * token and error out gracefully so rtas_call(rtas_token("str"), ...)
33 * may be safely used for one-shot calls to RTAS.
34 *
35 */
36
37typedef u32 rtas_arg_t;
38
39struct rtas_args {
40	u32 token;
41	u32 nargs;
42	u32 nret;
43	rtas_arg_t args[16];
44	rtas_arg_t *rets;     /* Pointer to return values in args[]. */
45};
46
47struct rtas_t {
48	unsigned long entry;		/* physical address pointer */
49	unsigned long base;		/* physical address pointer */
50	unsigned long size;
51	spinlock_t lock;
52
53	struct device_node *dev;	/* virtual address pointer */
54};
55
56/* Event classes */
57#define INTERNAL_ERROR		0x80000000 /* set bit 0 */
58#define EPOW_WARNING		0x40000000 /* set bit 1 */
59#define POWERMGM_EVENTS		0x20000000 /* set bit 2 */
60#define HOTPLUG_EVENTS		0x10000000 /* set bit 3 */
61#define EVENT_SCAN_ALL_EVENTS	0xf0000000
62
63/* event-scan returns */
64#define SEVERITY_FATAL		0x5
65#define SEVERITY_ERROR		0x4
66#define SEVERITY_ERROR_SYNC	0x3
67#define SEVERITY_WARNING	0x2
68#define SEVERITY_EVENT		0x1
69#define SEVERITY_NO_ERROR	0x0
70#define DISP_FULLY_RECOVERED	0x0
71#define DISP_LIMITED_RECOVERY	0x1
72#define DISP_NOT_RECOVERED	0x2
73#define PART_PRESENT		0x0
74#define PART_NOT_PRESENT	0x1
75#define INITIATOR_UNKNOWN	0x0
76#define INITIATOR_CPU		0x1
77#define INITIATOR_PCI		0x2
78#define INITIATOR_ISA		0x3
79#define INITIATOR_MEMORY	0x4
80#define INITIATOR_POWERMGM	0x5
81#define TARGET_UNKNOWN		0x0
82#define TARGET_CPU		0x1
83#define TARGET_PCI		0x2
84#define TARGET_ISA		0x3
85#define TARGET_MEMORY		0x4
86#define TARGET_POWERMGM		0x5
87#define TYPE_RETRY		0x01
88#define TYPE_TCE_ERR		0x02
89#define TYPE_INTERN_DEV_FAIL	0x03
90#define TYPE_TIMEOUT		0x04
91#define TYPE_DATA_PARITY	0x05
92#define TYPE_ADDR_PARITY	0x06
93#define TYPE_CACHE_PARITY	0x07
94#define TYPE_ADDR_INVALID	0x08
95#define TYPE_ECC_UNCORR		0x09
96#define TYPE_ECC_CORR		0x0a
97#define TYPE_EPOW		0x40
98/* I don't add PowerMGM events right now, this is a different topic */
99#define TYPE_PMGM_POWER_SW_ON	0x60
100#define TYPE_PMGM_POWER_SW_OFF	0x61
101#define TYPE_PMGM_LID_OPEN	0x62
102#define TYPE_PMGM_LID_CLOSE	0x63
103#define TYPE_PMGM_SLEEP_BTN	0x64
104#define TYPE_PMGM_WAKE_BTN	0x65
105#define TYPE_PMGM_BATTERY_WARN	0x66
106#define TYPE_PMGM_BATTERY_CRIT	0x67
107#define TYPE_PMGM_SWITCH_TO_BAT	0x68
108#define TYPE_PMGM_SWITCH_TO_AC	0x69
109#define TYPE_PMGM_KBD_OR_MOUSE	0x6a
110#define TYPE_PMGM_ENCLOS_OPEN	0x6b
111#define TYPE_PMGM_ENCLOS_CLOSED	0x6c
112#define TYPE_PMGM_RING_INDICATE	0x6d
113#define TYPE_PMGM_LAN_ATTENTION	0x6e
114#define TYPE_PMGM_TIME_ALARM	0x6f
115#define TYPE_PMGM_CONFIG_CHANGE	0x70
116#define TYPE_PMGM_SERVICE_PROC	0x71
117
118struct rtas_error_log {
119	unsigned long version:8;		/* Architectural version */
120	unsigned long severity:3;		/* Severity level of error */
121	unsigned long disposition:2;		/* Degree of recovery */
122	unsigned long extended:1;		/* extended log present? */
123	unsigned long /* reserved */ :2;	/* Reserved for future use */
124	unsigned long initiator:4;		/* Initiator of event */
125	unsigned long target:4;			/* Target of failed operation */
126	unsigned long type:8;			/* General event or error*/
127	unsigned long extended_log_length:32;	/* length in bytes */
128	unsigned char buffer[1];		/* allocated by klimit bump */
129};
130
131struct flash_block {
132	char *data;
133	unsigned long length;
134};
135
136/* This struct is very similar but not identical to
137 * that needed by the rtas flash update.
138 * All we need to do for rtas is rewrite num_blocks
139 * into a version/length and translate the pointers
140 * to absolute.
141 */
142#define FLASH_BLOCKS_PER_NODE ((PAGE_SIZE - 16) / sizeof(struct flash_block))
143struct flash_block_list {
144	unsigned long num_blocks;
145	struct flash_block_list *next;
146	struct flash_block blocks[FLASH_BLOCKS_PER_NODE];
147};
148struct flash_block_list_header { /* just the header of flash_block_list */
149	unsigned long num_blocks;
150	struct flash_block_list *next;
151};
152extern struct flash_block_list_header rtas_firmware_flash_list;
153
154extern struct rtas_t rtas;
155
156extern void enter_rtas(struct rtas_args *);
157extern int rtas_token(const char *service);
158extern long rtas_call(int token, int, int, unsigned long *, ...);
159extern void phys_call_rtas(int, int, int, ...);
160extern void phys_call_rtas_display_status(char);
161extern void call_rtas_display_status(char);
162extern void rtas_restart(char *cmd);
163extern void rtas_power_off(void);
164extern void rtas_halt(void);
165
166extern struct proc_dir_entry *rtas_proc_dir;
167
168
169#endif /* _PPC64_RTAS_H */
170