blob: 93e96b014fca51403746528aa192fd1412f0173f [file] [log] [blame]
Marek Behún35572c92018-12-17 16:10:08 +01001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2018 Marek Behun <marek.behun@nic.cz>
4 */
5
6#include <common.h>
Marek Behún1055ce12020-04-08 12:02:07 +02007#include <asm/arch/soc.h>
Marek Behún35572c92018-12-17 16:10:08 +01008#include <asm/io.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -06009#include <linux/bitops.h>
Simon Glassdbd79542020-05-10 11:40:11 -060010#include <linux/delay.h>
Pali Rohárdeb1e922022-02-23 14:15:47 +010011#include <mach/mbox.h>
Marek Behún35572c92018-12-17 16:10:08 +010012
13const char *mox_sp_get_ecdsa_public_key(void)
14{
15 static char public_key[135];
16 u32 out[16];
17 int res;
18
19 if (public_key[0])
20 return public_key;
21
Pali Rohár0e6dce72022-02-23 14:15:48 +010022 res = mbox_do_cmd(MBOX_CMD_ECDSA_PUB_KEY, NULL, 0, out, 16);
Marek Behún35572c92018-12-17 16:10:08 +010023 if (res < 0)
24 return NULL;
25
26 sprintf(public_key,
27 "%06x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x",
28 (u32)res, out[0], out[1], out[2], out[3], out[4], out[5],
29 out[6], out[7], out[8], out[9], out[10], out[11], out[12],
30 out[13], out[14], out[15]);
31
32 return public_key;
33}
34
35static inline void res_to_mac(u8 *mac, u32 t1, u32 t2)
36{
37 mac[0] = t1 >> 8;
38 mac[1] = t1;
39 mac[2] = t2 >> 24;
40 mac[3] = t2 >> 16;
41 mac[4] = t2 >> 8;
42 mac[5] = t2;
43}
44
45int mbox_sp_get_board_info(u64 *sn, u8 *mac1, u8 *mac2, int *bv, int *ram)
46{
47 u32 out[8];
48 int res;
49
Pali Rohár0e6dce72022-02-23 14:15:48 +010050 res = mbox_do_cmd(MBOX_CMD_BOARD_INFO, NULL, 0, out, 8);
Marek Behún35572c92018-12-17 16:10:08 +010051 if (res < 0)
52 return res;
53
54 if (sn) {
55 *sn = out[1];
56 *sn <<= 32;
57 *sn |= out[0];
58 }
59
60 if (bv)
61 *bv = out[2];
62
63 if (ram)
64 *ram = out[3];
65
66 if (mac1)
67 res_to_mac(mac1, out[4], out[5]);
68
69 if (mac2)
70 res_to_mac(mac2, out[6], out[7]);
71
72 return 0;
73}