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