1 #include <linux/types.h>
2 #include <linux/string.h>
3 #include <linux/init.h>
4 #include <linux/module.h>
5 #include <linux/ctype.h>
8 #include <linux/bootmem.h>
9 #include <linux/random.h>
11 #include <asm/unaligned.h>
13 struct kobject
*dmi_kobj
;
14 EXPORT_SYMBOL_GPL(dmi_kobj
);
17 * DMI stands for "Desktop Management Interface". It is part
18 * of and an antecedent to, SMBIOS, which stands for System
19 * Management BIOS. See further: http://www.dmtf.org/standards
21 static const char dmi_empty_string
[] = "";
23 static u32 dmi_ver __initdata
;
26 static u8 smbios_entry_point
[32];
27 static int smbios_entry_point_size
;
30 * Catch too early calls to dmi_check_system():
32 static int dmi_initialized
;
34 /* DMI system identification string used during boot */
35 static char dmi_ids_string
[128] __initdata
;
37 static struct dmi_memdev_info
{
42 static int dmi_memdev_nr
;
44 static const char * __init
dmi_string_nosave(const struct dmi_header
*dm
, u8 s
)
46 const u8
*bp
= ((u8
*) dm
) + dm
->length
;
50 while (--s
> 0 && *bp
)
53 /* Strings containing only spaces are considered empty */
61 return dmi_empty_string
;
64 static const char * __init
dmi_string(const struct dmi_header
*dm
, u8 s
)
66 const char *bp
= dmi_string_nosave(dm
, s
);
70 if (bp
== dmi_empty_string
)
71 return dmi_empty_string
;
82 * We have to be cautious here. We have seen BIOSes with DMI pointers
83 * pointing to completely the wrong place for example
85 static void dmi_decode_table(u8
*buf
,
86 void (*decode
)(const struct dmi_header
*, void *),
93 * Stop when we have seen all the items the table claimed to have
94 * (SMBIOS < 3.0 only) OR we reach an end-of-table marker (SMBIOS
95 * >= 3.0 only) OR we run off the end of the table (should never
96 * happen but sometimes does on bogus implementations.)
98 while ((!dmi_num
|| i
< dmi_num
) &&
99 (data
- buf
+ sizeof(struct dmi_header
)) <= dmi_len
) {
100 const struct dmi_header
*dm
= (const struct dmi_header
*)data
;
103 * We want to know the total length (formatted area and
104 * strings) before decoding to make sure we won't run off the
105 * table in dmi_decode or dmi_string
108 while ((data
- buf
< dmi_len
- 1) && (data
[0] || data
[1]))
110 if (data
- buf
< dmi_len
- 1)
111 decode(dm
, private_data
);
117 * 7.45 End-of-Table (Type 127) [SMBIOS reference spec v3.0.0]
118 * For tables behind a 64-bit entry point, we have no item
119 * count and no exact table length, so stop on end-of-table
120 * marker. For tables behind a 32-bit entry point, we have
121 * seen OEM structures behind the end-of-table marker on
122 * some systems, so don't trust it.
124 if (!dmi_num
&& dm
->type
== DMI_ENTRY_END_OF_TABLE
)
128 /* Trim DMI table length if needed */
129 if (dmi_len
> data
- buf
)
130 dmi_len
= data
- buf
;
133 static phys_addr_t dmi_base
;
135 static int __init
dmi_walk_early(void (*decode
)(const struct dmi_header
*,
139 u32 orig_dmi_len
= dmi_len
;
141 buf
= dmi_early_remap(dmi_base
, orig_dmi_len
);
145 dmi_decode_table(buf
, decode
, NULL
);
147 add_device_randomness(buf
, dmi_len
);
149 dmi_early_unmap(buf
, orig_dmi_len
);
153 static int __init
dmi_checksum(const u8
*buf
, u8 len
)
158 for (a
= 0; a
< len
; a
++)
164 static const char *dmi_ident
[DMI_STRING_MAX
];
165 static LIST_HEAD(dmi_devices
);
171 static void __init
dmi_save_ident(const struct dmi_header
*dm
, int slot
,
174 const char *d
= (const char *) dm
;
177 if (dmi_ident
[slot
] || dm
->length
<= string
)
180 p
= dmi_string(dm
, d
[string
]);
187 static void __init
dmi_save_uuid(const struct dmi_header
*dm
, int slot
,
192 int is_ff
= 1, is_00
= 1, i
;
194 if (dmi_ident
[slot
] || dm
->length
< index
+ 16)
197 d
= (u8
*) dm
+ index
;
198 for (i
= 0; i
< 16 && (is_ff
|| is_00
); i
++) {
208 s
= dmi_alloc(16*2+4+1);
213 * As of version 2.6 of the SMBIOS specification, the first 3 fields of
214 * the UUID are supposed to be little-endian encoded. The specification
215 * says that this is the defacto standard.
217 if (dmi_ver
>= 0x020600)
218 sprintf(s
, "%pUL", d
);
220 sprintf(s
, "%pUB", d
);
225 static void __init
dmi_save_type(const struct dmi_header
*dm
, int slot
,
231 if (dmi_ident
[slot
] || dm
->length
<= index
)
238 d
= (u8
*) dm
+ index
;
239 sprintf(s
, "%u", *d
& 0x7F);
243 static void __init
dmi_save_one_device(int type
, const char *name
)
245 struct dmi_device
*dev
;
247 /* No duplicate device */
248 if (dmi_find_device(type
, name
, NULL
))
251 dev
= dmi_alloc(sizeof(*dev
) + strlen(name
) + 1);
256 strcpy((char *)(dev
+ 1), name
);
257 dev
->name
= (char *)(dev
+ 1);
258 dev
->device_data
= NULL
;
259 list_add(&dev
->list
, &dmi_devices
);
262 static void __init
dmi_save_devices(const struct dmi_header
*dm
)
264 int i
, count
= (dm
->length
- sizeof(struct dmi_header
)) / 2;
266 for (i
= 0; i
< count
; i
++) {
267 const char *d
= (char *)(dm
+ 1) + (i
* 2);
269 /* Skip disabled device */
270 if ((*d
& 0x80) == 0)
273 dmi_save_one_device(*d
& 0x7f, dmi_string_nosave(dm
, *(d
+ 1)));
277 static void __init
dmi_save_oem_strings_devices(const struct dmi_header
*dm
)
280 struct dmi_device
*dev
;
282 if (dm
->length
< 0x05)
285 count
= *(u8
*)(dm
+ 1);
286 for (i
= 1; i
<= count
; i
++) {
287 const char *devname
= dmi_string(dm
, i
);
289 if (devname
== dmi_empty_string
)
292 dev
= dmi_alloc(sizeof(*dev
));
296 dev
->type
= DMI_DEV_TYPE_OEM_STRING
;
298 dev
->device_data
= NULL
;
300 list_add(&dev
->list
, &dmi_devices
);
304 static void __init
dmi_save_ipmi_device(const struct dmi_header
*dm
)
306 struct dmi_device
*dev
;
309 data
= dmi_alloc(dm
->length
);
313 memcpy(data
, dm
, dm
->length
);
315 dev
= dmi_alloc(sizeof(*dev
));
319 dev
->type
= DMI_DEV_TYPE_IPMI
;
320 dev
->name
= "IPMI controller";
321 dev
->device_data
= data
;
323 list_add_tail(&dev
->list
, &dmi_devices
);
326 static void __init
dmi_save_dev_pciaddr(int instance
, int segment
, int bus
,
327 int devfn
, const char *name
, int type
)
329 struct dmi_dev_onboard
*dev
;
331 /* Ignore invalid values */
332 if (type
== DMI_DEV_TYPE_DEV_SLOT
&&
333 segment
== 0xFFFF && bus
== 0xFF && devfn
== 0xFF)
336 dev
= dmi_alloc(sizeof(*dev
) + strlen(name
) + 1);
340 dev
->instance
= instance
;
341 dev
->segment
= segment
;
345 strcpy((char *)&dev
[1], name
);
346 dev
->dev
.type
= type
;
347 dev
->dev
.name
= (char *)&dev
[1];
348 dev
->dev
.device_data
= dev
;
350 list_add(&dev
->dev
.list
, &dmi_devices
);
353 static void __init
dmi_save_extended_devices(const struct dmi_header
*dm
)
356 const u8
*d
= (u8
*)dm
;
358 if (dm
->length
< 0x0B)
361 /* Skip disabled device */
362 if ((d
[0x5] & 0x80) == 0)
365 name
= dmi_string_nosave(dm
, d
[0x4]);
366 dmi_save_dev_pciaddr(d
[0x6], *(u16
*)(d
+ 0x7), d
[0x9], d
[0xA], name
,
367 DMI_DEV_TYPE_DEV_ONBOARD
);
368 dmi_save_one_device(d
[0x5] & 0x7f, name
);
371 static void __init
dmi_save_system_slot(const struct dmi_header
*dm
)
373 const u8
*d
= (u8
*)dm
;
375 /* Need SMBIOS 2.6+ structure */
376 if (dm
->length
< 0x11)
378 dmi_save_dev_pciaddr(*(u16
*)(d
+ 0x9), *(u16
*)(d
+ 0xD), d
[0xF],
379 d
[0x10], dmi_string_nosave(dm
, d
[0x4]),
380 DMI_DEV_TYPE_DEV_SLOT
);
383 static void __init
count_mem_devices(const struct dmi_header
*dm
, void *v
)
385 if (dm
->type
!= DMI_ENTRY_MEM_DEVICE
)
390 static void __init
save_mem_devices(const struct dmi_header
*dm
, void *v
)
392 const char *d
= (const char *)dm
;
395 if (dm
->type
!= DMI_ENTRY_MEM_DEVICE
|| dm
->length
< 0x12)
397 if (nr
>= dmi_memdev_nr
) {
398 pr_warn(FW_BUG
"Too many DIMM entries in SMBIOS table\n");
401 dmi_memdev
[nr
].handle
= get_unaligned(&dm
->handle
);
402 dmi_memdev
[nr
].device
= dmi_string(dm
, d
[0x10]);
403 dmi_memdev
[nr
].bank
= dmi_string(dm
, d
[0x11]);
407 void __init
dmi_memdev_walk(void)
412 if (dmi_walk_early(count_mem_devices
) == 0 && dmi_memdev_nr
) {
413 dmi_memdev
= dmi_alloc(sizeof(*dmi_memdev
) * dmi_memdev_nr
);
415 dmi_walk_early(save_mem_devices
);
420 * Process a DMI table entry. Right now all we care about are the BIOS
421 * and machine entries. For 2.5 we should pull the smbus controller info
424 static void __init
dmi_decode(const struct dmi_header
*dm
, void *dummy
)
427 case 0: /* BIOS Information */
428 dmi_save_ident(dm
, DMI_BIOS_VENDOR
, 4);
429 dmi_save_ident(dm
, DMI_BIOS_VERSION
, 5);
430 dmi_save_ident(dm
, DMI_BIOS_DATE
, 8);
432 case 1: /* System Information */
433 dmi_save_ident(dm
, DMI_SYS_VENDOR
, 4);
434 dmi_save_ident(dm
, DMI_PRODUCT_NAME
, 5);
435 dmi_save_ident(dm
, DMI_PRODUCT_VERSION
, 6);
436 dmi_save_ident(dm
, DMI_PRODUCT_SERIAL
, 7);
437 dmi_save_uuid(dm
, DMI_PRODUCT_UUID
, 8);
438 dmi_save_ident(dm
, DMI_PRODUCT_FAMILY
, 26);
440 case 2: /* Base Board Information */
441 dmi_save_ident(dm
, DMI_BOARD_VENDOR
, 4);
442 dmi_save_ident(dm
, DMI_BOARD_NAME
, 5);
443 dmi_save_ident(dm
, DMI_BOARD_VERSION
, 6);
444 dmi_save_ident(dm
, DMI_BOARD_SERIAL
, 7);
445 dmi_save_ident(dm
, DMI_BOARD_ASSET_TAG
, 8);
447 case 3: /* Chassis Information */
448 dmi_save_ident(dm
, DMI_CHASSIS_VENDOR
, 4);
449 dmi_save_type(dm
, DMI_CHASSIS_TYPE
, 5);
450 dmi_save_ident(dm
, DMI_CHASSIS_VERSION
, 6);
451 dmi_save_ident(dm
, DMI_CHASSIS_SERIAL
, 7);
452 dmi_save_ident(dm
, DMI_CHASSIS_ASSET_TAG
, 8);
454 case 9: /* System Slots */
455 dmi_save_system_slot(dm
);
457 case 10: /* Onboard Devices Information */
458 dmi_save_devices(dm
);
460 case 11: /* OEM Strings */
461 dmi_save_oem_strings_devices(dm
);
463 case 38: /* IPMI Device Information */
464 dmi_save_ipmi_device(dm
);
466 case 41: /* Onboard Devices Extended Information */
467 dmi_save_extended_devices(dm
);
471 static int __init
print_filtered(char *buf
, size_t len
, const char *info
)
479 for (p
= info
; *p
; p
++)
481 c
+= scnprintf(buf
+ c
, len
- c
, "%c", *p
);
483 c
+= scnprintf(buf
+ c
, len
- c
, "\\x%02x", *p
& 0xff);
487 static void __init
dmi_format_ids(char *buf
, size_t len
)
490 const char *board
; /* Board Name is optional */
492 c
+= print_filtered(buf
+ c
, len
- c
,
493 dmi_get_system_info(DMI_SYS_VENDOR
));
494 c
+= scnprintf(buf
+ c
, len
- c
, " ");
495 c
+= print_filtered(buf
+ c
, len
- c
,
496 dmi_get_system_info(DMI_PRODUCT_NAME
));
498 board
= dmi_get_system_info(DMI_BOARD_NAME
);
500 c
+= scnprintf(buf
+ c
, len
- c
, "/");
501 c
+= print_filtered(buf
+ c
, len
- c
, board
);
503 c
+= scnprintf(buf
+ c
, len
- c
, ", BIOS ");
504 c
+= print_filtered(buf
+ c
, len
- c
,
505 dmi_get_system_info(DMI_BIOS_VERSION
));
506 c
+= scnprintf(buf
+ c
, len
- c
, " ");
507 c
+= print_filtered(buf
+ c
, len
- c
,
508 dmi_get_system_info(DMI_BIOS_DATE
));
512 * Check for DMI/SMBIOS headers in the system firmware image. Any
513 * SMBIOS header must start 16 bytes before the DMI header, so take a
514 * 32 byte buffer and check for DMI at offset 16 and SMBIOS at offset
515 * 0. If the DMI header is present, set dmi_ver accordingly (SMBIOS
516 * takes precedence) and return 0. Otherwise return 1.
518 static int __init
dmi_present(const u8
*buf
)
522 if (memcmp(buf
, "_SM_", 4) == 0 &&
523 buf
[5] < 32 && dmi_checksum(buf
, buf
[5])) {
524 smbios_ver
= get_unaligned_be16(buf
+ 6);
525 smbios_entry_point_size
= buf
[5];
526 memcpy(smbios_entry_point
, buf
, smbios_entry_point_size
);
528 /* Some BIOS report weird SMBIOS version, fix that up */
529 switch (smbios_ver
) {
532 pr_debug("SMBIOS version fixup (2.%d->2.%d)\n",
533 smbios_ver
& 0xFF, 3);
537 pr_debug("SMBIOS version fixup (2.%d->2.%d)\n", 51, 6);
547 if (memcmp(buf
, "_DMI_", 5) == 0 && dmi_checksum(buf
, 15)) {
549 dmi_ver
= smbios_ver
;
551 dmi_ver
= (buf
[14] & 0xF0) << 4 | (buf
[14] & 0x0F);
553 dmi_num
= get_unaligned_le16(buf
+ 12);
554 dmi_len
= get_unaligned_le16(buf
+ 6);
555 dmi_base
= get_unaligned_le32(buf
+ 8);
557 if (dmi_walk_early(dmi_decode
) == 0) {
559 pr_info("SMBIOS %d.%d present.\n",
560 dmi_ver
>> 16, (dmi_ver
>> 8) & 0xFF);
562 smbios_entry_point_size
= 15;
563 memcpy(smbios_entry_point
, buf
,
564 smbios_entry_point_size
);
565 pr_info("Legacy DMI %d.%d present.\n",
566 dmi_ver
>> 16, (dmi_ver
>> 8) & 0xFF);
568 dmi_format_ids(dmi_ids_string
, sizeof(dmi_ids_string
));
569 pr_info("DMI: %s\n", dmi_ids_string
);
578 * Check for the SMBIOS 3.0 64-bit entry point signature. Unlike the legacy
579 * 32-bit entry point, there is no embedded DMI header (_DMI_) in here.
581 static int __init
dmi_smbios3_present(const u8
*buf
)
583 if (memcmp(buf
, "_SM3_", 5) == 0 &&
584 buf
[6] < 32 && dmi_checksum(buf
, buf
[6])) {
585 dmi_ver
= get_unaligned_be32(buf
+ 6) & 0xFFFFFF;
586 dmi_num
= 0; /* No longer specified */
587 dmi_len
= get_unaligned_le32(buf
+ 12);
588 dmi_base
= get_unaligned_le64(buf
+ 16);
589 smbios_entry_point_size
= buf
[6];
590 memcpy(smbios_entry_point
, buf
, smbios_entry_point_size
);
592 if (dmi_walk_early(dmi_decode
) == 0) {
593 pr_info("SMBIOS %d.%d.%d present.\n",
594 dmi_ver
>> 16, (dmi_ver
>> 8) & 0xFF,
596 dmi_format_ids(dmi_ids_string
, sizeof(dmi_ids_string
));
597 pr_info("DMI: %s\n", dmi_ids_string
);
604 void __init
dmi_scan_machine(void)
609 if (efi_enabled(EFI_CONFIG_TABLES
)) {
611 * According to the DMTF SMBIOS reference spec v3.0.0, it is
612 * allowed to define both the 64-bit entry point (smbios3) and
613 * the 32-bit entry point (smbios), in which case they should
614 * either both point to the same SMBIOS structure table, or the
615 * table pointed to by the 64-bit entry point should contain a
616 * superset of the table contents pointed to by the 32-bit entry
617 * point (section 5.2)
618 * This implies that the 64-bit entry point should have
619 * precedence if it is defined and supported by the OS. If we
620 * have the 64-bit entry point, but fail to decode it, fall
621 * back to the legacy one (if available)
623 if (efi
.smbios3
!= EFI_INVALID_TABLE_ADDR
) {
624 p
= dmi_early_remap(efi
.smbios3
, 32);
627 memcpy_fromio(buf
, p
, 32);
628 dmi_early_unmap(p
, 32);
630 if (!dmi_smbios3_present(buf
)) {
635 if (efi
.smbios
== EFI_INVALID_TABLE_ADDR
)
638 /* This is called as a core_initcall() because it isn't
639 * needed during early boot. This also means we can
640 * iounmap the space when we're done with it.
642 p
= dmi_early_remap(efi
.smbios
, 32);
645 memcpy_fromio(buf
, p
, 32);
646 dmi_early_unmap(p
, 32);
648 if (!dmi_present(buf
)) {
652 } else if (IS_ENABLED(CONFIG_DMI_SCAN_MACHINE_NON_EFI_FALLBACK
)) {
653 p
= dmi_early_remap(0xF0000, 0x10000);
658 * Same logic as above, look for a 64-bit entry point
659 * first, and if not found, fall back to 32-bit entry point.
661 memcpy_fromio(buf
, p
, 16);
662 for (q
= p
+ 16; q
< p
+ 0x10000; q
+= 16) {
663 memcpy_fromio(buf
+ 16, q
, 16);
664 if (!dmi_smbios3_present(buf
)) {
666 dmi_early_unmap(p
, 0x10000);
669 memcpy(buf
, buf
+ 16, 16);
673 * Iterate over all possible DMI header addresses q.
674 * Maintain the 32 bytes around q in buf. On the
675 * first iteration, substitute zero for the
676 * out-of-range bytes so there is no chance of falsely
677 * detecting an SMBIOS header.
680 for (q
= p
; q
< p
+ 0x10000; q
+= 16) {
681 memcpy_fromio(buf
+ 16, q
, 16);
682 if (!dmi_present(buf
)) {
684 dmi_early_unmap(p
, 0x10000);
687 memcpy(buf
, buf
+ 16, 16);
689 dmi_early_unmap(p
, 0x10000);
692 pr_info("DMI not present or invalid.\n");
697 static ssize_t
raw_table_read(struct file
*file
, struct kobject
*kobj
,
698 struct bin_attribute
*attr
, char *buf
,
699 loff_t pos
, size_t count
)
701 memcpy(buf
, attr
->private + pos
, count
);
705 static BIN_ATTR(smbios_entry_point
, S_IRUSR
, raw_table_read
, NULL
, 0);
706 static BIN_ATTR(DMI
, S_IRUSR
, raw_table_read
, NULL
, 0);
708 static int __init
dmi_init(void)
710 struct kobject
*tables_kobj
;
714 if (!dmi_available
) {
720 * Set up dmi directory at /sys/firmware/dmi. This entry should stay
721 * even after farther error, as it can be used by other modules like
724 dmi_kobj
= kobject_create_and_add("dmi", firmware_kobj
);
728 tables_kobj
= kobject_create_and_add("tables", dmi_kobj
);
732 dmi_table
= dmi_remap(dmi_base
, dmi_len
);
736 bin_attr_smbios_entry_point
.size
= smbios_entry_point_size
;
737 bin_attr_smbios_entry_point
.private = smbios_entry_point
;
738 ret
= sysfs_create_bin_file(tables_kobj
, &bin_attr_smbios_entry_point
);
742 bin_attr_DMI
.size
= dmi_len
;
743 bin_attr_DMI
.private = dmi_table
;
744 ret
= sysfs_create_bin_file(tables_kobj
, &bin_attr_DMI
);
748 sysfs_remove_bin_file(tables_kobj
,
749 &bin_attr_smbios_entry_point
);
751 dmi_unmap(dmi_table
);
753 kobject_del(tables_kobj
);
754 kobject_put(tables_kobj
);
756 pr_err("dmi: Firmware registration failed.\n");
760 subsys_initcall(dmi_init
);
763 * dmi_set_dump_stack_arch_desc - set arch description for dump_stack()
765 * Invoke dump_stack_set_arch_desc() with DMI system information so that
766 * DMI identifiers are printed out on task dumps. Arch boot code should
767 * call this function after dmi_scan_machine() if it wants to print out DMI
768 * identifiers on task dumps.
770 void __init
dmi_set_dump_stack_arch_desc(void)
772 dump_stack_set_arch_desc("%s", dmi_ids_string
);
776 * dmi_matches - check if dmi_system_id structure matches system DMI data
777 * @dmi: pointer to the dmi_system_id structure to check
779 static bool dmi_matches(const struct dmi_system_id
*dmi
)
783 WARN(!dmi_initialized
, KERN_ERR
"dmi check: not initialized yet.\n");
785 for (i
= 0; i
< ARRAY_SIZE(dmi
->matches
); i
++) {
786 int s
= dmi
->matches
[i
].slot
;
790 if (!dmi
->matches
[i
].exact_match
&&
791 strstr(dmi_ident
[s
], dmi
->matches
[i
].substr
))
793 else if (dmi
->matches
[i
].exact_match
&&
794 !strcmp(dmi_ident
[s
], dmi
->matches
[i
].substr
))
805 * dmi_is_end_of_table - check for end-of-table marker
806 * @dmi: pointer to the dmi_system_id structure to check
808 static bool dmi_is_end_of_table(const struct dmi_system_id
*dmi
)
810 return dmi
->matches
[0].slot
== DMI_NONE
;
814 * dmi_check_system - check system DMI data
815 * @list: array of dmi_system_id structures to match against
816 * All non-null elements of the list must match
817 * their slot's (field index's) data (i.e., each
818 * list string must be a substring of the specified
819 * DMI slot's string data) to be considered a
822 * Walk the blacklist table running matching functions until someone
823 * returns non zero or we hit the end. Callback function is called for
824 * each successful match. Returns the number of matches.
826 int dmi_check_system(const struct dmi_system_id
*list
)
829 const struct dmi_system_id
*d
;
831 for (d
= list
; !dmi_is_end_of_table(d
); d
++)
832 if (dmi_matches(d
)) {
834 if (d
->callback
&& d
->callback(d
))
840 EXPORT_SYMBOL(dmi_check_system
);
843 * dmi_first_match - find dmi_system_id structure matching system DMI data
844 * @list: array of dmi_system_id structures to match against
845 * All non-null elements of the list must match
846 * their slot's (field index's) data (i.e., each
847 * list string must be a substring of the specified
848 * DMI slot's string data) to be considered a
851 * Walk the blacklist table until the first match is found. Return the
852 * pointer to the matching entry or NULL if there's no match.
854 const struct dmi_system_id
*dmi_first_match(const struct dmi_system_id
*list
)
856 const struct dmi_system_id
*d
;
858 for (d
= list
; !dmi_is_end_of_table(d
); d
++)
864 EXPORT_SYMBOL(dmi_first_match
);
867 * dmi_get_system_info - return DMI data value
868 * @field: data index (see enum dmi_field)
870 * Returns one DMI data value, can be used to perform
871 * complex DMI data checks.
873 const char *dmi_get_system_info(int field
)
875 return dmi_ident
[field
];
877 EXPORT_SYMBOL(dmi_get_system_info
);
880 * dmi_name_in_serial - Check if string is in the DMI product serial information
881 * @str: string to check for
883 int dmi_name_in_serial(const char *str
)
885 int f
= DMI_PRODUCT_SERIAL
;
886 if (dmi_ident
[f
] && strstr(dmi_ident
[f
], str
))
892 * dmi_name_in_vendors - Check if string is in the DMI system or board vendor name
893 * @str: Case sensitive Name
895 int dmi_name_in_vendors(const char *str
)
897 static int fields
[] = { DMI_SYS_VENDOR
, DMI_BOARD_VENDOR
, DMI_NONE
};
899 for (i
= 0; fields
[i
] != DMI_NONE
; i
++) {
901 if (dmi_ident
[f
] && strstr(dmi_ident
[f
], str
))
906 EXPORT_SYMBOL(dmi_name_in_vendors
);
909 * dmi_find_device - find onboard device by type/name
910 * @type: device type or %DMI_DEV_TYPE_ANY to match all device types
911 * @name: device name string or %NULL to match all
912 * @from: previous device found in search, or %NULL for new search.
914 * Iterates through the list of known onboard devices. If a device is
915 * found with a matching @type and @name, a pointer to its device
916 * structure is returned. Otherwise, %NULL is returned.
917 * A new search is initiated by passing %NULL as the @from argument.
918 * If @from is not %NULL, searches continue from next device.
920 const struct dmi_device
*dmi_find_device(int type
, const char *name
,
921 const struct dmi_device
*from
)
923 const struct list_head
*head
= from
? &from
->list
: &dmi_devices
;
926 for (d
= head
->next
; d
!= &dmi_devices
; d
= d
->next
) {
927 const struct dmi_device
*dev
=
928 list_entry(d
, struct dmi_device
, list
);
930 if (((type
== DMI_DEV_TYPE_ANY
) || (dev
->type
== type
)) &&
931 ((name
== NULL
) || (strcmp(dev
->name
, name
) == 0)))
937 EXPORT_SYMBOL(dmi_find_device
);
940 * dmi_get_date - parse a DMI date
941 * @field: data index (see enum dmi_field)
942 * @yearp: optional out parameter for the year
943 * @monthp: optional out parameter for the month
944 * @dayp: optional out parameter for the day
946 * The date field is assumed to be in the form resembling
947 * [mm[/dd]]/yy[yy] and the result is stored in the out
948 * parameters any or all of which can be omitted.
950 * If the field doesn't exist, all out parameters are set to zero
951 * and false is returned. Otherwise, true is returned with any
952 * invalid part of date set to zero.
954 * On return, year, month and day are guaranteed to be in the
955 * range of [0,9999], [0,12] and [0,31] respectively.
957 bool dmi_get_date(int field
, int *yearp
, int *monthp
, int *dayp
)
959 int year
= 0, month
= 0, day
= 0;
964 s
= dmi_get_system_info(field
);
970 * Determine year first. We assume the date string resembles
971 * mm/dd/yy[yy] but the original code extracted only the year
972 * from the end. Keep the behavior in the spirit of no
980 year
= simple_strtoul(y
, &e
, 10);
981 if (y
!= e
&& year
< 100) { /* 2-digit year */
983 if (year
< 1996) /* no dates < spec 1.0 */
986 if (year
> 9999) /* year should fit in %04d */
989 /* parse the mm and dd */
990 month
= simple_strtoul(s
, &e
, 10);
991 if (s
== e
|| *e
!= '/' || !month
|| month
> 12) {
997 day
= simple_strtoul(s
, &e
, 10);
998 if (s
== y
|| s
== e
|| *e
!= '/' || day
> 31)
1009 EXPORT_SYMBOL(dmi_get_date
);
1012 * dmi_walk - Walk the DMI table and get called back for every record
1013 * @decode: Callback function
1014 * @private_data: Private data to be passed to the callback function
1016 * Returns 0 on success, -ENXIO if DMI is not selected or not present,
1017 * or a different negative error code if DMI walking fails.
1019 int dmi_walk(void (*decode
)(const struct dmi_header
*, void *),
1027 buf
= dmi_remap(dmi_base
, dmi_len
);
1031 dmi_decode_table(buf
, decode
, private_data
);
1036 EXPORT_SYMBOL_GPL(dmi_walk
);
1039 * dmi_match - compare a string to the dmi field (if exists)
1040 * @f: DMI field identifier
1041 * @str: string to compare the DMI field to
1043 * Returns true if the requested field equals to the str (including NULL).
1045 bool dmi_match(enum dmi_field f
, const char *str
)
1047 const char *info
= dmi_get_system_info(f
);
1049 if (info
== NULL
|| str
== NULL
)
1052 return !strcmp(info
, str
);
1054 EXPORT_SYMBOL_GPL(dmi_match
);
1056 void dmi_memdev_name(u16 handle
, const char **bank
, const char **device
)
1060 if (dmi_memdev
== NULL
)
1063 for (n
= 0; n
< dmi_memdev_nr
; n
++) {
1064 if (handle
== dmi_memdev
[n
].handle
) {
1065 *bank
= dmi_memdev
[n
].bank
;
1066 *device
= dmi_memdev
[n
].device
;
1071 EXPORT_SYMBOL_GPL(dmi_memdev_name
);