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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | #include <linux/dmi.h> |
Matt Domsch | 3ed3bce | 2006-03-26 01:37:03 -0800 | [diff] [blame] | 6 | #include <linux/efi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | #include <linux/bootmem.h> |
Andi Kleen | e992867 | 2006-01-11 22:43:33 +0100 | [diff] [blame] | 8 | #include <linux/slab.h> |
Andi Kleen | f2d3efe | 2006-03-25 16:30:22 +0100 | [diff] [blame] | 9 | #include <asm/dmi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | |
Parag Warudkar | 79da472 | 2008-01-30 13:31:59 +0100 | [diff] [blame] | 11 | static char dmi_empty_string[] = " "; |
| 12 | |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 13 | static char * __init dmi_string(const struct dmi_header *dm, u8 s) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | { |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 15 | const u8 *bp = ((u8 *) dm) + dm->length; |
Andrey Panin | c3c7120 | 2005-09-06 15:18:28 -0700 | [diff] [blame] | 16 | char *str = ""; |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 17 | |
Andrey Panin | c3c7120 | 2005-09-06 15:18:28 -0700 | [diff] [blame] | 18 | if (s) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | s--; |
Andrey Panin | c3c7120 | 2005-09-06 15:18:28 -0700 | [diff] [blame] | 20 | while (s > 0 && *bp) { |
| 21 | bp += strlen(bp) + 1; |
| 22 | s--; |
| 23 | } |
| 24 | |
| 25 | if (*bp != 0) { |
Parag Warudkar | 79da472 | 2008-01-30 13:31:59 +0100 | [diff] [blame] | 26 | size_t len = strlen(bp)+1; |
| 27 | size_t cmp_len = len > 8 ? 8 : len; |
| 28 | |
| 29 | if (!memcmp(bp, dmi_empty_string, cmp_len)) |
| 30 | return dmi_empty_string; |
| 31 | str = dmi_alloc(len); |
Andrey Panin | c3c7120 | 2005-09-06 15:18:28 -0700 | [diff] [blame] | 32 | if (str != NULL) |
| 33 | strcpy(str, bp); |
| 34 | else |
Parag Warudkar | 79da472 | 2008-01-30 13:31:59 +0100 | [diff] [blame] | 35 | printk(KERN_ERR "dmi_string: cannot allocate %Zu bytes.\n", len); |
Andrey Panin | c3c7120 | 2005-09-06 15:18:28 -0700 | [diff] [blame] | 36 | } |
Bjorn Helgaas | 4f705ae | 2006-04-03 17:09:22 -0700 | [diff] [blame] | 37 | } |
Andrey Panin | c3c7120 | 2005-09-06 15:18:28 -0700 | [diff] [blame] | 38 | |
| 39 | return str; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | /* |
| 43 | * We have to be cautious here. We have seen BIOSes with DMI pointers |
| 44 | * pointing to completely the wrong place for example |
| 45 | */ |
Jean Delvare | 7fce084 | 2007-11-03 17:29:20 +0100 | [diff] [blame] | 46 | static void dmi_table(u8 *buf, int len, int num, |
| 47 | void (*decode)(const struct dmi_header *)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | { |
Jean Delvare | 7fce084 | 2007-11-03 17:29:20 +0100 | [diff] [blame] | 49 | u8 *data = buf; |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 50 | int i = 0; |
Bjorn Helgaas | 4f705ae | 2006-04-03 17:09:22 -0700 | [diff] [blame] | 51 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | /* |
Bjorn Helgaas | 4f705ae | 2006-04-03 17:09:22 -0700 | [diff] [blame] | 53 | * Stop when we see all the items the table claimed to have |
| 54 | * OR we run off the end of the table (also happens) |
| 55 | */ |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 56 | while ((i < num) && (data - buf + sizeof(struct dmi_header)) <= len) { |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 57 | const struct dmi_header *dm = (const struct dmi_header *)data; |
| 58 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | /* |
| 60 | * We want to know the total length (formated area and strings) |
| 61 | * before decoding to make sure we won't run off the table in |
| 62 | * dmi_decode or dmi_string |
| 63 | */ |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 64 | data += dm->length; |
| 65 | while ((data - buf < len - 1) && (data[0] || data[1])) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | data++; |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 67 | if (data - buf < len - 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | decode(dm); |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 69 | data += 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | i++; |
| 71 | } |
Jean Delvare | 7fce084 | 2007-11-03 17:29:20 +0100 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | static u32 dmi_base; |
| 75 | static u16 dmi_len; |
| 76 | static u16 dmi_num; |
| 77 | |
| 78 | static int __init dmi_walk_early(void (*decode)(const struct dmi_header *)) |
| 79 | { |
| 80 | u8 *buf; |
| 81 | |
| 82 | buf = dmi_ioremap(dmi_base, dmi_len); |
| 83 | if (buf == NULL) |
| 84 | return -1; |
| 85 | |
| 86 | dmi_table(buf, dmi_len, dmi_num, decode); |
| 87 | |
| 88 | dmi_iounmap(buf, dmi_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | return 0; |
| 90 | } |
| 91 | |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 92 | static int __init dmi_checksum(const u8 *buf) |
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 | u8 sum = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | int a; |
Bjorn Helgaas | 4f705ae | 2006-04-03 17:09:22 -0700 | [diff] [blame] | 96 | |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 97 | for (a = 0; a < 15; a++) |
| 98 | sum += buf[a]; |
| 99 | |
| 100 | return sum == 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | static char *dmi_ident[DMI_STRING_MAX]; |
Andrey Panin | ebad6a4 | 2005-09-06 15:18:29 -0700 | [diff] [blame] | 104 | static LIST_HEAD(dmi_devices); |
Lennart Poettering | 4f5c791 | 2007-05-08 22:07:02 +0200 | [diff] [blame] | 105 | int dmi_available; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
| 107 | /* |
| 108 | * Save a DMI string |
| 109 | */ |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 110 | 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] | 111 | { |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 112 | const char *d = (const char*) dm; |
| 113 | char *p; |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 114 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | if (dmi_ident[slot]) |
| 116 | return; |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 117 | |
Andrey Panin | c3c7120 | 2005-09-06 15:18:28 -0700 | [diff] [blame] | 118 | p = dmi_string(dm, d[string]); |
| 119 | if (p == NULL) |
| 120 | return; |
| 121 | |
| 122 | dmi_ident[slot] = p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 125 | 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] | 126 | { |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 127 | const u8 *d = (u8*) dm + index; |
Lennart Poettering | 4f5c791 | 2007-05-08 22:07:02 +0200 | [diff] [blame] | 128 | char *s; |
| 129 | int is_ff = 1, is_00 = 1, i; |
| 130 | |
| 131 | if (dmi_ident[slot]) |
| 132 | return; |
| 133 | |
| 134 | for (i = 0; i < 16 && (is_ff || is_00); i++) { |
| 135 | if(d[i] != 0x00) is_ff = 0; |
| 136 | if(d[i] != 0xFF) is_00 = 0; |
| 137 | } |
| 138 | |
| 139 | if (is_ff || is_00) |
| 140 | return; |
| 141 | |
| 142 | s = dmi_alloc(16*2+4+1); |
| 143 | if (!s) |
| 144 | return; |
| 145 | |
| 146 | sprintf(s, |
| 147 | "%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X", |
| 148 | d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], |
| 149 | d[8], d[9], d[10], d[11], d[12], d[13], d[14], d[15]); |
| 150 | |
| 151 | dmi_ident[slot] = s; |
| 152 | } |
| 153 | |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 154 | 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] | 155 | { |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 156 | const u8 *d = (u8*) dm + index; |
Lennart Poettering | 4f5c791 | 2007-05-08 22:07:02 +0200 | [diff] [blame] | 157 | char *s; |
| 158 | |
| 159 | if (dmi_ident[slot]) |
| 160 | return; |
| 161 | |
| 162 | s = dmi_alloc(4); |
| 163 | if (!s) |
| 164 | return; |
| 165 | |
| 166 | sprintf(s, "%u", *d & 0x7F); |
| 167 | dmi_ident[slot] = s; |
| 168 | } |
| 169 | |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 170 | static void __init dmi_save_devices(const struct dmi_header *dm) |
Andrey Panin | ebad6a4 | 2005-09-06 15:18:29 -0700 | [diff] [blame] | 171 | { |
| 172 | int i, count = (dm->length - sizeof(struct dmi_header)) / 2; |
| 173 | struct dmi_device *dev; |
| 174 | |
| 175 | for (i = 0; i < count; i++) { |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 176 | const char *d = (char *)(dm + 1) + (i * 2); |
Andrey Panin | ebad6a4 | 2005-09-06 15:18:29 -0700 | [diff] [blame] | 177 | |
| 178 | /* Skip disabled device */ |
| 179 | if ((*d & 0x80) == 0) |
| 180 | continue; |
| 181 | |
Andi Kleen | e992867 | 2006-01-11 22:43:33 +0100 | [diff] [blame] | 182 | dev = dmi_alloc(sizeof(*dev)); |
Andrey Panin | ebad6a4 | 2005-09-06 15:18:29 -0700 | [diff] [blame] | 183 | if (!dev) { |
| 184 | printk(KERN_ERR "dmi_save_devices: out of memory.\n"); |
| 185 | break; |
| 186 | } |
| 187 | |
| 188 | dev->type = *d++ & 0x7f; |
| 189 | dev->name = dmi_string(dm, *d); |
| 190 | dev->device_data = NULL; |
Shem Multinymous | 2e0c1f6 | 2006-09-29 01:59:37 -0700 | [diff] [blame] | 191 | list_add(&dev->list, &dmi_devices); |
| 192 | } |
| 193 | } |
| 194 | |
Parag Warudkar | 79da472 | 2008-01-30 13:31:59 +0100 | [diff] [blame] | 195 | static struct dmi_device empty_oem_string_dev = { |
| 196 | .name = dmi_empty_string, |
| 197 | }; |
| 198 | |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 199 | 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] | 200 | { |
| 201 | int i, count = *(u8 *)(dm + 1); |
| 202 | struct dmi_device *dev; |
| 203 | |
| 204 | for (i = 1; i <= count; i++) { |
Parag Warudkar | 79da472 | 2008-01-30 13:31:59 +0100 | [diff] [blame] | 205 | char *devname = dmi_string(dm, i); |
| 206 | |
| 207 | if (!strcmp(devname, dmi_empty_string)) { |
| 208 | list_add(&empty_oem_string_dev.list, &dmi_devices); |
| 209 | continue; |
| 210 | } |
| 211 | |
Shem Multinymous | 2e0c1f6 | 2006-09-29 01:59:37 -0700 | [diff] [blame] | 212 | dev = dmi_alloc(sizeof(*dev)); |
| 213 | if (!dev) { |
| 214 | printk(KERN_ERR |
| 215 | "dmi_save_oem_strings_devices: out of memory.\n"); |
| 216 | break; |
| 217 | } |
| 218 | |
| 219 | dev->type = DMI_DEV_TYPE_OEM_STRING; |
Parag Warudkar | 79da472 | 2008-01-30 13:31:59 +0100 | [diff] [blame] | 220 | dev->name = devname; |
Shem Multinymous | 2e0c1f6 | 2006-09-29 01:59:37 -0700 | [diff] [blame] | 221 | dev->device_data = NULL; |
Andrey Panin | ebad6a4 | 2005-09-06 15:18:29 -0700 | [diff] [blame] | 222 | |
| 223 | list_add(&dev->list, &dmi_devices); |
| 224 | } |
| 225 | } |
| 226 | |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 227 | static void __init dmi_save_ipmi_device(const struct dmi_header *dm) |
Andrey Panin | ebad6a4 | 2005-09-06 15:18:29 -0700 | [diff] [blame] | 228 | { |
| 229 | struct dmi_device *dev; |
| 230 | void * data; |
| 231 | |
Andi Kleen | e992867 | 2006-01-11 22:43:33 +0100 | [diff] [blame] | 232 | data = dmi_alloc(dm->length); |
Andrey Panin | ebad6a4 | 2005-09-06 15:18:29 -0700 | [diff] [blame] | 233 | if (data == NULL) { |
| 234 | printk(KERN_ERR "dmi_save_ipmi_device: out of memory.\n"); |
| 235 | return; |
| 236 | } |
| 237 | |
| 238 | memcpy(data, dm, dm->length); |
| 239 | |
Andi Kleen | e992867 | 2006-01-11 22:43:33 +0100 | [diff] [blame] | 240 | dev = dmi_alloc(sizeof(*dev)); |
Andrey Panin | ebad6a4 | 2005-09-06 15:18:29 -0700 | [diff] [blame] | 241 | if (!dev) { |
| 242 | printk(KERN_ERR "dmi_save_ipmi_device: out of memory.\n"); |
| 243 | return; |
| 244 | } |
| 245 | |
| 246 | dev->type = DMI_DEV_TYPE_IPMI; |
| 247 | dev->name = "IPMI controller"; |
| 248 | dev->device_data = data; |
| 249 | |
| 250 | list_add(&dev->list, &dmi_devices); |
| 251 | } |
| 252 | |
Wim Van Sebroeck | b4bd7d5 | 2008-02-08 04:20:58 -0800 | [diff] [blame] | 253 | static void __init dmi_save_extended_devices(const struct dmi_header *dm) |
| 254 | { |
| 255 | const u8 *d = (u8*) dm + 5; |
| 256 | struct dmi_device *dev; |
| 257 | |
| 258 | /* Skip disabled device */ |
| 259 | if ((*d & 0x80) == 0) |
| 260 | return; |
| 261 | |
| 262 | dev = dmi_alloc(sizeof(*dev)); |
| 263 | if (!dev) { |
| 264 | printk(KERN_ERR "dmi_save_extended_devices: out of memory.\n"); |
| 265 | return; |
| 266 | } |
| 267 | |
| 268 | dev->type = *d-- & 0x7f; |
| 269 | dev->name = dmi_string(dm, *d); |
| 270 | dev->device_data = NULL; |
| 271 | |
| 272 | list_add(&dev->list, &dmi_devices); |
| 273 | } |
| 274 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | * Process a DMI table entry. Right now all we care about are the BIOS |
| 277 | * and machine entries. For 2.5 we should pull the smbus controller info |
| 278 | * out of here. |
| 279 | */ |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 280 | static void __init dmi_decode(const struct dmi_header *dm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | { |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 282 | switch(dm->type) { |
Andrey Panin | ebad6a4 | 2005-09-06 15:18:29 -0700 | [diff] [blame] | 283 | case 0: /* BIOS Information */ |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 284 | dmi_save_ident(dm, DMI_BIOS_VENDOR, 4); |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 285 | dmi_save_ident(dm, DMI_BIOS_VERSION, 5); |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 286 | dmi_save_ident(dm, DMI_BIOS_DATE, 8); |
| 287 | break; |
Andrey Panin | ebad6a4 | 2005-09-06 15:18:29 -0700 | [diff] [blame] | 288 | case 1: /* System Information */ |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 289 | dmi_save_ident(dm, DMI_SYS_VENDOR, 4); |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 290 | dmi_save_ident(dm, DMI_PRODUCT_NAME, 5); |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 291 | dmi_save_ident(dm, DMI_PRODUCT_VERSION, 6); |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 292 | dmi_save_ident(dm, DMI_PRODUCT_SERIAL, 7); |
Lennart Poettering | 4f5c791 | 2007-05-08 22:07:02 +0200 | [diff] [blame] | 293 | dmi_save_uuid(dm, DMI_PRODUCT_UUID, 8); |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 294 | break; |
Andrey Panin | ebad6a4 | 2005-09-06 15:18:29 -0700 | [diff] [blame] | 295 | case 2: /* Base Board Information */ |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 296 | dmi_save_ident(dm, DMI_BOARD_VENDOR, 4); |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 297 | dmi_save_ident(dm, DMI_BOARD_NAME, 5); |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 298 | dmi_save_ident(dm, DMI_BOARD_VERSION, 6); |
Lennart Poettering | 4f5c791 | 2007-05-08 22:07:02 +0200 | [diff] [blame] | 299 | dmi_save_ident(dm, DMI_BOARD_SERIAL, 7); |
| 300 | dmi_save_ident(dm, DMI_BOARD_ASSET_TAG, 8); |
| 301 | break; |
| 302 | case 3: /* Chassis Information */ |
| 303 | dmi_save_ident(dm, DMI_CHASSIS_VENDOR, 4); |
| 304 | dmi_save_type(dm, DMI_CHASSIS_TYPE, 5); |
| 305 | dmi_save_ident(dm, DMI_CHASSIS_VERSION, 6); |
| 306 | dmi_save_ident(dm, DMI_CHASSIS_SERIAL, 7); |
| 307 | dmi_save_ident(dm, DMI_CHASSIS_ASSET_TAG, 8); |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 308 | break; |
Andrey Panin | ebad6a4 | 2005-09-06 15:18:29 -0700 | [diff] [blame] | 309 | case 10: /* Onboard Devices Information */ |
| 310 | dmi_save_devices(dm); |
| 311 | break; |
Shem Multinymous | 2e0c1f6 | 2006-09-29 01:59:37 -0700 | [diff] [blame] | 312 | case 11: /* OEM Strings */ |
| 313 | dmi_save_oem_strings_devices(dm); |
| 314 | break; |
Andrey Panin | ebad6a4 | 2005-09-06 15:18:29 -0700 | [diff] [blame] | 315 | case 38: /* IPMI Device Information */ |
| 316 | dmi_save_ipmi_device(dm); |
Wim Van Sebroeck | b4bd7d5 | 2008-02-08 04:20:58 -0800 | [diff] [blame] | 317 | break; |
| 318 | case 41: /* Onboard Devices Extended Information */ |
| 319 | dmi_save_extended_devices(dm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | } |
| 321 | } |
| 322 | |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 323 | static int __init dmi_present(const char __iomem *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | { |
Andrey Panin | 61e032f | 2005-09-06 15:18:26 -0700 | [diff] [blame] | 325 | u8 buf[15]; |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 326 | |
Matt Domsch | 3ed3bce | 2006-03-26 01:37:03 -0800 | [diff] [blame] | 327 | memcpy_fromio(buf, p, 15); |
| 328 | if ((memcmp(buf, "_DMI_", 5) == 0) && dmi_checksum(buf)) { |
Jean Delvare | 7fce084 | 2007-11-03 17:29:20 +0100 | [diff] [blame] | 329 | dmi_num = (buf[13] << 8) | buf[12]; |
| 330 | dmi_len = (buf[7] << 8) | buf[6]; |
| 331 | dmi_base = (buf[11] << 24) | (buf[10] << 16) | |
Matt Domsch | 3ed3bce | 2006-03-26 01:37:03 -0800 | [diff] [blame] | 332 | (buf[9] << 8) | buf[8]; |
| 333 | |
| 334 | /* |
| 335 | * DMI version 0.0 means that the real version is taken from |
| 336 | * the SMBIOS version, which we don't know at this point. |
| 337 | */ |
| 338 | if (buf[14] != 0) |
| 339 | printk(KERN_INFO "DMI %d.%d present.\n", |
| 340 | buf[14] >> 4, buf[14] & 0xF); |
| 341 | else |
| 342 | printk(KERN_INFO "DMI present.\n"); |
Jean Delvare | 7fce084 | 2007-11-03 17:29:20 +0100 | [diff] [blame] | 343 | if (dmi_walk_early(dmi_decode) == 0) |
Matt Domsch | 3ed3bce | 2006-03-26 01:37:03 -0800 | [diff] [blame] | 344 | return 0; |
| 345 | } |
| 346 | return 1; |
| 347 | } |
| 348 | |
| 349 | void __init dmi_scan_machine(void) |
| 350 | { |
Andrey Panin | 61e032f | 2005-09-06 15:18:26 -0700 | [diff] [blame] | 351 | char __iomem *p, *q; |
Matt Domsch | 3ed3bce | 2006-03-26 01:37:03 -0800 | [diff] [blame] | 352 | int rc; |
Andrey Panin | 61e032f | 2005-09-06 15:18:26 -0700 | [diff] [blame] | 353 | |
Matt Domsch | 3ed3bce | 2006-03-26 01:37:03 -0800 | [diff] [blame] | 354 | if (efi_enabled) { |
Bjorn Helgaas | b2c99e3 | 2006-03-26 01:37:08 -0800 | [diff] [blame] | 355 | if (efi.smbios == EFI_INVALID_TABLE_ADDR) |
Matt Domsch | 3ed3bce | 2006-03-26 01:37:03 -0800 | [diff] [blame] | 356 | goto out; |
Andrey Panin | 61e032f | 2005-09-06 15:18:26 -0700 | [diff] [blame] | 357 | |
Lennart Poettering | 4f5c791 | 2007-05-08 22:07:02 +0200 | [diff] [blame] | 358 | /* This is called as a core_initcall() because it isn't |
| 359 | * needed during early boot. This also means we can |
| 360 | * iounmap the space when we're done with it. |
| 361 | */ |
Bjorn Helgaas | b2c99e3 | 2006-03-26 01:37:08 -0800 | [diff] [blame] | 362 | p = dmi_ioremap(efi.smbios, 32); |
Matt Domsch | 3ed3bce | 2006-03-26 01:37:03 -0800 | [diff] [blame] | 363 | if (p == NULL) |
| 364 | goto out; |
Andrey Panin | 61e032f | 2005-09-06 15:18:26 -0700 | [diff] [blame] | 365 | |
Matt Domsch | 3ed3bce | 2006-03-26 01:37:03 -0800 | [diff] [blame] | 366 | rc = dmi_present(p + 0x10); /* offset of _DMI_ string */ |
Tolentino, Matthew E | 23dd842 | 2006-03-26 01:37:09 -0800 | [diff] [blame] | 367 | dmi_iounmap(p, 32); |
Lennart Poettering | 4f5c791 | 2007-05-08 22:07:02 +0200 | [diff] [blame] | 368 | if (!rc) { |
| 369 | dmi_available = 1; |
Matt Domsch | 3ed3bce | 2006-03-26 01:37:03 -0800 | [diff] [blame] | 370 | return; |
Lennart Poettering | 4f5c791 | 2007-05-08 22:07:02 +0200 | [diff] [blame] | 371 | } |
Matt Domsch | 3ed3bce | 2006-03-26 01:37:03 -0800 | [diff] [blame] | 372 | } |
| 373 | else { |
| 374 | /* |
| 375 | * no iounmap() for that ioremap(); it would be a no-op, but |
| 376 | * it's so early in setup that sucker gets confused into doing |
| 377 | * what it shouldn't if we actually call it. |
| 378 | */ |
| 379 | p = dmi_ioremap(0xF0000, 0x10000); |
| 380 | if (p == NULL) |
| 381 | goto out; |
Andrey Panin | 61e032f | 2005-09-06 15:18:26 -0700 | [diff] [blame] | 382 | |
Matt Domsch | 3ed3bce | 2006-03-26 01:37:03 -0800 | [diff] [blame] | 383 | for (q = p; q < p + 0x10000; q += 16) { |
| 384 | rc = dmi_present(q); |
Lennart Poettering | 4f5c791 | 2007-05-08 22:07:02 +0200 | [diff] [blame] | 385 | if (!rc) { |
| 386 | dmi_available = 1; |
Ingo Molnar | 0d64484 | 2008-01-30 13:33:09 +0100 | [diff] [blame] | 387 | dmi_iounmap(p, 0x10000); |
Andrey Panin | 61e032f | 2005-09-06 15:18:26 -0700 | [diff] [blame] | 388 | return; |
Lennart Poettering | 4f5c791 | 2007-05-08 22:07:02 +0200 | [diff] [blame] | 389 | } |
Andrey Panin | 61e032f | 2005-09-06 15:18:26 -0700 | [diff] [blame] | 390 | } |
Yinghai Lu | 3212bff | 2008-01-30 13:33:32 +0100 | [diff] [blame] | 391 | dmi_iounmap(p, 0x10000); |
Andrey Panin | 61e032f | 2005-09-06 15:18:26 -0700 | [diff] [blame] | 392 | } |
Matt Domsch | 3ed3bce | 2006-03-26 01:37:03 -0800 | [diff] [blame] | 393 | out: printk(KERN_INFO "DMI not present or invalid.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | } |
| 395 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | /** |
| 397 | * dmi_check_system - check system DMI data |
| 398 | * @list: array of dmi_system_id structures to match against |
Randy Dunlap | b0ef371 | 2006-06-25 05:49:18 -0700 | [diff] [blame] | 399 | * All non-null elements of the list must match |
| 400 | * their slot's (field index's) data (i.e., each |
| 401 | * list string must be a substring of the specified |
| 402 | * DMI slot's string data) to be considered a |
| 403 | * successful match. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | * |
| 405 | * Walk the blacklist table running matching functions until someone |
| 406 | * 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] | 407 | * each successful match. Returns the number of matches. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | */ |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 409 | int dmi_check_system(const struct dmi_system_id *list) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | { |
| 411 | int i, count = 0; |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 412 | const struct dmi_system_id *d = list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | |
| 414 | while (d->ident) { |
| 415 | for (i = 0; i < ARRAY_SIZE(d->matches); i++) { |
| 416 | int s = d->matches[i].slot; |
| 417 | if (s == DMI_NONE) |
| 418 | continue; |
| 419 | if (dmi_ident[s] && strstr(dmi_ident[s], d->matches[i].substr)) |
| 420 | continue; |
| 421 | /* No match */ |
| 422 | goto fail; |
| 423 | } |
Robert Love | 640e803 | 2005-09-06 15:18:30 -0700 | [diff] [blame] | 424 | count++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | if (d->callback && d->callback(d)) |
| 426 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | fail: d++; |
| 428 | } |
| 429 | |
| 430 | return count; |
| 431 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | EXPORT_SYMBOL(dmi_check_system); |
| 433 | |
| 434 | /** |
| 435 | * dmi_get_system_info - return DMI data value |
Randy Dunlap | b0ef371 | 2006-06-25 05:49:18 -0700 | [diff] [blame] | 436 | * @field: data index (see enum dmi_field) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | * |
| 438 | * Returns one DMI data value, can be used to perform |
| 439 | * complex DMI data checks. |
| 440 | */ |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 441 | const char *dmi_get_system_info(int field) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | { |
| 443 | return dmi_ident[field]; |
| 444 | } |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 445 | EXPORT_SYMBOL(dmi_get_system_info); |
Andrey Panin | ebad6a4 | 2005-09-06 15:18:29 -0700 | [diff] [blame] | 446 | |
Andi Kleen | a1bae67 | 2006-10-21 18:37:02 +0200 | [diff] [blame] | 447 | |
| 448 | /** |
| 449 | * dmi_name_in_vendors - Check if string is anywhere in the DMI vendor information. |
| 450 | * @str: Case sensitive Name |
| 451 | */ |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 452 | int dmi_name_in_vendors(const char *str) |
Andi Kleen | a1bae67 | 2006-10-21 18:37:02 +0200 | [diff] [blame] | 453 | { |
| 454 | static int fields[] = { DMI_BIOS_VENDOR, DMI_BIOS_VERSION, DMI_SYS_VENDOR, |
| 455 | DMI_PRODUCT_NAME, DMI_PRODUCT_VERSION, DMI_BOARD_VENDOR, |
| 456 | DMI_BOARD_NAME, DMI_BOARD_VERSION, DMI_NONE }; |
| 457 | int i; |
| 458 | for (i = 0; fields[i] != DMI_NONE; i++) { |
| 459 | int f = fields[i]; |
| 460 | if (dmi_ident[f] && strstr(dmi_ident[f], str)) |
| 461 | return 1; |
| 462 | } |
| 463 | return 0; |
| 464 | } |
| 465 | EXPORT_SYMBOL(dmi_name_in_vendors); |
| 466 | |
Andrey Panin | ebad6a4 | 2005-09-06 15:18:29 -0700 | [diff] [blame] | 467 | /** |
| 468 | * dmi_find_device - find onboard device by type/name |
| 469 | * @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] | 470 | * @name: device name string or %NULL to match all |
Andrey Panin | ebad6a4 | 2005-09-06 15:18:29 -0700 | [diff] [blame] | 471 | * @from: previous device found in search, or %NULL for new search. |
| 472 | * |
| 473 | * Iterates through the list of known onboard devices. If a device is |
| 474 | * found with a matching @vendor and @device, a pointer to its device |
| 475 | * structure is returned. Otherwise, %NULL is returned. |
Randy Dunlap | b0ef371 | 2006-06-25 05:49:18 -0700 | [diff] [blame] | 476 | * A new search is initiated by passing %NULL as the @from argument. |
Andrey Panin | ebad6a4 | 2005-09-06 15:18:29 -0700 | [diff] [blame] | 477 | * If @from is not %NULL, searches continue from next device. |
| 478 | */ |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 479 | const struct dmi_device * dmi_find_device(int type, const char *name, |
| 480 | const struct dmi_device *from) |
Andrey Panin | ebad6a4 | 2005-09-06 15:18:29 -0700 | [diff] [blame] | 481 | { |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 482 | const struct list_head *head = from ? &from->list : &dmi_devices; |
| 483 | struct list_head *d; |
Andrey Panin | ebad6a4 | 2005-09-06 15:18:29 -0700 | [diff] [blame] | 484 | |
| 485 | for(d = head->next; d != &dmi_devices; d = d->next) { |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 486 | const struct dmi_device *dev = |
| 487 | list_entry(d, struct dmi_device, list); |
Andrey Panin | ebad6a4 | 2005-09-06 15:18:29 -0700 | [diff] [blame] | 488 | |
| 489 | if (((type == DMI_DEV_TYPE_ANY) || (dev->type == type)) && |
| 490 | ((name == NULL) || (strcmp(dev->name, name) == 0))) |
| 491 | return dev; |
| 492 | } |
| 493 | |
| 494 | return NULL; |
| 495 | } |
| 496 | EXPORT_SYMBOL(dmi_find_device); |
Andi Kleen | f083a32 | 2006-03-25 16:30:19 +0100 | [diff] [blame] | 497 | |
| 498 | /** |
| 499 | * dmi_get_year - Return year of a DMI date |
| 500 | * @field: data index (like dmi_get_system_info) |
| 501 | * |
| 502 | * Returns -1 when the field doesn't exist. 0 when it is broken. |
| 503 | */ |
| 504 | int dmi_get_year(int field) |
| 505 | { |
| 506 | int year; |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 507 | const char *s = dmi_get_system_info(field); |
Andi Kleen | f083a32 | 2006-03-25 16:30:19 +0100 | [diff] [blame] | 508 | |
| 509 | if (!s) |
| 510 | return -1; |
| 511 | if (*s == '\0') |
| 512 | return 0; |
| 513 | s = strrchr(s, '/'); |
| 514 | if (!s) |
| 515 | return 0; |
| 516 | |
| 517 | s += 1; |
| 518 | year = simple_strtoul(s, NULL, 0); |
| 519 | if (year && year < 100) { /* 2-digit year */ |
| 520 | year += 1900; |
| 521 | if (year < 1996) /* no dates < spec 1.0 */ |
| 522 | year += 100; |
| 523 | } |
| 524 | |
| 525 | return year; |
| 526 | } |
Jean Delvare | 7fce084 | 2007-11-03 17:29:20 +0100 | [diff] [blame] | 527 | |
| 528 | /** |
| 529 | * dmi_walk - Walk the DMI table and get called back for every record |
| 530 | * @decode: Callback function |
| 531 | * |
| 532 | * Returns -1 when the DMI table can't be reached, 0 on success. |
| 533 | */ |
| 534 | int dmi_walk(void (*decode)(const struct dmi_header *)) |
| 535 | { |
| 536 | u8 *buf; |
| 537 | |
| 538 | if (!dmi_available) |
| 539 | return -1; |
| 540 | |
| 541 | buf = ioremap(dmi_base, dmi_len); |
| 542 | if (buf == NULL) |
| 543 | return -1; |
| 544 | |
| 545 | dmi_table(buf, dmi_len, dmi_num, decode); |
| 546 | |
| 547 | iounmap(buf); |
| 548 | return 0; |
| 549 | } |
| 550 | EXPORT_SYMBOL_GPL(dmi_walk); |