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