blob: 0bba5e4a0733145bb2ae17451e03eb2323e6c581 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Beniamino Galvani38e1a602016-05-08 08:30:17 +02002/*
3 * (C) Copyright 2016 Beniamino Galvani <b.galvani@gmail.com>
4 *
Beniamino Galvani38e1a602016-05-08 08:30:17 +02005 * Secure monitor calls.
6 */
7
8#include <common.h>
Neil Armstrong6e89d922018-04-11 17:13:45 +02009#include <asm/arch/gx.h>
Beniamino Galvani38e1a602016-05-08 08:30:17 +020010#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
17static void *shmem_input;
18static void *shmem_output;
19
20static 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
38ssize_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}