SMBIOS type 9 descriptor implementation
cover SMBIOS type 9 descriptor implementation
This patch series implements SMBIOS type 9 descriptor, system slots. For each system slot, we can assign one descriptor for it if needed. In versions later than 2.6, a new PCI device field was added to make sure the descriptor is associated with a certain device, if provided.
For ease of usage, qemu-options.hx was updated.
Felix Wu (2):
Implement base of SMBIOS type 9 descriptor.
Implement SMBIOS type 9 v2.6
hw/smbios/smbios.c | 142 +++++++++++++++++++++++++++++++++++ include/hw/firmware/smbios.h | 17 +++++ qemu-options.hx | 3 + 3 files changed, 162 insertions(+)
Signature · 1 line
2.44.0.rc0.258.g7320e95886-goog
PATCH 1/2 Implement base of SMBIOS type 9 descriptor.
From: Felix Wu <[email protected]>
Version 2.1+.
--- hw/smbios/smbios.c | 99 ++++++++++++++++++++++++++++++++++++ include/hw/firmware/smbios.h | 13 +++++ qemu-options.hx | 3 ++ 3 files changed, 115 insertions(+)
hw/smbios/smbios.c +99 -0
@@ -121,6 +121,16 @@ struct type8_instance { }; static QTAILQ_HEAD(, type8_instance) type8 = QTAILQ_HEAD_INITIALIZER(type8); +/* type 9 instance for parsing */ +struct type9_instance { +const char *slot_designation; +uint8_t slot_type, slot_data_bus_width, current_usage, slot_length, + slot_characteristics1, slot_characteristics2; +uint16_t slot_id; +QTAILQ_ENTRY (type9_instance) next; +}; +static QTAILQ_HEAD(, type9_instance) type9 = QTAILQ_HEAD_INITIALIZER(type9); + static struct { size_t nvalues; char **values;
@@ -380,6 +390,54 @@ static const QemuOptDesc qemu_smbios_type8_opts[] = { {/* end of list */ } }; +static const QemuOptDesc qemu_smbios_type9_opts[] = { + { + .name ="type" , + .type =QEMU_OPT_NUMBER , + .help ="SMBIOS element type" , + }, + { + .name ="slot_designation" , + .type =QEMU_OPT_STRING , + .help ="string number for reference designation" , + }, + { + .name ="slot_type" , + .type =QEMU_OPT_NUMBER , + .help ="connector type" , + }, + { + .name ="slot_data_bus_width" , + .type =QEMU_OPT_NUMBER , + .help ="port type" , + }, + { + .name ="current_usage" , + .type =QEMU_OPT_NUMBER , + .help ="current usage" , + }, + { + .name ="slot_length" , + .type =QEMU_OPT_NUMBER , + .help ="system slot length" , + }, + { + .name ="slot_id" , + .type =QEMU_OPT_NUMBER , + .help ="system slot id" , + }, + { + .name ="slot_characteristics1" , + .type =QEMU_OPT_NUMBER , + .help ="slot characteristics1, see the spec" , + }, + { + .name ="slot_characteristics2" , + .type =QEMU_OPT_NUMBER , + .help ="slot characteristics2, see the spec" , + }, +}; +static const QemuOptDesc qemu_smbios_type11_opts[] = { { .name ="type" ,
@@ -609,6 +667,7 @@ bool smbios_skip_table(uint8_t type, bool required_table)#define T2_BASE 0x200#define T3_BASE 0x300#define T4_BASE 0x400 +#define T9_BASE 0x900#define T11_BASE 0xe00#define T16_BASE 0x1000
@@ -807,6 +866,28 @@ static void smbios_build_type_8_table(void) } } +static void smbios_build_type_9_table (void ) +{ +unsigned instance =0 ; +struct type9_instance *t9; + + QTAILQ_FOREACH(t9, &type9, next) { +SMBIOS_BUILD_TABLE_PRE (9 ,T9_BASE + instance, true); + +SMBIOS_TABLE_SET_STR (9 , slot_designation, t9->slot_designation); + t->slot_type = t9->slot_type; + t->slot_data_bus_width = t9->slot_data_bus_width; + t->current_usage = t9->current_usage; + t->slot_length = t9->slot_length; + t->slot_id = t9->slot_id; + t->slot_characteristics1 = t9->slot_characteristics1; + t->slot_characteristics2 = t9->slot_characteristics2; + +SMBIOS_BUILD_TABLE_POST ; + instance++; + } +} +static void smbios_build_type_11_table (void ) {char count_str[128 ];
@@ -1126,6 +1207,7 @@ void smbios_get_tables(MachineState *ms, }smbios_build_type_8_table (); +smbios_build_type_9_table ();smbios_build_type_11_table ();#define MAX_DIMM_SZ (16 * GiB)
@@ -1460,6 +1542,23 @@ void smbios_entry_add(QemuOpts *opts, Error **errp) t8_i->port_type =qemu_opt_get_number (opts,"port_type" ,0 );QTAILQ_INSERT_TAIL (&type8, t8_i, next);return ; +case 9 : { +if (!qemu_opts_validate (opts, qemu_smbios_type9_opts, errp)) { +return ; + } +struct type9_instance *t; + t = g_new0(struct type9_instance, 1); +save_opt (&t->slot_designation, opts,"slot_designation" ); + t->slot_type =qemu_opt_get_number (opts,"slot_type" ,0 ); + t->slot_data_bus_width =qemu_opt_get_number (opts,"slot_data_bus_width" ,0 ); + t->current_usage =qemu_opt_get_number (opts,"current_usage" ,0 ); + t->slot_length =qemu_opt_get_number (opts,"slot_length" ,0 ); + t->slot_id =qemu_opt_get_number (opts,"slot_id" ,0 ); + t->slot_characteristics1 =qemu_opt_get_number (opts,"slot_characteristics1" ,0 ); + t->slot_characteristics2 =qemu_opt_get_number (opts,"slot_characteristics2" ,0 ); +QTAILQ_INSERT_TAIL (&type9, t, next); +return ; + }case 11 :if (!qemu_opts_validate (opts, qemu_smbios_type11_opts, errp)) {return ;
include/hw/firmware/smbios.h +13 -0
@@ -211,6 +211,19 @@ struct smbios_type_8 {uint8_t port_type; }QEMU_PACKED ; +/* SMBIOS type 9 - System Slots (v2.1+) */ +struct smbios_type_9 { +struct smbios_structure_header header; +uint8_t slot_designation; +uint8_t slot_type; +uint8_t slot_data_bus_width; +uint8_t current_usage; +uint8_t slot_length; +uint16_t slot_id; +uint8_t slot_characteristics1; +uint8_t slot_characteristics2; +}QEMU_PACKED ; +/* SMBIOS type 11 - OEM strings */ struct smbios_type_11 {struct smbios_structure_header header;
qemu-options.hx +3 -0
@@ -2717,6 +2717,9 @@ SRST ``-smbios type=4[,sock_pfx=str][,manufacturer=str][,version=str][,serial=str][,asset=str][,part=str][,processor-family=%d][,processor-id=%d]`` Specify SMBIOS type 4 fields +``-smbios type=9[,slot_designation=str][,slot_type=%d][,slot_data_bus_width=%d][,current_usage=%d][,slot_length=%d][,slot_id=%d][,slot_characteristics1=%d][,slot_characteristics12=%d]`` + Specify SMBIOS type 9 fields + ``-smbios type=11[,value=str][,path=filename]`` Specify SMBIOS type 11 fields
Signature · 1 line
2.44.0.rc0.258.g7320e95886-goog
PATCH 2/2 Implement SMBIOS type 9 v2.6
In reply to Nabih EstefanFrom: Felix Wu <[email protected]>
--- hw/smbios/smbios.c | 49 +++++++++++++++++++++++++++++++++--- include/hw/firmware/smbios.h | 4 +++ qemu-options.hx | 2 +- 3 files changed, 51 insertions(+), 4 deletions(-)
hw/smbios/smbios.c +46 -3
@@ -123,7 +123,7 @@ static QTAILQ_HEAD(, type8_instance) type8 = QTAILQ_HEAD_INITIALIZER(type8);/* type 9 instance for parsing */ struct type9_instance { -const char *slot_designation; +const char *slot_designation, *pcidev;uint8_t slot_type, slot_data_bus_width, current_usage, slot_length, slot_characteristics1, slot_characteristics2;uint16_t slot_id;
@@ -436,6 +436,11 @@ static const QemuOptDesc qemu_smbios_type9_opts[] = { .type = QEMU_OPT_NUMBER, .help = "slot characteristics2, see the spec", }, + { + .name = "pci_device", + .type = QEMU_OPT_STRING, + .help = "PCI device, if provided." + } }; static const QemuOptDesc qemu_smbios_type11_opts[] = {
@@ -866,7 +871,7 @@ static void smbios_build_type_8_table(void) } } -static void smbios_build_type_9_table (void ) +static void smbios_build_type_9_table (Error **errp) {unsigned instance =0 ;struct type9_instance *t9;
@@ -883,6 +888,43 @@ static void smbios_build_type_9_table(void) t->slot_characteristics1 = t9->slot_characteristics1; t->slot_characteristics2 = t9->slot_characteristics2; +if (t9->pcidev) { +PCIDevice *pdev =NULL ; +int rc =pci_qdev_find_device (t9->pcidev, &pdev); +if (rc !=0 ) { +error_setg (errp, +"No PCI device %s for SMBIOS type 9 entry %s" , + t9->pcidev, t9->slot_designation); +return ; + } +/* +* We only handle the case were the device is attached to +* the PCI root bus. The general case is more complex as +* bridges are enumerated later and the table would need +* to be updated at this moment. +*/ +if (!pci_bus_is_root (pci_get_bus (pdev))) { +error_setg (errp, +"Cannot create type 9 entry for PCI device %s: " +"not attached to the root bus" , + t9->pcidev); +return ; + } + t->segment_group_number =cpu_to_le16 (0 ); + t->bus_number =pci_dev_bus_num (pdev); + t->device_number = pdev->devfn; + }else { +/* +* Per SMBIOS spec, For slots that are not of the PCI, AGP, PCI-X, +* or PCI-Express type that do not have bus/device/function +* information, 0FFh should be populated in the fields of Segment +* Group Number, Bus Number, Device/Function Number. +*/ + t->segment_group_number =0xff ; + t->bus_number =0xff ; + t->device_number =0xff ; + } +SMBIOS_BUILD_TABLE_POST ; instance++; }
@@ -1207,7 +1249,7 @@ void smbios_get_tables(MachineState *ms, }smbios_build_type_8_table (); -smbios_build_type_9_table (); +smbios_build_type_9_table (errp);smbios_build_type_11_table ();#define MAX_DIMM_SZ (16 * GiB)
@@ -1556,6 +1598,7 @@ void smbios_entry_add(QemuOpts *opts, Error **errp) t->slot_id =qemu_opt_get_number (opts,"slot_id" ,0 ); t->slot_characteristics1 =qemu_opt_get_number (opts,"slot_characteristics1" ,0 ); t->slot_characteristics2 =qemu_opt_get_number (opts,"slot_characteristics2" ,0 ); +save_opt (&t->pcidev, opts,"pcidev" );QTAILQ_INSERT_TAIL (&type9, t, next);return ; }
include/hw/firmware/smbios.h +4 -0
@@ -222,6 +222,10 @@ struct smbios_type_9 {uint16_t slot_id;uint8_t slot_characteristics1;uint8_t slot_characteristics2; +/* SMBIOS spec v2.6+ */ +uint16_t segment_group_number; +uint8_t bus_number; +uint8_t device_number; }QEMU_PACKED ;/* SMBIOS type 11 - OEM strings */
qemu-options.hx +1 -1
@@ -2717,7 +2717,7 @@ SRST ``-smbios type=4[,sock_pfx=str][,manufacturer=str][,version=str][,serial=str][,asset=str][,part=str][,processor-family=%d][,processor-id=%d]`` Specify SMBIOS type 4 fields -``-smbios type=9[,slot_designation=str][,slot_type=%d][,slot_data_bus_width=%d][,current_usage=%d][,slot_length=%d][,slot_id=%d][,slot_characteristics1=%d][,slot_characteristics12=%d]`` +``-smbios type=9[,slot_designation=str][,slot_type=%d][,slot_data_bus_width=%d][,current_usage=%d][,slot_length=%d][,slot_id=%d][,slot_characteristics1=%d][,slot_characteristics12=%d][,pci_device=str]`` Specify SMBIOS type 9 fields ``-smbios type=11[,value=str][,path=filename]``
Signature · 1 line
2.44.0.rc0.258.g7320e95886-goog
Friendly ping on review for this patchset!
It's been ~2 weeks since it was sent out, please let us know if there's any changes that should be done to upstream it!
Thanks,
Nabih Estefan
Nabih Estefan (he/him) | Software Engineer |
[email protected] | 857-308-9574
Quoted 19 lines · Nabih Estefan
This patch series implements SMBIOS type 9 descriptor, system slots. For each system slot, we can assign one descriptor for it if needed. In versions later than 2.6, a new PCI device field was added to make sure the descriptor is associated with a certain device, if provided.
For ease of usage, qemu-options.hx was updated.Felix Wu (2):
Implement base of SMBIOS type 9 descriptor.
Implement SMBIOS type 9 v2.6hw/smbios/smbios.c | 142 +++++++++++++++++++++++++++++++++++ include/hw/firmware/smbios.h | 17 +++++ qemu-options.hx | 3 + 3 files changed, 162 insertions(+)--
2.44.0.rc0.258.g7320e95886-goog