blob: ac4bfd29271a396b5e084a5a059843557468fc8d [file] [log] [blame]
Chandni Cherukuri771d6442018-05-10 12:03:50 +05301/*
Nishant Sharma289f7822021-11-30 09:31:48 +00002 * Copyright (c) 2018-2022, ARM Limited and Contributors. All rights reserved.
Chandni Cherukuri771d6442018-05-10 12:03:50 +05303 *
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>
Nishant Sharma289f7822021-11-30 09:31:48 +000012#include <drivers/arm/css/sds.h>
Antonio Nino Diazbd7b7402019-01-25 14:30:04 +000013#include <plat/arm/common/plat_arm.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000014#include <plat/common/platform.h>
15
Nishant Sharma289f7822021-11-30 09:31:48 +000016#include <platform_def.h>
17#include <sgi_base_platform_def.h>
Chandni Cherukuri3aa09f72018-11-28 11:31:51 +053018#include <sgi_variant.h>
Chandni Cherukuri771d6442018-05-10 12:03:50 +053019
Nishant Sharma289f7822021-11-30 09:31:48 +000020/*
21 * Information about the isolated CPUs obtained from SDS.
22 */
23struct isolated_cpu_mpid_list {
24 uint64_t num_entries; /* Number of entries in the list */
25 uint64_t mpid_list[PLATFORM_CORE_COUNT]; /* List of isolated CPU MPIDs */
26};
27
28/* Function to read isolated CPU MPID list from SDS. */
29void plat_arm_sgi_get_isolated_cpu_list(struct isolated_cpu_mpid_list *list)
30{
31 int ret;
32
33 ret = sds_init();
34 if (ret != SDS_OK) {
35 ERROR("SDS initialization failed, error: %d\n", ret);
36 panic();
37 }
38
39 ret = sds_struct_read(SDS_ISOLATED_CPU_LIST_ID, 0, &list->num_entries,
40 sizeof(list->num_entries), SDS_ACCESS_MODE_CACHED);
41 if (ret != SDS_OK) {
42 INFO("SDS CPU num elements read failed, error: %d\n", ret);
43 list->num_entries = 0;
44 return;
45 }
46
47 if (list->num_entries > PLATFORM_CORE_COUNT) {
48 ERROR("Isolated CPU list count %ld greater than max"
49 " number supported %d\n",
50 list->num_entries, PLATFORM_CORE_COUNT);
51 panic();
52 } else if (list->num_entries == 0) {
53 INFO("SDS isolated CPU list is empty\n");
54 return;
55 }
56
57 ret = sds_struct_read(SDS_ISOLATED_CPU_LIST_ID,
58 sizeof(list->num_entries),
59 &list->mpid_list,
60 sizeof(list->mpid_list[0]) * list->num_entries,
61 SDS_ACCESS_MODE_CACHED);
62 if (ret != SDS_OK) {
63 ERROR("SDS CPU list read failed. error: %d\n", ret);
64 panic();
65 }
66}
67
Chandni Cherukuri771d6442018-05-10 12:03:50 +053068/*******************************************************************************
69 * This function inserts Platform information via device tree nodes as,
70 * system-id {
71 * platform-id = <0>;
Chandni Cherukuri33fcfee2018-08-17 11:23:46 +053072 * config-id = <0>;
Nishant Sharma289f7822021-11-30 09:31:48 +000073 * isolated-cpu-list = <0>
Chandni Cherukuri771d6442018-05-10 12:03:50 +053074 * }
75 ******************************************************************************/
76static int plat_sgi_append_config_node(void)
77{
78 bl_mem_params_node_t *mem_params;
79 void *fdt;
80 int nodeoffset, err;
Chandni Cherukuri33fcfee2018-08-17 11:23:46 +053081 unsigned int platid = 0, platcfg = 0;
Nishant Sharma289f7822021-11-30 09:31:48 +000082 struct isolated_cpu_mpid_list cpu_mpid_list = {0};
Chandni Cherukuri771d6442018-05-10 12:03:50 +053083
Chandni Cherukuri29ea98d2018-11-28 11:26:19 +053084 mem_params = get_bl_mem_params_node(NT_FW_CONFIG_ID);
Chandni Cherukuri771d6442018-05-10 12:03:50 +053085 if (mem_params == NULL) {
Chandni Cherukuri29ea98d2018-11-28 11:26:19 +053086 ERROR("NT_FW CONFIG base address is NULL");
Chandni Cherukuri771d6442018-05-10 12:03:50 +053087 return -1;
88 }
89
90 fdt = (void *)(mem_params->image_info.image_base);
91
92 /* Check the validity of the fdt */
93 if (fdt_check_header(fdt) != 0) {
Chandni Cherukuri29ea98d2018-11-28 11:26:19 +053094 ERROR("Invalid NT_FW_CONFIG DTB passed\n");
Chandni Cherukuri771d6442018-05-10 12:03:50 +053095 return -1;
96 }
97
Chandni Cherukuri33fcfee2018-08-17 11:23:46 +053098 nodeoffset = fdt_subnode_offset(fdt, 0, "system-id");
99 if (nodeoffset < 0) {
100 ERROR("Failed to get system-id node offset\n");
Chandni Cherukuri771d6442018-05-10 12:03:50 +0530101 return -1;
102 }
103
Chandni Cherukuri3aa09f72018-11-28 11:31:51 +0530104 platid = plat_arm_sgi_get_platform_id();
Chandni Cherukuri33fcfee2018-08-17 11:23:46 +0530105 err = fdt_setprop_u32(fdt, nodeoffset, "platform-id", platid);
106 if (err < 0) {
107 ERROR("Failed to set platform-id\n");
Chandni Cherukuri771d6442018-05-10 12:03:50 +0530108 return -1;
109 }
110
Chandni Cherukuri3aa09f72018-11-28 11:31:51 +0530111 platcfg = plat_arm_sgi_get_config_id();
Chandni Cherukuri33fcfee2018-08-17 11:23:46 +0530112 err = fdt_setprop_u32(fdt, nodeoffset, "config-id", platcfg);
Chandni Cherukuri771d6442018-05-10 12:03:50 +0530113 if (err < 0) {
Chandni Cherukuri33fcfee2018-08-17 11:23:46 +0530114 ERROR("Failed to set config-id\n");
Chandni Cherukuri771d6442018-05-10 12:03:50 +0530115 return -1;
116 }
Chandni Cherukuri33fcfee2018-08-17 11:23:46 +0530117
Vijayenthiran Subramaniam03f58bf2019-10-30 12:52:25 +0530118 platcfg = plat_arm_sgi_get_multi_chip_mode();
119 err = fdt_setprop_u32(fdt, nodeoffset, "multi-chip-mode", platcfg);
120 if (err < 0) {
121 ERROR("Failed to set multi-chip-mode\n");
122 return -1;
123 }
124
Nishant Sharma289f7822021-11-30 09:31:48 +0000125 plat_arm_sgi_get_isolated_cpu_list(&cpu_mpid_list);
126 if (cpu_mpid_list.num_entries > 0) {
127 err = fdt_setprop(fdt, nodeoffset, "isolated-cpu-list",
128 &cpu_mpid_list,
129 (sizeof(cpu_mpid_list.num_entries) *
130 (cpu_mpid_list.num_entries + 1)));
131 if (err < 0) {
132 ERROR("Failed to set isolated-cpu-list, error: %d\n",
133 err);
134 }
135 }
136
Chandni Cherukuri33fcfee2018-08-17 11:23:46 +0530137 flush_dcache_range((uintptr_t)fdt, mem_params->image_info.image_size);
138
Chandni Cherukuri771d6442018-05-10 12:03:50 +0530139 return 0;
140}
141
142/*******************************************************************************
143 * This function returns the list of executable images.
144 ******************************************************************************/
145bl_params_t *plat_get_next_bl_params(void)
146{
147 int ret;
Chandni Cherukuri771d6442018-05-10 12:03:50 +0530148
149 ret = plat_sgi_append_config_node();
150 if (ret != 0)
151 panic();
152
Sathees Balya90950092018-11-15 14:22:30 +0000153 return arm_get_next_bl_params();
Chandni Cherukuri771d6442018-05-10 12:03:50 +0530154}
Sathees Balya90950092018-11-15 14:22:30 +0000155