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