arch: meson: use secure monitor driver

Now we have to use UCLASS_SM driver instead of
raw smc_call() function call.

Signed-off-by: Alexey Romanov <avromanov@salutedevices.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Link: https://lore.kernel.org/r/20230921081346.22157-9-avromanov@salutedevices.com
Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
This commit is contained in:
Alexey Romanov 2023-09-21 11:13:41 +03:00 committed by Neil Armstrong
parent 67c03a9474
commit 7cd53e0d52
2 changed files with 58 additions and 53 deletions

View file

@ -11,6 +11,7 @@ config MESON64_COMMON
select PWRSEQ select PWRSEQ
select MMC_PWRSEQ select MMC_PWRSEQ
select BOARD_LATE_INIT select BOARD_LATE_INIT
select MESON_SM
imply CMD_DM imply CMD_DM
config MESON_GX config MESON_GX

View file

@ -9,6 +9,7 @@
#include <dm.h> #include <dm.h>
#include <log.h> #include <log.h>
#include <regmap.h> #include <regmap.h>
#include <sm.h>
#include <syscon.h> #include <syscon.h>
#include <asm/arch/sm.h> #include <asm/arch/sm.h>
#include <asm/cache.h> #include <asm/cache.h>
@ -18,70 +19,62 @@
#include <linux/err.h> #include <linux/err.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/bitfield.h> #include <linux/bitfield.h>
#include <meson/sm.h>
#define FN_GET_SHARE_MEM_INPUT_BASE 0x82000020 static inline struct udevice *meson_get_sm_device(void)
#define FN_GET_SHARE_MEM_OUTPUT_BASE 0x82000021
#define FN_EFUSE_READ 0x82000030
#define FN_EFUSE_WRITE 0x82000031
#define FN_CHIP_ID 0x82000044
#define FN_PWRDM_SET 0x82000093
static void *shmem_input;
static void *shmem_output;
static void meson_init_shmem(void)
{ {
struct pt_regs regs; struct udevice *dev;
int err;
if (shmem_input && shmem_output) err = uclass_first_device_err(UCLASS_SM, &dev);
return; if (err) {
pr_err("Mesom SM device not found\n");
return ERR_PTR(err);
}
regs.regs[0] = FN_GET_SHARE_MEM_INPUT_BASE; return dev;
smc_call(&regs);
shmem_input = (void *)regs.regs[0];
regs.regs[0] = FN_GET_SHARE_MEM_OUTPUT_BASE;
smc_call(&regs);
shmem_output = (void *)regs.regs[0];
debug("Secure Monitor shmem: 0x%p 0x%p\n", shmem_input, shmem_output);
} }
ssize_t meson_sm_read_efuse(uintptr_t offset, void *buffer, size_t size) ssize_t meson_sm_read_efuse(uintptr_t offset, void *buffer, size_t size)
{ {
struct pt_regs regs; struct udevice *dev;
struct pt_regs regs = { 0 };
int err;
meson_init_shmem(); dev = meson_get_sm_device();
if (IS_ERR(dev))
return PTR_ERR(dev);
regs.regs[0] = FN_EFUSE_READ;
regs.regs[1] = offset; regs.regs[1] = offset;
regs.regs[2] = size; regs.regs[2] = size;
smc_call(&regs); err = sm_call_read(dev, buffer, size,
MESON_SMC_CMD_EFUSE_READ, &regs);
if (err < 0)
pr_err("Failed to read efuse memory (%d)\n", err);
if (regs.regs[0] == 0) return err;
return -1;
memcpy(buffer, shmem_output, min(size, regs.regs[0]));
return regs.regs[0];
} }
ssize_t meson_sm_write_efuse(uintptr_t offset, void *buffer, size_t size) ssize_t meson_sm_write_efuse(uintptr_t offset, void *buffer, size_t size)
{ {
struct pt_regs regs; struct udevice *dev;
struct pt_regs regs = { 0 };
int err;
meson_init_shmem(); dev = meson_get_sm_device();
if (IS_ERR(dev))
return PTR_ERR(dev);
memcpy(shmem_input, buffer, size);
regs.regs[0] = FN_EFUSE_WRITE;
regs.regs[1] = offset; regs.regs[1] = offset;
regs.regs[2] = size; regs.regs[2] = size;
smc_call(&regs); err = sm_call_write(dev, buffer, size,
MESON_SMC_CMD_EFUSE_WRITE, &regs);
if (err < 0)
pr_err("Failed to write efuse memory (%d)\n", err);
return regs.regs[0]; return err;
} }
#define SM_CHIP_ID_LENGTH 119 #define SM_CHIP_ID_LENGTH 119
@ -90,18 +83,21 @@ ssize_t meson_sm_write_efuse(uintptr_t offset, void *buffer, size_t size)
int meson_sm_get_serial(void *buffer, size_t size) int meson_sm_get_serial(void *buffer, size_t size)
{ {
struct pt_regs regs; struct udevice *dev;
struct pt_regs regs = { 0 };
u8 id_buffer[SM_CHIP_ID_LENGTH];
int err;
meson_init_shmem(); dev = meson_get_sm_device();
if (IS_ERR(dev))
return PTR_ERR(dev);
regs.regs[0] = FN_CHIP_ID; err = sm_call_read(dev, id_buffer, SM_CHIP_ID_LENGTH,
regs.regs[1] = 0; MESON_SMC_CMD_CHIP_ID_GET, &regs);
regs.regs[2] = 0; if (err < 0)
pr_err("Failed to read serial number (%d)\n", err);
smc_call(&regs); memcpy(buffer, id_buffer + SM_CHIP_ID_OFFSET, size);
memcpy(buffer, shmem_output + SM_CHIP_ID_OFFSET,
min_t(size_t, size, SM_CHIP_ID_SIZE));
return 0; return 0;
} }
@ -141,13 +137,21 @@ int meson_sm_get_reboot_reason(void)
int meson_sm_pwrdm_set(size_t index, int cmd) int meson_sm_pwrdm_set(size_t index, int cmd)
{ {
struct pt_regs regs; struct udevice *dev;
struct pt_regs regs = { 0 };
int err;
dev = meson_get_sm_device();
if (IS_ERR(dev))
return PTR_ERR(dev);
regs.regs[0] = FN_PWRDM_SET;
regs.regs[1] = index; regs.regs[1] = index;
regs.regs[2] = cmd; regs.regs[2] = cmd;
smc_call(&regs); err = sm_call(dev, MESON_SMC_CMD_PWRDM_SET, NULL, &regs);
if (err)
pr_err("Failed to %s power domain ind=%zu (%d)\n", cmd == PWRDM_ON ?
"enable" : "disable", index, err);
return regs.regs[0]; return err;
} }