From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752698AbcD0NEg (ORCPT ); Wed, 27 Apr 2016 09:04:36 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:34572 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752344AbcD0NEe (ORCPT ); Wed, 27 Apr 2016 09:04:34 -0400 From: minyard@acm.org To: openipmi-developer@lists.sourceforge.net, linux-kernel@vger.kernel.org, Jean Delvare Cc: Corey Minyard , Andy Lutomirski Subject: [PATCH v3 4/5] dmi: Add IPMI DMI devices as platform devices Date: Wed, 27 Apr 2016 08:04:19 -0500 Message-Id: <1461762260-32454-5-git-send-email-minyard@acm.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1461762260-32454-1-git-send-email-minyard@acm.org> References: <1461762260-32454-1-git-send-email-minyard@acm.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Corey Minyard Have DMI create a platform device for every IPMI device it finds. Signed-off-by: Corey Minyard Cc: Jean Delvare Cc: Andy Lutomirski Tested-by: Andy Lutomirski --- drivers/firmware/dmi_scan.c | 55 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c index 16e5174..6a9598b 100644 --- a/drivers/firmware/dmi_scan.c +++ b/drivers/firmware/dmi_scan.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -783,6 +784,52 @@ static ssize_t raw_table_read(struct file *file, struct kobject *kobj, return count; } +static void __init dmi_add_platform_ipmi(struct dmi_device *dev, int *nr) +{ + struct platform_device *pdev; + struct dmi_dev_ipmi *ipmi_dev = to_dmi_dev_ipmi(dev); + int rv; + + if (!ipmi_dev->good_data) { + pr_err("dmi: Invalid IPMI data, not creating platform device"); + return; + } + + if (ipmi_dev->type == IPMI_DMI_TYPE_SSIF) + pdev = platform_device_alloc("dmi-ipmi-ssif", *nr); + else + pdev = platform_device_alloc("dmi-ipmi-si", *nr); + if (!pdev) { + pr_err("dmi: Error allocation IPMI platform device"); + return; + } + if (ipmi_dev->type == IPMI_DMI_TYPE_SSIF) + pdev->driver_override = "ipmi_ssif"; + else + pdev->driver_override = "ipmi_si"; + + pdev->dev.fwnode = &dev->fwnode; + rv = platform_device_add(pdev); + if (rv) { + dev_err(&pdev->dev, "dmi: Unable to add device: %d\n", rv); + platform_device_del(pdev); + return; + } + + (*nr)++; +} + +static void __init dmi_add_platform_devices(void) +{ + struct dmi_device *dev; + int nr_ipmi = 0; + + list_for_each_entry(dev, &dmi_devices, list) { + if (dev->type == DMI_DEV_TYPE_IPMI) + dmi_add_platform_ipmi(dev, &nr_ipmi); + } +} + static BIN_ATTR(smbios_entry_point, S_IRUSR, raw_table_read, NULL, 0); static BIN_ATTR(DMI, S_IRUSR, raw_table_read, NULL, 0); @@ -823,9 +870,13 @@ static int __init dmi_init(void) bin_attr_DMI.size = dmi_len; bin_attr_DMI.private = dmi_table; ret = sysfs_create_bin_file(tables_kobj, &bin_attr_DMI); - if (!ret) - return 0; + if (ret) + goto out_remove_bin_file; + + dmi_add_platform_devices(); + return 0; + out_remove_bin_file: sysfs_remove_bin_file(tables_kobj, &bin_attr_smbios_entry_point); err_unmap: -- 2.7.4