aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc
diff options
context:
space:
mode:
authorChristian Krafft <parabelboi@bopserverein.de>2007-02-14 08:09:45 -0500
committerPaul Mackerras <paulus@samba.org>2007-02-15 22:00:19 -0500
commit0e8266437c62f4848676ea6e87a1ff10367502a9 (patch)
tree57f3b86ffb2c205f513896bbf52f836c7d0a0302 /arch/powerpc
parentfde5efd0e50e026f3f69629fc5790a4f0533dcaa (diff)
[POWERPC] Add PMI driver for cell blade
This adds driver code for the PMI device found in future IBM products. PMI stands for "Platform Management Interrupt" and is a way to communicate with the BMC (Baseboard Management Controller). It provides bidirectional communication with a low latency. Signed-off-by: Christian Krafft <krafft@de.ibm.com> Acked-by: Arnd Bergmann <arnd.bergmann@de.ibm.com> Acked-by: Heiko J Schick <schickhj@de.ibm.com> Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'arch/powerpc')
-rw-r--r--arch/powerpc/Kconfig9
-rw-r--r--arch/powerpc/configs/cell_defconfig1
-rw-r--r--arch/powerpc/sysdev/Makefile1
-rw-r--r--arch/powerpc/sysdev/pmi.c305
4 files changed, 316 insertions, 0 deletions
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 340d9beab6d1..6dfbd52694ab 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -620,6 +620,15 @@ config RTAS_FLASH
620 tristate "Firmware flash interface" 620 tristate "Firmware flash interface"
621 depends on PPC64 && RTAS_PROC 621 depends on PPC64 && RTAS_PROC
622 622
623config PPC_PMI
624 tristate "Support for PMI"
625 depends PPC_IBM_CELL_BLADE
626 help
627 PMI (Platform Management Interrupt) is a way to
628 communicate with the BMC (Baseboard Mangement Controller).
629 It is used in some IBM Cell blades.
630 default m
631
623config MMIO_NVRAM 632config MMIO_NVRAM
624 bool 633 bool
625 default n 634 default n
diff --git a/arch/powerpc/configs/cell_defconfig b/arch/powerpc/configs/cell_defconfig
index e956548da00c..24367319ce24 100644
--- a/arch/powerpc/configs/cell_defconfig
+++ b/arch/powerpc/configs/cell_defconfig
@@ -147,6 +147,7 @@ CONFIG_PPC_RTAS=y
147# CONFIG_RTAS_ERROR_LOGGING is not set 147# CONFIG_RTAS_ERROR_LOGGING is not set
148CONFIG_RTAS_PROC=y 148CONFIG_RTAS_PROC=y
149CONFIG_RTAS_FLASH=y 149CONFIG_RTAS_FLASH=y
150CONFIG_PPC_PMI=m
150CONFIG_MMIO_NVRAM=y 151CONFIG_MMIO_NVRAM=y
151# CONFIG_PPC_MPC106 is not set 152# CONFIG_PPC_MPC106 is not set
152# CONFIG_PPC_970_NAP is not set 153# CONFIG_PPC_970_NAP is not set
diff --git a/arch/powerpc/sysdev/Makefile b/arch/powerpc/sysdev/Makefile
index 85dcdf178415..26ca3ffbc1de 100644
--- a/arch/powerpc/sysdev/Makefile
+++ b/arch/powerpc/sysdev/Makefile
@@ -7,6 +7,7 @@ obj-$(CONFIG_PPC_INDIRECT_PCI) += indirect_pci.o
7obj-$(CONFIG_PPC_MPC106) += grackle.o 7obj-$(CONFIG_PPC_MPC106) += grackle.o
8obj-$(CONFIG_PPC_DCR) += dcr.o 8obj-$(CONFIG_PPC_DCR) += dcr.o
9obj-$(CONFIG_PPC_DCR_NATIVE) += dcr-low.o 9obj-$(CONFIG_PPC_DCR_NATIVE) += dcr-low.o
10obj-$(CONFIG_PPC_PMI) += pmi.o
10obj-$(CONFIG_U3_DART) += dart_iommu.o 11obj-$(CONFIG_U3_DART) += dart_iommu.o
11obj-$(CONFIG_MMIO_NVRAM) += mmio_nvram.o 12obj-$(CONFIG_MMIO_NVRAM) += mmio_nvram.o
12obj-$(CONFIG_FSL_SOC) += fsl_soc.o 13obj-$(CONFIG_FSL_SOC) += fsl_soc.o
diff --git a/arch/powerpc/sysdev/pmi.c b/arch/powerpc/sysdev/pmi.c
new file mode 100644
index 000000000000..a5282011d39e
--- /dev/null
+++ b/arch/powerpc/sysdev/pmi.c
@@ -0,0 +1,305 @@
1/*
2 * pmi driver
3 *
4 * (C) Copyright IBM Deutschland Entwicklung GmbH 2005
5 *
6 * PMI (Platform Management Interrupt) is a way to communicate
7 * with the BMC (Baseboard Management Controller) via interrupts.
8 * Unlike IPMI it is bidirectional and has a low latency.
9 *
10 * Author: Christian Krafft <krafft@de.ibm.com>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2, or (at your option)
15 * any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 */
26
27#include <linux/interrupt.h>
28#include <linux/completion.h>
29#include <linux/spinlock.h>
30#include <linux/workqueue.h>
31
32#include <asm/of_device.h>
33#include <asm/of_platform.h>
34#include <asm/io.h>
35#include <asm/pmi.h>
36
37
38struct pmi_data {
39 struct list_head handler;
40 spinlock_t handler_spinlock;
41 spinlock_t pmi_spinlock;
42 struct mutex msg_mutex;
43 pmi_message_t msg;
44 struct completion *completion;
45 struct of_device *dev;
46 int irq;
47 u8 __iomem *pmi_reg;
48 struct work_struct work;
49};
50
51
52
53static void __iomem *of_iomap(struct device_node *np)
54{
55 struct resource res;
56
57 if (of_address_to_resource(np, 0, &res))
58 return NULL;
59
60 pr_debug("Resource start: 0x%lx\n", res.start);
61 pr_debug("Resource end: 0x%lx\n", res.end);
62
63 return ioremap(res.start, 1 + res.end - res.start);
64}
65
66
67static int pmi_irq_handler(int irq, void *dev_id)
68{
69 struct pmi_data *data;
70 u8 type;
71 int rc;
72
73 data = dev_id;
74
75 spin_lock(&data->pmi_spinlock);
76
77 type = ioread8(data->pmi_reg + PMI_READ_TYPE);
78 pr_debug("pmi: got message of type %d\n", type);
79
80 if (type & PMI_ACK && !data->completion) {
81 printk(KERN_WARNING "pmi: got unexpected ACK message.\n");
82 rc = -EIO;
83 goto unlock;
84 }
85
86 if (data->completion && !(type & PMI_ACK)) {
87 printk(KERN_WARNING "pmi: expected ACK, but got %d\n", type);
88 rc = -EIO;
89 goto unlock;
90 }
91
92 data->msg.type = type;
93 data->msg.data0 = ioread8(data->pmi_reg + PMI_READ_DATA0);
94 data->msg.data1 = ioread8(data->pmi_reg + PMI_READ_DATA1);
95 data->msg.data2 = ioread8(data->pmi_reg + PMI_READ_DATA2);
96 rc = 0;
97unlock:
98 spin_unlock(&data->pmi_spinlock);
99
100 if (rc == -EIO) {
101 rc = IRQ_HANDLED;
102 goto out;
103 }
104
105 if (data->msg.type & PMI_ACK) {
106 complete(data->completion);
107 rc = IRQ_HANDLED;
108 goto out;
109 }
110
111 schedule_work(&data->work);
112
113 rc = IRQ_HANDLED;
114out:
115 return rc;
116}
117
118
119static struct of_device_id pmi_match[] = {
120 { .type = "ibm,pmi", .name = "ibm,pmi" },
121 {},
122};
123
124MODULE_DEVICE_TABLE(of, pmi_match);
125
126static void pmi_notify_handlers(struct work_struct *work)
127{
128 struct pmi_data *data;
129 struct pmi_handler *handler;
130
131 data = container_of(work, struct pmi_data, work);
132
133 spin_lock(&data->handler_spinlock);
134 list_for_each_entry(handler, &data->handler, node) {
135 pr_debug(KERN_INFO "pmi: notifying handler %p\n", handler);
136 if (handler->type == data->msg.type)
137 handler->handle_pmi_message(data->dev, data->msg);
138 }
139 spin_unlock(&data->handler_spinlock);
140}
141
142static int pmi_of_probe(struct of_device *dev,
143 const struct of_device_id *match)
144{
145 struct device_node *np = dev->node;
146 struct pmi_data *data;
147 int rc;
148
149 data = kzalloc(sizeof(struct pmi_data), GFP_KERNEL);
150 if (!data) {
151 printk(KERN_ERR "pmi: could not allocate memory.\n");
152 rc = -ENOMEM;
153 goto out;
154 }
155
156 data->pmi_reg = of_iomap(np);
157 if (!data->pmi_reg) {
158 printk(KERN_ERR "pmi: invalid register address.\n");
159 rc = -EFAULT;
160 goto error_cleanup_data;
161 }
162
163 INIT_LIST_HEAD(&data->handler);
164
165 mutex_init(&data->msg_mutex);
166 spin_lock_init(&data->pmi_spinlock);
167 spin_lock_init(&data->handler_spinlock);
168
169 INIT_WORK(&data->work, pmi_notify_handlers);
170
171 dev->dev.driver_data = data;
172 data->dev = dev;
173
174 data->irq = irq_of_parse_and_map(np, 0);
175 if (data->irq == NO_IRQ) {
176 printk(KERN_ERR "pmi: invalid interrupt.\n");
177 rc = -EFAULT;
178 goto error_cleanup_iomap;
179 }
180
181 rc = request_irq(data->irq, pmi_irq_handler, 0, "pmi", data);
182 if (rc) {
183 printk(KERN_ERR "pmi: can't request IRQ %d: returned %d\n",
184 data->irq, rc);
185 goto error_cleanup_iomap;
186 }
187
188 printk(KERN_INFO "pmi: found pmi device at addr %p.\n", data->pmi_reg);
189
190 goto out;
191
192error_cleanup_iomap:
193 iounmap(data->pmi_reg);
194
195error_cleanup_data:
196 kfree(data);
197
198out:
199 return rc;
200}
201
202static int pmi_of_remove(struct of_device *dev)
203{
204 struct pmi_data *data;
205 struct pmi_handler *handler, *tmp;
206
207 data = dev->dev.driver_data;
208
209 free_irq(data->irq, data);
210 iounmap(data->pmi_reg);
211
212 spin_lock(&data->handler_spinlock);
213
214 list_for_each_entry_safe(handler, tmp, &data->handler, node)
215 list_del(&handler->node);
216
217 spin_unlock(&data->handler_spinlock);
218
219 kfree(dev->dev.driver_data);
220
221 return 0;
222}
223
224static struct of_platform_driver pmi_of_platform_driver = {
225 .name = "pmi",
226 .match_table = pmi_match,
227 .probe = pmi_of_probe,
228 .remove = pmi_of_remove
229};
230
231static int __init pmi_module_init(void)
232{
233 return of_register_platform_driver(&pmi_of_platform_driver);
234}
235module_init(pmi_module_init);
236
237static void __exit pmi_module_exit(void)
238{
239 of_unregister_platform_driver(&pmi_of_platform_driver);
240}
241module_exit(pmi_module_exit);
242
243void pmi_send_message(struct of_device *device, pmi_message_t msg)
244{
245 struct pmi_data *data;
246 unsigned long flags;
247 DECLARE_COMPLETION_ONSTACK(completion);
248
249 data = device->dev.driver_data;
250
251 mutex_lock(&data->msg_mutex);
252
253 data->msg = msg;
254 pr_debug("pmi_send_message: msg is %08x\n", *(u32*)&msg);
255
256 data->completion = &completion;
257
258 spin_lock_irqsave(&data->pmi_spinlock, flags);
259 iowrite8(msg.data0, data->pmi_reg + PMI_WRITE_DATA0);
260 iowrite8(msg.data1, data->pmi_reg + PMI_WRITE_DATA1);
261 iowrite8(msg.data2, data->pmi_reg + PMI_WRITE_DATA2);
262 iowrite8(msg.type, data->pmi_reg + PMI_WRITE_TYPE);
263 spin_unlock_irqrestore(&data->pmi_spinlock, flags);
264
265 pr_debug("pmi_send_message: wait for completion\n");
266
267 wait_for_completion_interruptible_timeout(data->completion,
268 PMI_TIMEOUT);
269
270 data->completion = NULL;
271
272 mutex_unlock(&data->msg_mutex);
273}
274EXPORT_SYMBOL_GPL(pmi_send_message);
275
276void pmi_register_handler(struct of_device *device,
277 struct pmi_handler *handler)
278{
279 struct pmi_data *data;
280 data = device->dev.driver_data;
281
282 spin_lock(&data->handler_spinlock);
283 list_add_tail(&handler->node, &data->handler);
284 spin_unlock(&data->handler_spinlock);
285}
286EXPORT_SYMBOL_GPL(pmi_register_handler);
287
288void pmi_unregister_handler(struct of_device *device,
289 struct pmi_handler *handler)
290{
291 struct pmi_data *data;
292
293 pr_debug("pmi: unregistering handler %p\n", handler);
294
295 data = device->dev.driver_data;
296
297 spin_lock(&data->handler_spinlock);
298 list_del(&handler->node);
299 spin_unlock(&data->handler_spinlock);
300}
301EXPORT_SYMBOL_GPL(pmi_unregister_handler);
302
303MODULE_LICENSE("GPL");
304MODULE_AUTHOR("Christian Krafft <krafft@de.ibm.com>");
305MODULE_DESCRIPTION("IBM Platform Management Interrupt driver");