Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * bioscalls.c - the lowlevel layer of the PnPBIOS driver |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | */ |
| 4 | |
| 5 | #include <linux/types.h> |
| 6 | #include <linux/module.h> |
| 7 | #include <linux/init.h> |
| 8 | #include <linux/linkage.h> |
| 9 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/device.h> |
| 11 | #include <linux/pnp.h> |
| 12 | #include <linux/mm.h> |
| 13 | #include <linux/smp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/kmod.h> |
| 15 | #include <linux/completion.h> |
| 16 | #include <linux/spinlock.h> |
| 17 | |
| 18 | #include <asm/page.h> |
| 19 | #include <asm/desc.h> |
| 20 | #include <asm/system.h> |
| 21 | #include <asm/byteorder.h> |
| 22 | |
| 23 | #include "pnpbios.h" |
| 24 | |
| 25 | static struct { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 26 | u16 offset; |
| 27 | u16 segment; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | } pnp_bios_callpoint; |
| 29 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | /* |
| 31 | * These are some opcodes for a "static asmlinkage" |
| 32 | * As this code is *not* executed inside the linux kernel segment, but in a |
| 33 | * alias at offset 0, we need a far return that can not be compiled by |
| 34 | * default (please, prove me wrong! this is *really* ugly!) |
| 35 | * This is the only way to get the bios to return into the kernel code, |
| 36 | * because the bios code runs in 16 bit protected mode and therefore can only |
| 37 | * return to the caller if the call is within the first 64kB, and the linux |
| 38 | * kernel begins at offset 3GB... |
| 39 | */ |
| 40 | |
| 41 | asmlinkage void pnp_bios_callfunc(void); |
| 42 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 43 | __asm__(".text \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | __ALIGN_STR "\n" |
| 45 | "pnp_bios_callfunc:\n" |
| 46 | " pushl %edx \n" |
| 47 | " pushl %ecx \n" |
| 48 | " pushl %ebx \n" |
| 49 | " pushl %eax \n" |
| 50 | " lcallw *pnp_bios_callpoint\n" |
| 51 | " addl $16, %esp \n" |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 52 | " lret \n" |
| 53 | ".previous \n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | #define Q2_SET_SEL(cpu, selname, address, size) \ |
| 56 | do { \ |
Akinobu Mita | 5759474 | 2009-07-19 00:11:06 +0900 | [diff] [blame] | 57 | struct desc_struct *gdt = get_cpu_gdt_table((cpu)); \ |
| 58 | set_desc_base(&gdt[(selname) >> 3], (u32)(address)); \ |
| 59 | set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | } while(0) |
| 61 | |
Akinobu Mita | c742531 | 2009-08-09 17:03:52 +0900 | [diff] [blame] | 62 | static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092, |
| 63 | (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
| 65 | /* |
| 66 | * At some point we want to use this stack frame pointer to unwind |
| 67 | * after PnP BIOS oopses. |
| 68 | */ |
| 69 | |
| 70 | u32 pnp_bios_fault_esp; |
| 71 | u32 pnp_bios_fault_eip; |
| 72 | u32 pnp_bios_is_utter_crap = 0; |
| 73 | |
| 74 | static spinlock_t pnp_bios_lock; |
| 75 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | /* |
| 77 | * Support Functions |
| 78 | */ |
| 79 | |
| 80 | static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3, |
| 81 | u16 arg4, u16 arg5, u16 arg6, u16 arg7, |
| 82 | void *ts1_base, u32 ts1_size, |
| 83 | void *ts2_base, u32 ts2_size) |
| 84 | { |
| 85 | unsigned long flags; |
| 86 | u16 status; |
| 87 | struct desc_struct save_desc_40; |
| 88 | int cpu; |
| 89 | |
| 90 | /* |
| 91 | * PnP BIOSes are generally not terribly re-entrant. |
| 92 | * Also, don't rely on them to save everything correctly. |
| 93 | */ |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 94 | if (pnp_bios_is_utter_crap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | return PNP_FUNCTION_NOT_SUPPORTED; |
| 96 | |
| 97 | cpu = get_cpu(); |
Zachary Amsden | 7c4cb60 | 2006-01-06 00:11:47 -0800 | [diff] [blame] | 98 | save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8]; |
| 99 | get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
| 101 | /* On some boxes IRQ's during PnP BIOS calls are deadly. */ |
| 102 | spin_lock_irqsave(&pnp_bios_lock, flags); |
| 103 | |
| 104 | /* The lock prevents us bouncing CPU here */ |
| 105 | if (ts1_size) |
| 106 | Q2_SET_SEL(smp_processor_id(), PNP_TS1, ts1_base, ts1_size); |
| 107 | if (ts2_size) |
| 108 | Q2_SET_SEL(smp_processor_id(), PNP_TS2, ts2_base, ts2_size); |
| 109 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 110 | __asm__ __volatile__("pushl %%ebp\n\t" |
| 111 | "pushl %%edi\n\t" |
| 112 | "pushl %%esi\n\t" |
| 113 | "pushl %%ds\n\t" |
| 114 | "pushl %%es\n\t" |
| 115 | "pushl %%fs\n\t" |
| 116 | "pushl %%gs\n\t" |
| 117 | "pushfl\n\t" |
| 118 | "movl %%esp, pnp_bios_fault_esp\n\t" |
| 119 | "movl $1f, pnp_bios_fault_eip\n\t" |
| 120 | "lcall %5,%6\n\t" |
| 121 | "1:popfl\n\t" |
| 122 | "popl %%gs\n\t" |
| 123 | "popl %%fs\n\t" |
| 124 | "popl %%es\n\t" |
| 125 | "popl %%ds\n\t" |
| 126 | "popl %%esi\n\t" |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 127 | "popl %%edi\n\t" |
| 128 | "popl %%ebp\n\t":"=a"(status) |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 129 | :"0"((func) | (((u32) arg1) << 16)), |
| 130 | "b"((arg2) | (((u32) arg3) << 16)), |
| 131 | "c"((arg4) | (((u32) arg5) << 16)), |
| 132 | "d"((arg6) | (((u32) arg7) << 16)), |
| 133 | "i"(PNP_CS32), "i"(0) |
| 134 | :"memory"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | spin_unlock_irqrestore(&pnp_bios_lock, flags); |
| 136 | |
Zachary Amsden | 7c4cb60 | 2006-01-06 00:11:47 -0800 | [diff] [blame] | 137 | get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | put_cpu(); |
| 139 | |
| 140 | /* If we get here and this is set then the PnP BIOS faulted on us. */ |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 141 | if (pnp_bios_is_utter_crap) { |
| 142 | printk(KERN_ERR |
| 143 | "PnPBIOS: Warning! Your PnP BIOS caused a fatal error. Attempting to continue\n"); |
| 144 | printk(KERN_ERR |
| 145 | "PnPBIOS: You may need to reboot with the \"pnpbios=off\" option to operate stably\n"); |
| 146 | printk(KERN_ERR |
| 147 | "PnPBIOS: Check with your vendor for an updated BIOS\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | return status; |
| 151 | } |
| 152 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 153 | void pnpbios_print_status(const char *module, u16 status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 155 | switch (status) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | case PNP_SUCCESS: |
| 157 | printk(KERN_ERR "PnPBIOS: %s: function successful\n", module); |
| 158 | break; |
| 159 | case PNP_NOT_SET_STATICALLY: |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 160 | printk(KERN_ERR "PnPBIOS: %s: unable to set static resources\n", |
| 161 | module); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | break; |
| 163 | case PNP_UNKNOWN_FUNCTION: |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 164 | printk(KERN_ERR "PnPBIOS: %s: invalid function number passed\n", |
| 165 | module); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | break; |
| 167 | case PNP_FUNCTION_NOT_SUPPORTED: |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 168 | printk(KERN_ERR |
| 169 | "PnPBIOS: %s: function not supported on this system\n", |
| 170 | module); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | break; |
| 172 | case PNP_INVALID_HANDLE: |
| 173 | printk(KERN_ERR "PnPBIOS: %s: invalid handle\n", module); |
| 174 | break; |
| 175 | case PNP_BAD_PARAMETER: |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 176 | printk(KERN_ERR "PnPBIOS: %s: invalid parameters were passed\n", |
| 177 | module); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | break; |
| 179 | case PNP_SET_FAILED: |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 180 | printk(KERN_ERR "PnPBIOS: %s: unable to set resources\n", |
| 181 | module); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | break; |
| 183 | case PNP_EVENTS_NOT_PENDING: |
| 184 | printk(KERN_ERR "PnPBIOS: %s: no events are pending\n", module); |
| 185 | break; |
| 186 | case PNP_SYSTEM_NOT_DOCKED: |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 187 | printk(KERN_ERR "PnPBIOS: %s: the system is not docked\n", |
| 188 | module); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | break; |
| 190 | case PNP_NO_ISA_PNP_CARDS: |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 191 | printk(KERN_ERR |
| 192 | "PnPBIOS: %s: no isapnp cards are installed on this system\n", |
| 193 | module); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | break; |
| 195 | case PNP_UNABLE_TO_DETERMINE_DOCK_CAPABILITIES: |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 196 | printk(KERN_ERR |
| 197 | "PnPBIOS: %s: cannot determine the capabilities of the docking station\n", |
| 198 | module); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | break; |
| 200 | case PNP_CONFIG_CHANGE_FAILED_NO_BATTERY: |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 201 | printk(KERN_ERR |
| 202 | "PnPBIOS: %s: unable to undock, the system does not have a battery\n", |
| 203 | module); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | break; |
| 205 | case PNP_CONFIG_CHANGE_FAILED_RESOURCE_CONFLICT: |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 206 | printk(KERN_ERR |
| 207 | "PnPBIOS: %s: could not dock due to resource conflicts\n", |
| 208 | module); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | break; |
| 210 | case PNP_BUFFER_TOO_SMALL: |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 211 | printk(KERN_ERR "PnPBIOS: %s: the buffer passed is too small\n", |
| 212 | module); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | break; |
| 214 | case PNP_USE_ESCD_SUPPORT: |
| 215 | printk(KERN_ERR "PnPBIOS: %s: use ESCD instead\n", module); |
| 216 | break; |
| 217 | case PNP_MESSAGE_NOT_SUPPORTED: |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 218 | printk(KERN_ERR "PnPBIOS: %s: the message is unsupported\n", |
| 219 | module); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | break; |
| 221 | case PNP_HARDWARE_ERROR: |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 222 | printk(KERN_ERR "PnPBIOS: %s: a hardware failure has occured\n", |
| 223 | module); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | break; |
| 225 | default: |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 226 | printk(KERN_ERR "PnPBIOS: %s: unexpected status 0x%x\n", module, |
| 227 | status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | break; |
| 229 | } |
| 230 | } |
| 231 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | /* |
| 233 | * PnP BIOS Low Level Calls |
| 234 | */ |
| 235 | |
| 236 | #define PNP_GET_NUM_SYS_DEV_NODES 0x00 |
| 237 | #define PNP_GET_SYS_DEV_NODE 0x01 |
| 238 | #define PNP_SET_SYS_DEV_NODE 0x02 |
| 239 | #define PNP_GET_EVENT 0x03 |
| 240 | #define PNP_SEND_MESSAGE 0x04 |
| 241 | #define PNP_GET_DOCKING_STATION_INFORMATION 0x05 |
| 242 | #define PNP_SET_STATIC_ALLOCED_RES_INFO 0x09 |
| 243 | #define PNP_GET_STATIC_ALLOCED_RES_INFO 0x0a |
| 244 | #define PNP_GET_APM_ID_TABLE 0x0b |
| 245 | #define PNP_GET_PNP_ISA_CONFIG_STRUC 0x40 |
| 246 | #define PNP_GET_ESCD_INFO 0x41 |
| 247 | #define PNP_READ_ESCD 0x42 |
| 248 | #define PNP_WRITE_ESCD 0x43 |
| 249 | |
| 250 | /* |
| 251 | * Call PnP BIOS with function 0x00, "get number of system device nodes" |
| 252 | */ |
| 253 | static int __pnp_bios_dev_node_info(struct pnp_dev_node_info *data) |
| 254 | { |
| 255 | u16 status; |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 256 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | if (!pnp_bios_present()) |
| 258 | return PNP_FUNCTION_NOT_SUPPORTED; |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 259 | status = call_pnp_bios(PNP_GET_NUM_SYS_DEV_NODES, 0, PNP_TS1, 2, |
| 260 | PNP_TS1, PNP_DS, 0, 0, data, |
| 261 | sizeof(struct pnp_dev_node_info), NULL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | data->no_nodes &= 0xff; |
| 263 | return status; |
| 264 | } |
| 265 | |
| 266 | int pnp_bios_dev_node_info(struct pnp_dev_node_info *data) |
| 267 | { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 268 | int status = __pnp_bios_dev_node_info(data); |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 269 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 270 | if (status) |
| 271 | pnpbios_print_status("dev_node_info", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | return status; |
| 273 | } |
| 274 | |
| 275 | /* |
| 276 | * Note that some PnP BIOSes (e.g., on Sony Vaio laptops) die a horrible |
| 277 | * death if they are asked to access the "current" configuration. |
| 278 | * Therefore, if it's a matter of indifference, it's better to call |
| 279 | * get_dev_node() and set_dev_node() with boot=1 rather than with boot=0. |
| 280 | */ |
| 281 | |
| 282 | /* |
| 283 | * Call PnP BIOS with function 0x01, "get system device node" |
| 284 | * Input: *nodenum = desired node, |
| 285 | * boot = whether to get nonvolatile boot (!=0) |
| 286 | * or volatile current (0) config |
| 287 | * Output: *nodenum=next node or 0xff if no more nodes |
| 288 | */ |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 289 | static int __pnp_bios_get_dev_node(u8 *nodenum, char boot, |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 290 | struct pnp_bios_node *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | { |
| 292 | u16 status; |
Zachary Amsden | 5fe9fe3c | 2006-01-06 00:11:55 -0800 | [diff] [blame] | 293 | u16 tmp_nodenum; |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 294 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | if (!pnp_bios_present()) |
| 296 | return PNP_FUNCTION_NOT_SUPPORTED; |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 297 | if (!boot && pnpbios_dont_use_current_config) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | return PNP_FUNCTION_NOT_SUPPORTED; |
Zachary Amsden | 5fe9fe3c | 2006-01-06 00:11:55 -0800 | [diff] [blame] | 299 | tmp_nodenum = *nodenum; |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 300 | status = call_pnp_bios(PNP_GET_SYS_DEV_NODE, 0, PNP_TS1, 0, PNP_TS2, |
| 301 | boot ? 2 : 1, PNP_DS, 0, &tmp_nodenum, |
| 302 | sizeof(tmp_nodenum), data, 65536); |
Zachary Amsden | 5fe9fe3c | 2006-01-06 00:11:55 -0800 | [diff] [blame] | 303 | *nodenum = tmp_nodenum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | return status; |
| 305 | } |
| 306 | |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 307 | int pnp_bios_get_dev_node(u8 *nodenum, char boot, struct pnp_bios_node *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | { |
| 309 | int status; |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 310 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 311 | status = __pnp_bios_get_dev_node(nodenum, boot, data); |
| 312 | if (status) |
| 313 | pnpbios_print_status("get_dev_node", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | return status; |
| 315 | } |
| 316 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | /* |
| 318 | * Call PnP BIOS with function 0x02, "set system device node" |
| 319 | * Input: *nodenum = desired node, |
| 320 | * boot = whether to set nonvolatile boot (!=0) |
| 321 | * or volatile current (0) config |
| 322 | */ |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 323 | static int __pnp_bios_set_dev_node(u8 nodenum, char boot, |
| 324 | struct pnp_bios_node *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | { |
| 326 | u16 status; |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 327 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | if (!pnp_bios_present()) |
| 329 | return PNP_FUNCTION_NOT_SUPPORTED; |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 330 | if (!boot && pnpbios_dont_use_current_config) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | return PNP_FUNCTION_NOT_SUPPORTED; |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 332 | status = call_pnp_bios(PNP_SET_SYS_DEV_NODE, nodenum, 0, PNP_TS1, |
| 333 | boot ? 2 : 1, PNP_DS, 0, 0, data, 65536, NULL, |
| 334 | 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | return status; |
| 336 | } |
| 337 | |
| 338 | int pnp_bios_set_dev_node(u8 nodenum, char boot, struct pnp_bios_node *data) |
| 339 | { |
| 340 | int status; |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 341 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 342 | status = __pnp_bios_set_dev_node(nodenum, boot, data); |
| 343 | if (status) { |
| 344 | pnpbios_print_status("set_dev_node", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | return status; |
| 346 | } |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 347 | if (!boot) { /* Update devlist */ |
| 348 | status = pnp_bios_get_dev_node(&nodenum, boot, data); |
| 349 | if (status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | return status; |
| 351 | } |
| 352 | return status; |
| 353 | } |
| 354 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | /* |
| 356 | * Call PnP BIOS with function 0x05, "get docking station information" |
| 357 | */ |
| 358 | int pnp_bios_dock_station_info(struct pnp_docking_station_info *data) |
| 359 | { |
| 360 | u16 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | if (!pnp_bios_present()) |
| 363 | return PNP_FUNCTION_NOT_SUPPORTED; |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 364 | status = call_pnp_bios(PNP_GET_DOCKING_STATION_INFORMATION, 0, PNP_TS1, |
| 365 | PNP_DS, 0, 0, 0, 0, data, |
| 366 | sizeof(struct pnp_docking_station_info), NULL, |
| 367 | 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | return status; |
| 369 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | |
| 371 | /* |
| 372 | * Call PnP BIOS with function 0x0a, "get statically allocated resource |
| 373 | * information" |
| 374 | */ |
| 375 | static int __pnp_bios_get_stat_res(char *info) |
| 376 | { |
| 377 | u16 status; |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 378 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | if (!pnp_bios_present()) |
| 380 | return PNP_FUNCTION_NOT_SUPPORTED; |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 381 | status = call_pnp_bios(PNP_GET_STATIC_ALLOCED_RES_INFO, 0, PNP_TS1, |
| 382 | PNP_DS, 0, 0, 0, 0, info, 65536, NULL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | return status; |
| 384 | } |
| 385 | |
| 386 | int pnp_bios_get_stat_res(char *info) |
| 387 | { |
| 388 | int status; |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 389 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 390 | status = __pnp_bios_get_stat_res(info); |
| 391 | if (status) |
| 392 | pnpbios_print_status("get_stat_res", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | return status; |
| 394 | } |
| 395 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | /* |
| 397 | * Call PnP BIOS with function 0x40, "get isa pnp configuration structure" |
| 398 | */ |
| 399 | static int __pnp_bios_isapnp_config(struct pnp_isa_config_struc *data) |
| 400 | { |
| 401 | u16 status; |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 402 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | if (!pnp_bios_present()) |
| 404 | return PNP_FUNCTION_NOT_SUPPORTED; |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 405 | status = call_pnp_bios(PNP_GET_PNP_ISA_CONFIG_STRUC, 0, PNP_TS1, PNP_DS, |
| 406 | 0, 0, 0, 0, data, |
| 407 | sizeof(struct pnp_isa_config_struc), NULL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | return status; |
| 409 | } |
| 410 | |
| 411 | int pnp_bios_isapnp_config(struct pnp_isa_config_struc *data) |
| 412 | { |
| 413 | int status; |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 414 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 415 | status = __pnp_bios_isapnp_config(data); |
| 416 | if (status) |
| 417 | pnpbios_print_status("isapnp_config", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | return status; |
| 419 | } |
| 420 | |
| 421 | /* |
| 422 | * Call PnP BIOS with function 0x41, "get ESCD info" |
| 423 | */ |
| 424 | static int __pnp_bios_escd_info(struct escd_info_struc *data) |
| 425 | { |
| 426 | u16 status; |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 427 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | if (!pnp_bios_present()) |
| 429 | return ESCD_FUNCTION_NOT_SUPPORTED; |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 430 | status = call_pnp_bios(PNP_GET_ESCD_INFO, 0, PNP_TS1, 2, PNP_TS1, 4, |
| 431 | PNP_TS1, PNP_DS, data, |
| 432 | sizeof(struct escd_info_struc), NULL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | return status; |
| 434 | } |
| 435 | |
| 436 | int pnp_bios_escd_info(struct escd_info_struc *data) |
| 437 | { |
| 438 | int status; |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 439 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 440 | status = __pnp_bios_escd_info(data); |
| 441 | if (status) |
| 442 | pnpbios_print_status("escd_info", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | return status; |
| 444 | } |
| 445 | |
| 446 | /* |
| 447 | * Call PnP BIOS function 0x42, "read ESCD" |
| 448 | * nvram_base is determined by calling escd_info |
| 449 | */ |
| 450 | static int __pnp_bios_read_escd(char *data, u32 nvram_base) |
| 451 | { |
| 452 | u16 status; |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 453 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | if (!pnp_bios_present()) |
| 455 | return ESCD_FUNCTION_NOT_SUPPORTED; |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 456 | status = call_pnp_bios(PNP_READ_ESCD, 0, PNP_TS1, PNP_TS2, PNP_DS, 0, 0, |
| 457 | 0, data, 65536, __va(nvram_base), 65536); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | return status; |
| 459 | } |
| 460 | |
| 461 | int pnp_bios_read_escd(char *data, u32 nvram_base) |
| 462 | { |
| 463 | int status; |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 464 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 465 | status = __pnp_bios_read_escd(data, nvram_base); |
| 466 | if (status) |
| 467 | pnpbios_print_status("read_escd", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | return status; |
| 469 | } |
| 470 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | void pnpbios_calls_init(union pnp_bios_install_struct *header) |
| 472 | { |
| 473 | int i; |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 474 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | spin_lock_init(&pnp_bios_lock); |
| 476 | pnp_bios_callpoint.offset = header->fields.pm16offset; |
| 477 | pnp_bios_callpoint.segment = PNP_CS16; |
| 478 | |
Rusty Russell | 6aaa8ce | 2009-01-01 10:12:14 +1030 | [diff] [blame] | 479 | for_each_possible_cpu(i) { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 480 | struct desc_struct *gdt = get_cpu_gdt_table(i); |
| 481 | if (!gdt) |
| 482 | continue; |
Akinobu Mita | 5759474 | 2009-07-19 00:11:06 +0900 | [diff] [blame] | 483 | set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_CS32], |
| 484 | (unsigned long)&pnp_bios_callfunc); |
| 485 | set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_CS16], |
| 486 | (unsigned long)__va(header->fields.pm16cseg)); |
| 487 | set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS], |
| 488 | (unsigned long)__va(header->fields.pm16dseg)); |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 489 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | } |