From patchwork Wed May 11 16:38:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 9073061 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id B985CBF29F for ; Wed, 11 May 2016 16:41:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CACD72010F for ; Wed, 11 May 2016 16:41:06 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C7F72200F2 for ; Wed, 11 May 2016 16:41:05 +0000 (UTC) Received: from localhost ([::1]:53211 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0XC4-0008EU-VC for patchwork-qemu-devel@patchwork.kernel.org; Wed, 11 May 2016 12:41:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48930) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0XAD-0004o5-VX for qemu-devel@nongnu.org; Wed, 11 May 2016 12:39:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b0XA6-0002BF-T7 for qemu-devel@nongnu.org; Wed, 11 May 2016 12:39:08 -0400 Received: from mail-pf0-x243.google.com ([2607:f8b0:400e:c00::243]:35441) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0XA6-0002B4-JS for qemu-devel@nongnu.org; Wed, 11 May 2016 12:39:02 -0400 Received: by mail-pf0-x243.google.com with SMTP id r187so4909602pfr.2 for ; Wed, 11 May 2016 09:39:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=aOKZLWGdKBPdQgGi2rc+tRmWKmDfyRuefcHXiqaMYIA=; b=vTSYBkd6Xl7xSSHg/yZj+gd0T7RvToGxiv4VGaubuJduIaCwbAq28/Y1zofcdY5Gv/ f4Y5iXKRDvU3YgDrGKy2/GDcSGZaflEtjffP7TlQLqn+gWrxBGC7KfLOKGf2X938Tl+E 5XFVZuYBK28W2EZj+svTOFysVnh36TnILTFkqHjw7+ROXiGsl3mRanpH8BmA/SphPLpT qKXJ5dRIpO17zb5EEdMkTEG4QhXXLgMqG1vlPqgmgFqQe+ayQS5ZnaKXw+i5puDKJERR qE7JKK8TLWUHV6jc73Y24gkfvgywbebTnYK55+1lsNBp3WP7QjcQ4WBOYonlZ3djv45o 7jgw== 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:cc:subject:date:message-id :in-reply-to:references; bh=aOKZLWGdKBPdQgGi2rc+tRmWKmDfyRuefcHXiqaMYIA=; b=WvCyvsteBuE8mbUak6AJJJmHesSTbPhxfnURE7v11ip5Bb0kz52o87VzxdvPf2nme9 DbMZeO6nULQo1Zd4VePGjgERsQ5wXgNF+TucwoVogD4TYD4SwMAFVEGKjU1Uge2tUkj6 uPR9erGnoBKAFACAVO4LxRY642vlHj4om2Uzqm+xZ2622r1XBp9MTtdDTDiRHn7gICQl RSomAeE57oCSfQyZNBmg/subwT//WlddX5hxkbXJlyYJw63Tg+MkqrY4/a4sNZ5u9Wxn PEP6q9DUmBCtRsmUzhW0fvEPa2AGhiXpnD+TliJFV2TB+O9/XzJNG9wixLpAFVPb+BaI hg0A== X-Gm-Message-State: AOPr4FUP8ASuGU7ZRuGhicUpeyD1mlm3pllBvoVkye+rdiL8+1oOF26GxcY4J4q8I5zoAA== X-Received: by 10.98.24.88 with SMTP id 85mr6498735pfy.52.1462984742055; Wed, 11 May 2016 09:39:02 -0700 (PDT) Received: from serve.minyard.net ([108.19.215.157]) by smtp.gmail.com with ESMTPSA id 71sm13411207pfy.32.2016.05.11.09.38.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 May 2016 09:38:59 -0700 (PDT) Received: from t430.minyard.net (unknown [IPv6:2001:470:b8f6:1b:a430:dab6:589a:a3a1]) by serve.minyard.net (Postfix) with ESMTPA id 1B86F1995; Wed, 11 May 2016 11:38:58 -0500 (CDT) Received: by t430.minyard.net (Postfix, from userid 1000) id 68BD7300536; Wed, 11 May 2016 11:38:56 -0500 (CDT) From: minyard@acm.org To: Igor Mammedov , "Michael S . Tsirkin" , Paolo Bonzini , qemu-devel@nongnu.org, minyard@acm.org Date: Wed, 11 May 2016 11:38:51 -0500 Message-Id: <1462984734-23803-3-git-send-email-minyard@acm.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1462984734-23803-1-git-send-email-minyard@acm.org> References: <1462984734-23803-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:400e:c00::243 Subject: [Qemu-devel] [PATCH v2 2/5] 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: , Cc: Corey Minyard Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 | 77 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 64 deletions(-) create mode 100644 hw/smbios/smbios_build.h 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..2257721 --- /dev/null +++ b/hw/smbios/smbios_build.h @@ -0,0 +1,77 @@ +/* + * SMBIOS Support + * + * Copyright (C) 2009 Hewlett-Packard Development Company, L.P. + * Copyright (C) 2013 Red Hat, Inc. + */ + +#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 */