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
;
29 /* DMI system identification string used during boot */
30 static char dmi_ids_string
[128] __initdata
;
32 static struct dmi_memdev_info
{
37 static int dmi_memdev_nr
;
39 static const char * __init
dmi_string_nosave(const struct dmi_header
*dm
, u8 s
)
41 const u8
*bp
= ((u8
*) dm
) + dm
->length
;
45 while (--s
> 0 && *bp
)
48 /* Strings containing only spaces are considered empty */
56 return dmi_empty_string
;
59 static const char * __init
dmi_string(const struct dmi_header
*dm
, u8 s
)
61 const char *bp
= dmi_string_nosave(dm
, s
);
65 if (bp
== dmi_empty_string
)
66 return dmi_empty_string
;
77 * We have to be cautious here. We have seen BIOSes with DMI pointers
78 * pointing to completely the wrong place for example
80 static void dmi_decode_table(u8
*buf
,
81 void (*decode
)(const struct dmi_header
*, void *),
88 * Stop when we have seen all the items the table claimed to have
89 * (SMBIOS < 3.0 only) OR we reach an end-of-table marker (SMBIOS
90 * >= 3.0 only) OR we run off the end of the table (should never
91 * happen but sometimes does on bogus implementations.)
93 while ((!dmi_num
|| i
< dmi_num
) &&
94 (data
- buf
+ sizeof(struct dmi_header
)) <= dmi_len
) {
95 const struct dmi_header
*dm
= (const struct dmi_header
*)data
;
98 * We want to know the total length (formatted area and
99 * strings) before decoding to make sure we won't run off the
100 * table in dmi_decode or dmi_string
103 while ((data
- buf
< dmi_len
- 1) && (data
[0] || data
[1]))
105 if (data
- buf
< dmi_len
- 1)
106 decode(dm
, private_data
);
112 * 7.45 End-of-Table (Type 127) [SMBIOS reference spec v3.0.0]
113 * For tables behind a 64-bit entry point, we have no item
114 * count and no exact table length, so stop on end-of-table
115 * marker. For tables behind a 32-bit entry point, we have
116 * seen OEM structures behind the end-of-table marker on
117 * some systems, so don't trust it.
119 if (!dmi_num
&& dm
->type
== DMI_ENTRY_END_OF_TABLE
)
123 /* Trim DMI table length if needed */
124 if (dmi_len
> data
- buf
)
125 dmi_len
= data
- buf
;
128 static phys_addr_t dmi_base
;
130 static int __init
dmi_walk_early(void (*decode
)(const struct dmi_header
*,
134 u32 orig_dmi_len
= dmi_len
;
136 buf
= dmi_early_remap(dmi_base
, orig_dmi_len
);
140 dmi_decode_table(buf
, decode
, NULL
);
142 add_device_randomness(buf
, dmi_len
);
144 dmi_early_unmap(buf
, orig_dmi_len
);
148 static int __init
dmi_checksum(const u8
*buf
, u8 len
)
153 for (a
= 0; a
< len
; a
++)
159 static const char *dmi_ident
[DMI_STRING_MAX
];
160 static LIST_HEAD(dmi_devices
);
166 static void __init
dmi_save_ident(const struct dmi_header
*dm
, int slot
,
169 const char *d
= (const char *) dm
;
172 if (dmi_ident
[slot
] || dm
->length
<= string
)
175 p
= dmi_string(dm
, d
[string
]);
182 static void __init
dmi_save_uuid(const struct dmi_header
*dm
, int slot
,
187 int is_ff
= 1, is_00
= 1, i
;
189 if (dmi_ident
[slot
] || dm
->length
<= index
+ 16)
192 d
= (u8
*) dm
+ index
;
193 for (i
= 0; i
< 16 && (is_ff
|| is_00
); i
++) {
203 s
= dmi_alloc(16*2+4+1);
208 * As of version 2.6 of the SMBIOS specification, the first 3 fields of
209 * the UUID are supposed to be little-endian encoded. The specification
210 * says that this is the defacto standard.
212 if (dmi_ver
>= 0x020600)
213 sprintf(s
, "%pUL", d
);
215 sprintf(s
, "%pUB", d
);
220 static void __init
dmi_save_type(const struct dmi_header
*dm
, int slot
,
226 if (dmi_ident
[slot
] || dm
->length
<= index
)
233 d
= (u8
*) dm
+ index
;
234 sprintf(s
, "%u", *d
& 0x7F);
238 static void __init
dmi_save_one_device(int type
, const char *name
)
240 struct dmi_device
*dev
;
242 /* No duplicate device */
243 if (dmi_find_device(type
, name
, NULL
))
246 dev
= dmi_alloc(sizeof(*dev
) + strlen(name
) + 1);
251 strcpy((char *)(dev
+ 1), name
);
252 dev
->name
= (char *)(dev
+ 1);
253 dev
->device_data
= NULL
;
254 list_add(&dev
->list
, &dmi_devices
);
257 static void __init
dmi_save_devices(const struct dmi_header
*dm
)
259 int i
, count
= (dm
->length
- sizeof(struct dmi_header
)) / 2;
261 for (i
= 0; i
< count
; i
++) {
262 const char *d
= (char *)(dm
+ 1) + (i
* 2);
264 /* Skip disabled device */
265 if ((*d
& 0x80) == 0)
268 dmi_save_one_device(*d
& 0x7f, dmi_string_nosave(dm
, *(d
+ 1)));
272 static void __init
dmi_save_oem_strings_devices(const struct dmi_header
*dm
)
275 struct dmi_device
*dev
;
277 if (dm
->length
< 0x05)
280 count
= *(u8
*)(dm
+ 1);
281 for (i
= 1; i
<= count
; i
++) {
282 const char *devname
= dmi_string(dm
, i
);
284 if (devname
== dmi_empty_string
)
287 dev
= dmi_alloc(sizeof(*dev
));
291 dev
->type
= DMI_DEV_TYPE_OEM_STRING
;
293 dev
->device_data
= NULL
;
295 list_add(&dev
->list
, &dmi_devices
);
299 static void __init
dmi_save_ipmi_device(const struct dmi_header
*dm
)
301 struct dmi_device
*dev
;
304 data
= dmi_alloc(dm
->length
);
308 memcpy(data
, dm
, dm
->length
);
310 dev
= dmi_alloc(sizeof(*dev
));
314 dev
->type
= DMI_DEV_TYPE_IPMI
;
315 dev
->name
= "IPMI controller";
316 dev
->device_data
= data
;
318 list_add_tail(&dev
->list
, &dmi_devices
);
321 static void __init
dmi_save_dev_pciaddr(int instance
, int segment
, int bus
,
322 int devfn
, const char *name
, int type
)
324 struct dmi_dev_onboard
*dev
;
326 /* Ignore invalid values */
327 if (type
== DMI_DEV_TYPE_DEV_SLOT
&&
328 segment
== 0xFFFF && bus
== 0xFF && devfn
== 0xFF)
331 dev
= dmi_alloc(sizeof(*dev
) + strlen(name
) + 1);
335 dev
->instance
= instance
;
336 dev
->segment
= segment
;
340 strcpy((char *)&dev
[1], name
);
341 dev
->dev
.type
= type
;
342 dev
->dev
.name
= (char *)&dev
[1];
343 dev
->dev
.device_data
= dev
;
345 list_add(&dev
->dev
.list
, &dmi_devices
);
348 static void __init
dmi_save_extended_devices(const struct dmi_header
*dm
)
351 const u8
*d
= (u8
*)dm
;
353 if (dm
->length
< 0x0B)
356 /* Skip disabled device */
357 if ((d
[0x5] & 0x80) == 0)
360 name
= dmi_string_nosave(dm
, d
[0x4]);
361 dmi_save_dev_pciaddr(d
[0x6], *(u16
*)(d
+ 0x7), d
[0x9], d
[0xA], name
,
362 DMI_DEV_TYPE_DEV_ONBOARD
);
363 dmi_save_one_device(d
[0x5] & 0x7f, name
);
366 static void __init
dmi_save_system_slot(const struct dmi_header
*dm
)
368 const u8
*d
= (u8
*)dm
;
370 /* Need SMBIOS 2.6+ structure */
371 if (dm
->length
< 0x11)
373 dmi_save_dev_pciaddr(*(u16
*)(d
+ 0x9), *(u16
*)(d
+ 0xD), d
[0xF],
374 d
[0x10], dmi_string_nosave(dm
, d
[0x4]),
375 DMI_DEV_TYPE_DEV_SLOT
);
378 static void __init
count_mem_devices(const struct dmi_header
*dm
, void *v
)
380 if (dm
->type
!= DMI_ENTRY_MEM_DEVICE
)
385 static void __init
save_mem_devices(const struct dmi_header
*dm
, void *v
)
387 const char *d
= (const char *)dm
;
390 if (dm
->type
!= DMI_ENTRY_MEM_DEVICE
|| dm
->length
< 0x12)
392 if (nr
>= dmi_memdev_nr
) {
393 pr_warn(FW_BUG
"Too many DIMM entries in SMBIOS table\n");
396 dmi_memdev
[nr
].handle
= get_unaligned(&dm
->handle
);
397 dmi_memdev
[nr
].device
= dmi_string(dm
, d
[0x10]);
398 dmi_memdev
[nr
].bank
= dmi_string(dm
, d
[0x11]);
402 void __init
dmi_memdev_walk(void)
407 if (dmi_walk_early(count_mem_devices
) == 0 && dmi_memdev_nr
) {
408 dmi_memdev
= dmi_alloc(sizeof(*dmi_memdev
) * dmi_memdev_nr
);
410 dmi_walk_early(save_mem_devices
);
415 * Process a DMI table entry. Right now all we care about are the BIOS
416 * and machine entries. For 2.5 we should pull the smbus controller info
419 static void __init
dmi_decode(const struct dmi_header
*dm
, void *dummy
)
422 case 0: /* BIOS Information */
423 dmi_save_ident(dm
, DMI_BIOS_VENDOR
, 4);
424 dmi_save_ident(dm
, DMI_BIOS_VERSION
, 5);
425 dmi_save_ident(dm
, DMI_BIOS_DATE
, 8);
427 case 1: /* System Information */
428 dmi_save_ident(dm
, DMI_SYS_VENDOR
, 4);
429 dmi_save_ident(dm
, DMI_PRODUCT_NAME
, 5);
430 dmi_save_ident(dm
, DMI_PRODUCT_VERSION
, 6);
431 dmi_save_ident(dm
, DMI_PRODUCT_SERIAL
, 7);
432 dmi_save_uuid(dm
, DMI_PRODUCT_UUID
, 8);
433 dmi_save_ident(dm
, DMI_PRODUCT_FAMILY
, 26);
435 case 2: /* Base Board Information */
436 dmi_save_ident(dm
, DMI_BOARD_VENDOR
, 4);
437 dmi_save_ident(dm
, DMI_BOARD_NAME
, 5);
438 dmi_save_ident(dm
, DMI_BOARD_VERSION
, 6);
439 dmi_save_ident(dm
, DMI_BOARD_SERIAL
, 7);
440 dmi_save_ident(dm
, DMI_BOARD_ASSET_TAG
, 8);
442 case 3: /* Chassis Information */
443 dmi_save_ident(dm
, DMI_CHASSIS_VENDOR
, 4);
444 dmi_save_type(dm
, DMI_CHASSIS_TYPE
, 5);
445 dmi_save_ident(dm
, DMI_CHASSIS_VERSION
, 6);
446 dmi_save_ident(dm
, DMI_CHASSIS_SERIAL
, 7);
447 dmi_save_ident(dm
, DMI_CHASSIS_ASSET_TAG
, 8);
449 case 9: /* System Slots */
450 dmi_save_system_slot(dm
);
452 case 10: /* Onboard Devices Information */
453 dmi_save_devices(dm
);
455 case 11: /* OEM Strings */
456 dmi_save_oem_strings_devices(dm
);
458 case 38: /* IPMI Device Information */
459 dmi_save_ipmi_device(dm
);
461 case 41: /* Onboard Devices Extended Information */
462 dmi_save_extended_devices(dm
);
466 static int __init
print_filtered(char *buf
, size_t len
, const char *info
)
474 for (p
= info
; *p
; p
++)
476 c
+= scnprintf(buf
+ c
, len
- c
, "%c", *p
);
478 c
+= scnprintf(buf
+ c
, len
- c
, "\\x%02x", *p
& 0xff);
482 static void __init
dmi_format_ids(char *buf
, size_t len
)
485 const char *board
; /* Board Name is optional */
487 c
+= print_filtered(buf
+ c
, len
- c
,
488 dmi_get_system_info(DMI_SYS_VENDOR
));
489 c
+= scnprintf(buf
+ c
, len
- c
, " ");
490 c
+= print_filtered(buf
+ c
, len
- c
,
491 dmi_get_system_info(DMI_PRODUCT_NAME
));
493 board
= dmi_get_system_info(DMI_BOARD_NAME
);
495 c
+= scnprintf(buf
+ c
, len
- c
, "/");
496 c
+= print_filtered(buf
+ c
, len
- c
, board
);
498 c
+= scnprintf(buf
+ c
, len
- c
, ", BIOS ");
499 c
+= print_filtered(buf
+ c
, len
- c
,
500 dmi_get_system_info(DMI_BIOS_VERSION
));
501 c
+= scnprintf(buf
+ c
, len
- c
, " ");
502 c
+= print_filtered(buf
+ c
, len
- c
,
503 dmi_get_system_info(DMI_BIOS_DATE
));
507 * Check for DMI/SMBIOS headers in the system firmware image. Any
508 * SMBIOS header must start 16 bytes before the DMI header, so take a
509 * 32 byte buffer and check for DMI at offset 16 and SMBIOS at offset
510 * 0. If the DMI header is present, set dmi_ver accordingly (SMBIOS
511 * takes precedence) and return 0. Otherwise return 1.
513 static int __init
dmi_present(const u8
*buf
)
517 if (memcmp(buf
, "_SM_", 4) == 0 &&
518 buf
[5] < 32 && dmi_checksum(buf
, buf
[5])) {
519 smbios_ver
= get_unaligned_be16(buf
+ 6);
520 smbios_entry_point_size
= buf
[5];
521 memcpy(smbios_entry_point
, buf
, smbios_entry_point_size
);
523 /* Some BIOS report weird SMBIOS version, fix that up */
524 switch (smbios_ver
) {
527 pr_debug("SMBIOS version fixup (2.%d->2.%d)\n",
528 smbios_ver
& 0xFF, 3);
532 pr_debug("SMBIOS version fixup (2.%d->2.%d)\n", 51, 6);
542 if (memcmp(buf
, "_DMI_", 5) == 0 && dmi_checksum(buf
, 15)) {
544 dmi_ver
= smbios_ver
;
546 dmi_ver
= (buf
[14] & 0xF0) << 4 | (buf
[14] & 0x0F);
548 dmi_num
= get_unaligned_le16(buf
+ 12);
549 dmi_len
= get_unaligned_le16(buf
+ 6);
550 dmi_base
= get_unaligned_le32(buf
+ 8);
552 if (dmi_walk_early(dmi_decode
) == 0) {
554 pr_info("SMBIOS %d.%d present.\n",
555 dmi_ver
>> 16, (dmi_ver
>> 8) & 0xFF);
557 smbios_entry_point_size
= 15;
558 memcpy(smbios_entry_point
, buf
,
559 smbios_entry_point_size
);
560 pr_info("Legacy DMI %d.%d present.\n",
561 dmi_ver
>> 16, (dmi_ver
>> 8) & 0xFF);
563 dmi_format_ids(dmi_ids_string
, sizeof(dmi_ids_string
));
564 pr_info("DMI: %s\n", dmi_ids_string
);
573 * Check for the SMBIOS 3.0 64-bit entry point signature. Unlike the legacy
574 * 32-bit entry point, there is no embedded DMI header (_DMI_) in here.
576 static int __init
dmi_smbios3_present(const u8
*buf
)
578 if (memcmp(buf
, "_SM3_", 5) == 0 &&
579 buf
[6] < 32 && dmi_checksum(buf
, buf
[6])) {
580 dmi_ver
= get_unaligned_be32(buf
+ 6) & 0xFFFFFF;
581 dmi_num
= 0; /* No longer specified */
582 dmi_len
= get_unaligned_le32(buf
+ 12);
583 dmi_base
= get_unaligned_le64(buf
+ 16);
584 smbios_entry_point_size
= buf
[6];
585 memcpy(smbios_entry_point
, buf
, smbios_entry_point_size
);
587 if (dmi_walk_early(dmi_decode
) == 0) {
588 pr_info("SMBIOS %d.%d.%d present.\n",
589 dmi_ver
>> 16, (dmi_ver
>> 8) & 0xFF,
591 dmi_format_ids(dmi_ids_string
, sizeof(dmi_ids_string
));
592 pr_info("DMI: %s\n", dmi_ids_string
);
599 void __init
dmi_scan_machine(void)
604 if (efi_enabled(EFI_CONFIG_TABLES
)) {
606 * According to the DMTF SMBIOS reference spec v3.0.0, it is
607 * allowed to define both the 64-bit entry point (smbios3) and
608 * the 32-bit entry point (smbios), in which case they should
609 * either both point to the same SMBIOS structure table, or the
610 * table pointed to by the 64-bit entry point should contain a
611 * superset of the table contents pointed to by the 32-bit entry
612 * point (section 5.2)
613 * This implies that the 64-bit entry point should have
614 * precedence if it is defined and supported by the OS. If we
615 * have the 64-bit entry point, but fail to decode it, fall
616 * back to the legacy one (if available)
618 if (efi
.smbios3
!= EFI_INVALID_TABLE_ADDR
) {
619 p
= dmi_early_remap(efi
.smbios3
, 32);
622 memcpy_fromio(buf
, p
, 32);
623 dmi_early_unmap(p
, 32);
625 if (!dmi_smbios3_present(buf
)) {
630 if (efi
.smbios
== EFI_INVALID_TABLE_ADDR
)
633 /* This is called as a core_initcall() because it isn't
634 * needed during early boot. This also means we can
635 * iounmap the space when we're done with it.
637 p
= dmi_early_remap(efi
.smbios
, 32);
640 memcpy_fromio(buf
, p
, 32);
641 dmi_early_unmap(p
, 32);
643 if (!dmi_present(buf
)) {
647 } else if (IS_ENABLED(CONFIG_DMI_SCAN_MACHINE_NON_EFI_FALLBACK
)) {
648 p
= dmi_early_remap(0xF0000, 0x10000);
653 * Same logic as above, look for a 64-bit entry point
654 * first, and if not found, fall back to 32-bit entry point.
656 memcpy_fromio(buf
, p
, 16);
657 for (q
= p
+ 16; q
< p
+ 0x10000; q
+= 16) {
658 memcpy_fromio(buf
+ 16, q
, 16);
659 if (!dmi_smbios3_present(buf
)) {
661 dmi_early_unmap(p
, 0x10000);
664 memcpy(buf
, buf
+ 16, 16);
668 * Iterate over all possible DMI header addresses q.
669 * Maintain the 32 bytes around q in buf. On the
670 * first iteration, substitute zero for the
671 * out-of-range bytes so there is no chance of falsely
672 * detecting an SMBIOS header.
675 for (q
= p
; q
< p
+ 0x10000; q
+= 16) {
676 memcpy_fromio(buf
+ 16, q
, 16);
677 if (!dmi_present(buf
)) {
679 dmi_early_unmap(p
, 0x10000);
682 memcpy(buf
, buf
+ 16, 16);
684 dmi_early_unmap(p
, 0x10000);
687 pr_info("DMI not present or invalid.\n");
690 static ssize_t
raw_table_read(struct file
*file
, struct kobject
*kobj
,
691 struct bin_attribute
*attr
, char *buf
,
692 loff_t pos
, size_t count
)
694 memcpy(buf
, attr
->private + pos
, count
);
698 static BIN_ATTR(smbios_entry_point
, S_IRUSR
, raw_table_read
, NULL
, 0);
699 static BIN_ATTR(DMI
, S_IRUSR
, raw_table_read
, NULL
, 0);
701 static int __init
dmi_init(void)
703 struct kobject
*tables_kobj
;
711 * Set up dmi directory at /sys/firmware/dmi. This entry should stay
712 * even after farther error, as it can be used by other modules like
715 dmi_kobj
= kobject_create_and_add("dmi", firmware_kobj
);
719 tables_kobj
= kobject_create_and_add("tables", dmi_kobj
);
723 dmi_table
= dmi_remap(dmi_base
, dmi_len
);
727 bin_attr_smbios_entry_point
.size
= smbios_entry_point_size
;
728 bin_attr_smbios_entry_point
.private = smbios_entry_point
;
729 ret
= sysfs_create_bin_file(tables_kobj
, &bin_attr_smbios_entry_point
);
733 bin_attr_DMI
.size
= dmi_len
;
734 bin_attr_DMI
.private = dmi_table
;
735 ret
= sysfs_create_bin_file(tables_kobj
, &bin_attr_DMI
);
739 sysfs_remove_bin_file(tables_kobj
,
740 &bin_attr_smbios_entry_point
);
742 dmi_unmap(dmi_table
);
744 kobject_del(tables_kobj
);
745 kobject_put(tables_kobj
);
747 pr_err("dmi: Firmware registration failed.\n");
751 subsys_initcall(dmi_init
);
754 * dmi_set_dump_stack_arch_desc - set arch description for dump_stack()
756 * Invoke dump_stack_set_arch_desc() with DMI system information so that
757 * DMI identifiers are printed out on task dumps. Arch boot code should
758 * call this function after dmi_scan_machine() if it wants to print out DMI
759 * identifiers on task dumps.
761 void __init
dmi_set_dump_stack_arch_desc(void)
763 dump_stack_set_arch_desc("%s", dmi_ids_string
);
767 * dmi_matches - check if dmi_system_id structure matches system DMI data
768 * @dmi: pointer to the dmi_system_id structure to check
770 static bool dmi_matches(const struct dmi_system_id
*dmi
)
774 for (i
= 0; i
< ARRAY_SIZE(dmi
->matches
); i
++) {
775 int s
= dmi
->matches
[i
].slot
;
779 if (dmi
->matches
[i
].exact_match
) {
780 if (!strcmp(dmi_ident
[s
],
781 dmi
->matches
[i
].substr
))
784 if (strstr(dmi_ident
[s
],
785 dmi
->matches
[i
].substr
))
797 * dmi_is_end_of_table - check for end-of-table marker
798 * @dmi: pointer to the dmi_system_id structure to check
800 static bool dmi_is_end_of_table(const struct dmi_system_id
*dmi
)
802 return dmi
->matches
[0].slot
== DMI_NONE
;
806 * dmi_check_system - check system DMI data
807 * @list: array of dmi_system_id structures to match against
808 * All non-null elements of the list must match
809 * their slot's (field index's) data (i.e., each
810 * list string must be a substring of the specified
811 * DMI slot's string data) to be considered a
814 * Walk the blacklist table running matching functions until someone
815 * returns non zero or we hit the end. Callback function is called for
816 * each successful match. Returns the number of matches.
818 * dmi_scan_machine must be called before this function is called.
820 int dmi_check_system(const struct dmi_system_id
*list
)
823 const struct dmi_system_id
*d
;
825 for (d
= list
; !dmi_is_end_of_table(d
); d
++)
826 if (dmi_matches(d
)) {
828 if (d
->callback
&& d
->callback(d
))
834 EXPORT_SYMBOL(dmi_check_system
);
837 * dmi_first_match - find dmi_system_id structure matching system DMI data
838 * @list: array of dmi_system_id structures to match against
839 * All non-null elements of the list must match
840 * their slot's (field index's) data (i.e., each
841 * list string must be a substring of the specified
842 * DMI slot's string data) to be considered a
845 * Walk the blacklist table until the first match is found. Return the
846 * pointer to the matching entry or NULL if there's no match.
848 * dmi_scan_machine must be called before this function is called.
850 const struct dmi_system_id
*dmi_first_match(const struct dmi_system_id
*list
)
852 const struct dmi_system_id
*d
;
854 for (d
= list
; !dmi_is_end_of_table(d
); d
++)
860 EXPORT_SYMBOL(dmi_first_match
);
863 * dmi_get_system_info - return DMI data value
864 * @field: data index (see enum dmi_field)
866 * Returns one DMI data value, can be used to perform
867 * complex DMI data checks.
869 const char *dmi_get_system_info(int field
)
871 return dmi_ident
[field
];
873 EXPORT_SYMBOL(dmi_get_system_info
);
876 * dmi_name_in_serial - Check if string is in the DMI product serial information
877 * @str: string to check for
879 int dmi_name_in_serial(const char *str
)
881 int f
= DMI_PRODUCT_SERIAL
;
882 if (dmi_ident
[f
] && strstr(dmi_ident
[f
], str
))
888 * dmi_name_in_vendors - Check if string is in the DMI system or board vendor name
889 * @str: Case sensitive Name
891 int dmi_name_in_vendors(const char *str
)
893 static int fields
[] = { DMI_SYS_VENDOR
, DMI_BOARD_VENDOR
, DMI_NONE
};
895 for (i
= 0; fields
[i
] != DMI_NONE
; i
++) {
897 if (dmi_ident
[f
] && strstr(dmi_ident
[f
], str
))
902 EXPORT_SYMBOL(dmi_name_in_vendors
);
905 * dmi_find_device - find onboard device by type/name
906 * @type: device type or %DMI_DEV_TYPE_ANY to match all device types
907 * @name: device name string or %NULL to match all
908 * @from: previous device found in search, or %NULL for new search.
910 * Iterates through the list of known onboard devices. If a device is
911 * found with a matching @type and @name, a pointer to its device
912 * structure is returned. Otherwise, %NULL is returned.
913 * A new search is initiated by passing %NULL as the @from argument.
914 * If @from is not %NULL, searches continue from next device.
916 const struct dmi_device
*dmi_find_device(int type
, const char *name
,
917 const struct dmi_device
*from
)
919 const struct list_head
*head
= from
? &from
->list
: &dmi_devices
;
922 for (d
= head
->next
; d
!= &dmi_devices
; d
= d
->next
) {
923 const struct dmi_device
*dev
=
924 list_entry(d
, struct dmi_device
, list
);
926 if (((type
== DMI_DEV_TYPE_ANY
) || (dev
->type
== type
)) &&
927 ((name
== NULL
) || (strcmp(dev
->name
, name
) == 0)))
933 EXPORT_SYMBOL(dmi_find_device
);
936 * dmi_get_date - parse a DMI date
937 * @field: data index (see enum dmi_field)
938 * @yearp: optional out parameter for the year
939 * @monthp: optional out parameter for the month
940 * @dayp: optional out parameter for the day
942 * The date field is assumed to be in the form resembling
943 * [mm[/dd]]/yy[yy] and the result is stored in the out
944 * parameters any or all of which can be omitted.
946 * If the field doesn't exist, all out parameters are set to zero
947 * and false is returned. Otherwise, true is returned with any
948 * invalid part of date set to zero.
950 * On return, year, month and day are guaranteed to be in the
951 * range of [0,9999], [0,12] and [0,31] respectively.
953 bool dmi_get_date(int field
, int *yearp
, int *monthp
, int *dayp
)
955 int year
= 0, month
= 0, day
= 0;
960 s
= dmi_get_system_info(field
);
966 * Determine year first. We assume the date string resembles
967 * mm/dd/yy[yy] but the original code extracted only the year
968 * from the end. Keep the behavior in the spirit of no
976 year
= simple_strtoul(y
, &e
, 10);
977 if (y
!= e
&& year
< 100) { /* 2-digit year */
979 if (year
< 1996) /* no dates < spec 1.0 */
982 if (year
> 9999) /* year should fit in %04d */
985 /* parse the mm and dd */
986 month
= simple_strtoul(s
, &e
, 10);
987 if (s
== e
|| *e
!= '/' || !month
|| month
> 12) {
993 day
= simple_strtoul(s
, &e
, 10);
994 if (s
== y
|| s
== e
|| *e
!= '/' || day
> 31)
1005 EXPORT_SYMBOL(dmi_get_date
);
1008 * dmi_walk - Walk the DMI table and get called back for every record
1009 * @decode: Callback function
1010 * @private_data: Private data to be passed to the callback function
1012 * Returns 0 on success, -ENXIO if DMI is not selected or not present,
1013 * or a different negative error code if DMI walking fails.
1015 int dmi_walk(void (*decode
)(const struct dmi_header
*, void *),
1023 buf
= dmi_remap(dmi_base
, dmi_len
);
1027 dmi_decode_table(buf
, decode
, private_data
);
1032 EXPORT_SYMBOL_GPL(dmi_walk
);
1035 * dmi_match - compare a string to the dmi field (if exists)
1036 * @f: DMI field identifier
1037 * @str: string to compare the DMI field to
1039 * Returns true if the requested field equals to the str (including NULL).
1041 bool dmi_match(enum dmi_field f
, const char *str
)
1043 const char *info
= dmi_get_system_info(f
);
1045 if (info
== NULL
|| str
== NULL
)
1048 return !strcmp(info
, str
);
1050 EXPORT_SYMBOL_GPL(dmi_match
);
1052 void dmi_memdev_name(u16 handle
, const char **bank
, const char **device
)
1056 if (dmi_memdev
== NULL
)
1059 for (n
= 0; n
< dmi_memdev_nr
; n
++) {
1060 if (handle
== dmi_memdev
[n
].handle
) {
1061 *bank
= dmi_memdev
[n
].bank
;
1062 *device
= dmi_memdev
[n
].device
;
1067 EXPORT_SYMBOL_GPL(dmi_memdev_name
);