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> |
| 6 | #include <linux/bootmem.h> |
| 7 | |
| 8 | |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 9 | struct dmi_header { |
| 10 | u8 type; |
| 11 | u8 length; |
| 12 | u16 handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | }; |
| 14 | |
| 15 | #undef DMI_DEBUG |
| 16 | |
| 17 | #ifdef DMI_DEBUG |
| 18 | #define dmi_printk(x) printk x |
| 19 | #else |
| 20 | #define dmi_printk(x) |
| 21 | #endif |
| 22 | |
| 23 | static char * __init dmi_string(struct dmi_header *dm, u8 s) |
| 24 | { |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 25 | u8 *bp = ((u8 *) dm) + dm->length; |
| 26 | |
| 27 | if (!s) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | return ""; |
| 29 | s--; |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 30 | while (s > 0 && *bp) { |
| 31 | bp += strlen(bp) + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | s--; |
| 33 | } |
| 34 | return bp; |
| 35 | } |
| 36 | |
| 37 | /* |
| 38 | * We have to be cautious here. We have seen BIOSes with DMI pointers |
| 39 | * pointing to completely the wrong place for example |
| 40 | */ |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 41 | static int __init dmi_table(u32 base, int len, int num, |
| 42 | void (*decode)(struct dmi_header *)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | { |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 44 | u8 *buf, *data; |
| 45 | int i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
| 47 | buf = bt_ioremap(base, len); |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 48 | if (buf == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | return -1; |
| 50 | |
| 51 | data = buf; |
| 52 | |
| 53 | /* |
| 54 | * Stop when we see all the items the table claimed to have |
| 55 | * OR we run off the end of the table (also happens) |
| 56 | */ |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 57 | while ((i < num) && (data - buf + sizeof(struct dmi_header)) <= len) { |
| 58 | struct dmi_header *dm = (struct dmi_header *)data; |
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 | } |
| 72 | bt_iounmap(buf, len); |
| 73 | return 0; |
| 74 | } |
| 75 | |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 76 | static int __init dmi_checksum(u8 *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | { |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 78 | u8 sum = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | int a; |
| 80 | |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 81 | for (a = 0; a < 15; a++) |
| 82 | sum += buf[a]; |
| 83 | |
| 84 | return sum == 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | } |
| 86 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | static char *dmi_ident[DMI_STRING_MAX]; |
| 88 | |
| 89 | /* |
| 90 | * Save a DMI string |
| 91 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | static void __init dmi_save_ident(struct dmi_header *dm, int slot, int string) |
| 93 | { |
| 94 | char *d = (char*)dm; |
| 95 | char *p = dmi_string(dm, d[string]); |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 96 | |
| 97 | if (p == NULL || *p == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | return; |
| 99 | if (dmi_ident[slot]) |
| 100 | return; |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 101 | |
| 102 | dmi_ident[slot] = alloc_bootmem(strlen(p) + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | if(dmi_ident[slot]) |
| 104 | strcpy(dmi_ident[slot], p); |
| 105 | else |
| 106 | printk(KERN_ERR "dmi_save_ident: out of memory.\n"); |
| 107 | } |
| 108 | |
| 109 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | * Process a DMI table entry. Right now all we care about are the BIOS |
| 111 | * and machine entries. For 2.5 we should pull the smbus controller info |
| 112 | * out of here. |
| 113 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | static void __init dmi_decode(struct dmi_header *dm) |
| 115 | { |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 116 | u8 *data __attribute__((__unused__)) = (u8 *)dm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | |
Andrey Panin | 1249c51 | 2005-06-25 14:54:47 -0700 | [diff] [blame] | 118 | switch(dm->type) { |
| 119 | case 0: |
| 120 | dmi_printk(("BIOS Vendor: %s\n", dmi_string(dm, data[4]))); |
| 121 | dmi_save_ident(dm, DMI_BIOS_VENDOR, 4); |
| 122 | dmi_printk(("BIOS Version: %s\n", dmi_string(dm, data[5]))); |
| 123 | dmi_save_ident(dm, DMI_BIOS_VERSION, 5); |
| 124 | dmi_printk(("BIOS Release: %s\n", dmi_string(dm, data[8]))); |
| 125 | dmi_save_ident(dm, DMI_BIOS_DATE, 8); |
| 126 | break; |
| 127 | case 1: |
| 128 | dmi_printk(("System Vendor: %s\n", dmi_string(dm, data[4]))); |
| 129 | dmi_save_ident(dm, DMI_SYS_VENDOR, 4); |
| 130 | dmi_printk(("Product Name: %s\n", dmi_string(dm, data[5]))); |
| 131 | dmi_save_ident(dm, DMI_PRODUCT_NAME, 5); |
| 132 | dmi_printk(("Version: %s\n", dmi_string(dm, data[6]))); |
| 133 | dmi_save_ident(dm, DMI_PRODUCT_VERSION, 6); |
| 134 | dmi_printk(("Serial Number: %s\n", dmi_string(dm, data[7]))); |
| 135 | dmi_save_ident(dm, DMI_PRODUCT_SERIAL, 7); |
| 136 | break; |
| 137 | case 2: |
| 138 | dmi_printk(("Board Vendor: %s\n", dmi_string(dm, data[4]))); |
| 139 | dmi_save_ident(dm, DMI_BOARD_VENDOR, 4); |
| 140 | dmi_printk(("Board Name: %s\n", dmi_string(dm, data[5]))); |
| 141 | dmi_save_ident(dm, DMI_BOARD_NAME, 5); |
| 142 | dmi_printk(("Board Version: %s\n", dmi_string(dm, data[6]))); |
| 143 | dmi_save_ident(dm, DMI_BOARD_VERSION, 6); |
| 144 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | } |
| 146 | } |
| 147 | |
| 148 | void __init dmi_scan_machine(void) |
| 149 | { |
Andrey Panin | 61e032fa | 2005-09-06 15:18:26 -0700 | [diff] [blame^] | 150 | u8 buf[15]; |
| 151 | char __iomem *p, *q; |
| 152 | |
| 153 | /* |
| 154 | * no iounmap() for that ioremap(); it would be a no-op, but it's |
| 155 | * so early in setup that sucker gets confused into doing what |
| 156 | * it shouldn't if we actually call it. |
| 157 | */ |
| 158 | p = ioremap(0xF0000, 0x10000); |
| 159 | if (p == NULL) |
| 160 | goto out; |
| 161 | |
| 162 | for (q = p; q < p + 0x10000; q += 16) { |
| 163 | memcpy_fromio(buf, q, 15); |
| 164 | if ((memcmp(buf, "_DMI_", 5) == 0) && dmi_checksum(buf)) { |
| 165 | u16 num = (buf[13] << 8) | buf[12]; |
| 166 | u16 len = (buf[7] << 8) | buf[6]; |
| 167 | u32 base = (buf[11] << 24) | (buf[10] << 16) | |
| 168 | (buf[9] << 8) | buf[8]; |
| 169 | |
| 170 | /* |
| 171 | * DMI version 0.0 means that the real version is taken from |
| 172 | * the SMBIOS version, which we don't know at this point. |
| 173 | */ |
| 174 | if (buf[14] != 0) |
| 175 | printk(KERN_INFO "DMI %d.%d present.\n", |
| 176 | buf[14] >> 4, buf[14] & 0xF); |
| 177 | else |
| 178 | printk(KERN_INFO "DMI present.\n"); |
| 179 | |
| 180 | dmi_printk((KERN_INFO "%d structures occupying %d bytes.\n", |
| 181 | num, len)); |
| 182 | dmi_printk((KERN_INFO "DMI table at 0x%08X.\n", base)); |
| 183 | |
| 184 | if (dmi_table(base,len, num, dmi_decode) == 0) |
| 185 | return; |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | out: printk(KERN_INFO "DMI not present.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | |
| 193 | /** |
| 194 | * dmi_check_system - check system DMI data |
| 195 | * @list: array of dmi_system_id structures to match against |
| 196 | * |
| 197 | * Walk the blacklist table running matching functions until someone |
| 198 | * returns non zero or we hit the end. Callback function is called for |
| 199 | * each successfull match. Returns the number of matches. |
| 200 | */ |
| 201 | int dmi_check_system(struct dmi_system_id *list) |
| 202 | { |
| 203 | int i, count = 0; |
| 204 | struct dmi_system_id *d = list; |
| 205 | |
| 206 | while (d->ident) { |
| 207 | for (i = 0; i < ARRAY_SIZE(d->matches); i++) { |
| 208 | int s = d->matches[i].slot; |
| 209 | if (s == DMI_NONE) |
| 210 | continue; |
| 211 | if (dmi_ident[s] && strstr(dmi_ident[s], d->matches[i].substr)) |
| 212 | continue; |
| 213 | /* No match */ |
| 214 | goto fail; |
| 215 | } |
| 216 | if (d->callback && d->callback(d)) |
| 217 | break; |
| 218 | count++; |
| 219 | fail: d++; |
| 220 | } |
| 221 | |
| 222 | return count; |
| 223 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | EXPORT_SYMBOL(dmi_check_system); |
| 225 | |
| 226 | /** |
| 227 | * dmi_get_system_info - return DMI data value |
| 228 | * @field: data index (see enum dmi_filed) |
| 229 | * |
| 230 | * Returns one DMI data value, can be used to perform |
| 231 | * complex DMI data checks. |
| 232 | */ |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 233 | char *dmi_get_system_info(int field) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | { |
| 235 | return dmi_ident[field]; |
| 236 | } |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 237 | EXPORT_SYMBOL(dmi_get_system_info); |