Marek Behún | 35572c9 | 2018-12-17 16:10:08 +0100 | [diff] [blame] | 1 | // 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ún | 1055ce1 | 2020-04-08 12:02:07 +0200 | [diff] [blame] | 7 | #include <asm/arch/soc.h> |
Marek Behún | 35572c9 | 2018-12-17 16:10:08 +0100 | [diff] [blame] | 8 | #include <asm/io.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 9 | #include <linux/bitops.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 10 | #include <linux/delay.h> |
Pali Rohár | deb1e92 | 2022-02-23 14:15:47 +0100 | [diff] [blame] | 11 | #include <mach/mbox.h> |
Marek Behún | 35572c9 | 2018-12-17 16:10:08 +0100 | [diff] [blame] | 12 | |
| 13 | const 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ár | 0e6dce7 | 2022-02-23 14:15:48 +0100 | [diff] [blame^] | 22 | res = mbox_do_cmd(MBOX_CMD_ECDSA_PUB_KEY, NULL, 0, out, 16); |
Marek Behún | 35572c9 | 2018-12-17 16:10:08 +0100 | [diff] [blame] | 23 | 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 | |
| 35 | static 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 | |
| 45 | int 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ár | 0e6dce7 | 2022-02-23 14:15:48 +0100 | [diff] [blame^] | 50 | res = mbox_do_cmd(MBOX_CMD_BOARD_INFO, NULL, 0, out, 8); |
Marek Behún | 35572c9 | 2018-12-17 16:10:08 +0100 | [diff] [blame] | 51 | 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 | } |