^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * pmi driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * (C) Copyright IBM Deutschland Entwicklung GmbH 2005
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * PMI (Platform Management Interrupt) is a way to communicate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * with the BMC (Baseboard Management Controller) via interrupts.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Unlike IPMI it is bidirectional and has a low latency.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Author: Christian Krafft <krafft@de.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/completion.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/of_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/of_platform.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <asm/pmi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <asm/prom.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) struct pmi_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) struct list_head handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) spinlock_t handler_spinlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) spinlock_t pmi_spinlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct mutex msg_mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) pmi_message_t msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct completion *completion;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) struct platform_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) int irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) u8 __iomem *pmi_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) struct work_struct work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) static struct pmi_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) static irqreturn_t pmi_irq_handler(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) u8 type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) spin_lock(&data->pmi_spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) type = ioread8(data->pmi_reg + PMI_READ_TYPE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) pr_debug("pmi: got message of type %d\n", type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) if (type & PMI_ACK && !data->completion) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) printk(KERN_WARNING "pmi: got unexpected ACK message.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) if (data->completion && !(type & PMI_ACK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) printk(KERN_WARNING "pmi: expected ACK, but got %d\n", type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) data->msg.type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) data->msg.data0 = ioread8(data->pmi_reg + PMI_READ_DATA0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) data->msg.data1 = ioread8(data->pmi_reg + PMI_READ_DATA1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) data->msg.data2 = ioread8(data->pmi_reg + PMI_READ_DATA2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) spin_unlock(&data->pmi_spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) if (rc == -EIO) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) rc = IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) if (data->msg.type & PMI_ACK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) complete(data->completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) rc = IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) schedule_work(&data->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) rc = IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) static const struct of_device_id pmi_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) { .type = "ibm,pmi", .name = "ibm,pmi" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) { .type = "ibm,pmi" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) MODULE_DEVICE_TABLE(of, pmi_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) static void pmi_notify_handlers(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) struct pmi_handler *handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) spin_lock(&data->handler_spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) list_for_each_entry(handler, &data->handler, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) pr_debug("pmi: notifying handler %p\n", handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) if (handler->type == data->msg.type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) handler->handle_pmi_message(data->msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) spin_unlock(&data->handler_spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) static int pmi_of_probe(struct platform_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) struct device_node *np = dev->dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) if (data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) printk(KERN_ERR "pmi: driver has already been initialized.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) rc = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) data = kzalloc(sizeof(struct pmi_data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) if (!data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) printk(KERN_ERR "pmi: could not allocate memory.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) data->pmi_reg = of_iomap(np, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) if (!data->pmi_reg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) printk(KERN_ERR "pmi: invalid register address.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) rc = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) goto error_cleanup_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) INIT_LIST_HEAD(&data->handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) mutex_init(&data->msg_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) spin_lock_init(&data->pmi_spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) spin_lock_init(&data->handler_spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) INIT_WORK(&data->work, pmi_notify_handlers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) data->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) data->irq = irq_of_parse_and_map(np, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) if (!data->irq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) printk(KERN_ERR "pmi: invalid interrupt.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) rc = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) goto error_cleanup_iomap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) rc = request_irq(data->irq, pmi_irq_handler, 0, "pmi", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) printk(KERN_ERR "pmi: can't request IRQ %d: returned %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) data->irq, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) goto error_cleanup_iomap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) printk(KERN_INFO "pmi: found pmi device at addr %p.\n", data->pmi_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) error_cleanup_iomap:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) iounmap(data->pmi_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) error_cleanup_data:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) kfree(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) static int pmi_of_remove(struct platform_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) struct pmi_handler *handler, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) free_irq(data->irq, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) iounmap(data->pmi_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) spin_lock(&data->handler_spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) list_for_each_entry_safe(handler, tmp, &data->handler, node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) list_del(&handler->node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) spin_unlock(&data->handler_spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) kfree(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) static struct platform_driver pmi_of_platform_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) .probe = pmi_of_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) .remove = pmi_of_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) .name = "pmi",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) .of_match_table = pmi_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) module_platform_driver(pmi_of_platform_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) int pmi_send_message(pmi_message_t msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) DECLARE_COMPLETION_ONSTACK(completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) mutex_lock(&data->msg_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) data->msg = msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) pr_debug("pmi_send_message: msg is %08x\n", *(u32*)&msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) data->completion = &completion;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) spin_lock_irqsave(&data->pmi_spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) iowrite8(msg.data0, data->pmi_reg + PMI_WRITE_DATA0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) iowrite8(msg.data1, data->pmi_reg + PMI_WRITE_DATA1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) iowrite8(msg.data2, data->pmi_reg + PMI_WRITE_DATA2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) iowrite8(msg.type, data->pmi_reg + PMI_WRITE_TYPE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) spin_unlock_irqrestore(&data->pmi_spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) pr_debug("pmi_send_message: wait for completion\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) wait_for_completion_interruptible_timeout(data->completion,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) PMI_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) data->completion = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) mutex_unlock(&data->msg_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) EXPORT_SYMBOL_GPL(pmi_send_message);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) int pmi_register_handler(struct pmi_handler *handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) spin_lock(&data->handler_spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) list_add_tail(&handler->node, &data->handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) spin_unlock(&data->handler_spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) EXPORT_SYMBOL_GPL(pmi_register_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) void pmi_unregister_handler(struct pmi_handler *handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) pr_debug("pmi: unregistering handler %p\n", handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) spin_lock(&data->handler_spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) list_del(&handler->node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) spin_unlock(&data->handler_spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) EXPORT_SYMBOL_GPL(pmi_unregister_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) MODULE_AUTHOR("Christian Krafft <krafft@de.ibm.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) MODULE_DESCRIPTION("IBM Platform Management Interrupt driver");