1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2016 Beniamino Galvani <b.galvani@gmail.com>
5 * Secure monitor calls.
9 #include <asm/arch/sm.h>
10 #include <linux/kernel.h>
12 #define FN_GET_SHARE_MEM_INPUT_BASE 0x82000020
13 #define FN_GET_SHARE_MEM_OUTPUT_BASE 0x82000021
14 #define FN_EFUSE_READ 0x82000030
15 #define FN_EFUSE_WRITE 0x82000031
16 #define FN_CHIP_ID 0x82000044
18 static void *shmem_input;
19 static void *shmem_output;
21 static void meson_init_shmem(void)
25 if (shmem_input && shmem_output)
28 regs.regs[0] = FN_GET_SHARE_MEM_INPUT_BASE;
30 shmem_input = (void *)regs.regs[0];
32 regs.regs[0] = FN_GET_SHARE_MEM_OUTPUT_BASE;
34 shmem_output = (void *)regs.regs[0];
36 debug("Secure Monitor shmem: 0x%p 0x%p\n", shmem_input, shmem_output);
39 ssize_t meson_sm_read_efuse(uintptr_t offset, void *buffer, size_t size)
45 regs.regs[0] = FN_EFUSE_READ;
46 regs.regs[1] = offset;
51 if (regs.regs[0] == 0)
54 memcpy(buffer, shmem_output, min(size, regs.regs[0]));
59 #define SM_CHIP_ID_LENGTH 119
60 #define SM_CHIP_ID_OFFSET 4
61 #define SM_CHIP_ID_SIZE 12
63 int meson_sm_get_serial(void *buffer, size_t size)
69 regs.regs[0] = FN_CHIP_ID;
75 memcpy(buffer, shmem_output + SM_CHIP_ID_OFFSET,
76 min_t(size_t, size, SM_CHIP_ID_SIZE));