1 // SPDX-License-Identifier: GPL-2.0-only
2 #include <linux/types.h>
3 #include <linux/string.h>
4 #include <linux/init.h>
5 #include <linux/module.h>
6 #include <linux/ctype.h>
9 #include <linux/memblock.h>
10 #include <linux/random.h>
12 #include <asm/unaligned.h>
14 struct kobject
*dmi_kobj
;
15 EXPORT_SYMBOL_GPL(dmi_kobj
);
18 * DMI stands for "Desktop Management Interface". It is part
19 * of and an antecedent to, SMBIOS, which stands for System
20 * Management BIOS. See further: http://www.dmtf.org/standards
22 static const char dmi_empty_string
[] = "";
24 static u32 dmi_ver __initdata
;
27 static u8 smbios_entry_point
[32];
28 static int smbios_entry_point_size
;
30 /* DMI system identification string used during boot */
31 static char dmi_ids_string
[128] __initdata
;
33 static struct dmi_memdev_info
{
39 static int dmi_memdev_nr
;
41 static const char * __init
dmi_string_nosave(const struct dmi_header
*dm
, u8 s
)
43 const u8
*bp
= ((u8
*) dm
) + dm
->length
;
47 while (--s
> 0 && *bp
)
50 /* Strings containing only spaces are considered empty */
58 return dmi_empty_string
;
61 static const char * __init
dmi_string(const struct dmi_header
*dm
, u8 s
)
63 const char *bp
= dmi_string_nosave(dm
, s
);
67 if (bp
== dmi_empty_string
)
68 return dmi_empty_string
;
79 * We have to be cautious here. We have seen BIOSes with DMI pointers
80 * pointing to completely the wrong place for example
82 static void dmi_decode_table(u8
*buf
,
83 void (*decode
)(const struct dmi_header
*, void *),
90 * Stop when we have seen all the items the table claimed to have
91 * (SMBIOS < 3.0 only) OR we reach an end-of-table marker (SMBIOS
92 * >= 3.0 only) OR we run off the end of the table (should never
93 * happen but sometimes does on bogus implementations.)
95 while ((!dmi_num
|| i
< dmi_num
) &&
96 (data
- buf
+ sizeof(struct dmi_header
)) <= dmi_len
) {
97 const struct dmi_header
*dm
= (const struct dmi_header
*)data
;
100 * We want to know the total length (formatted area and
101 * strings) before decoding to make sure we won't run off the
102 * table in dmi_decode or dmi_string
105 while ((data
- buf
< dmi_len
- 1) && (data
[0] || data
[1]))
107 if (data
- buf
< dmi_len
- 1)
108 decode(dm
, private_data
);
114 * 7.45 End-of-Table (Type 127) [SMBIOS reference spec v3.0.0]
115 * For tables behind a 64-bit entry point, we have no item
116 * count and no exact table length, so stop on end-of-table
117 * marker. For tables behind a 32-bit entry point, we have
118 * seen OEM structures behind the end-of-table marker on
119 * some systems, so don't trust it.
121 if (!dmi_num
&& dm
->type
== DMI_ENTRY_END_OF_TABLE
)
125 /* Trim DMI table length if needed */
126 if (dmi_len
> data
- buf
)
127 dmi_len
= data
- buf
;
130 static phys_addr_t dmi_base
;
132 static int __init
dmi_walk_early(void (*decode
)(const struct dmi_header
*,
136 u32 orig_dmi_len
= dmi_len
;
138 buf
= dmi_early_remap(dmi_base
, orig_dmi_len
);
142 dmi_decode_table(buf
, decode
, NULL
);
144 add_device_randomness(buf
, dmi_len
);
146 dmi_early_unmap(buf
, orig_dmi_len
);
150 static int __init
dmi_checksum(const u8
*buf
, u8 len
)
155 for (a
= 0; a
< len
; a
++)
161 static const char *dmi_ident
[DMI_STRING_MAX
];
162 static LIST_HEAD(dmi_devices
);
168 static void __init
dmi_save_ident(const struct dmi_header
*dm
, int slot
,
171 const char *d
= (const char *) dm
;
174 if (dmi_ident
[slot
] || dm
->length
<= string
)
177 p
= dmi_string(dm
, d
[string
]);
184 static void __init
dmi_save_uuid(const struct dmi_header
*dm
, int slot
,
189 int is_ff
= 1, is_00
= 1, i
;
191 if (dmi_ident
[slot
] || dm
->length
< index
+ 16)
194 d
= (u8
*) dm
+ index
;
195 for (i
= 0; i
< 16 && (is_ff
|| is_00
); i
++) {
205 s
= dmi_alloc(16*2+4+1);
210 * As of version 2.6 of the SMBIOS specification, the first 3 fields of
211 * the UUID are supposed to be little-endian encoded. The specification
212 * says that this is the defacto standard.
214 if (dmi_ver
>= 0x020600)
215 sprintf(s
, "%pUl", d
);
217 sprintf(s
, "%pUb", d
);
222 static void __init
dmi_save_type(const struct dmi_header
*dm
, int slot
,
228 if (dmi_ident
[slot
] || dm
->length
<= index
)
235 d
= (u8
*) dm
+ index
;
236 sprintf(s
, "%u", *d
& 0x7F);
240 static void __init
dmi_save_one_device(int type
, const char *name
)
242 struct dmi_device
*dev
;
244 /* No duplicate device */
245 if (dmi_find_device(type
, name
, NULL
))
248 dev
= dmi_alloc(sizeof(*dev
) + strlen(name
) + 1);
253 strcpy((char *)(dev
+ 1), name
);
254 dev
->name
= (char *)(dev
+ 1);
255 dev
->device_data
= NULL
;
256 list_add(&dev
->list
, &dmi_devices
);
259 static void __init
dmi_save_devices(const struct dmi_header
*dm
)
261 int i
, count
= (dm
->length
- sizeof(struct dmi_header
)) / 2;
263 for (i
= 0; i
< count
; i
++) {
264 const char *d
= (char *)(dm
+ 1) + (i
* 2);
266 /* Skip disabled device */
267 if ((*d
& 0x80) == 0)
270 dmi_save_one_device(*d
& 0x7f, dmi_string_nosave(dm
, *(d
+ 1)));
274 static void __init
dmi_save_oem_strings_devices(const struct dmi_header
*dm
)
277 struct dmi_device
*dev
;
279 if (dm
->length
< 0x05)
282 count
= *(u8
*)(dm
+ 1);
283 for (i
= 1; i
<= count
; i
++) {
284 const char *devname
= dmi_string(dm
, i
);
286 if (devname
== dmi_empty_string
)
289 dev
= dmi_alloc(sizeof(*dev
));
293 dev
->type
= DMI_DEV_TYPE_OEM_STRING
;
295 dev
->device_data
= NULL
;
297 list_add(&dev
->list
, &dmi_devices
);
301 static void __init
dmi_save_ipmi_device(const struct dmi_header
*dm
)
303 struct dmi_device
*dev
;
306 data
= dmi_alloc(dm
->length
);
310 memcpy(data
, dm
, dm
->length
);
312 dev
= dmi_alloc(sizeof(*dev
));
316 dev
->type
= DMI_DEV_TYPE_IPMI
;
317 dev
->name
= "IPMI controller";
318 dev
->device_data
= data
;
320 list_add_tail(&dev
->list
, &dmi_devices
);
323 static void __init
dmi_save_dev_pciaddr(int instance
, int segment
, int bus
,
324 int devfn
, const char *name
, int type
)
326 struct dmi_dev_onboard
*dev
;
328 /* Ignore invalid values */
329 if (type
== DMI_DEV_TYPE_DEV_SLOT
&&
330 segment
== 0xFFFF && bus
== 0xFF && devfn
== 0xFF)
333 dev
= dmi_alloc(sizeof(*dev
) + strlen(name
) + 1);
337 dev
->instance
= instance
;
338 dev
->segment
= segment
;
342 strcpy((char *)&dev
[1], name
);
343 dev
->dev
.type
= type
;
344 dev
->dev
.name
= (char *)&dev
[1];
345 dev
->dev
.device_data
= dev
;
347 list_add(&dev
->dev
.list
, &dmi_devices
);
350 static void __init
dmi_save_extended_devices(const struct dmi_header
*dm
)
353 const u8
*d
= (u8
*)dm
;
355 if (dm
->length
< 0x0B)
358 /* Skip disabled device */
359 if ((d
[0x5] & 0x80) == 0)
362 name
= dmi_string_nosave(dm
, d
[0x4]);
363 dmi_save_dev_pciaddr(d
[0x6], *(u16
*)(d
+ 0x7), d
[0x9], d
[0xA], name
,
364 DMI_DEV_TYPE_DEV_ONBOARD
);
365 dmi_save_one_device(d
[0x5] & 0x7f, name
);
368 static void __init
dmi_save_system_slot(const struct dmi_header
*dm
)
370 const u8
*d
= (u8
*)dm
;
372 /* Need SMBIOS 2.6+ structure */
373 if (dm
->length
< 0x11)
375 dmi_save_dev_pciaddr(*(u16
*)(d
+ 0x9), *(u16
*)(d
+ 0xD), d
[0xF],
376 d
[0x10], dmi_string_nosave(dm
, d
[0x4]),
377 DMI_DEV_TYPE_DEV_SLOT
);
380 static void __init
count_mem_devices(const struct dmi_header
*dm
, void *v
)
382 if (dm
->type
!= DMI_ENTRY_MEM_DEVICE
)
387 static void __init
save_mem_devices(const struct dmi_header
*dm
, void *v
)
389 const char *d
= (const char *)dm
;
394 if (dm
->type
!= DMI_ENTRY_MEM_DEVICE
|| dm
->length
< 0x12)
396 if (nr
>= dmi_memdev_nr
) {
397 pr_warn(FW_BUG
"Too many DIMM entries in SMBIOS table\n");
400 dmi_memdev
[nr
].handle
= get_unaligned(&dm
->handle
);
401 dmi_memdev
[nr
].device
= dmi_string(dm
, d
[0x10]);
402 dmi_memdev
[nr
].bank
= dmi_string(dm
, d
[0x11]);
404 size
= get_unaligned((u16
*)&d
[0xC]);
407 else if (size
== 0xffff)
409 else if (size
& 0x8000)
410 bytes
= (u64
)(size
& 0x7fff) << 10;
411 else if (size
!= 0x7fff)
412 bytes
= (u64
)size
<< 20;
414 bytes
= (u64
)get_unaligned((u32
*)&d
[0x1C]) << 20;
416 dmi_memdev
[nr
].size
= bytes
;
420 static void __init
dmi_memdev_walk(void)
422 if (dmi_walk_early(count_mem_devices
) == 0 && dmi_memdev_nr
) {
423 dmi_memdev
= dmi_alloc(sizeof(*dmi_memdev
) * dmi_memdev_nr
);
425 dmi_walk_early(save_mem_devices
);
430 * Process a DMI table entry. Right now all we care about are the BIOS
431 * and machine entries. For 2.5 we should pull the smbus controller info
434 static void __init
dmi_decode(const struct dmi_header
*dm
, void *dummy
)
437 case 0: /* BIOS Information */
438 dmi_save_ident(dm
, DMI_BIOS_VENDOR
, 4);
439 dmi_save_ident(dm
, DMI_BIOS_VERSION
, 5);
440 dmi_save_ident(dm
, DMI_BIOS_DATE
, 8);
442 case 1: /* System Information */
443 dmi_save_ident(dm
, DMI_SYS_VENDOR
, 4);
444 dmi_save_ident(dm
, DMI_PRODUCT_NAME
, 5);
445 dmi_save_ident(dm
, DMI_PRODUCT_VERSION
, 6);
446 dmi_save_ident(dm
, DMI_PRODUCT_SERIAL
, 7);
447 dmi_save_uuid(dm
, DMI_PRODUCT_UUID
, 8);
448 dmi_save_ident(dm
, DMI_PRODUCT_SKU
, 25);
449 dmi_save_ident(dm
, DMI_PRODUCT_FAMILY
, 26);
451 case 2: /* Base Board Information */
452 dmi_save_ident(dm
, DMI_BOARD_VENDOR
, 4);
453 dmi_save_ident(dm
, DMI_BOARD_NAME
, 5);
454 dmi_save_ident(dm
, DMI_BOARD_VERSION
, 6);
455 dmi_save_ident(dm
, DMI_BOARD_SERIAL
, 7);
456 dmi_save_ident(dm
, DMI_BOARD_ASSET_TAG
, 8);
458 case 3: /* Chassis Information */
459 dmi_save_ident(dm
, DMI_CHASSIS_VENDOR
, 4);
460 dmi_save_type(dm
, DMI_CHASSIS_TYPE
, 5);
461 dmi_save_ident(dm
, DMI_CHASSIS_VERSION
, 6);
462 dmi_save_ident(dm
, DMI_CHASSIS_SERIAL
, 7);
463 dmi_save_ident(dm
, DMI_CHASSIS_ASSET_TAG
, 8);
465 case 9: /* System Slots */
466 dmi_save_system_slot(dm
);
468 case 10: /* Onboard Devices Information */
469 dmi_save_devices(dm
);
471 case 11: /* OEM Strings */
472 dmi_save_oem_strings_devices(dm
);
474 case 38: /* IPMI Device Information */
475 dmi_save_ipmi_device(dm
);
477 case 41: /* Onboard Devices Extended Information */
478 dmi_save_extended_devices(dm
);
482 static int __init
print_filtered(char *buf
, size_t len
, const char *info
)
490 for (p
= info
; *p
; p
++)
492 c
+= scnprintf(buf
+ c
, len
- c
, "%c", *p
);
494 c
+= scnprintf(buf
+ c
, len
- c
, "\\x%02x", *p
& 0xff);
498 static void __init
dmi_format_ids(char *buf
, size_t len
)
501 const char *board
; /* Board Name is optional */
503 c
+= print_filtered(buf
+ c
, len
- c
,
504 dmi_get_system_info(DMI_SYS_VENDOR
));
505 c
+= scnprintf(buf
+ c
, len
- c
, " ");
506 c
+= print_filtered(buf
+ c
, len
- c
,
507 dmi_get_system_info(DMI_PRODUCT_NAME
));
509 board
= dmi_get_system_info(DMI_BOARD_NAME
);
511 c
+= scnprintf(buf
+ c
, len
- c
, "/");
512 c
+= print_filtered(buf
+ c
, len
- c
, board
);
514 c
+= scnprintf(buf
+ c
, len
- c
, ", BIOS ");
515 c
+= print_filtered(buf
+ c
, len
- c
,
516 dmi_get_system_info(DMI_BIOS_VERSION
));
517 c
+= scnprintf(buf
+ c
, len
- c
, " ");
518 c
+= print_filtered(buf
+ c
, len
- c
,
519 dmi_get_system_info(DMI_BIOS_DATE
));
523 * Check for DMI/SMBIOS headers in the system firmware image. Any
524 * SMBIOS header must start 16 bytes before the DMI header, so take a
525 * 32 byte buffer and check for DMI at offset 16 and SMBIOS at offset
526 * 0. If the DMI header is present, set dmi_ver accordingly (SMBIOS
527 * takes precedence) and return 0. Otherwise return 1.
529 static int __init
dmi_present(const u8
*buf
)
533 if (memcmp(buf
, "_SM_", 4) == 0 &&
534 buf
[5] < 32 && dmi_checksum(buf
, buf
[5])) {
535 smbios_ver
= get_unaligned_be16(buf
+ 6);
536 smbios_entry_point_size
= buf
[5];
537 memcpy(smbios_entry_point
, buf
, smbios_entry_point_size
);
539 /* Some BIOS report weird SMBIOS version, fix that up */
540 switch (smbios_ver
) {
543 pr_debug("SMBIOS version fixup (2.%d->2.%d)\n",
544 smbios_ver
& 0xFF, 3);
548 pr_debug("SMBIOS version fixup (2.%d->2.%d)\n", 51, 6);
558 if (memcmp(buf
, "_DMI_", 5) == 0 && dmi_checksum(buf
, 15)) {
560 dmi_ver
= smbios_ver
;
562 dmi_ver
= (buf
[14] & 0xF0) << 4 | (buf
[14] & 0x0F);
564 dmi_num
= get_unaligned_le16(buf
+ 12);
565 dmi_len
= get_unaligned_le16(buf
+ 6);
566 dmi_base
= get_unaligned_le32(buf
+ 8);
568 if (dmi_walk_early(dmi_decode
) == 0) {
570 pr_info("SMBIOS %d.%d present.\n",
571 dmi_ver
>> 16, (dmi_ver
>> 8) & 0xFF);
573 smbios_entry_point_size
= 15;
574 memcpy(smbios_entry_point
, buf
,
575 smbios_entry_point_size
);
576 pr_info("Legacy DMI %d.%d present.\n",
577 dmi_ver
>> 16, (dmi_ver
>> 8) & 0xFF);
579 dmi_format_ids(dmi_ids_string
, sizeof(dmi_ids_string
));
580 pr_info("DMI: %s\n", dmi_ids_string
);
589 * Check for the SMBIOS 3.0 64-bit entry point signature. Unlike the legacy
590 * 32-bit entry point, there is no embedded DMI header (_DMI_) in here.
592 static int __init
dmi_smbios3_present(const u8
*buf
)
594 if (memcmp(buf
, "_SM3_", 5) == 0 &&
595 buf
[6] < 32 && dmi_checksum(buf
, buf
[6])) {
596 dmi_ver
= get_unaligned_be32(buf
+ 6) & 0xFFFFFF;
597 dmi_num
= 0; /* No longer specified */
598 dmi_len
= get_unaligned_le32(buf
+ 12);
599 dmi_base
= get_unaligned_le64(buf
+ 16);
600 smbios_entry_point_size
= buf
[6];
601 memcpy(smbios_entry_point
, buf
, smbios_entry_point_size
);
603 if (dmi_walk_early(dmi_decode
) == 0) {
604 pr_info("SMBIOS %d.%d.%d present.\n",
605 dmi_ver
>> 16, (dmi_ver
>> 8) & 0xFF,
607 dmi_format_ids(dmi_ids_string
, sizeof(dmi_ids_string
));
608 pr_info("DMI: %s\n", dmi_ids_string
);
615 static void __init
dmi_scan_machine(void)
620 if (efi_enabled(EFI_CONFIG_TABLES
)) {
622 * According to the DMTF SMBIOS reference spec v3.0.0, it is
623 * allowed to define both the 64-bit entry point (smbios3) and
624 * the 32-bit entry point (smbios), in which case they should
625 * either both point to the same SMBIOS structure table, or the
626 * table pointed to by the 64-bit entry point should contain a
627 * superset of the table contents pointed to by the 32-bit entry
628 * point (section 5.2)
629 * This implies that the 64-bit entry point should have
630 * precedence if it is defined and supported by the OS. If we
631 * have the 64-bit entry point, but fail to decode it, fall
632 * back to the legacy one (if available)
634 if (efi
.smbios3
!= EFI_INVALID_TABLE_ADDR
) {
635 p
= dmi_early_remap(efi
.smbios3
, 32);
638 memcpy_fromio(buf
, p
, 32);
639 dmi_early_unmap(p
, 32);
641 if (!dmi_smbios3_present(buf
)) {
646 if (efi
.smbios
== EFI_INVALID_TABLE_ADDR
)
649 /* This is called as a core_initcall() because it isn't
650 * needed during early boot. This also means we can
651 * iounmap the space when we're done with it.
653 p
= dmi_early_remap(efi
.smbios
, 32);
656 memcpy_fromio(buf
, p
, 32);
657 dmi_early_unmap(p
, 32);
659 if (!dmi_present(buf
)) {
663 } else if (IS_ENABLED(CONFIG_DMI_SCAN_MACHINE_NON_EFI_FALLBACK
)) {
664 p
= dmi_early_remap(0xF0000, 0x10000);
669 * Same logic as above, look for a 64-bit entry point
670 * first, and if not found, fall back to 32-bit entry point.
672 memcpy_fromio(buf
, p
, 16);
673 for (q
= p
+ 16; q
< p
+ 0x10000; q
+= 16) {
674 memcpy_fromio(buf
+ 16, q
, 16);
675 if (!dmi_smbios3_present(buf
)) {
677 dmi_early_unmap(p
, 0x10000);
680 memcpy(buf
, buf
+ 16, 16);
684 * Iterate over all possible DMI header addresses q.
685 * Maintain the 32 bytes around q in buf. On the
686 * first iteration, substitute zero for the
687 * out-of-range bytes so there is no chance of falsely
688 * detecting an SMBIOS header.
691 for (q
= p
; q
< p
+ 0x10000; q
+= 16) {
692 memcpy_fromio(buf
+ 16, q
, 16);
693 if (!dmi_present(buf
)) {
695 dmi_early_unmap(p
, 0x10000);
698 memcpy(buf
, buf
+ 16, 16);
700 dmi_early_unmap(p
, 0x10000);
703 pr_info("DMI not present or invalid.\n");
706 static ssize_t
raw_table_read(struct file
*file
, struct kobject
*kobj
,
707 struct bin_attribute
*attr
, char *buf
,
708 loff_t pos
, size_t count
)
710 memcpy(buf
, attr
->private + pos
, count
);
714 static BIN_ATTR(smbios_entry_point
, S_IRUSR
, raw_table_read
, NULL
, 0);
715 static BIN_ATTR(DMI
, S_IRUSR
, raw_table_read
, NULL
, 0);
717 static int __init
dmi_init(void)
719 struct kobject
*tables_kobj
;
727 * Set up dmi directory at /sys/firmware/dmi. This entry should stay
728 * even after farther error, as it can be used by other modules like
731 dmi_kobj
= kobject_create_and_add("dmi", firmware_kobj
);
735 tables_kobj
= kobject_create_and_add("tables", dmi_kobj
);
739 dmi_table
= dmi_remap(dmi_base
, dmi_len
);
743 bin_attr_smbios_entry_point
.size
= smbios_entry_point_size
;
744 bin_attr_smbios_entry_point
.private = smbios_entry_point
;
745 ret
= sysfs_create_bin_file(tables_kobj
, &bin_attr_smbios_entry_point
);
749 bin_attr_DMI
.size
= dmi_len
;
750 bin_attr_DMI
.private = dmi_table
;
751 ret
= sysfs_create_bin_file(tables_kobj
, &bin_attr_DMI
);
755 sysfs_remove_bin_file(tables_kobj
,
756 &bin_attr_smbios_entry_point
);
758 dmi_unmap(dmi_table
);
760 kobject_del(tables_kobj
);
761 kobject_put(tables_kobj
);
763 pr_err("dmi: Firmware registration failed.\n");
767 subsys_initcall(dmi_init
);
770 * dmi_setup - scan and setup DMI system information
772 * Scan the DMI system information. This setups DMI identifiers
773 * (dmi_system_id) for printing it out on task dumps and prepares
774 * DIMM entry information (dmi_memdev_info) from the SMBIOS table
775 * for using this when reporting memory errors.
777 void __init
dmi_setup(void)
784 dump_stack_set_arch_desc("%s", dmi_ids_string
);
788 * dmi_matches - check if dmi_system_id structure matches system DMI data
789 * @dmi: pointer to the dmi_system_id structure to check
791 static bool dmi_matches(const struct dmi_system_id
*dmi
)
795 for (i
= 0; i
< ARRAY_SIZE(dmi
->matches
); i
++) {
796 int s
= dmi
->matches
[i
].slot
;
799 if (s
== DMI_OEM_STRING
) {
800 /* DMI_OEM_STRING must be exact match */
801 const struct dmi_device
*valid
;
803 valid
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
,
804 dmi
->matches
[i
].substr
, NULL
);
807 } else if (dmi_ident
[s
]) {
808 if (dmi
->matches
[i
].exact_match
) {
809 if (!strcmp(dmi_ident
[s
],
810 dmi
->matches
[i
].substr
))
813 if (strstr(dmi_ident
[s
],
814 dmi
->matches
[i
].substr
))
826 * dmi_is_end_of_table - check for end-of-table marker
827 * @dmi: pointer to the dmi_system_id structure to check
829 static bool dmi_is_end_of_table(const struct dmi_system_id
*dmi
)
831 return dmi
->matches
[0].slot
== DMI_NONE
;
835 * dmi_check_system - check system DMI data
836 * @list: array of dmi_system_id structures to match against
837 * All non-null elements of the list must match
838 * their slot's (field index's) data (i.e., each
839 * list string must be a substring of the specified
840 * DMI slot's string data) to be considered a
843 * Walk the blacklist table running matching functions until someone
844 * returns non zero or we hit the end. Callback function is called for
845 * each successful match. Returns the number of matches.
847 * dmi_setup must be called before this function is called.
849 int dmi_check_system(const struct dmi_system_id
*list
)
852 const struct dmi_system_id
*d
;
854 for (d
= list
; !dmi_is_end_of_table(d
); d
++)
855 if (dmi_matches(d
)) {
857 if (d
->callback
&& d
->callback(d
))
863 EXPORT_SYMBOL(dmi_check_system
);
866 * dmi_first_match - find dmi_system_id structure matching system DMI data
867 * @list: array of dmi_system_id structures to match against
868 * All non-null elements of the list must match
869 * their slot's (field index's) data (i.e., each
870 * list string must be a substring of the specified
871 * DMI slot's string data) to be considered a
874 * Walk the blacklist table until the first match is found. Return the
875 * pointer to the matching entry or NULL if there's no match.
877 * dmi_setup must be called before this function is called.
879 const struct dmi_system_id
*dmi_first_match(const struct dmi_system_id
*list
)
881 const struct dmi_system_id
*d
;
883 for (d
= list
; !dmi_is_end_of_table(d
); d
++)
889 EXPORT_SYMBOL(dmi_first_match
);
892 * dmi_get_system_info - return DMI data value
893 * @field: data index (see enum dmi_field)
895 * Returns one DMI data value, can be used to perform
896 * complex DMI data checks.
898 const char *dmi_get_system_info(int field
)
900 return dmi_ident
[field
];
902 EXPORT_SYMBOL(dmi_get_system_info
);
905 * dmi_name_in_serial - Check if string is in the DMI product serial information
906 * @str: string to check for
908 int dmi_name_in_serial(const char *str
)
910 int f
= DMI_PRODUCT_SERIAL
;
911 if (dmi_ident
[f
] && strstr(dmi_ident
[f
], str
))
917 * dmi_name_in_vendors - Check if string is in the DMI system or board vendor name
918 * @str: Case sensitive Name
920 int dmi_name_in_vendors(const char *str
)
922 static int fields
[] = { DMI_SYS_VENDOR
, DMI_BOARD_VENDOR
, DMI_NONE
};
924 for (i
= 0; fields
[i
] != DMI_NONE
; i
++) {
926 if (dmi_ident
[f
] && strstr(dmi_ident
[f
], str
))
931 EXPORT_SYMBOL(dmi_name_in_vendors
);
934 * dmi_find_device - find onboard device by type/name
935 * @type: device type or %DMI_DEV_TYPE_ANY to match all device types
936 * @name: device name string or %NULL to match all
937 * @from: previous device found in search, or %NULL for new search.
939 * Iterates through the list of known onboard devices. If a device is
940 * found with a matching @type and @name, a pointer to its device
941 * structure is returned. Otherwise, %NULL is returned.
942 * A new search is initiated by passing %NULL as the @from argument.
943 * If @from is not %NULL, searches continue from next device.
945 const struct dmi_device
*dmi_find_device(int type
, const char *name
,
946 const struct dmi_device
*from
)
948 const struct list_head
*head
= from
? &from
->list
: &dmi_devices
;
951 for (d
= head
->next
; d
!= &dmi_devices
; d
= d
->next
) {
952 const struct dmi_device
*dev
=
953 list_entry(d
, struct dmi_device
, list
);
955 if (((type
== DMI_DEV_TYPE_ANY
) || (dev
->type
== type
)) &&
956 ((name
== NULL
) || (strcmp(dev
->name
, name
) == 0)))
962 EXPORT_SYMBOL(dmi_find_device
);
965 * dmi_get_date - parse a DMI date
966 * @field: data index (see enum dmi_field)
967 * @yearp: optional out parameter for the year
968 * @monthp: optional out parameter for the month
969 * @dayp: optional out parameter for the day
971 * The date field is assumed to be in the form resembling
972 * [mm[/dd]]/yy[yy] and the result is stored in the out
973 * parameters any or all of which can be omitted.
975 * If the field doesn't exist, all out parameters are set to zero
976 * and false is returned. Otherwise, true is returned with any
977 * invalid part of date set to zero.
979 * On return, year, month and day are guaranteed to be in the
980 * range of [0,9999], [0,12] and [0,31] respectively.
982 bool dmi_get_date(int field
, int *yearp
, int *monthp
, int *dayp
)
984 int year
= 0, month
= 0, day
= 0;
989 s
= dmi_get_system_info(field
);
995 * Determine year first. We assume the date string resembles
996 * mm/dd/yy[yy] but the original code extracted only the year
997 * from the end. Keep the behavior in the spirit of no
1000 y
= strrchr(s
, '/');
1005 year
= simple_strtoul(y
, &e
, 10);
1006 if (y
!= e
&& year
< 100) { /* 2-digit year */
1008 if (year
< 1996) /* no dates < spec 1.0 */
1011 if (year
> 9999) /* year should fit in %04d */
1014 /* parse the mm and dd */
1015 month
= simple_strtoul(s
, &e
, 10);
1016 if (s
== e
|| *e
!= '/' || !month
|| month
> 12) {
1022 day
= simple_strtoul(s
, &e
, 10);
1023 if (s
== y
|| s
== e
|| *e
!= '/' || day
> 31)
1034 EXPORT_SYMBOL(dmi_get_date
);
1037 * dmi_get_bios_year - get a year out of DMI_BIOS_DATE field
1039 * Returns year on success, -ENXIO if DMI is not selected,
1040 * or a different negative error code if DMI field is not present
1043 int dmi_get_bios_year(void)
1048 exists
= dmi_get_date(DMI_BIOS_DATE
, &year
, NULL
, NULL
);
1052 return year
? year
: -ERANGE
;
1054 EXPORT_SYMBOL(dmi_get_bios_year
);
1057 * dmi_walk - Walk the DMI table and get called back for every record
1058 * @decode: Callback function
1059 * @private_data: Private data to be passed to the callback function
1061 * Returns 0 on success, -ENXIO if DMI is not selected or not present,
1062 * or a different negative error code if DMI walking fails.
1064 int dmi_walk(void (*decode
)(const struct dmi_header
*, void *),
1072 buf
= dmi_remap(dmi_base
, dmi_len
);
1076 dmi_decode_table(buf
, decode
, private_data
);
1081 EXPORT_SYMBOL_GPL(dmi_walk
);
1084 * dmi_match - compare a string to the dmi field (if exists)
1085 * @f: DMI field identifier
1086 * @str: string to compare the DMI field to
1088 * Returns true if the requested field equals to the str (including NULL).
1090 bool dmi_match(enum dmi_field f
, const char *str
)
1092 const char *info
= dmi_get_system_info(f
);
1094 if (info
== NULL
|| str
== NULL
)
1097 return !strcmp(info
, str
);
1099 EXPORT_SYMBOL_GPL(dmi_match
);
1101 void dmi_memdev_name(u16 handle
, const char **bank
, const char **device
)
1105 if (dmi_memdev
== NULL
)
1108 for (n
= 0; n
< dmi_memdev_nr
; n
++) {
1109 if (handle
== dmi_memdev
[n
].handle
) {
1110 *bank
= dmi_memdev
[n
].bank
;
1111 *device
= dmi_memdev
[n
].device
;
1116 EXPORT_SYMBOL_GPL(dmi_memdev_name
);
1118 u64
dmi_memdev_size(u16 handle
)
1123 for (n
= 0; n
< dmi_memdev_nr
; n
++) {
1124 if (handle
== dmi_memdev
[n
].handle
)
1125 return dmi_memdev
[n
].size
;
1130 EXPORT_SYMBOL_GPL(dmi_memdev_size
);