All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/1] hvmloader: add SMBIOS type 2 info for customized string
@ 2019-03-28 13:56 Xin Li
  2019-03-28 14:26 ` Jan Beulich
  0 siblings, 1 reply; 7+ messages in thread
From: Xin Li @ 2019-03-28 13:56 UTC (permalink / raw)
  To: xen-devel
  Cc: Xin Li, Sergey Dyasli, Andrew Cooper, Jan Beulich, Igor Druzhinin

Extend smbios type 2 struct to match specification, add support to
write it when customized string provided and no smbios passed in.

Signed-off-by: Xin Li <xin.li@citrix.com>

---
CC: Jan Beulich <JBeulich@suse.com>
CC: Igor Druzhinin <igor.druzhinin@citrix.com>
CC: Sergey Dyasli <sergey.dyasli@citrix.com>
CC: Andrew Cooper <andrew.cooper3@citrix.com>

v2
1: write the struct if any of the strings is provided
2: add contained_handles as flexible array member
3: update commit message and fix style issue
---
 tools/firmware/hvmloader/smbios.c       | 69 ++++++++++++++++++++++++-
 tools/firmware/hvmloader/smbios_types.h |  7 +++
 xen/include/public/hvm/hvm_xs_strings.h |  6 +++
 3 files changed, 80 insertions(+), 2 deletions(-)

diff --git a/tools/firmware/hvmloader/smbios.c b/tools/firmware/hvmloader/smbios.c
index 40d8399be1..7815f1dbd3 100644
--- a/tools/firmware/hvmloader/smbios.c
+++ b/tools/firmware/hvmloader/smbios.c
@@ -497,9 +497,11 @@ static void *
 smbios_type_2_init(void *start)
 {
     struct smbios_type_2 *p = (struct smbios_type_2 *)start;
+    const char *s;
     uint8_t *ptr;
     void *pts;
     uint32_t length;
+    unsigned int counter = 0;
 
     pts = get_smbios_pt_struct(2, &length);
     if ( (pts != NULL)&&(length > 0) )
@@ -518,8 +520,71 @@ smbios_type_2_init(void *start)
         return (start + length);
     }
 
-    /* Only present when passed in */
-    return start;
+    memset(p, 0, sizeof(*p));
+    p->header.type = 2;
+    p->header.length = sizeof(struct smbios_type_2);
+    p->header.handle = SMBIOS_HANDLE_TYPE2;
+    p->feature_flags = 0x09; /* Board is a hosting board and replaceable */
+    p->chassis_handle = SMBIOS_HANDLE_TYPE3;
+    p->board_type = 0x0a; /* Motherboard */
+    start += sizeof(*p);
+
+    s = xenstore_read(HVM_XS_BASEBOARD_MANUFACTURER, NULL);
+    if ( (s != NULL) && (*s != '\0') )
+    {
+        strcpy(start, s);
+        start += strlen(s) + 1;
+        p->manufacturer_str = ++counter;
+    }
+
+    s = xenstore_read(HVM_XS_BASEBOARD_PRODUCT_NAME, NULL);
+    if ( (s != NULL) && (*s != '\0') )
+    {
+        strcpy(start, s);
+        start += strlen(s) + 1;
+        p->product_name_str = ++counter;
+    }
+
+    s = xenstore_read(HVM_XS_BASEBOARD_VERSION, NULL);
+    if ( (s != NULL) && (*s != '\0') )
+    {
+        strcpy(start, s);
+        start += strlen(s) + 1;
+        p->version_str = ++counter;
+    }
+
+    s = xenstore_read(HVM_XS_BASEBOARD_SERIAL_NUMBER, NULL);
+    if ( (s != NULL) && (*s != '\0') )
+    {
+        strcpy(start, s);
+        start += strlen(s) + 1;
+        p->serial_number_str = ++counter;
+    }
+
+    s = xenstore_read(HVM_XS_BASEBOARD_ASSET_TAG, NULL);
+    if ( (s != NULL) && (*s != '\0') )
+    {
+        strcpy(start, s);
+        start += strlen(s) + 1;
+        p->asset_tag_str = ++counter;
+    }
+
+    s = xenstore_read(HVM_XS_BASEBOARD_LOCATION_IN_CHASSIS, NULL);
+    if ( (s != NULL) && (*s != '\0') )
+    {
+        strcpy(start, s);
+        start += strlen(s) + 1;
+        p->location_in_chassis_str = ++counter;
+    }
+
+    if ( counter )
+    {
+        *((uint8_t *)start) = 0;
+        return start + 1;
+    }
+
+    /* Only present when passed in or with customized string */
+    return start - sizeof(*p);
 }
 
 /* Type 3 -- System Enclosure */
diff --git a/tools/firmware/hvmloader/smbios_types.h b/tools/firmware/hvmloader/smbios_types.h
index acb63e2fe9..7c648ece71 100644
--- a/tools/firmware/hvmloader/smbios_types.h
+++ b/tools/firmware/hvmloader/smbios_types.h
@@ -90,6 +90,13 @@ struct smbios_type_2 {
     uint8_t product_name_str;
     uint8_t version_str;
     uint8_t serial_number_str;
+    uint8_t asset_tag_str;
+    uint8_t feature_flags;
+    uint8_t location_in_chassis_str;
+    uint16_t chassis_handle;
+    uint8_t board_type;
+    uint8_t contained_handle_count;
+    uint16_t contained_handles[];
 } __attribute__ ((packed));
 
 /* System Enclosure - Contained Elements */
diff --git a/xen/include/public/hvm/hvm_xs_strings.h b/xen/include/public/hvm/hvm_xs_strings.h
index fea1dd4407..fba2546424 100644
--- a/xen/include/public/hvm/hvm_xs_strings.h
+++ b/xen/include/public/hvm/hvm_xs_strings.h
@@ -69,6 +69,12 @@
 #define HVM_XS_SYSTEM_PRODUCT_NAME     "bios-strings/system-product-name"
 #define HVM_XS_SYSTEM_VERSION          "bios-strings/system-version"
 #define HVM_XS_SYSTEM_SERIAL_NUMBER    "bios-strings/system-serial-number"
+#define HVM_XS_BASEBOARD_MANUFACTURER  "bios-strings/baseboard-manufacturer"
+#define HVM_XS_BASEBOARD_PRODUCT_NAME  "bios-strings/baseboard-product-name"
+#define HVM_XS_BASEBOARD_VERSION       "bios-strings/baseboard-version"
+#define HVM_XS_BASEBOARD_SERIAL_NUMBER "bios-strings/baseboard-serial-number"
+#define HVM_XS_BASEBOARD_ASSET_TAG     "bios-strings/baseboard-asset-tag"
+#define HVM_XS_BASEBOARD_LOCATION_IN_CHASSIS "bios-strings/baseboard-location-in-chassis"
 #define HVM_XS_ENCLOSURE_MANUFACTURER  "bios-strings/enclosure-manufacturer"
 #define HVM_XS_ENCLOSURE_SERIAL_NUMBER "bios-strings/enclosure-serial-number"
 #define HVM_XS_ENCLOSURE_ASSET_TAG     "bios-strings/enclosure-asset-tag"
-- 
2.20.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/1] hvmloader: add SMBIOS type 2 info for customized string
  2019-03-28 13:56 [PATCH v2 1/1] hvmloader: add SMBIOS type 2 info for customized string Xin Li
@ 2019-03-28 14:26 ` Jan Beulich
  0 siblings, 0 replies; 7+ messages in thread
