blob: a2f10dcc7f716394238e29aa86ac925dd4fcef30 [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>
Antonio Nino Diazbd7b7402019-01-25 14:30:04 +000012#include <plat/arm/common/plat_arm.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000013#include <plat/common/platform.h>
14
Chandni Cherukuri3aa09f72018-11-28 11:31:51 +053015#include <sgi_variant.h>
Chandni Cherukuri771d6442018-05-10 12:03:50 +053016
17/*******************************************************************************
18 * This function inserts Platform information via device tree nodes as,
19 * system-id {
20 * platform-id = <0>;
Chandni Cherukuri33fcfee2018-08-17 11:23:46 +053021 * config-id = <0>;
Chandni Cherukuri771d6442018-05-10 12:03:50 +053022 * }
23 ******************************************************************************/
24static int plat_sgi_append_config_node(void)
25{
26 bl_mem_params_node_t *mem_params;
27 void *fdt;
28 int nodeoffset, err;
Chandni Cherukuri33fcfee2018-08-17 11:23:46 +053029 unsigned int platid = 0, platcfg = 0;
Chandni Cherukuri771d6442018-05-10 12:03:50 +053030
Chandni Cherukuri29ea98d2018-11-28 11:26:19 +053031 mem_params = get_bl_mem_params_node(NT_FW_CONFIG_ID);
Chandni Cherukuri771d6442018-05-10 12:03:50 +053032 if (mem_params == NULL) {
Chandni Cherukuri29ea98d2018-11-28 11:26:19 +053033 ERROR("NT_FW CONFIG base address is NULL");
Chandni Cherukuri771d6442018-05-10 12:03:50 +053034 return -1;
35 }
36
37 fdt = (void *)(mem_params->image_info.image_base);
38
39 /* Check the validity of the fdt */
40 if (fdt_check_header(fdt) != 0) {
Chandni Cherukuri29ea98d2018-11-28 11:26:19 +053041 ERROR("Invalid NT_FW_CONFIG DTB passed\n");
Chandni Cherukuri771d6442018-05-10 12:03:50 +053042 return -1;
43 }
44
Chandni Cherukuri33fcfee2018-08-17 11:23:46 +053045 nodeoffset = fdt_subnode_offset(fdt, 0, "system-id");
46 if (nodeoffset < 0) {
47 ERROR("Failed to get system-id node offset\n");
Chandni Cherukuri771d6442018-05-10 12:03:50 +053048 return -1;
49 }
50
Chandni Cherukuri3aa09f72018-11-28 11:31:51 +053051 platid = plat_arm_sgi_get_platform_id();
Chandni Cherukuri33fcfee2018-08-17 11:23:46 +053052 err = fdt_setprop_u32(fdt, nodeoffset, "platform-id", platid);
53 if (err < 0) {
54 ERROR("Failed to set platform-id\n");
Chandni Cherukuri771d6442018-05-10 12:03:50 +053055 return -1;
56 }
57
Chandni Cherukuri3aa09f72018-11-28 11:31:51 +053058 platcfg = plat_arm_sgi_get_config_id();
Chandni Cherukuri33fcfee2018-08-17 11:23:46 +053059 err = fdt_setprop_u32(fdt, nodeoffset, "config-id", platcfg);
Chandni Cherukuri771d6442018-05-10 12:03:50 +053060 if (err < 0) {
Chandni Cherukuri33fcfee2018-08-17 11:23:46 +053061 ERROR("Failed to set config-id\n");
Chandni Cherukuri771d6442018-05-10 12:03:50 +053062 return -1;
63 }
Chandni Cherukuri33fcfee2018-08-17 11:23:46 +053064
65 flush_dcache_range((uintptr_t)fdt, mem_params->image_info.image_size);
66
Chandni Cherukuri771d6442018-05-10 12:03:50 +053067 return 0;
68}
69
70/*******************************************************************************
71 * This function returns the list of executable images.
72 ******************************************************************************/
73bl_params_t *plat_get_next_bl_params(void)
74{
75 int ret;
Chandni Cherukuri771d6442018-05-10 12:03:50 +053076
77 ret = plat_sgi_append_config_node();
78 if (ret != 0)
79 panic();
80
Sathees Balya90950092018-11-15 14:22:30 +000081 return arm_get_next_bl_params();
Chandni Cherukuri771d6442018-05-10 12:03:50 +053082}
Sathees Balya90950092018-11-15 14:22:30 +000083