Merge "amlogic: scpi: Add support to retrieve chip ID" into integration
diff --git a/plat/amlogic/common/aml_scpi.c b/plat/amlogic/common/aml_scpi.c
index 728bcd0..c8a6772 100644
--- a/plat/amlogic/common/aml_scpi.c
+++ b/plat/amlogic/common/aml_scpi.c
@@ -25,6 +25,7 @@
 
 #define SCPI_CMD_JTAG_SET_STATE		0xC0
 #define SCPI_CMD_EFUSE_READ		0xC2
+#define SCPI_CMD_CHIP_ID		0xC6
 
 #define SCPI_CMD_COPY_FW 0xd4
 #define SCPI_CMD_SET_FW_ADDR 0xd3
@@ -142,6 +143,28 @@
 	aml_mhu_secure_message_end();
 }
 
+uint32_t aml_scpi_get_chip_id(uint8_t *obuff, uint32_t osize)
+{
+	uint32_t *response;
+	size_t resp_size;
+
+	if ((osize != 16) && (osize != 12))
+		return 0;
+
+	aml_mhu_secure_message_start();
+	aml_mhu_secure_message_send(aml_scpi_cmd(SCPI_CMD_CHIP_ID, osize));
+	aml_scpi_secure_message_receive((void *)&response, &resp_size);
+	aml_mhu_secure_message_end();
+
+	if (!((resp_size == 16) && (osize == 16)) &&
+	    !((resp_size == 0) && (osize == 12)))
+		return 0;
+
+	memcpy((void *)obuff, (const void *)response, osize);
+
+	return osize;
+}
+
 static inline void aml_scpi_copy_scp_data(uint8_t *data, size_t len)
 {
 	void *dst = (void *)AML_MHU_SECURE_AP_TO_SCP_PAYLOAD;
diff --git a/plat/amlogic/common/aml_sip_svc.c b/plat/amlogic/common/aml_sip_svc.c
index 8a9b070..ab4c015 100644
--- a/plat/amlogic/common/aml_sip_svc.c
+++ b/plat/amlogic/common/aml_sip_svc.c
@@ -9,9 +9,39 @@
 #include <lib/mmio.h>
 #include <platform_def.h>
 #include <stdint.h>
+#include <string.h>
 
 #include "aml_private.h"
 
+struct aml_cpu_info {
+	uint32_t version;
+	uint8_t chip_id[16];
+};
+
+static int aml_sip_get_chip_id(uint64_t version)
+{
+	struct aml_cpu_info *info = (void *)AML_SHARE_MEM_OUTPUT_BASE;
+	uint32_t size;
+
+	if (version > 2)
+		return -1;
+
+	memset(info, 0, sizeof(struct aml_cpu_info));
+
+	if (version == 2) {
+		info->version = 2;
+		size = 16;
+	} else {
+		info->version = 1;
+		size = 12;
+	}
+
+	if (aml_scpi_get_chip_id(info->chip_id, size) == 0)
+		return -1;
+
+	return 0;
+}
+
 /*******************************************************************************
  * This function is responsible for handling all SiP calls
  ******************************************************************************/
@@ -47,6 +77,9 @@
 		aml_scpi_jtag_set_state(AML_JTAG_STATE_OFF, x1);
 		SMC_RET1(handle, 0);
 
+	case AML_SM_GET_CHIP_ID:
+		SMC_RET1(handle, aml_sip_get_chip_id(x1));
+
 	default:
 		ERROR("BL31: Unhandled SIP SMC: 0x%08x\n", smc_fid);
 		break;
diff --git a/plat/amlogic/common/include/aml_private.h b/plat/amlogic/common/include/aml_private.h
index 4923745..724f382 100644
--- a/plat/amlogic/common/include/aml_private.h
+++ b/plat/amlogic/common/include/aml_private.h
@@ -31,6 +31,7 @@
 void aml_scpi_unknown_thermal(uint32_t arg0, uint32_t arg1,
 			      uint32_t arg2, uint32_t arg3);
 void aml_scpi_upload_scp_fw(uintptr_t addr, size_t size, int send);
+uint32_t aml_scpi_get_chip_id(uint8_t *obuff, uint32_t osize);
 
 /* Peripherals */
 void aml_thermal_unknown(void);
diff --git a/plat/amlogic/gxbb/gxbb_def.h b/plat/amlogic/gxbb/gxbb_def.h
index 2f6d1d2..59d9cc9 100644
--- a/plat/amlogic/gxbb/gxbb_def.h
+++ b/plat/amlogic/gxbb/gxbb_def.h
@@ -106,6 +106,7 @@
 
 #define AML_SM_JTAG_ON				U(0x82000040)
 #define AML_SM_JTAG_OFF				U(0x82000041)
+#define AML_SM_GET_CHIP_ID			U(0x82000044)
 
 #define AML_JTAG_STATE_ON			U(0)
 #define AML_JTAG_STATE_OFF			U(1)
diff --git a/plat/amlogic/gxl/gxl_def.h b/plat/amlogic/gxl/gxl_def.h
index 6f49ed2..1e1a934 100644
--- a/plat/amlogic/gxl/gxl_def.h
+++ b/plat/amlogic/gxl/gxl_def.h
@@ -116,6 +116,7 @@
 
 #define AML_SM_JTAG_ON				U(0x82000040)
 #define AML_SM_JTAG_OFF				U(0x82000041)
+#define AML_SM_GET_CHIP_ID			U(0x82000044)
 
 #define AML_JTAG_STATE_ON			U(0)
 #define AML_JTAG_STATE_OFF			U(1)