From: Jan Beulich @ 2019-03-28 14:26 UTC (permalink / raw)
  To: Xin Li; +Cc: Andrew Cooper, Sergey Dyasli, xen-devel, Xin Li, Igor Druzhinin

>>> On 28.03.19 at 14:56, <talons.lee@gmail.com> wrote:
> Extend smbios type 2 struct to match specification, add support to
> write it when customized string provided and no smbios passed in.
> 
> Signed-off-by: Xin Li <xin.li@citrix.com>

Reviewed-by: Jan Beulich <jbeulich@suse.com>

with one minor remaining remark:

> @@ -518,8 +520,71 @@ smbios_type_2_init(void *start)
>          return (start + length);
>      }
>  
> -    /* Only present when passed in */
> -    return start;
> +    memset(p, 0, sizeof(*p));
> +    p->header.type = 2;
> +    p->header.length = sizeof(struct smbios_type_2);
> +    p->header.handle = SMBIOS_HANDLE_TYPE2;
> +    p->feature_flags = 0x09; /* Board is a hosting board and replaceable */
> +    p->chassis_handle = SMBIOS_HANDLE_TYPE3;
> +    p->board_type = 0x0a; /* Motherboard */
> +    start += sizeof(*p);
> +
> +    s = xenstore_read(HVM_XS_BASEBOARD_MANUFACTURER, NULL);
> +    if ( (s != NULL) && (*s != '\0') )
> +    {
> +        strcpy(start, s);
> +        start += strlen(s) + 1;
> +        p->manufacturer_str = ++counter;
> +    }
> +
> +    s = xenstore_read(HVM_XS_BASEBOARD_PRODUCT_NAME, NULL);
> +    if ( (s != NULL) && (*s != '\0') )
> +    {
> +        strcpy(start, s);
> +        start += strlen(s) + 1;
> +        p->product_name_str = ++counter;
> +    }
> +
> +    s = xenstore_read(HVM_XS_BASEBOARD_VERSION, NULL);
> +    if ( (s != NULL) && (*s != '\0') )
> +    {
> +        strcpy(start, s);
> +        start += strlen(s) + 1;
> +        p->version_str = ++counter;
> +    }
> +
> +    s = xenstore_read(HVM_XS_BASEBOARD_SERIAL_NUMBER, NULL);
> +    if ( (s != NULL) && (*s != '\0') )
> +    {
> +        strcpy(start, s);
> +        start += strlen(s) + 1;
> +        p->serial_number_str = ++counter;
> +    }
> +
> +    s = xenstore_read(HVM_XS_BASEBOARD_ASSET_TAG, NULL);
> +    if ( (s != NULL) && (*s != '\0') )
> +    {
> +        strcpy(start, s);
> +        start += strlen(s) + 1;
> +        p->asset_tag_str = ++counter;
> +    }
> +
> +    s = xenstore_read(HVM_XS_BASEBOARD_LOCATION_IN_CHASSIS, NULL);
> +    if ( (s != NULL) && (*s != '\0') )
> +    {
> +        strcpy(start, s);
> +        start += strlen(s) + 1;
> +        p->location_in_chassis_str = ++counter;
> +    }
> +
> +    if ( counter )
> +    {
> +        *((uint8_t *)start) = 0;

There's another pair of unnecessary parentheses here. If I end
up committing this I may take the liberty to drop them.

Jan



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/1] hvmloader: add SMBIOS type 2 info for customized string
  2019-03-29 11:08 ` Jan Beulich
@ 2019-04-01  1:24   ` Xin Li (Talons)
  0 siblings, 0 replies; 7+ messages in thread
