dmi_scan.c (80f9d9023058e156eb09226ac339f56a8411bc8a) dmi_scan.c (66bc1a173328dec3e37c203a999f2a2914c96b56)
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>
7#include <linux/dmi.h>
8#include <linux/efi.h>

--- 28 unchanged lines hidden (view full) ---

37static struct dmi_memdev_info {
38 const char *device;
39 const char *bank;
40 u64 size; /* bytes */
41 u16 handle;
42 u8 type; /* DDR2, DDR3, DDR4 etc */
43} *dmi_memdev;
44static int dmi_memdev_nr;
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>
7#include <linux/dmi.h>
8#include <linux/efi.h>

--- 28 unchanged lines hidden (view full) ---

37static struct dmi_memdev_info {
38 const char *device;
39 const char *bank;
40 u64 size; /* bytes */
41 u16 handle;
42 u8 type; /* DDR2, DDR3, DDR4 etc */
43} *dmi_memdev;
44static int dmi_memdev_nr;
45static int dmi_memdev_populated_nr __initdata;
46
47static const char * __init dmi_string_nosave(const struct dmi_header *dm, u8 s)
48{
49 const u8 *bp = ((u8 *) dm) + dm->length;
50 const u8 *nsp;
51
52 if (s) {
53 while (--s > 0 && *bp)

--- 44 unchanged lines hidden (view full) ---

98 * >= 3.0 only) OR we run off the end of the table (should never
99 * happen but sometimes does on bogus implementations.)
100 */
101 while ((!dmi_num || i < dmi_num) &&
102 (data - buf + sizeof(struct dmi_header)) <= dmi_len) {
103 const struct dmi_header *dm = (const struct dmi_header *)data;
104
105 /*
45
46static const char * __init dmi_string_nosave(const struct dmi_header *dm, u8 s)
47{
48 const u8 *bp = ((u8 *) dm) + dm->length;
49 const u8 *nsp;
50
51 if (s) {
52 while (--s > 0 && *bp)

--- 44 unchanged lines hidden (view full) ---

97 * >= 3.0 only) OR we run off the end of the table (should never
98 * happen but sometimes does on bogus implementations.)
99 */
100 while ((!dmi_num || i < dmi_num) &&
101 (data - buf + sizeof(struct dmi_header)) <= dmi_len) {
102 const struct dmi_header *dm = (const struct dmi_header *)data;
103
104 /*
106 * If a short entry is found (less than 4 bytes), not only it
107 * is invalid, but we cannot reliably locate the next entry.
108 */
109 if (dm->length < sizeof(struct dmi_header)) {
110 pr_warn(FW_BUG
111 "Corrupted DMI table, offset %zd (only %d entries processed)\n",
112 data - buf, i);
113 break;
114 }
115
116 /*
117 * We want to know the total length (formatted area and
118 * strings) before decoding to make sure we won't run off the
119 * table in dmi_decode or dmi_string
120 */
121 data += dm->length;
122 while ((data - buf < dmi_len - 1) && (data[0] || data[1]))
123 data++;
124 if (data - buf < dmi_len - 1)

--- 330 unchanged lines hidden (view full) ---

455 bytes = ~0ull;
456 else if (size & 0x8000)
457 bytes = (u64)(size & 0x7fff) << 10;
458 else if (size != 0x7fff || dm->length < 0x20)
459 bytes = (u64)size << 20;
460 else
461 bytes = (u64)get_unaligned((u32 *)&d[0x1C]) << 20;
462
105 * We want to know the total length (formatted area and
106 * strings) before decoding to make sure we won't run off the
107 * table in dmi_decode or dmi_string
108 */
109 data += dm->length;
110 while ((data - buf < dmi_len - 1) && (data[0] || data[1]))
111 data++;
112 if (data - buf < dmi_len - 1)

--- 330 unchanged lines hidden (view full) ---

443 bytes = ~0ull;
444 else if (size & 0x8000)
445 bytes = (u64)(size & 0x7fff) << 10;
446 else if (size != 0x7fff || dm->length < 0x20)
447 bytes = (u64)size << 20;
448 else
449 bytes = (u64)get_unaligned((u32 *)&d[0x1C]) << 20;
450
463 if (bytes)
464 dmi_memdev_populated_nr++;
465
466 dmi_memdev[nr].size = bytes;
467 nr++;
468}
469
470static void __init dmi_memdev_walk(void)
471{
472 if (dmi_walk_early(count_mem_devices) == 0 && dmi_memdev_nr) {
473 dmi_memdev = dmi_alloc(sizeof(*dmi_memdev) * dmi_memdev_nr);

--- 282 unchanged lines hidden (view full) ---

756 memcpy(buf, buf + 16, 16);
757 }
758 dmi_early_unmap(p, 0x10000);
759 }
760 error:
761 pr_info("DMI not present or invalid.\n");
762}
763
451 dmi_memdev[nr].size = bytes;
452 nr++;
453}
454
455static void __init dmi_memdev_walk(void)
456{
457 if (dmi_walk_early(count_mem_devices) == 0 && dmi_memdev_nr) {
458 dmi_memdev = dmi_alloc(sizeof(*dmi_memdev) * dmi_memdev_nr);

--- 282 unchanged lines hidden (view full) ---

741 memcpy(buf, buf + 16, 16);
742 }
743 dmi_early_unmap(p, 0x10000);
744 }
745 error:
746 pr_info("DMI not present or invalid.\n");
747}
748
764static ssize_t raw_table_read(struct file *file, struct kobject *kobj,
765 struct bin_attribute *attr, char *buf,
766 loff_t pos, size_t count)
767{
768 memcpy(buf, attr->private + pos, count);
769 return count;
770}
749static BIN_ATTR_SIMPLE_ADMIN_RO(smbios_entry_point);
750static BIN_ATTR_SIMPLE_ADMIN_RO(DMI);
771
751
772static BIN_ATTR(smbios_entry_point, S_IRUSR, raw_table_read, NULL, 0);
773static BIN_ATTR(DMI, S_IRUSR, raw_table_read, NULL, 0);
774
775static int __init dmi_init(void)
776{
777 struct kobject *tables_kobj;
778 u8 *dmi_table;
779 int ret = -ENOMEM;
780
781 if (!dmi_available)
782 return 0;

--- 51 unchanged lines hidden (view full) ---

834 */
835void __init dmi_setup(void)
836{
837 dmi_scan_machine();
838 if (!dmi_available)
839 return;
840
841 dmi_memdev_walk();
752static int __init dmi_init(void)
753{
754 struct kobject *tables_kobj;
755 u8 *dmi_table;
756 int ret = -ENOMEM;
757
758 if (!dmi_available)
759 return 0;

--- 51 unchanged lines hidden (view full) ---

811 */
812void __init dmi_setup(void)
813{
814 dmi_scan_machine();
815 if (!dmi_available)
816 return;
817
818 dmi_memdev_walk();
842 pr_info("DMI: Memory slots populated: %d/%d\n",
843 dmi_memdev_populated_nr, dmi_memdev_nr);
844 dump_stack_set_arch_desc("%s", dmi_ids_string);
845}
846
847/**
848 * dmi_matches - check if dmi_system_id structure matches system DMI data
849 * @dmi: pointer to the dmi_system_id structure to check
850 */
851static bool dmi_matches(const struct dmi_system_id *dmi)

--- 376 unchanged lines hidden ---
819 dump_stack_set_arch_desc("%s", dmi_ids_string);
820}
821
822/**
823 * dmi_matches - check if dmi_system_id structure matches system DMI data
824 * @dmi: pointer to the dmi_system_id structure to check
825 */
826static bool dmi_matches(const struct dmi_system_id *dmi)

--- 376 unchanged lines hidden ---