The branch main has been updated by markj:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=889cec66d39d60d0a00cd249614924291759fb82

commit 889cec66d39d60d0a00cd249614924291759fb82
Author:     Mark Johnston <[email protected]>
AuthorDate: 2022-09-09 03:26:47 +0000
Commit:     Mark Johnston <[email protected]>
CommitDate: 2022-09-29 16:36:44 +0000

    bhyve: Make smbios tables local to smbiostbl.c
    
    Also flag them as const.
    
    MFC after:      2 weeks
---
 usr.sbin/bhyve/smbiostbl.c | 119 +++++++++++++++++++++++----------------------
 1 file changed, 62 insertions(+), 57 deletions(-)

diff --git a/usr.sbin/bhyve/smbiostbl.c b/usr.sbin/bhyve/smbiostbl.c
index bc85bb6c97af..22e6a6c73848 100644
--- a/usr.sbin/bhyve/smbiostbl.c
+++ b/usr.sbin/bhyve/smbiostbl.c
@@ -81,14 +81,14 @@ struct smbios_string {
        const char *value;
 };
 
-typedef int (*initializer_func_t)(struct smbios_structure *template_entry,
-    struct smbios_string *template_strings, char *curaddr, char **endaddr,
+typedef int (*initializer_func_t)(const struct smbios_structure 
*template_entry,
+    const struct smbios_string *template_strings, char *curaddr, char 
**endaddr,
     uint16_t *n, uint16_t *size);
 
 struct smbios_template_entry {
-       struct smbios_structure *entry;
-       struct smbios_string    *strings;
-       initializer_func_t      initializer;
+       const struct smbios_structure   *entry;
+       const struct smbios_string      *strings;
+       initializer_func_t              initializer;
 };
 
 /*
@@ -339,7 +339,7 @@ struct smbios_table_type127 {
        struct smbios_structure header;
 } __packed;
 
-struct smbios_table_type0 smbios_type0_template = {
+static const struct smbios_table_type0 smbios_type0_template = {
        { SMBIOS_TYPE_BIOS, sizeof (struct smbios_table_type0), 0 },
        1,      /* bios vendor string */
        2,      /* bios version string */
@@ -355,14 +355,14 @@ struct smbios_table_type0 smbios_type0_template = {
        0xff    /* embedded controller firmware minor release */
 };
 
-struct smbios_string smbios_type0_strings[] = {
+static const struct smbios_string smbios_type0_strings[] = {
        { "bios.vendor", "BHYVE" },                     /* vendor string */
        { "bios.version", FIRMWARE_VERSION },           /* bios version string 
*/
        { "bios.release_date", FIRMWARE_RELEASE_DATE }, /* bios release date 
string */
        { 0 }
 };
 
-struct smbios_table_type1 smbios_type1_template = {
+static const struct smbios_table_type1 smbios_type1_template = {
        { SMBIOS_TYPE_SYSTEM, sizeof (struct smbios_table_type1), 0 },
        1,              /* manufacturer string */
        2,              /* product string */
@@ -374,11 +374,11 @@ struct smbios_table_type1 smbios_type1_template = {
        6               /* family string */
 };
 
-static int smbios_type1_initializer(struct smbios_structure *template_entry,
-    struct smbios_string *template_strings, char *curaddr, char **endaddr,
+static int smbios_type1_initializer(const struct smbios_structure 
*template_entry,
+    const struct smbios_string *template_strings, char *curaddr, char 
**endaddr,
     uint16_t *n, uint16_t *size);
 
-struct smbios_string smbios_type1_strings[] = {
+static const struct smbios_string smbios_type1_strings[] = {
        { "system.manufacturer", "FreeBSD" },        /* manufacturer string */
        { "system.product_name", "BHYVE" },          /* product string */
        { "system.version", "1.0" },                 /* version string */
@@ -388,7 +388,7 @@ struct smbios_string smbios_type1_strings[] = {
        { 0 }
 };
 
-struct smbios_table_type2 smbios_type2_template = {
+static const struct smbios_table_type2 smbios_type2_template = {
        { SMBIOS_TYPE_BOARD, sizeof (struct smbios_table_type2), 0 },
        1,                      /* manufacturer string */
        2,                      /* product string */
@@ -402,7 +402,7 @@ struct smbios_table_type2 smbios_type2_template = {
        0
 };
 
-struct smbios_string smbios_type2_strings[] = {
+static const struct smbios_string smbios_type2_strings[] = {
        { "board.manufacturer", "FreeBSD" },    /* manufacturer string */
        { "board.product_name", "BHYVE" },      /* product name string */
        { "board.version", "1.0" },             /* version string */
@@ -412,7 +412,7 @@ struct smbios_string smbios_type2_strings[] = {
        { 0 }
 };
 
-struct smbios_table_type3 smbios_type3_template = {
+static const struct smbios_table_type3 smbios_type3_template = {
        { SMBIOS_TYPE_CHASSIS, sizeof (struct smbios_table_type3), 0 },
        1,              /* manufacturer string */
        SMBIOS_CHT_UNKNOWN,
@@ -431,7 +431,7 @@ struct smbios_table_type3 smbios_type3_template = {
        5               /* sku number string */
 };
 
-struct smbios_string smbios_type3_strings[] = {
+static const struct smbios_string smbios_type3_strings[] = {
        { "chassis.manufacturer", "FreeBSD" },  /* manufacturer string */
        { "chassis.version", "1.0" },           /* version string */
        { "chassis.serial_number", "None" },    /* serial number string */
@@ -440,7 +440,7 @@ struct smbios_string smbios_type3_strings[] = {
        { 0 }
 };
 
-struct smbios_table_type4 smbios_type4_template = {
+static const struct smbios_table_type4 smbios_type4_template = {
        { SMBIOS_TYPE_PROCESSOR, sizeof (struct smbios_table_type4), 0 },
        1,              /* socket designation string */
        SMBIOS_PRT_CENTRAL,
@@ -467,7 +467,7 @@ struct smbios_table_type4 smbios_type4_template = {
        SMBIOS_PRF_OTHER
 };
 
-struct smbios_string smbios_type4_strings[] = {
+static const struct smbios_string smbios_type4_strings[] = {
        { NULL, " " },          /* socket designation string */
        { NULL, " " },          /* manufacturer string */
        { NULL, " " },          /* version string */
@@ -477,11 +477,12 @@ struct smbios_string smbios_type4_strings[] = {
        { 0 }
 };
 
-static int smbios_type4_initializer(struct smbios_structure *template_entry,
-    struct smbios_string *template_strings, char *curaddr, char **endaddr,
+static int smbios_type4_initializer(
+    const struct smbios_structure *template_entry,
+    const struct smbios_string *template_strings, char *curaddr, char 
**endaddr,
     uint16_t *n, uint16_t *size);
 
-struct smbios_table_type16 smbios_type16_template = {
+static const struct smbios_table_type16 smbios_type16_template = {
        { SMBIOS_TYPE_MEMARRAY, sizeof (struct smbios_table_type16),  0 },
        SMBIOS_MAL_SYSMB,
        SMBIOS_MAU_SYSTEM,
@@ -492,11 +493,12 @@ struct smbios_table_type16 smbios_type16_template = {
        0               /* extended maximum memory capacity in bytes (TBD) */
 };
 
-static int smbios_type16_initializer(struct smbios_structure *template_entry,
-    struct smbios_string *template_strings, char *curaddr, char **endaddr,
+static int smbios_type16_initializer(
+    const struct smbios_structure *template_entry,
+    const struct smbios_string *template_strings, char *curaddr, char 
**endaddr,
     uint16_t *n, uint16_t *size);
 
-struct smbios_table_type17 smbios_type17_template = {
+static const struct smbios_table_type17 smbios_type17_template = {
        { SMBIOS_TYPE_MEMDEVICE, sizeof (struct smbios_table_type17),  0 },
        -1,             /* handle of physical memory array */
        -1,             /* handle of memory error data */
@@ -522,7 +524,7 @@ struct smbios_table_type17 smbios_type17_template = {
        0               /* configured voltage in mv (0=unknown) */
 };
 
-struct smbios_string smbios_type17_strings[] = {
+static const struct smbios_string smbios_type17_strings[] = {
        { NULL, " " },          /* device locator string */
        { NULL, " " },          /* physical bank locator string */
        { NULL, " " },          /* manufacturer string */
@@ -532,11 +534,12 @@ struct smbios_string smbios_type17_strings[] = {
        { 0 }
 };
 
-static int smbios_type17_initializer(struct smbios_structure *template_entry,
-    struct smbios_string *template_strings, char *curaddr, char **endaddr,
+static int smbios_type17_initializer(
+    const struct smbios_structure *template_entry,
+    const struct smbios_string *template_strings, char *curaddr, char 
**endaddr,
     uint16_t *n, uint16_t *size);
 
-struct smbios_table_type19 smbios_type19_template = {
+static const struct smbios_table_type19 smbios_type19_template = {
        { SMBIOS_TYPE_MEMARRAYMAP, sizeof (struct smbios_table_type19),  0 },
        0xffffffff,     /* starting phys addr in kb (0xffffffff=use ext) */
        0xffffffff,     /* ending phys addr in kb (0xffffffff=use ext) */
@@ -546,53 +549,55 @@ struct smbios_table_type19 smbios_type19_template = {
        0               /* extended ending phys addr in bytes (TDB) */
 };
 
-static int smbios_type19_initializer(struct smbios_structure *template_entry,
-    struct smbios_string *template_strings, char *curaddr, char **endaddr,
+static int smbios_type19_initializer(
+    const struct smbios_structure *template_entry,
+    const struct smbios_string *template_strings, char *curaddr, char 
**endaddr,
     uint16_t *n, uint16_t *size);
 
-struct smbios_table_type32 smbios_type32_template = {
+static struct smbios_table_type32 smbios_type32_template = {
        { SMBIOS_TYPE_BOOT, sizeof (struct smbios_table_type32),  0 },
        { 0, 0, 0, 0, 0, 0 },
        SMBIOS_BOOT_NORMAL
 };
 
-struct smbios_table_type127 smbios_type127_template = {
+static const struct smbios_table_type127 smbios_type127_template = {
        { SMBIOS_TYPE_EOT, sizeof (struct smbios_table_type127),  0 }
 };
 
-static int smbios_generic_initializer(struct smbios_structure *template_entry,
-    struct smbios_string *template_strings, char *curaddr, char **endaddr,
+static int smbios_generic_initializer(
+    const struct smbios_structure *template_entry,
+    const struct smbios_string *template_strings, char *curaddr, char 
**endaddr,
     uint16_t *n, uint16_t *size);
 
 static struct smbios_template_entry smbios_template[] = {
-       { (struct smbios_structure *)&smbios_type0_template,
+       { (const struct smbios_structure *)&smbios_type0_template,
          smbios_type0_strings,
          smbios_generic_initializer },
-       { (struct smbios_structure *)&smbios_type1_template,
+       { (const struct smbios_structure *)&smbios_type1_template,
          smbios_type1_strings,
          smbios_type1_initializer },
-       { (struct smbios_structure *)&smbios_type2_template,
+       { (const struct smbios_structure *)&smbios_type2_template,
          smbios_type2_strings,
          smbios_generic_initializer },
-       { (struct smbios_structure *)&smbios_type3_template,
+       { (const struct smbios_structure *)&smbios_type3_template,
          smbios_type3_strings,
          smbios_generic_initializer },
-       { (struct smbios_structure *)&smbios_type4_template,
+       { (const struct smbios_structure *)&smbios_type4_template,
          smbios_type4_strings,
          smbios_type4_initializer },
-       { (struct smbios_structure *)&smbios_type16_template,
+       { (const struct smbios_structure *)&smbios_type16_template,
          NULL,
          smbios_type16_initializer },
-       { (struct smbios_structure *)&smbios_type17_template,
+       { (const struct smbios_structure *)&smbios_type17_template,
          smbios_type17_strings,
          smbios_type17_initializer },
-       { (struct smbios_structure *)&smbios_type19_template,
+       { (const struct smbios_structure *)&smbios_type19_template,
          NULL,
          smbios_type19_initializer },
-       { (struct smbios_structure *)&smbios_type32_template,
+       { (const struct smbios_structure *)&smbios_type32_template,
          NULL,
          smbios_generic_initializer },
-       { (struct smbios_structure *)&smbios_type127_template,
+       { (const struct smbios_structure *)&smbios_type127_template,
          NULL,
          smbios_generic_initializer },
        { NULL,NULL, NULL }
@@ -602,8 +607,8 @@ static uint64_t guest_lomem, guest_himem;
 static uint16_t type16_handle;
 
 static int
-smbios_generic_initializer(struct smbios_structure *template_entry,
-    struct smbios_string *template_strings, char *curaddr, char **endaddr,
+smbios_generic_initializer(const struct smbios_structure *template_entry,
+    const struct smbios_string *template_strings, char *curaddr, char 
**endaddr,
     uint16_t *n, uint16_t *size)
 {
        struct smbios_structure *entry;
@@ -649,8 +654,8 @@ smbios_generic_initializer(struct smbios_structure 
*template_entry,
 }
 
 static int
-smbios_type1_initializer(struct smbios_structure *template_entry,
-    struct smbios_string *template_strings, char *curaddr, char **endaddr,
+smbios_type1_initializer(const struct smbios_structure *template_entry,
+    const struct smbios_string *template_strings, char *curaddr, char 
**endaddr,
     uint16_t *n, uint16_t *size)
 {
        struct smbios_table_type1 *type1;
@@ -707,8 +712,8 @@ smbios_type1_initializer(struct smbios_structure 
*template_entry,
 }
 
 static int
-smbios_type4_initializer(struct smbios_structure *template_entry,
-    struct smbios_string *template_strings, char *curaddr, char **endaddr,
+smbios_type4_initializer(const struct smbios_structure *template_entry,
+    const struct smbios_string *template_strings, char *curaddr, char 
**endaddr,
     uint16_t *n, uint16_t *size)
 {
        int i;
@@ -749,8 +754,8 @@ smbios_type4_initializer(struct smbios_structure 
*template_entry,
 }
 
 static int
-smbios_type16_initializer(struct smbios_structure *template_entry,
-    struct smbios_string *template_strings, char *curaddr, char **endaddr,
+smbios_type16_initializer(const struct smbios_structure *template_entry,
+    const struct smbios_string *template_strings, char *curaddr, char 
**endaddr,
     uint16_t *n, uint16_t *size)
 {
        struct smbios_table_type16 *type16;
@@ -766,8 +771,8 @@ smbios_type16_initializer(struct smbios_structure 
*template_entry,
 }
 
 static int
-smbios_type17_initializer(struct smbios_structure *template_entry,
-    struct smbios_string *template_strings, char *curaddr, char **endaddr,
+smbios_type17_initializer(const struct smbios_structure *template_entry,
+    const struct smbios_string *template_strings, char *curaddr, char 
**endaddr,
     uint16_t *n, uint16_t *size)
 {
        struct smbios_table_type17 *type17;
@@ -810,8 +815,8 @@ smbios_type17_initializer(struct smbios_structure 
*template_entry,
 }
 
 static int
-smbios_type19_initializer(struct smbios_structure *template_entry,
-    struct smbios_string *template_strings, char *curaddr, char **endaddr,
+smbios_type19_initializer(const struct smbios_structure *template_entry,
+    const struct smbios_string *template_strings, char *curaddr, char 
**endaddr,
     uint16_t *n, uint16_t *size)
 {
        struct smbios_table_type19 *type19;
@@ -907,8 +912,8 @@ smbios_build(struct vmctx *ctx)
        n = 0;
        maxssize = 0;
        for (i = 0; smbios_template[i].entry != NULL; i++) {
-               struct smbios_structure *entry;
-               struct smbios_string    *strings;
+               const struct smbios_structure   *entry;
+               const struct smbios_string      *strings;
                initializer_func_t      initializer;
                char                    *endaddr;
                uint16_t                size;

Reply via email to