Diff markup
1 /* toshiba.c -- Linux driver for accessing the 1 /* toshiba.c -- Linux driver for accessing the SMM on Toshiba laptops
2 * 2 *
3 * Copyright (c) 1996-2001 Jonathan A. Buzzar 3 * Copyright (c) 1996-2001 Jonathan A. Buzzard (jonathan@buzzard.org.uk)
4 * 4 *
5 * Valuable assistance and patches from: 5 * Valuable assistance and patches from:
6 * Tom May <tom@you-bastards.com> 6 * Tom May <tom@you-bastards.com>
7 * Rob Napier <rnapier@employees.org> 7 * Rob Napier <rnapier@employees.org>
8 * 8 *
9 * Fn status port numbers for machine ID's cou 9 * Fn status port numbers for machine ID's courtesy of
10 * 0xfc02: Scott Eisert <scott.e@sky-eye.c 10 * 0xfc02: Scott Eisert <scott.e@sky-eye.com>
11 * 0xfc04: Steve VanDevender <stevev@efn.o 11 * 0xfc04: Steve VanDevender <stevev@efn.org>
12 * 0xfc08: Garth Berry <garth@itsbruce.net 12 * 0xfc08: Garth Berry <garth@itsbruce.net>
13 * 0xfc0a: Egbert Eich <eich@xfree86.org> 13 * 0xfc0a: Egbert Eich <eich@xfree86.org>
14 * 0xfc10: Andrew Lofthouse <Andrew.Loftho 14 * 0xfc10: Andrew Lofthouse <Andrew.Lofthouse@robins.af.mil>
15 * 0xfc11: Spencer Olson <solson@novell.co 15 * 0xfc11: Spencer Olson <solson@novell.com>
16 * 0xfc13: Claudius Frankewitz <kryp@gmx.d 16 * 0xfc13: Claudius Frankewitz <kryp@gmx.de>
17 * 0xfc15: Tom May <tom@you-bastards.com> 17 * 0xfc15: Tom May <tom@you-bastards.com>
18 * 0xfc17: Dave Konrad <konrad@xenia.it> 18 * 0xfc17: Dave Konrad <konrad@xenia.it>
19 * 0xfc1a: George Betzos <betzos@engr.colo 19 * 0xfc1a: George Betzos <betzos@engr.colostate.edu>
20 * 0xfc1b: Munemasa Wada <munemasa@jnovel. 20 * 0xfc1b: Munemasa Wada <munemasa@jnovel.co.jp>
21 * 0xfc1d: Arthur Liu <armie@slap.mine.nu> 21 * 0xfc1d: Arthur Liu <armie@slap.mine.nu>
22 * 0xfc5a: Jacques L'helgoualc'h <lhh@free 22 * 0xfc5a: Jacques L'helgoualc'h <lhh@free.fr>
23 * 0xfcd1: Mr. Dave Konrad <konrad@xenia.i 23 * 0xfcd1: Mr. Dave Konrad <konrad@xenia.it>
24 * 24 *
25 * WARNING WARNING WARNING WARNING WARNING WAR 25 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
26 * 26 *
27 * This code is covered by the GNU GPL and y 27 * This code is covered by the GNU GPL and you are free to make any
28 * changes you wish to it under the terms of 28 * changes you wish to it under the terms of the license. However the
29 * code has the potential to render your com 29 * code has the potential to render your computer and/or someone else's
30 * unusable. Please proceed with care when m 30 * unusable. Please proceed with care when modifying the code.
31 * 31 *
32 * Note: Unfortunately the laptop hardware can 32 * Note: Unfortunately the laptop hardware can close the System Configuration
33 * Interface on it's own accord. It is t 33 * Interface on it's own accord. It is therefore necessary for *all*
34 * programs using this driver to be awar 34 * programs using this driver to be aware that *any* SCI call can fail at
35 * *any* time. It is up to any program t 35 * *any* time. It is up to any program to be aware of this eventuality
36 * and take appropriate steps. 36 * and take appropriate steps.
37 * 37 *
38 * This program is free software; you can redi 38 * This program is free software; you can redistribute it and/or modify it
39 * under the terms of the GNU General Public L 39 * under the terms of the GNU General Public License as published by the
40 * Free Software Foundation; either version 2, 40 * Free Software Foundation; either version 2, or (at your option) any
41 * later version. 41 * later version.
42 * 42 *
43 * This program is distributed in the hope tha 43 * This program is distributed in the hope that it will be useful, but
44 * WITHOUT ANY WARRANTY; without even the impl 44 * WITHOUT ANY WARRANTY; without even the implied warranty of
45 * MERCHANTABILITY or FITNESS FOR A PARTICULAR 45 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
46 * General Public License for more details. 46 * General Public License for more details.
47 * 47 *
48 * The information used to write this driver h 48 * The information used to write this driver has been obtained by reverse
49 * engineering the software supplied by Toshib 49 * engineering the software supplied by Toshiba for their portable computers in
50 * strict accordance with the European Council 50 * strict accordance with the European Council Directive 92/250/EEC on the legal
51 * protection of computer programs, and it's i 51 * protection of computer programs, and it's implementation into English Law by
52 * the Copyright (Computer Programs) Regulatio 52 * the Copyright (Computer Programs) Regulations 1992 (S.I. 1992 No.3233).
53 * 53 *
54 */ 54 */
55 55
56 #define TOSH_VERSION "1.11 26/9/2001" 56 #define TOSH_VERSION "1.11 26/9/2001"
57 #define TOSH_DEBUG 0 57 #define TOSH_DEBUG 0
58 58
59 #include <linux/module.h> 59 #include <linux/module.h>
60 #include <linux/kernel.h> 60 #include <linux/kernel.h>
>> 61 #include <linux/sched.h>
61 #include <linux/types.h> 62 #include <linux/types.h>
62 #include <linux/fcntl.h> 63 #include <linux/fcntl.h>
63 #include <linux/miscdevice.h> 64 #include <linux/miscdevice.h>
64 #include <linux/ioport.h> 65 #include <linux/ioport.h>
65 #include <asm/io.h> 66 #include <asm/io.h>
66 #include <asm/uaccess.h> 67 #include <asm/uaccess.h>
67 #include <linux/init.h> 68 #include <linux/init.h>
68 #include <linux/stat.h> 69 #include <linux/stat.h>
69 #include <linux/proc_fs.h> 70 #include <linux/proc_fs.h>
70 #include <linux/seq_file.h> <<
71 71
72 #include <linux/toshiba.h> 72 #include <linux/toshiba.h>
73 73
74 #define TOSH_MINOR_DEV 181 74 #define TOSH_MINOR_DEV 181
75 75
76 MODULE_LICENSE("GPL"); !! 76 static int tosh_id = 0x0000;
77 MODULE_AUTHOR("Jonathan Buzzard <jonathan@buzz !! 77 static int tosh_bios = 0x0000;
78 MODULE_DESCRIPTION("Toshiba laptop SMM driver" !! 78 static int tosh_date = 0x0000;
79 MODULE_SUPPORTED_DEVICE("toshiba"); !! 79 static int tosh_sci = 0x0000;
>> 80 static int tosh_fan = 0;
>> 81
>> 82 static int tosh_fn = 0;
>> 83
>> 84 module_param(tosh_fn, int, 0);
80 85
81 static int tosh_fn; <<
82 module_param_named(fn, tosh_fn, int, 0); <<
83 MODULE_PARM_DESC(fn, "User specified Fn key de <<
84 <<
85 static int tosh_id; <<
86 static int tosh_bios; <<
87 static int tosh_date; <<
88 static int tosh_sci; <<
89 static int tosh_fan; <<
90 86
91 static int tosh_ioctl(struct inode *, struct f 87 static int tosh_ioctl(struct inode *, struct file *, unsigned int,
92 unsigned long); 88 unsigned long);
93 89
94 90
95 static const struct file_operations tosh_fops !! 91 static struct file_operations tosh_fops = {
96 .owner = THIS_MODULE, 92 .owner = THIS_MODULE,
97 .ioctl = tosh_ioctl, 93 .ioctl = tosh_ioctl,
98 }; 94 };
99 95
100 static struct miscdevice tosh_device = { 96 static struct miscdevice tosh_device = {
101 TOSH_MINOR_DEV, 97 TOSH_MINOR_DEV,
102 "toshiba", 98 "toshiba",
103 &tosh_fops 99 &tosh_fops
104 }; 100 };
105 101
106 /* 102 /*
107 * Read the Fn key status 103 * Read the Fn key status
108 */ 104 */
109 #ifdef CONFIG_PROC_FS 105 #ifdef CONFIG_PROC_FS
110 static int tosh_fn_status(void) 106 static int tosh_fn_status(void)
111 { 107 {
112 unsigned char scan; 108 unsigned char scan;
113 unsigned long flags; 109 unsigned long flags;
114 110
115 if (tosh_fn!=0) { 111 if (tosh_fn!=0) {
116 scan = inb(tosh_fn); 112 scan = inb(tosh_fn);
117 } else { 113 } else {
118 local_irq_save(flags); 114 local_irq_save(flags);
119 outb(0x8e, 0xe4); 115 outb(0x8e, 0xe4);
120 scan = inb(0xe5); 116 scan = inb(0xe5);
121 local_irq_restore(flags); 117 local_irq_restore(flags);
122 } 118 }
123 119
124 return (int) scan; 120 return (int) scan;
125 } 121 }
126 #endif 122 #endif
127 123
128 124
129 /* 125 /*
130 * For the Portage 610CT and the Tecra 700CS/7 126 * For the Portage 610CT and the Tecra 700CS/700CDT emulate the HCI fan function
131 */ 127 */
132 static int tosh_emulate_fan(SMMRegisters *regs 128 static int tosh_emulate_fan(SMMRegisters *regs)
133 { 129 {
134 unsigned long eax,ecx,flags; 130 unsigned long eax,ecx,flags;
135 unsigned char al; 131 unsigned char al;
136 132
137 eax = regs->eax & 0xff00; 133 eax = regs->eax & 0xff00;
138 ecx = regs->ecx & 0xffff; 134 ecx = regs->ecx & 0xffff;
139 135
140 /* Portage 610CT */ 136 /* Portage 610CT */
141 137
142 if (tosh_id==0xfccb) { 138 if (tosh_id==0xfccb) {
143 if (eax==0xfe00) { 139 if (eax==0xfe00) {
144 /* fan status */ 140 /* fan status */
145 local_irq_save(flags); 141 local_irq_save(flags);
146 outb(0xbe, 0xe4); 142 outb(0xbe, 0xe4);
147 al = inb(0xe5); 143 al = inb(0xe5);
148 local_irq_restore(flag 144 local_irq_restore(flags);
149 regs->eax = 0x00; 145 regs->eax = 0x00;
150 regs->ecx = (unsigned 146 regs->ecx = (unsigned int) (al & 0x01);
151 } 147 }
152 if ((eax==0xff00) && (ecx==0x0 148 if ((eax==0xff00) && (ecx==0x0000)) {
153 /* fan off */ 149 /* fan off */
154 local_irq_save(flags); 150 local_irq_save(flags);
155 outb(0xbe, 0xe4); 151 outb(0xbe, 0xe4);
156 al = inb(0xe5); 152 al = inb(0xe5);
157 outb(0xbe, 0xe4); 153 outb(0xbe, 0xe4);
158 outb (al | 0x01, 0xe5) 154 outb (al | 0x01, 0xe5);
159 local_irq_restore(flag 155 local_irq_restore(flags);
160 regs->eax = 0x00; 156 regs->eax = 0x00;
161 regs->ecx = 0x00; 157 regs->ecx = 0x00;
162 } 158 }
163 if ((eax==0xff00) && (ecx==0x0 159 if ((eax==0xff00) && (ecx==0x0001)) {
164 /* fan on */ 160 /* fan on */
165 local_irq_save(flags); 161 local_irq_save(flags);
166 outb(0xbe, 0xe4); 162 outb(0xbe, 0xe4);
167 al = inb(0xe5); 163 al = inb(0xe5);
168 outb(0xbe, 0xe4); 164 outb(0xbe, 0xe4);
169 outb(al & 0xfe, 0xe5); 165 outb(al & 0xfe, 0xe5);
170 local_irq_restore(flag 166 local_irq_restore(flags);
171 regs->eax = 0x00; 167 regs->eax = 0x00;
172 regs->ecx = 0x01; 168 regs->ecx = 0x01;
173 } 169 }
174 } 170 }
175 171
176 /* Tecra 700CS/CDT */ 172 /* Tecra 700CS/CDT */
177 173
178 if (tosh_id==0xfccc) { 174 if (tosh_id==0xfccc) {
179 if (eax==0xfe00) { 175 if (eax==0xfe00) {
180 /* fan status */ 176 /* fan status */
181 local_irq_save(flags); 177 local_irq_save(flags);
182 outb(0xe0, 0xe4); 178 outb(0xe0, 0xe4);
183 al = inb(0xe5); 179 al = inb(0xe5);
184 local_irq_restore(flag 180 local_irq_restore(flags);
185 regs->eax = 0x00; 181 regs->eax = 0x00;
186 regs->ecx = al & 0x01; 182 regs->ecx = al & 0x01;
187 } 183 }
188 if ((eax==0xff00) && (ecx==0x0 184 if ((eax==0xff00) && (ecx==0x0000)) {
189 /* fan off */ 185 /* fan off */
190 local_irq_save(flags); 186 local_irq_save(flags);
191 outb(0xe0, 0xe4); 187 outb(0xe0, 0xe4);
192 al = inb(0xe5); 188 al = inb(0xe5);
193 outw(0xe0 | ((al & 0xf 189 outw(0xe0 | ((al & 0xfe) << 8), 0xe4);
194 local_irq_restore(flag 190 local_irq_restore(flags);
195 regs->eax = 0x00; 191 regs->eax = 0x00;
196 regs->ecx = 0x00; 192 regs->ecx = 0x00;
197 } 193 }
198 if ((eax==0xff00) && (ecx==0x0 194 if ((eax==0xff00) && (ecx==0x0001)) {
199 /* fan on */ 195 /* fan on */
200 local_irq_save(flags); 196 local_irq_save(flags);
201 outb(0xe0, 0xe4); 197 outb(0xe0, 0xe4);
202 al = inb(0xe5); 198 al = inb(0xe5);
203 outw(0xe0 | ((al | 0x0 199 outw(0xe0 | ((al | 0x01) << 8), 0xe4);
204 local_irq_restore(flag 200 local_irq_restore(flags);
205 regs->eax = 0x00; 201 regs->eax = 0x00;
206 regs->ecx = 0x01; 202 regs->ecx = 0x01;
207 } 203 }
208 } 204 }
209 205
210 return 0; 206 return 0;
211 } 207 }
212 208
213 209
214 /* 210 /*
215 * Put the laptop into System Management Mode 211 * Put the laptop into System Management Mode
216 */ 212 */
217 int tosh_smm(SMMRegisters *regs) 213 int tosh_smm(SMMRegisters *regs)
218 { 214 {
219 int eax; 215 int eax;
220 216
221 asm ("# load the values into the regis 217 asm ("# load the values into the registers\n\t" \
222 "pushl %%eax\n\t" \ 218 "pushl %%eax\n\t" \
223 "movl 0(%%eax),%%edx\n\t" \ 219 "movl 0(%%eax),%%edx\n\t" \
224 "push %%edx\n\t" \ 220 "push %%edx\n\t" \
225 "movl 4(%%eax),%%ebx\n\t" \ 221 "movl 4(%%eax),%%ebx\n\t" \
226 "movl 8(%%eax),%%ecx\n\t" \ 222 "movl 8(%%eax),%%ecx\n\t" \
227 "movl 12(%%eax),%%edx\n\t" \ 223 "movl 12(%%eax),%%edx\n\t" \
228 "movl 16(%%eax),%%esi\n\t" \ 224 "movl 16(%%eax),%%esi\n\t" \
229 "movl 20(%%eax),%%edi\n\t" \ 225 "movl 20(%%eax),%%edi\n\t" \
230 "popl %%eax\n\t" \ 226 "popl %%eax\n\t" \
231 "# call the System Management 227 "# call the System Management mode\n\t" \
232 "inb $0xb2,%%al\n\t" 228 "inb $0xb2,%%al\n\t"
233 "# fill out the memory with th 229 "# fill out the memory with the values in the registers\n\t" \
234 "xchgl %%eax,(%%esp)\n\t" 230 "xchgl %%eax,(%%esp)\n\t"
235 "movl %%ebx,4(%%eax)\n\t" \ 231 "movl %%ebx,4(%%eax)\n\t" \
236 "movl %%ecx,8(%%eax)\n\t" \ 232 "movl %%ecx,8(%%eax)\n\t" \
237 "movl %%edx,12(%%eax)\n\t" \ 233 "movl %%edx,12(%%eax)\n\t" \
238 "movl %%esi,16(%%eax)\n\t" \ 234 "movl %%esi,16(%%eax)\n\t" \
239 "movl %%edi,20(%%eax)\n\t" \ 235 "movl %%edi,20(%%eax)\n\t" \
240 "popl %%edx\n\t" \ 236 "popl %%edx\n\t" \
241 "movl %%edx,0(%%eax)\n\t" \ 237 "movl %%edx,0(%%eax)\n\t" \
242 "# setup the return value to t 238 "# setup the return value to the carry flag\n\t" \
243 "lahf\n\t" \ 239 "lahf\n\t" \
244 "shrl $8,%%eax\n\t" \ 240 "shrl $8,%%eax\n\t" \
245 "andl $1,%%eax\n" \ 241 "andl $1,%%eax\n" \
246 : "=a" (eax) 242 : "=a" (eax)
247 : "a" (regs) 243 : "a" (regs)
248 : "%ebx", "%ecx", "%edx", "%es 244 : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
249 245
250 return eax; 246 return eax;
251 } 247 }
252 EXPORT_SYMBOL(tosh_smm); <<
253 248
254 249
255 static int tosh_ioctl(struct inode *ip, struct 250 static int tosh_ioctl(struct inode *ip, struct file *fp, unsigned int cmd,
256 unsigned long arg) 251 unsigned long arg)
257 { 252 {
258 SMMRegisters regs; 253 SMMRegisters regs;
259 SMMRegisters __user *argp = (SMMRegist 254 SMMRegisters __user *argp = (SMMRegisters __user *)arg;
260 unsigned short ax,bx; 255 unsigned short ax,bx;
261 int err; 256 int err;
262 257
263 if (!argp) 258 if (!argp)
264 return -EINVAL; 259 return -EINVAL;
265 260
266 if (copy_from_user(®s, argp, sizeof 261 if (copy_from_user(®s, argp, sizeof(SMMRegisters)))
267 return -EFAULT; 262 return -EFAULT;
268 263
269 switch (cmd) { 264 switch (cmd) {
270 case TOSH_SMM: 265 case TOSH_SMM:
271 ax = regs.eax & 0xff00 266 ax = regs.eax & 0xff00;
272 bx = regs.ebx & 0xffff 267 bx = regs.ebx & 0xffff;
273 /* block HCI calls to 268 /* block HCI calls to read/write memory & PCI devices */
274 if (((ax==0xff00) || ( 269 if (((ax==0xff00) || (ax==0xfe00)) && (bx>0x0069))
275 return -EINVAL 270 return -EINVAL;
276 271
277 /* do we need to emula 272 /* do we need to emulate the fan ? */
278 if (tosh_fan==1) { 273 if (tosh_fan==1) {
279 if (((ax==0xf3 274 if (((ax==0xf300) || (ax==0xf400)) && (bx==0x0004)) {
280 err = 275 err = tosh_emulate_fan(®s);
281 break; 276 break;
282 } 277 }
283 } 278 }
284 err = tosh_smm(®s); 279 err = tosh_smm(®s);
285 break; 280 break;
286 default: 281 default:
287 return -EINVAL; 282 return -EINVAL;
288 } 283 }
289 284
290 if (copy_to_user(argp, ®s, sizeof(S 285 if (copy_to_user(argp, ®s, sizeof(SMMRegisters)))
291 return -EFAULT; 286 return -EFAULT;
292 287
293 return (err==0) ? 0:-EINVAL; 288 return (err==0) ? 0:-EINVAL;
294 } 289 }
295 290
296 291
297 /* 292 /*
298 * Print the information for /proc/toshiba 293 * Print the information for /proc/toshiba
299 */ 294 */
300 #ifdef CONFIG_PROC_FS 295 #ifdef CONFIG_PROC_FS
301 static int proc_toshiba_show(struct seq_file * !! 296 static int tosh_get_info(char *buffer, char **start, off_t fpos, int length)
302 { 297 {
>> 298 char *temp;
303 int key; 299 int key;
304 300
>> 301 temp = buffer;
305 key = tosh_fn_status(); 302 key = tosh_fn_status();
306 303
307 /* Arguments 304 /* Arguments
308 0) Linux driver version (this wil 305 0) Linux driver version (this will change if format changes)
309 1) Machine ID 306 1) Machine ID
310 2) SCI version 307 2) SCI version
311 3) BIOS version (major, minor) 308 3) BIOS version (major, minor)
312 4) BIOS date (in SCI date format) 309 4) BIOS date (in SCI date format)
313 5) Fn Key status 310 5) Fn Key status
314 */ 311 */
315 seq_printf(m, "1.1 0x%04x %d.%d %d.%d !! 312
>> 313 temp += sprintf(temp, "1.1 0x%04x %d.%d %d.%d 0x%04x 0x%02x\n",
316 tosh_id, 314 tosh_id,
317 (tosh_sci & 0xff00)>>8, 315 (tosh_sci & 0xff00)>>8,
318 tosh_sci & 0xff, 316 tosh_sci & 0xff,
319 (tosh_bios & 0xff00)>>8, 317 (tosh_bios & 0xff00)>>8,
320 tosh_bios & 0xff, 318 tosh_bios & 0xff,
321 tosh_date, 319 tosh_date,
322 key); 320 key);
323 return 0; <<
324 } <<
325 321
326 static int proc_toshiba_open(struct inode *ino !! 322 return temp-buffer;
327 { <<
328 return single_open(file, proc_toshiba_ <<
329 } 323 }
330 <<
331 static const struct file_operations proc_toshi <<
332 .owner = THIS_MODULE, <<
333 .open = proc_toshiba_open, <<
334 .read = seq_read, <<
335 .llseek = seq_lseek, <<
336 .release = single_release, <<
337 }; <<
338 #endif 324 #endif
339 325
340 326
341 /* 327 /*
342 * Determine which port to use for the Fn key 328 * Determine which port to use for the Fn key status
343 */ 329 */
344 static void tosh_set_fn_port(void) 330 static void tosh_set_fn_port(void)
345 { 331 {
346 switch (tosh_id) { 332 switch (tosh_id) {
347 case 0xfc02: case 0xfc04: case 333 case 0xfc02: case 0xfc04: case 0xfc09: case 0xfc0a: case 0xfc10:
348 case 0xfc11: case 0xfc13: case 334 case 0xfc11: case 0xfc13: case 0xfc15: case 0xfc1a: case 0xfc1b:
349 case 0xfc5a: 335 case 0xfc5a:
350 tosh_fn = 0x62; 336 tosh_fn = 0x62;
351 break; 337 break;
352 case 0xfc08: case 0xfc17: case 338 case 0xfc08: case 0xfc17: case 0xfc1d: case 0xfcd1: case 0xfce0:
353 case 0xfce2: 339 case 0xfce2:
354 tosh_fn = 0x68; 340 tosh_fn = 0x68;
355 break; 341 break;
356 default: 342 default:
357 tosh_fn = 0x00; 343 tosh_fn = 0x00;
358 break; 344 break;
359 } 345 }
360 346
361 return; 347 return;
362 } 348 }
363 349
364 350
365 /* 351 /*
366 * Get the machine identification number of th 352 * Get the machine identification number of the current model
367 */ 353 */
368 static int tosh_get_machine_id(void __iomem *b !! 354 static int tosh_get_machine_id(void)
369 { 355 {
370 int id; 356 int id;
371 SMMRegisters regs; 357 SMMRegisters regs;
372 unsigned short bx,cx; 358 unsigned short bx,cx;
373 unsigned long address; 359 unsigned long address;
374 360
375 id = (0x100*(int) readb(bios+0xfffe))+ !! 361 id = (0x100*(int) isa_readb(0xffffe))+((int) isa_readb(0xffffa));
376 !! 362
377 /* do we have a SCTTable machine ident 363 /* do we have a SCTTable machine identication number on our hands */
378 364
379 if (id==0xfc2f) { 365 if (id==0xfc2f) {
380 366
381 /* start by getting a pointer 367 /* start by getting a pointer into the BIOS */
382 368
383 regs.eax = 0xc000; 369 regs.eax = 0xc000;
384 regs.ebx = 0x0000; 370 regs.ebx = 0x0000;
385 regs.ecx = 0x0000; 371 regs.ecx = 0x0000;
386 tosh_smm(®s); 372 tosh_smm(®s);
387 bx = (unsigned short) (regs.eb 373 bx = (unsigned short) (regs.ebx & 0xffff);
388 374
389 /* At this point in the Toshib 375 /* At this point in the Toshiba routines under MS Windows
390 the bx register holds 0xe6f 376 the bx register holds 0xe6f5. However my code is producing
391 a different value! For the 377 a different value! For the time being I will just fudge the
392 value. This has been verifi 378 value. This has been verified on a Satellite Pro 430CDT,
393 Tecra 750CDT, Tecra 780DVD 379 Tecra 750CDT, Tecra 780DVD and Satellite 310CDT. */
394 #if TOSH_DEBUG 380 #if TOSH_DEBUG
395 printk("toshiba: debugging ID 381 printk("toshiba: debugging ID ebx=0x%04x\n", regs.ebx);
396 #endif 382 #endif
397 bx = 0xe6f5; 383 bx = 0xe6f5;
398 384
399 /* now twiddle with our pointe 385 /* now twiddle with our pointer a bit */
400 386
401 address = bx; !! 387 address = 0x000f0000+bx;
402 cx = readw(bios + address); !! 388 cx = isa_readw(address);
403 address = 9+bx+cx; !! 389 address = 0x000f0009+bx+cx;
404 cx = readw(bios + address); !! 390 cx = isa_readw(address);
405 address = 0xa+cx; !! 391 address = 0x000f000a+cx;
406 cx = readw(bios + address); !! 392 cx = isa_readw(address);
407 393
408 /* now construct our machine i 394 /* now construct our machine identification number */
409 395
410 id = ((cx & 0xff)<<8)+((cx & 0 396 id = ((cx & 0xff)<<8)+((cx & 0xff00)>>8);
411 } 397 }
412 398
413 return id; 399 return id;
414 } 400 }
415 401
416 402
417 /* 403 /*
418 * Probe for the presence of a Toshiba laptop 404 * Probe for the presence of a Toshiba laptop
419 * 405 *
420 * returns and non-zero if unable to detect 406 * returns and non-zero if unable to detect the presence of a Toshiba
421 * laptop, otherwise zero and determines the 407 * laptop, otherwise zero and determines the Machine ID, BIOS version and
422 * date, and SCI version. 408 * date, and SCI version.
423 */ 409 */
424 static int tosh_probe(void) 410 static int tosh_probe(void)
425 { 411 {
426 int i,major,minor,day,year,month,flag; 412 int i,major,minor,day,year,month,flag;
427 unsigned char signature[7] = { 0x54,0x 413 unsigned char signature[7] = { 0x54,0x4f,0x53,0x48,0x49,0x42,0x41 };
428 SMMRegisters regs; 414 SMMRegisters regs;
429 void __iomem *bios = ioremap(0xf0000, <<
430 <<
431 if (!bios) <<
432 return -ENOMEM; <<
433 415
434 /* extra sanity check for the string " 416 /* extra sanity check for the string "TOSHIBA" in the BIOS because
435 some machines that are not Toshiba' 417 some machines that are not Toshiba's pass the next test */
436 418
437 for (i=0;i<7;i++) { 419 for (i=0;i<7;i++) {
438 if (readb(bios+0xe010+i)!=sign !! 420 if (isa_readb(0xfe010+i)!=signature[i]) {
439 printk("toshiba: not a 421 printk("toshiba: not a supported Toshiba laptop\n");
440 iounmap(bios); <<
441 return -ENODEV; 422 return -ENODEV;
442 } 423 }
443 } 424 }
444 425
445 /* call the Toshiba SCI support check 426 /* call the Toshiba SCI support check routine */
446 !! 427
447 regs.eax = 0xf0f0; 428 regs.eax = 0xf0f0;
448 regs.ebx = 0x0000; 429 regs.ebx = 0x0000;
449 regs.ecx = 0x0000; 430 regs.ecx = 0x0000;
450 flag = tosh_smm(®s); 431 flag = tosh_smm(®s);
451 432
452 /* if this is not a Toshiba laptop car 433 /* if this is not a Toshiba laptop carry flag is set and ah=0x86 */
453 434
454 if ((flag==1) || ((regs.eax & 0xff00)= 435 if ((flag==1) || ((regs.eax & 0xff00)==0x8600)) {
455 printk("toshiba: not a support 436 printk("toshiba: not a supported Toshiba laptop\n");
456 iounmap(bios); <<
457 return -ENODEV; 437 return -ENODEV;
458 } 438 }
459 439
460 /* if we get this far then we are runn 440 /* if we get this far then we are running on a Toshiba (probably)! */
461 441
462 tosh_sci = regs.edx & 0xffff; 442 tosh_sci = regs.edx & 0xffff;
463 !! 443
464 /* next get the machine ID of the curr 444 /* next get the machine ID of the current laptop */
465 445
466 tosh_id = tosh_get_machine_id(bios); !! 446 tosh_id = tosh_get_machine_id();
467 447
468 /* get the BIOS version */ 448 /* get the BIOS version */
469 449
470 major = readb(bios+0xe009)-''; !! 450 major = isa_readb(0xfe009)-'';
471 minor = ((readb(bios+0xe00b)-'')*10)+( !! 451 minor = ((isa_readb(0xfe00b)-'')*10)+(isa_readb(0xfe00c)-'');
472 tosh_bios = (major*0x100)+minor; 452 tosh_bios = (major*0x100)+minor;
473 453
474 /* get the BIOS date */ 454 /* get the BIOS date */
475 455
476 day = ((readb(bios+0xfff5)-'')*10)+(re !! 456 day = ((isa_readb(0xffff5)-'')*10)+(isa_readb(0xffff6)-'');
477 month = ((readb(bios+0xfff8)-'')*10)+( !! 457 month = ((isa_readb(0xffff8)-'')*10)+(isa_readb(0xffff9)-'');
478 year = ((readb(bios+0xfffb)-'')*10)+(r !! 458 year = ((isa_readb(0xffffb)-'')*10)+(isa_readb(0xffffc)-'');
479 tosh_date = (((year-90) & 0x1f)<<10) | 459 tosh_date = (((year-90) & 0x1f)<<10) | ((month & 0xf)<<6)
480 | ((day & 0x1f)<<1); 460 | ((day & 0x1f)<<1);
481 461
482 462
483 /* in theory we should check the ports 463 /* in theory we should check the ports we are going to use for the
484 fn key detection (and the fan on th 464 fn key detection (and the fan on the Portage 610/Tecra700), and
485 then request them to stop other dri 465 then request them to stop other drivers using them. However as
486 the keyboard driver grabs 0x60-0x6f 466 the keyboard driver grabs 0x60-0x6f and the pic driver grabs
487 0xa0-0xbf we can't. We just have to 467 0xa0-0xbf we can't. We just have to live dangerously and use the
488 ports anyway, oh boy! */ 468 ports anyway, oh boy! */
489 469
490 /* do we need to emulate the fan? */ 470 /* do we need to emulate the fan? */
491 471
492 if ((tosh_id==0xfccb) || (tosh_id==0xf 472 if ((tosh_id==0xfccb) || (tosh_id==0xfccc))
493 tosh_fan = 1; 473 tosh_fan = 1;
494 474
495 iounmap(bios); <<
496 <<
497 return 0; 475 return 0;
498 } 476 }
499 477
500 static int __init toshiba_init(void) !! 478 int __init tosh_init(void)
501 { 479 {
502 int retval; 480 int retval;
503 /* are we running on a Toshiba laptop 481 /* are we running on a Toshiba laptop */
504 482
505 if (tosh_probe()) !! 483 if (tosh_probe()!=0)
506 return -ENODEV; !! 484 return -EIO;
507 485
508 printk(KERN_INFO "Toshiba System Manag !! 486 printk(KERN_INFO "Toshiba System Managment Mode driver v"
>> 487 TOSH_VERSION"\n");
509 488
510 /* set the port to use for Fn status i 489 /* set the port to use for Fn status if not specified as a parameter */
511 if (tosh_fn==0x00) 490 if (tosh_fn==0x00)
512 tosh_set_fn_port(); 491 tosh_set_fn_port();
513 492
514 /* register the device file */ 493 /* register the device file */
515 retval = misc_register(&tosh_device); 494 retval = misc_register(&tosh_device);
516 if (retval < 0) !! 495 if(retval < 0)
517 return retval; 496 return retval;
518 497
519 #ifdef CONFIG_PROC_FS 498 #ifdef CONFIG_PROC_FS
520 { !! 499 /* register the proc entry */
521 struct proc_dir_entry *pde; !! 500 if(create_proc_info_entry("toshiba", 0, NULL, tosh_get_info) == NULL){
522 !! 501 misc_deregister(&tosh_device);
523 pde = create_proc_entry("toshi !! 502 return -ENOMEM;
524 if (!pde) { <<
525 misc_deregister(&tosh_ <<
526 return -ENOMEM; <<
527 } <<
528 pde->proc_fops = &proc_toshiba <<
529 } 503 }
530 #endif 504 #endif
531 505
532 return 0; 506 return 0;
533 } 507 }
534 508
535 static void __exit toshiba_exit(void) !! 509 #ifdef MODULE
>> 510 int init_module(void)
>> 511 {
>> 512 return tosh_init();
>> 513 }
>> 514
>> 515 void cleanup_module(void)
536 { 516 {
>> 517 /* remove the proc entry */
>> 518
537 remove_proc_entry("toshiba", NULL); 519 remove_proc_entry("toshiba", NULL);
>> 520
>> 521 /* unregister the device file */
>> 522
538 misc_deregister(&tosh_device); 523 misc_deregister(&tosh_device);
539 } 524 }
>> 525 #endif
540 526
541 module_init(toshiba_init); !! 527 MODULE_LICENSE("GPL");
542 module_exit(toshiba_exit); !! 528 MODULE_PARM_DESC(tosh_fn, "User specified Fn key detection port");
>> 529 MODULE_AUTHOR("Jonathan Buzzard <jonathan@buzzard.org.uk>");
>> 530 MODULE_DESCRIPTION("Toshiba laptop SMM driver");
>> 531 MODULE_SUPPORTED_DEVICE("toshiba");
543 532
544 533
|
This page was automatically generated by the
LXR engine.
|