ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.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-2003 Thibaut Varene <varenet@esiee.fr>
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
34 #include <asm/pdc_chassis.h>
35 #include <asm/processor.h>
36
37
38 #ifdef CONFIG_PDC_CHASSIS
39 static int pdc_chassis_old = 0; 
40
41
42 /** 
43  * pdc_chassis_checkold() - Checks for old PDC_CHASSIS compatibility
44  * @pdc_chassis_old: 1 if old pdc chassis style
45  * 
46  * Currently, only E class and A180 are known to work with this.
47  * Inspired by Christoph Plattner
48  */
49
50 static void __init pdc_chassis_checkold(void)
51 {
52         switch(CPU_HVERSION) {
53                 case 0x480:             /* E25 */
54                 case 0x481:             /* E35 */
55                 case 0x482:             /* E45 */
56                 case 0x483:             /* E55 */
57                 case 0x516:             /* A180 */
58                         pdc_chassis_old = 1;
59                         break;
60
61                 default:
62                         break;
63         }
64         DPRINTK(KERN_DEBUG "%s: pdc_chassis_checkold(); pdc_chassis_old = %d\n", __FILE__, pdc_chassis_old);
65 }
66
67
68 /**
69  * pdc_chassis_panic_event() - Called by the panic handler.
70  *
71  * As soon as a panic occurs, we should inform the PDC.
72  */
73
74 static int pdc_chassis_panic_event(struct notifier_block *this,
75                         unsigned long event, void *ptr)
76 {
77         pdc_chassis_send_status(PDC_CHASSIS_DIRECT_PANIC);
78                 return NOTIFY_DONE;
79 }   
80
81
82 static struct notifier_block pdc_chassis_panic_block = {
83         .notifier_call = pdc_chassis_panic_event,
84         .priority = INT_MAX,
85 };
86
87
88 /**
89  * parisc_reboot_event() - Called by the reboot handler.
90  *
91  * As soon as a reboot occurs, we should inform the PDC.
92  */
93
94 static int pdc_chassis_reboot_event(struct notifier_block *this,
95                         unsigned long event, void *ptr)
96 {
97         pdc_chassis_send_status(PDC_CHASSIS_DIRECT_SHUTDOWN);
98                 return NOTIFY_DONE;
99 }   
100
101
102 static struct notifier_block pdc_chassis_reboot_block = {
103         .notifier_call = pdc_chassis_reboot_event,
104         .priority = INT_MAX,
105 };
106 #endif /* CONFIG_PDC_CHASSIS */
107
108
109 /**
110  * parisc_pdc_chassis_init() - Called at boot time.
111  */
112
113 void __init parisc_pdc_chassis_init(void)
114 {
115 #ifdef CONFIG_PDC_CHASSIS
116         int handle = 0;
117
118         DPRINTK(KERN_DEBUG "%s: parisc_pdc_chassis_init()\n", __FILE__);
119
120         /* Let see if we have something to handle... */
121         /* Check for PDC_PAT or old LED Panel */
122         pdc_chassis_checkold();
123         if (is_pdc_pat()) {
124 #ifdef __LP64__ /* see pdc_chassis_send_status() */
125                 printk(KERN_INFO "Enabling PDC_PAT chassis codes support.\n");
126                 handle = 1;
127 #endif /* __LP64__ */
128         }
129         else if (pdc_chassis_old) {
130                 printk(KERN_INFO "Enabling old style chassis LED panel support.\n");
131                 handle = 1;
132         }
133         
134         if (handle) {
135                 /* initialize panic notifier chain */
136                 notifier_chain_register(&panic_notifier_list, &pdc_chassis_panic_block);
137
138                 /* initialize reboot notifier chain */
139                 register_reboot_notifier(&pdc_chassis_reboot_block);
140         }
141 #endif /* CONFIG_PDC_CHASSIS */
142 }
143
144
145 /** 
146  * pdc_chassis_send_status() - Sends a predefined message to the chassis,
147  * and changes the front panel LEDs according to the new system state
148  * @retval: PDC call return value.
149  *
150  * Only machines with 64 bits PDC PAT and those reported in
151  * pdc_chassis_checkold() are supported atm.
152  * 
153  * returns 0 if no error, -1 if no supported PDC is present or invalid message,
154  * else returns the appropriate PDC error code.
155  * 
156  * For a list of predefined messages, see asm-parisc/pdc_chassis.h
157  */
158
159 int pdc_chassis_send_status(int message)
160 {
161         /* Maybe we should do that in an other way ? */
162         int retval = 0;
163 #ifdef CONFIG_PDC_CHASSIS
164         DPRINTK(KERN_DEBUG "%s: pdc_chassis_send_status(%d)\n", __FILE__, message);
165
166 #ifdef __LP64__ /* pdc_pat_chassis_send_log is defined only when #ifdef __LP64__ */
167         if (is_pdc_pat()) {
168                 switch(message) {
169                         case PDC_CHASSIS_DIRECT_BSTART:
170                                 retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_BSTART, PDC_CHASSIS_LSTATE_RUN_NORMAL);
171                                 break;
172                         
173                         case PDC_CHASSIS_DIRECT_BCOMPLETE:
174                                 retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_BCOMPLETE, PDC_CHASSIS_LSTATE_RUN_NORMAL);
175                                 break;
176                         
177                         case PDC_CHASSIS_DIRECT_SHUTDOWN:
178                                 retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_SHUTDOWN, PDC_CHASSIS_LSTATE_NONOS);
179                                 break;
180                         
181                         case PDC_CHASSIS_DIRECT_PANIC:
182                                 retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_PANIC, PDC_CHASSIS_LSTATE_RUN_CRASHREC);
183                                 break;
184                 
185                         case PDC_CHASSIS_DIRECT_LPMC:
186                                 retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_LPMC, PDC_CHASSIS_LSTATE_RUN_SYSINT);
187                                 break;
188
189                         case PDC_CHASSIS_DIRECT_HPMC:
190                                 retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_HPMC, PDC_CHASSIS_LSTATE_RUN_NCRIT);
191                                 break;
192
193                         default:
194                                 retval = -1;
195                 }
196         } else retval = -1;
197 #else
198         if (pdc_chassis_old) {
199                 switch (message) {
200                         case PDC_CHASSIS_DIRECT_BSTART:
201                         case PDC_CHASSIS_DIRECT_BCOMPLETE:
202                                 retval = pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_RUN));
203                                 break;
204                                                         
205                         case PDC_CHASSIS_DIRECT_SHUTDOWN:
206                                 retval = pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_SHUT));
207                                 break;
208                         
209                         case PDC_CHASSIS_DIRECT_HPMC:
210                         case PDC_CHASSIS_DIRECT_PANIC:
211                                 retval = pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_FLT));
212                                 break;
213                 
214                         case PDC_CHASSIS_DIRECT_LPMC:
215                                 retval = pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_WARN));
216                                 break;
217
218                         default:
219                                 retval = -1;
220                 }
221         } else retval = -1;
222 #endif /* __LP64__ */
223 #endif /* CONFIG_PDC_CHASSIS */
224         return retval;
225 }