blob: e078bd2af09320ca0b179027038f918ca2146f6e [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 Cherukuri33fcfee2018-08-17 11:23:46 +05307#include <arch_helpers.h>
Chandni Cherukuri771d6442018-05-10 12:03:50 +05308#include <debug.h>
9#include <desc_image_load.h>
10#include <libfdt.h>
11#include <platform.h>
Chandni Cherukuri3aa09f72018-11-28 11:31:51 +053012#include <sgi_variant.h>
Chandni Cherukuri771d6442018-05-10 12:03:50 +053013
14/*******************************************************************************
15 * This function inserts Platform information via device tree nodes as,
16 * system-id {
17 * platform-id = <0>;
Chandni Cherukuri33fcfee2018-08-17 11:23:46 +053018 * config-id = <0>;
Chandni Cherukuri771d6442018-05-10 12:03:50 +053019 * }
20 ******************************************************************************/
21static int plat_sgi_append_config_node(void)
22{
23 bl_mem_params_node_t *mem_params;
24 void *fdt;
25 int nodeoffset, err;
Chandni Cherukuri33fcfee2018-08-17 11:23:46 +053026 unsigned int platid = 0, platcfg = 0;
Chandni Cherukuri771d6442018-05-10 12:03:50 +053027
Chandni Cherukuri29ea98d2018-11-28 11:26:19 +053028 mem_params = get_bl_mem_params_node(NT_FW_CONFIG_ID);
Chandni Cherukuri771d6442018-05-10 12:03:50 +053029 if (mem_params == NULL) {
Chandni Cherukuri29ea98d2018-11-28 11:26:19 +053030 ERROR("NT_FW CONFIG base address is NULL");
Chandni Cherukuri771d6442018-05-10 12:03:50 +053031 return -1;
32 }
33
34 fdt = (void *)(mem_params->image_info.image_base);
35
36 /* Check the validity of the fdt */
37 if (fdt_check_header(fdt) != 0) {
Chandni Cherukuri29ea98d2018-11-28 11:26:19 +053038 ERROR("Invalid NT_FW_CONFIG DTB passed\n");
Chandni Cherukuri771d6442018-05-10 12:03:50 +053039 return -1;
40 }
41
Chandni Cherukuri33fcfee2018-08-17 11:23:46 +053042 nodeoffset = fdt_subnode_offset(fdt, 0, "system-id");
43 if (nodeoffset < 0) {
44 ERROR("Failed to get system-id node offset\n");
Chandni Cherukuri771d6442018-05-10 12:03:50 +053045 return -1;
46 }
47
Chandni Cherukuri3aa09f72018-11-28 11:31:51 +053048 platid = plat_arm_sgi_get_platform_id();
Chandni Cherukuri33fcfee2018-08-17 11:23:46 +053049 err = fdt_setprop_u32(fdt, nodeoffset, "platform-id", platid);
50 if (err < 0) {
51 ERROR("Failed to set platform-id\n");
Chandni Cherukuri771d6442018-05-10 12:03:50 +053052 return -1;
53 }
54
Chandni Cherukuri3aa09f72018-11-28 11:31:51 +053055 platcfg = plat_arm_sgi_get_config_id();
Chandni Cherukuri33fcfee2018-08-17 11:23:46 +053056 err = fdt_setprop_u32(fdt, nodeoffset, "config-id", platcfg);
Chandni Cherukuri771d6442018-05-10 12:03:50 +053057 if (err < 0) {
Chandni Cherukuri33fcfee2018-08-17 11:23:46 +053058 ERROR("Failed to set config-id\n");
Chandni Cherukuri771d6442018-05-10 12:03:50 +053059 return -1;
60 }
Chandni Cherukuri33fcfee2018-08-17 11:23:46 +053061
62 flush_dcache_range((uintptr_t)fdt, mem_params->image_info.image_size);
63
Chandni Cherukuri771d6442018-05-10 12:03:50 +053064 return 0;
65}
66
67/*******************************************************************************
68 * This function returns the list of executable images.
69 ******************************************************************************/
70bl_params_t *plat_get_next_bl_params(void)
71{
72 int ret;
73 bl_params_t *next_bl_params;
74
75 ret = plat_sgi_append_config_node();
76 if (ret != 0)
77 panic();
78
79 next_bl_params = get_next_bl_params_from_mem_params_desc();
80 populate_next_bl_params_config(next_bl_params);
81
82 return next_bl_params;
83}