ipmi: Make the DMI probe into a generic platform probe

Rework the DMI probe function to be a generic platform probe, and
then rework the DMI code (and a few other things) to use the more
generic information.  This is so other things can declare platform
IPMI devices.

Signed-off-by: Corey Minyard <cminyard@mvista.com>
This commit is contained in:
Corey Minyard 2017-09-18 12:38:17 -05:00
parent 55f91cb6f1
commit 95e300c052
8 changed files with 104 additions and 95 deletions

View File

@ -8,10 +8,16 @@
#include <linux/dmi.h> #include <linux/dmi.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/property.h> #include <linux/property.h>
#include "ipmi_si_sm.h"
#include "ipmi_dmi.h" #include "ipmi_dmi.h"
#define IPMI_DMI_TYPE_KCS 0x01
#define IPMI_DMI_TYPE_SMIC 0x02
#define IPMI_DMI_TYPE_BT 0x03
#define IPMI_DMI_TYPE_SSIF 0x04
struct ipmi_dmi_info { struct ipmi_dmi_info {
int type; enum si_type si_type;
u32 flags; u32 flags;
unsigned long addr; unsigned long addr;
u8 slave_addr; u8 slave_addr;
@ -22,6 +28,15 @@ static struct ipmi_dmi_info *ipmi_dmi_infos;
static int ipmi_dmi_nr __initdata; static int ipmi_dmi_nr __initdata;
#define set_prop_entry(_p_, _name_, type, val) \
do { \
struct property_entry *_p = &_p_; \
_p->name = _name_; \
_p->length = sizeof(type); \
_p->is_string = false; \
_p->value.type##_data = val; \
} while(0)
static void __init dmi_add_platform_ipmi(unsigned long base_addr, static void __init dmi_add_platform_ipmi(unsigned long base_addr,
u32 flags, u32 flags,
u8 slave_addr, u8 slave_addr,
@ -32,27 +47,14 @@ static void __init dmi_add_platform_ipmi(unsigned long base_addr,
struct platform_device *pdev; struct platform_device *pdev;
struct resource r[4]; struct resource r[4];
unsigned int num_r = 1, size; unsigned int num_r = 1, size;
struct property_entry p[4] = { struct property_entry p[5];
PROPERTY_ENTRY_U8("slave-addr", slave_addr), unsigned int pidx = 0;
PROPERTY_ENTRY_U8("ipmi-type", type),
PROPERTY_ENTRY_U16("i2c-addr", base_addr),
{ }
};
char *name, *override; char *name, *override;
int rv; int rv;
enum si_type si_type;
struct ipmi_dmi_info *info; struct ipmi_dmi_info *info;
info = kmalloc(sizeof(*info), GFP_KERNEL); memset(p, 0, sizeof(p));
if (!info) {
pr_warn("ipmi:dmi: Could not allocate dmi info\n");
} else {
info->type = type;
info->flags = flags;
info->addr = base_addr;
info->slave_addr = slave_addr;
info->next = ipmi_dmi_infos;
ipmi_dmi_infos = info;
}
name = "dmi-ipmi-si"; name = "dmi-ipmi-si";
override = "ipmi_si"; override = "ipmi_si";
@ -62,19 +64,42 @@ static void __init dmi_add_platform_ipmi(unsigned long base_addr,
override = "ipmi_ssif"; override = "ipmi_ssif";
offset = 1; offset = 1;
size = 1; size = 1;
si_type = SI_TYPE_INVALID;
break; break;
case IPMI_DMI_TYPE_BT: case IPMI_DMI_TYPE_BT:
size = 3; size = 3;
si_type = SI_BT;
break; break;
case IPMI_DMI_TYPE_KCS: case IPMI_DMI_TYPE_KCS:
size = 2;
si_type = SI_KCS;
break;
case IPMI_DMI_TYPE_SMIC: case IPMI_DMI_TYPE_SMIC:
size = 2; size = 2;
si_type = SI_SMIC;
break; break;
default: default:
pr_err("ipmi:dmi: Invalid IPMI type: %d", type); pr_err("ipmi:dmi: Invalid IPMI type: %d", type);
return; return;
} }
if (si_type != SI_TYPE_INVALID)
set_prop_entry(p[pidx++], "ipmi-type", u8, si_type);
set_prop_entry(p[pidx++], "slave-addr", u8, slave_addr);
set_prop_entry(p[pidx++], "addr-source", u8, SI_SMBIOS);
info = kmalloc(sizeof(*info), GFP_KERNEL);
if (!info) {
pr_warn("ipmi:dmi: Could not allocate dmi info\n");
} else {
info->si_type = si_type;
info->flags = flags;
info->addr = base_addr;
info->slave_addr = slave_addr;
info->next = ipmi_dmi_infos;
ipmi_dmi_infos = info;
}
pdev = platform_device_alloc(name, ipmi_dmi_nr); pdev = platform_device_alloc(name, ipmi_dmi_nr);
if (!pdev) { if (!pdev) {
pr_err("ipmi:dmi: Error allocation IPMI platform device"); pr_err("ipmi:dmi: Error allocation IPMI platform device");
@ -82,8 +107,10 @@ static void __init dmi_add_platform_ipmi(unsigned long base_addr,
} }
pdev->driver_override = override; pdev->driver_override = override;
if (type == IPMI_DMI_TYPE_SSIF) if (type == IPMI_DMI_TYPE_SSIF) {
set_prop_entry(p[pidx++], "i2c-addr", u16, base_addr);
goto add_properties; goto add_properties;
}
memset(r, 0, sizeof(r)); memset(r, 0, sizeof(r));
@ -151,12 +178,13 @@ static void __init dmi_add_platform_ipmi(unsigned long base_addr,
* This function allows an ACPI-specified IPMI device to look up the * This function allows an ACPI-specified IPMI device to look up the
* slave address from the DMI table. * slave address from the DMI table.
*/ */
int ipmi_dmi_get_slave_addr(int type, u32 flags, unsigned long base_addr) int ipmi_dmi_get_slave_addr(enum si_type si_type, u32 flags,
unsigned long base_addr)
{ {
struct ipmi_dmi_info *info = ipmi_dmi_infos; struct ipmi_dmi_info *info = ipmi_dmi_infos;
while (info) { while (info) {
if (info->type == type && if (info->si_type == si_type &&
info->flags == flags && info->flags == flags &&
info->addr == base_addr) info->addr == base_addr)
return info->slave_addr; return info->slave_addr;

View File

@ -2,11 +2,7 @@
* DMI defines for use by IPMI * DMI defines for use by IPMI
*/ */
#define IPMI_DMI_TYPE_KCS 0x01
#define IPMI_DMI_TYPE_SMIC 0x02
#define IPMI_DMI_TYPE_BT 0x03
#define IPMI_DMI_TYPE_SSIF 0x04
#ifdef CONFIG_IPMI_DMI_DECODE #ifdef CONFIG_IPMI_DMI_DECODE
int ipmi_dmi_get_slave_addr(int type, u32 flags, unsigned long base_addr); int ipmi_dmi_get_slave_addr(enum si_type si_type, u32 flags,
unsigned long base_addr);
#endif #endif

View File

@ -594,7 +594,7 @@ static DEFINE_MUTEX(smi_watchers_mutex);
static const char * const addr_src_to_str[] = { static const char * const addr_src_to_str[] = {
"invalid", "hotmod", "hardcoded", "SPMI", "ACPI", "SMBIOS", "PCI", "invalid", "hotmod", "hardcoded", "SPMI", "ACPI", "SMBIOS", "PCI",
"device-tree" "device-tree", "platform"
}; };
const char *ipmi_addr_src_to_str(enum ipmi_addr_src src) const char *ipmi_addr_src_to_str(enum ipmi_addr_src src)

View File

@ -89,7 +89,7 @@ enum si_intf_state {
#define IPMI_BT_INTMASK_CLEAR_IRQ_BIT 2 #define IPMI_BT_INTMASK_CLEAR_IRQ_BIT 2
#define IPMI_BT_INTMASK_ENABLE_IRQ_BIT 1 #define IPMI_BT_INTMASK_ENABLE_IRQ_BIT 1
static const char * const si_to_str[] = { "kcs", "smic", "bt" }; static const char * const si_to_str[] = { "invalid", "kcs", "smic", "bt" };
static int initialized; static int initialized;

View File

@ -6,14 +6,13 @@
*/ */
#include <linux/types.h> #include <linux/types.h>
#include <linux/module.h> #include <linux/module.h>
#include "ipmi_dmi.h"
#include <linux/dmi.h>
#include <linux/of_device.h> #include <linux/of_device.h>
#include <linux/of_platform.h> #include <linux/of_platform.h>
#include <linux/of_address.h> #include <linux/of_address.h>
#include <linux/of_irq.h> #include <linux/of_irq.h>
#include <linux/acpi.h> #include <linux/acpi.h>
#include "ipmi_si.h" #include "ipmi_si.h"
#include "ipmi_dmi.h"
#define PFX "ipmi_platform: " #define PFX "ipmi_platform: "
@ -21,19 +20,29 @@ static bool si_tryplatform = true;
#ifdef CONFIG_ACPI #ifdef CONFIG_ACPI
static bool si_tryacpi = true; static bool si_tryacpi = true;
#endif #endif
#ifdef CONFIG_OF
static bool si_tryopenfirmware = true;
#endif
#ifdef CONFIG_DMI #ifdef CONFIG_DMI
static bool si_trydmi = true; static bool si_trydmi = true;
#else
static bool si_trydmi = false;
#endif #endif
module_param_named(tryplatform, si_tryplatform, bool, 0); module_param_named(tryplatform, si_tryplatform, bool, 0);
MODULE_PARM_DESC(tryplatform, "Setting this to zero will disable the" MODULE_PARM_DESC(tryplatform, "Setting this to zero will disable the"
" default scan of the interfaces identified via platform" " default scan of the interfaces identified via platform"
" interfaces like openfirmware"); " interfaces besides ACPI, OpenFirmware, and DMI");
#ifdef CONFIG_ACPI #ifdef CONFIG_ACPI
module_param_named(tryacpi, si_tryacpi, bool, 0); module_param_named(tryacpi, si_tryacpi, bool, 0);
MODULE_PARM_DESC(tryacpi, "Setting this to zero will disable the" MODULE_PARM_DESC(tryacpi, "Setting this to zero will disable the"
" default scan of the interfaces identified via ACPI"); " default scan of the interfaces identified via ACPI");
#endif #endif
#ifdef CONFIG_OF
module_param_named(tryopenfirmware, si_tryopenfirmware, bool, 0);
MODULE_PARM_DESC(tryacpi, "Setting this to zero will disable the"
" default scan of the interfaces identified via OpenFirmware");
#endif
#ifdef CONFIG_DMI #ifdef CONFIG_DMI
module_param_named(trydmi, si_trydmi, bool, 0); module_param_named(trydmi, si_trydmi, bool, 0);
MODULE_PARM_DESC(trydmi, "Setting this to zero will disable the" MODULE_PARM_DESC(trydmi, "Setting this to zero will disable the"
@ -235,7 +244,6 @@ static void spmi_find_bmc(void)
} }
#endif #endif
#if defined(CONFIG_DMI) || defined(CONFIG_ACPI)
static struct resource * static struct resource *
ipmi_get_info_from_resources(struct platform_device *pdev, ipmi_get_info_from_resources(struct platform_device *pdev,
struct si_sm_io *io) struct si_sm_io *io)
@ -271,48 +279,52 @@ ipmi_get_info_from_resources(struct platform_device *pdev,
return res; return res;
} }
#endif static int platform_ipmi_probe(struct platform_device *pdev)
#ifdef CONFIG_DMI
static int dmi_ipmi_probe(struct platform_device *pdev)
{ {
struct si_sm_io io; struct si_sm_io io;
u8 type, slave_addr; u8 type, slave_addr, addr_source;
int rv; int rv;
rv = device_property_read_u8(&pdev->dev, "addr-source", &addr_source);
if (rv)
addr_source = SI_PLATFORM;
if (addr_source >= SI_LAST)
return -EINVAL;
if (addr_source == SI_SMBIOS) {
if (!si_trydmi) if (!si_trydmi)
return -ENODEV; return -ENODEV;
} else {
if (!si_tryplatform)
return -ENODEV;
}
rv = device_property_read_u8(&pdev->dev, "ipmi-type", &type); rv = device_property_read_u8(&pdev->dev, "ipmi-type", &type);
if (rv) if (rv)
return -ENODEV; return -ENODEV;
memset(&io, 0, sizeof(io)); memset(&io, 0, sizeof(io));
io.addr_source = SI_SMBIOS; io.addr_source = addr_source;
pr_info(PFX "probing via SMBIOS\n"); dev_info(&pdev->dev, PFX "probing via %s\n",
ipmi_addr_src_to_str(addr_source));
switch (type) { switch (type) {
case IPMI_DMI_TYPE_KCS: case SI_KCS:
io.si_type = SI_KCS; case SI_SMIC:
break; case SI_BT:
case IPMI_DMI_TYPE_SMIC: io.si_type = type;
io.si_type = SI_SMIC;
break;
case IPMI_DMI_TYPE_BT:
io.si_type = SI_BT;
break; break;
default: default:
dev_err(&pdev->dev, "ipmi-type property is invalid\n");
return -EINVAL; return -EINVAL;
} }
if (!ipmi_get_info_from_resources(pdev, &io)) { if (!ipmi_get_info_from_resources(pdev, &io))
rv = -EINVAL; return -EINVAL;
goto err_free;
}
rv = device_property_read_u8(&pdev->dev, "slave-addr", &slave_addr); rv = device_property_read_u8(&pdev->dev, "slave-addr", &slave_addr);
if (rv) { if (rv) {
dev_warn(&pdev->dev, "device has no slave-addr property"); dev_warn(&pdev->dev, "device has no slave-addr property\n");
io.slave_addr = 0x20; io.slave_addr = 0x20;
} else { } else {
io.slave_addr = slave_addr; io.slave_addr = slave_addr;
@ -333,16 +345,7 @@ static int dmi_ipmi_probe(struct platform_device *pdev)
ipmi_si_add_smi(&io); ipmi_si_add_smi(&io);
return 0; return 0;
err_free:
return rv;
} }
#else
static int dmi_ipmi_probe(struct platform_device *pdev)
{
return -ENODEV;
}
#endif /* CONFIG_DMI */
#ifdef CONFIG_OF #ifdef CONFIG_OF
static const struct of_device_id of_ipmi_match[] = { static const struct of_device_id of_ipmi_match[] = {
@ -366,6 +369,9 @@ static int of_ipmi_probe(struct platform_device *pdev)
int ret; int ret;
int proplen; int proplen;
if (!si_tryopenfirmware)
return -ENODEV;
dev_info(&pdev->dev, "probing via device tree\n"); dev_info(&pdev->dev, "probing via device tree\n");
match = of_match_device(of_ipmi_match, &pdev->dev); match = of_match_device(of_ipmi_match, &pdev->dev);
@ -436,25 +442,12 @@ static int find_slave_address(struct si_sm_io *io, int slave_addr)
{ {
#ifdef CONFIG_IPMI_DMI_DECODE #ifdef CONFIG_IPMI_DMI_DECODE
if (!slave_addr) { if (!slave_addr) {
int type = -1;
u32 flags = IORESOURCE_IO; u32 flags = IORESOURCE_IO;
switch (io->si_type) {
case SI_KCS:
type = IPMI_DMI_TYPE_KCS;
break;
case SI_BT:
type = IPMI_DMI_TYPE_BT;
break;
case SI_SMIC:
type = IPMI_DMI_TYPE_SMIC;
break;
}
if (io->addr_type == IPMI_MEM_ADDR_SPACE) if (io->addr_type == IPMI_MEM_ADDR_SPACE)
flags = IORESOURCE_MEM; flags = IORESOURCE_MEM;
slave_addr = ipmi_dmi_get_slave_addr(type, flags, slave_addr = ipmi_dmi_get_slave_addr(io->si_type, flags,
io->addr_data); io->addr_data);
} }
#endif #endif
@ -563,7 +556,7 @@ static int ipmi_probe(struct platform_device *pdev)
if (acpi_ipmi_probe(pdev) == 0) if (acpi_ipmi_probe(pdev) == 0)
return 0; return 0;
return dmi_ipmi_probe(pdev); return platform_ipmi_probe(pdev);
} }
static int ipmi_remove(struct platform_device *pdev) static int ipmi_remove(struct platform_device *pdev)
@ -583,11 +576,9 @@ struct platform_driver ipmi_platform_driver = {
void ipmi_si_platform_init(void) void ipmi_si_platform_init(void)
{ {
if (si_tryplatform) {
int rv = platform_driver_register(&ipmi_platform_driver); int rv = platform_driver_register(&ipmi_platform_driver);
if (rv) if (rv)
pr_err(PFX "Unable to register driver: %d\n", rv); pr_err(PFX "Unable to register driver: %d\n", rv);
}
#ifdef CONFIG_ACPI #ifdef CONFIG_ACPI
if (si_tryacpi) if (si_tryacpi)

View File

@ -43,7 +43,7 @@
struct si_sm_data; struct si_sm_data;
enum si_type { enum si_type {
SI_KCS, SI_SMIC, SI_BT SI_TYPE_INVALID, SI_KCS, SI_SMIC, SI_BT
}; };
/* /*

View File

@ -53,6 +53,7 @@
#include <linux/acpi.h> #include <linux/acpi.h>
#include <linux/ctype.h> #include <linux/ctype.h>
#include <linux/time64.h> #include <linux/time64.h>
#include "ipmi_si_sm.h"
#include "ipmi_dmi.h" #include "ipmi_dmi.h"
#define PFX "ipmi_ssif: " #define PFX "ipmi_ssif: "
@ -1482,7 +1483,7 @@ static int find_slave_address(struct i2c_client *client, int slave_addr)
#ifdef CONFIG_IPMI_DMI_DECODE #ifdef CONFIG_IPMI_DMI_DECODE
if (!slave_addr) if (!slave_addr)
slave_addr = ipmi_dmi_get_slave_addr( slave_addr = ipmi_dmi_get_slave_addr(
IPMI_DMI_TYPE_SSIF, SI_TYPE_INVALID,
i2c_adapter_id(client->adapter), i2c_adapter_id(client->adapter),
client->addr); client->addr);
#endif #endif
@ -2013,20 +2014,13 @@ static void spmi_find_bmc(void) { }
#ifdef CONFIG_DMI #ifdef CONFIG_DMI
static int dmi_ipmi_probe(struct platform_device *pdev) static int dmi_ipmi_probe(struct platform_device *pdev)
{ {
u8 type, slave_addr = 0; u8 slave_addr = 0;
u16 i2c_addr; u16 i2c_addr;
int rv; int rv;
if (!ssif_trydmi) if (!ssif_trydmi)
return -ENODEV; return -ENODEV;
rv = device_property_read_u8(&pdev->dev, "ipmi-type", &type);
if (rv)
return -ENODEV;
if (type != IPMI_DMI_TYPE_SSIF)
return -ENODEV;
rv = device_property_read_u16(&pdev->dev, "i2c-addr", &i2c_addr); rv = device_property_read_u16(&pdev->dev, "i2c-addr", &i2c_addr);
if (rv) { if (rv) {
dev_warn(&pdev->dev, PFX "No i2c-addr property\n"); dev_warn(&pdev->dev, PFX "No i2c-addr property\n");

View File

@ -277,7 +277,7 @@ int ipmi_validate_addr(struct ipmi_addr *addr, int len);
*/ */
enum ipmi_addr_src { enum ipmi_addr_src {
SI_INVALID = 0, SI_HOTMOD, SI_HARDCODED, SI_SPMI, SI_ACPI, SI_SMBIOS, SI_INVALID = 0, SI_HOTMOD, SI_HARDCODED, SI_SPMI, SI_ACPI, SI_SMBIOS,
SI_PCI, SI_DEVICETREE, SI_LAST SI_PCI, SI_DEVICETREE, SI_PLATFORM, SI_LAST
}; };
const char *ipmi_addr_src_to_str(enum ipmi_addr_src src); const char *ipmi_addr_src_to_str(enum ipmi_addr_src src);