1 #include <linux/types.h>
2 #include <linux/string.h>
3 #include <linux/init.h>
4 #include <linux/module.h>
7 #include <linux/bootmem.h>
8 #include <linux/slab.h>
11 static char dmi_empty_string
[] = " ";
13 static char * __init
dmi_string(const struct dmi_header
*dm
, u8 s
)
15 const u8
*bp
= ((u8
*) dm
) + dm
->length
;
20 while (s
> 0 && *bp
) {
26 size_t len
= strlen(bp
)+1;
27 size_t cmp_len
= len
> 8 ? 8 : len
;
29 if (!memcmp(bp
, dmi_empty_string
, cmp_len
))
30 return dmi_empty_string
;
35 printk(KERN_ERR
"dmi_string: cannot allocate %Zu bytes.\n", len
);
43 * We have to be cautious here. We have seen BIOSes with DMI pointers
44 * pointing to completely the wrong place for example
46 static void dmi_table(u8
*buf
, int len
, int num
,
47 void (*decode
)(const struct dmi_header
*))
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)
56 while ((i
< num
) && (data
- buf
+ sizeof(struct dmi_header
)) <= len
) {
57 const struct dmi_header
*dm
= (const struct dmi_header
*)data
;
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
65 while ((data
- buf
< len
- 1) && (data
[0] || data
[1]))
67 if (data
- buf
< len
- 1)
78 static int __init
dmi_walk_early(void (*decode
)(const struct dmi_header
*))
82 buf
= dmi_ioremap(dmi_base
, dmi_len
);
86 dmi_table(buf
, dmi_len
, dmi_num
, decode
);
88 dmi_iounmap(buf
, dmi_len
);
92 static int __init
dmi_checksum(const u8
*buf
)
97 for (a
= 0; a
< 15; a
++)
103 static char *dmi_ident
[DMI_STRING_MAX
];
104 static LIST_HEAD(dmi_devices
);
110 static void __init
dmi_save_ident(const struct dmi_header
*dm
, int slot
, int string
)
112 const char *d
= (const char*) dm
;
118 p
= dmi_string(dm
, d
[string
]);
125 static void __init
dmi_save_uuid(const struct dmi_header
*dm
, int slot
, int index
)
127 const u8
*d
= (u8
*) dm
+ index
;
129 int is_ff
= 1, is_00
= 1, i
;
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;
142 s
= dmi_alloc(16*2+4+1);
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]);
154 static void __init
dmi_save_type(const struct dmi_header
*dm
, int slot
, int index
)
156 const u8
*d
= (u8
*) dm
+ index
;
166 sprintf(s
, "%u", *d
& 0x7F);
170 static void __init
dmi_save_devices(const struct dmi_header
*dm
)
172 int i
, count
= (dm
->length
- sizeof(struct dmi_header
)) / 2;
173 struct dmi_device
*dev
;
175 for (i
= 0; i
< count
; i
++) {
176 const char *d
= (char *)(dm
+ 1) + (i
* 2);
178 /* Skip disabled device */
179 if ((*d
& 0x80) == 0)
182 dev
= dmi_alloc(sizeof(*dev
));
184 printk(KERN_ERR
"dmi_save_devices: out of memory.\n");
188 dev
->type
= *d
++ & 0x7f;
189 dev
->name
= dmi_string(dm
, *d
);
190 dev
->device_data
= NULL
;
191 list_add(&dev
->list
, &dmi_devices
);
195 static struct dmi_device empty_oem_string_dev
= {
196 .name
= dmi_empty_string
,
199 static void __init
dmi_save_oem_strings_devices(const struct dmi_header
*dm
)
201 int i
, count
= *(u8
*)(dm
+ 1);
202 struct dmi_device
*dev
;
204 for (i
= 1; i
<= count
; i
++) {
205 char *devname
= dmi_string(dm
, i
);
207 if (!strcmp(devname
, dmi_empty_string
)) {
208 list_add(&empty_oem_string_dev
.list
, &dmi_devices
);
212 dev
= dmi_alloc(sizeof(*dev
));
215 "dmi_save_oem_strings_devices: out of memory.\n");
219 dev
->type
= DMI_DEV_TYPE_OEM_STRING
;
221 dev
->device_data
= NULL
;
223 list_add(&dev
->list
, &dmi_devices
);
227 static void __init
dmi_save_ipmi_device(const struct dmi_header
*dm
)
229 struct dmi_device
*dev
;
232 data
= dmi_alloc(dm
->length
);
234 printk(KERN_ERR
"dmi_save_ipmi_device: out of memory.\n");
238 memcpy(data
, dm
, dm
->length
);
240 dev
= dmi_alloc(sizeof(*dev
));
242 printk(KERN_ERR
"dmi_save_ipmi_device: out of memory.\n");
246 dev
->type
= DMI_DEV_TYPE_IPMI
;
247 dev
->name
= "IPMI controller";
248 dev
->device_data
= data
;
250 list_add(&dev
->list
, &dmi_devices
);
254 * Process a DMI table entry. Right now all we care about are the BIOS
255 * and machine entries. For 2.5 we should pull the smbus controller info
258 static void __init
dmi_decode(const struct dmi_header
*dm
)
261 case 0: /* BIOS Information */
262 dmi_save_ident(dm
, DMI_BIOS_VENDOR
, 4);
263 dmi_save_ident(dm
, DMI_BIOS_VERSION
, 5);
264 dmi_save_ident(dm
, DMI_BIOS_DATE
, 8);
266 case 1: /* System Information */
267 dmi_save_ident(dm
, DMI_SYS_VENDOR
, 4);
268 dmi_save_ident(dm
, DMI_PRODUCT_NAME
, 5);
269 dmi_save_ident(dm
, DMI_PRODUCT_VERSION
, 6);
270 dmi_save_ident(dm
, DMI_PRODUCT_SERIAL
, 7);
271 dmi_save_uuid(dm
, DMI_PRODUCT_UUID
, 8);
273 case 2: /* Base Board Information */
274 dmi_save_ident(dm
, DMI_BOARD_VENDOR
, 4);
275 dmi_save_ident(dm
, DMI_BOARD_NAME
, 5);
276 dmi_save_ident(dm
, DMI_BOARD_VERSION
, 6);
277 dmi_save_ident(dm
, DMI_BOARD_SERIAL
, 7);
278 dmi_save_ident(dm
, DMI_BOARD_ASSET_TAG
, 8);
280 case 3: /* Chassis Information */
281 dmi_save_ident(dm
, DMI_CHASSIS_VENDOR
, 4);
282 dmi_save_type(dm
, DMI_CHASSIS_TYPE
, 5);
283 dmi_save_ident(dm
, DMI_CHASSIS_VERSION
, 6);
284 dmi_save_ident(dm
, DMI_CHASSIS_SERIAL
, 7);
285 dmi_save_ident(dm
, DMI_CHASSIS_ASSET_TAG
, 8);
287 case 10: /* Onboard Devices Information */
288 dmi_save_devices(dm
);
290 case 11: /* OEM Strings */
291 dmi_save_oem_strings_devices(dm
);
293 case 38: /* IPMI Device Information */
294 dmi_save_ipmi_device(dm
);
298 static int __init
dmi_present(const char __iomem
*p
)
302 memcpy_fromio(buf
, p
, 15);
303 if ((memcmp(buf
, "_DMI_", 5) == 0) && dmi_checksum(buf
)) {
304 dmi_num
= (buf
[13] << 8) | buf
[12];
305 dmi_len
= (buf
[7] << 8) | buf
[6];
306 dmi_base
= (buf
[11] << 24) | (buf
[10] << 16) |
307 (buf
[9] << 8) | buf
[8];
310 * DMI version 0.0 means that the real version is taken from
311 * the SMBIOS version, which we don't know at this point.
314 printk(KERN_INFO
"DMI %d.%d present.\n",
315 buf
[14] >> 4, buf
[14] & 0xF);
317 printk(KERN_INFO
"DMI present.\n");
318 if (dmi_walk_early(dmi_decode
) == 0)
324 void __init
dmi_scan_machine(void)
330 if (efi
.smbios
== EFI_INVALID_TABLE_ADDR
)
333 /* This is called as a core_initcall() because it isn't
334 * needed during early boot. This also means we can
335 * iounmap the space when we're done with it.
337 p
= dmi_ioremap(efi
.smbios
, 32);
341 rc
= dmi_present(p
+ 0x10); /* offset of _DMI_ string */
350 * no iounmap() for that ioremap(); it would be a no-op, but
351 * it's so early in setup that sucker gets confused into doing
352 * what it shouldn't if we actually call it.
354 p
= dmi_ioremap(0xF0000, 0x10000);
358 for (q
= p
; q
< p
+ 0x10000; q
+= 16) {
362 dmi_iounmap(p
, 0x10000);
366 dmi_iounmap(p
, 0x10000);
368 out
: printk(KERN_INFO
"DMI not present or invalid.\n");
372 * dmi_check_system - check system DMI data
373 * @list: array of dmi_system_id structures to match against
374 * All non-null elements of the list must match
375 * their slot's (field index's) data (i.e., each
376 * list string must be a substring of the specified
377 * DMI slot's string data) to be considered a
380 * Walk the blacklist table running matching functions until someone
381 * returns non zero or we hit the end. Callback function is called for
382 * each successful match. Returns the number of matches.
384 int dmi_check_system(const struct dmi_system_id
*list
)
387 const struct dmi_system_id
*d
= list
;
390 for (i
= 0; i
< ARRAY_SIZE(d
->matches
); i
++) {
391 int s
= d
->matches
[i
].slot
;
394 if (dmi_ident
[s
] && strstr(dmi_ident
[s
], d
->matches
[i
].substr
))
400 if (d
->callback
&& d
->callback(d
))
407 EXPORT_SYMBOL(dmi_check_system
);
410 * dmi_get_system_info - return DMI data value
411 * @field: data index (see enum dmi_field)
413 * Returns one DMI data value, can be used to perform
414 * complex DMI data checks.
416 const char *dmi_get_system_info(int field
)
418 return dmi_ident
[field
];
420 EXPORT_SYMBOL(dmi_get_system_info
);
424 * dmi_name_in_vendors - Check if string is anywhere in the DMI vendor information.
425 * @str: Case sensitive Name
427 int dmi_name_in_vendors(const char *str
)
429 static int fields
[] = { DMI_BIOS_VENDOR
, DMI_BIOS_VERSION
, DMI_SYS_VENDOR
,
430 DMI_PRODUCT_NAME
, DMI_PRODUCT_VERSION
, DMI_BOARD_VENDOR
,
431 DMI_BOARD_NAME
, DMI_BOARD_VERSION
, DMI_NONE
};
433 for (i
= 0; fields
[i
] != DMI_NONE
; i
++) {
435 if (dmi_ident
[f
] && strstr(dmi_ident
[f
], str
))
440 EXPORT_SYMBOL(dmi_name_in_vendors
);
443 * dmi_find_device - find onboard device by type/name
444 * @type: device type or %DMI_DEV_TYPE_ANY to match all device types
445 * @name: device name string or %NULL to match all
446 * @from: previous device found in search, or %NULL for new search.
448 * Iterates through the list of known onboard devices. If a device is
449 * found with a matching @vendor and @device, a pointer to its device
450 * structure is returned. Otherwise, %NULL is returned.
451 * A new search is initiated by passing %NULL as the @from argument.
452 * If @from is not %NULL, searches continue from next device.
454 const struct dmi_device
* dmi_find_device(int type
, const char *name
,
455 const struct dmi_device
*from
)
457 const struct list_head
*head
= from
? &from
->list
: &dmi_devices
;
460 for(d
= head
->next
; d
!= &dmi_devices
; d
= d
->next
) {
461 const struct dmi_device
*dev
=
462 list_entry(d
, struct dmi_device
, list
);
464 if (((type
== DMI_DEV_TYPE_ANY
) || (dev
->type
== type
)) &&
465 ((name
== NULL
) || (strcmp(dev
->name
, name
) == 0)))
471 EXPORT_SYMBOL(dmi_find_device
);
474 * dmi_get_year - Return year of a DMI date
475 * @field: data index (like dmi_get_system_info)
477 * Returns -1 when the field doesn't exist. 0 when it is broken.
479 int dmi_get_year(int field
)
482 const char *s
= dmi_get_system_info(field
);
493 year
= simple_strtoul(s
, NULL
, 0);
494 if (year
&& year
< 100) { /* 2-digit year */
496 if (year
< 1996) /* no dates < spec 1.0 */
504 * dmi_walk - Walk the DMI table and get called back for every record
505 * @decode: Callback function
507 * Returns -1 when the DMI table can't be reached, 0 on success.
509 int dmi_walk(void (*decode
)(const struct dmi_header
*))
516 buf
= ioremap(dmi_base
, dmi_len
);
520 dmi_table(buf
, dmi_len
, dmi_num
, decode
);
525 EXPORT_SYMBOL_GPL(dmi_walk
);