blob: 52dcf889e07607a79baf1227567c69cbf9ad2cc2 [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>
12
13/*******************************************************************************
14 * This function inserts Platform information via device tree nodes as,
15 * system-id {
16 * platform-id = <0>;
Chandni Cherukuri33fcfee2018-08-17 11:23:46 +053017 * config-id = <0>;
Chandni Cherukuri771d6442018-05-10 12:03:50 +053018 * }
19 ******************************************************************************/
20static int plat_sgi_append_config_node(void)
21{
22 bl_mem_params_node_t *mem_params;
23 void *fdt;
24 int nodeoffset, err;
Chandni Cherukuri33fcfee2018-08-17 11:23:46 +053025 unsigned int platid = 0, platcfg = 0;
Chandni Cherukuri771d6442018-05-10 12:03:50 +053026 char *platform_name;
27
28 mem_params = get_bl_mem_params_node(HW_CONFIG_ID);
29 if (mem_params == NULL) {
30 ERROR("HW CONFIG base address is NULL");
31 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) {
38 ERROR("Invalid HW_CONFIG DTB passed\n");
39 return -1;
40 }
41
42 platform_name = (char *)fdt_getprop(fdt, 0, "compatible", NULL);
43
John Tsichritzis049db962018-08-16 14:37:40 +010044 if (platform_name == NULL) {
45 ERROR("Invalid HW_CONFIG DTB passed\n");
46 return -1;
47 }
48
Chandni Cherukuri771d6442018-05-10 12:03:50 +053049 if (strcmp(platform_name, "arm,sgi575") == 0) {
Chandni Cherukuri33fcfee2018-08-17 11:23:46 +053050 platid = mmio_read_32(SSC_VERSION) & SSC_VERSION_PART_NUM_MASK;
51 platcfg = (mmio_read_32(SSC_VERSION) >> SSC_VERSION_CONFIG_SHIFT)
52 & SSC_VERSION_CONFIG_MASK;
Chandni Cherukuri771d6442018-05-10 12:03:50 +053053 } else {
John Tsichritzis049db962018-08-16 14:37:40 +010054 WARN("Invalid platform\n");
Chandni Cherukuri771d6442018-05-10 12:03:50 +053055 return -1;
56 }
57
Chandni Cherukuri33fcfee2018-08-17 11:23:46 +053058 nodeoffset = fdt_subnode_offset(fdt, 0, "system-id");
59 if (nodeoffset < 0) {
60 ERROR("Failed to get system-id node offset\n");
Chandni Cherukuri771d6442018-05-10 12:03:50 +053061 return -1;
62 }
63
Chandni Cherukuri33fcfee2018-08-17 11:23:46 +053064 err = fdt_setprop_u32(fdt, nodeoffset, "platform-id", platid);
65 if (err < 0) {
66 ERROR("Failed to set platform-id\n");
Chandni Cherukuri771d6442018-05-10 12:03:50 +053067 return -1;
68 }
69
Chandni Cherukuri33fcfee2018-08-17 11:23:46 +053070 err = fdt_setprop_u32(fdt, nodeoffset, "config-id", platcfg);
Chandni Cherukuri771d6442018-05-10 12:03:50 +053071 if (err < 0) {
Chandni Cherukuri33fcfee2018-08-17 11:23:46 +053072 ERROR("Failed to set config-id\n");
Chandni Cherukuri771d6442018-05-10 12:03:50 +053073 return -1;
74 }
Chandni Cherukuri33fcfee2018-08-17 11:23:46 +053075
76 flush_dcache_range((uintptr_t)fdt, mem_params->image_info.image_size);
77
Chandni Cherukuri771d6442018-05-10 12:03:50 +053078 return 0;
79}
80
81/*******************************************************************************
82 * This function returns the list of executable images.
83 ******************************************************************************/
84bl_params_t *plat_get_next_bl_params(void)
85{
86 int ret;
87 bl_params_t *next_bl_params;
88
89 ret = plat_sgi_append_config_node();
90 if (ret != 0)
91 panic();
92
93 next_bl_params = get_next_bl_params_from_mem_params_desc();
94 populate_next_bl_params_config(next_bl_params);
95
96 return next_bl_params;
97}