From patchwork Mon Mar 10 16:58:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gabriel L. Somlo" X-Patchwork-Id: 328636 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id D684E2C0089 for ; Tue, 11 Mar 2014 04:06:52 +1100 (EST) Received: from localhost ([::1]:50157 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WN3cm-0005Ea-Ol for incoming@patchwork.ozlabs.org; Mon, 10 Mar 2014 13:04:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53463) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WN3aU-0000X6-2C for qemu-devel@nongnu.org; Mon, 10 Mar 2014 13:02:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WN3aO-0002UK-Gm for qemu-devel@nongnu.org; Mon, 10 Mar 2014 13:02:02 -0400 Received: from mail-qc0-x22a.google.com ([2607:f8b0:400d:c01::22a]:61531) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WN3aO-0002UA-An for qemu-devel@nongnu.org; Mon, 10 Mar 2014 13:01:56 -0400 Received: by mail-qc0-f170.google.com with SMTP id e9so8059624qcy.15 for ; Mon, 10 Mar 2014 10:01:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:mime-version:content-type :content-disposition:user-agent; bh=DIUFHLtf7h8s12awMeuXebM6jIkuGvyoA3IHZMDdVQg=; b=AVO89Nnk7Bu1cjX2JLSTB1SbxHlItZY1JqlZE+t+DlzfbjhIULiLksrwNy9LoMOofX HaDuOd7A5WcvJLv/CpnBATl5cisjVQ+1byAicu1+QhBfcedJtAB60tsyYqXDOs6B/SDJ XUqg64Dlzuuomw1aa3owB6PFOm3zO//pyTliLeMqszd7E8+6SDJC6j+RopX5FMcCpNzY NobgSeJUYDJut9Pv7QiiAUJRPYLXRzfdj9URIehLxl9EDiTBKzMIKR4LgOffC64VKFtU 1cspQgrejRi3nj0tQba1L6sxeoVHrHiwrzvmiXPfQ3T9U7ic9eS+xagNvuZ9vs7uqmeJ khfw== X-Received: by 10.140.20.17 with SMTP id 17mr40442346qgi.28.1394470915654; Mon, 10 Mar 2014 10:01:55 -0700 (PDT) Received: from ERROL.INI.CMU.EDU (ERROL.INI.CMU.EDU. [128.2.16.43]) by mx.google.com with ESMTPSA id m74sm24572314qgd.14.2014.03.10.10.01.54 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 10 Mar 2014 10:01:55 -0700 (PDT) Date: Mon, 10 Mar 2014 12:58:48 -0400 From: "Gabriel L. Somlo" To: qemu-devel@nongnu.org Message-ID: <20140310165847.GP17184@ERROL.INI.CMU.EDU> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400d:c01::22a Cc: agraf@suse.de, armbru@redhat.com, alex.williamson@redhat.com, kevin@koconnor.net, kraxel@redhat.com, lersek@redhat.com Subject: [Qemu-devel] [PATCH 8/10] SMBIOS: Build full type 3 table X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Build smbios type 3 (system enclosure) table, and make it available to the bios via fw_cfg. Signed-off-by: Gabriel Somlo --- hw/i386/smbios.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/hw/i386/smbios.c b/hw/i386/smbios.c index 54ad3e7..eaf5bcc 100644 --- a/hw/i386/smbios.c +++ b/hw/i386/smbios.c @@ -61,6 +61,10 @@ static struct { const char *manufacturer, *product, *version, *serial, *asset, *location; } type2; +static struct { + const char *manufacturer, *version, *serial, *asset; +} type3; + static QemuOptsList qemu_smbios_opts = { .name = "smbios", .head = QTAILQ_HEAD_INITIALIZER(qemu_smbios_opts.head), @@ -177,6 +181,31 @@ static const QemuOptDesc qemu_smbios_type2_opts[] = { { /* end of list */ } }; +static const QemuOptDesc qemu_smbios_type3_opts[] = { + { + .name = "type", + .type = QEMU_OPT_NUMBER, + .help = "SMBIOS element type", + },{ + .name = "manufacturer", + .type = QEMU_OPT_STRING, + .help = "manufacturer name", + },{ + .name = "version", + .type = QEMU_OPT_STRING, + .help = "version number", + },{ + .name = "serial", + .type = QEMU_OPT_STRING, + .help = "serial number", + },{ + .name = "asset", + .type = QEMU_OPT_STRING, + .help = "asset tag number", + }, + { /* end of list */ } +}; + static void smbios_register_config(void) { qemu_add_opts(&qemu_smbios_opts); @@ -350,6 +379,27 @@ static void smbios_build_type_2_table(void) SMBIOS_BUILD_TABLE_POST; } +static void smbios_build_type_3_table(void) +{ + SMBIOS_BUILD_TABLE_PRE(3, 0x300, true); /* required */ + + SMBIOS_TABLE_SET_STR(3, manufacturer_str, type3.manufacturer); + t->type = 0x01; /* Other */ + SMBIOS_TABLE_SET_STR(3, version_str, type3.version); + SMBIOS_TABLE_SET_STR(3, serial_number_str, type3.serial); + SMBIOS_TABLE_SET_STR(3, asset_tag_number_str, type3.asset); + t->boot_up_state = 0x03; /* Safe */ + t->power_supply_state = 0x03; /* Safe */ + t->thermal_state = 0x03; /* Safe */ + t->security_status = 0x02; /* Unknown */ + t->oem_defined = 0; + t->height = 0; + t->number_of_power_cords = 0; + t->contained_element_count = 0; + + SMBIOS_BUILD_TABLE_POST; +} + #define SMBIOS_SET_DEFAULT(field, value) \ if (!field) { \ field = value; \ @@ -368,6 +418,8 @@ void smbios_set_defaults(const char *manufacturer, SMBIOS_SET_DEFAULT(type2.manufacturer, manufacturer); SMBIOS_SET_DEFAULT(type2.product, product); SMBIOS_SET_DEFAULT(type2.version, version); + SMBIOS_SET_DEFAULT(type3.manufacturer, manufacturer); + SMBIOS_SET_DEFAULT(type3.version, version); } uint8_t *smbios_get_table(size_t *length) @@ -376,6 +428,7 @@ uint8_t *smbios_get_table(size_t *length) smbios_build_type_0_table(); smbios_build_type_1_table(); smbios_build_type_2_table(); + smbios_build_type_3_table(); smbios_validate_table(); smbios_immutable = true; } @@ -522,6 +575,17 @@ void smbios_entry_add(QemuOpts *opts) save_opt(&type2.asset, opts, "asset"); save_opt(&type2.location, opts, "location"); return; + case 3: + qemu_opts_validate(opts, qemu_smbios_type3_opts, &local_err); + if (local_err) { + error_report("%s", error_get_pretty(local_err)); + exit(1); + } + save_opt(&type3.manufacturer, opts, "manufacturer"); + save_opt(&type3.version, opts, "version"); + save_opt(&type3.serial, opts, "serial"); + save_opt(&type3.asset, opts, "asset"); + return; default: error_report("Don't know how to build fields for SMBIOS type %ld", type);