2 * bioscalls.c - the lowlevel layer of the PnPBIOS driver
6 #include <linux/types.h>
7 #include <linux/module.h>
8 #include <linux/init.h>
9 #include <linux/linkage.h>
10 #include <linux/kernel.h>
11 #include <linux/pnpbios.h>
12 #include <linux/device.h>
13 #include <linux/pnp.h>
15 #include <linux/smp.h>
16 #include <linux/slab.h>
17 #include <linux/kmod.h>
18 #include <linux/completion.h>
19 #include <linux/spinlock.h>
23 #include <asm/system.h>
24 #include <asm/byteorder.h>
35 * These are some opcodes for a "static asmlinkage"
36 * As this code is *not* executed inside the linux kernel segment, but in a
37 * alias at offset 0, we need a far return that can not be compiled by
38 * default (please, prove me wrong! this is *really* ugly!)
39 * This is the only way to get the bios to return into the kernel code,
40 * because the bios code runs in 16 bit protected mode and therefore can only
41 * return to the caller if the call is within the first 64kB, and the linux
42 * kernel begins at offset 3GB...
45 asmlinkage
void pnp_bios_callfunc(void);
50 "pnp_bios_callfunc:\n"
55 " lcallw *pnp_bios_callpoint\n"
61 #define Q_SET_SEL(cpu, selname, address, size) \
63 struct desc_struct *gdt = get_cpu_gdt_table((cpu)); \
64 set_base(gdt[(selname) >> 3], __va((u32)(address))); \
65 set_limit(gdt[(selname) >> 3], size); \
68 #define Q2_SET_SEL(cpu, selname, address, size) \
70 struct desc_struct *gdt = get_cpu_gdt_table((cpu)); \
71 set_base(gdt[(selname) >> 3], (u32)(address)); \
72 set_limit(gdt[(selname) >> 3], size); \
75 static struct desc_struct bad_bios_desc
= { 0, 0x00409200 };
78 * At some point we want to use this stack frame pointer to unwind
79 * after PnP BIOS oopses.
82 u32 pnp_bios_fault_esp
;
83 u32 pnp_bios_fault_eip
;
84 u32 pnp_bios_is_utter_crap
= 0;
86 static spinlock_t pnp_bios_lock
;
93 static inline u16
call_pnp_bios(u16 func
, u16 arg1
, u16 arg2
, u16 arg3
,
94 u16 arg4
, u16 arg5
, u16 arg6
, u16 arg7
,
95 void *ts1_base
, u32 ts1_size
,
96 void *ts2_base
, u32 ts2_size
)
100 struct desc_struct save_desc_40
;
104 * PnP BIOSes are generally not terribly re-entrant.
105 * Also, don't rely on them to save everything correctly.
107 if(pnp_bios_is_utter_crap
)
108 return PNP_FUNCTION_NOT_SUPPORTED
;
111 save_desc_40
= get_cpu_gdt_table(cpu
)[0x40 / 8];
112 get_cpu_gdt_table(cpu
)[0x40 / 8] = bad_bios_desc
;
114 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
115 spin_lock_irqsave(&pnp_bios_lock
, flags
);
117 /* The lock prevents us bouncing CPU here */
119 Q2_SET_SEL(smp_processor_id(), PNP_TS1
, ts1_base
, ts1_size
);
121 Q2_SET_SEL(smp_processor_id(), PNP_TS2
, ts2_base
, ts2_size
);
123 __asm__
__volatile__(
132 "movl %%esp, pnp_bios_fault_esp\n\t"
133 "movl $1f, pnp_bios_fault_eip\n\t"
144 : "0" ((func
) | (((u32
)arg1
) << 16)),
145 "b" ((arg2
) | (((u32
)arg3
) << 16)),
146 "c" ((arg4
) | (((u32
)arg5
) << 16)),
147 "d" ((arg6
) | (((u32
)arg7
) << 16)),
152 spin_unlock_irqrestore(&pnp_bios_lock
, flags
);
154 get_cpu_gdt_table(cpu
)[0x40 / 8] = save_desc_40
;
157 /* If we get here and this is set then the PnP BIOS faulted on us. */
158 if(pnp_bios_is_utter_crap
)
160 printk(KERN_ERR
"PnPBIOS: Warning! Your PnP BIOS caused a fatal error. Attempting to continue\n");
161 printk(KERN_ERR
"PnPBIOS: You may need to reboot with the \"pnpbios=off\" option to operate stably\n");
162 printk(KERN_ERR
"PnPBIOS: Check with your vendor for an updated BIOS\n");
168 void pnpbios_print_status(const char * module
, u16 status
)
172 printk(KERN_ERR
"PnPBIOS: %s: function successful\n", module
);
174 case PNP_NOT_SET_STATICALLY
:
175 printk(KERN_ERR
"PnPBIOS: %s: unable to set static resources\n", module
);
177 case PNP_UNKNOWN_FUNCTION
:
178 printk(KERN_ERR
"PnPBIOS: %s: invalid function number passed\n", module
);
180 case PNP_FUNCTION_NOT_SUPPORTED
:
181 printk(KERN_ERR
"PnPBIOS: %s: function not supported on this system\n", module
);
183 case PNP_INVALID_HANDLE
:
184 printk(KERN_ERR
"PnPBIOS: %s: invalid handle\n", module
);
186 case PNP_BAD_PARAMETER
:
187 printk(KERN_ERR
"PnPBIOS: %s: invalid parameters were passed\n", module
);
190 printk(KERN_ERR
"PnPBIOS: %s: unable to set resources\n", module
);
192 case PNP_EVENTS_NOT_PENDING
:
193 printk(KERN_ERR
"PnPBIOS: %s: no events are pending\n", module
);
195 case PNP_SYSTEM_NOT_DOCKED
:
196 printk(KERN_ERR
"PnPBIOS: %s: the system is not docked\n", module
);
198 case PNP_NO_ISA_PNP_CARDS
:
199 printk(KERN_ERR
"PnPBIOS: %s: no isapnp cards are installed on this system\n", module
);
201 case PNP_UNABLE_TO_DETERMINE_DOCK_CAPABILITIES
:
202 printk(KERN_ERR
"PnPBIOS: %s: cannot determine the capabilities of the docking station\n", module
);
204 case PNP_CONFIG_CHANGE_FAILED_NO_BATTERY
:
205 printk(KERN_ERR
"PnPBIOS: %s: unable to undock, the system does not have a battery\n", module
);
207 case PNP_CONFIG_CHANGE_FAILED_RESOURCE_CONFLICT
:
208 printk(KERN_ERR
"PnPBIOS: %s: could not dock due to resource conflicts\n", module
);
210 case PNP_BUFFER_TOO_SMALL
:
211 printk(KERN_ERR
"PnPBIOS: %s: the buffer passed is too small\n", module
);
213 case PNP_USE_ESCD_SUPPORT
:
214 printk(KERN_ERR
"PnPBIOS: %s: use ESCD instead\n", module
);
216 case PNP_MESSAGE_NOT_SUPPORTED
:
217 printk(KERN_ERR
"PnPBIOS: %s: the message is unsupported\n", module
);
219 case PNP_HARDWARE_ERROR
:
220 printk(KERN_ERR
"PnPBIOS: %s: a hardware failure has occured\n", module
);
223 printk(KERN_ERR
"PnPBIOS: %s: unexpected status 0x%x\n", module
, status
);
230 * PnP BIOS Low Level Calls
233 #define PNP_GET_NUM_SYS_DEV_NODES 0x00
234 #define PNP_GET_SYS_DEV_NODE 0x01
235 #define PNP_SET_SYS_DEV_NODE 0x02
236 #define PNP_GET_EVENT 0x03
237 #define PNP_SEND_MESSAGE 0x04
238 #define PNP_GET_DOCKING_STATION_INFORMATION 0x05
239 #define PNP_SET_STATIC_ALLOCED_RES_INFO 0x09
240 #define PNP_GET_STATIC_ALLOCED_RES_INFO 0x0a
241 #define PNP_GET_APM_ID_TABLE 0x0b
242 #define PNP_GET_PNP_ISA_CONFIG_STRUC 0x40
243 #define PNP_GET_ESCD_INFO 0x41
244 #define PNP_READ_ESCD 0x42
245 #define PNP_WRITE_ESCD 0x43
248 * Call PnP BIOS with function 0x00, "get number of system device nodes"
250 static int __pnp_bios_dev_node_info(struct pnp_dev_node_info
*data
)
253 if (!pnp_bios_present())
254 return PNP_FUNCTION_NOT_SUPPORTED
;
255 status
= call_pnp_bios(PNP_GET_NUM_SYS_DEV_NODES
, 0, PNP_TS1
, 2, PNP_TS1
, PNP_DS
, 0, 0,
256 data
, sizeof(struct pnp_dev_node_info
), NULL
, 0);
257 data
->no_nodes
&= 0xff;
261 int pnp_bios_dev_node_info(struct pnp_dev_node_info
*data
)
263 int status
= __pnp_bios_dev_node_info( data
);
265 pnpbios_print_status( "dev_node_info", status
);
270 * Note that some PnP BIOSes (e.g., on Sony Vaio laptops) die a horrible
271 * death if they are asked to access the "current" configuration.
272 * Therefore, if it's a matter of indifference, it's better to call
273 * get_dev_node() and set_dev_node() with boot=1 rather than with boot=0.
277 * Call PnP BIOS with function 0x01, "get system device node"
278 * Input: *nodenum = desired node,
279 * boot = whether to get nonvolatile boot (!=0)
280 * or volatile current (0) config
281 * Output: *nodenum=next node or 0xff if no more nodes
283 static int __pnp_bios_get_dev_node(u8
*nodenum
, char boot
, struct pnp_bios_node
*data
)
286 if (!pnp_bios_present())
287 return PNP_FUNCTION_NOT_SUPPORTED
;
288 if ( !boot
&& pnpbios_dont_use_current_config
)
289 return PNP_FUNCTION_NOT_SUPPORTED
;
290 status
= call_pnp_bios(PNP_GET_SYS_DEV_NODE
, 0, PNP_TS1
, 0, PNP_TS2
, boot
? 2 : 1, PNP_DS
, 0,
291 nodenum
, sizeof(char), data
, 65536);
295 int pnp_bios_get_dev_node(u8
*nodenum
, char boot
, struct pnp_bios_node
*data
)
298 status
= __pnp_bios_get_dev_node( nodenum
, boot
, data
);
300 pnpbios_print_status( "get_dev_node", status
);
306 * Call PnP BIOS with function 0x02, "set system device node"
307 * Input: *nodenum = desired node,
308 * boot = whether to set nonvolatile boot (!=0)
309 * or volatile current (0) config
311 static int __pnp_bios_set_dev_node(u8 nodenum
, char boot
, struct pnp_bios_node
*data
)
314 if (!pnp_bios_present())
315 return PNP_FUNCTION_NOT_SUPPORTED
;
316 if ( !boot
&& pnpbios_dont_use_current_config
)
317 return PNP_FUNCTION_NOT_SUPPORTED
;
318 status
= call_pnp_bios(PNP_SET_SYS_DEV_NODE
, nodenum
, 0, PNP_TS1
, boot
? 2 : 1, PNP_DS
, 0, 0,
319 data
, 65536, NULL
, 0);
323 int pnp_bios_set_dev_node(u8 nodenum
, char boot
, struct pnp_bios_node
*data
)
326 status
= __pnp_bios_set_dev_node( nodenum
, boot
, data
);
328 pnpbios_print_status( "set_dev_node", status
);
331 if ( !boot
) { /* Update devlist */
332 status
= pnp_bios_get_dev_node( &nodenum
, boot
, data
);
341 * Call PnP BIOS with function 0x03, "get event"
343 static int pnp_bios_get_event(u16
*event
)
346 if (!pnp_bios_present())
347 return PNP_FUNCTION_NOT_SUPPORTED
;
348 status
= call_pnp_bios(PNP_GET_EVENT
, 0, PNP_TS1
, PNP_DS
, 0, 0 ,0 ,0,
349 event
, sizeof(u16
), NULL
, 0);
356 * Call PnP BIOS with function 0x04, "send message"
358 static int pnp_bios_send_message(u16 message
)
361 if (!pnp_bios_present())
362 return PNP_FUNCTION_NOT_SUPPORTED
;
363 status
= call_pnp_bios(PNP_SEND_MESSAGE
, message
, PNP_DS
, 0, 0, 0, 0, 0, 0, 0, 0, 0);
369 * Call PnP BIOS with function 0x05, "get docking station information"
371 int pnp_bios_dock_station_info(struct pnp_docking_station_info
*data
)
374 if (!pnp_bios_present())
375 return PNP_FUNCTION_NOT_SUPPORTED
;
376 status
= call_pnp_bios(PNP_GET_DOCKING_STATION_INFORMATION
, 0, PNP_TS1
, PNP_DS
, 0, 0, 0, 0,
377 data
, sizeof(struct pnp_docking_station_info
), NULL
, 0);
383 * Call PnP BIOS with function 0x09, "set statically allocated resource
386 static int pnp_bios_set_stat_res(char *info
)
389 if (!pnp_bios_present())
390 return PNP_FUNCTION_NOT_SUPPORTED
;
391 status
= call_pnp_bios(PNP_SET_STATIC_ALLOCED_RES_INFO
, 0, PNP_TS1
, PNP_DS
, 0, 0, 0, 0,
392 info
, *((u16
*) info
), 0, 0);
398 * Call PnP BIOS with function 0x0a, "get statically allocated resource
401 static int __pnp_bios_get_stat_res(char *info
)
404 if (!pnp_bios_present())
405 return PNP_FUNCTION_NOT_SUPPORTED
;
406 status
= call_pnp_bios(PNP_GET_STATIC_ALLOCED_RES_INFO
, 0, PNP_TS1
, PNP_DS
, 0, 0, 0, 0,
407 info
, 65536, NULL
, 0);
411 int pnp_bios_get_stat_res(char *info
)
414 status
= __pnp_bios_get_stat_res( info
);
416 pnpbios_print_status( "get_stat_res", status
);
422 * Call PnP BIOS with function 0x0b, "get APM id table"
424 static int pnp_bios_apm_id_table(char *table
, u16
*size
)
427 if (!pnp_bios_present())
428 return PNP_FUNCTION_NOT_SUPPORTED
;
429 status
= call_pnp_bios(PNP_GET_APM_ID_TABLE
, 0, PNP_TS2
, 0, PNP_TS1
, PNP_DS
, 0, 0,
430 table
, *size
, size
, sizeof(u16
));
436 * Call PnP BIOS with function 0x40, "get isa pnp configuration structure"
438 static int __pnp_bios_isapnp_config(struct pnp_isa_config_struc
*data
)
441 if (!pnp_bios_present())
442 return PNP_FUNCTION_NOT_SUPPORTED
;
443 status
= call_pnp_bios(PNP_GET_PNP_ISA_CONFIG_STRUC
, 0, PNP_TS1
, PNP_DS
, 0, 0, 0, 0,
444 data
, sizeof(struct pnp_isa_config_struc
), NULL
, 0);
448 int pnp_bios_isapnp_config(struct pnp_isa_config_struc
*data
)
451 status
= __pnp_bios_isapnp_config( data
);
453 pnpbios_print_status( "isapnp_config", status
);
458 * Call PnP BIOS with function 0x41, "get ESCD info"
460 static int __pnp_bios_escd_info(struct escd_info_struc
*data
)
463 if (!pnp_bios_present())
464 return ESCD_FUNCTION_NOT_SUPPORTED
;
465 status
= call_pnp_bios(PNP_GET_ESCD_INFO
, 0, PNP_TS1
, 2, PNP_TS1
, 4, PNP_TS1
, PNP_DS
,
466 data
, sizeof(struct escd_info_struc
), NULL
, 0);
470 int pnp_bios_escd_info(struct escd_info_struc
*data
)
473 status
= __pnp_bios_escd_info( data
);
475 pnpbios_print_status( "escd_info", status
);
480 * Call PnP BIOS function 0x42, "read ESCD"
481 * nvram_base is determined by calling escd_info
483 static int __pnp_bios_read_escd(char *data
, u32 nvram_base
)
486 if (!pnp_bios_present())
487 return ESCD_FUNCTION_NOT_SUPPORTED
;
488 status
= call_pnp_bios(PNP_READ_ESCD
, 0, PNP_TS1
, PNP_TS2
, PNP_DS
, 0, 0, 0,
489 data
, 65536, __va(nvram_base
), 65536);
493 int pnp_bios_read_escd(char *data
, u32 nvram_base
)
496 status
= __pnp_bios_read_escd( data
, nvram_base
);
498 pnpbios_print_status( "read_escd", status
);
504 * Call PnP BIOS function 0x43, "write ESCD"
506 static int pnp_bios_write_escd(char *data
, u32 nvram_base
)
509 if (!pnp_bios_present())
510 return ESCD_FUNCTION_NOT_SUPPORTED
;
511 status
= call_pnp_bios(PNP_WRITE_ESCD
, 0, PNP_TS1
, PNP_TS2
, PNP_DS
, 0, 0, 0,
512 data
, 65536, __va(nvram_base
), 65536);
522 void pnpbios_calls_init(union pnp_bios_install_struct
*header
)
525 spin_lock_init(&pnp_bios_lock
);
526 pnp_bios_callpoint
.offset
= header
->fields
.pm16offset
;
527 pnp_bios_callpoint
.segment
= PNP_CS16
;
529 set_base(bad_bios_desc
, __va((unsigned long)0x40 << 4));
530 _set_limit((char *)&bad_bios_desc
, 4095 - (0x40 << 4));
531 for (i
= 0; i
< NR_CPUS
; i
++) {
532 struct desc_struct
*gdt
= get_cpu_gdt_table(i
);
535 Q2_SET_SEL(i
, PNP_CS32
, &pnp_bios_callfunc
, 64 * 1024);
536 Q_SET_SEL(i
, PNP_CS16
, header
->fields
.pm16cseg
, 64 * 1024);
537 Q_SET_SEL(i
, PNP_DS
, header
->fields
.pm16dseg
, 64 * 1024);