Skip to content

Commit 9e0afe3

Browse files
committed
firmware: dmi: Remember the memory type
Store the memory type while walking the memory slots, and provide a way to retrieve it later. Signed-off-by: Jean Delvare <[email protected]>
1 parent 219d543 commit 9e0afe3

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

drivers/firmware/dmi_scan.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ static struct dmi_memdev_info {
3535
const char *bank;
3636
u64 size; /* bytes */
3737
u16 handle;
38+
u8 type; /* DDR2, DDR3, DDR4 etc */
3839
} *dmi_memdev;
3940
static int dmi_memdev_nr;
4041

@@ -391,7 +392,7 @@ static void __init save_mem_devices(const struct dmi_header *dm, void *v)
391392
u64 bytes;
392393
u16 size;
393394

394-
if (dm->type != DMI_ENTRY_MEM_DEVICE || dm->length < 0x12)
395+
if (dm->type != DMI_ENTRY_MEM_DEVICE || dm->length < 0x13)
395396
return;
396397
if (nr >= dmi_memdev_nr) {
397398
pr_warn(FW_BUG "Too many DIMM entries in SMBIOS table\n");
@@ -400,6 +401,7 @@ static void __init save_mem_devices(const struct dmi_header *dm, void *v)
400401
dmi_memdev[nr].handle = get_unaligned(&dm->handle);
401402
dmi_memdev[nr].device = dmi_string(dm, d[0x10]);
402403
dmi_memdev[nr].bank = dmi_string(dm, d[0x11]);
404+
dmi_memdev[nr].type = d[0x12];
403405

404406
size = get_unaligned((u16 *)&d[0xC]);
405407
if (size == 0)
@@ -1128,3 +1130,24 @@ u64 dmi_memdev_size(u16 handle)
11281130
return ~0ull;
11291131
}
11301132
EXPORT_SYMBOL_GPL(dmi_memdev_size);
1133+
1134+
/**
1135+
* dmi_memdev_type - get the memory type
1136+
* @handle: DMI structure handle
1137+
*
1138+
* Return the DMI memory type of the module in the slot associated with the
1139+
* given DMI handle, or 0x0 if no such DMI handle exists.
1140+
*/
1141+
u8 dmi_memdev_type(u16 handle)
1142+
{
1143+
int n;
1144+
1145+
if (dmi_memdev) {
1146+
for (n = 0; n < dmi_memdev_nr; n++) {
1147+
if (handle == dmi_memdev[n].handle)
1148+
return dmi_memdev[n].type;
1149+
}
1150+
}
1151+
return 0x0; /* Not a valid value */
1152+
}
1153+
EXPORT_SYMBOL_GPL(dmi_memdev_type);

include/linux/dmi.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ extern int dmi_walk(void (*decode)(const struct dmi_header *, void *),
113113
extern bool dmi_match(enum dmi_field f, const char *str);
114114
extern void dmi_memdev_name(u16 handle, const char **bank, const char **device);
115115
extern u64 dmi_memdev_size(u16 handle);
116+
extern u8 dmi_memdev_type(u16 handle);
116117

117118
#else
118119

@@ -142,6 +143,7 @@ static inline bool dmi_match(enum dmi_field f, const char *str)
142143
static inline void dmi_memdev_name(u16 handle, const char **bank,
143144
const char **device) { }
144145
static inline u64 dmi_memdev_size(u16 handle) { return ~0ul; }
146+
static inline u8 dmi_memdev_type(u16 handle) { return 0x0; }
145147
static inline const struct dmi_system_id *
146148
dmi_first_match(const struct dmi_system_id *list) { return NULL; }
147149

0 commit comments

Comments
 (0)