amlogic: scpi: Add support to retrieve chip ID
authorCarlo Caione <ccaione@baylibre.com>
Mon, 16 Sep 2019 11:13:49 +0000 (12:13 +0100)
committerCarlo Caione <ccaione@baylibre.com>
Tue, 17 Sep 2019 12:11:50 +0000 (13:11 +0100)
Both kernel and U-Boot use a SMC call to the secure monitor to get the
chip ID. This call is translated by BL31 to a call to the SCP to
retrieve the ID. Add a new SiP call and the backing SCPI command.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
Change-Id: Ib128f5645ee92866e7ebbcd550dacd33f573524b

plat/amlogic/common/aml_scpi.c
plat/amlogic/common/aml_sip_svc.c
plat/amlogic/common/include/aml_private.h
plat/amlogic/gxbb/gxbb_def.h
plat/amlogic/gxl/gxl_def.h

index 728bcd0616598430f3a580f6c0975c261c8a589d..c8a6772c0776616f596d355f036ec0e5c6fdcfa3 100644 (file)
@@ -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 @@ void aml_scpi_unknown_thermal(uint32_t arg0, uint32_t arg1,
        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;
index 8a9b070d82761e19374796a7abf56af7e55f1d24..ab4c01563362c730a2c9e5a0de7a3933801d2140 100644 (file)
@@ -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 @@ static uintptr_t aml_sip_handler(uint32_t smc_fid,
                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;
index 4923745687ea35fed4168cd4e982aaeef72ce115..724f382fb1a26d33060e9627d37989f879df30f3 100644 (file)
@@ -31,6 +31,7 @@ uint32_t aml_scpi_efuse_read(void *dst, uint32_t base, uint32_t size);
 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);
index 2f6d1d2aecf80279cdc222eb4a032dbba22ed8a2..59d9cc9acb79b73dfa06e430a17bf2fe762fa7a7 100644 (file)
 
 #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)
index 6f49ed2b0b6dde684fcc4ba2105cebe243f047b7..1e1a934d8ab69ceb404731901d85170dde685763 100644 (file)
 
 #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)