aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/watchdog
diff options
context:
space:
mode:
authorRoland Dreier <rdreier@cisco.com>2008-02-28 15:34:42 -0500
committerWim Van Sebroeck <wim@iguana.be>2008-03-06 06:10:53 -0500
commit30ec910e02b35e7c3d600af694a5aec4b6690ddc (patch)
tree5d482c467bbd615ff3008ecea70322b67e5ee7bc /drivers/watchdog
parentef82710a3f80cd24d459c508f91542ecccb1f340 (diff)
[WATCHDOG] hpwdt: Use dmi_walk() instead of own copy
We can simplify the code by deleting all of the duplicated DMI table walking code and using the kernel's existing dmi_walk() interface to find the DMI entry the driver is looking for. Signed-off-by: Roland Dreier <rolandd@cisco.com> Acked-by: Thomas Mingarelli <Thomas.Mingarelli@hp.com> Signed-off-by: Wim Van Sebroeck <wim@iguana.be> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'drivers/watchdog')
-rw-r--r--drivers/watchdog/hpwdt.c203
1 files changed, 20 insertions, 183 deletions
diff --git a/drivers/watchdog/hpwdt.c b/drivers/watchdog/hpwdt.c
index b1cd0aca9b3c..2686f3eaeedf 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 */
79struct 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 u32 table_address;
92 u16 table_num_structs;
93 u8 bcd_revision;
94};
95
96/* type 212 */ 61/* type 212 */
97struct smbios_cru64_info { 62struct smbios_cru64_info {
98 u8 type; 63 u8 type;
@@ -175,24 +140,6 @@ static struct pci_device_id hpwdt_devices[] = {
175}; 140};
176MODULE_DEVICE_TABLE(pci, hpwdt_devices); 141MODULE_DEVICE_TABLE(pci, hpwdt_devices);
177 142
178/*
179 * bios_checksum
180 */
181static 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
@@ -303,6 +250,24 @@ static int __devinit cru_detect(unsigned long map_entry,
303} 250}
304 251
305/* 252/*
253 * bios_checksum
254 */
255static 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:
@@ -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 */
420static void __devinit dmi_find_cru(const struct dmi_header *dm) 381static void __devinit dmi_find_cru(const struct dmi_header *dm)
421{ 382{
@@ -434,135 +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 */
447static 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 */
486static 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
531static void __devinit smbios_scan_machine(void)
532{
533 char __iomem *p, *q;
534
535 if (efi_enabled) {
536 if (efi.smbios == EFI_INVALID_TABLE_ADDR)
537 return;
538
539 p = ioremap(efi.smbios, 32);
540 if (p == NULL)
541 return;
542
543 smbios_present(p);
544 iounmap(p);
545 } else {
546 /*
547 * Search from 0x0f0000 through 0x0fffff, inclusive.
548 */
549 p = ioremap(PCI_ROM_BASE1, ROM_SIZE);
550 if (p == NULL)
551 return;
552
553 for (q = p; q < p + ROM_SIZE; q += 16)
554 if (!smbios_present(q))
555 break;
556
557 iounmap(p);
558 }
559}
560
561static int __devinit detect_cru_service(void) 398static int __devinit detect_cru_service(void)
562{ 399{
563 cru_rom_addr = NULL; 400 cru_rom_addr = NULL;
564 401
565 smbios_scan_machine(); /* will become dmi_walk(dmi_find_cru); */ 402 dmi_walk(dmi_find_cru);
566 403
567 /* 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 */
568 return ((cru_rom_addr != NULL)? 0: -ENODEV); 405 return ((cru_rom_addr != NULL)? 0: -ENODEV);