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