Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #include <linux/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | #include <linux/string.h> |
| 3 | #include <linux/init.h> |
| 4 | #include <linux/module.h> |
Bjorn Helgaas | 8881cdc | 2010-10-27 15:32:59 -0700 | [diff] [blame] | 5 | #include <linux/ctype.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | #include <linux/dmi.h> |
Matt Domsch | 3ed3bce | 2006-03-26 01:37:03 -0800 | [diff] [blame] | 7 | #include <linux/efi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <linux/bootmem.h> |
Tony Luck | d114a33 | 2012-07-20 13:15:20 -0700 | [diff] [blame] | 9 | #include <linux/random.h> |
Andi Kleen | f2d3efe | 2006-03-25 16:30:22 +0100 | [diff] [blame] | 10 | #include <asm/dmi.h> |
Luck, Tony | 0841c04 | 2013-11-01 13:59:52 -0700 | [diff] [blame] | 11 | #include <asm/unaligned.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | |
Paul Jackson | cb5dd7c | 2008-05-14 08:15:16 -0700 | [diff] [blame] | 13 | /* |
| 14 | * DMI stands for "Desktop Management Interface". It is part |
| 15 | * of and an antecedent to, SMBIOS, which stands for System |
| 16 | * Management BIOS. See further: http://www.dmtf.org/standards |
| 17 | */ |
Jean Delvare | ffbbb96 | 2013-09-11 14:24:09 -0700 | [diff] [blame] | 18 | static const char dmi_empty_string[] = " "; |
Parag Warudkar | 79da472 | 2008-01-30 13:31:59 +0100 | [diff] [blame] | 19 | |
Ivan Khoronzhuk | 95be58d | 2015-02-18 13:33:20 +0200 | [diff] [blame] | 20 | static u32 dmi_ver __initdata; |
Ivan Khoronzhuk | 552e19d8 | 2015-02-18 13:33:21 +0200 | [diff] [blame] | 21 | static u32 dmi_len; |
| 22 | static u16 dmi_num; |
Ingo Molnar | 9a22b6e | 2008-09-18 12:50:18 +0200 | [diff] [blame] | 23 | /* |
| 24 | * Catch too early calls to dmi_check_system(): |
| 25 | */ |
| 26 | static int dmi_initialized; |
| 27 | |
Tejun Heo | c90fe6b | 2013-04-30 15:27:14 -0700 | [diff] [blame] | 28 | /* DMI system identification string used during boot */ |
| 29 | static char dmi_ids_string[128] __initdata; |
| 30 | |
Chen, Gong | dd6dad4 | 2013-10-18 14:29:25 -0700 | [diff] [blame] | 31 | static struct dmi_memdev_info { |
| 32 | const char *device; |
| 33 | const char *bank; |
| 34 | u16 handle; |
| 35 | } *dmi_memdev; |
| 36 | static int dmi_memdev_nr; |
| 37 | |
Jean Delvare | f3069ae | 2008-02-23 15:23:46 -0800 | [diff] [blame] | 38 | static const char * __init dmi_string_nosave(const struct dmi_header *dm, u8 s) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | { |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 40 | const u8 *bp = ((u8 *) dm) + dm->length; |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 41 | |
Andrey Panin | c3c7120 | 2005-09-06 15:18:28 -0700 | [diff] [blame] | 42 | if (s) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | s--; |
Andrey Panin | c3c7120 | 2005-09-06 15:18:28 -0700 | [diff] [blame] | 44 | while (s > 0 && *bp) { |
| 45 | bp += strlen(bp) + 1; |
| 46 | s--; |
| 47 | } |
| 48 | |
| 49 | if (*bp != 0) { |
Parag Warudkar | 79da472 | 2008-01-30 13:31:59 +0100 | [diff] [blame] | 50 | size_t len = strlen(bp)+1; |
| 51 | size_t cmp_len = len > 8 ? 8 : len; |
| 52 | |
| 53 | if (!memcmp(bp, dmi_empty_string, cmp_len)) |
| 54 | return dmi_empty_string; |
Jean Delvare | f3069ae | 2008-02-23 15:23:46 -0800 | [diff] [blame] | 55 | return bp; |
Andrey Panin | c3c7120 | 2005-09-06 15:18:28 -0700 | [diff] [blame] | 56 | } |
Bjorn Helgaas | 4f705ae | 2006-04-03 17:09:22 -0700 | [diff] [blame] | 57 | } |
Andrey Panin | c3c7120 | 2005-09-06 15:18:28 -0700 | [diff] [blame] | 58 | |
Jean Delvare | f3069ae | 2008-02-23 15:23:46 -0800 | [diff] [blame] | 59 | return ""; |
| 60 | } |
| 61 | |
Jean Delvare | ffbbb96 | 2013-09-11 14:24:09 -0700 | [diff] [blame] | 62 | static const char * __init dmi_string(const struct dmi_header *dm, u8 s) |
Jean Delvare | f3069ae | 2008-02-23 15:23:46 -0800 | [diff] [blame] | 63 | { |
| 64 | const char *bp = dmi_string_nosave(dm, s); |
| 65 | char *str; |
| 66 | size_t len; |
| 67 | |
| 68 | if (bp == dmi_empty_string) |
| 69 | return dmi_empty_string; |
| 70 | |
| 71 | len = strlen(bp) + 1; |
| 72 | str = dmi_alloc(len); |
| 73 | if (str != NULL) |
| 74 | strcpy(str, bp); |
Jean Delvare | f3069ae | 2008-02-23 15:23:46 -0800 | [diff] [blame] | 75 | |
Andrey Panin | c3c7120 | 2005-09-06 15:18:28 -0700 | [diff] [blame] | 76 | return str; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | /* |
| 80 | * We have to be cautious here. We have seen BIOSes with DMI pointers |
| 81 | * pointing to completely the wrong place for example |
| 82 | */ |
Ivan Khoronzhuk | 552e19d8 | 2015-02-18 13:33:21 +0200 | [diff] [blame] | 83 | static void dmi_table(u8 *buf, |
Jean Delvare | e7a19c56 | 2009-03-30 21:46:44 +0200 | [diff] [blame] | 84 | void (*decode)(const struct dmi_header *, void *), |
| 85 | void *private_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | { |
Jean Delvare | 7fce084 | 2007-11-03 17:29:20 +0100 | [diff] [blame] | 87 | u8 *data = buf; |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 88 | int i = 0; |
Bjorn Helgaas | 4f705ae | 2006-04-03 17:09:22 -0700 | [diff] [blame] | 89 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | /* |
Jean Delvare | bfbaafa | 2015-03-20 09:59:47 +0100 | [diff] [blame] | 91 | * Stop when we have seen all the items the table claimed to have |
| 92 | * (SMBIOS < 3.0 only) OR we reach an end-of-table marker OR we run |
| 93 | * off the end of the table (should never happen but sometimes does |
| 94 | * on bogus implementations.) |
Bjorn Helgaas | 4f705ae | 2006-04-03 17:09:22 -0700 | [diff] [blame] | 95 | */ |
Linus Torvalds | 9c65e12 | 2015-04-13 10:22:30 -0700 | [diff] [blame] | 96 | while ((!dmi_num || i < dmi_num) && |
| 97 | (data - buf + sizeof(struct dmi_header)) <= dmi_len) { |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 98 | const struct dmi_header *dm = (const struct dmi_header *)data; |
| 99 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | /* |
Alan Cox | 8638545 | 2008-11-07 16:03:46 +0000 | [diff] [blame] | 101 | * We want to know the total length (formatted area and |
| 102 | * strings) before decoding to make sure we won't run off the |
| 103 | * table in dmi_decode or dmi_string |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | */ |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 105 | data += dm->length; |
Ivan Khoronzhuk | 552e19d8 | 2015-02-18 13:33:21 +0200 | [diff] [blame] | 106 | while ((data - buf < dmi_len - 1) && (data[0] || data[1])) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | data++; |
Ivan Khoronzhuk | 552e19d8 | 2015-02-18 13:33:21 +0200 | [diff] [blame] | 108 | if (data - buf < dmi_len - 1) |
Jean Delvare | e7a19c56 | 2009-03-30 21:46:44 +0200 | [diff] [blame] | 109 | decode(dm, private_data); |
Ivan Khoronzhuk | ce204e9 | 2015-02-18 15:51:41 +0200 | [diff] [blame] | 110 | |
| 111 | /* |
| 112 | * 7.45 End-of-Table (Type 127) [SMBIOS reference spec v3.0.0] |
| 113 | */ |
| 114 | if (dm->type == DMI_ENTRY_END_OF_TABLE) |
| 115 | break; |
| 116 | |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 117 | data += 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | i++; |
| 119 | } |
Jean Delvare | 7fce084 | 2007-11-03 17:29:20 +0100 | [diff] [blame] | 120 | } |
| 121 | |
Ard Biesheuvel | fc43026 | 2014-10-14 16:41:27 +0200 | [diff] [blame] | 122 | static phys_addr_t dmi_base; |
Jean Delvare | 7fce084 | 2007-11-03 17:29:20 +0100 | [diff] [blame] | 123 | |
Jean Delvare | e7a19c56 | 2009-03-30 21:46:44 +0200 | [diff] [blame] | 124 | static int __init dmi_walk_early(void (*decode)(const struct dmi_header *, |
| 125 | void *)) |
Jean Delvare | 7fce084 | 2007-11-03 17:29:20 +0100 | [diff] [blame] | 126 | { |
| 127 | u8 *buf; |
| 128 | |
Ard Biesheuvel | cf07440 | 2014-01-23 15:54:39 -0800 | [diff] [blame] | 129 | buf = dmi_early_remap(dmi_base, dmi_len); |
Jean Delvare | 7fce084 | 2007-11-03 17:29:20 +0100 | [diff] [blame] | 130 | if (buf == NULL) |
| 131 | return -1; |
| 132 | |
Ivan Khoronzhuk | 552e19d8 | 2015-02-18 13:33:21 +0200 | [diff] [blame] | 133 | dmi_table(buf, decode, NULL); |
Jean Delvare | 7fce084 | 2007-11-03 17:29:20 +0100 | [diff] [blame] | 134 | |
Tony Luck | d114a33 | 2012-07-20 13:15:20 -0700 | [diff] [blame] | 135 | add_device_randomness(buf, dmi_len); |
| 136 | |
Ard Biesheuvel | cf07440 | 2014-01-23 15:54:39 -0800 | [diff] [blame] | 137 | dmi_early_unmap(buf, dmi_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | return 0; |
| 139 | } |
| 140 | |
Zhenzhong Duan | 9f9c9cbb | 2012-12-20 15:05:14 -0800 | [diff] [blame] | 141 | static int __init dmi_checksum(const u8 *buf, u8 len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | { |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 143 | u8 sum = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | int a; |
Bjorn Helgaas | 4f705ae | 2006-04-03 17:09:22 -0700 | [diff] [blame] | 145 | |
Zhenzhong Duan | 9f9c9cbb | 2012-12-20 15:05:14 -0800 | [diff] [blame] | 146 | for (a = 0; a < len; a++) |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 147 | sum += buf[a]; |
| 148 | |
| 149 | return sum == 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | } |
| 151 | |
Jean Delvare | ffbbb96 | 2013-09-11 14:24:09 -0700 | [diff] [blame] | 152 | static const char *dmi_ident[DMI_STRING_MAX]; |
Andrey Panin | ebad6a4 | 2005-09-06 15:18:29 -0700 | [diff] [blame] | 153 | static LIST_HEAD(dmi_devices); |
Lennart Poettering | 4f5c791 | 2007-05-08 22:07:02 +0200 | [diff] [blame] | 154 | int dmi_available; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
| 156 | /* |
| 157 | * Save a DMI string |
| 158 | */ |
Jean Delvare | 02d9c47 | 2013-09-11 14:24:08 -0700 | [diff] [blame] | 159 | static void __init dmi_save_ident(const struct dmi_header *dm, int slot, |
| 160 | int string) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | { |
Jean Delvare | 02d9c47 | 2013-09-11 14:24:08 -0700 | [diff] [blame] | 162 | const char *d = (const char *) dm; |
Jean Delvare | ffbbb96 | 2013-09-11 14:24:09 -0700 | [diff] [blame] | 163 | const char *p; |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 164 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | if (dmi_ident[slot]) |
| 166 | return; |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 167 | |
Andrey Panin | c3c7120 | 2005-09-06 15:18:28 -0700 | [diff] [blame] | 168 | p = dmi_string(dm, d[string]); |
| 169 | if (p == NULL) |
| 170 | return; |
| 171 | |
| 172 | dmi_ident[slot] = p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | } |
| 174 | |
Jean Delvare | 02d9c47 | 2013-09-11 14:24:08 -0700 | [diff] [blame] | 175 | static void __init dmi_save_uuid(const struct dmi_header *dm, int slot, |
| 176 | int index) |
Lennart Poettering | 4f5c791 | 2007-05-08 22:07:02 +0200 | [diff] [blame] | 177 | { |
Jean Delvare | 02d9c47 | 2013-09-11 14:24:08 -0700 | [diff] [blame] | 178 | const u8 *d = (u8 *) dm + index; |
Lennart Poettering | 4f5c791 | 2007-05-08 22:07:02 +0200 | [diff] [blame] | 179 | char *s; |
| 180 | int is_ff = 1, is_00 = 1, i; |
| 181 | |
| 182 | if (dmi_ident[slot]) |
| 183 | return; |
| 184 | |
| 185 | for (i = 0; i < 16 && (is_ff || is_00); i++) { |
Zhenzhong Duan | f1d8e61 | 2012-12-20 15:05:13 -0800 | [diff] [blame] | 186 | if (d[i] != 0x00) |
| 187 | is_00 = 0; |
| 188 | if (d[i] != 0xFF) |
| 189 | is_ff = 0; |
Lennart Poettering | 4f5c791 | 2007-05-08 22:07:02 +0200 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | if (is_ff || is_00) |
| 193 | return; |
| 194 | |
| 195 | s = dmi_alloc(16*2+4+1); |
| 196 | if (!s) |
| 197 | return; |
| 198 | |
Zhenzhong Duan | f1d8e61 | 2012-12-20 15:05:13 -0800 | [diff] [blame] | 199 | /* |
| 200 | * As of version 2.6 of the SMBIOS specification, the first 3 fields of |
| 201 | * the UUID are supposed to be little-endian encoded. The specification |
| 202 | * says that this is the defacto standard. |
| 203 | */ |
Ivan Khoronzhuk | 95be58d | 2015-02-18 13:33:20 +0200 | [diff] [blame] | 204 | if (dmi_ver >= 0x020600) |
Zhenzhong Duan | f1d8e61 | 2012-12-20 15:05:13 -0800 | [diff] [blame] | 205 | sprintf(s, "%pUL", d); |
| 206 | else |
| 207 | sprintf(s, "%pUB", d); |
Lennart Poettering | 4f5c791 | 2007-05-08 22:07:02 +0200 | [diff] [blame] | 208 | |
Jean Delvare | 02d9c47 | 2013-09-11 14:24:08 -0700 | [diff] [blame] | 209 | dmi_ident[slot] = s; |
Lennart Poettering | 4f5c791 | 2007-05-08 22:07:02 +0200 | [diff] [blame] | 210 | } |
| 211 | |
Jean Delvare | 02d9c47 | 2013-09-11 14:24:08 -0700 | [diff] [blame] | 212 | static void __init dmi_save_type(const struct dmi_header *dm, int slot, |
| 213 | int index) |
Lennart Poettering | 4f5c791 | 2007-05-08 22:07:02 +0200 | [diff] [blame] | 214 | { |
Jean Delvare | 02d9c47 | 2013-09-11 14:24:08 -0700 | [diff] [blame] | 215 | const u8 *d = (u8 *) dm + index; |
Lennart Poettering | 4f5c791 | 2007-05-08 22:07:02 +0200 | [diff] [blame] | 216 | char *s; |
| 217 | |
| 218 | if (dmi_ident[slot]) |
| 219 | return; |
| 220 | |
| 221 | s = dmi_alloc(4); |
| 222 | if (!s) |
| 223 | return; |
| 224 | |
| 225 | sprintf(s, "%u", *d & 0x7F); |
| 226 | dmi_ident[slot] = s; |
| 227 | } |
| 228 | |
Jean Delvare | f3069ae | 2008-02-23 15:23:46 -0800 | [diff] [blame] | 229 | static void __init dmi_save_one_device(int type, const char *name) |
| 230 | { |
| 231 | struct dmi_device *dev; |
| 232 | |
| 233 | /* No duplicate device */ |
| 234 | if (dmi_find_device(type, name, NULL)) |
| 235 | return; |
| 236 | |
| 237 | dev = dmi_alloc(sizeof(*dev) + strlen(name) + 1); |
Jean Delvare | ae79744 | 2013-09-11 14:24:10 -0700 | [diff] [blame] | 238 | if (!dev) |
Jean Delvare | f3069ae | 2008-02-23 15:23:46 -0800 | [diff] [blame] | 239 | return; |
Jean Delvare | f3069ae | 2008-02-23 15:23:46 -0800 | [diff] [blame] | 240 | |
| 241 | dev->type = type; |
| 242 | strcpy((char *)(dev + 1), name); |
| 243 | dev->name = (char *)(dev + 1); |
| 244 | dev->device_data = NULL; |
| 245 | list_add(&dev->list, &dmi_devices); |
| 246 | } |
| 247 | |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 248 | static void __init dmi_save_devices(const struct dmi_header *dm) |
Andrey Panin | ebad6a4 | 2005-09-06 15:18:29 -0700 | [diff] [blame] | 249 | { |
| 250 | int i, count = (dm->length - sizeof(struct dmi_header)) / 2; |
Andrey Panin | ebad6a4 | 2005-09-06 15:18:29 -0700 | [diff] [blame] | 251 | |
| 252 | for (i = 0; i < count; i++) { |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 253 | const char *d = (char *)(dm + 1) + (i * 2); |
Andrey Panin | ebad6a4 | 2005-09-06 15:18:29 -0700 | [diff] [blame] | 254 | |
| 255 | /* Skip disabled device */ |
| 256 | if ((*d & 0x80) == 0) |
| 257 | continue; |
| 258 | |
Jean Delvare | f3069ae | 2008-02-23 15:23:46 -0800 | [diff] [blame] | 259 | dmi_save_one_device(*d & 0x7f, dmi_string_nosave(dm, *(d + 1))); |
Shem Multinymous | 2e0c1f6 | 2006-09-29 01:59:37 -0700 | [diff] [blame] | 260 | } |
| 261 | } |
| 262 | |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 263 | static void __init dmi_save_oem_strings_devices(const struct dmi_header *dm) |
Shem Multinymous | 2e0c1f6 | 2006-09-29 01:59:37 -0700 | [diff] [blame] | 264 | { |
| 265 | int i, count = *(u8 *)(dm + 1); |
| 266 | struct dmi_device *dev; |
| 267 | |
| 268 | for (i = 1; i <= count; i++) { |
Jean Delvare | ffbbb96 | 2013-09-11 14:24:09 -0700 | [diff] [blame] | 269 | const char *devname = dmi_string(dm, i); |
Parag Warudkar | 79da472 | 2008-01-30 13:31:59 +0100 | [diff] [blame] | 270 | |
Jean Delvare | 43fe105 | 2008-02-23 15:23:55 -0800 | [diff] [blame] | 271 | if (devname == dmi_empty_string) |
Parag Warudkar | 79da472 | 2008-01-30 13:31:59 +0100 | [diff] [blame] | 272 | continue; |
Parag Warudkar | 79da472 | 2008-01-30 13:31:59 +0100 | [diff] [blame] | 273 | |
Shem Multinymous | 2e0c1f6 | 2006-09-29 01:59:37 -0700 | [diff] [blame] | 274 | dev = dmi_alloc(sizeof(*dev)); |
Jean Delvare | ae79744 | 2013-09-11 14:24:10 -0700 | [diff] [blame] | 275 | if (!dev) |
Shem Multinymous | 2e0c1f6 | 2006-09-29 01:59:37 -0700 | [diff] [blame] | 276 | break; |
Shem Multinymous | 2e0c1f6 | 2006-09-29 01:59:37 -0700 | [diff] [blame] | 277 | |
| 278 | dev->type = DMI_DEV_TYPE_OEM_STRING; |
Parag Warudkar | 79da472 | 2008-01-30 13:31:59 +0100 | [diff] [blame] | 279 | dev->name = devname; |
Shem Multinymous | 2e0c1f6 | 2006-09-29 01:59:37 -0700 | [diff] [blame] | 280 | dev->device_data = NULL; |
Andrey Panin | ebad6a4 | 2005-09-06 15:18:29 -0700 | [diff] [blame] | 281 | |
| 282 | list_add(&dev->list, &dmi_devices); |
| 283 | } |
| 284 | } |
| 285 | |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 286 | static void __init dmi_save_ipmi_device(const struct dmi_header *dm) |
Andrey Panin | ebad6a4 | 2005-09-06 15:18:29 -0700 | [diff] [blame] | 287 | { |
| 288 | struct dmi_device *dev; |
Jean Delvare | 02d9c47 | 2013-09-11 14:24:08 -0700 | [diff] [blame] | 289 | void *data; |
Andrey Panin | ebad6a4 | 2005-09-06 15:18:29 -0700 | [diff] [blame] | 290 | |
Andi Kleen | e992867 | 2006-01-11 22:43:33 +0100 | [diff] [blame] | 291 | data = dmi_alloc(dm->length); |
Jean Delvare | ae79744 | 2013-09-11 14:24:10 -0700 | [diff] [blame] | 292 | if (data == NULL) |
Andrey Panin | ebad6a4 | 2005-09-06 15:18:29 -0700 | [diff] [blame] | 293 | return; |
Andrey Panin | ebad6a4 | 2005-09-06 15:18:29 -0700 | [diff] [blame] | 294 | |
| 295 | memcpy(data, dm, dm->length); |
| 296 | |
Andi Kleen | e992867 | 2006-01-11 22:43:33 +0100 | [diff] [blame] | 297 | dev = dmi_alloc(sizeof(*dev)); |
Jean Delvare | ae79744 | 2013-09-11 14:24:10 -0700 | [diff] [blame] | 298 | if (!dev) |
Andrey Panin | ebad6a4 | 2005-09-06 15:18:29 -0700 | [diff] [blame] | 299 | return; |
Andrey Panin | ebad6a4 | 2005-09-06 15:18:29 -0700 | [diff] [blame] | 300 | |
| 301 | dev->type = DMI_DEV_TYPE_IPMI; |
| 302 | dev->name = "IPMI controller"; |
| 303 | dev->device_data = data; |
| 304 | |
Carol Hebert | abd24df | 2008-04-04 14:30:03 -0700 | [diff] [blame] | 305 | list_add_tail(&dev->list, &dmi_devices); |
Andrey Panin | ebad6a4 | 2005-09-06 15:18:29 -0700 | [diff] [blame] | 306 | } |
| 307 | |
Narendra K | 911e1c9 | 2010-07-26 05:56:50 -0500 | [diff] [blame] | 308 | static void __init dmi_save_dev_onboard(int instance, int segment, int bus, |
| 309 | int devfn, const char *name) |
| 310 | { |
| 311 | struct dmi_dev_onboard *onboard_dev; |
| 312 | |
| 313 | onboard_dev = dmi_alloc(sizeof(*onboard_dev) + strlen(name) + 1); |
Jean Delvare | ae79744 | 2013-09-11 14:24:10 -0700 | [diff] [blame] | 314 | if (!onboard_dev) |
Narendra K | 911e1c9 | 2010-07-26 05:56:50 -0500 | [diff] [blame] | 315 | return; |
Jean Delvare | ae79744 | 2013-09-11 14:24:10 -0700 | [diff] [blame] | 316 | |
Narendra K | 911e1c9 | 2010-07-26 05:56:50 -0500 | [diff] [blame] | 317 | onboard_dev->instance = instance; |
| 318 | onboard_dev->segment = segment; |
| 319 | onboard_dev->bus = bus; |
| 320 | onboard_dev->devfn = devfn; |
| 321 | |
| 322 | strcpy((char *)&onboard_dev[1], name); |
| 323 | onboard_dev->dev.type = DMI_DEV_TYPE_DEV_ONBOARD; |
| 324 | onboard_dev->dev.name = (char *)&onboard_dev[1]; |
| 325 | onboard_dev->dev.device_data = onboard_dev; |
| 326 | |
| 327 | list_add(&onboard_dev->dev.list, &dmi_devices); |
| 328 | } |
| 329 | |
Wim Van Sebroeck | b4bd7d5 | 2008-02-08 04:20:58 -0800 | [diff] [blame] | 330 | static void __init dmi_save_extended_devices(const struct dmi_header *dm) |
| 331 | { |
Jean Delvare | 02d9c47 | 2013-09-11 14:24:08 -0700 | [diff] [blame] | 332 | const u8 *d = (u8 *) dm + 5; |
Wim Van Sebroeck | b4bd7d5 | 2008-02-08 04:20:58 -0800 | [diff] [blame] | 333 | |
| 334 | /* Skip disabled device */ |
| 335 | if ((*d & 0x80) == 0) |
| 336 | return; |
| 337 | |
Narendra K | 911e1c9 | 2010-07-26 05:56:50 -0500 | [diff] [blame] | 338 | dmi_save_dev_onboard(*(d+1), *(u16 *)(d+2), *(d+4), *(d+5), |
| 339 | dmi_string_nosave(dm, *(d-1))); |
Jean Delvare | f3069ae | 2008-02-23 15:23:46 -0800 | [diff] [blame] | 340 | dmi_save_one_device(*d & 0x7f, dmi_string_nosave(dm, *(d - 1))); |
Wim Van Sebroeck | b4bd7d5 | 2008-02-08 04:20:58 -0800 | [diff] [blame] | 341 | } |
| 342 | |
Chen, Gong | dd6dad4 | 2013-10-18 14:29:25 -0700 | [diff] [blame] | 343 | static void __init count_mem_devices(const struct dmi_header *dm, void *v) |
| 344 | { |
| 345 | if (dm->type != DMI_ENTRY_MEM_DEVICE) |
| 346 | return; |
| 347 | dmi_memdev_nr++; |
| 348 | } |
| 349 | |
| 350 | static void __init save_mem_devices(const struct dmi_header *dm, void *v) |
| 351 | { |
| 352 | const char *d = (const char *)dm; |
| 353 | static int nr; |
| 354 | |
| 355 | if (dm->type != DMI_ENTRY_MEM_DEVICE) |
| 356 | return; |
| 357 | if (nr >= dmi_memdev_nr) { |
| 358 | pr_warn(FW_BUG "Too many DIMM entries in SMBIOS table\n"); |
| 359 | return; |
| 360 | } |
Luck, Tony | 0841c04 | 2013-11-01 13:59:52 -0700 | [diff] [blame] | 361 | dmi_memdev[nr].handle = get_unaligned(&dm->handle); |
Chen, Gong | dd6dad4 | 2013-10-18 14:29:25 -0700 | [diff] [blame] | 362 | dmi_memdev[nr].device = dmi_string(dm, d[0x10]); |
| 363 | dmi_memdev[nr].bank = dmi_string(dm, d[0x11]); |
| 364 | nr++; |
| 365 | } |
| 366 | |
| 367 | void __init dmi_memdev_walk(void) |
| 368 | { |
| 369 | if (!dmi_available) |
| 370 | return; |
| 371 | |
| 372 | if (dmi_walk_early(count_mem_devices) == 0 && dmi_memdev_nr) { |
| 373 | dmi_memdev = dmi_alloc(sizeof(*dmi_memdev) * dmi_memdev_nr); |
| 374 | if (dmi_memdev) |
| 375 | dmi_walk_early(save_mem_devices); |
| 376 | } |
| 377 | } |
| 378 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | * Process a DMI table entry. Right now all we care about are the BIOS |
| 381 | * and machine entries. For 2.5 we should pull the smbus controller info |
| 382 | * out of here. |
| 383 | */ |
Jean Delvare | e7a19c56 | 2009-03-30 21:46:44 +0200 | [diff] [blame] | 384 | static void __init dmi_decode(const struct dmi_header *dm, void *dummy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | { |
Jean Delvare | 02d9c47 | 2013-09-11 14:24:08 -0700 | [diff] [blame] | 386 | switch (dm->type) { |
Andrey Panin | ebad6a4 | 2005-09-06 15:18:29 -0700 | [diff] [blame] | 387 | case 0: /* BIOS Information */ |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 388 | dmi_save_ident(dm, DMI_BIOS_VENDOR, 4); |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 389 | dmi_save_ident(dm, DMI_BIOS_VERSION, 5); |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 390 | dmi_save_ident(dm, DMI_BIOS_DATE, 8); |
| 391 | break; |
Andrey Panin | ebad6a4 | 2005-09-06 15:18:29 -0700 | [diff] [blame] | 392 | case 1: /* System Information */ |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 393 | dmi_save_ident(dm, DMI_SYS_VENDOR, 4); |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 394 | dmi_save_ident(dm, DMI_PRODUCT_NAME, 5); |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 395 | dmi_save_ident(dm, DMI_PRODUCT_VERSION, 6); |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 396 | dmi_save_ident(dm, DMI_PRODUCT_SERIAL, 7); |
Lennart Poettering | 4f5c791 | 2007-05-08 22:07:02 +0200 | [diff] [blame] | 397 | dmi_save_uuid(dm, DMI_PRODUCT_UUID, 8); |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 398 | break; |
Andrey Panin | ebad6a4 | 2005-09-06 15:18:29 -0700 | [diff] [blame] | 399 | case 2: /* Base Board Information */ |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 400 | dmi_save_ident(dm, DMI_BOARD_VENDOR, 4); |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 401 | dmi_save_ident(dm, DMI_BOARD_NAME, 5); |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 402 | dmi_save_ident(dm, DMI_BOARD_VERSION, 6); |
Lennart Poettering | 4f5c791 | 2007-05-08 22:07:02 +0200 | [diff] [blame] | 403 | dmi_save_ident(dm, DMI_BOARD_SERIAL, 7); |
| 404 | dmi_save_ident(dm, DMI_BOARD_ASSET_TAG, 8); |
| 405 | break; |
| 406 | case 3: /* Chassis Information */ |
| 407 | dmi_save_ident(dm, DMI_CHASSIS_VENDOR, 4); |
| 408 | dmi_save_type(dm, DMI_CHASSIS_TYPE, 5); |
| 409 | dmi_save_ident(dm, DMI_CHASSIS_VERSION, 6); |
| 410 | dmi_save_ident(dm, DMI_CHASSIS_SERIAL, 7); |
| 411 | dmi_save_ident(dm, DMI_CHASSIS_ASSET_TAG, 8); |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 412 | break; |
Andrey Panin | ebad6a4 | 2005-09-06 15:18:29 -0700 | [diff] [blame] | 413 | case 10: /* Onboard Devices Information */ |
| 414 | dmi_save_devices(dm); |
| 415 | break; |
Shem Multinymous | 2e0c1f6 | 2006-09-29 01:59:37 -0700 | [diff] [blame] | 416 | case 11: /* OEM Strings */ |
| 417 | dmi_save_oem_strings_devices(dm); |
| 418 | break; |
Andrey Panin | ebad6a4 | 2005-09-06 15:18:29 -0700 | [diff] [blame] | 419 | case 38: /* IPMI Device Information */ |
| 420 | dmi_save_ipmi_device(dm); |
Wim Van Sebroeck | b4bd7d5 | 2008-02-08 04:20:58 -0800 | [diff] [blame] | 421 | break; |
| 422 | case 41: /* Onboard Devices Extended Information */ |
| 423 | dmi_save_extended_devices(dm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | } |
| 425 | } |
| 426 | |
Tejun Heo | c90fe6b | 2013-04-30 15:27:14 -0700 | [diff] [blame] | 427 | static int __init print_filtered(char *buf, size_t len, const char *info) |
Bjorn Helgaas | 8881cdc | 2010-10-27 15:32:59 -0700 | [diff] [blame] | 428 | { |
Tejun Heo | c90fe6b | 2013-04-30 15:27:14 -0700 | [diff] [blame] | 429 | int c = 0; |
Bjorn Helgaas | 8881cdc | 2010-10-27 15:32:59 -0700 | [diff] [blame] | 430 | const char *p; |
| 431 | |
| 432 | if (!info) |
Tejun Heo | c90fe6b | 2013-04-30 15:27:14 -0700 | [diff] [blame] | 433 | return c; |
Bjorn Helgaas | 8881cdc | 2010-10-27 15:32:59 -0700 | [diff] [blame] | 434 | |
| 435 | for (p = info; *p; p++) |
| 436 | if (isprint(*p)) |
Tejun Heo | c90fe6b | 2013-04-30 15:27:14 -0700 | [diff] [blame] | 437 | c += scnprintf(buf + c, len - c, "%c", *p); |
Bjorn Helgaas | 8881cdc | 2010-10-27 15:32:59 -0700 | [diff] [blame] | 438 | else |
Tejun Heo | c90fe6b | 2013-04-30 15:27:14 -0700 | [diff] [blame] | 439 | c += scnprintf(buf + c, len - c, "\\x%02x", *p & 0xff); |
| 440 | return c; |
Bjorn Helgaas | 8881cdc | 2010-10-27 15:32:59 -0700 | [diff] [blame] | 441 | } |
| 442 | |
Tejun Heo | c90fe6b | 2013-04-30 15:27:14 -0700 | [diff] [blame] | 443 | static void __init dmi_format_ids(char *buf, size_t len) |
Bjorn Helgaas | 8881cdc | 2010-10-27 15:32:59 -0700 | [diff] [blame] | 444 | { |
Tejun Heo | c90fe6b | 2013-04-30 15:27:14 -0700 | [diff] [blame] | 445 | int c = 0; |
Naga Chumbalkar | 84e383b | 2011-02-14 22:47:17 +0000 | [diff] [blame] | 446 | const char *board; /* Board Name is optional */ |
| 447 | |
Tejun Heo | c90fe6b | 2013-04-30 15:27:14 -0700 | [diff] [blame] | 448 | c += print_filtered(buf + c, len - c, |
| 449 | dmi_get_system_info(DMI_SYS_VENDOR)); |
| 450 | c += scnprintf(buf + c, len - c, " "); |
| 451 | c += print_filtered(buf + c, len - c, |
| 452 | dmi_get_system_info(DMI_PRODUCT_NAME)); |
| 453 | |
Naga Chumbalkar | 84e383b | 2011-02-14 22:47:17 +0000 | [diff] [blame] | 454 | board = dmi_get_system_info(DMI_BOARD_NAME); |
| 455 | if (board) { |
Tejun Heo | c90fe6b | 2013-04-30 15:27:14 -0700 | [diff] [blame] | 456 | c += scnprintf(buf + c, len - c, "/"); |
| 457 | c += print_filtered(buf + c, len - c, board); |
Naga Chumbalkar | 84e383b | 2011-02-14 22:47:17 +0000 | [diff] [blame] | 458 | } |
Tejun Heo | c90fe6b | 2013-04-30 15:27:14 -0700 | [diff] [blame] | 459 | c += scnprintf(buf + c, len - c, ", BIOS "); |
| 460 | c += print_filtered(buf + c, len - c, |
| 461 | dmi_get_system_info(DMI_BIOS_VERSION)); |
| 462 | c += scnprintf(buf + c, len - c, " "); |
| 463 | c += print_filtered(buf + c, len - c, |
| 464 | dmi_get_system_info(DMI_BIOS_DATE)); |
Bjorn Helgaas | 8881cdc | 2010-10-27 15:32:59 -0700 | [diff] [blame] | 465 | } |
| 466 | |
Ben Hutchings | d39de28 | 2013-07-31 13:53:30 -0700 | [diff] [blame] | 467 | /* |
| 468 | * Check for DMI/SMBIOS headers in the system firmware image. Any |
| 469 | * SMBIOS header must start 16 bytes before the DMI header, so take a |
| 470 | * 32 byte buffer and check for DMI at offset 16 and SMBIOS at offset |
| 471 | * 0. If the DMI header is present, set dmi_ver accordingly (SMBIOS |
| 472 | * takes precedence) and return 0. Otherwise return 1. |
| 473 | */ |
Ben Hutchings | 79bae42 | 2013-04-30 15:27:46 -0700 | [diff] [blame] | 474 | static int __init dmi_present(const u8 *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | { |
Ivan Khoronzhuk | 95be58d | 2015-02-18 13:33:20 +0200 | [diff] [blame] | 476 | u32 smbios_ver; |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 477 | |
Ben Hutchings | 79bae42 | 2013-04-30 15:27:46 -0700 | [diff] [blame] | 478 | if (memcmp(buf, "_SM_", 4) == 0 && |
| 479 | buf[5] < 32 && dmi_checksum(buf, buf[5])) { |
Ard Biesheuvel | fc43026 | 2014-10-14 16:41:27 +0200 | [diff] [blame] | 480 | smbios_ver = get_unaligned_be16(buf + 6); |
Ben Hutchings | 79bae42 | 2013-04-30 15:27:46 -0700 | [diff] [blame] | 481 | |
| 482 | /* Some BIOS report weird SMBIOS version, fix that up */ |
| 483 | switch (smbios_ver) { |
| 484 | case 0x021F: |
| 485 | case 0x0221: |
| 486 | pr_debug("SMBIOS version fixup(2.%d->2.%d)\n", |
| 487 | smbios_ver & 0xFF, 3); |
| 488 | smbios_ver = 0x0203; |
| 489 | break; |
| 490 | case 0x0233: |
| 491 | pr_debug("SMBIOS version fixup(2.%d->2.%d)\n", 51, 6); |
| 492 | smbios_ver = 0x0206; |
| 493 | break; |
| 494 | } |
| 495 | } else { |
| 496 | smbios_ver = 0; |
| 497 | } |
| 498 | |
| 499 | buf += 16; |
| 500 | |
| 501 | if (memcmp(buf, "_DMI_", 5) == 0 && dmi_checksum(buf, 15)) { |
Ard Biesheuvel | fc43026 | 2014-10-14 16:41:27 +0200 | [diff] [blame] | 502 | dmi_num = get_unaligned_le16(buf + 12); |
| 503 | dmi_len = get_unaligned_le16(buf + 6); |
| 504 | dmi_base = get_unaligned_le32(buf + 8); |
Matt Domsch | 3ed3bce | 2006-03-26 01:37:03 -0800 | [diff] [blame] | 505 | |
Bjorn Helgaas | 8881cdc | 2010-10-27 15:32:59 -0700 | [diff] [blame] | 506 | if (dmi_walk_early(dmi_decode) == 0) { |
Ben Hutchings | 79bae42 | 2013-04-30 15:27:46 -0700 | [diff] [blame] | 507 | if (smbios_ver) { |
| 508 | dmi_ver = smbios_ver; |
Ivan Khoronzhuk | 95be58d | 2015-02-18 13:33:20 +0200 | [diff] [blame] | 509 | pr_info("SMBIOS %d.%d%s present.\n", |
| 510 | dmi_ver >> 8, dmi_ver & 0xFF, |
| 511 | (dmi_ver < 0x0300) ? "" : ".x"); |
Ben Hutchings | 79bae42 | 2013-04-30 15:27:46 -0700 | [diff] [blame] | 512 | } else { |
Zhenzhong Duan | 9f9c9cbb | 2012-12-20 15:05:14 -0800 | [diff] [blame] | 513 | dmi_ver = (buf[14] & 0xF0) << 4 | |
| 514 | (buf[14] & 0x0F); |
| 515 | pr_info("Legacy DMI %d.%d present.\n", |
| 516 | dmi_ver >> 8, dmi_ver & 0xFF); |
| 517 | } |
Ivan Khoronzhuk | 95be58d | 2015-02-18 13:33:20 +0200 | [diff] [blame] | 518 | dmi_ver <<= 8; |
Tejun Heo | c90fe6b | 2013-04-30 15:27:14 -0700 | [diff] [blame] | 519 | dmi_format_ids(dmi_ids_string, sizeof(dmi_ids_string)); |
| 520 | printk(KERN_DEBUG "DMI: %s\n", dmi_ids_string); |
Matt Domsch | 3ed3bce | 2006-03-26 01:37:03 -0800 | [diff] [blame] | 521 | return 0; |
Bjorn Helgaas | 8881cdc | 2010-10-27 15:32:59 -0700 | [diff] [blame] | 522 | } |
Matt Domsch | 3ed3bce | 2006-03-26 01:37:03 -0800 | [diff] [blame] | 523 | } |
Matt Domsch | 3ed3bce | 2006-03-26 01:37:03 -0800 | [diff] [blame] | 524 | |
Ben Hutchings | a40e7cf | 2013-03-08 12:43:32 -0800 | [diff] [blame] | 525 | return 1; |
Zhenzhong Duan | 9f9c9cbb | 2012-12-20 15:05:14 -0800 | [diff] [blame] | 526 | } |
| 527 | |
Ard Biesheuvel | fc43026 | 2014-10-14 16:41:27 +0200 | [diff] [blame] | 528 | /* |
| 529 | * Check for the SMBIOS 3.0 64-bit entry point signature. Unlike the legacy |
| 530 | * 32-bit entry point, there is no embedded DMI header (_DMI_) in here. |
| 531 | */ |
| 532 | static int __init dmi_smbios3_present(const u8 *buf) |
| 533 | { |
| 534 | if (memcmp(buf, "_SM3_", 5) == 0 && |
| 535 | buf[6] < 32 && dmi_checksum(buf, buf[6])) { |
Ivan Khoronzhuk | 95be58d | 2015-02-18 13:33:20 +0200 | [diff] [blame] | 536 | dmi_ver = get_unaligned_be32(buf + 6); |
| 537 | dmi_ver &= 0xFFFFFF; |
Jean Delvare | bfbaafa | 2015-03-20 09:59:47 +0100 | [diff] [blame] | 538 | dmi_num = 0; /* No longer specified */ |
Ard Biesheuvel | fc43026 | 2014-10-14 16:41:27 +0200 | [diff] [blame] | 539 | dmi_len = get_unaligned_le32(buf + 12); |
| 540 | dmi_base = get_unaligned_le64(buf + 16); |
| 541 | |
Ard Biesheuvel | fc43026 | 2014-10-14 16:41:27 +0200 | [diff] [blame] | 542 | if (dmi_walk_early(dmi_decode) == 0) { |
Ivan Khoronzhuk | 95be58d | 2015-02-18 13:33:20 +0200 | [diff] [blame] | 543 | pr_info("SMBIOS %d.%d.%d present.\n", |
| 544 | dmi_ver >> 16, (dmi_ver >> 8) & 0xFF, |
| 545 | dmi_ver & 0xFF); |
Ard Biesheuvel | fc43026 | 2014-10-14 16:41:27 +0200 | [diff] [blame] | 546 | dmi_format_ids(dmi_ids_string, sizeof(dmi_ids_string)); |
| 547 | pr_debug("DMI: %s\n", dmi_ids_string); |
| 548 | return 0; |
| 549 | } |
| 550 | } |
| 551 | return 1; |
| 552 | } |
| 553 | |
Matt Domsch | 3ed3bce | 2006-03-26 01:37:03 -0800 | [diff] [blame] | 554 | void __init dmi_scan_machine(void) |
| 555 | { |
Andrey Panin | 61e032f | 2005-09-06 15:18:26 -0700 | [diff] [blame] | 556 | char __iomem *p, *q; |
Ben Hutchings | 79bae42 | 2013-04-30 15:27:46 -0700 | [diff] [blame] | 557 | char buf[32]; |
Andrey Panin | 61e032f | 2005-09-06 15:18:26 -0700 | [diff] [blame] | 558 | |
Matt Fleming | 83e6818 | 2012-11-14 09:42:35 +0000 | [diff] [blame] | 559 | if (efi_enabled(EFI_CONFIG_TABLES)) { |
Ard Biesheuvel | fc43026 | 2014-10-14 16:41:27 +0200 | [diff] [blame] | 560 | /* |
| 561 | * According to the DMTF SMBIOS reference spec v3.0.0, it is |
| 562 | * allowed to define both the 64-bit entry point (smbios3) and |
| 563 | * the 32-bit entry point (smbios), in which case they should |
| 564 | * either both point to the same SMBIOS structure table, or the |
| 565 | * table pointed to by the 64-bit entry point should contain a |
| 566 | * superset of the table contents pointed to by the 32-bit entry |
| 567 | * point (section 5.2) |
| 568 | * This implies that the 64-bit entry point should have |
| 569 | * precedence if it is defined and supported by the OS. If we |
| 570 | * have the 64-bit entry point, but fail to decode it, fall |
| 571 | * back to the legacy one (if available) |
| 572 | */ |
| 573 | if (efi.smbios3 != EFI_INVALID_TABLE_ADDR) { |
| 574 | p = dmi_early_remap(efi.smbios3, 32); |
| 575 | if (p == NULL) |
| 576 | goto error; |
| 577 | memcpy_fromio(buf, p, 32); |
| 578 | dmi_early_unmap(p, 32); |
| 579 | |
| 580 | if (!dmi_smbios3_present(buf)) { |
| 581 | dmi_available = 1; |
| 582 | goto out; |
| 583 | } |
| 584 | } |
Bjorn Helgaas | b2c99e3 | 2006-03-26 01:37:08 -0800 | [diff] [blame] | 585 | if (efi.smbios == EFI_INVALID_TABLE_ADDR) |
Ingo Molnar | 9a22b6e | 2008-09-18 12:50:18 +0200 | [diff] [blame] | 586 | goto error; |
Andrey Panin | 61e032f | 2005-09-06 15:18:26 -0700 | [diff] [blame] | 587 | |
Lennart Poettering | 4f5c791 | 2007-05-08 22:07:02 +0200 | [diff] [blame] | 588 | /* This is called as a core_initcall() because it isn't |
| 589 | * needed during early boot. This also means we can |
| 590 | * iounmap the space when we're done with it. |
| 591 | */ |
Ard Biesheuvel | cf07440 | 2014-01-23 15:54:39 -0800 | [diff] [blame] | 592 | p = dmi_early_remap(efi.smbios, 32); |
Matt Domsch | 3ed3bce | 2006-03-26 01:37:03 -0800 | [diff] [blame] | 593 | if (p == NULL) |
Ingo Molnar | 9a22b6e | 2008-09-18 12:50:18 +0200 | [diff] [blame] | 594 | goto error; |
Ben Hutchings | 79bae42 | 2013-04-30 15:27:46 -0700 | [diff] [blame] | 595 | memcpy_fromio(buf, p, 32); |
Ard Biesheuvel | cf07440 | 2014-01-23 15:54:39 -0800 | [diff] [blame] | 596 | dmi_early_unmap(p, 32); |
Ben Hutchings | 79bae42 | 2013-04-30 15:27:46 -0700 | [diff] [blame] | 597 | |
| 598 | if (!dmi_present(buf)) { |
Lennart Poettering | 4f5c791 | 2007-05-08 22:07:02 +0200 | [diff] [blame] | 599 | dmi_available = 1; |
Ingo Molnar | 9a22b6e | 2008-09-18 12:50:18 +0200 | [diff] [blame] | 600 | goto out; |
Lennart Poettering | 4f5c791 | 2007-05-08 22:07:02 +0200 | [diff] [blame] | 601 | } |
Ard Biesheuvel | cf07440 | 2014-01-23 15:54:39 -0800 | [diff] [blame] | 602 | } else if (IS_ENABLED(CONFIG_DMI_SCAN_MACHINE_NON_EFI_FALLBACK)) { |
| 603 | p = dmi_early_remap(0xF0000, 0x10000); |
Matt Domsch | 3ed3bce | 2006-03-26 01:37:03 -0800 | [diff] [blame] | 604 | if (p == NULL) |
Ingo Molnar | 9a22b6e | 2008-09-18 12:50:18 +0200 | [diff] [blame] | 605 | goto error; |
Andrey Panin | 61e032f | 2005-09-06 15:18:26 -0700 | [diff] [blame] | 606 | |
Ben Hutchings | d39de28 | 2013-07-31 13:53:30 -0700 | [diff] [blame] | 607 | /* |
| 608 | * Iterate over all possible DMI header addresses q. |
| 609 | * Maintain the 32 bytes around q in buf. On the |
| 610 | * first iteration, substitute zero for the |
| 611 | * out-of-range bytes so there is no chance of falsely |
| 612 | * detecting an SMBIOS header. |
| 613 | */ |
Ben Hutchings | 79bae42 | 2013-04-30 15:27:46 -0700 | [diff] [blame] | 614 | memset(buf, 0, 16); |
Matt Domsch | 3ed3bce | 2006-03-26 01:37:03 -0800 | [diff] [blame] | 615 | for (q = p; q < p + 0x10000; q += 16) { |
Ben Hutchings | 79bae42 | 2013-04-30 15:27:46 -0700 | [diff] [blame] | 616 | memcpy_fromio(buf + 16, q, 16); |
Ard Biesheuvel | fc43026 | 2014-10-14 16:41:27 +0200 | [diff] [blame] | 617 | if (!dmi_smbios3_present(buf) || !dmi_present(buf)) { |
Lennart Poettering | 4f5c791 | 2007-05-08 22:07:02 +0200 | [diff] [blame] | 618 | dmi_available = 1; |
Ard Biesheuvel | cf07440 | 2014-01-23 15:54:39 -0800 | [diff] [blame] | 619 | dmi_early_unmap(p, 0x10000); |
Ingo Molnar | 9a22b6e | 2008-09-18 12:50:18 +0200 | [diff] [blame] | 620 | goto out; |
Lennart Poettering | 4f5c791 | 2007-05-08 22:07:02 +0200 | [diff] [blame] | 621 | } |
Ben Hutchings | 79bae42 | 2013-04-30 15:27:46 -0700 | [diff] [blame] | 622 | memcpy(buf, buf + 16, 16); |
Andrey Panin | 61e032f | 2005-09-06 15:18:26 -0700 | [diff] [blame] | 623 | } |
Ard Biesheuvel | cf07440 | 2014-01-23 15:54:39 -0800 | [diff] [blame] | 624 | dmi_early_unmap(p, 0x10000); |
Andrey Panin | 61e032f | 2005-09-06 15:18:26 -0700 | [diff] [blame] | 625 | } |
Ingo Molnar | 9a22b6e | 2008-09-18 12:50:18 +0200 | [diff] [blame] | 626 | error: |
Jean Delvare | 02d9c47 | 2013-09-11 14:24:08 -0700 | [diff] [blame] | 627 | pr_info("DMI not present or invalid.\n"); |
Ingo Molnar | 9a22b6e | 2008-09-18 12:50:18 +0200 | [diff] [blame] | 628 | out: |
| 629 | dmi_initialized = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | } |
| 631 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | /** |
Tejun Heo | 98e5e1b | 2013-04-30 15:27:15 -0700 | [diff] [blame] | 633 | * dmi_set_dump_stack_arch_desc - set arch description for dump_stack() |
| 634 | * |
| 635 | * Invoke dump_stack_set_arch_desc() with DMI system information so that |
| 636 | * DMI identifiers are printed out on task dumps. Arch boot code should |
| 637 | * call this function after dmi_scan_machine() if it wants to print out DMI |
| 638 | * identifiers on task dumps. |
| 639 | */ |
| 640 | void __init dmi_set_dump_stack_arch_desc(void) |
| 641 | { |
| 642 | dump_stack_set_arch_desc("%s", dmi_ids_string); |
| 643 | } |
| 644 | |
| 645 | /** |
Rafael J. Wysocki | d7b1956 | 2009-01-19 20:55:50 +0100 | [diff] [blame] | 646 | * dmi_matches - check if dmi_system_id structure matches system DMI data |
| 647 | * @dmi: pointer to the dmi_system_id structure to check |
| 648 | */ |
| 649 | static bool dmi_matches(const struct dmi_system_id *dmi) |
| 650 | { |
| 651 | int i; |
| 652 | |
| 653 | WARN(!dmi_initialized, KERN_ERR "dmi check: not initialized yet.\n"); |
| 654 | |
| 655 | for (i = 0; i < ARRAY_SIZE(dmi->matches); i++) { |
| 656 | int s = dmi->matches[i].slot; |
| 657 | if (s == DMI_NONE) |
Dmitry Torokhov | 7575750 | 2009-12-04 10:24:19 -0800 | [diff] [blame] | 658 | break; |
Jani Nikula | 5017b28 | 2013-07-03 15:05:02 -0700 | [diff] [blame] | 659 | if (dmi_ident[s]) { |
| 660 | if (!dmi->matches[i].exact_match && |
| 661 | strstr(dmi_ident[s], dmi->matches[i].substr)) |
| 662 | continue; |
| 663 | else if (dmi->matches[i].exact_match && |
| 664 | !strcmp(dmi_ident[s], dmi->matches[i].substr)) |
| 665 | continue; |
| 666 | } |
| 667 | |
Rafael J. Wysocki | d7b1956 | 2009-01-19 20:55:50 +0100 | [diff] [blame] | 668 | /* No match */ |
| 669 | return false; |
| 670 | } |
| 671 | return true; |
| 672 | } |
| 673 | |
| 674 | /** |
Dmitry Torokhov | 7575750 | 2009-12-04 10:24:19 -0800 | [diff] [blame] | 675 | * dmi_is_end_of_table - check for end-of-table marker |
| 676 | * @dmi: pointer to the dmi_system_id structure to check |
| 677 | */ |
| 678 | static bool dmi_is_end_of_table(const struct dmi_system_id *dmi) |
| 679 | { |
| 680 | return dmi->matches[0].slot == DMI_NONE; |
| 681 | } |
| 682 | |
| 683 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | * dmi_check_system - check system DMI data |
| 685 | * @list: array of dmi_system_id structures to match against |
Randy Dunlap | b0ef371 | 2006-06-25 05:49:18 -0700 | [diff] [blame] | 686 | * All non-null elements of the list must match |
| 687 | * their slot's (field index's) data (i.e., each |
| 688 | * list string must be a substring of the specified |
| 689 | * DMI slot's string data) to be considered a |
| 690 | * successful match. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | * |
| 692 | * Walk the blacklist table running matching functions until someone |
| 693 | * returns non zero or we hit the end. Callback function is called for |
Randy Dunlap | b0ef371 | 2006-06-25 05:49:18 -0700 | [diff] [blame] | 694 | * each successful match. Returns the number of matches. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | */ |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 696 | int dmi_check_system(const struct dmi_system_id *list) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | { |
Rafael J. Wysocki | d7b1956 | 2009-01-19 20:55:50 +0100 | [diff] [blame] | 698 | int count = 0; |
| 699 | const struct dmi_system_id *d; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | |
Dmitry Torokhov | 7575750 | 2009-12-04 10:24:19 -0800 | [diff] [blame] | 701 | for (d = list; !dmi_is_end_of_table(d); d++) |
Rafael J. Wysocki | d7b1956 | 2009-01-19 20:55:50 +0100 | [diff] [blame] | 702 | if (dmi_matches(d)) { |
| 703 | count++; |
| 704 | if (d->callback && d->callback(d)) |
| 705 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | |
| 708 | return count; |
| 709 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | EXPORT_SYMBOL(dmi_check_system); |
| 711 | |
| 712 | /** |
Rafael J. Wysocki | d7b1956 | 2009-01-19 20:55:50 +0100 | [diff] [blame] | 713 | * dmi_first_match - find dmi_system_id structure matching system DMI data |
| 714 | * @list: array of dmi_system_id structures to match against |
| 715 | * All non-null elements of the list must match |
| 716 | * their slot's (field index's) data (i.e., each |
| 717 | * list string must be a substring of the specified |
| 718 | * DMI slot's string data) to be considered a |
| 719 | * successful match. |
| 720 | * |
| 721 | * Walk the blacklist table until the first match is found. Return the |
| 722 | * pointer to the matching entry or NULL if there's no match. |
| 723 | */ |
| 724 | const struct dmi_system_id *dmi_first_match(const struct dmi_system_id *list) |
| 725 | { |
| 726 | const struct dmi_system_id *d; |
| 727 | |
Dmitry Torokhov | 7575750 | 2009-12-04 10:24:19 -0800 | [diff] [blame] | 728 | for (d = list; !dmi_is_end_of_table(d); d++) |
Rafael J. Wysocki | d7b1956 | 2009-01-19 20:55:50 +0100 | [diff] [blame] | 729 | if (dmi_matches(d)) |
| 730 | return d; |
| 731 | |
| 732 | return NULL; |
| 733 | } |
| 734 | EXPORT_SYMBOL(dmi_first_match); |
| 735 | |
| 736 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | * dmi_get_system_info - return DMI data value |
Randy Dunlap | b0ef371 | 2006-06-25 05:49:18 -0700 | [diff] [blame] | 738 | * @field: data index (see enum dmi_field) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | * |
| 740 | * Returns one DMI data value, can be used to perform |
| 741 | * complex DMI data checks. |
| 742 | */ |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 743 | const char *dmi_get_system_info(int field) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | { |
| 745 | return dmi_ident[field]; |
| 746 | } |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 747 | EXPORT_SYMBOL(dmi_get_system_info); |
Andrey Panin | ebad6a4 | 2005-09-06 15:18:29 -0700 | [diff] [blame] | 748 | |
Alok Kataria | fd8cd7e | 2008-11-03 15:50:38 -0800 | [diff] [blame] | 749 | /** |
Randy Dunlap | c2bacfc | 2009-01-06 14:41:40 -0800 | [diff] [blame] | 750 | * dmi_name_in_serial - Check if string is in the DMI product serial information |
| 751 | * @str: string to check for |
Alok Kataria | fd8cd7e | 2008-11-03 15:50:38 -0800 | [diff] [blame] | 752 | */ |
| 753 | int dmi_name_in_serial(const char *str) |
| 754 | { |
| 755 | int f = DMI_PRODUCT_SERIAL; |
| 756 | if (dmi_ident[f] && strstr(dmi_ident[f], str)) |
| 757 | return 1; |
| 758 | return 0; |
| 759 | } |
Andi Kleen | a1bae67 | 2006-10-21 18:37:02 +0200 | [diff] [blame] | 760 | |
| 761 | /** |
Jean Delvare | 66e13e6 | 2011-11-15 14:36:09 -0800 | [diff] [blame] | 762 | * dmi_name_in_vendors - Check if string is in the DMI system or board vendor name |
Jean Delvare | 02d9c47 | 2013-09-11 14:24:08 -0700 | [diff] [blame] | 763 | * @str: Case sensitive Name |
Andi Kleen | a1bae67 | 2006-10-21 18:37:02 +0200 | [diff] [blame] | 764 | */ |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 765 | int dmi_name_in_vendors(const char *str) |
Andi Kleen | a1bae67 | 2006-10-21 18:37:02 +0200 | [diff] [blame] | 766 | { |
Jean Delvare | 66e13e6 | 2011-11-15 14:36:09 -0800 | [diff] [blame] | 767 | static int fields[] = { DMI_SYS_VENDOR, DMI_BOARD_VENDOR, DMI_NONE }; |
Andi Kleen | a1bae67 | 2006-10-21 18:37:02 +0200 | [diff] [blame] | 768 | int i; |
| 769 | for (i = 0; fields[i] != DMI_NONE; i++) { |
| 770 | int f = fields[i]; |
| 771 | if (dmi_ident[f] && strstr(dmi_ident[f], str)) |
| 772 | return 1; |
| 773 | } |
| 774 | return 0; |
| 775 | } |
| 776 | EXPORT_SYMBOL(dmi_name_in_vendors); |
| 777 | |
Andrey Panin | ebad6a4 | 2005-09-06 15:18:29 -0700 | [diff] [blame] | 778 | /** |
| 779 | * dmi_find_device - find onboard device by type/name |
| 780 | * @type: device type or %DMI_DEV_TYPE_ANY to match all device types |
Randy Dunlap | b0ef371 | 2006-06-25 05:49:18 -0700 | [diff] [blame] | 781 | * @name: device name string or %NULL to match all |
Andrey Panin | ebad6a4 | 2005-09-06 15:18:29 -0700 | [diff] [blame] | 782 | * @from: previous device found in search, or %NULL for new search. |
| 783 | * |
| 784 | * Iterates through the list of known onboard devices. If a device is |
| 785 | * found with a matching @vendor and @device, a pointer to its device |
| 786 | * structure is returned. Otherwise, %NULL is returned. |
Randy Dunlap | b0ef371 | 2006-06-25 05:49:18 -0700 | [diff] [blame] | 787 | * A new search is initiated by passing %NULL as the @from argument. |
Andrey Panin | ebad6a4 | 2005-09-06 15:18:29 -0700 | [diff] [blame] | 788 | * If @from is not %NULL, searches continue from next device. |
| 789 | */ |
Jean Delvare | 02d9c47 | 2013-09-11 14:24:08 -0700 | [diff] [blame] | 790 | const struct dmi_device *dmi_find_device(int type, const char *name, |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 791 | const struct dmi_device *from) |
Andrey Panin | ebad6a4 | 2005-09-06 15:18:29 -0700 | [diff] [blame] | 792 | { |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 793 | const struct list_head *head = from ? &from->list : &dmi_devices; |
| 794 | struct list_head *d; |
Andrey Panin | ebad6a4 | 2005-09-06 15:18:29 -0700 | [diff] [blame] | 795 | |
Jean Delvare | 02d9c47 | 2013-09-11 14:24:08 -0700 | [diff] [blame] | 796 | for (d = head->next; d != &dmi_devices; d = d->next) { |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 797 | const struct dmi_device *dev = |
| 798 | list_entry(d, struct dmi_device, list); |
Andrey Panin | ebad6a4 | 2005-09-06 15:18:29 -0700 | [diff] [blame] | 799 | |
| 800 | if (((type == DMI_DEV_TYPE_ANY) || (dev->type == type)) && |
| 801 | ((name == NULL) || (strcmp(dev->name, name) == 0))) |
| 802 | return dev; |
| 803 | } |
| 804 | |
| 805 | return NULL; |
| 806 | } |
| 807 | EXPORT_SYMBOL(dmi_find_device); |
Andi Kleen | f083a32 | 2006-03-25 16:30:19 +0100 | [diff] [blame] | 808 | |
| 809 | /** |
Tejun Heo | 3e5cd1f | 2009-08-16 21:02:36 +0900 | [diff] [blame] | 810 | * dmi_get_date - parse a DMI date |
| 811 | * @field: data index (see enum dmi_field) |
| 812 | * @yearp: optional out parameter for the year |
| 813 | * @monthp: optional out parameter for the month |
| 814 | * @dayp: optional out parameter for the day |
Andi Kleen | f083a32 | 2006-03-25 16:30:19 +0100 | [diff] [blame] | 815 | * |
Tejun Heo | 3e5cd1f | 2009-08-16 21:02:36 +0900 | [diff] [blame] | 816 | * The date field is assumed to be in the form resembling |
| 817 | * [mm[/dd]]/yy[yy] and the result is stored in the out |
| 818 | * parameters any or all of which can be omitted. |
| 819 | * |
| 820 | * If the field doesn't exist, all out parameters are set to zero |
| 821 | * and false is returned. Otherwise, true is returned with any |
| 822 | * invalid part of date set to zero. |
| 823 | * |
| 824 | * On return, year, month and day are guaranteed to be in the |
| 825 | * range of [0,9999], [0,12] and [0,31] respectively. |
Andi Kleen | f083a32 | 2006-03-25 16:30:19 +0100 | [diff] [blame] | 826 | */ |
Tejun Heo | 3e5cd1f | 2009-08-16 21:02:36 +0900 | [diff] [blame] | 827 | bool dmi_get_date(int field, int *yearp, int *monthp, int *dayp) |
Andi Kleen | f083a32 | 2006-03-25 16:30:19 +0100 | [diff] [blame] | 828 | { |
Tejun Heo | 3e5cd1f | 2009-08-16 21:02:36 +0900 | [diff] [blame] | 829 | int year = 0, month = 0, day = 0; |
| 830 | bool exists; |
| 831 | const char *s, *y; |
Tejun Heo | 02c24fa | 2009-08-16 21:01:22 +0900 | [diff] [blame] | 832 | char *e; |
Andi Kleen | f083a32 | 2006-03-25 16:30:19 +0100 | [diff] [blame] | 833 | |
Tejun Heo | 3e5cd1f | 2009-08-16 21:02:36 +0900 | [diff] [blame] | 834 | s = dmi_get_system_info(field); |
| 835 | exists = s; |
| 836 | if (!exists) |
| 837 | goto out; |
Andi Kleen | f083a32 | 2006-03-25 16:30:19 +0100 | [diff] [blame] | 838 | |
Tejun Heo | 3e5cd1f | 2009-08-16 21:02:36 +0900 | [diff] [blame] | 839 | /* |
| 840 | * Determine year first. We assume the date string resembles |
| 841 | * mm/dd/yy[yy] but the original code extracted only the year |
| 842 | * from the end. Keep the behavior in the spirit of no |
| 843 | * surprises. |
| 844 | */ |
| 845 | y = strrchr(s, '/'); |
| 846 | if (!y) |
| 847 | goto out; |
| 848 | |
| 849 | y++; |
| 850 | year = simple_strtoul(y, &e, 10); |
| 851 | if (y != e && year < 100) { /* 2-digit year */ |
Andi Kleen | f083a32 | 2006-03-25 16:30:19 +0100 | [diff] [blame] | 852 | year += 1900; |
| 853 | if (year < 1996) /* no dates < spec 1.0 */ |
| 854 | year += 100; |
| 855 | } |
Tejun Heo | 3e5cd1f | 2009-08-16 21:02:36 +0900 | [diff] [blame] | 856 | if (year > 9999) /* year should fit in %04d */ |
| 857 | year = 0; |
Andi Kleen | f083a32 | 2006-03-25 16:30:19 +0100 | [diff] [blame] | 858 | |
Tejun Heo | 3e5cd1f | 2009-08-16 21:02:36 +0900 | [diff] [blame] | 859 | /* parse the mm and dd */ |
| 860 | month = simple_strtoul(s, &e, 10); |
| 861 | if (s == e || *e != '/' || !month || month > 12) { |
| 862 | month = 0; |
| 863 | goto out; |
| 864 | } |
| 865 | |
| 866 | s = e + 1; |
| 867 | day = simple_strtoul(s, &e, 10); |
| 868 | if (s == y || s == e || *e != '/' || day > 31) |
| 869 | day = 0; |
| 870 | out: |
| 871 | if (yearp) |
| 872 | *yearp = year; |
| 873 | if (monthp) |
| 874 | *monthp = month; |
| 875 | if (dayp) |
| 876 | *dayp = day; |
| 877 | return exists; |
Andi Kleen | f083a32 | 2006-03-25 16:30:19 +0100 | [diff] [blame] | 878 | } |
Tejun Heo | 3e5cd1f | 2009-08-16 21:02:36 +0900 | [diff] [blame] | 879 | EXPORT_SYMBOL(dmi_get_date); |
Jean Delvare | 7fce084 | 2007-11-03 17:29:20 +0100 | [diff] [blame] | 880 | |
| 881 | /** |
| 882 | * dmi_walk - Walk the DMI table and get called back for every record |
| 883 | * @decode: Callback function |
Jean Delvare | e7a19c56 | 2009-03-30 21:46:44 +0200 | [diff] [blame] | 884 | * @private_data: Private data to be passed to the callback function |
Jean Delvare | 7fce084 | 2007-11-03 17:29:20 +0100 | [diff] [blame] | 885 | * |
| 886 | * Returns -1 when the DMI table can't be reached, 0 on success. |
| 887 | */ |
Jean Delvare | e7a19c56 | 2009-03-30 21:46:44 +0200 | [diff] [blame] | 888 | int dmi_walk(void (*decode)(const struct dmi_header *, void *), |
| 889 | void *private_data) |
Jean Delvare | 7fce084 | 2007-11-03 17:29:20 +0100 | [diff] [blame] | 890 | { |
| 891 | u8 *buf; |
| 892 | |
| 893 | if (!dmi_available) |
| 894 | return -1; |
| 895 | |
Ard Biesheuvel | cf07440 | 2014-01-23 15:54:39 -0800 | [diff] [blame] | 896 | buf = dmi_remap(dmi_base, dmi_len); |
Jean Delvare | 7fce084 | 2007-11-03 17:29:20 +0100 | [diff] [blame] | 897 | if (buf == NULL) |
| 898 | return -1; |
| 899 | |
Ivan Khoronzhuk | 552e19d8 | 2015-02-18 13:33:21 +0200 | [diff] [blame] | 900 | dmi_table(buf, decode, private_data); |
Jean Delvare | 7fce084 | 2007-11-03 17:29:20 +0100 | [diff] [blame] | 901 | |
Ard Biesheuvel | cf07440 | 2014-01-23 15:54:39 -0800 | [diff] [blame] | 902 | dmi_unmap(buf); |
Jean Delvare | 7fce084 | 2007-11-03 17:29:20 +0100 | [diff] [blame] | 903 | return 0; |
| 904 | } |
| 905 | EXPORT_SYMBOL_GPL(dmi_walk); |
Jiri Slaby | d61c72e | 2008-12-10 14:07:21 +0100 | [diff] [blame] | 906 | |
| 907 | /** |
| 908 | * dmi_match - compare a string to the dmi field (if exists) |
Randy Dunlap | c2bacfc | 2009-01-06 14:41:40 -0800 | [diff] [blame] | 909 | * @f: DMI field identifier |
| 910 | * @str: string to compare the DMI field to |
Jiri Slaby | d61c72e | 2008-12-10 14:07:21 +0100 | [diff] [blame] | 911 | * |
| 912 | * Returns true if the requested field equals to the str (including NULL). |
| 913 | */ |
| 914 | bool dmi_match(enum dmi_field f, const char *str) |
| 915 | { |
| 916 | const char *info = dmi_get_system_info(f); |
| 917 | |
| 918 | if (info == NULL || str == NULL) |
| 919 | return info == str; |
| 920 | |
| 921 | return !strcmp(info, str); |
| 922 | } |
| 923 | EXPORT_SYMBOL_GPL(dmi_match); |
Chen, Gong | dd6dad4 | 2013-10-18 14:29:25 -0700 | [diff] [blame] | 924 | |
| 925 | void dmi_memdev_name(u16 handle, const char **bank, const char **device) |
| 926 | { |
| 927 | int n; |
| 928 | |
| 929 | if (dmi_memdev == NULL) |
| 930 | return; |
| 931 | |
| 932 | for (n = 0; n < dmi_memdev_nr; n++) { |
| 933 | if (handle == dmi_memdev[n].handle) { |
| 934 | *bank = dmi_memdev[n].bank; |
| 935 | *device = dmi_memdev[n].device; |
| 936 | break; |
| 937 | } |
| 938 | } |
| 939 | } |
| 940 | EXPORT_SYMBOL_GPL(dmi_memdev_name); |