1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2020-2021 Intel Corporation <www.intel.com>
7 #include <asm/arch/handoff_soc64.h>
13 static enum endianness check_endianness(u32 handoff)
16 case SOC64_HANDOFF_MAGIC_BOOT:
17 case SOC64_HANDOFF_MAGIC_MUX:
18 case SOC64_HANDOFF_MAGIC_IOCTL:
19 case SOC64_HANDOFF_MAGIC_FPGA:
20 case SOC64_HANDOFF_MAGIC_DELAY:
21 case SOC64_HANDOFF_MAGIC_CLOCK:
22 case SOC64_HANDOFF_MAGIC_MISC:
24 #if IS_ENABLED(CONFIG_TARGET_SOCFPGA_N5X)
25 case SOC64_HANDOFF_DDR_UMCTL2_MAGIC:
26 debug("%s: umctl2 handoff data\n", __func__);
28 case SOC64_HANDOFF_DDR_PHY_MAGIC:
29 debug("%s: PHY handoff data\n", __func__);
31 case SOC64_HANDOFF_DDR_PHY_INIT_ENGINE_MAGIC:
32 debug("%s: PHY engine handoff data\n", __func__);
36 debug("%s: Unknown endianness!!\n", __func__);
37 return UNKNOWN_ENDIANNESS;
41 static int getting_endianness(void *handoff_address, enum endianness *endian_t)
43 /* Checking handoff data is little endian ? */
44 *endian_t = check_endianness(readl(handoff_address));
46 if (*endian_t == UNKNOWN_ENDIANNESS) {
47 /* Trying to check handoff data is big endian? */
48 *endian_t = check_endianness(swab32(readl(handoff_address)));
49 if (*endian_t == UNKNOWN_ENDIANNESS) {
50 debug("%s: Cannot find HANDOFF MAGIC ", __func__);
51 debug("at addr 0x%p\n", (u32 *)handoff_address);
59 int socfpga_get_handoff_size(void *handoff_address)
63 enum endianness endian_t;
65 ret = getting_endianness(handoff_address, &endian_t);
69 size = readl(handoff_address + SOC64_HANDOFF_OFFSET_LENGTH);
70 if (endian_t == BIG_ENDIAN)
73 size = (size - SOC64_HANDOFF_OFFSET_DATA) / sizeof(u32);
75 debug("%s: handoff address = 0x%p handoff size = 0x%08x\n", __func__,
76 (u32 *)handoff_address, size);
81 int socfpga_handoff_read(void *handoff_address, void *table, u32 table_len)
84 u32 *table_x32 = table;
87 enum endianness endian_t;
89 ret = getting_endianness(handoff_address, &endian_t);
93 temp = readl(handoff_address + SOC64_HANDOFF_OFFSET_DATA +
96 if (endian_t == BIG_ENDIAN) {
97 debug("%s: Handoff addr = 0x%p ", __func__, (u32 *)handoff_address);
98 debug("Handoff table address = 0x%p ", table_x32);
99 debug("table length = 0x%x\n", table_len);
100 debug("%s: handoff data =\n{\n", __func__);
101 *table_x32 = swab32(temp);
102 } else if (endian_t == LITTLE_ENDIAN) {
107 debug(" No.%d Addr 0x%08x: ", i, *table_x32);
109 for (i = 1; i < table_len; i++) {
112 temp = readl(handoff_address +
113 SOC64_HANDOFF_OFFSET_DATA +
116 if (endian_t == BIG_ENDIAN)
117 *table_x32 = swab32(temp);
118 else if (endian_t == LITTLE_ENDIAN)
122 debug(" No.%d Addr 0x%08x: ", i,
125 debug(" 0x%08x\n", *table_x32);