From: Xin Li (Talons) @ 2019-04-01  1:24 UTC (permalink / raw)
  To: Jan Beulich, Xin Li
  Cc: Andrew Cooper, Sergey Dyasli, xen-devel, Igor Druzhinin

> So this is the 3rd variant of v2 that you've sent, without making it clear
> what the difference is. I suppose you've addressed my one remaining
> cosmetic request and added my R-b, but we should be at v4 then.

Yes. Since these are all style change, I kept the version number 2.
Sorry for the confusion.

Kind Regards

Xin(Talons)

________________________________________
From: Jan Beulich <JBeulich@suse.com>
Sent: Friday, March 29, 2019 7:08 PM
To: Xin Li
Cc: Andrew Cooper; Igor Druzhinin; Sergey Dyasli; Xin Li (Talons); xen-devel@lists.xen.org
Subject: Re: [PATCH v2 1/1] hvmloader: add SMBIOS type 2 info for customized string

>>> On 29.03.19 at 04:28, <talons.lee@gmail.com> wrote:
> Extend smbios type 2 struct to match specification, add support to
> write it when customized string provided and no smbios passed in.
>
> Signed-off-by: Xin Li <xin.li@citrix.com>
> Reviewed-by: Jan Beulich <jbeulich@suse.com>
>
> ---
> CC: Jan Beulich <JBeulich@suse.com>
> CC: Igor Druzhinin <igor.druzhinin@citrix.com>
> CC: Sergey Dyasli <sergey.dyasli@citrix.com>
> CC: Andrew Cooper <andrew.cooper3@citrix.com>
>
> v2
> 1: write the struct if any of the strings is provided
> 2: add contained_handles as flexible array member
> 3: update commit message and fix style issue

So this is the 3rd variant of v2 that you've sent, without making it clear
what the difference is. I suppose you've addressed my one remaining
cosmetic request and added my R-b, but we should be at v4 then.

Jan



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/1] hvmloader: add SMBIOS type 2 info for customized string
  2019-03-29  3:28 Xin Li
@ 2019-03-29 11:08 ` Jan Beulich
  2019-04-01  1:24   ` Xin Li (Talons)
  0 siblings, 1 reply; 7+ messages in thread
From: Jan Beulich @ 2019-03-29 11:08 UTC (permalink / raw)
  To: Xin Li; +Cc: Andrew Cooper, Sergey Dyasli, xen-devel, Xin Li, Igor Druzhinin

>>> On 29.03.19 at 04:28, <talons.lee@gmail.com> wrote:
> Extend smbios type 2 struct to match specification, add support to
> write it when customized string provided and no smbios passed in.
> 
> Signed-off-by: Xin Li <xin.li@citrix.com>
> Reviewed-by: Jan Beulich <jbeulich@suse.com>
> 
> ---
> CC: Jan Beulich <JBeulich@suse.com>
> CC: Igor Druzhinin <igor.druzhinin@citrix.com>
> CC: Sergey Dyasli <sergey.dyasli@citrix.com>
> CC: Andrew Cooper <andrew.cooper3@citrix.com>
> 
> v2
> 1: write the struct if any of the strings is provided
> 2: add contained_handles as flexible array member
> 3: update commit message and fix style issue

So this is the 3rd variant of v2 that you've sent, without making it clear
what the difference is. I suppose you've addressed my one remaining
cosmetic request and added my R-b, but we should be at v4 then.

