[PATCH v3 2/5] dmi: Add a DMI firmware node and handling
From: minyard
Date: Wed Apr 27 2016 - 09:04:52 EST
From: Corey Minyard <cminyard@xxxxxxxxxx>
This is so that an IPMI platform device can be created from a
DMI firmware entry.
Signed-off-by: Corey Minyard <cminyard@xxxxxxxxxx>
Cc: Jean Delvare <jdelvare@xxxxxxx>
Cc: Andy Lutomirski <luto@xxxxxxxxxx>
Tested-by: Andy Lutomirski <luto@xxxxxxxxxx>
---
drivers/firmware/dmi_scan.c | 16 ++++++++++------
include/linux/dmi.h | 14 ++++++++++++++
include/linux/fwnode.h | 1 +
3 files changed, 25 insertions(+), 6 deletions(-)
diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
index da471b2..5519b4f 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 8516717..8690de2 100644
--- a/include/linux/fwnode.h
+++ b/include/linux/fwnode.h
@@ -19,6 +19,7 @@ enum fwnode_type {
FWNODE_ACPI_DATA,
FWNODE_PDATA,
FWNODE_IRQCHIP,
+ FWNODE_DMI,
};
struct fwnode_handle {
--
2.7.4