Commit 3cd83bac authored by Corey Minyard's avatar Corey Minyard

ipmi: Consolidate the adding of platform devices

It was being done in two different places now that hard-coded devices
use platform devices, and it's about to be three with hotmod switching
to platform devices.  So put the code in one place.

This required some rework on some interfaces to make the type space
clean.
Signed-off-by: default avatarCorey Minyard <cminyard@mvista.com>
parent f6296bdc
...@@ -18,6 +18,10 @@ menuconfig IPMI_HANDLER ...@@ -18,6 +18,10 @@ menuconfig IPMI_HANDLER
If unsure, say N. If unsure, say N.
config IPMI_DMI_DECODE config IPMI_DMI_DECODE
select IPMI_PLAT_DATA
bool
config IPMI_PLAT_DATA
bool bool
if IPMI_HANDLER if IPMI_HANDLER
...@@ -56,6 +60,7 @@ config IPMI_DEVICE_INTERFACE ...@@ -56,6 +60,7 @@ config IPMI_DEVICE_INTERFACE
config IPMI_SI config IPMI_SI
tristate 'IPMI System Interface handler' tristate 'IPMI System Interface handler'
select IPMI_PLAT_DATA
help help
Provides a driver for System Interfaces (KCS, SMIC, BT). Provides a driver for System Interfaces (KCS, SMIC, BT).
Currently, only KCS and SMIC are supported. If Currently, only KCS and SMIC are supported. If
......
...@@ -17,6 +17,7 @@ obj-$(CONFIG_IPMI_HANDLER) += ipmi_msghandler.o ...@@ -17,6 +17,7 @@ obj-$(CONFIG_IPMI_HANDLER) += ipmi_msghandler.o
obj-$(CONFIG_IPMI_DEVICE_INTERFACE) += ipmi_devintf.o obj-$(CONFIG_IPMI_DEVICE_INTERFACE) += ipmi_devintf.o
obj-$(CONFIG_IPMI_SI) += ipmi_si.o obj-$(CONFIG_IPMI_SI) += ipmi_si.o
obj-$(CONFIG_IPMI_DMI_DECODE) += ipmi_dmi.o obj-$(CONFIG_IPMI_DMI_DECODE) += ipmi_dmi.o
obj-$(CONFIG_IPMI_PLAT_DATA) += ipmi_plat_data.o
obj-$(CONFIG_IPMI_SSIF) += ipmi_ssif.o obj-$(CONFIG_IPMI_SSIF) += ipmi_ssif.o
obj-$(CONFIG_IPMI_POWERNV) += ipmi_powernv.o obj-$(CONFIG_IPMI_POWERNV) += ipmi_powernv.o
obj-$(CONFIG_IPMI_WATCHDOG) += ipmi_watchdog.o obj-$(CONFIG_IPMI_WATCHDOG) += ipmi_watchdog.o
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <linux/property.h> #include <linux/property.h>
#include "ipmi_si_sm.h" #include "ipmi_si_sm.h"
#include "ipmi_dmi.h" #include "ipmi_dmi.h"
#include "ipmi_plat_data.h"
#define IPMI_DMI_TYPE_KCS 0x01 #define IPMI_DMI_TYPE_KCS 0x01
#define IPMI_DMI_TYPE_SMIC 0x02 #define IPMI_DMI_TYPE_SMIC 0x02
...@@ -22,7 +23,7 @@ ...@@ -22,7 +23,7 @@
struct ipmi_dmi_info { struct ipmi_dmi_info {
enum si_type si_type; enum si_type si_type;
u32 flags; unsigned int space; /* addr space for si, intf# for ssif */
unsigned long addr; unsigned long addr;
u8 slave_addr; u8 slave_addr;
struct ipmi_dmi_info *next; struct ipmi_dmi_info *next;
...@@ -33,133 +34,60 @@ static struct ipmi_dmi_info *ipmi_dmi_infos; ...@@ -33,133 +34,60 @@ static struct ipmi_dmi_info *ipmi_dmi_infos;
static int ipmi_dmi_nr __initdata; static int ipmi_dmi_nr __initdata;
static void __init dmi_add_platform_ipmi(unsigned long base_addr, static void __init dmi_add_platform_ipmi(unsigned long base_addr,
u32 flags, unsigned int space,
u8 slave_addr, u8 slave_addr,
int irq, int irq,
int offset, int offset,
int type) int type)
{ {
struct platform_device *pdev; const char *name;
struct resource r[4];
unsigned int num_r = 1, size;
struct property_entry p[5];
unsigned int pidx = 0;
char *name;
int rv;
enum si_type si_type;
struct ipmi_dmi_info *info; struct ipmi_dmi_info *info;
struct ipmi_plat_data p;
memset(p, 0, sizeof(p)); memset(&p, 0, sizeof(p));
name = "dmi-ipmi-si"; name = "dmi-ipmi-si";
switch (type) { switch (type) {
case IPMI_DMI_TYPE_SSIF: case IPMI_DMI_TYPE_SSIF:
name = "dmi-ipmi-ssif"; name = "dmi-ipmi-ssif";
offset = 1; p.type = SI_TYPE_INVALID;
size = 1;
si_type = SI_TYPE_INVALID;
break; break;
case IPMI_DMI_TYPE_BT: case IPMI_DMI_TYPE_BT:
size = 3; p.type = SI_BT;
si_type = SI_BT;
break; break;
case IPMI_DMI_TYPE_KCS: case IPMI_DMI_TYPE_KCS:
size = 2; p.type = SI_KCS;
si_type = SI_KCS;
break; break;
case IPMI_DMI_TYPE_SMIC: case IPMI_DMI_TYPE_SMIC:
size = 2; p.type = SI_SMIC;
si_type = SI_SMIC;
break; break;
default: default:
pr_err("Invalid IPMI type: %d\n", type); pr_err("Invalid IPMI type: %d\n", type);
return; return;
} }
if (si_type != SI_TYPE_INVALID) memset(&p, 0, sizeof(p));
p[pidx++] = PROPERTY_ENTRY_U8("ipmi-type", si_type); p.addr = base_addr;
p.space = space;
p[pidx++] = PROPERTY_ENTRY_U8("slave-addr", slave_addr); p.regspacing = offset;
p[pidx++] = PROPERTY_ENTRY_U8("addr-source", SI_SMBIOS); p.irq = irq;
p.slave_addr = slave_addr;
p.addr_source = SI_SMBIOS;
info = kmalloc(sizeof(*info), GFP_KERNEL); info = kmalloc(sizeof(*info), GFP_KERNEL);
if (!info) { if (!info) {
pr_warn("Could not allocate dmi info\n"); pr_warn("Could not allocate dmi info\n");
} else { } else {
info->si_type = si_type; info->si_type = p.type;
info->flags = flags; info->space = space;
info->addr = base_addr; info->addr = base_addr;
info->slave_addr = slave_addr; info->slave_addr = slave_addr;
info->next = ipmi_dmi_infos; info->next = ipmi_dmi_infos;
ipmi_dmi_infos = info; ipmi_dmi_infos = info;
} }
pdev = platform_device_alloc(name, ipmi_dmi_nr); if (ipmi_platform_add(name, ipmi_dmi_nr, &p))
if (!pdev) {
pr_err("Error allocation IPMI platform device\n");
return;
}
if (type == IPMI_DMI_TYPE_SSIF) {
p[pidx++] = PROPERTY_ENTRY_U16("i2c-addr", base_addr);
goto add_properties;
}
memset(r, 0, sizeof(r));
r[0].start = base_addr;
r[0].end = r[0].start + offset - 1;
r[0].name = "IPMI Address 1";
r[0].flags = flags;
if (size > 1) {
r[1].start = r[0].start + offset;
r[1].end = r[1].start + offset - 1;
r[1].name = "IPMI Address 2";
r[1].flags = flags;
num_r++;
}
if (size > 2) {
r[2].start = r[1].start + offset;
r[2].end = r[2].start + offset - 1;
r[2].name = "IPMI Address 3";
r[2].flags = flags;
num_r++;
}
if (irq) {
r[num_r].start = irq;
r[num_r].end = irq;
r[num_r].name = "IPMI IRQ";
r[num_r].flags = IORESOURCE_IRQ;
num_r++;
}
rv = platform_device_add_resources(pdev, r, num_r);
if (rv) {
dev_err(&pdev->dev, "Unable to add resources: %d\n", rv);
goto err;
}
add_properties:
rv = platform_device_add_properties(pdev, p);
if (rv) {
dev_err(&pdev->dev, "Unable to add properties: %d\n", rv);
goto err;
}
rv = platform_device_add(pdev);
if (rv) {
dev_err(&pdev->dev, "Unable to add device: %d\n", rv);
goto err;
}
ipmi_dmi_nr++; ipmi_dmi_nr++;
return;
err:
platform_device_put(pdev);
} }
/* /*
...@@ -169,14 +97,14 @@ static void __init dmi_add_platform_ipmi(unsigned long base_addr, ...@@ -169,14 +97,14 @@ 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(enum si_type si_type, u32 flags, int ipmi_dmi_get_slave_addr(enum si_type si_type, unsigned int space,
unsigned long base_addr) 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->si_type == si_type && if (info->si_type == si_type &&
info->flags == flags && info->space == space &&
info->addr == base_addr) info->addr == base_addr)
return info->slave_addr; return info->slave_addr;
info = info->next; info = info->next;
...@@ -198,11 +126,11 @@ EXPORT_SYMBOL(ipmi_dmi_get_slave_addr); ...@@ -198,11 +126,11 @@ EXPORT_SYMBOL(ipmi_dmi_get_slave_addr);
static void __init dmi_decode_ipmi(const struct dmi_header *dm) static void __init dmi_decode_ipmi(const struct dmi_header *dm)
{ {
const u8 *data = (const u8 *) dm; const u8 *data = (const u8 *) dm;
u32 flags = IORESOURCE_IO; int space = IPMI_IO_ADDR_SPACE;
unsigned long base_addr; unsigned long base_addr;
u8 len = dm->length; u8 len = dm->length;
u8 slave_addr; u8 slave_addr;
int irq = 0, offset; int irq = 0, offset = 0;
int type; int type;
if (len < DMI_IPMI_MIN_LENGTH) if (len < DMI_IPMI_MIN_LENGTH)
...@@ -218,8 +146,7 @@ static void __init dmi_decode_ipmi(const struct dmi_header *dm) ...@@ -218,8 +146,7 @@ static void __init dmi_decode_ipmi(const struct dmi_header *dm)
} }
if (len >= DMI_IPMI_VER2_LENGTH) { if (len >= DMI_IPMI_VER2_LENGTH) {
if (type == IPMI_DMI_TYPE_SSIF) { if (type == IPMI_DMI_TYPE_SSIF) {
offset = 0; space = 0; /* Match I2C interface 0. */
flags = 0;
base_addr = data[DMI_IPMI_ADDR] >> 1; base_addr = data[DMI_IPMI_ADDR] >> 1;
if (base_addr == 0) { if (base_addr == 0) {
/* /*
...@@ -236,7 +163,7 @@ static void __init dmi_decode_ipmi(const struct dmi_header *dm) ...@@ -236,7 +163,7 @@ static void __init dmi_decode_ipmi(const struct dmi_header *dm)
base_addr &= DMI_IPMI_IO_MASK; base_addr &= DMI_IPMI_IO_MASK;
} else { } else {
/* Memory */ /* Memory */
flags = IORESOURCE_MEM; space = IPMI_MEM_ADDR_SPACE;
} }
/* /*
...@@ -280,7 +207,7 @@ static void __init dmi_decode_ipmi(const struct dmi_header *dm) ...@@ -280,7 +207,7 @@ static void __init dmi_decode_ipmi(const struct dmi_header *dm)
offset = 1; offset = 1;
} }
dmi_add_platform_ipmi(base_addr, flags, slave_addr, irq, dmi_add_platform_ipmi(base_addr, space, slave_addr, irq,
offset, type); offset, type);
} }
......
...@@ -4,6 +4,6 @@ ...@@ -4,6 +4,6 @@
*/ */
#ifdef CONFIG_IPMI_DMI_DECODE #ifdef CONFIG_IPMI_DMI_DECODE
int ipmi_dmi_get_slave_addr(enum si_type si_type, u32 flags, int ipmi_dmi_get_slave_addr(enum si_type si_type, unsigned int space,
unsigned long base_addr); unsigned long base_addr);
#endif #endif
// SPDX-License-Identifier: GPL-2.0+
/*
* Add an IPMI platform device.
*/
#include <linux/platform_device.h>
#include "ipmi_plat_data.h"
#include "ipmi_si.h"
struct platform_device *ipmi_platform_add(const char *name, unsigned int inst,
struct ipmi_plat_data *p)
{
struct platform_device *pdev;
unsigned int num_r = 1, size, pidx = 0;
struct resource r[4];
struct property_entry pr[6];
u32 flags;
int rv;
memset(pr, 0, sizeof(pr));
memset(r, 0, sizeof(r));
if (p->type == SI_BT)
size = 3;
else if (p->type == SI_TYPE_INVALID)
size = 0;
else
size = 2;
if (p->regsize == 0)
p->regsize = DEFAULT_REGSIZE;
if (p->regspacing == 0)
p->regspacing = p->regsize;
pr[pidx++] = PROPERTY_ENTRY_U8("ipmi-type", p->type);
if (p->slave_addr)
pr[pidx++] = PROPERTY_ENTRY_U8("slave-addr", p->slave_addr);
pr[pidx++] = PROPERTY_ENTRY_U8("addr-source", p->addr_source);
if (p->regshift)
pr[pidx++] = PROPERTY_ENTRY_U8("reg-shift", p->regshift);
pr[pidx++] = PROPERTY_ENTRY_U8("reg-size", p->regsize);
/* Last entry must be left NULL to terminate it. */
pdev = platform_device_alloc(name, inst);
if (!pdev) {
pr_err("Error allocating IPMI platform device %s.%d\n",
name, inst);
return NULL;
}
if (size == 0)
/* An invalid or SSIF interface, no resources. */
goto add_properties;
/*
* Register spacing is derived from the resources in
* the IPMI platform code.
*/
if (p->space == IPMI_IO_ADDR_SPACE)
flags = IORESOURCE_IO;
else
flags = IORESOURCE_MEM;
r[0].start = p->addr;
r[0].end = r[0].start + p->regsize - 1;
r[0].name = "IPMI Address 1";
r[0].flags = flags;
if (size > 1) {
r[1].start = r[0].start + p->regspacing;
r[1].end = r[1].start + p->regsize - 1;
r[1].name = "IPMI Address 2";
r[1].flags = flags;
num_r++;
}
if (size > 2) {
r[2].start = r[1].start + p->regspacing;
r[2].end = r[2].start + p->regsize - 1;
r[2].name = "IPMI Address 3";
r[2].flags = flags;
num_r++;
}
if (p->irq) {
r[num_r].start = p->irq;
r[num_r].end = p->irq;
r[num_r].name = "IPMI IRQ";
r[num_r].flags = IORESOURCE_IRQ;
num_r++;
}
rv = platform_device_add_resources(pdev, r, num_r);
if (rv) {
dev_err(&pdev->dev,
"Unable to add hard-code resources: %d\n", rv);
goto err;
}
add_properties:
rv = platform_device_add_properties(pdev, pr);
if (rv) {
dev_err(&pdev->dev,
"Unable to add hard-code properties: %d\n", rv);
goto err;
}
rv = platform_device_add(pdev);
if (rv) {
dev_err(&pdev->dev,
"Unable to add hard-code device: %d\n", rv);
goto err;
}
return pdev;
err:
platform_device_put(pdev);
return NULL;
}
EXPORT_SYMBOL(ipmi_platform_add);
/* SPDX-License-Identifier: GPL-2.0+ */
/*
* Generic code to add IPMI platform devices.
*/
#include <linux/ipmi.h>
struct ipmi_plat_data {
unsigned int type; /* si_type for si, SI_INVALID for others */
unsigned int space; /* addr_space for si, intf# for ssif. */
unsigned long addr;
unsigned int regspacing;
unsigned int regsize;
unsigned int regshift;
unsigned int irq;
unsigned int slave_addr;
enum ipmi_addr_src addr_source;
};
struct platform_device *ipmi_platform_add(const char *name, unsigned int inst,
struct ipmi_plat_data *p);
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
*/ */
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/platform_device.h>
#include "ipmi_si_sm.h" #include "ipmi_si_sm.h"
#define DEFAULT_REGSPACING 1 #define DEFAULT_REGSPACING 1
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <linux/moduleparam.h> #include <linux/moduleparam.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include "ipmi_si.h" #include "ipmi_si.h"
#include "ipmi_plat_data.h"
/* /*
* There can be 4 IO ports passed in (with or without IRQs), 4 addresses, * There can be 4 IO ports passed in (with or without IRQs), 4 addresses,
...@@ -78,121 +79,39 @@ static struct platform_device *ipmi_hc_pdevs[SI_MAX_PARMS]; ...@@ -78,121 +79,39 @@ static struct platform_device *ipmi_hc_pdevs[SI_MAX_PARMS];
static void __init ipmi_hardcode_init_one(const char *si_type_str, static void __init ipmi_hardcode_init_one(const char *si_type_str,
unsigned int i, unsigned int i,
unsigned long addr, unsigned long addr,
unsigned int flags) enum ipmi_addr_space addr_space)
{ {
struct platform_device *pdev; struct ipmi_plat_data p;
unsigned int num_r = 1, size;
struct resource r[4];
struct property_entry p[6];
enum si_type si_type;
unsigned int regspacing, regsize;
int rv;
memset(p, 0, sizeof(p)); memset(&p, 0, sizeof(p));
memset(r, 0, sizeof(r));
if (!si_type_str || !*si_type_str || strcmp(si_type_str, "kcs") == 0) { if (!si_type_str || !*si_type_str || strcmp(si_type_str, "kcs") == 0) {
size = 2; p.type = SI_KCS;
si_type = SI_KCS;
} else if (strcmp(si_type_str, "smic") == 0) { } else if (strcmp(si_type_str, "smic") == 0) {
size = 2; p.type = SI_SMIC;
si_type = SI_SMIC;
} else if (strcmp(si_type_str, "bt") == 0) { } else if (strcmp(si_type_str, "bt") == 0) {
size = 3; p.type = SI_BT;
si_type = SI_BT;
} else if (strcmp(si_type_str, "invalid") == 0) { } else if (strcmp(si_type_str, "invalid") == 0) {
/* /*
* Allow a firmware-specified interface to be * Allow a firmware-specified interface to be
* disabled. * disabled.
*/ */
size = 1; p.type = SI_TYPE_INVALID;
si_type = SI_TYPE_INVALID;
} else { } else {
pr_warn("Interface type specified for interface %d, was invalid: %s\n", pr_warn("Interface type specified for interface %d, was invalid: %s\n",
i, si_type_str); i, si_type_str);
return; return;
} }
regsize = regsizes[i]; p.regsize = regsizes[i];
if (regsize == 0) p.slave_addr = slave_addrs[i];
regsize = DEFAULT_REGSIZE; p.addr_source = SI_HARDCODED;
p.regshift = regshifts[i];
p.regsize = regsizes[i];
p.addr = addr;
p.space = addr_space;
p[0] = PROPERTY_ENTRY_U8("ipmi-type", si_type); ipmi_hc_pdevs[i] = ipmi_platform_add("hardcode-ipmi-si", i, &p);
p[1] = PROPERTY_ENTRY_U8("slave-addr", slave_addrs[i]);
p[2] = PROPERTY_ENTRY_U8("addr-source", SI_HARDCODED);
p[3] = PROPERTY_ENTRY_U8("reg-shift", regshifts[i]);
p[4] = PROPERTY_ENTRY_U8("reg-size", regsize);
/* Last entry must be left NULL to terminate it. */
/*
* Register spacing is derived from the resources in
* the IPMI platform code.
*/
regspacing = regspacings[i];
if (regspacing == 0)
regspacing = regsize;
r[0].start = addr;
r[0].end = r[0].start + regsize - 1;
r[0].name = "IPMI Address 1";
r[0].flags = flags;
if (size > 1) {
r[1].start = r[0].start + regspacing;
r[1].end = r[1].start + regsize - 1;
r[1].name = "IPMI Address 2";
r[1].flags = flags;
num_r++;
}
if (size > 2) {
r[2].start = r[1].start + regspacing;
r[2].end = r[2].start + regsize - 1;
r[2].name = "IPMI Address 3";
r[2].flags = flags;
num_r++;
}
if (irqs[i]) {
r[num_r].start = irqs[i];
r[num_r].end = irqs[i];
r[num_r].name = "IPMI IRQ";
r[num_r].flags = IORESOURCE_IRQ;
num_r++;
}
pdev = platform_device_alloc("hardcode-ipmi-si", i);
if (!pdev) {
pr_err("Error allocating IPMI platform device %d\n", i);
return;
}
rv = platform_device_add_resources(pdev, r, num_r);
if (rv) {
dev_err(&pdev->dev,
"Unable to add hard-code resources: %d\n", rv);
goto err;
}
rv = platform_device_add_properties(pdev, p);
if (rv) {
dev_err(&pdev->dev,
"Unable to add hard-code properties: %d\n", rv);
goto err;
}
rv = platform_device_add(pdev);
if (rv) {
dev_err(&pdev->dev,
"Unable to add hard-code device: %d\n", rv);
goto err;
}
ipmi_hc_pdevs[i] = pdev;
return;
err:
platform_device_put(pdev);
} }
void __init ipmi_hardcode_init(void) void __init ipmi_hardcode_init(void)
...@@ -219,10 +138,10 @@ void __init ipmi_hardcode_init(void) ...@@ -219,10 +138,10 @@ void __init ipmi_hardcode_init(void)
for (i = 0; i < SI_MAX_PARMS; i++) { for (i = 0; i < SI_MAX_PARMS; i++) {
if (i < num_ports && ports[i]) if (i < num_ports && ports[i])
ipmi_hardcode_init_one(si_type[i], i, ports[i], ipmi_hardcode_init_one(si_type[i], i, ports[i],
IORESOURCE_IO); IPMI_IO_ADDR_SPACE);
if (i < num_addrs && addrs[i]) if (i < num_addrs && addrs[i])
ipmi_hardcode_init_one(si_type[i], i, addrs[i], ipmi_hardcode_init_one(si_type[i], i, addrs[i],
IORESOURCE_MEM); IPMI_MEM_ADDR_SPACE);
} }
} }
......
...@@ -307,15 +307,10 @@ static int of_ipmi_probe(struct platform_device *dev) ...@@ -307,15 +307,10 @@ static int of_ipmi_probe(struct platform_device *dev)
static int find_slave_address(struct si_sm_io *io, int slave_addr) 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)
u32 flags = IORESOURCE_IO; slave_addr = ipmi_dmi_get_slave_addr(io->si_type,
io->addr_space,
if (io->addr_space == IPMI_MEM_ADDR_SPACE)
flags = IORESOURCE_MEM;
slave_addr = ipmi_dmi_get_slave_addr(io->si_type, flags,
io->addr_data); io->addr_data);
}
#endif #endif
return slave_addr; return slave_addr;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment