[Skiboot] [PATCH] Move ipmi-opal.c from hw/ipmi to core
Vasant Hegde
hegdevasant at linux.vnet.ibm.com
Tue Mar 15 21:23:54 AEDT 2016
ipmi-opal.c contain OPAL API related functions. Commit a561cf7b added IPMI
support for FSP based system. Now FSP and AMI BMC based system makes use of
these functions. Hence move this file from hw specific dir to core dir.
Signed-off-by: Vasant Hegde <hegdevasant at linux.vnet.ibm.com>
---
@Stewart,
Feel free to ignore this patch, if you think its fine to keep this file
under hw/ipmi.
-Vasant
core/Makefile.inc | 2 -
core/ipmi-opal.c | 141 ++++++++++++++++++++++++++++++++++++++++++++++++++
hw/ipmi/Makefile.inc | 2 -
hw/ipmi/ipmi-opal.c | 141 --------------------------------------------------
4 files changed, 143 insertions(+), 143 deletions(-)
create mode 100644 core/ipmi-opal.c
delete mode 100644 hw/ipmi/ipmi-opal.c
diff --git a/core/Makefile.inc b/core/Makefile.inc
index 83370c1..5af0d7c 100644
--- a/core/Makefile.inc
+++ b/core/Makefile.inc
@@ -7,7 +7,7 @@ CORE_OBJS += timebase.o opal-msg.o pci.o pci-opal.o fast-reboot.o
CORE_OBJS += device.o exceptions.o trace.o affinity.o vpd.o
CORE_OBJS += hostservices.o platform.o nvram.o nvram-format.o hmi.o
CORE_OBJS += console-log.o ipmi.o time-utils.o pel.o pool.o errorlog.o
-CORE_OBJS += timer.o i2c.o rtc.o flash.o sensor.o
+CORE_OBJS += timer.o i2c.o rtc.o flash.o sensor.o ipmi-opal.o
ifeq ($(SKIBOOT_GCOV),1)
CORE_OBJS += gcov-profiling.o
diff --git a/core/ipmi-opal.c b/core/ipmi-opal.c
new file mode 100644
index 0000000..1b28aa6
--- /dev/null
+++ b/core/ipmi-opal.c
@@ -0,0 +1,141 @@
+/* Copyright 2013-2014 IBM Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <ipmi.h>
+#include <lock.h>
+#include <opal.h>
+#include <device.h>
+#include <ccan/list/list.h>
+
+static struct lock msgq_lock = LOCK_UNLOCKED;
+static struct list_head msgq = LIST_HEAD_INIT(msgq);
+
+static void opal_send_complete(struct ipmi_msg *msg)
+{
+ lock(&msgq_lock);
+ list_add_tail(&msgq, &msg->link);
+ opal_update_pending_evt(ipmi_backend->opal_event_ipmi_recv,
+ ipmi_backend->opal_event_ipmi_recv);
+ unlock(&msgq_lock);
+}
+
+static int64_t opal_ipmi_send(uint64_t interface,
+ struct opal_ipmi_msg *opal_ipmi_msg, uint64_t msg_len)
+{
+ struct ipmi_msg *msg;
+
+ if (opal_ipmi_msg->version != OPAL_IPMI_MSG_FORMAT_VERSION_1) {
+ prerror("OPAL IPMI: Incorrect version\n");
+ return OPAL_UNSUPPORTED;
+ }
+
+ msg_len -= sizeof(struct opal_ipmi_msg);
+ if (msg_len > IPMI_MAX_REQ_SIZE) {
+ prerror("OPAL IPMI: Invalid request length\n");
+ return OPAL_PARAMETER;
+ }
+
+ prlog(PR_DEBUG, "opal_ipmi_send(cmd: 0x%02x netfn: 0x%02x len: 0x%02llx)\n",
+ opal_ipmi_msg->cmd, opal_ipmi_msg->netfn >> 2, msg_len);
+
+ msg = ipmi_mkmsg(interface,
+ IPMI_CODE(opal_ipmi_msg->netfn >> 2, opal_ipmi_msg->cmd),
+ opal_send_complete, NULL, opal_ipmi_msg->data,
+ msg_len, IPMI_MAX_RESP_SIZE);
+ if (!msg)
+ return OPAL_RESOURCE;
+
+ msg->complete = opal_send_complete;
+ msg->error = opal_send_complete;
+ return ipmi_queue_msg(msg);
+}
+
+static int64_t opal_ipmi_recv(uint64_t interface,
+ struct opal_ipmi_msg *opal_ipmi_msg, uint64_t *msg_len)
+{
+ struct ipmi_msg *msg;
+ int64_t rc;
+
+ lock(&msgq_lock);
+ msg = list_top(&msgq, struct ipmi_msg, link);
+
+ if (!msg) {
+ rc = OPAL_EMPTY;
+ goto out_unlock;
+ }
+
+ if (opal_ipmi_msg->version != OPAL_IPMI_MSG_FORMAT_VERSION_1) {
+ prerror("OPAL IPMI: Incorrect version\n");
+ rc = OPAL_UNSUPPORTED;
+ goto out_del_msg;
+ }
+
+ if (interface != IPMI_DEFAULT_INTERFACE) {
+ prerror("IPMI: Invalid interface 0x%llx in opal_ipmi_recv\n", interface);
+ rc = OPAL_PARAMETER;
+ goto out_del_msg;
+ }
+
+ if (*msg_len - sizeof(struct opal_ipmi_msg) < msg->resp_size + 1) {
+ rc = OPAL_RESOURCE;
+ goto out_del_msg;
+ }
+
+ list_del(&msg->link);
+ if (list_empty(&msgq))
+ opal_update_pending_evt(ipmi_backend->opal_event_ipmi_recv, 0);
+ unlock(&msgq_lock);
+
+ opal_ipmi_msg->cmd = msg->cmd;
+ opal_ipmi_msg->netfn = msg->netfn;
+ opal_ipmi_msg->data[0] = msg->cc;
+ memcpy(&opal_ipmi_msg->data[1], msg->data, msg->resp_size);
+
+ prlog(PR_DEBUG, "opal_ipmi_recv(cmd: 0x%02x netfn: 0x%02x resp_size: 0x%02x)\n",
+ msg->cmd, msg->netfn >> 2, msg->resp_size);
+
+ /* Add one as the completion code is returned in the message data */
+ *msg_len = msg->resp_size + sizeof(struct opal_ipmi_msg) + 1;
+ ipmi_free_msg(msg);
+
+ return OPAL_SUCCESS;
+
+out_del_msg:
+ list_del(&msg->link);
+ if (list_empty(&msgq))
+ opal_update_pending_evt(ipmi_backend->opal_event_ipmi_recv, 0);
+ ipmi_free_msg(msg);
+out_unlock:
+ unlock(&msgq_lock);
+ return rc;
+}
+
+void ipmi_opal_init(void)
+{
+ struct dt_node *opal_ipmi;
+
+ opal_ipmi = dt_new(opal_node, "ipmi");
+ dt_add_property_strings(opal_ipmi, "compatible", "ibm,opal-ipmi");
+ dt_add_property_cells(opal_ipmi, "ibm,ipmi-interface-id",
+ IPMI_DEFAULT_INTERFACE);
+ dt_add_property_cells(opal_ipmi, "interrupts",
+ ilog2(ipmi_backend->opal_event_ipmi_recv));
+
+ opal_register(OPAL_IPMI_SEND, opal_ipmi_send, 3);
+ opal_register(OPAL_IPMI_RECV, opal_ipmi_recv, 3);
+}
diff --git a/hw/ipmi/Makefile.inc b/hw/ipmi/Makefile.inc
index 6325369..a54602c 100644
--- a/hw/ipmi/Makefile.inc
+++ b/hw/ipmi/Makefile.inc
@@ -1,6 +1,6 @@
SUBDIRS += hw/ipmi
-IPMI_OBJS = ipmi-rtc.o ipmi-power.o ipmi-opal.o ipmi-fru.o ipmi-sel.o
+IPMI_OBJS = ipmi-rtc.o ipmi-power.o ipmi-fru.o ipmi-sel.o
IPMI_OBJS += ipmi-watchdog.o ipmi-sensor.o ipmi-attn.o
IPMI = hw/ipmi/built-in.o
diff --git a/hw/ipmi/ipmi-opal.c b/hw/ipmi/ipmi-opal.c
deleted file mode 100644
index 1b28aa6..0000000
--- a/hw/ipmi/ipmi-opal.c
+++ /dev/null
@@ -1,141 +0,0 @@
-/* Copyright 2013-2014 IBM Corp.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- * implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <ipmi.h>
-#include <lock.h>
-#include <opal.h>
-#include <device.h>
-#include <ccan/list/list.h>
-
-static struct lock msgq_lock = LOCK_UNLOCKED;
-static struct list_head msgq = LIST_HEAD_INIT(msgq);
-
-static void opal_send_complete(struct ipmi_msg *msg)
-{
- lock(&msgq_lock);
- list_add_tail(&msgq, &msg->link);
- opal_update_pending_evt(ipmi_backend->opal_event_ipmi_recv,
- ipmi_backend->opal_event_ipmi_recv);
- unlock(&msgq_lock);
-}
-
-static int64_t opal_ipmi_send(uint64_t interface,
- struct opal_ipmi_msg *opal_ipmi_msg, uint64_t msg_len)
-{
- struct ipmi_msg *msg;
-
- if (opal_ipmi_msg->version != OPAL_IPMI_MSG_FORMAT_VERSION_1) {
- prerror("OPAL IPMI: Incorrect version\n");
- return OPAL_UNSUPPORTED;
- }
-
- msg_len -= sizeof(struct opal_ipmi_msg);
- if (msg_len > IPMI_MAX_REQ_SIZE) {
- prerror("OPAL IPMI: Invalid request length\n");
- return OPAL_PARAMETER;
- }
-
- prlog(PR_DEBUG, "opal_ipmi_send(cmd: 0x%02x netfn: 0x%02x len: 0x%02llx)\n",
- opal_ipmi_msg->cmd, opal_ipmi_msg->netfn >> 2, msg_len);
-
- msg = ipmi_mkmsg(interface,
- IPMI_CODE(opal_ipmi_msg->netfn >> 2, opal_ipmi_msg->cmd),
- opal_send_complete, NULL, opal_ipmi_msg->data,
- msg_len, IPMI_MAX_RESP_SIZE);
- if (!msg)
- return OPAL_RESOURCE;
-
- msg->complete = opal_send_complete;
- msg->error = opal_send_complete;
- return ipmi_queue_msg(msg);
-}
-
-static int64_t opal_ipmi_recv(uint64_t interface,
- struct opal_ipmi_msg *opal_ipmi_msg, uint64_t *msg_len)
-{
- struct ipmi_msg *msg;
- int64_t rc;
-
- lock(&msgq_lock);
- msg = list_top(&msgq, struct ipmi_msg, link);
-
- if (!msg) {
- rc = OPAL_EMPTY;
- goto out_unlock;
- }
-
- if (opal_ipmi_msg->version != OPAL_IPMI_MSG_FORMAT_VERSION_1) {
- prerror("OPAL IPMI: Incorrect version\n");
- rc = OPAL_UNSUPPORTED;
- goto out_del_msg;
- }
-
- if (interface != IPMI_DEFAULT_INTERFACE) {
- prerror("IPMI: Invalid interface 0x%llx in opal_ipmi_recv\n", interface);
- rc = OPAL_PARAMETER;
- goto out_del_msg;
- }
-
- if (*msg_len - sizeof(struct opal_ipmi_msg) < msg->resp_size + 1) {
- rc = OPAL_RESOURCE;
- goto out_del_msg;
- }
-
- list_del(&msg->link);
- if (list_empty(&msgq))
- opal_update_pending_evt(ipmi_backend->opal_event_ipmi_recv, 0);
- unlock(&msgq_lock);
-
- opal_ipmi_msg->cmd = msg->cmd;
- opal_ipmi_msg->netfn = msg->netfn;
- opal_ipmi_msg->data[0] = msg->cc;
- memcpy(&opal_ipmi_msg->data[1], msg->data, msg->resp_size);
-
- prlog(PR_DEBUG, "opal_ipmi_recv(cmd: 0x%02x netfn: 0x%02x resp_size: 0x%02x)\n",
- msg->cmd, msg->netfn >> 2, msg->resp_size);
-
- /* Add one as the completion code is returned in the message data */
- *msg_len = msg->resp_size + sizeof(struct opal_ipmi_msg) + 1;
- ipmi_free_msg(msg);
-
- return OPAL_SUCCESS;
-
-out_del_msg:
- list_del(&msg->link);
- if (list_empty(&msgq))
- opal_update_pending_evt(ipmi_backend->opal_event_ipmi_recv, 0);
- ipmi_free_msg(msg);
-out_unlock:
- unlock(&msgq_lock);
- return rc;
-}
-
-void ipmi_opal_init(void)
-{
- struct dt_node *opal_ipmi;
-
- opal_ipmi = dt_new(opal_node, "ipmi");
- dt_add_property_strings(opal_ipmi, "compatible", "ibm,opal-ipmi");
- dt_add_property_cells(opal_ipmi, "ibm,ipmi-interface-id",
- IPMI_DEFAULT_INTERFACE);
- dt_add_property_cells(opal_ipmi, "interrupts",
- ilog2(ipmi_backend->opal_event_ipmi_recv));
-
- opal_register(OPAL_IPMI_SEND, opal_ipmi_send, 3);
- opal_register(OPAL_IPMI_RECV, opal_ipmi_recv, 3);
-}
More information about the Skiboot
mailing list