1 #include <linux/types.h>
2 #include <linux/string.h>
3 #include <linux/init.h>
4 #include <linux/module.h>
6 #include <linux/bootmem.h>
9 static char * __init
dmi_string(struct dmi_header
*dm
, u8 s
)
11 u8
*bp
= ((u8
*) dm
) + dm
->length
;
16 while (s
> 0 && *bp
) {
22 str
= alloc_bootmem(strlen(bp
) + 1);
26 printk(KERN_ERR
"dmi_string: out of memory.\n");
34 * We have to be cautious here. We have seen BIOSes with DMI pointers
35 * pointing to completely the wrong place for example
37 static int __init
dmi_table(u32 base
, int len
, int num
,
38 void (*decode
)(struct dmi_header
*))
43 buf
= bt_ioremap(base
, len
);
50 * Stop when we see all the items the table claimed to have
51 * OR we run off the end of the table (also happens)
53 while ((i
< num
) && (data
- buf
+ sizeof(struct dmi_header
)) <= len
) {
54 struct dmi_header
*dm
= (struct dmi_header
*)data
;
56 * We want to know the total length (formated area and strings)
57 * before decoding to make sure we won't run off the table in
58 * dmi_decode or dmi_string
61 while ((data
- buf
< len
- 1) && (data
[0] || data
[1]))
63 if (data
- buf
< len
- 1)
72 static int __init
dmi_checksum(u8
*buf
)
77 for (a
= 0; a
< 15; a
++)
83 static char *dmi_ident
[DMI_STRING_MAX
];
84 static LIST_HEAD(dmi_devices
);
89 static void __init
dmi_save_ident(struct dmi_header
*dm
, int slot
, int string
)
91 char *p
, *d
= (char*) dm
;
96 p
= dmi_string(dm
, d
[string
]);
103 static void __init
dmi_save_devices(struct dmi_header
*dm
)
105 int i
, count
= (dm
->length
- sizeof(struct dmi_header
)) / 2;
106 struct dmi_device
*dev
;
108 for (i
= 0; i
< count
; i
++) {
109 char *d
= ((char *) dm
) + (i
* 2);
111 /* Skip disabled device */
112 if ((*d
& 0x80) == 0)
115 dev
= alloc_bootmem(sizeof(*dev
));
117 printk(KERN_ERR
"dmi_save_devices: out of memory.\n");
121 dev
->type
= *d
++ & 0x7f;
122 dev
->name
= dmi_string(dm
, *d
);
123 dev
->device_data
= NULL
;
125 list_add(&dev
->list
, &dmi_devices
);
129 static void __init
dmi_save_ipmi_device(struct dmi_header
*dm
)
131 struct dmi_device
*dev
;
134 data
= alloc_bootmem(dm
->length
);
136 printk(KERN_ERR
"dmi_save_ipmi_device: out of memory.\n");
140 memcpy(data
, dm
, dm
->length
);
142 dev
= alloc_bootmem(sizeof(*dev
));
144 printk(KERN_ERR
"dmi_save_ipmi_device: out of memory.\n");
148 dev
->type
= DMI_DEV_TYPE_IPMI
;
149 dev
->name
= "IPMI controller";
150 dev
->device_data
= data
;
152 list_add(&dev
->list
, &dmi_devices
);
156 * Process a DMI table entry. Right now all we care about are the BIOS
157 * and machine entries. For 2.5 we should pull the smbus controller info
160 static void __init
dmi_decode(struct dmi_header
*dm
)
163 case 0: /* BIOS Information */
164 dmi_save_ident(dm
, DMI_BIOS_VENDOR
, 4);
165 dmi_save_ident(dm
, DMI_BIOS_VERSION
, 5);
166 dmi_save_ident(dm
, DMI_BIOS_DATE
, 8);
168 case 1: /* System Information */
169 dmi_save_ident(dm
, DMI_SYS_VENDOR
, 4);
170 dmi_save_ident(dm
, DMI_PRODUCT_NAME
, 5);
171 dmi_save_ident(dm
, DMI_PRODUCT_VERSION
, 6);
172 dmi_save_ident(dm
, DMI_PRODUCT_SERIAL
, 7);
174 case 2: /* Base Board Information */
175 dmi_save_ident(dm
, DMI_BOARD_VENDOR
, 4);
176 dmi_save_ident(dm
, DMI_BOARD_NAME
, 5);
177 dmi_save_ident(dm
, DMI_BOARD_VERSION
, 6);
179 case 10: /* Onboard Devices Information */
180 dmi_save_devices(dm
);
182 case 38: /* IPMI Device Information */
183 dmi_save_ipmi_device(dm
);
187 void __init
dmi_scan_machine(void)
193 * no iounmap() for that ioremap(); it would be a no-op, but it's
194 * so early in setup that sucker gets confused into doing what
195 * it shouldn't if we actually call it.
197 p
= ioremap(0xF0000, 0x10000);
201 for (q
= p
; q
< p
+ 0x10000; q
+= 16) {
202 memcpy_fromio(buf
, q
, 15);
203 if ((memcmp(buf
, "_DMI_", 5) == 0) && dmi_checksum(buf
)) {
204 u16 num
= (buf
[13] << 8) | buf
[12];
205 u16 len
= (buf
[7] << 8) | buf
[6];
206 u32 base
= (buf
[11] << 24) | (buf
[10] << 16) |
207 (buf
[9] << 8) | buf
[8];
210 * DMI version 0.0 means that the real version is taken from
211 * the SMBIOS version, which we don't know at this point.
214 printk(KERN_INFO
"DMI %d.%d present.\n",
215 buf
[14] >> 4, buf
[14] & 0xF);
217 printk(KERN_INFO
"DMI present.\n");
219 if (dmi_table(base
,len
, num
, dmi_decode
) == 0)
224 out
: printk(KERN_INFO
"DMI not present.\n");
229 * dmi_check_system - check system DMI data
230 * @list: array of dmi_system_id structures to match against
232 * Walk the blacklist table running matching functions until someone
233 * returns non zero or we hit the end. Callback function is called for
234 * each successfull match. Returns the number of matches.
236 int dmi_check_system(struct dmi_system_id
*list
)
239 struct dmi_system_id
*d
= list
;
242 for (i
= 0; i
< ARRAY_SIZE(d
->matches
); i
++) {
243 int s
= d
->matches
[i
].slot
;
246 if (dmi_ident
[s
] && strstr(dmi_ident
[s
], d
->matches
[i
].substr
))
252 if (d
->callback
&& d
->callback(d
))
259 EXPORT_SYMBOL(dmi_check_system
);
262 * dmi_get_system_info - return DMI data value
263 * @field: data index (see enum dmi_filed)
265 * Returns one DMI data value, can be used to perform
266 * complex DMI data checks.
268 char *dmi_get_system_info(int field
)
270 return dmi_ident
[field
];
272 EXPORT_SYMBOL(dmi_get_system_info
);
275 * dmi_find_device - find onboard device by type/name
276 * @type: device type or %DMI_DEV_TYPE_ANY to match all device types
277 * @desc: device name string or %NULL to match all
278 * @from: previous device found in search, or %NULL for new search.
280 * Iterates through the list of known onboard devices. If a device is
281 * found with a matching @vendor and @device, a pointer to its device
282 * structure is returned. Otherwise, %NULL is returned.
283 * A new search is initiated by passing %NULL to the @from argument.
284 * If @from is not %NULL, searches continue from next device.
286 struct dmi_device
* dmi_find_device(int type
, const char *name
,
287 struct dmi_device
*from
)
289 struct list_head
*d
, *head
= from
? &from
->list
: &dmi_devices
;
291 for(d
= head
->next
; d
!= &dmi_devices
; d
= d
->next
) {
292 struct dmi_device
*dev
= list_entry(d
, struct dmi_device
, list
);
294 if (((type
== DMI_DEV_TYPE_ANY
) || (dev
->type
== type
)) &&
295 ((name
== NULL
) || (strcmp(dev
->name
, name
) == 0)))
301 EXPORT_SYMBOL(dmi_find_device
);