Siew Chin Lim | ff1eec3 | 2021-03-24 13:11:38 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Copyright (C) 2020 Intel Corporation <www.intel.com> |
| 4 | * |
| 5 | */ |
| 6 | |
| 7 | #include <asm/arch/handoff_soc64.h> |
| 8 | #include <asm/io.h> |
| 9 | #include <common.h> |
| 10 | #include <errno.h> |
| 11 | #include "log.h" |
| 12 | |
| 13 | int socfpga_get_handoff_size(void *handoff_address, enum endianness endian) |
| 14 | { |
| 15 | u32 size; |
| 16 | |
| 17 | size = readl(handoff_address + SOC64_HANDOFF_OFFSET_LENGTH); |
| 18 | if (endian == BIG_ENDIAN) |
| 19 | size = swab32(size); |
| 20 | |
| 21 | size = (size - SOC64_HANDOFF_OFFSET_DATA) / sizeof(u32); |
| 22 | |
| 23 | debug("%s: handoff address = 0x%p handoff size = 0x%08x\n", __func__, |
| 24 | (u32 *)handoff_address, size); |
| 25 | |
| 26 | return size; |
| 27 | } |
| 28 | |
| 29 | int socfpga_handoff_read(void *handoff_address, void *table, u32 table_len, |
| 30 | enum endianness big_endian) |
| 31 | { |
| 32 | u32 temp, i; |
| 33 | u32 *table_x32 = table; |
| 34 | |
| 35 | debug("%s: handoff addr = 0x%p ", __func__, (u32 *)handoff_address); |
| 36 | |
| 37 | if (big_endian) { |
| 38 | if (swab32(readl(SOC64_HANDOFF_BASE)) == SOC64_HANDOFF_MAGIC_BOOT) { |
| 39 | debug("Handoff table address = 0x%p ", table_x32); |
| 40 | debug("table length = 0x%x\n", table_len); |
| 41 | debug("%s: handoff data =\n{\n", __func__); |
| 42 | |
| 43 | for (i = 0; i < table_len; i++) { |
| 44 | temp = readl(handoff_address + |
| 45 | SOC64_HANDOFF_OFFSET_DATA + |
| 46 | (i * sizeof(u32))); |
| 47 | *table_x32 = swab32(temp); |
| 48 | |
| 49 | if (!(i % 2)) |
| 50 | debug(" No.%d Addr 0x%08x: ", i, |
| 51 | *table_x32); |
| 52 | else |
| 53 | debug(" 0x%08x\n", *table_x32); |
| 54 | |
| 55 | table_x32++; |
| 56 | } |
| 57 | debug("\n}\n"); |
| 58 | } else { |
| 59 | debug("%s: Cannot find SOC64_HANDOFF_MAGIC_BOOT ", __func__); |
| 60 | debug("at addr 0x%p\n", (u32 *)handoff_address); |
| 61 | return -EPERM; |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | return 0; |
| 66 | } |