Merge branch 'upstream' of git://git.kernel.org/pub/scm/linux/kernel/git/linville...
[deliverable/linux.git] / arch / parisc / kernel / pdc_chassis.c
1 /*
2 * interfaces to log Chassis Codes via PDC (firmware)
3 *
4 * Copyright (C) 2002 Laurent Canet <canetl@esiee.fr>
5 * Copyright (C) 2002-2004 Thibaut VARENE <varenet@parisc-linux.org>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22 #undef PDC_CHASSIS_DEBUG
23 #ifdef PDC_CHASSIS_DEBUG
24 #define DPRINTK(fmt, args...) printk(fmt, ## args)
25 #else
26 #define DPRINTK(fmt, args...)
27 #endif
28
29 #include <linux/init.h>
30 #include <linux/kernel.h>
31 #include <linux/reboot.h>
32 #include <linux/notifier.h>
33 #include <linux/cache.h>
34
35 #include <asm/pdc_chassis.h>
36 #include <asm/processor.h>
37 #include <asm/pdc.h>
38 #include <asm/pdcpat.h>
39
40
41 #ifdef CONFIG_PDC_CHASSIS
42 static int pdc_chassis_old __read_mostly = 0;
43 static unsigned int pdc_chassis_enabled __read_mostly = 1;
44
45
46 /**
47 * pdc_chassis_setup() - Enable/disable pdc_chassis code at boot time.
48 * @str configuration param: 0 to disable chassis log
49 * @return 1
50 */
51
52 static int __init pdc_chassis_setup(char *str)
53 {
54 /*panic_timeout = simple_strtoul(str, NULL, 0);*/
55 get_option(&str, &pdc_chassis_enabled);
56 return 1;
57 }
58 __setup("pdcchassis=", pdc_chassis_setup);
59
60
61 /**
62 * pdc_chassis_checkold() - Checks for old PDC_CHASSIS compatibility
63 * @pdc_chassis_old: 1 if old pdc chassis style
64 *
65 * Currently, only E class and A180 are known to work with this.
66 * Inspired by Christoph Plattner
67 */
68
69 static void __init pdc_chassis_checkold(void)
70 {
71 switch(CPU_HVERSION) {
72 case 0x480: /* E25 */
73 case 0x481: /* E35 */
74 case 0x482: /* E45 */
75 case 0x483: /* E55 */
76 case 0x516: /* A180 */
77 pdc_chassis_old = 1;
78 break;
79
80 default:
81 break;
82 }
83 DPRINTK(KERN_DEBUG "%s: pdc_chassis_checkold(); pdc_chassis_old = %d\n", __FILE__, pdc_chassis_old);
84 }
85
86
87 /**
88 * pdc_chassis_panic_event() - Called by the panic handler.
89 *
90 * As soon as a panic occurs, we should inform the PDC.
91 */
92
93 static int pdc_chassis_panic_event(struct notifier_block *this,
94 unsigned long event, void *ptr)
95 {
96 pdc_chassis_send_status(PDC_CHASSIS_DIRECT_PANIC);
97 return NOTIFY_DONE;
98 }
99
100
101 static struct notifier_block pdc_chassis_panic_block = {
102 .notifier_call = pdc_chassis_panic_event,
103 .priority = INT_MAX,
104 };
105
106
107 /**
108 * parisc_reboot_event() - Called by the reboot handler.
109 *
110 * As soon as a reboot occurs, we should inform the PDC.
111 */
112
113 static int pdc_chassis_reboot_event(struct notifier_block *this,
114 unsigned long event, void *ptr)
115 {
116 pdc_chassis_send_status(PDC_CHASSIS_DIRECT_SHUTDOWN);
117 return NOTIFY_DONE;
118 }
119
120
121 static struct notifier_block pdc_chassis_reboot_block = {
122 .notifier_call = pdc_chassis_reboot_event,
123 .priority = INT_MAX,
124 };
125 #endif /* CONFIG_PDC_CHASSIS */
126
127
128 /**
129 * parisc_pdc_chassis_init() - Called at boot time.
130 */
131
132 void __init parisc_pdc_chassis_init(void)
133 {
134 #ifdef CONFIG_PDC_CHASSIS
135 int handle = 0;
136 if (likely(pdc_chassis_enabled)) {
137 DPRINTK(KERN_DEBUG "%s: parisc_pdc_chassis_init()\n", __FILE__);
138
139 /* Let see if we have something to handle... */
140 /* Check for PDC_PAT or old LED Panel */
141 pdc_chassis_checkold();
142 if (is_pdc_pat()) {
143 printk(KERN_INFO "Enabling PDC_PAT chassis codes support.\n");
144 handle = 1;
145 }
146 else if (unlikely(pdc_chassis_old)) {
147 printk(KERN_INFO "Enabling old style chassis LED panel support.\n");
148 handle = 1;
149 }
150
151 if (handle) {
152 /* initialize panic notifier chain */
153 atomic_notifier_chain_register(&panic_notifier_list,
154 &pdc_chassis_panic_block);
155
156 /* initialize reboot notifier chain */
157 register_reboot_notifier(&pdc_chassis_reboot_block);
158 }
159 }
160 #endif /* CONFIG_PDC_CHASSIS */
161 }
162
163
164 /**
165 * pdc_chassis_send_status() - Sends a predefined message to the chassis,
166 * and changes the front panel LEDs according to the new system state
167 * @retval: PDC call return value.
168 *
169 * Only machines with 64 bits PDC PAT and those reported in
170 * pdc_chassis_checkold() are supported atm.
171 *
172 * returns 0 if no error, -1 if no supported PDC is present or invalid message,
173 * else returns the appropriate PDC error code.
174 *
175 * For a list of predefined messages, see asm-parisc/pdc_chassis.h
176 */
177
178 int pdc_chassis_send_status(int message)
179 {
180 /* Maybe we should do that in an other way ? */
181 int retval = 0;
182 #ifdef CONFIG_PDC_CHASSIS
183 if (likely(pdc_chassis_enabled)) {
184
185 DPRINTK(KERN_DEBUG "%s: pdc_chassis_send_status(%d)\n", __FILE__, message);
186
187 #ifdef CONFIG_64BIT
188 if (is_pdc_pat()) {
189 switch(message) {
190 case PDC_CHASSIS_DIRECT_BSTART:
191 retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_BSTART, PDC_CHASSIS_LSTATE_RUN_NORMAL);
192 break;
193
194 case PDC_CHASSIS_DIRECT_BCOMPLETE:
195 retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_BCOMPLETE, PDC_CHASSIS_LSTATE_RUN_NORMAL);
196 break;
197
198 case PDC_CHASSIS_DIRECT_SHUTDOWN:
199 retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_SHUTDOWN, PDC_CHASSIS_LSTATE_NONOS);
200 break;
201
202 case PDC_CHASSIS_DIRECT_PANIC:
203 retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_PANIC, PDC_CHASSIS_LSTATE_RUN_CRASHREC);
204 break;
205
206 case PDC_CHASSIS_DIRECT_LPMC:
207 retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_LPMC, PDC_CHASSIS_LSTATE_RUN_SYSINT);
208 break;
209
210 case PDC_CHASSIS_DIRECT_HPMC:
211 retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_HPMC, PDC_CHASSIS_LSTATE_RUN_NCRIT);
212 break;
213
214 default:
215 retval = -1;
216 }
217 } else retval = -1;
218 #else
219 if (unlikely(pdc_chassis_old)) {
220 switch (message) {
221 case PDC_CHASSIS_DIRECT_BSTART:
222 case PDC_CHASSIS_DIRECT_BCOMPLETE:
223 retval = pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_RUN));
224 break;
225
226 case PDC_CHASSIS_DIRECT_SHUTDOWN:
227 retval = pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_SHUT));
228 break;
229
230 case PDC_CHASSIS_DIRECT_HPMC:
231 case PDC_CHASSIS_DIRECT_PANIC:
232 retval = pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_FLT));
233 break;
234
235 case PDC_CHASSIS_DIRECT_LPMC:
236 retval = pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_WARN));
237 break;
238
239 default:
240 retval = -1;
241 }
242 } else retval = -1;
243 #endif /* CONFIG_64BIT */
244 } /* if (pdc_chassis_enabled) */
245 #endif /* CONFIG_PDC_CHASSIS */
246 return retval;
247 }
This page took 0.038476 seconds and 6 git commands to generate.