Jan



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 1/1] hvmloader: add SMBIOS type 2 info for customized string
@ 2019-03-29  3:28 Xin Li
  2019-03-29 11:08 ` Jan Beulich
  0 siblings, 1 reply; 7+ messages in thread
From: Xin Li @ 2019-03-29  3:28 UTC (permalink / raw)
  To: xen-devel
  Cc: Xin Li, Sergey Dyasli, Andrew Cooper, Jan Beulich, Igor Druzhinin

Extend smbios type 2 struct to match specification, add support to
write it when customized string provided and no smbios passed in.

Signed-off-by: Xin Li <xin.li@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>

---
CC: Jan Beulich <JBeulich@suse.com>
CC: Igor Druzhinin <igor.druzhinin@citrix.com>
CC: Sergey Dyasli <sergey.dyasli@citrix.com>
CC: Andrew Cooper <andrew.cooper3@citrix.com>

v2
1: write the struct if any of the strings is provided
2: add contained_handles as flexible array member
3: update commit message and fix style issue
---
 tools/firmware/hvmloader/smbios.c       | 69 ++++++++++++++++++++++++-
 tools/firmware/hvmloader/smbios_types.h |  7 +++
 xen/include/public/hvm/hvm_xs_strings.h |  6 +++
 3 files changed, 80 insertions(+), 2 deletions(-)

diff --git a/tools/firmware/hvmloader/smbios.c b/tools/firmware/hvmloader/smbios.c
index 40d8399be1..97a054e9e3 100644
--- a/tools/firmware/hvmloader/smbios.c
+++ b/tools/firmware/hvmloader/smbios.c
@@ -497,9 +497,11 @@ static void *
 smbios_type_2_init(void *start)
 {
     struct smbios_type_2 *p = (struct smbios_type_2 *)start;
+    const char *s;
     uint8_t *ptr;
     void *pts;
     uint32_t length;
+    unsigned int counter = 0;
 
     pts = get_smbios_pt_struct(2, &length);
     if ( (pts != NULL)&&(length > 0) )
@@ -518,8 +520,71 @@ smbios_type_2_init(void *start)
         return (start + length);
     }
 
-    /* Only present when passed in */
-    return start;
+    memset(p, 0, sizeof(*p));
+    p->header.type = 2;
+    p->header.length = sizeof(struct smbios_type_2);
+    p->header.handle = SMBIOS_HANDLE_TYPE2;
+    p->feature_flags = 0x09; /* Board is a hosting board and replaceable */
+    p->chassis_handle = SMBIOS_HANDLE_TYPE3;
+    p->board_type = 0x0a; /* Motherboard */
+    start += sizeof(*p);
+
+    s = xenstore_read(HVM_XS_BASEBOARD_MANUFACTURER, NULL);
+    if ( (s != NULL) && (*s != '\0') )
+    {
+        strcpy(start, s);
+        start += strlen(s) + 1;
+        p->manufacturer_str = ++counter;
+    }
+
+    s = xenstore_read(HVM_XS_BASEBOARD_PRODUCT_NAME, NULL);
+    if ( (s != NULL) && (*s != '\0') )
+    {
+        strcpy(start, s);
+        start += strlen(s) + 1;
+        p->product_name_str = ++counter;
+    }
+
+    s = xenstore_read(HVM_XS_BASEBOARD_VERSION, NULL);
+    if ( (s != NULL) && (*s != '\0') )
+    {
+        strcpy(start, s);
+        start += strlen(s) + 1;
+        p->version_str = ++counter;
+    }
+
+    s = xenstore_read(HVM_XS_BASEBOARD_SERIAL_NUMBER, NULL);
+    if ( (s != NULL) && (*s != '\0') )
+    {
+        strcpy(start, s);
+        start += strlen(s) + 1;
+        p->serial_number_str = ++counter;
+    }
+
+    s = xenstore_read(HVM_XS_BASEBOARD_ASSET_TAG, NULL);
+    if ( (s != NULL) && (*s != '\0') )
+    {
+        strcpy(start, s);
+        start += strlen(s) + 1;
+        p->asset_tag_str = ++counter;
+    }
+
+    s = xenstore_read(HVM_XS_BASEBOARD_LOCATION_IN_CHASSIS, NULL);
+    if ( (s != NULL) && (*s != '\0') )
+    {
+        strcpy(start, s);
+        start += strlen(s) + 1;
+        p->location_in_chassis_str = ++counter;
+    }
+
+    if ( counter )
+    {
+        *(uint8_t *)start = 0;
+        return start + 1;
+    }
+
+    /* Only present when passed in or with customized string */
+    return start - sizeof(*p);
 }
 
 /* Type 3 -- System Enclosure */
diff --git a/tools/firmware/hvmloader/smbios_types.h b/tools/firmware/hvmloader/smbios_types.h
index acb63e2fe9..7c648ece71 100644
--- a/tools/firmware/hvmloader/smbios_types.h
+++ b/tools/firmware/hvmloader/smbios_types.h
@@ -90,6 +90,13 @@ struct smbios_type_2 {
     uint8_t product_name_str;
     uint8_t version_str;
     uint8_t serial_number_str;
+    uint8_t asset_tag_str;
+    uint8_t feature_flags;
+    uint8_t location_in_chassis_str;
+    uint16_t chassis_handle;
+    uint8_t board_type;
+    uint8_t contained_handle_count;
+    uint16_t contained_handles[];
 } __attribute__ ((packed));
 
 /* System Enclosure - Contained Elements */
diff --git a/xen/include/public/hvm/hvm_xs_strings.h b/xen/include/public/hvm/hvm_xs_strings.h
index fea1dd4407..fba2546424 100644
--- a/xen/include/public/hvm/hvm_xs_strings.h
+++ b/xen/include/public/hvm/hvm_xs_strings.h
@@ -69,6 +69,12 @@
 #define HVM_XS_SYSTEM_PRODUCT_NAME     "bios-strings/system-product-name"
 #define HVM_XS_SYSTEM_VERSION          "bios-strings/system-version"
 #define HVM_XS_SYSTEM_SERIAL_NUMBER    "bios-strings/system-serial-number"
+#define HVM_XS_BASEBOARD_MANUFACTURER  "bios-strings/baseboard-manufacturer"
+#define HVM_XS_BASEBOARD_PRODUCT_NAME  "bios-strings/baseboard-product-name"
+#define HVM_XS_BASEBOARD_VERSION       "bios-strings/baseboard-version"
+#define HVM_XS_BASEBOARD_SERIAL_NUMBER "bios-strings/baseboard-serial-number"
+#define HVM_XS_BASEBOARD_ASSET_TAG     "bios-strings/baseboard-asset-tag"
+#define HVM_XS_BASEBOARD_LOCATION_IN_CHASSIS "bios-strings/baseboard-location-in-chassis"
 #define HVM_XS_ENCLOSURE_MANUFACTURER  "bios-strings/enclosure-manufacturer"
 #define HVM_XS_ENCLOSURE_SERIAL_NUMBER "bios-strings/enclosure-serial-number"
 #define HVM_XS_ENCLOSURE_ASSET_TAG     "bios-strings/enclosure-asset-tag"
-- 
2.20.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/1] hvmloader: add SMBIOS type 2 info for customized string
  2019-03-28  9:05 Xin Li
@ 2019-03-28 10:48 ` Jan Beulich
  0 siblings, 0 replies; 7+ messages in thread
