blob: d97583ef9fa7e3a01aeb39090f0631985e0395db [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 Cherukuric8ef0452018-10-04 16:32:03 +053053 } else if (strcmp(platform_name, "arm,sgi-clark") == 0) {
54 platid = mmio_read_32(SID_REG_BASE + SID_SYSTEM_ID_OFFSET)
55 & SID_SYSTEM_ID_PART_NUM_MASK;
56 platcfg = mmio_read_32(SID_REG_BASE + SID_SYSTEM_CFG_OFFSET);
Chandni Cherukuri771d6442018-05-10 12:03:50 +053057 } else {
John Tsichritzis049db962018-08-16 14:37:40 +010058 WARN("Invalid platform\n");
Chandni Cherukuri771d6442018-05-10 12:03:50 +053059 return -1;
60 }
61
Chandni Cherukuri33fcfee2018-08-17 11:23:46 +053062 nodeoffset = fdt_subnode_offset(fdt, 0, "system-id");
63 if (nodeoffset < 0) {
64 ERROR("Failed to get system-id node offset\n");
Chandni Cherukuri771d6442018-05-10 12:03:50 +053065 return -1;
66 }
67
Chandni Cherukuri33fcfee2018-08-17 11:23:46 +053068 err = fdt_setprop_u32(fdt, nodeoffset, "platform-id", platid);
69 if (err < 0) {
70 ERROR("Failed to set platform-id\n");
Chandni Cherukuri771d6442018-05-10 12:03:50 +053071 return -1;
72 }
73
Chandni Cherukuri33fcfee2018-08-17 11:23:46 +053074 err = fdt_setprop_u32(fdt, nodeoffset, "config-id", platcfg);
Chandni Cherukuri771d6442018-05-10 12:03:50 +053075 if (err < 0) {
Chandni Cherukuri33fcfee2018-08-17 11:23:46 +053076 ERROR("Failed to set config-id\n");
Chandni Cherukuri771d6442018-05-10 12:03:50 +053077 return -1;
78 }
Chandni Cherukuri33fcfee2018-08-17 11:23:46 +053079
80 flush_dcache_range((uintptr_t)fdt, mem_params->image_info.image_size);
81
Chandni Cherukuri771d6442018-05-10 12:03:50 +053082 return 0;
83}
84
85/*******************************************************************************
86 * This function returns the list of executable images.
87 ******************************************************************************/
88bl_params_t *plat_get_next_bl_params(void)
89{
90 int ret;
91 bl_params_t *next_bl_params;
92
93 ret = plat_sgi_append_config_node();
94 if (ret != 0)
95 panic();
96
97 next_bl_params = get_next_bl_params_from_mem_params_desc();
98 populate_next_bl_params_config(next_bl_params);
99
100 return next_bl_params;
101}