SMBIOS: Introduce struct for SMBIOS table header

All SMBIOS `type X` tables start with the same 4-byte header. Add a
struct definition for it, and use it where applicable. The union is
temporary and allows doing the necessary changes in smaller commits.

Change-Id: Ibd9a80010f83fd7ebefc014b981d430f5723808c
Signed-off-by: Angel Pons <th3fanbus@gmail.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/55906
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org>
diff --git a/src/drivers/wifi/generic/smbios.c b/src/drivers/wifi/generic/smbios.c
index b819116..96b11d3 100644
--- a/src/drivers/wifi/generic/smbios.c
+++ b/src/drivers/wifi/generic/smbios.c
@@ -10,9 +10,14 @@
 static int smbios_write_intel_wifi(struct device *dev, int *handle, unsigned long *current)
 {
 	struct smbios_type_intel_wifi {
-		u8 type;
-		u8 length;
-		u16 handle;
+		union {
+			struct {
+				u8 type;
+				u8 length;
+				u16 handle;
+			};
+			struct smbios_header header;
+		};
 		u8 str;
 		u8 eos[2];
 	} __packed;
diff --git a/src/include/smbios.h b/src/include/smbios.h
index e5e5df5..1e307c8 100644
--- a/src/include/smbios.h
+++ b/src/include/smbios.h
@@ -276,10 +276,21 @@
 	u64 struct_table_address;
 } __packed;
 
