diff mbox

[15/16] smbios: Add a function to directly add an entry

Message ID 1384273995-16486-16-git-send-email-cminyard@mvista.com
State New
Headers show

Commit Message

Corey Minyard Nov. 12, 2013, 4:33 p.m. UTC
There was no way to directly add a table entry to the SMBIOS table,
even though the BIOS supports this.  So add a function to do this.
This is in preparation for the IPMI handler adding it's SMBIOS table
entry.

Signed-off-by: Corey Minyard <cminyard@mvista.com>
---
 hw/i386/smbios.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

Comments

Bret Ketchum Nov. 13, 2013, 2:37 p.m. UTC | #1
Don't know if it matters much but this patch cannot be applied without
the prototype definition in 16/16.


On Tue, Nov 12, 2013 at 10:33 AM, Corey Minyard <minyard@acm.org> wrote:

> There was no way to directly add a table entry to the SMBIOS table,
> even though the BIOS supports this.  So add a function to do this.
> This is in preparation for the IPMI handler adding it's SMBIOS table
> entry.
>
> Signed-off-by: Corey Minyard <cminyard@mvista.com>
> ---
>  hw/i386/smbios.c | 27 +++++++++++++++++++++++++++
>  1 file changed, 27 insertions(+)
>
> diff --git a/hw/i386/smbios.c b/hw/i386/smbios.c
> index d3f1ee6..9c53131 100644
> --- a/hw/i386/smbios.c
> +++ b/hw/i386/smbios.c
> @@ -277,6 +277,33 @@ static void save_opt(const char **dest, QemuOpts
> *opts, const char *name)
>      }
>  }
>
> +int smbios_table_entry_add(struct smbios_structure_header *entry)
> +{
> +    struct smbios_table *table;
> +    struct smbios_structure_header *header;
> +    unsigned int size = entry->length;
> +
> +    if (!smbios_entries) {
> +        smbios_entries_len = sizeof(uint16_t);
> +        smbios_entries = g_malloc0(smbios_entries_len);
> +    }
> +    smbios_entries = g_realloc(smbios_entries, smbios_entries_len +
> +                              sizeof(*table) + size);
> +    table = (struct smbios_table *)(smbios_entries + smbios_entries_len);
> +    table->header.type = SMBIOS_TABLE_ENTRY;
> +    table->header.length = cpu_to_le16(sizeof(*table) + size);
> +
> +    header = (struct smbios_structure_header *)(table->data);
> +    memcpy(header, entry, size);
> +
> +    smbios_check_collision(header->type, SMBIOS_TABLE_ENTRY);
> +
> +    smbios_entries_len += sizeof(*table) + size;
> +    (*(uint16_t *)smbios_entries) =
> +       cpu_to_le16(le16_to_cpu(*(uint16_t *)smbios_entries) + 1);
> +    return 0;
> +}
> +
>  void smbios_entry_add(QemuOpts *opts)
>  {
>      Error *local_err = NULL;
> --
> 1.8.3.1
>
>
Andreas Färber Nov. 13, 2013, 4:22 p.m. UTC | #2
Am 13.11.2013 15:37, schrieb Bret Ketchum:
> 
>     Don't know if it matters much but this patch cannot be applied
> without the prototype definition in 16/16.

It does matter for bisecting, thanks for pointing it out!

Cheers,
Andreas
Corey Minyard Nov. 13, 2013, 8:52 p.m. UTC | #3
On 11/13/2013 08:37 AM, Bret Ketchum wrote:
>
>     Don't know if it matters much but this patch cannot be applied
> without the prototype definition in 16/16.

Thanks, I'll fix this.

-corey

>
>
> On Tue, Nov 12, 2013 at 10:33 AM, Corey Minyard <minyard@acm.org
> <mailto:minyard@acm.org>> wrote:
>
>     There was no way to directly add a table entry to the SMBIOS table,
>     even though the BIOS supports this.  So add a function to do this.
>     This is in preparation for the IPMI handler adding it's SMBIOS table
>     entry.
>
>     Signed-off-by: Corey Minyard <cminyard@mvista.com
>     <mailto:cminyard@mvista.com>>
>     ---
>      hw/i386/smbios.c | 27 +++++++++++++++++++++++++++
>      1 file changed, 27 insertions(+)
>
>     diff --git a/hw/i386/smbios.c b/hw/i386/smbios.c
>     index d3f1ee6..9c53131 100644
>     --- a/hw/i386/smbios.c
>     +++ b/hw/i386/smbios.c
>     @@ -277,6 +277,33 @@ static void save_opt(const char **dest,
>     QemuOpts *opts, const char *name)
>          }
>      }
>
>     +int smbios_table_entry_add(struct smbios_structure_header *entry)
>     +{
>     +    struct smbios_table *table;
>     +    struct smbios_structure_header *header;
>     +    unsigned int size = entry->length;
>     +
>     +    if (!smbios_entries) {
>     +        smbios_entries_len = sizeof(uint16_t);
>     +        smbios_entries = g_malloc0(smbios_entries_len);
>     +    }
>     +    smbios_entries = g_realloc(smbios_entries, smbios_entries_len +
>     +                              sizeof(*table) + size);
>     +    table = (struct smbios_table *)(smbios_entries +
>     smbios_entries_len);
>     +    table->header.type = SMBIOS_TABLE_ENTRY;
>     +    table->header.length = cpu_to_le16(sizeof(*table) + size);
>     +
>     +    header = (struct smbios_structure_header *)(table->data);
>     +    memcpy(header, entry, size);
>     +
>     +    smbios_check_collision(header->type, SMBIOS_TABLE_ENTRY);
>     +
>     +    smbios_entries_len += sizeof(*table) + size;
>     +    (*(uint16_t *)smbios_entries) =
>     +       cpu_to_le16(le16_to_cpu(*(uint16_t *)smbios_entries) + 1);
>     +    return 0;
>     +}
>     +
>      void smbios_entry_add(QemuOpts *opts)
>      {
>          Error *local_err = NULL;
>     --
>     1.8.3.1
>
>
diff mbox

Patch

diff --git a/hw/i386/smbios.c b/hw/i386/smbios.c
index d3f1ee6..9c53131 100644
--- a/hw/i386/smbios.c
+++ b/hw/i386/smbios.c
@@ -277,6 +277,33 @@  static void save_opt(const char **dest, QemuOpts *opts, const char *name)
     }
 }
 
+int smbios_table_entry_add(struct smbios_structure_header *entry)
+{
+    struct smbios_table *table;
+    struct smbios_structure_header *header;
+    unsigned int size = entry->length;
+
+    if (!smbios_entries) {
+        smbios_entries_len = sizeof(uint16_t);
+        smbios_entries = g_malloc0(smbios_entries_len);
+    }
+    smbios_entries = g_realloc(smbios_entries, smbios_entries_len +
+                              sizeof(*table) + size);
+    table = (struct smbios_table *)(smbios_entries + smbios_entries_len);
+    table->header.type = SMBIOS_TABLE_ENTRY;
+    table->header.length = cpu_to_le16(sizeof(*table) + size);
+
+    header = (struct smbios_structure_header *)(table->data);
+    memcpy(header, entry, size);
+
+    smbios_check_collision(header->type, SMBIOS_TABLE_ENTRY);
+
+    smbios_entries_len += sizeof(*table) + size;
+    (*(uint16_t *)smbios_entries) =
+       cpu_to_le16(le16_to_cpu(*(uint16_t *)smbios_entries) + 1);
+    return 0;
+}
+
 void smbios_entry_add(QemuOpts *opts)
 {
     Error *local_err = NULL;