From patchwork Fri Jun 10 09:15:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 69750 Delivered-To: patch@linaro.org Received: by 10.140.106.246 with SMTP id e109csp193845qgf; Fri, 10 Jun 2016 02:21:23 -0700 (PDT) X-Received: by 10.200.56.230 with SMTP id g35mr867948qtc.4.1465550483185; Fri, 10 Jun 2016 02:21:23 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id v127si5803884qkd.7.2016.06.10.02.21.23 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 10 Jun 2016 02:21:23 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org Received: from localhost ([::1]:39254 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bBId0-00078J-J0 for patch@linaro.org; Fri, 10 Jun 2016 05:21:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55626) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bBIXl-0003Kf-Pd for qemu-devel@nongnu.org; Fri, 10 Jun 2016 05:15:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bBIXg-0004ka-Nf for qemu-devel@nongnu.org; Fri, 10 Jun 2016 05:15:56 -0400 Received: from mail-oi0-x241.google.com ([2607:f8b0:4003:c06::241]:35641) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bBIXg-0004kS-HP for qemu-devel@nongnu.org; Fri, 10 Jun 2016 05:15:52 -0400 Received: by mail-oi0-x241.google.com with SMTP id k63so12080197oib.2 for ; Fri, 10 Jun 2016 02:15:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=T9OkgWMZ9fxV39dcVimfwtpDmdpL2rd9xGSRCvPlsLM=; b=f1/qUsqIIIoHTJW83eWmifvdHwfXnfgRAgYj7QBjSoJn+6h0iQeuPVIkZSmEs3pCgd BLVSHVptGg0Tp41x16eKBprCsNGM/1GQMAfjR6CpAY4C4oppLT90Zsw+SkEuhNcs2l4h iFhoEp3TwTd+qwY/By3MazQH3OqI6djqbCr1oNsw7ofetZuJ8mXYq2YUmrfsR8li0932 b8ET6jCnDt+7zDgdxv0Ywvd7e128qTFLsTZxm6qwtD/cgBB6BYOmpCm9wHsC0f9EX053 Rh8aKJyQTGDmE52FIcDvJGgmfVT/LX5nw3joc3YkRc61EvAxQjCvEw3c44+7paG8CrX1 7crA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=T9OkgWMZ9fxV39dcVimfwtpDmdpL2rd9xGSRCvPlsLM=; b=hS/YJTI7qPeFH8u8DlEiVj18C/YrS5+YEtXIzlyIF80MbX3GNqRyi0eAWlC6hBDyj9 qItKVedxyufLO6WIbVB0iRckEynvbynX4hpICTgo6FSISNAjwCrPcOluyz0QlQBdtpwh 84Wnatuz2c9ZD4oXEwzVxkTrInIRwDeXbUuTMEQzNNKCh+DTv6kUQWk1ooU6IOXm2MqQ QCLp3qTJnfiOEI6M/oD3cwxX8nABJh5a+9IvOh+qRn0Bc/zqmGglG8E7Bw/MSBXK7cRi XHmiCn8ESihJC4TL+GfH8UEjn6+Nm1RdvdnDIgAVx0M2Mwj/dt7EDSWHtYDk2RAhpWpS ZzMQ== X-Gm-Message-State: ALyK8tL0aMQkxbwcqo7RgvIoxQJBsGbZn/w9+sURDR1Le+g0X1uH/aeEY9zMkce3qyyLCw== X-Received: by 10.157.62.230 with SMTP id b93mr386272otc.163.1465550151560; Fri, 10 Jun 2016 02:15:51 -0700 (PDT) Received: from serve.minyard.net (serve.minyard.net. [2001:470:b8f6:1b::1]) by smtp.gmail.com with ESMTPSA id y84sm1073104oie.5.2016.06.10.02.15.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Jun 2016 02:15:50 -0700 (PDT) Received: from t430.minyard.net (unknown [111.93.218.67]) by serve.minyard.net (Postfix) with ESMTPA id 24319107C; Fri, 10 Jun 2016 04:15:49 -0500 (CDT) Received: by t430.minyard.net (Postfix, from userid 1000) id 0DEDE30004E; Fri, 10 Jun 2016 04:15:45 -0500 (CDT) From: minyard@acm.org To: Igor Mammedov , "Michael S . Tsirkin" , Paolo Bonzini , qemu-devel@nongnu.org, minyard@acm.org, cminyard@mvista.com Date: Fri, 10 Jun 2016 04:15:40 -0500 Message-Id: <1465550143-12611-2-git-send-email-minyard@acm.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1465550143-12611-1-git-send-email-minyard@acm.org> References: <1465550143-12611-1-git-send-email-minyard@acm.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4003:c06::241 Subject: [Qemu-devel] [PATCH v8 1/4] smbios: Move table build tools into an include file. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard This will let things in other files (like IPMI) build SMBIOS tables. Signed-off-by: Corey Minyard --- hw/smbios/smbios.c | 70 ++++---------------------------------- hw/smbios/smbios_build.h | 87 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 64 deletions(-) create mode 100644 hw/smbios/smbios_build.h -- 2.7.4 diff --git a/hw/smbios/smbios.c b/hw/smbios/smbios.c index cb8a111..5dc3e43 100644 --- a/hw/smbios/smbios.c +++ b/hw/smbios/smbios.c @@ -24,6 +24,7 @@ #include "hw/smbios/smbios.h" #include "hw/loader.h" #include "exec/cpu-common.h" +#include "smbios_build.h" /* legacy structures and constants for <= 2.0 machines */ struct smbios_header { @@ -53,10 +54,10 @@ static bool smbios_uuid_encoded = true; /* end: legacy structures & constants for <= 2.0 machines */ -static uint8_t *smbios_tables; -static size_t smbios_tables_len; -static unsigned smbios_table_max; -static unsigned smbios_table_cnt; +uint8_t *smbios_tables; +size_t smbios_tables_len; +unsigned smbios_table_max; +unsigned smbios_table_cnt; static SmbiosEntryPointType smbios_ep_type = SMBIOS_ENTRY_POINT_21; static SmbiosEntryPoint ep; @@ -429,7 +430,7 @@ uint8_t *smbios_get_table_legacy(size_t *length) /* end: legacy setup functions for <= 2.0 machines */ -static bool smbios_skip_table(uint8_t type, bool required_table) +bool smbios_skip_table(uint8_t type, bool required_table) { if (test_bit(type, have_binfile_bitmap)) { return true; /* user provided their own binary blob(s) */ @@ -443,65 +444,6 @@ static bool smbios_skip_table(uint8_t type, bool required_table) return true; } -#define SMBIOS_BUILD_TABLE_PRE(tbl_type, tbl_handle, tbl_required) \ - struct smbios_type_##tbl_type *t; \ - size_t t_off; /* table offset into smbios_tables */ \ - int str_index = 0; \ - do { \ - /* should we skip building this table ? */ \ - if (smbios_skip_table(tbl_type, tbl_required)) { \ - return; \ - } \ - \ - /* use offset of table t within smbios_tables */ \ - /* (pointer must be updated after each realloc) */ \ - t_off = smbios_tables_len; \ - smbios_tables_len += sizeof(*t); \ - smbios_tables = g_realloc(smbios_tables, smbios_tables_len); \ - t = (struct smbios_type_##tbl_type *)(smbios_tables + t_off); \ - \ - t->header.type = tbl_type; \ - t->header.length = sizeof(*t); \ - t->header.handle = cpu_to_le16(tbl_handle); \ - } while (0) - -#define SMBIOS_TABLE_SET_STR(tbl_type, field, value) \ - do { \ - int len = (value != NULL) ? strlen(value) + 1 : 0; \ - if (len > 1) { \ - smbios_tables = g_realloc(smbios_tables, \ - smbios_tables_len + len); \ - memcpy(smbios_tables + smbios_tables_len, value, len); \ - smbios_tables_len += len; \ - /* update pointer post-realloc */ \ - t = (struct smbios_type_##tbl_type *)(smbios_tables + t_off); \ - t->field = ++str_index; \ - } else { \ - t->field = 0; \ - } \ - } while (0) - -#define SMBIOS_BUILD_TABLE_POST \ - do { \ - size_t term_cnt, t_size; \ - \ - /* add '\0' terminator (add two if no strings defined) */ \ - term_cnt = (str_index == 0) ? 2 : 1; \ - smbios_tables = g_realloc(smbios_tables, \ - smbios_tables_len + term_cnt); \ - memset(smbios_tables + smbios_tables_len, 0, term_cnt); \ - smbios_tables_len += term_cnt; \ - \ - /* update smbios max. element size */ \ - t_size = smbios_tables_len - t_off; \ - if (t_size > smbios_table_max) { \ - smbios_table_max = t_size; \ - } \ - \ - /* update smbios element count */ \ - smbios_table_cnt++; \ - } while (0) - static void smbios_build_type_0_table(void) { SMBIOS_BUILD_TABLE_PRE(0, 0x000, false); /* optional, leave up to BIOS */ diff --git a/hw/smbios/smbios_build.h b/hw/smbios/smbios_build.h new file mode 100644 index 0000000..68b8b72 --- /dev/null +++ b/hw/smbios/smbios_build.h @@ -0,0 +1,87 @@ +/* + * SMBIOS Support + * + * Copyright (C) 2009 Hewlett-Packard Development Company, L.P. + * Copyright (C) 2013 Red Hat, Inc. + * + * Authors: + * Alex Williamson + * Markus Armbruster + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + * + * Contributions after 2012-01-13 are licensed under the terms of the + * GNU GPL, version 2 or (at your option) any later version. + */ + +#ifndef QEMU_SMBIOS_BUILD_H +#define QEMU_SMBIOS_BUILD_H + +bool smbios_skip_table(uint8_t type, bool required_table); + +extern uint8_t *smbios_tables; +extern size_t smbios_tables_len; +extern unsigned smbios_table_max; +extern unsigned smbios_table_cnt; + +#define SMBIOS_BUILD_TABLE_PRE(tbl_type, tbl_handle, tbl_required) \ + struct smbios_type_##tbl_type *t; \ + size_t t_off; /* table offset into smbios_tables */ \ + int str_index = 0; \ + do { \ + /* should we skip building this table ? */ \ + if (smbios_skip_table(tbl_type, tbl_required)) { \ + return; \ + } \ + \ + /* use offset of table t within smbios_tables */ \ + /* (pointer must be updated after each realloc) */ \ + t_off = smbios_tables_len; \ + smbios_tables_len += sizeof(*t); \ + smbios_tables = g_realloc(smbios_tables, smbios_tables_len); \ + t = (struct smbios_type_##tbl_type *)(smbios_tables + t_off); \ + \ + t->header.type = tbl_type; \ + t->header.length = sizeof(*t); \ + t->header.handle = cpu_to_le16(tbl_handle); \ + } while (0) + +#define SMBIOS_TABLE_SET_STR(tbl_type, field, value) \ + do { \ + int len = (value != NULL) ? strlen(value) + 1 : 0; \ + if (len > 1) { \ + smbios_tables = g_realloc(smbios_tables, \ + smbios_tables_len + len); \ + memcpy(smbios_tables + smbios_tables_len, value, len); \ + smbios_tables_len += len; \ + /* update pointer post-realloc */ \ + t = (struct smbios_type_##tbl_type *)(smbios_tables + t_off); \ + t->field = ++str_index; \ + } else { \ + t->field = 0; \ + } \ + } while (0) + +#define SMBIOS_BUILD_TABLE_POST \ + do { \ + size_t term_cnt, t_size; \ + \ + /* add '\0' terminator (add two if no strings defined) */ \ + term_cnt = (str_index == 0) ? 2 : 1; \ + smbios_tables = g_realloc(smbios_tables, \ + smbios_tables_len + term_cnt); \ + memset(smbios_tables + smbios_tables_len, 0, term_cnt); \ + smbios_tables_len += term_cnt; \ + \ + /* update smbios max. element size */ \ + t_size = smbios_tables_len - t_off; \ + if (t_size > smbios_table_max) { \ + smbios_table_max = t_size; \ + } \ + \ + /* update smbios element count */ \ + smbios_table_cnt++; \ + } while (0) + +#endif /* QEMU_SMBIOS_BUILD_H */