blob: 1ed219d65350386a31e25084aca71edf3a04994c [file] [log] [blame]
Chandni Cherukuri771d6442018-05-10 12:03:50 +05301/*
2 * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Chandni Cherukuri771d6442018-05-10 12:03:50 +05307#include <libfdt.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00008
9#include <arch_helpers.h>
10#include <common/debug.h>
11#include <common/desc_image_load.h>
12#include <plat/common/platform.h>
13
Chandni Cherukuri3aa09f72018-11-28 11:31:51 +053014#include <sgi_variant.h>
Chandni Cherukuri771d6442018-05-10 12:03:50 +053015
16/*******************************************************************************
17 * This function inserts Platform information via device tree nodes as,
18 * system-id {
19 * platform-id = <0>;
Chandni Cherukuri33fcfee2018-08-17 11:23:46 +053020 * config-id = <0>;
Chandni Cherukuri771d6442018-05-10 12:03:50 +053021 * }
22 ******************************************************************************/
23static int plat_sgi_append_config_node(void)
24{
25 bl_mem_params_node_t *mem_params;
26 void *fdt;
27 int nodeoffset, err;
Chandni Cherukuri33fcfee2018-08-17 11:23:46 +053028 unsigned int platid = 0, platcfg = 0;
Chandni Cherukuri771d6442018-05-10 12:03:50 +053029
Chandni Cherukuri29ea98d2018-11-28 11:26:19 +053030 mem_params = get_bl_mem_params_node(NT_FW_CONFIG_ID);
Chandni Cherukuri771d6442018-05-10 12:03:50 +053031 if (mem_params == NULL) {
Chandni Cherukuri29ea98d2018-11-28 11:26:19 +053032 ERROR("NT_FW CONFIG base address is NULL");
Chandni Cherukuri771d6442018-05-10 12:03:50 +053033 return -1;
34 }
35
36 fdt = (void *)(mem_params->image_info.image_base);
37
38 /* Check the validity of the fdt */
39 if (fdt_check_header(fdt) != 0) {
Chandni Cherukuri29ea98d2018-11-28 11:26:19 +053040 ERROR("Invalid NT_FW_CONFIG DTB passed\n");
Chandni Cherukuri771d6442018-05-10 12:03:50 +053041 return -1;
42 }
43
Chandni Cherukuri33fcfee2018-08-17 11:23:46 +053044 nodeoffset = fdt_subnode_offset(fdt, 0, "system-id");
45 if (nodeoffset < 0) {
46 ERROR("Failed to get system-id node offset\n");
Chandni Cherukuri771d6442018-05-10 12:03:50 +053047 return -1;
48 }
49
Chandni Cherukuri3aa09f72018-11-28 11:31:51 +053050 platid = plat_arm_sgi_get_platform_id();
Chandni Cherukuri33fcfee2018-08-17 11:23:46 +053051 err = fdt_setprop_u32(fdt, nodeoffset, "platform-id", platid);
52 if (err < 0) {
53 ERROR("Failed to set platform-id\n");
Chandni Cherukuri771d6442018-05-10 12:03:50 +053054 return -1;
55 }
56
Chandni Cherukuri3aa09f72018-11-28 11:31:51 +053057 platcfg = plat_arm_sgi_get_config_id();
Chandni Cherukuri33fcfee2018-08-17 11:23:46 +053058 err = fdt_setprop_u32(fdt, nodeoffset, "config-id", platcfg);
Chandni Cherukuri771d6442018-05-10 12:03:50 +053059 if (err < 0) {
Chandni Cherukuri33fcfee2018-08-17 11:23:46 +053060 ERROR("Failed to set config-id\n");
Chandni Cherukuri771d6442018-05-10 12:03:50 +053061 return -1;
62 }
Chandni Cherukuri33fcfee2018-08-17 11:23:46 +053063
64 flush_dcache_range((uintptr_t)fdt, mem_params->image_info.image_size);
65
Chandni Cherukuri771d6442018-05-10 12:03:50 +053066 return 0;
67}
68
69/*******************************************************************************
70 * This function returns the list of executable images.
71 ******************************************************************************/
72bl_params_t *plat_get_next_bl_params(void)
73{
74 int ret;
75 bl_params_t *next_bl_params;
76
77 ret = plat_sgi_append_config_node();
78 if (ret != 0)
79 panic();
80
81 next_bl_params = get_next_bl_params_from_mem_params_desc();
82 populate_next_bl_params_config(next_bl_params);
83
84 return next_bl_params;
85}