From patchwork Mon Mar 23 19:11:07 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 13812 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n2NJC7sU028021 for ; Mon, 23 Mar 2009 19:12:08 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758945AbZCWTLe (ORCPT ); Mon, 23 Mar 2009 15:11:34 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1757660AbZCWTLe (ORCPT ); Mon, 23 Mar 2009 15:11:34 -0400 Received: from g5t0008.atlanta.hp.com ([15.192.0.45]:22263 "EHLO g5t0008.atlanta.hp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758631AbZCWTLd (ORCPT ); Mon, 23 Mar 2009 15:11:33 -0400 Received: from g5t0030.atlanta.hp.com (g5t0030.atlanta.hp.com [16.228.8.142]) by g5t0008.atlanta.hp.com (Postfix) with ESMTP id BE1B12400D; Mon, 23 Mar 2009 19:11:31 +0000 (UTC) Received: from ldl.fc.hp.com (ldl.fc.hp.com [15.11.146.30]) by g5t0030.atlanta.hp.com (Postfix) with ESMTP id 4FAB324065; Mon, 23 Mar 2009 19:11:21 +0000 (UTC) Received: from localhost (ldl.fc.hp.com [127.0.0.1]) by ldl.fc.hp.com (Postfix) with ESMTP id CFC3F39C071; Mon, 23 Mar 2009 13:11:20 -0600 (MDT) X-Virus-Scanned: Debian amavisd-new at ldl.fc.hp.com Received: from ldl.fc.hp.com ([127.0.0.1]) by localhost (ldl.fc.hp.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xpYJov6zhuBg; Mon, 23 Mar 2009 13:11:18 -0600 (MDT) Received: from [10.91.73.10] (lart.fc.hp.com [15.11.146.31]) by ldl.fc.hp.com (Postfix) with ESMTP id A23F139C070; Mon, 23 Mar 2009 13:11:17 -0600 (MDT) Subject: [PATCH 2/2] qemu:bios: Read external SMBIOS entries from the VM From: Alex Williamson To: qemu-devel Cc: kvm , Alex Williamson In-Reply-To: <1237835133.7276.1107.camel@lappy> References: <1237835133.7276.1107.camel@lappy> Organization: OSLO R&D Date: Mon, 23 Mar 2009 13:11:07 -0600 Message-Id: <1237835467.15558.5.camel@lappy> Mime-Version: 1.0 X-Mailer: Evolution 2.24.3 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org SMBIOS entries can be read from the VM using the same mechanism as additional ACPI tables. External entries will supercede generated entries. Signed-off-by: Alex Williamson --- -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/bios/rombios32.c b/bios/rombios32.c index 7be4216..f0e0f8c 100644 --- a/bios/rombios32.c +++ b/bios/rombios32.c @@ -471,6 +471,7 @@ void wrmsr_smp(uint32_t index, uint64_t val) #define QEMU_CFG_UUID 0x02 #define QEMU_CFG_ARCH_LOCAL 0x8000 #define QEMU_CFG_ACPI_TABLES (QEMU_CFG_ARCH_LOCAL + 0) +#define QEMU_CFG_SMBIOS_ENTRIES (QEMU_CFG_ARCH_LOCAL + 1) int qemu_cfg_port; @@ -519,6 +520,16 @@ static int acpi_load_table(int i, uint32_t addr, uint16_t *len) qemu_cfg_read((uint8_t*)addr, *len); return 0; } + +static uint16_t smbios_entries(void) +{ + uint16_t cnt; + + qemu_cfg_select(QEMU_CFG_SMBIOS_ENTRIES); + qemu_cfg_read((uint8_t*)&cnt, sizeof(cnt)); + + return cnt; +} #endif void uuid_probe(void) @@ -1966,7 +1977,7 @@ smbios_entry_point_init(void *start, /* Type 0 -- BIOS Information */ #define RELEASE_DATE_STR "01/01/2007" static void * -smbios_type_0_init(void *start) +smbios_init_type_0(void *start) { struct smbios_type_0 *p = (struct smbios_type_0 *)start; @@ -2002,7 +2013,7 @@ smbios_type_0_init(void *start) /* Type 1 -- System Information */ static void * -smbios_type_1_init(void *start) +smbios_init_type_1(void *start) { struct smbios_type_1 *p = (struct smbios_type_1 *)start; p->header.type = 1; @@ -2028,7 +2039,7 @@ smbios_type_1_init(void *start) /* Type 3 -- System Enclosure */ static void * -smbios_type_3_init(void *start) +smbios_init_type_3(void *start) { struct smbios_type_3 *p = (struct smbios_type_3 *)start; @@ -2058,7 +2069,7 @@ smbios_type_3_init(void *start) /* Type 4 -- Processor Information */ static void * -smbios_type_4_init(void *start, unsigned int cpu_number) +smbios_init_type_4(void *start, unsigned int cpu_number) { struct smbios_type_4 *p = (struct smbios_type_4 *)start; @@ -2098,7 +2109,7 @@ smbios_type_4_init(void *start, unsigned int cpu_number) /* Type 16 -- Physical Memory Array */ static void * -smbios_type_16_init(void *start, uint32_t memsize, int nr_mem_devs) +smbios_init_type_16(void *start, uint32_t memsize, int nr_mem_devs) { struct smbios_type_16 *p = (struct smbios_type_16*)start; @@ -2121,7 +2132,7 @@ smbios_type_16_init(void *start, uint32_t memsize, int nr_mem_devs) /* Type 17 -- Memory Device */ static void * -smbios_type_17_init(void *start, uint32_t memory_size_mb, int instance) +smbios_init_type_17(void *start, uint32_t memory_size_mb, int instance) { struct smbios_type_17 *p = (struct smbios_type_17 *)start; @@ -2151,7 +2162,7 @@ smbios_type_17_init(void *start, uint32_t memory_size_mb, int instance) /* Type 19 -- Memory Array Mapped Address */ static void * -smbios_type_19_init(void *start, uint32_t memory_size_mb, int instance) +smbios_init_type_19(void *start, uint32_t memory_size_mb, int instance) { struct smbios_type_19 *p = (struct smbios_type_19 *)start; @@ -2172,7 +2183,7 @@ smbios_type_19_init(void *start, uint32_t memory_size_mb, int instance) /* Type 20 -- Memory Device Mapped Address */ static void * -smbios_type_20_init(void *start, uint32_t memory_size_mb, int instance) +smbios_init_type_20(void *start, uint32_t memory_size_mb, int instance) { struct smbios_type_20 *p = (struct smbios_type_20 *)start; @@ -2196,7 +2207,7 @@ smbios_type_20_init(void *start, uint32_t memory_size_mb, int instance) /* Type 32 -- System Boot Information */ static void * -smbios_type_32_init(void *start) +smbios_init_type_32(void *start) { struct smbios_type_32 *p = (struct smbios_type_32 *)start; @@ -2214,7 +2225,7 @@ smbios_type_32_init(void *start) /* Type 127 -- End of Table */ static void * -smbios_type_127_init(void *start) +smbios_init_type_127(void *start) { struct smbios_type_127 *p = (struct smbios_type_127 *)start; @@ -2228,6 +2239,91 @@ smbios_type_127_init(void *start) return start + 2; } +static int +smbios_load_external(int type, char **p, char **q, unsigned *nr_structs, + unsigned *max_struct_size) +{ +#ifdef BX_QEMU + static uint64_t used_bitmap[4] = { 0 }; + static uint16_t used_cnt = 0; + char *start = *p; + uint16_t len; + int i; + + /* Keep track of the entry types we've already processed */ + if (used_bitmap[(type >> 6) & 0x3] & (1ULL << (type & 0x3f))) + return 1; + + /* Skip end markers, they could lead to bogus tables */ + if (type == 127) + return 0; + + /* Check if there are any tables left to report, also reset read index */ + i = smbios_entries(); + if (used_cnt == i) + return 0; + + for (; i > 0; *q = *p, i--) { + int string_data; + qemu_cfg_read((uint8_t*)&len, sizeof(len)); + if (!len) + continue; + if (len < sizeof(struct smbios_structure_header)) { + while (len--) + inb(QEMU_CFG_DATA_PORT); /* Invalid, skip to the next one */ + continue; + } + + qemu_cfg_read((uint8_t*)*p, sizeof(struct smbios_structure_header)); + if (((struct smbios_structure_header *)*p)->type != type) { + len -= sizeof(struct smbios_structure_header); + while (len--) + inb(QEMU_CFG_DATA_PORT); /* skip to the next one */ + continue; + } + + /* Entries end with a double NULL char, if there's a string at + * the end (length is greater than formatted length), the string + * terminator provides the first NULL. */ + string_data = (len > ((struct smbios_structure_header *)*p)->length); + + /* Read the rest and terminate the entry */ + len -= sizeof(struct smbios_structure_header); + *p += sizeof(struct smbios_structure_header); + qemu_cfg_read((uint8_t*)*p, len); + *p += len; + *((uint8_t*)*p) = 0; + (*p)++; + if (!string_data) { + *((uint8_t*)*p) = 0; + (*p)++; + } + + (*nr_structs)++; + used_cnt++; + if (*p - *q > *max_struct_size) + *max_struct_size = *p - *q; + + /* Mark that we've reported on this type */ + used_bitmap[(type >> 6) & 0x3] |= (1ULL << (type & 0x3f)); + + /* A type 1 entry provides a UUID, but so does the QEMU_CFG_UUID + * port. If the QEMU_CFG_UUID value is not zero, use it, otherwise + * use whatever was in the provided table. */ + if (type == 1) { + const static uint8_t null_uuid[16] = { 0 }; + if (memcmp(bios_uuid, null_uuid, 16)) { + struct smbios_type_1 *t = (struct smbios_type_1 *)*q; + memcpy(t->uuid, bios_uuid, 16); + } + } + } + return (start != *p); +#else /* !BX_QEMU */ + return 0; +#endif +} + void smbios_init(void) { unsigned cpu_num, nr_structs = 0, max_struct_size = 0; @@ -2246,34 +2342,39 @@ void smbios_init(void) p = (char *)start + sizeof(struct smbios_entry_point); -#define add_struct(fn) do{ \ - q = (fn); \ - nr_structs++; \ - if ((q - p) > max_struct_size) \ - max_struct_size = q - p; \ - p = q; \ +#define add_struct(type, args...) do{ \ + if (!smbios_load_external(type, &p, &q, &nr_structs, &max_struct_size)) { \ + q = smbios_init_type_##type(args); \ + nr_structs++; \ + if ((q - p) > max_struct_size) \ + max_struct_size = q - p; \ + p = q; \ + } \ }while (0) - add_struct(smbios_type_0_init(p)); - add_struct(smbios_type_1_init(p)); - add_struct(smbios_type_3_init(p)); + add_struct(0, p); + add_struct(1, p); + add_struct(3, p); for (cpu_num = 1; cpu_num <= smp_cpus; cpu_num++) - add_struct(smbios_type_4_init(p, cpu_num)); + add_struct(4, p, cpu_num); /* Each 'memory device' covers up to 16GB of address space. */ nr_mem_devs = (memsize + 0x3fff) >> 14; - add_struct(smbios_type_16_init(p, memsize, nr_mem_devs)); + add_struct(16, p, memsize, nr_mem_devs); for ( i = 0; i < nr_mem_devs; i++ ) { uint32_t dev_memsize = ((i == (nr_mem_devs - 1)) ? (((memsize-1) & 0x3fff)+1) : 0x4000); - add_struct(smbios_type_17_init(p, dev_memsize, i)); - add_struct(smbios_type_19_init(p, dev_memsize, i)); - add_struct(smbios_type_20_init(p, dev_memsize, i)); + add_struct(17, p, dev_memsize, i); + add_struct(19, p, dev_memsize, i); + add_struct(20, p, dev_memsize, i); } - add_struct(smbios_type_32_init(p)); - add_struct(smbios_type_127_init(p)); + add_struct(32, p); + /* Add any remaining provided entries before the end marker */ + for (i = 0; i < 256; i++) + smbios_load_external(i, &p, &q, &nr_structs, &max_struct_size); + add_struct(127, p); #undef add_struct