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