qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: minyard@acm.org
Cc: Igor Mammedov <imammedo@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	qemu-devel@nongnu.org, cminyard@mvista.com
Subject: Re: [Qemu-devel] [PATCH v7 3/6] smbios: Move table build tools into an include file.
Date: Fri, 3 Jun 2016 19:15:22 +0300	[thread overview]
Message-ID: <20160603191237-mutt-send-email-mst@redhat.com> (raw)
In-Reply-To: <1464111442-10387-4-git-send-email-minyard@acm.org>

On Tue, May 24, 2016 at 12:37:19PM -0500, minyard@acm.org wrote:
> From: Corey Minyard <cminyard@mvista.com>
> 
> This will let things in other files (like IPMI) build SMBIOS tables.
> 
> Signed-off-by: Corey Minyard <cminyard@mvista.com>
> ---
>  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.
> + */

Pls add license and author info as well.

> +
> +#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 */
> -- 
> 2.7.4

  reply	other threads:[~2016-06-03 16:15 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-24 17:37 [Qemu-devel] [PATCH v7 1/6] Add IPMI to firmware tables minyard
2016-05-24 17:37 ` [Qemu-devel] [PATCH v7 1/6] ipmi: rework the fwinfo to be fetched from the interface minyard
2016-05-24 17:37 ` [Qemu-devel] [PATCH v7 2/6] pc: Postpone SMBIOS table installation to post machine init minyard
2016-05-24 17:37 ` [Qemu-devel] [PATCH v7 3/6] smbios: Move table build tools into an include file minyard
2016-06-03 16:15   ` Michael S. Tsirkin [this message]
2016-06-05  4:04     ` Corey Minyard
2016-05-24 17:37 ` [Qemu-devel] [PATCH v7 4/6] ipmi: Add SMBIOS table entry minyard
2016-05-24 17:37 ` [Qemu-devel] [PATCH v7 5/6] acpi: Add IPMI table entries minyard
2016-06-03 16:16   ` Michael S. Tsirkin
2016-05-24 17:37 ` [Qemu-devel] [PATCH v7 6/6] bios: Add tests for the IPMI ACPI and SMBIOS entries minyard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160603191237-mutt-send-email-mst@redhat.com \
    --to=mst@redhat.com \
    --cc=cminyard@mvista.com \
    --cc=imammedo@redhat.com \
    --cc=minyard@acm.org \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).