diff options
Diffstat (limited to 'drivers/watchdog/hpwdt.c')
-rw-r--r-- | drivers/watchdog/hpwdt.c | 214 |
1 files changed, 24 insertions, 190 deletions
diff --git a/drivers/watchdog/hpwdt.c b/drivers/watchdog/hpwdt.c index a2e174b09fe7..6483d1066b95 100644 --- a/drivers/watchdog/hpwdt.c +++ b/drivers/watchdog/hpwdt.c | |||
@@ -58,41 +58,6 @@ struct bios32_service_dir { | |||
58 | u8 reserved[5]; | 58 | u8 reserved[5]; |
59 | }; | 59 | }; |
60 | 60 | ||
61 | /* | ||
62 | * smbios_entry_point - defines SMBIOS entry point structure | ||
63 | * | ||
64 | * anchor[4] - anchor string (_SM_) | ||
65 | * checksum - checksum of the entry point structure | ||
66 | * length - length of the entry point structure | ||
67 | * major_ver - major version (02h for revision 2.1) | ||
68 | * minor_ver - minor version (01h for revision 2.1) | ||
69 | * max_struct_size - size of the largest SMBIOS structure | ||
70 | * revision - entry point structure revision implemented | ||
71 | * formatted_area[5] - reserved | ||
72 | * intermediate_anchor[5] - intermediate anchor string (_DMI_) | ||
73 | * intermediate_checksum - intermediate checksum | ||
74 | * table_length - structure table length | ||
75 | * table_address - structure table address | ||
76 | * table_num_structs - number of SMBIOS structures present | ||
77 | * bcd_revision - BCD revision | ||
78 | */ | ||
79 | struct smbios_entry_point { | ||
80 | u8 anchor[4]; | ||
81 | u8 checksum; | ||
82 | u8 length; | ||
83 | u8 major_ver; | ||
84 | u8 minor_ver; | ||
85 | u16 max_struct_size; | ||
86 | u8 revision; | ||
87 | u8 formatted_area[5]; | ||
88 | u8 intermediate_anchor[5]; | ||
89 | u8 intermediate_checksum; | ||
90 | u16 table_length; | ||
91 | u64 table_address; | ||
92 | u16 table_num_structs; | ||
93 | u8 bcd_revision; | ||
94 | }; | ||
95 | |||
96 | /* type 212 */ | 61 | /* type 212 */ |
97 | struct smbios_cru64_info { | 62 | struct smbios_cru64_info { |
98 | u8 type; | 63 | u8 type; |
@@ -175,31 +140,13 @@ static struct pci_device_id hpwdt_devices[] = { | |||
175 | }; | 140 | }; |
176 | MODULE_DEVICE_TABLE(pci, hpwdt_devices); | 141 | MODULE_DEVICE_TABLE(pci, hpwdt_devices); |
177 | 142 | ||
178 | /* | ||
179 | * bios_checksum | ||
180 | */ | ||
181 | static int __devinit bios_checksum(const char __iomem *ptr, int len) | ||
182 | { | ||
183 | char sum = 0; | ||
184 | int i; | ||
185 | |||
186 | /* | ||
187 | * calculate checksum of size bytes. This should add up | ||
188 | * to zero if we have a valid header. | ||
189 | */ | ||
190 | for (i = 0; i < len; i++) | ||
191 | sum += ptr[i]; | ||
192 | |||
193 | return ((sum == 0) && (len > 0)); | ||
194 | } | ||
195 | |||
196 | #ifndef CONFIG_X86_64 | 143 | #ifndef CONFIG_X86_64 |
197 | /* --32 Bit Bios------------------------------------------------------------ */ | 144 | /* --32 Bit Bios------------------------------------------------------------ */ |
198 | 145 | ||
199 | #define HPWDT_ARCH 32 | 146 | #define HPWDT_ARCH 32 |
200 | 147 | ||
201 | asmlinkage void asminline_call(struct cmn_registers *pi86Regs, | 148 | static void asminline_call(struct cmn_registers *pi86Regs, |
202 | unsigned long *pRomEntry) | 149 | unsigned long *pRomEntry) |
203 | { | 150 | { |
204 | asm("pushl %ebp \n\t" | 151 | asm("pushl %ebp \n\t" |
205 | "movl %esp, %ebp \n\t" | 152 | "movl %esp, %ebp \n\t" |
@@ -303,6 +250,24 @@ static int __devinit cru_detect(unsigned long map_entry, | |||
303 | } | 250 | } |
304 | 251 | ||
305 | /* | 252 | /* |
253 | * bios_checksum | ||
254 | */ | ||
255 | static int __devinit bios_checksum(const char __iomem *ptr, int len) | ||
256 | { | ||
257 | char sum = 0; | ||
258 | int i; | ||
259 | |||
260 | /* | ||
261 | * calculate checksum of size bytes. This should add up | ||
262 | * to zero if we have a valid header. | ||
263 | */ | ||
264 | for (i = 0; i < len; i++) | ||
265 | sum += ptr[i]; | ||
266 | |||
267 | return ((sum == 0) && (len > 0)); | ||
268 | } | ||
269 | |||
270 | /* | ||
306 | * bios32_present | 271 | * bios32_present |
307 | * | 272 | * |
308 | * Routine Description: | 273 | * Routine Description: |
@@ -368,8 +333,8 @@ static int __devinit detect_cru_service(void) | |||
368 | 333 | ||
369 | #define HPWDT_ARCH 64 | 334 | #define HPWDT_ARCH 64 |
370 | 335 | ||
371 | asmlinkage void asminline_call(struct cmn_registers *pi86Regs, | 336 | static void asminline_call(struct cmn_registers *pi86Regs, |
372 | unsigned long *pRomEntry) | 337 | unsigned long *pRomEntry) |
373 | { | 338 | { |
374 | asm("pushq %rbp \n\t" | 339 | asm("pushq %rbp \n\t" |
375 | "movq %rsp, %rbp \n\t" | 340 | "movq %rsp, %rbp \n\t" |
@@ -410,12 +375,8 @@ asmlinkage void asminline_call(struct cmn_registers *pi86Regs, | |||
410 | * dmi_find_cru | 375 | * dmi_find_cru |
411 | * | 376 | * |
412 | * Routine Description: | 377 | * Routine Description: |
413 | * This function checks wether or not a SMBIOS/DMI record is | 378 | * This function checks whether or not a SMBIOS/DMI record is |
414 | * the 64bit CRU info or not | 379 | * the 64bit CRU info or not |
415 | * | ||
416 | * Return Value: | ||
417 | * 0 : SUCCESS - if record found | ||
418 | * <0 : FAILURE - if record not found | ||
419 | */ | 380 | */ |
420 | static void __devinit dmi_find_cru(const struct dmi_header *dm) | 381 | static void __devinit dmi_find_cru(const struct dmi_header *dm) |
421 | { | 382 | { |
@@ -434,138 +395,11 @@ static void __devinit dmi_find_cru(const struct dmi_header *dm) | |||
434 | } | 395 | } |
435 | } | 396 | } |
436 | 397 | ||
437 | /* | ||
438 | * dmi_table | ||
439 | * | ||
440 | * Routine Description: | ||
441 | * Decode the SMBIOS/DMI table and check if we have a 64bit CRU record | ||
442 | * or not. | ||
443 | * | ||
444 | * We have to be cautious here. We have seen BIOSes with DMI pointers | ||
445 | * pointing to completely the wrong place for example | ||
446 | */ | ||
447 | static void __devinit dmi_table(u8 *buf, int len, int num, | ||
448 | void (*decode)(const struct dmi_header *)) | ||
449 | { | ||
450 | u8 *data = buf; | ||
451 | int i = 0; | ||
452 | |||
453 | /* | ||
454 | * Stop when we see all the items the table claimed to have | ||
455 | * OR we run off the end of the table (also happens) | ||
456 | */ | ||
457 | while ((i < num) && (data - buf + sizeof(struct dmi_header)) <= len) { | ||
458 | const struct dmi_header *dm = (const struct dmi_header *)data; | ||
459 | |||
460 | /* | ||
461 | * We want to know the total length (formated area and strings) | ||
462 | * before decoding to make sure we won't run off the table in | ||
463 | * dmi_decode or dmi_string | ||
464 | */ | ||
465 | data += dm->length; | ||
466 | while ((data - buf < len - 1) && (data[0] || data[1])) | ||
467 | data++; | ||
468 | if (data - buf < len - 1) | ||
469 | decode(dm); | ||
470 | data += 2; | ||
471 | i++; | ||
472 | } | ||
473 | } | ||
474 | |||
475 | /* | ||
476 | * smbios_present | ||
477 | * | ||
478 | * Routine Description: | ||
479 | * This function parses the SMBIOS entry point table to retrieve | ||
480 | * the 64 bit CRU Service. | ||
481 | * | ||
482 | * Return Value: | ||
483 | * 0 : SUCCESS | ||
484 | * <0 : FAILURE | ||
485 | */ | ||
486 | static int __devinit smbios_present(const char __iomem *p) | ||
487 | { | ||
488 | struct smbios_entry_point *eps = | ||
489 | (struct smbios_entry_point *) p; | ||
490 | int length; | ||
491 | u8 *buf; | ||
492 | |||
493 | /* check if we have indeed the SMBIOS table entry point */ | ||
494 | if ((strncmp((char *)eps->anchor, "_SM_", | ||
495 | sizeof(eps->anchor))) == 0) { | ||
496 | length = eps->length; | ||
497 | |||
498 | /* SMBIOS v2.1 implementation might use 0x1e */ | ||
499 | if ((length == 0x1e) && | ||
500 | (eps->major_ver == 2) && | ||
501 | (eps->minor_ver == 1)) | ||
502 | length = 0x1f; | ||
503 | |||
504 | /* | ||
505 | * Now we will check: | ||
506 | * - SMBIOS checksum must be 0 | ||
507 | * - intermediate anchor should be _DMI_ | ||
508 | * - intermediate checksum should be 0 | ||
509 | */ | ||
510 | if ((bios_checksum(p, length)) && | ||
511 | (strncmp((char *)eps->intermediate_anchor, "_DMI_", | ||
512 | sizeof(eps->intermediate_anchor)) == 0) && | ||
513 | (bios_checksum(p+0x10, 15))) { | ||
514 | buf = ioremap(eps->table_address, eps->table_length); | ||
515 | if (buf == NULL) | ||
516 | return -ENODEV; | ||
517 | |||
518 | |||
519 | /* Scan the DMI table for the 64 bit CRU service */ | ||
520 | dmi_table(buf, eps->table_length, | ||
521 | eps->table_num_structs, dmi_find_cru); | ||
522 | |||
523 | iounmap(buf); | ||
524 | return 0; | ||
525 | } | ||
526 | } | ||
527 | |||
528 | return -ENODEV; | ||
529 | } | ||
530 | |||
531 | static int __devinit smbios_scan_machine(void) | ||
532 | { | ||
533 | char __iomem *p, *q; | ||
534 | int rc; | ||
535 | |||
536 | if (efi_enabled) { | ||
537 | if (efi.smbios == EFI_INVALID_TABLE_ADDR) | ||
538 | return -ENODEV; | ||
539 | |||
540 | p = ioremap(efi.smbios, 32); | ||
541 | if (p == NULL) | ||
542 | return -ENOMEM; | ||
543 | |||
544 | rc = smbios_present(p); | ||
545 | iounmap(p); | ||
546 | } else { | ||
547 | /* | ||
548 | * Search from 0x0f0000 through 0x0fffff, inclusive. | ||
549 | */ | ||
550 | p = ioremap(PCI_ROM_BASE1, ROM_SIZE); | ||
551 | if (p == NULL) | ||
552 | return -ENOMEM; | ||
553 | |||
554 | for (q = p; q < p + ROM_SIZE; q += 16) { | ||
555 | rc = smbios_present(q); | ||
556 | if (!rc) { | ||
557 | break; | ||
558 | } | ||
559 | } | ||
560 | iounmap(p); | ||
561 | } | ||
562 | } | ||
563 | |||
564 | static int __devinit detect_cru_service(void) | 398 | static int __devinit detect_cru_service(void) |
565 | { | 399 | { |
566 | cru_rom_addr = NULL; | 400 | cru_rom_addr = NULL; |
567 | 401 | ||
568 | smbios_scan_machine(); /* will become dmi_walk(dmi_find_cru); */ | 402 | dmi_walk(dmi_find_cru); |
569 | 403 | ||
570 | /* if cru_rom_addr has been set then we found a CRU service */ | 404 | /* if cru_rom_addr has been set then we found a CRU service */ |
571 | return ((cru_rom_addr != NULL)? 0: -ENODEV); | 405 | return ((cru_rom_addr != NULL)? 0: -ENODEV); |