Kevin O'Connor | 0525d29 | 2008-07-04 06:18:30 -0400 | [diff] [blame] | 1 | // smbios table generation (on emulators) |
Kevin O'Connor | 8996ad2 | 2014-04-07 16:02:22 -0400 | [diff] [blame] | 2 | // DO NOT ADD NEW FEATURES HERE. (See paravirt.c / biostables.c instead.) |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 3 | // |
Kevin O'Connor | 2929c35 | 2009-07-25 13:48:27 -0400 | [diff] [blame] | 4 | // Copyright (C) 2008,2009 Kevin O'Connor <kevin@koconnor.net> |
Kevin O'Connor | 0525d29 | 2008-07-04 06:18:30 -0400 | [diff] [blame] | 5 | // Copyright (C) 2006 Fabrice Bellard |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 6 | // |
Kevin O'Connor | b1b7c2a | 2009-01-15 20:52:58 -0500 | [diff] [blame] | 7 | // This file may be distributed under the terms of the GNU LGPLv3 license. |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 8 | |
Kevin O'Connor | de9e705 | 2013-02-09 19:09:20 -0500 | [diff] [blame] | 9 | #include "config.h" // CONFIG_* |
Kevin O'Connor | 9dea590 | 2013-09-14 20:23:54 -0400 | [diff] [blame] | 10 | #include "malloc.h" // free |
Kevin O'Connor | 2d2fa31 | 2013-09-14 21:55:26 -0400 | [diff] [blame] | 11 | #include "output.h" // dprintf |
| 12 | #include "paravirt.h" // RamSize |
Kevin O'Connor | 41639f8 | 2013-09-14 19:37:36 -0400 | [diff] [blame] | 13 | #include "romfile.h" // romfile_findprefix |
Kevin O'Connor | b37a528 | 2013-09-14 22:45:05 -0400 | [diff] [blame] | 14 | #include "std/smbios.h" // struct smbios_entry_point |
Kevin O'Connor | fa9c66a | 2013-09-14 19:10:40 -0400 | [diff] [blame] | 15 | #include "string.h" // memset |
Kevin O'Connor | 2d2fa31 | 2013-09-14 21:55:26 -0400 | [diff] [blame] | 16 | #include "util.h" // MaxCountCPUs |
Kevin O'Connor | b9c6a96 | 2013-09-14 13:01:30 -0400 | [diff] [blame] | 17 | #include "x86.h" // cpuid |
Kevin O'Connor | 0525d29 | 2008-07-04 06:18:30 -0400 | [diff] [blame] | 18 | |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 19 | static void |
Kevin O'Connor | d83c87b | 2013-01-21 01:14:12 -0500 | [diff] [blame] | 20 | smbios_entry_point_setup(u16 max_structure_size, |
| 21 | u16 structure_table_length, |
| 22 | void *structure_table_address, |
| 23 | u16 number_of_structures) |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 24 | { |
Kevin O'Connor | 32f0387 | 2011-08-03 20:45:32 -0400 | [diff] [blame] | 25 | void *finaltable; |
| 26 | if (structure_table_length <= BUILD_MAX_SMBIOS_FSEG) |
| 27 | // Table is small enough for f-seg - allocate there. This |
| 28 | // works around a bug in JunOS (at least for small SMBIOS tables). |
| 29 | finaltable = malloc_fseg(structure_table_length); |
| 30 | else |
| 31 | finaltable = malloc_high(structure_table_length); |
Kevin O'Connor | 3bd2dc6 | 2014-04-07 16:35:18 -0400 | [diff] [blame] | 32 | if (!finaltable) { |
Kevin O'Connor | cfdc13f | 2010-02-14 13:07:54 -0500 | [diff] [blame] | 33 | warn_noalloc(); |
Kevin O'Connor | 2929c35 | 2009-07-25 13:48:27 -0400 | [diff] [blame] | 34 | return; |
| 35 | } |
Kevin O'Connor | fe2c3ee | 2009-12-26 23:26:44 -0500 | [diff] [blame] | 36 | memcpy(finaltable, structure_table_address, structure_table_length); |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 37 | |
Kevin O'Connor | 3bd2dc6 | 2014-04-07 16:35:18 -0400 | [diff] [blame] | 38 | struct smbios_entry_point ep; |
| 39 | memset(&ep, 0, sizeof(ep)); |
| 40 | memcpy(ep.anchor_string, "_SM_", 4); |
| 41 | ep.length = 0x1f; |
| 42 | ep.smbios_major_version = 2; |
| 43 | ep.smbios_minor_version = 4; |
| 44 | ep.max_structure_size = max_structure_size; |
| 45 | memcpy(ep.intermediate_anchor_string, "_DMI_", 5); |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 46 | |
Kevin O'Connor | 3bd2dc6 | 2014-04-07 16:35:18 -0400 | [diff] [blame] | 47 | ep.structure_table_length = structure_table_length; |
| 48 | ep.structure_table_address = (u32)finaltable; |
| 49 | ep.number_of_structures = number_of_structures; |
| 50 | ep.smbios_bcd_revision = 0x24; |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 51 | |
Kevin O'Connor | 3bd2dc6 | 2014-04-07 16:35:18 -0400 | [diff] [blame] | 52 | ep.checksum -= checksum(&ep, 0x10); |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 53 | |
Kevin O'Connor | 3bd2dc6 | 2014-04-07 16:35:18 -0400 | [diff] [blame] | 54 | ep.intermediate_checksum -= checksum((void*)&ep + 0x10, ep.length - 0x10); |
Kevin O'Connor | 2929c35 | 2009-07-25 13:48:27 -0400 | [diff] [blame] | 55 | |
Kevin O'Connor | 3bd2dc6 | 2014-04-07 16:35:18 -0400 | [diff] [blame] | 56 | copy_smbios(&ep); |
Kevin O'Connor | 2e7ab8b | 2008-03-29 14:29:35 -0400 | [diff] [blame] | 57 | } |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 58 | |
Kevin O'Connor | de9e705 | 2013-02-09 19:09:20 -0500 | [diff] [blame] | 59 | static int |
| 60 | get_field(int type, int offset, void *dest) |
| 61 | { |
| 62 | char name[128]; |
| 63 | snprintf(name, sizeof(name), "smbios/field%d-%d", type, offset); |
| 64 | struct romfile_s *file = romfile_find(name); |
| 65 | if (!file) |
| 66 | return 0; |
| 67 | file->copy(file, dest, file->size); |
| 68 | return file->size; |
| 69 | } |
| 70 | |
| 71 | static int |
| 72 | get_external(int type, char **p, unsigned *nr_structs, |
| 73 | unsigned *max_struct_size, char *end) |
| 74 | { |
| 75 | static u64 used_bitmap[4] = { 0 }; |
| 76 | char *start = *p; |
| 77 | |
| 78 | /* Check if we've already reported these tables */ |
| 79 | if (used_bitmap[(type >> 6) & 0x3] & (1ULL << (type & 0x3f))) |
| 80 | return 1; |
| 81 | |
| 82 | /* Don't introduce spurious end markers */ |
| 83 | if (type == 127) |
| 84 | return 0; |
| 85 | |
| 86 | char prefix[128]; |
| 87 | snprintf(prefix, sizeof(prefix), "smbios/table%d-", type); |
| 88 | struct romfile_s *file = NULL; |
| 89 | for (;;) { |
| 90 | file = romfile_findprefix(prefix, file); |
| 91 | if (!file) |
| 92 | break; |
| 93 | |
| 94 | if (end - *p < file->size) { |
| 95 | warn_noalloc(); |
| 96 | break; |
| 97 | } |
| 98 | |
| 99 | struct smbios_structure_header *header = (void*)*p; |
| 100 | file->copy(file, header, file->size); |
| 101 | *p += file->size; |
| 102 | |
| 103 | /* Entries end with a double NULL char, if there's a string at |
| 104 | * the end (length is greater than formatted length), the string |
| 105 | * terminator provides the first NULL. */ |
| 106 | *((u8*)*p) = 0; |
| 107 | (*p)++; |
| 108 | if (header->length >= file->size) { |
| 109 | *((u8*)*p) = 0; |
| 110 | (*p)++; |
| 111 | } |
| 112 | |
| 113 | (*nr_structs)++; |
| 114 | if (*p - (char*)header > *max_struct_size) |
| 115 | *max_struct_size = *p - (char*)header; |
| 116 | } |
| 117 | |
| 118 | if (start == *p) |
| 119 | return 0; |
| 120 | |
| 121 | /* Mark that we've reported on this type */ |
| 122 | used_bitmap[(type >> 6) & 0x3] |= (1ULL << (type & 0x3f)); |
| 123 | return 1; |
| 124 | } |
| 125 | |
Kevin O'Connor | 4e4b410 | 2009-10-08 21:21:59 -0400 | [diff] [blame] | 126 | #define load_str_field_with_default(type, field, def) \ |
| 127 | do { \ |
Kevin O'Connor | de9e705 | 2013-02-09 19:09:20 -0500 | [diff] [blame] | 128 | size = get_field(type, offsetof(struct smbios_type_##type, \ |
| 129 | field), end); \ |
Gerd Hoffmann | 344496f | 2014-01-20 14:32:54 +0100 | [diff] [blame] | 130 | if (size == 1) { \ |
| 131 | /* zero-length string, skip to avoid bogus end marker */ \ |
| 132 | p->field = 0; \ |
| 133 | } else if (size > 1) { \ |
Kevin O'Connor | 4e4b410 | 2009-10-08 21:21:59 -0400 | [diff] [blame] | 134 | end += size; \ |
Gerd Hoffmann | 344496f | 2014-01-20 14:32:54 +0100 | [diff] [blame] | 135 | p->field = ++str_index; \ |
Kevin O'Connor | 4e4b410 | 2009-10-08 21:21:59 -0400 | [diff] [blame] | 136 | } else { \ |
| 137 | memcpy(end, def, sizeof(def)); \ |
| 138 | end += sizeof(def); \ |
Gerd Hoffmann | 344496f | 2014-01-20 14:32:54 +0100 | [diff] [blame] | 139 | p->field = ++str_index; \ |
Kevin O'Connor | 4e4b410 | 2009-10-08 21:21:59 -0400 | [diff] [blame] | 140 | } \ |
Kevin O'Connor | 4e4b410 | 2009-10-08 21:21:59 -0400 | [diff] [blame] | 141 | } while (0) |
| 142 | |
Alex Williamson | 17d3e46 | 2010-06-21 09:46:19 -0600 | [diff] [blame] | 143 | #define load_str_field_or_skip(type, field) \ |
Kevin O'Connor | 4e4b410 | 2009-10-08 21:21:59 -0400 | [diff] [blame] | 144 | do { \ |
Kevin O'Connor | de9e705 | 2013-02-09 19:09:20 -0500 | [diff] [blame] | 145 | size = get_field(type, offsetof(struct smbios_type_##type, \ |
| 146 | field), end); \ |
Gerd Hoffmann | 344496f | 2014-01-20 14:32:54 +0100 | [diff] [blame] | 147 | if (size > 1) { \ |
Kevin O'Connor | 4e4b410 | 2009-10-08 21:21:59 -0400 | [diff] [blame] | 148 | end += size; \ |
| 149 | p->field = ++str_index; \ |
| 150 | } else { \ |
| 151 | p->field = 0; \ |
| 152 | } \ |
| 153 | } while (0) |
| 154 | |
Alex Williamson | 17d3e46 | 2010-06-21 09:46:19 -0600 | [diff] [blame] | 155 | #define set_field_with_default(type, field, def) \ |
| 156 | do { \ |
Kevin O'Connor | de9e705 | 2013-02-09 19:09:20 -0500 | [diff] [blame] | 157 | if (!get_field(type, offsetof(struct smbios_type_##type, \ |
| 158 | field), &p->field)) { \ |
Alex Williamson | 17d3e46 | 2010-06-21 09:46:19 -0600 | [diff] [blame] | 159 | p->field = def; \ |
| 160 | } \ |
| 161 | } while (0) |
| 162 | |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 163 | /* Type 0 -- BIOS Information */ |
Gerd Hoffmann | 46ee834 | 2012-06-07 10:34:31 +0200 | [diff] [blame] | 164 | #define RELEASE_DATE_STR "01/01/2011" |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 165 | static void * |
Kevin O'Connor | 4e4b410 | 2009-10-08 21:21:59 -0400 | [diff] [blame] | 166 | smbios_init_type_0(void *start) |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 167 | { |
| 168 | struct smbios_type_0 *p = (struct smbios_type_0 *)start; |
Kevin O'Connor | 4e4b410 | 2009-10-08 21:21:59 -0400 | [diff] [blame] | 169 | char *end = (char *)start + sizeof(struct smbios_type_0); |
| 170 | size_t size; |
| 171 | int str_index = 0; |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 172 | |
| 173 | p->header.type = 0; |
| 174 | p->header.length = sizeof(struct smbios_type_0); |
| 175 | p->header.handle = 0; |
| 176 | |
Kevin O'Connor | e52ad39 | 2013-02-20 23:48:22 -0500 | [diff] [blame] | 177 | load_str_field_with_default(0, vendor_str, BUILD_APPNAME); |
| 178 | load_str_field_with_default(0, bios_version_str, BUILD_APPNAME); |
Kevin O'Connor | 4e4b410 | 2009-10-08 21:21:59 -0400 | [diff] [blame] | 179 | |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 180 | p->bios_starting_address_segment = 0xe800; |
Kevin O'Connor | 4e4b410 | 2009-10-08 21:21:59 -0400 | [diff] [blame] | 181 | |
| 182 | load_str_field_with_default(0, bios_release_date_str, RELEASE_DATE_STR); |
| 183 | |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 184 | p->bios_rom_size = 0; /* FIXME */ |
| 185 | |
Kevin O'Connor | de9e705 | 2013-02-09 19:09:20 -0500 | [diff] [blame] | 186 | if (!get_field(0, offsetof(struct smbios_type_0, bios_characteristics), |
| 187 | &p->bios_characteristics)) { |
Alex Williamson | 17d3e46 | 2010-06-21 09:46:19 -0600 | [diff] [blame] | 188 | memset(p->bios_characteristics, 0, 8); |
| 189 | /* BIOS characteristics not supported */ |
| 190 | p->bios_characteristics[0] = 0x08; |
| 191 | } |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 192 | |
Kevin O'Connor | de9e705 | 2013-02-09 19:09:20 -0500 | [diff] [blame] | 193 | if (!get_field(0, offsetof(struct smbios_type_0, |
| 194 | bios_characteristics_extension_bytes), |
| 195 | &p->bios_characteristics_extension_bytes)) { |
Alex Williamson | 17d3e46 | 2010-06-21 09:46:19 -0600 | [diff] [blame] | 196 | p->bios_characteristics_extension_bytes[0] = 0; |
| 197 | /* Enable targeted content distribution. Needed for SVVP */ |
| 198 | p->bios_characteristics_extension_bytes[1] = 4; |
| 199 | } |
Kevin O'Connor | 4e4b410 | 2009-10-08 21:21:59 -0400 | [diff] [blame] | 200 | |
Alex Williamson | 17d3e46 | 2010-06-21 09:46:19 -0600 | [diff] [blame] | 201 | set_field_with_default(0, system_bios_major_release, 1); |
| 202 | set_field_with_default(0, system_bios_minor_release, 0); |
| 203 | set_field_with_default(0, embedded_controller_major_release, 0xff); |
| 204 | set_field_with_default(0, embedded_controller_minor_release, 0xff); |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 205 | |
Kevin O'Connor | 4e4b410 | 2009-10-08 21:21:59 -0400 | [diff] [blame] | 206 | *end = 0; |
| 207 | end++; |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 208 | |
Kevin O'Connor | 4e4b410 | 2009-10-08 21:21:59 -0400 | [diff] [blame] | 209 | return end; |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | /* Type 1 -- System Information */ |
| 213 | static void * |
Kevin O'Connor | 4e4b410 | 2009-10-08 21:21:59 -0400 | [diff] [blame] | 214 | smbios_init_type_1(void *start) |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 215 | { |
| 216 | struct smbios_type_1 *p = (struct smbios_type_1 *)start; |
Kevin O'Connor | 4e4b410 | 2009-10-08 21:21:59 -0400 | [diff] [blame] | 217 | char *end = (char *)start + sizeof(struct smbios_type_1); |
| 218 | size_t size; |
| 219 | int str_index = 0; |
| 220 | |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 221 | p->header.type = 1; |
| 222 | p->header.length = sizeof(struct smbios_type_1); |
| 223 | p->header.handle = 0x100; |
| 224 | |
Kevin O'Connor | e52ad39 | 2013-02-20 23:48:22 -0500 | [diff] [blame] | 225 | load_str_field_with_default(1, manufacturer_str, BUILD_APPNAME); |
| 226 | load_str_field_with_default(1, product_name_str, BUILD_APPNAME); |
Kevin O'Connor | 4e4b410 | 2009-10-08 21:21:59 -0400 | [diff] [blame] | 227 | load_str_field_or_skip(1, version_str); |
| 228 | load_str_field_or_skip(1, serial_number_str); |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 229 | |
Kevin O'Connor | de9e705 | 2013-02-09 19:09:20 -0500 | [diff] [blame] | 230 | if (!get_field(1, offsetof(struct smbios_type_1, uuid), &p->uuid)) |
Kevin O'Connor | 4e4b410 | 2009-10-08 21:21:59 -0400 | [diff] [blame] | 231 | memset(p->uuid, 0, 16); |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 232 | |
Alex Williamson | 17d3e46 | 2010-06-21 09:46:19 -0600 | [diff] [blame] | 233 | set_field_with_default(1, wake_up_type, 0x06); /* power switch */ |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 234 | |
Kevin O'Connor | 4e4b410 | 2009-10-08 21:21:59 -0400 | [diff] [blame] | 235 | load_str_field_or_skip(1, sku_number_str); |
| 236 | load_str_field_or_skip(1, family_str); |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 237 | |
Kevin O'Connor | 4e4b410 | 2009-10-08 21:21:59 -0400 | [diff] [blame] | 238 | *end = 0; |
| 239 | end++; |
| 240 | if (!str_index) { |
| 241 | *end = 0; |
| 242 | end++; |
| 243 | } |
| 244 | |
| 245 | return end; |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | /* Type 3 -- System Enclosure */ |
| 249 | static void * |
Kevin O'Connor | 4e4b410 | 2009-10-08 21:21:59 -0400 | [diff] [blame] | 250 | smbios_init_type_3(void *start) |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 251 | { |
| 252 | struct smbios_type_3 *p = (struct smbios_type_3 *)start; |
Alex Williamson | 17d3e46 | 2010-06-21 09:46:19 -0600 | [diff] [blame] | 253 | char *end = (char *)start + sizeof(struct smbios_type_3); |
| 254 | size_t size; |
| 255 | int str_index = 0; |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 256 | |
| 257 | p->header.type = 3; |
| 258 | p->header.length = sizeof(struct smbios_type_3); |
| 259 | p->header.handle = 0x300; |
| 260 | |
Kevin O'Connor | e52ad39 | 2013-02-20 23:48:22 -0500 | [diff] [blame] | 261 | load_str_field_with_default(3, manufacturer_str, BUILD_APPNAME); |
Alex Williamson | 17d3e46 | 2010-06-21 09:46:19 -0600 | [diff] [blame] | 262 | set_field_with_default(3, type, 0x01); /* other */ |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 263 | |
Alex Williamson | 17d3e46 | 2010-06-21 09:46:19 -0600 | [diff] [blame] | 264 | load_str_field_or_skip(3, version_str); |
| 265 | load_str_field_or_skip(3, serial_number_str); |
| 266 | load_str_field_or_skip(3, asset_tag_number_str); |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 267 | |
Alex Williamson | 17d3e46 | 2010-06-21 09:46:19 -0600 | [diff] [blame] | 268 | set_field_with_default(3, boot_up_state, 0x03); /* safe */ |
| 269 | set_field_with_default(3, power_supply_state, 0x03); /* safe */ |
| 270 | set_field_with_default(3, thermal_state, 0x03); /* safe */ |
| 271 | set_field_with_default(3, security_status, 0x02); /* unknown */ |
| 272 | |
| 273 | set_field_with_default(3, oem_defined, 0); |
| 274 | set_field_with_default(3, height, 0); |
| 275 | set_field_with_default(3, number_of_power_cords, 0); |
| 276 | set_field_with_default(3, contained_element_count, 0); |
| 277 | |
| 278 | *end = 0; |
| 279 | end++; |
| 280 | if (!str_index) { |
| 281 | *end = 0; |
| 282 | end++; |
| 283 | } |
| 284 | |
| 285 | return end; |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | /* Type 4 -- Processor Information */ |
| 289 | static void * |
Kevin O'Connor | 4e4b410 | 2009-10-08 21:21:59 -0400 | [diff] [blame] | 290 | smbios_init_type_4(void *start, unsigned int cpu_number) |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 291 | { |
| 292 | struct smbios_type_4 *p = (struct smbios_type_4 *)start; |
Alex Williamson | 17d3e46 | 2010-06-21 09:46:19 -0600 | [diff] [blame] | 293 | char *end = (char *)start + sizeof(struct smbios_type_4); |
| 294 | size_t size; |
| 295 | int str_index = 0; |
| 296 | char name[1024]; |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 297 | |
| 298 | p->header.type = 4; |
| 299 | p->header.length = sizeof(struct smbios_type_4); |
| 300 | p->header.handle = 0x400 + cpu_number; |
| 301 | |
Kevin O'Connor | de9e705 | 2013-02-09 19:09:20 -0500 | [diff] [blame] | 302 | size = get_field(4, offsetof(struct smbios_type_4, socket_designation_str), |
| 303 | name); |
Alex Williamson | 17d3e46 | 2010-06-21 09:46:19 -0600 | [diff] [blame] | 304 | if (size) |
| 305 | snprintf(name + size - 1, sizeof(name) - size, "%2x", cpu_number); |
| 306 | else |
| 307 | snprintf(name, sizeof(name), "CPU%2x", cpu_number); |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 308 | |
Alex Williamson | 17d3e46 | 2010-06-21 09:46:19 -0600 | [diff] [blame] | 309 | memcpy(end, name, strlen(name) + 1); |
| 310 | end += strlen(name) + 1; |
| 311 | p->socket_designation_str = ++str_index; |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 312 | |
Alex Williamson | 17d3e46 | 2010-06-21 09:46:19 -0600 | [diff] [blame] | 313 | set_field_with_default(4, processor_type, 0x03); /* CPU */ |
| 314 | set_field_with_default(4, processor_family, 0x01); /* other */ |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 315 | |
Kevin O'Connor | e52ad39 | 2013-02-20 23:48:22 -0500 | [diff] [blame] | 316 | load_str_field_with_default(4, processor_manufacturer_str, BUILD_APPNAME); |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 317 | |
Kevin O'Connor | de9e705 | 2013-02-09 19:09:20 -0500 | [diff] [blame] | 318 | if (!get_field(4, offsetof(struct smbios_type_4, processor_id) |
| 319 | , p->processor_id)) { |
Alex Williamson | 17d3e46 | 2010-06-21 09:46:19 -0600 | [diff] [blame] | 320 | u32 cpuid_signature, ebx, ecx, cpuid_features; |
| 321 | cpuid(1, &cpuid_signature, &ebx, &ecx, &cpuid_features); |
| 322 | p->processor_id[0] = cpuid_signature; |
| 323 | p->processor_id[1] = cpuid_features; |
| 324 | } |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 325 | |
Alex Williamson | 17d3e46 | 2010-06-21 09:46:19 -0600 | [diff] [blame] | 326 | load_str_field_or_skip(4, processor_version_str); |
| 327 | set_field_with_default(4, voltage, 0); |
| 328 | set_field_with_default(4, external_clock, 0); |
Kevin O'Connor | f2ce191 | 2008-10-25 15:23:53 -0400 | [diff] [blame] | 329 | |
Alex Williamson | 17d3e46 | 2010-06-21 09:46:19 -0600 | [diff] [blame] | 330 | set_field_with_default(4, max_speed, 2000); |
| 331 | set_field_with_default(4, current_speed, 2000); |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 332 | |
Alex Williamson | 17d3e46 | 2010-06-21 09:46:19 -0600 | [diff] [blame] | 333 | set_field_with_default(4, status, 0x41); /* socket populated, CPU enabled */ |
| 334 | set_field_with_default(4, processor_upgrade, 0x01); /* other */ |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 335 | |
Alex Williamson | 17d3e46 | 2010-06-21 09:46:19 -0600 | [diff] [blame] | 336 | /* cache information structure not provided */ |
| 337 | p->l1_cache_handle = 0xffff; |
| 338 | p->l2_cache_handle = 0xffff; |
| 339 | p->l3_cache_handle = 0xffff; |
| 340 | |
| 341 | *end = 0; |
| 342 | end++; |
| 343 | if (!str_index) { |
| 344 | *end = 0; |
| 345 | end++; |
| 346 | } |
| 347 | |
| 348 | return end; |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | /* Type 16 -- Physical Memory Array */ |
| 352 | static void * |
Kevin O'Connor | 4e4b410 | 2009-10-08 21:21:59 -0400 | [diff] [blame] | 353 | smbios_init_type_16(void *start, u32 memory_size_mb, int nr_mem_devs) |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 354 | { |
| 355 | struct smbios_type_16 *p = (struct smbios_type_16*)start; |
| 356 | |
| 357 | p->header.type = 16; |
| 358 | p->header.length = sizeof(struct smbios_type_16); |
| 359 | p->header.handle = 0x1000; |
| 360 | |
Alex Williamson | 17d3e46 | 2010-06-21 09:46:19 -0600 | [diff] [blame] | 361 | set_field_with_default(16, location, 0x01); /* other */ |
| 362 | set_field_with_default(16, use, 0x03); /* system memory */ |
| 363 | /* Multi-bit ECC to make Microsoft happy */ |
| 364 | set_field_with_default(16, error_correction, 0x06); |
Alex Williamson | 6d66316 | 2010-05-07 13:38:55 -0600 | [diff] [blame] | 365 | /* 0x80000000 = unknown, accept sizes < 2TB - TODO multiple arrays */ |
| 366 | p->maximum_capacity = memory_size_mb < 2 << 20 ? |
| 367 | memory_size_mb << 10 : 0x80000000; |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 368 | p->memory_error_information_handle = 0xfffe; /* none provided */ |
Kevin O'Connor | 2a3dfea | 2009-10-07 19:44:23 -0400 | [diff] [blame] | 369 | p->number_of_memory_devices = nr_mem_devs; |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 370 | |
| 371 | start += sizeof(struct smbios_type_16); |
Kevin O'Connor | e51313d | 2008-03-12 21:19:34 -0400 | [diff] [blame] | 372 | *((u16 *)start) = 0; |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 373 | |
| 374 | return start + 2; |
| 375 | } |
| 376 | |
| 377 | /* Type 17 -- Memory Device */ |
| 378 | static void * |
Alex Williamson | 6d66316 | 2010-05-07 13:38:55 -0600 | [diff] [blame] | 379 | smbios_init_type_17(void *start, u32 size_mb, int instance) |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 380 | { |
| 381 | struct smbios_type_17 *p = (struct smbios_type_17 *)start; |
Alex Williamson | 17d3e46 | 2010-06-21 09:46:19 -0600 | [diff] [blame] | 382 | char *end = (char *)start + sizeof(struct smbios_type_17); |
| 383 | size_t size; |
| 384 | int str_index = 0; |
| 385 | char name[1024]; |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 386 | |
| 387 | p->header.type = 17; |
| 388 | p->header.length = sizeof(struct smbios_type_17); |
Kevin O'Connor | 2a3dfea | 2009-10-07 19:44:23 -0400 | [diff] [blame] | 389 | p->header.handle = 0x1100 + instance; |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 390 | |
| 391 | p->physical_memory_array_handle = 0x1000; |
Alex Williamson | 17d3e46 | 2010-06-21 09:46:19 -0600 | [diff] [blame] | 392 | set_field_with_default(17, total_width, 64); |
| 393 | set_field_with_default(17, data_width, 64); |
Kevin O'Connor | 2a3dfea | 2009-10-07 19:44:23 -0400 | [diff] [blame] | 394 | /* TODO: should assert in case something is wrong ASSERT((memory_size_mb & ~0x7fff) == 0); */ |
Alex Williamson | 6d66316 | 2010-05-07 13:38:55 -0600 | [diff] [blame] | 395 | p->size = size_mb; |
Alex Williamson | 17d3e46 | 2010-06-21 09:46:19 -0600 | [diff] [blame] | 396 | set_field_with_default(17, form_factor, 0x09); /* DIMM */ |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 397 | p->device_set = 0; |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 398 | |
Kevin O'Connor | de9e705 | 2013-02-09 19:09:20 -0500 | [diff] [blame] | 399 | size = get_field(17, offsetof(struct smbios_type_17, device_locator_str), |
| 400 | name); |
Alex Williamson | 17d3e46 | 2010-06-21 09:46:19 -0600 | [diff] [blame] | 401 | if (size) |
| 402 | snprintf(name + size - 1, sizeof(name) - size, "%d", instance); |
| 403 | else |
| 404 | snprintf(name, sizeof(name), "DIMM %d", instance); |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 405 | |
Alex Williamson | 17d3e46 | 2010-06-21 09:46:19 -0600 | [diff] [blame] | 406 | memcpy(end, name, strlen(name) + 1); |
| 407 | end += strlen(name) + 1; |
| 408 | p->device_locator_str = ++str_index; |
| 409 | |
| 410 | load_str_field_or_skip(17, bank_locator_str); |
| 411 | set_field_with_default(17, memory_type, 0x07); /* RAM */ |
| 412 | set_field_with_default(17, type_detail, 0); |
| 413 | |
| 414 | *end = 0; |
| 415 | end++; |
| 416 | if (!str_index) { |
| 417 | *end = 0; |
| 418 | end++; |
| 419 | } |
| 420 | |
| 421 | return end; |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | /* Type 19 -- Memory Array Mapped Address */ |
| 425 | static void * |
Alex Williamson | 6d66316 | 2010-05-07 13:38:55 -0600 | [diff] [blame] | 426 | smbios_init_type_19(void *start, u32 start_mb, u32 size_mb, int instance) |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 427 | { |
| 428 | struct smbios_type_19 *p = (struct smbios_type_19 *)start; |
| 429 | |
| 430 | p->header.type = 19; |
| 431 | p->header.length = sizeof(struct smbios_type_19); |
Kevin O'Connor | 2a3dfea | 2009-10-07 19:44:23 -0400 | [diff] [blame] | 432 | p->header.handle = 0x1300 + instance; |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 433 | |
Alex Williamson | 6d66316 | 2010-05-07 13:38:55 -0600 | [diff] [blame] | 434 | p->starting_address = start_mb << 10; |
| 435 | p->ending_address = p->starting_address + (size_mb << 10) - 1; |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 436 | p->memory_array_handle = 0x1000; |
| 437 | p->partition_width = 1; |
| 438 | |
| 439 | start += sizeof(struct smbios_type_19); |
Kevin O'Connor | e51313d | 2008-03-12 21:19:34 -0400 | [diff] [blame] | 440 | *((u16 *)start) = 0; |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 441 | |
| 442 | return start + 2; |
| 443 | } |
| 444 | |
| 445 | /* Type 20 -- Memory Device Mapped Address */ |
| 446 | static void * |
Alex Williamson | 6d66316 | 2010-05-07 13:38:55 -0600 | [diff] [blame] | 447 | smbios_init_type_20(void *start, u32 start_mb, u32 size_mb, int instance, |
| 448 | int dev_handle, int array_handle) |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 449 | { |
| 450 | struct smbios_type_20 *p = (struct smbios_type_20 *)start; |
| 451 | |
| 452 | p->header.type = 20; |
| 453 | p->header.length = sizeof(struct smbios_type_20); |
Kevin O'Connor | 2a3dfea | 2009-10-07 19:44:23 -0400 | [diff] [blame] | 454 | p->header.handle = 0x1400 + instance; |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 455 | |
Alex Williamson | 6d66316 | 2010-05-07 13:38:55 -0600 | [diff] [blame] | 456 | p->starting_address = start_mb << 10; |
| 457 | p->ending_address = p->starting_address + (size_mb << 10) - 1; |
| 458 | p->memory_device_handle = 0x1100 + dev_handle; |
| 459 | p->memory_array_mapped_address_handle = 0x1300 + array_handle; |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 460 | p->partition_row_position = 1; |
| 461 | p->interleave_position = 0; |
| 462 | p->interleaved_data_depth = 0; |
| 463 | |
| 464 | start += sizeof(struct smbios_type_20); |
| 465 | |
Kevin O'Connor | e51313d | 2008-03-12 21:19:34 -0400 | [diff] [blame] | 466 | *((u16 *)start) = 0; |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 467 | return start+2; |
| 468 | } |
| 469 | |
| 470 | /* Type 32 -- System Boot Information */ |
| 471 | static void * |
Kevin O'Connor | 4e4b410 | 2009-10-08 21:21:59 -0400 | [diff] [blame] | 472 | smbios_init_type_32(void *start) |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 473 | { |
| 474 | struct smbios_type_32 *p = (struct smbios_type_32 *)start; |
| 475 | |
| 476 | p->header.type = 32; |
| 477 | p->header.length = sizeof(struct smbios_type_32); |
| 478 | p->header.handle = 0x2000; |
| 479 | memset(p->reserved, 0, 6); |
Alex Williamson | 17d3e46 | 2010-06-21 09:46:19 -0600 | [diff] [blame] | 480 | set_field_with_default(32, boot_status, 0); /* no errors detected */ |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 481 | |
| 482 | start += sizeof(struct smbios_type_32); |
Kevin O'Connor | e51313d | 2008-03-12 21:19:34 -0400 | [diff] [blame] | 483 | *((u16 *)start) = 0; |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 484 | |
| 485 | return start+2; |
| 486 | } |
| 487 | |
| 488 | /* Type 127 -- End of Table */ |
| 489 | static void * |
Kevin O'Connor | 4e4b410 | 2009-10-08 21:21:59 -0400 | [diff] [blame] | 490 | smbios_init_type_127(void *start) |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 491 | { |
| 492 | struct smbios_type_127 *p = (struct smbios_type_127 *)start; |
| 493 | |
| 494 | p->header.type = 127; |
| 495 | p->header.length = sizeof(struct smbios_type_127); |
| 496 | p->header.handle = 0x7f00; |
| 497 | |
| 498 | start += sizeof(struct smbios_type_127); |
Kevin O'Connor | e51313d | 2008-03-12 21:19:34 -0400 | [diff] [blame] | 499 | *((u16 *)start) = 0; |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 500 | |
| 501 | return start + 2; |
| 502 | } |
| 503 | |
Kevin O'Connor | fe2c3ee | 2009-12-26 23:26:44 -0500 | [diff] [blame] | 504 | #define TEMPSMBIOSSIZE (32 * 1024) |
| 505 | |
Kevin O'Connor | 0525d29 | 2008-07-04 06:18:30 -0400 | [diff] [blame] | 506 | void |
Gabriel L. Somlo | d85c22e | 2014-04-23 15:04:49 -0400 | [diff] [blame] | 507 | smbios_legacy_setup(void) |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 508 | { |
Kevin O'Connor | 6cb8ba9 | 2008-08-17 11:03:24 -0400 | [diff] [blame] | 509 | if (! CONFIG_SMBIOS) |
| 510 | return; |
| 511 | |
Kevin O'Connor | 7b49cd9 | 2008-11-08 10:35:26 -0500 | [diff] [blame] | 512 | dprintf(3, "init SMBIOS tables\n"); |
| 513 | |
Kevin O'Connor | fe2c3ee | 2009-12-26 23:26:44 -0500 | [diff] [blame] | 514 | char *start = malloc_tmphigh(TEMPSMBIOSSIZE); |
Kevin O'Connor | 2929c35 | 2009-07-25 13:48:27 -0400 | [diff] [blame] | 515 | if (! start) { |
Kevin O'Connor | cfdc13f | 2010-02-14 13:07:54 -0500 | [diff] [blame] | 516 | warn_noalloc(); |
Kevin O'Connor | 2929c35 | 2009-07-25 13:48:27 -0400 | [diff] [blame] | 517 | return; |
| 518 | } |
Kevin O'Connor | 9b9c240 | 2014-03-11 11:46:42 -0400 | [diff] [blame] | 519 | memset(start, 0, TEMPSMBIOSSIZE); |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 520 | |
Kevin O'Connor | 2929c35 | 2009-07-25 13:48:27 -0400 | [diff] [blame] | 521 | u32 nr_structs = 0, max_struct_size = 0; |
Kevin O'Connor | fe2c3ee | 2009-12-26 23:26:44 -0500 | [diff] [blame] | 522 | char *q, *p = start; |
| 523 | char *end = start + TEMPSMBIOSSIZE - sizeof(struct smbios_type_127); |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 524 | |
Kevin O'Connor | 4e4b410 | 2009-10-08 21:21:59 -0400 | [diff] [blame] | 525 | #define add_struct(type, args...) \ |
| 526 | do { \ |
Kevin O'Connor | de9e705 | 2013-02-09 19:09:20 -0500 | [diff] [blame] | 527 | if (!get_external(type, &p, &nr_structs, &max_struct_size, end)) { \ |
Kevin O'Connor | 4e4b410 | 2009-10-08 21:21:59 -0400 | [diff] [blame] | 528 | q = smbios_init_type_##type(args); \ |
| 529 | nr_structs++; \ |
| 530 | if ((q - p) > max_struct_size) \ |
| 531 | max_struct_size = q - p; \ |
| 532 | p = q; \ |
| 533 | } \ |
| 534 | } while (0) |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 535 | |
Kevin O'Connor | 4e4b410 | 2009-10-08 21:21:59 -0400 | [diff] [blame] | 536 | add_struct(0, p); |
| 537 | add_struct(1, p); |
| 538 | add_struct(3, p); |
| 539 | |
Kevin O'Connor | a26df9b | 2009-10-09 09:42:11 -0400 | [diff] [blame] | 540 | int cpu_num; |
| 541 | for (cpu_num = 1; cpu_num <= MaxCountCPUs; cpu_num++) |
Kevin O'Connor | 4e4b410 | 2009-10-08 21:21:59 -0400 | [diff] [blame] | 542 | add_struct(4, p, cpu_num); |
Alex Williamson | 6d66316 | 2010-05-07 13:38:55 -0600 | [diff] [blame] | 543 | |
| 544 | int ram_mb = (RamSize + RamSizeOver4G) >> 20; |
| 545 | int nr_mem_devs = (ram_mb + 0x3fff) >> 14; |
| 546 | add_struct(16, p, ram_mb, nr_mem_devs); |
| 547 | |
| 548 | int i, j; |
Kevin O'Connor | 2a3dfea | 2009-10-07 19:44:23 -0400 | [diff] [blame] | 549 | for (i = 0; i < nr_mem_devs; i++) { |
Alex Williamson | 6d66316 | 2010-05-07 13:38:55 -0600 | [diff] [blame] | 550 | u32 dev_mb = ((i == (nr_mem_devs - 1)) |
| 551 | ? (((ram_mb - 1) & 0x3fff) + 1) |
| 552 | : 16384); |
| 553 | add_struct(17, p, dev_mb, i); |
| 554 | } |
Kevin O'Connor | 7d09d0e | 2010-05-10 21:51:38 -0400 | [diff] [blame] | 555 | |
Alex Williamson | 6d66316 | 2010-05-07 13:38:55 -0600 | [diff] [blame] | 556 | add_struct(19, p, 0, RamSize >> 20, 0); |
| 557 | if (RamSizeOver4G) |
| 558 | add_struct(19, p, 4096, RamSizeOver4G >> 20, 1); |
| 559 | |
| 560 | add_struct(20, p, 0, RamSize >> 20, 0, 0, 0); |
| 561 | if (RamSizeOver4G) { |
| 562 | u32 start_mb = 4096; |
| 563 | for (j = 1, i = 0; i < nr_mem_devs; i++, j++) { |
| 564 | u32 dev_mb = ((i == (nr_mem_devs - 1)) |
| 565 | ? (((ram_mb - 1) & 0x3fff) + 1) |
| 566 | : 16384); |
| 567 | if (i == 0) |
| 568 | dev_mb -= RamSize >> 20; |
| 569 | |
| 570 | add_struct(20, p, start_mb, dev_mb, j, i, 1); |
| 571 | start_mb += dev_mb; |
| 572 | } |
Kevin O'Connor | 2a3dfea | 2009-10-07 19:44:23 -0400 | [diff] [blame] | 573 | } |
Kevin O'Connor | 4e4b410 | 2009-10-08 21:21:59 -0400 | [diff] [blame] | 574 | |
| 575 | add_struct(32, p); |
| 576 | /* Add any remaining provided entries before the end marker */ |
| 577 | for (i = 0; i < 256; i++) |
Kevin O'Connor | de9e705 | 2013-02-09 19:09:20 -0500 | [diff] [blame] | 578 | get_external(i, &p, &nr_structs, &max_struct_size, end); |
Kevin O'Connor | 4e4b410 | 2009-10-08 21:21:59 -0400 | [diff] [blame] | 579 | add_struct(127, p); |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 580 | |
| 581 | #undef add_struct |
| 582 | |
Kevin O'Connor | d83c87b | 2013-01-21 01:14:12 -0500 | [diff] [blame] | 583 | smbios_entry_point_setup(max_struct_size, p - start, start, nr_structs); |
Kevin O'Connor | fe2c3ee | 2009-12-26 23:26:44 -0500 | [diff] [blame] | 584 | free(start); |
Kevin O'Connor | a4d3576 | 2008-03-08 15:43:03 -0500 | [diff] [blame] | 585 | } |