xref: /openbmc/u-boot/arch/arm/mach-meson/sm.c (revision 53deb24d)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2016 Beniamino Galvani <b.galvani@gmail.com>
4  *
5  * Secure monitor calls.
6  */
7 
8 #include <common.h>
9 #include <asm/arch/gx.h>
10 #include <linux/kernel.h>
11 
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 
17 static void *shmem_input;
18 static void *shmem_output;
19 
20 static void meson_init_shmem(void)
21 {
22 	struct pt_regs regs;
23 
24 	if (shmem_input && shmem_output)
25 		return;
26 
27 	regs.regs[0] = FN_GET_SHARE_MEM_INPUT_BASE;
28 	smc_call(&regs);
29 	shmem_input = (void *)regs.regs[0];
30 
31 	regs.regs[0] = FN_GET_SHARE_MEM_OUTPUT_BASE;
32 	smc_call(&regs);
33 	shmem_output = (void *)regs.regs[0];
34 
35 	debug("Secure Monitor shmem: 0x%p 0x%p\n", shmem_input, shmem_output);
36 }
37 
38 ssize_t meson_sm_read_efuse(uintptr_t offset, void *buffer, size_t size)
39 {
40 	struct pt_regs regs;
41 
42 	meson_init_shmem();
43 
44 	regs.regs[0] = FN_EFUSE_READ;
45 	regs.regs[1] = offset;
46 	regs.regs[2] = size;
47 
48 	smc_call(&regs);
49 
50 	if (regs.regs[0] == 0)
51 		return -1;
52 
53 	memcpy(buffer, shmem_output, min(size, regs.regs[0]));
54 
55 	return regs.regs[0];
56 }
57