-struct smbios_type0 {
+struct smbios_header {
 	u8 type;
 	u8 length;
 	u16 handle;
+} __packed;
+
+struct smbios_type0 {
+	union {
+		struct {
+			u8 type;
+			u8 length;
+			u16 handle;
+		};
+		struct smbios_header header;
+	};
 	u8 vendor;
 	u8 bios_version;
 	u16 bios_start_segment;
@@ -297,9 +308,14 @@
 } __packed;
 
 struct smbios_type1 {
-	u8 type;
-	u8 length;
-	u16 handle;
+	union {
+		struct {
+			u8 type;
+			u8 length;
+			u16 handle;
+		};
+		struct smbios_header header;
+	};
 	u8 manufacturer;
 	u8 product_name;
 	u8 version;
@@ -334,9 +350,14 @@
 } smbios_board_type;
 
 struct smbios_type2 {
-	u8 type;
-	u8 length;
-	u16 handle;
+	union {
+		struct {
+			u8 type;
+			u8 length;
+			u16 handle;
+		};
+		struct smbios_header header;
+	};
 	u8 manufacturer;
 	u8 product_name;
 	u8 version;
@@ -389,9 +410,14 @@
 } smbios_enclosure_type;
 
 struct smbios_type3 {
-	u8 type;
-	u8 length;
-	u16 handle;
+	union {
+		struct {
+			u8 type;
+			u8 length;
+			u16 handle;
+		};
+		struct smbios_header header;
+	};
 	u8 manufacturer;
 	u8 _type;
 	u8 version;
@@ -411,9 +437,14 @@
 } __packed;
 
 struct smbios_type4 {
-	u8 type;
-	u8 length;
-	u16 handle;
+	union {
+		struct {
+			u8 type;
+			u8 length;
+			u16 handle;
+		};
+		struct smbios_header header;
+	};
 	u8 socket_designation;
 	u8 processor_type;
 	u8 processor_family;
@@ -524,9 +555,14 @@
 #define SMBIOS_CACHE_OP_MODE_UNKNOWN 3
 
 struct smbios_type7 {
-	u8 type;
-	u8 length;
-	u16 handle;
+	union {
+		struct {
+			u8 type;
+			u8 length;
+			u16 handle;
+		};
+		struct smbios_header header;
+	};
 	u8 socket_designation;
 	u16 cache_configuration;
 	u16 max_cache_size;
@@ -640,9 +676,14 @@
 };
 
 struct smbios_type8 {
-	u8 type;
-	u8 length;
-	u16 handle;
+	union {
+		struct {
+			u8 type;
+			u8 length;
+			u16 handle;
+		};
+		struct smbios_header header;
+	};
 	u8 internal_reference_designator;
 	u8 internal_connector_type;
 	u8 external_reference_designator;
@@ -777,9 +818,14 @@
 } __packed;
 
 struct smbios_type9 {
-	u8 type;
-	u8 length;
-	u16 handle;
+	union {
+		struct {
+			u8 type;
+			u8 length;
+			u16 handle;
+		};
+		struct smbios_header header;
+	};
 	u8 slot_designation;
 	u8 slot_type;
 	u8 slot_data_bus_width;
@@ -798,17 +844,27 @@
 } __packed;
 
 struct smbios_type11 {
-	u8 type;
-	u8 length;
-	u16 handle;
+	union {
+		struct {
+			u8 type;
+			u8 length;
+			u16 handle;
+		};
+		struct smbios_header header;
+	};
 	u8 count;
 	u8 eos[2];
 } __packed;
 
 struct smbios_type15 {
-	u8 type;
-	u8 length;
-	u16 handle;
+	union {
+		struct {
+			u8 type;
+			u8 length;
+			u16 handle;
+		};
+		struct smbios_header header;
+	};
 	u16 area_length;
 	u16 header_offset;
 	u16 data_offset;
@@ -838,9 +894,14 @@
 #define SMBIOS_USE_EXTENDED_MAX_CAPACITY	(1 << 31)
 
 struct smbios_type16 {
-	u8 type;
-	u8 length;
-	u16 handle;
+	union {
+		struct {
+			u8 type;
+			u8 length;
+			u16 handle;
+		};
+		struct smbios_header header;
+	};
 	u8 location;
 	u8 use;
 	u8 memory_error_correction;
@@ -852,9 +913,14 @@
 } __packed;
 
 struct smbios_type17 {
-	u8 type;
-	u8 length;
-	u16 handle;
+	union {
+		struct {
+			u8 type;
+			u8 length;
+			u16 handle;
+		};
+		struct smbios_header header;
+	};
 	u16 phys_memory_array_handle;
 	u16 memory_error_information_handle;
 	u16 total_width;
@@ -881,9 +947,14 @@
 } __packed;
 
 struct smbios_type19 {
-	u8 type;
-	u8 length;
-	u16 handle;
+	union {
+		struct {
+			u8 type;
+			u8 length;
+			u16 handle;
+		};
+		struct smbios_header header;
+	};
 	u32 starting_address;
 	u32 ending_address;
 	u16 memory_array_handle;
@@ -894,18 +965,28 @@
 } __packed;
 
 struct smbios_type32 {
-	u8 type;
-	u8 length;
-	u16 handle;
+	union {
+		struct {
+			u8 type;
+			u8 length;
+			u16 handle;
+		};
+		struct smbios_header header;
+	};
 	u8 reserved[6];
 	u8 boot_status;
 	u8 eos[2];
 } __packed;
 
 struct smbios_type38 {
-	u8 type;
-	u8 length;
-	u16 handle;
+	union {
+		struct {
+			u8 type;
+			u8 length;
+			u16 handle;
+		};
+		struct smbios_header header;
+	};
 	u8 interface_type;
 	u8 ipmi_rev;
 	u8 i2c_slave_addr;
@@ -940,9 +1021,14 @@
 #define SMBIOS_DEVICE_TYPE_COUNT 10
 
 struct smbios_type41 {
-	u8 type;
-	u8 length;
-	u16 handle;
+	union {
+		struct {
+			u8 type;
+			u8 length;
+			u16 handle;
+		};
+		struct smbios_header header;
+	};
 	u8 reference_designation;
 	u8 device_type: 7;
 	u8 device_status: 1;
@@ -955,9 +1041,14 @@
 } __packed;
 
 struct smbios_type127 {
-	u8 type;
-	u8 length;
-	u16 handle;
+	union {
+		struct {
+			u8 type;
+			u8 length;
+			u16 handle;
+		};
+		struct smbios_header header;
+	};
 	u8 eos[2];
 } __packed;