Management Complex (MC) Portal is an interface between MC firmware
and U-boot/Linux. U-boot/Linux could interact with MC firmware
through sending/receiving MC commands to/from MC firmware.
This patch enables the hardware interface between MC firmware and
U-boot/Linux. Current patch supports MC portal flib version 0.4.

Signed-off-by: Lijun Pan <lijun....@freescale.com>
---
 include/layerscape/mc_hardware/fsl_mc_cmd_common.h | 54 ++++++++++++++++++
 .../layerscape/mc_hardware/fsl_mc_dpmng_commands.h | 60 ++++++++++++++++++++
 include/layerscape/mc_hardware/fsl_mc_io.h         | 65 ++++++++++++++++++++++
 3 files changed, 179 insertions(+)
 create mode 100644 include/layerscape/mc_hardware/fsl_mc_cmd_common.h
 create mode 100644 include/layerscape/mc_hardware/fsl_mc_dpmng_commands.h
 create mode 100644 include/layerscape/mc_hardware/fsl_mc_io.h

diff --git a/include/layerscape/mc_hardware/fsl_mc_cmd_common.h 
b/include/layerscape/mc_hardware/fsl_mc_cmd_common.h
new file mode 100644
index 0000000..bf2a3d0
--- /dev/null
+++ b/include/layerscape/mc_hardware/fsl_mc_cmd_common.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2014 Freescale Semiconductor, Inc.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#ifndef __FSL_MC_CMD_COMMON_H
+#define __FSL_MC_CMD_COMMON_H
+
+#define MC_CMD_NUM_OF_PARAMS   7
+
+struct mc_command {
+       uint64_t header;
+       uint64_t params[MC_CMD_NUM_OF_PARAMS];
+};
+
+enum mc_cmd_status {
+       MC_CMD_STATUS_OK = 0x0, /* passed */
+       MC_CMD_STATUS_READY = 0x1,      /* Ready to be processed */
+       MC_CMD_STATUS_AUTH_ERR = 0x3,   /* Authentication error */
+       MC_CMD_STATUS_NO_PRIVILEGE = 0x4,
+       MC_CMD_STATUS_DMA_ERR = 0x5,
+       MC_CMD_STATUS_CONFIG_ERR = 0x6,
+       MC_CMD_STATUS_TIMEOUT = 0x7,
+       MC_CMD_STATUS_NO_RESOURCE = 0x8,
+       MC_CMD_STATUS_NO_MEMORY = 0x9,
+       MC_CMD_STATUS_BUSY = 0xA,
+       MC_CMD_STATUS_UNSUPPORTED_OP = 0xB,
+       MC_CMD_STATUS_INVALID_STATE = 0xC
+};
+
+/*
+ * MC command priorities
+ */
+enum mc_cmd_priorities {
+       CMDIF_PRI_LOW = 0,      /* Low Priority command indication */
+       CMDIF_PRI_HIGH = 1      /* High Priority command indication */
+};
+
+static inline uint64_t mc_encode_cmd_header(uint16_t cmd_id,
+                                           uint8_t cmd_size,
+                                           uint8_t priority, uint16_t auth_id)
+{
+       uint64_t header;
+
+       header = (cmd_id & 0xfffULL) << 52;
+       header |= (auth_id & 0x3ffULL) << 38;
+       header |= (cmd_size & 0x3fULL) << 31;
+       header |= (priority & 0x1ULL) << 15;
+       header |= (MC_CMD_STATUS_READY & 0xff) << 16;
+
+       return header;
+}
+#endif /* __FSL_MC_CMD_COMMON_H */
diff --git a/include/layerscape/mc_hardware/fsl_mc_dpmng_commands.h 
b/include/layerscape/mc_hardware/fsl_mc_dpmng_commands.h
new file mode 100644
index 0000000..fa3c078
--- /dev/null
+++ b/include/layerscape/mc_hardware/fsl_mc_dpmng_commands.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2014 Freescale Semiconductor, Inc.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/*
+ * fsl_mc_dpmng_commands.h
+ * Management Complex (MC) Data Path Management commands
+ */
+#ifndef _FSL_MC_DPMNG_COMMANDS_H
+#define _FSL_MC_DPMNG_COMMANDS_H
+
+#include <layerscape/mc_hardware/fsl_mc_cmd_common.h>
+#include <linux/compat.h>
+
+/*
+ * Define Management Complex firmware version information
+ */
+#define MC_VER_MAJOR   2
+#define MC_VER_MINOR   0
+
+/*
+ * Management Complex firmware version information
+ */
+struct mc_version {
+       uint32_t major;
+       /* Major version number: incremented on API compatibility changes */
+       uint32_t minor;
+       /* Minor version number: incremented on API additions (backward
+        * compatible); reset when major version is incremented. */
+       uint32_t revision;
+       /* Internal revision number: incremented on implementation changes
+        * and/or bug fixes that have no impact on API */
+};
+
+/*
+ * Retrieves the Management Complex firmware version information
+ */
+#define DPMNG_CMDID_GET_VERSION                0x831
+#define DPMNG_CMDSZ_GET_VERSION                (8 * 2)
+
+static inline void build_cmd_mc_get_version(struct mc_command *cmd)
+{
+       cmd->header = mc_encode_cmd_header(DPMNG_CMDID_GET_VERSION,
+                                          DPMNG_CMDSZ_GET_VERSION,
+                                          CMDIF_PRI_LOW, 0);
+
+       memset(cmd->params, 0, sizeof(cmd->params));
+}
+
+static inline void parse_resp_mc_get_version(struct mc_command *cmd,
+                                            struct mc_version *mc_ver_info)
+{
+       mc_ver_info->revision = lower_32_bits(cmd->params[0]);
+       mc_ver_info->major = upper_32_bits(cmd->params[0]);
+       mc_ver_info->minor = cmd->params[1] & 0xff;
+}
+
+#endif /* _FSL_MC_DPMNG_COMMANDS_H */
diff --git a/include/layerscape/mc_hardware/fsl_mc_io.h 
b/include/layerscape/mc_hardware/fsl_mc_io.h
new file mode 100644
index 0000000..f121238
--- /dev/null
+++ b/include/layerscape/mc_hardware/fsl_mc_io.h
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2014 Freescale Semiconductor, Inc.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#ifndef __FSL_MC_IO_H
+#define __FSL_MC_IO_H
+
+#include <layerscape/mc_hardware/fsl_mc_cmd_common.h>
+
+/**
+ * mc_write_command - writes a command to a Management Complex (MC) portal
+ *
+ * @portal_regs: pointer to an MC portal's MMIO registers
+ * @cmd: pointer to a filled command
+ */
+static inline void __must_check mc_write_command(struct mc_command __iomem *
+                                               portal_regs,
+                                               struct mc_command *cmd)
+{
+       int i;
+
+       /* copy command parameters into the portal MMIO registers */
+       for (i = 0; i < MC_CMD_NUM_OF_PARAMS; i++)
+               writeq(cmd->params[i], &portal_regs->params[i]);
+
+       /* submit the command by writing the header */
+       writeq(cmd->header, &portal_regs->header);
+}
+
+/**
+ * mc_read_response - reads the response for the last MC command from a
+ * Management Complex (MC) portal
+ *
+ * @portal_regs: pointer to an MC portal's MMIO registers
+ * @response: pointer to command response buffer
+ *
+ * Returns MC_CMD_STATUS_OK on Success; Error code otherwise.
+ */
+static inline enum mc_cmd_status __must_check mc_read_response(struct 
mc_command
+                                                              __iomem *
+                                                              portal_regs,
+                                                              struct mc_command
+                                                              *response)
+{
+       int i;
+       enum mc_cmd_status status;
+
+       /* Copy command response header from MC portal MMIO space: */
+       response->header = readq(&portal_regs->header);
+       status = (response->header >> 16) & 0xff;
+
+       if (status != MC_CMD_STATUS_OK)
+               goto out;
+
+       /* Copy command response data from MC portal MMIO space: */
+       for (i = 0; i < MC_CMD_NUM_OF_PARAMS; i++)
+               response->params[i] = readq(&portal_regs->params[i]);
+
+out:
+       return status;
+}
+
+#endif /* __FSL_MC_IO_H */
-- 
1.9.3

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to