From patchwork Fri Jan 29 22:43:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 60843 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp1415946lbb; Fri, 29 Jan 2016 15:44:03 -0800 (PST) X-Received: by 10.67.14.168 with SMTP id fh8mr17592940pad.11.1454111043367; Fri, 29 Jan 2016 15:44:03 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bc9si5064585pad.140.2016.01.29.15.44.03; Fri, 29 Jan 2016 15:44:03 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756268AbcA2XoA (ORCPT + 30 others); Fri, 29 Jan 2016 18:44:00 -0500 Received: from vms173021pub.verizon.net ([206.46.173.21]:52266 "EHLO vms173021pub.verizon.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755927AbcA2Xn6 (ORCPT ); Fri, 29 Jan 2016 18:43:58 -0500 X-Greylist: delayed 3602 seconds by postgrey-1.27 at vger.kernel.org; Fri, 29 Jan 2016 18:43:57 EST Received: from serve.minyard.net ([173.57.176.17]) by vms173021.mailsrvcs.net (Oracle Communications Messaging Server 7.0.5.32.0 64bit (built Jul 16 2014)) with ESMTPA id <0O1Q00HZ2KGCI380@vms173021.mailsrvcs.net> for linux-kernel@vger.kernel.org; Fri, 29 Jan 2016 16:43:31 -0600 (CST) X-CMAE-Score: 0 X-CMAE-Analysis: v=2.1 cv=Nc0brD34 c=1 sm=1 tr=0 a=bXmWQgKa9n63w7XTPFb8JQ==:117 a=7aQ_Q-yQQ-AA:10 a=fk1lIlRQAAAA:8 a=VwQbUJbxAAAA:8 a=bJhvGbxDW82cPSu1DBQA:9 a=mw4tGAyqSR1U-A0q:21 a=cgBZtDhATazH7heT:21 Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id 9DA4E17A6; Fri, 29 Jan 2016 16:43:24 -0600 (CST) Received: by t430.minyard.net (Postfix, from userid 1000) id 4E91130002C; Fri, 29 Jan 2016 16:43:22 -0600 (CST) From: minyard@acm.org To: openipmi-developer@lists.sourceforge.net, linux-kernel@vger.kernel.org Cc: Jean Delvare , Andy Lutomirski , Corey Minyard Subject: [PATCH 2/4] dmi: Add a DMI firmware node and handling Date: Fri, 29 Jan 2016 16:43:12 -0600 Message-id: <1454107394-8914-3-git-send-email-minyard@acm.org> X-Mailer: git-send-email 2.5.0 In-reply-to: <1454107394-8914-1-git-send-email-minyard@acm.org> References: <1454107394-8914-1-git-send-email-minyard@acm.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Corey Minyard This is so that an IPMI platform device can be created from a DMI firmware entry. Signed-off-by: Corey Minyard Cc: Jean Delvare Cc: Andy Lutomirski --- drivers/firmware/dmi_scan.c | 34 ++++++++++++++++++++++++---------- include/linux/dmi.h | 24 ++++++++++++++++++++++++ include/linux/fwnode.h | 1 + 3 files changed, 49 insertions(+), 10 deletions(-) -- 2.5.0 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c index da471b2..13d9bca 100644 --- a/drivers/firmware/dmi_scan.c +++ b/drivers/firmware/dmi_scan.c @@ -41,6 +41,16 @@ static struct dmi_memdev_info { } *dmi_memdev; static int dmi_memdev_nr; +static void *dmi_zalloc(unsigned len) +{ + void *ret = dmi_alloc(len); + + if (ret) + memset(ret, 0, len); + + return ret; +} + static const char * __init dmi_string_nosave(const struct dmi_header *dm, u8 s) { const u8 *bp = ((u8 *) dm) + dm->length; @@ -242,6 +252,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; @@ -250,15 +266,14 @@ static void __init dmi_save_one_device(int type, const char *name) if (dmi_find_device(type, name, NULL)) return; - dev = dmi_alloc(sizeof(*dev) + strlen(name) + 1); + dev = dmi_zalloc(sizeof(*dev) + strlen(name) + 1); if (!dev) return; 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) @@ -287,15 +302,14 @@ static void __init dmi_save_oem_strings_devices(const struct dmi_header *dm) if (devname == dmi_empty_string) continue; - dev = dmi_alloc(sizeof(*dev)); + dev = dmi_zalloc(sizeof(*dev)); if (!dev) break; 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); } } @@ -310,7 +324,7 @@ static void __init dmi_save_ipmi_device(const struct dmi_header *dm) memcpy(data, dm, dm->length); - dev = dmi_alloc(sizeof(*dev)); + dev = dmi_zalloc(sizeof(*dev)); if (!dev) return; @@ -318,7 +332,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, @@ -331,7 +345,7 @@ static void __init dmi_save_dev_pciaddr(int instance, int segment, int bus, segment == 0xFFFF && bus == 0xFF && devfn == 0xFF) return; - dev = dmi_alloc(sizeof(*dev) + strlen(name) + 1); + dev = dmi_zalloc(sizeof(*dev) + strlen(name) + 1); if (!dev) return; @@ -345,7 +359,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..e130c38 100644 --- a/include/linux/dmi.h +++ b/include/linux/dmi.h @@ -4,6 +4,7 @@ #include #include #include +#include /* 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; } @@ -144,6 +158,16 @@ static inline void dmi_memdev_name(u16 handle, const char **bank, static inline const struct dmi_system_id * dmi_first_match(const struct dmi_system_id *list) { return NULL; } +static inline bool is_dmi_fwnode(struct fwnode_handle *fwnode) +{ + return false +} + +static inline struct dmi_fwnode *to_dmi_device(struct fwnode_handle *fwnode) +{ + return NULL; +} + #endif #endif /* __DMI_H__ */ 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 {