[v5,2/5] dmi: Add a DMI firmware node and handling

Message ID 1495050984-5602-3-git-send-email-minyard@acm.org
State New
Headers show
Series
  • [v5,1/5] dmi: remove const from return of dmi_find_device
Related show

Commit Message

Corey Minyard May 17, 2017, 7:56 p.m.
From: Corey Minyard <cminyard@mvista.com>


This is so that an IPMI platform device can be created from a
DMI firmware entry.

Signed-off-by: Corey Minyard <cminyard@mvista.com>

Cc: Jean Delvare <jdelvare@suse.de>
Cc: Andy Lutomirski <luto@kernel.org>
Tested-by: Andy Lutomirski <luto@kernel.org>

---
 drivers/firmware/dmi_scan.c | 16 ++++++++++------
 include/linux/dmi.h         | 14 ++++++++++++++
 include/linux/fwnode.h      |  3 ++-
 3 files changed, 26 insertions(+), 7 deletions(-)

-- 
2.7.4

Patch hide | download patch | download mbox

diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
index a29e96a..78ef357 100644
--- a/drivers/firmware/dmi_scan.c
+++ b/drivers/firmware/dmi_scan.c
@@ -242,6 +242,12 @@  static void __init dmi_save_type(const struct dmi_header *dm, int slot,
 	dmi_ident[slot] = s;
 }
 
+static void __init dmi_devices_list_add(struct dmi_device *dev)
+{
+	dev->fwnode.type = FWNODE_DMI;
+	list_add(&dev->list, &dmi_devices);
+}
+
 static void __init dmi_save_one_device(int type, const char *name)
 {
 	struct dmi_device *dev;
@@ -257,8 +263,7 @@  static void __init dmi_save_one_device(int type, const char *name)
 	dev->type = type;
 	strcpy((char *)(dev + 1), name);
 	dev->name = (char *)(dev + 1);
-	dev->device_data = NULL;
-	list_add(&dev->list, &dmi_devices);
+	dmi_devices_list_add(dev);
 }
 
 static void __init dmi_save_devices(const struct dmi_header *dm)
@@ -293,9 +298,8 @@  static void __init dmi_save_oem_strings_devices(const struct dmi_header *dm)
 
 		dev->type = DMI_DEV_TYPE_OEM_STRING;
 		dev->name = devname;
-		dev->device_data = NULL;
 
-		list_add(&dev->list, &dmi_devices);
+		dmi_devices_list_add(dev);
 	}
 }
 
@@ -318,7 +322,7 @@  static void __init dmi_save_ipmi_device(const struct dmi_header *dm)
 	dev->name = "IPMI controller";
 	dev->device_data = data;
 
-	list_add_tail(&dev->list, &dmi_devices);
+	dmi_devices_list_add(dev);
 }
 
 static void __init dmi_save_dev_pciaddr(int instance, int segment, int bus,
@@ -345,7 +349,7 @@  static void __init dmi_save_dev_pciaddr(int instance, int segment, int bus,
 	dev->dev.name = (char *)&dev[1];
 	dev->dev.device_data = dev;
 
-	list_add(&dev->dev.list, &dmi_devices);
+	dmi_devices_list_add(&dev->dev);
 }
 
 static void __init dmi_save_extended_devices(const struct dmi_header *dm)
diff --git a/include/linux/dmi.h b/include/linux/dmi.h
index a930a4d..c8dd5b8 100644
--- a/include/linux/dmi.h
+++ b/include/linux/dmi.h
@@ -4,6 +4,7 @@ 
 #include <linux/list.h>
 #include <linux/kobject.h>
 #include <linux/mod_devicetable.h>
+#include <linux/fwnode.h>
 
 /* enum dmi_field is in mod_devicetable.h */
 
@@ -80,6 +81,7 @@  struct dmi_header {
 
 struct dmi_device {
 	struct list_head list;
+	struct fwnode_handle fwnode;
 	int type;
 	const char *name;
 	void *device_data;	/* Type specific data */
@@ -113,6 +115,18 @@  extern int dmi_walk(void (*decode)(const struct dmi_header *, void *),
 extern bool dmi_match(enum dmi_field f, const char *str);
 extern void dmi_memdev_name(u16 handle, const char **bank, const char **device);
 
+static inline bool is_dmi_fwnode(struct fwnode_handle *fwnode)
+{
+	return fwnode && fwnode->type == FWNODE_DMI;
+}
+
+static inline struct dmi_device *to_dmi_device(struct fwnode_handle *fwnode)
+{
+	if (is_dmi_fwnode(fwnode))
+		return container_of(fwnode, struct dmi_device, fwnode);
+	return NULL;
+}
+
 #else
 
 static inline int dmi_check_system(const struct dmi_system_id *list) { return 0; }
diff --git a/include/linux/fwnode.h b/include/linux/fwnode.h
index 3dff239..630c1ef 100644
--- a/include/linux/fwnode.h
+++ b/include/linux/fwnode.h
@@ -19,7 +19,8 @@  enum fwnode_type {
 	FWNODE_ACPI_DATA,
 	FWNODE_ACPI_STATIC,
 	FWNODE_PDATA,
-	FWNODE_IRQCHIP
+	FWNODE_IRQCHIP,
+	FWNODE_DMI
 };
 
 struct fwnode_handle {