From: Jan Beulich @ 2019-03-28 10:48 UTC (permalink / raw)
  To: Xin Li; +Cc: Andrew Cooper, Sergey Dyasli, xen-devel, Xin Li, Igor Druzhinin

>>> On 28.03.19 at 10:05, <talons.lee@gmail.com> wrote:
> --- a/tools/firmware/hvmloader/smbios.c
> +++ b/tools/firmware/hvmloader/smbios.c
> @@ -497,9 +497,11 @@ static void *
>  smbios_type_2_init(void *start)
>  {
>      struct smbios_type_2 *p = (struct smbios_type_2 *)start;
> +    const char *s;
>      uint8_t *ptr;
>      void *pts;
>      uint32_t length;
> +    uint32_t counter = 0;

I think this wants to be unsigned int.

> @@ -518,8 +520,71 @@ smbios_type_2_init(void *start)
>          return (start + length);
>      }
>  
> -    /* Only present when passed in */
> -    return start;
> +    memset(p, 0, sizeof(*p));
> +    p->header.type = 2;
> +    p->header.length = sizeof(struct smbios_type_2);
> +    p->header.handle = SMBIOS_HANDLE_TYPE2;
> +    p->feature_flags = 0x09; /* Board is a hosting board and replaceable */
> +    p->chassis_handle = SMBIOS_HANDLE_TYPE3;
> +    p->board_type = 0x0a; /* Motherboard */
> +    start += sizeof(struct smbios_type_2);

sizeof(*p) (also below) please.

> +    s = xenstore_read(HVM_XS_BASEBOARD_MANUFACTURER, NULL);
> +    if ( (s != NULL) && (*s != '\0') )
> +    {
> +        strcpy(start, s);
> +        start += strlen(s) + 1;
> +        p->manufacturer_str = ++counter;
> +    }
> +
> +    s = xenstore_read(HVM_XS_BASEBOARD_PRODUCT_NAME, NULL);
> +    if ( (s != NULL) && (*s != '\0') )
> +    {
> +        strcpy(start, s);
> +        start += strlen(s) + 1;
> +        p->product_name_str = ++counter;
> +    }
> +
> +    s = xenstore_read(HVM_XS_BASEBOARD_VERSION, NULL);
> +    if ( (s != NULL) && (*s != '\0') )
> +    {
> +        strcpy(start, s);
> +        start += strlen(s) + 1;
> +        p->version_str = ++counter;
> +    }
> +
> +    s = xenstore_read(HVM_XS_BASEBOARD_SERIAL_NUMBER, NULL);
> +    if ( (s != NULL) && (*s != '\0') )
> +    {
> +        strcpy(start, s);
> +        start += strlen(s) + 1;
> +        p->serial_number_str = ++counter;
> +    }
> +
> +    s = xenstore_read(HVM_XS_BASEBOARD_ASSET_TAG, NULL);
> +    if ( (s != NULL) && (*s != '\0') )
> +    {
> +        strcpy(start, s);
> +        start += strlen(s) + 1;
> +        p->asset_tag_str = ++counter;
> +    }
> +
> +    s = xenstore_read(HVM_XS_BASEBOARD_LOCATION_IN_CHASSIS, NULL);
> +    if ( (s != NULL) && (*s != '\0') )
> +    {
> +        strcpy(start, s);
> +        start += strlen(s) + 1;
> +        p->location_in_chassis_str = ++counter;
> +    }
> +
> +    if ( counter )
> +    {
> +        *((uint8_t *)start) = 0;
> +        return (start + 1);
> +    }
> +    else
> +        /* Only present when passed in or with customized string */
> +        return (start - sizeof(struct smbios_type_2));

