]>
git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - arch/i386/kernel/dmi_scan.c
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>
18 #define dmi_printk(x) printk x
23 static char * __init
dmi_string(struct dmi_header
*dm
, u8 s
)
25 u8
*bp
= ((u8
*) dm
) + dm
->length
;
30 while (s
> 0 && *bp
) {
38 * We have to be cautious here. We have seen BIOSes with DMI pointers
39 * pointing to completely the wrong place for example
41 static int __init
dmi_table(u32 base
, int len
, int num
,
42 void (*decode
)(struct dmi_header
*))
47 buf
= bt_ioremap(base
, len
);
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)
57 while ((i
< num
) && (data
- buf
+ sizeof(struct dmi_header
)) <= len
) {
58 struct dmi_header
*dm
= (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)
76 static int __init
dmi_checksum(u8
*buf
)
81 for (a
= 0; a
< 15; a
++)
87 static int __init
dmi_iterate(void (*decode
)(struct dmi_header
*))
93 * no iounmap() for that ioremap(); it would be a no-op, but it's
94 * so early in setup that sucker gets confused into doing what
95 * it shouldn't if we actually call it.
97 p
= ioremap(0xF0000, 0x10000);
101 for (q
= p
; q
< p
+ 0x10000; q
+= 16) {
102 memcpy_fromio(buf
, q
, 15);
103 if ((memcmp(buf
, "_DMI_", 5) == 0) && dmi_checksum(buf
)) {
104 u16 num
= (buf
[13] << 8) | buf
[12];
105 u16 len
= (buf
[7] << 8) | buf
[6];
106 u32 base
= (buf
[11] << 24) | (buf
[10] << 16) |
107 (buf
[9] << 8) | buf
[8];
110 * DMI version 0.0 means that the real version is taken from
111 * the SMBIOS version, which we don't know at this point.
114 printk(KERN_INFO
"DMI %d.%d present.\n",
115 buf
[14] >> 4, buf
[14] & 0xF);
117 printk(KERN_INFO
"DMI present.\n");
119 dmi_printk((KERN_INFO
"%d structures occupying %d bytes.\n",
121 dmi_printk((KERN_INFO
"DMI table at 0x%08X.\n", base
));
123 if (dmi_table(base
,len
, num
, decode
) == 0)
130 static char *dmi_ident
[DMI_STRING_MAX
];
135 static void __init
dmi_save_ident(struct dmi_header
*dm
, int slot
, int string
)
138 char *p
= dmi_string(dm
, d
[string
]);
140 if (p
== NULL
|| *p
== 0)
145 dmi_ident
[slot
] = alloc_bootmem(strlen(p
) + 1);
147 strcpy(dmi_ident
[slot
], p
);
149 printk(KERN_ERR
"dmi_save_ident: out of memory.\n");
153 * Process a DMI table entry. Right now all we care about are the BIOS
154 * and machine entries. For 2.5 we should pull the smbus controller info
157 static void __init
dmi_decode(struct dmi_header
*dm
)
159 u8
*data
__attribute__((__unused__
)) = (u8
*)dm
;
163 dmi_printk(("BIOS Vendor: %s\n", dmi_string(dm
, data
[4])));
164 dmi_save_ident(dm
, DMI_BIOS_VENDOR
, 4);
165 dmi_printk(("BIOS Version: %s\n", dmi_string(dm
, data
[5])));
166 dmi_save_ident(dm
, DMI_BIOS_VERSION
, 5);
167 dmi_printk(("BIOS Release: %s\n", dmi_string(dm
, data
[8])));
168 dmi_save_ident(dm
, DMI_BIOS_DATE
, 8);
171 dmi_printk(("System Vendor: %s\n", dmi_string(dm
, data
[4])));
172 dmi_save_ident(dm
, DMI_SYS_VENDOR
, 4);
173 dmi_printk(("Product Name: %s\n", dmi_string(dm
, data
[5])));
174 dmi_save_ident(dm
, DMI_PRODUCT_NAME
, 5);
175 dmi_printk(("Version: %s\n", dmi_string(dm
, data
[6])));
176 dmi_save_ident(dm
, DMI_PRODUCT_VERSION
, 6);
177 dmi_printk(("Serial Number: %s\n", dmi_string(dm
, data
[7])));
178 dmi_save_ident(dm
, DMI_PRODUCT_SERIAL
, 7);
181 dmi_printk(("Board Vendor: %s\n", dmi_string(dm
, data
[4])));
182 dmi_save_ident(dm
, DMI_BOARD_VENDOR
, 4);
183 dmi_printk(("Board Name: %s\n", dmi_string(dm
, data
[5])));
184 dmi_save_ident(dm
, DMI_BOARD_NAME
, 5);
185 dmi_printk(("Board Version: %s\n", dmi_string(dm
, data
[6])));
186 dmi_save_ident(dm
, DMI_BOARD_VERSION
, 6);
191 void __init
dmi_scan_machine(void)
193 if (dmi_iterate(dmi_decode
))
194 printk(KERN_INFO
"DMI not present.\n");
199 * dmi_check_system - check system DMI data
200 * @list: array of dmi_system_id structures to match against
202 * Walk the blacklist table running matching functions until someone
203 * returns non zero or we hit the end. Callback function is called for
204 * each successfull match. Returns the number of matches.
206 int dmi_check_system(struct dmi_system_id
*list
)
209 struct dmi_system_id
*d
= list
;
212 for (i
= 0; i
< ARRAY_SIZE(d
->matches
); i
++) {
213 int s
= d
->matches
[i
].slot
;
216 if (dmi_ident
[s
] && strstr(dmi_ident
[s
], d
->matches
[i
].substr
))
221 if (d
->callback
&& d
->callback(d
))
229 EXPORT_SYMBOL(dmi_check_system
);
232 * dmi_get_system_info - return DMI data value
233 * @field: data index (see enum dmi_filed)
235 * Returns one DMI data value, can be used to perform
236 * complex DMI data checks.
238 char *dmi_get_system_info(int field
)
240 return dmi_ident
[field
];
242 EXPORT_SYMBOL(dmi_get_system_info
);