From f5b9369720ac0458be13e723468e27ab987b439e Mon Sep 17 00:00:00 2001
From: Patrick Rudolph <patrick.rudolph@9elements.com>
Date: Fri, 12 Apr 2019 15:59:40 +0200
Subject: smbios: Walk over PCI devicetree to fill type 9

Use the devicetree values for type 9 slots.

Tested on Lenovo T520.

Change-Id: I1961d8af2d21f755ff52ad58804ea9b31d2a5b9b
Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/32308
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: HAOUAS Elyes <ehaouas@noos.fr>
Reviewed-by: Philipp Deppenwiese <zaolin.daisuki@gmail.com>
---
 src/arch/x86/smbios.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)

(limited to 'src')

diff --git a/src/arch/x86/smbios.c b/src/arch/x86/smbios.c
index 7c87c693e1..589f4f0e30 100644
--- a/src/arch/x86/smbios.c
+++ b/src/arch/x86/smbios.c
@@ -999,6 +999,56 @@ static int smbios_write_type127(unsigned long *current, int handle)
 	return len;
 }
 
+/* Generate Type9 entries from devicetree */
+static int smbios_walk_device_tree_type9(struct device *dev, int *handle,
+					 unsigned long *current)
+{
+	enum misc_slot_usage usage;
+	enum slot_data_bus_bandwidth bandwidth;
+	enum misc_slot_type type;
+	enum misc_slot_length length;
+
+	if (dev->path.type != DEVICE_PATH_PCI)
+		return 0;
+
+	if (!dev->smbios_slot_type && !dev->smbios_slot_data_width &&
+	    !dev->smbios_slot_designation && !dev->smbios_slot_length)
+		return 0;
+
+	if (dev_is_active_bridge(dev))
+		usage = SlotUsageInUse;
+	else if (dev->enabled)
+		usage = SlotUsageAvailable;
+	else
+		usage = SlotUsageUnknown;
+
+	if (dev->smbios_slot_data_width)
+		bandwidth = dev->smbios_slot_data_width;
+	else
+		bandwidth = SlotDataBusWidthUnknown;
+
+	if (dev->smbios_slot_type)
+		type = dev->smbios_slot_type;
+	else
+		type = SlotTypeUnknown;
+
+	if (dev->smbios_slot_length)
+		length = dev->smbios_slot_length;
+	else
+		length = SlotLengthUnknown;
+
+	return smbios_write_type9(current, handle,
+				  dev->smbios_slot_designation,
+				  type,
+				  bandwidth,
+				  usage,
+				  length,
+				  1,
+				  0,
+				  dev->bus->secondary,
+				  dev->path.pci.devfn);
+}
+
 static int smbios_walk_device_tree(struct device *tree, int *handle,
 	unsigned long *current)
 {
@@ -1011,6 +1061,7 @@ static int smbios_walk_device_tree(struct device *tree, int *handle,
 				dev_name(dev));
 			len += dev->ops->get_smbios_data(dev, handle, current);
 		}
+		len += smbios_walk_device_tree_type9(dev, handle, current);
 	}
 	return len;
 }
-- 
cgit v1.2.3