1 /*
2  * Copyright (c) 2019, Intel Corporation. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #include <string.h>
8 
9 #include "socfpga_handoff.h"
10 
11 #define SWAP_UINT32(x) (((x) >> 24) | (((x) & 0x00FF0000) >> 8) |	\
12 				(((x) & 0x0000FF00) << 8) | ((x) << 24))
13 
socfpga_get_handoff(handoff * reverse_hoff_ptr)14 int socfpga_get_handoff(handoff *reverse_hoff_ptr)
15 {
16 	int i;
17 	uint32_t *buffer;
18 	handoff *handoff_ptr = (handoff *) PLAT_HANDOFF_OFFSET;
19 
20 	memcpy(reverse_hoff_ptr, handoff_ptr, sizeof(handoff));
21 	buffer = (uint32_t *)reverse_hoff_ptr;
22 
23 	/* convert big endian to little endian */
24 	for (i = 0; i < sizeof(handoff) / 4; i++)
25 		buffer[i] = SWAP_UINT32(buffer[i]);
26 
27 	if (reverse_hoff_ptr->header_magic != HANDOFF_MAGIC_HEADER)
28 		return -1;
29 	if (reverse_hoff_ptr->pinmux_sel_magic != HANDOFF_MAGIC_PINMUX_SEL)
30 		return -1;
31 	if (reverse_hoff_ptr->pinmux_io_magic != HANDOFF_MAGIC_IOCTLR)
32 		return -1;
33 	if (reverse_hoff_ptr->pinmux_fpga_magic != HANDOFF_MAGIC_FPGA)
34 		return -1;
35 	if (reverse_hoff_ptr->pinmux_delay_magic != HANDOFF_MAGIC_IODELAY)
36 		return -1;
37 
38 	return 0;
39 }
40