This will work, but is slightly more cumbersome to read than if
you simply used a local variable and kept "start" unchanged. If
the local variable was of "char *" type, you could also avoid the
uint8_t * cast above.

And I think there are a number of unnecessary parentheses in
these last few lines. The "else" is unnecessary as well.

If you don't want to go the route of a separate local variable,
then with the cosmetic issues fixed this patch can have my
Acked-by: Jan Beulich <jbeulich@suse.com>
right away, and these cosmetic adjustments could be done
while committing. But please let me know whether to wait for a
v3 instead.

Jan



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 1/1] hvmloader: add SMBIOS type 2 info for customized string
@ 2019-03-28  9:05 Xin Li
  2019-03-28 10:48 ` Jan Beulich
  0 siblings, 1 reply; 7+ messages in thread
From: Xin Li @ 2019-03-28  9:05 UTC (permalink / raw)
  To: xen-devel
  Cc: Xin Li, Sergey Dyasli, Andrew Cooper, Jan Beulich, Igor Druzhinin

Extend smbios type 2 struct to match specification, add support to
write it when customized string provided and no smbios passed in.

Signed-off-by: Xin Li <xin.li@citrix.com>

---
CC: Jan Beulich <JBeulich@suse.com>
CC: Igor Druzhinin <igor.druzhinin@citrix.com>
CC: Sergey Dyasli <sergey.dyasli@citrix.com>
CC: Andrew Cooper <andrew.cooper3@citrix.com>

v2
1: write the struct if any of the strings is provided
2: add contained_handles as flexible array member
3: update commit message and fix style issue
---
 tools/firmware/hvmloader/smbios.c       | 69 ++++++++++++++++++++++++-
 tools/firmware/hvmloader/smbios_types.h |  7 +++
 xen/include/public/hvm/hvm_xs_strings.h |  6 +++
 3 files changed, 80 insertions(+), 2 deletions(-)

diff --git a/tools/firmware/hvmloader/smbios.c b/tools/firmware/hvmloader/smbios.c
index 40d8399be1..226c38efb2 100644
--- a/tools/firmware/hvmloader/smbios.c
+++ b/tools/firmware/hvmloader/smbios.c
@@ -497,9 +497,11 @@ static void *
 smbios_type_2_init(void *start)
 {
     struct smbios_type_2 *p = (struct smbios_type_2 *)start;
+    const char *s;
     uint8_t *ptr;
     void *pts;
     uint32_t length;
+    uint32_t counter = 0;
 
     pts = get_smbios_pt_struct(2, &length);
     if ( (pts != NULL)&&(length > 0) )
@@ -518,8 +520,71 @@ smbios_type_2_init(void *start)
         return (start + length);
     }
 
-    /* Only present when passed in */
-    return start;
+    memset(p, 0, sizeof(*p));
+    p->header.type = 2;
+    p->header.length = sizeof(struct smbios_type_2);
+    p->header.handle = SMBIOS_HANDLE_TYPE2;
+    p->feature_flags = 0x09; /* Board is a hosting board and replaceable */
+    p->chassis_handle = SMBIOS_HANDLE_TYPE3;
+    p->board_type = 0x0a; /* Motherboard */
+    start += sizeof(struct smbios_type_2);
+
+    s = xenstore_read(HVM_XS_BASEBOARD_MANUFACTURER, NULL);
+    if ( (s != NULL) && (*s != '\0') )
+    {
+        strcpy(start, s);
+        start += strlen(s) + 1;
+        p->manufacturer_str = ++counter;
+    }
+
+    s = xenstore_read(HVM_XS_BASEBOARD_PRODUCT_NAME, NULL);
+    if ( (s != NULL) && (*s != '\0') )
+    {
+        strcpy(start, s);
+        start += strlen(s) + 1;
+        p->product_name_str = ++counter;
+    }
+
+    s = xenstore_read(HVM_XS_BASEBOARD_VERSION, NULL);
+    if ( (s != NULL) && (*s != '\0') )
+    {
+        strcpy(start, s);
+        start += strlen(s) + 1;
+        p->version_str = ++counter;
+    }
+
+    s = xenstore_read(HVM_XS_BASEBOARD_SERIAL_NUMBER, NULL);
+    if ( (s != NULL) && (*s != '\0') )
+    {
+        strcpy(start, s);
+        start += strlen(s) + 1;
+        p->serial_number_str = ++counter;
+    }
+
+    s = xenstore_read(HVM_XS_BASEBOARD_ASSET_TAG, NULL);
+    if ( (s != NULL) && (*s != '\0') )
+    {
+        strcpy(start, s);
+        start += strlen(s) + 1;
+        p->asset_tag_str = ++counter;
+    }
+
+    s = xenstore_read(HVM_XS_BASEBOARD_LOCATION_IN_CHASSIS, NULL);
+    if ( (s != NULL) && (*s != '\0') )
+    {
+        strcpy(start, s);
+        start += strlen(s) + 1;
+        p->location_in_chassis_str = ++counter;
+    }
+
+    if ( counter )
+    {
+        *((uint8_t *)start) = 0;
+        return (start + 1);
+    }
+    else
+        /* Only present when passed in or with customized string */
+        return (start - sizeof(struct smbios_type_2));
 }
 
 /* Type 3 -- System Enclosure */
diff --git a/tools/firmware/hvmloader/smbios_types.h b/tools/firmware/hvmloader/smbios_types.h
index acb63e2fe9..7c648ece71 100644
--- a/tools/firmware/hvmloader/smbios_types.h
+++ b/tools/firmware/hvmloader/smbios_types.h
@@ -90,6 +90,13 @@ struct smbios_type_2 {
     uint8_t product_name_str;
     uint8_t version_str;
     uint8_t serial_number_str;
+    uint8_t asset_tag_str;
+    uint8_t feature_flags;
+    uint8_t location_in_chassis_str;
+    uint16_t chassis_handle;
+    uint8_t board_type;
+    uint8_t contained_handle_count;
+    uint16_t contained_handles[];
 } __attribute__ ((packed));
 
 /* System Enclosure - Contained Elements */
diff --git a/xen/include/public/hvm/hvm_xs_strings.h b/xen/include/public/hvm/hvm_xs_strings.h
index fea1dd4407..fba2546424 100644
--- a/xen/include/public/hvm/hvm_xs_strings.h
+++ b/xen/include/public/hvm/hvm_xs_strings.h
@@ -69,6 +69,12 @@
 #define HVM_XS_SYSTEM_PRODUCT_NAME     "bios-strings/system-product-name"
 #define HVM_XS_SYSTEM_VERSION          "bios-strings/system-version"
 #define HVM_XS_SYSTEM_SERIAL_NUMBER    "bios-strings/system-serial-number"
+#define HVM_XS_BASEBOARD_MANUFACTURER  "bios-strings/baseboard-manufacturer"
+#define HVM_XS_BASEBOARD_PRODUCT_NAME  "bios-strings/baseboard-product-name"
+#define HVM_XS_BASEBOARD_VERSION       "bios-strings/baseboard-version"
+#define HVM_XS_BASEBOARD_SERIAL_NUMBER "bios-strings/baseboard-serial-number"
+#define HVM_XS_BASEBOARD_ASSET_TAG     "bios-strings/baseboard-asset-tag"
+#define HVM_XS_BASEBOARD_LOCATION_IN_CHASSIS "bios-strings/baseboard-location-in-chassis"
 #define HVM_XS_ENCLOSURE_MANUFACTURER  "bios-strings/enclosure-manufacturer"
 #define HVM_XS_ENCLOSURE_SERIAL_NUMBER "bios-strings/enclosure-serial-number"
 #define HVM_XS_ENCLOSURE_ASSET_TAG     "bios-strings/enclosure-asset-tag"
-- 
2.20.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-04-01  1:24 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-28 13:56 [PATCH v2 1/1] hvmloader: add SMBIOS type 2 info for customized string Xin Li
2019-03-28 14:26 ` Jan Beulich
  -- strict thread matches above, loose matches on Subject: below --
2019-03-29  3:28 Xin Li
2019-03-29 11:08 ` Jan Beulich
2019-04-01  1:24   ` Xin Li (Talons)
2019-03-28  9:05 Xin Li
2019-03-28 10:48 ` Jan Beulich

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.