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