Mark Dykes | e7810b5 | 2020-06-03 15:46:55 -0500 | [diff] [blame] | 1 | /* |
mardyk01 | 7b51dbe | 2024-01-17 15:25:36 -0600 | [diff] [blame^] | 2 | * Copyright (c) 2024, Arm Limited. All rights reserved. |
Mark Dykes | e7810b5 | 2020-06-03 15:46:55 -0500 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <debug.h> |
| 8 | #include <drivers/arm/private_timer.h> |
| 9 | #include <events.h> |
| 10 | #include "fifo3d.h" |
| 11 | #include <libfdt.h> |
| 12 | |
| 13 | #include <power_management.h> |
| 14 | #include <sdei.h> |
| 15 | #include <tftf_lib.h> |
| 16 | #include <timer.h> |
| 17 | |
| 18 | #include <plat_topology.h> |
| 19 | #include <platform.h> |
| 20 | |
| 21 | #ifdef SMC_FUZZ_TMALLOC |
| 22 | #define GENMALLOC(x) malloc((x)) |
| 23 | #define GENFREE(x) free((x)) |
| 24 | #else |
| 25 | #define GENMALLOC(x) smcmalloc((x), mmod) |
| 26 | #define GENFREE(x) smcfree((x), mmod) |
| 27 | #endif |
| 28 | |
| 29 | /* |
mardyk01 | 7b51dbe | 2024-01-17 15:25:36 -0600 | [diff] [blame^] | 30 | * Push function name string into the data structure from device tree file |
Mark Dykes | e7810b5 | 2020-06-03 15:46:55 -0500 | [diff] [blame] | 31 | */ |
| 32 | void push_3dfifo_fname(struct fifo3d *f3d, char *fname) |
| 33 | { |
| 34 | strlcpy(f3d->fnamefifo[f3d->col - 1][f3d->row[f3d->col - 1] - 1], |
| 35 | fname, MAX_NAME_CHARS); |
| 36 | } |
| 37 | |
| 38 | /* |
mardyk01 | 7b51dbe | 2024-01-17 15:25:36 -0600 | [diff] [blame^] | 39 | * Push bias value into data structure from device tree file |
Mark Dykes | e7810b5 | 2020-06-03 15:46:55 -0500 | [diff] [blame] | 40 | */ |
| 41 | void push_3dfifo_bias(struct fifo3d *f3d, int bias) |
| 42 | { |
| 43 | f3d->biasfifo[f3d->col - 1][f3d->row[f3d->col - 1] - 1] = bias; |
| 44 | } |
| 45 | |
| 46 | /* |
mardyk01 | 7b51dbe | 2024-01-17 15:25:36 -0600 | [diff] [blame^] | 47 | * Push function id value into data structure from device tree file |
| 48 | */ |
| 49 | void push_3dfifo_fid(struct fifo3d *f3d, int id) |
| 50 | { |
| 51 | f3d->fidfifo[f3d->col - 1][f3d->row[f3d->col - 1] - 1] = id; |
| 52 | } |
| 53 | |
| 54 | |
| 55 | /* |
Mark Dykes | e7810b5 | 2020-06-03 15:46:55 -0500 | [diff] [blame] | 56 | * Create new column and/or row for raw data structure for newly |
mardyk01 | 7b51dbe | 2024-01-17 15:25:36 -0600 | [diff] [blame^] | 57 | * found node from device tree. The fifo has four elements that reflect |
| 58 | * values obtained from the device tree for each node read. This preserves |
| 59 | * the hierarchy found in that file so it can be utilized in construction of |
| 60 | * the smc nodes structure for final use in randomly calling the SMC functions. |
| 61 | * This is essentially a bias tree in final form. |
Mark Dykes | e7810b5 | 2020-06-03 15:46:55 -0500 | [diff] [blame] | 62 | */ |
| 63 | void push_3dfifo_col(struct fifo3d *f3d, char *entry, struct memmod *mmod) |
| 64 | { |
mardyk01 | 7b51dbe | 2024-01-17 15:25:36 -0600 | [diff] [blame^] | 65 | |
| 66 | /* |
| 67 | * four elements required: |
| 68 | * 1. node name as a string |
| 69 | * 2. function name as a string |
| 70 | * 3. bias value as an integer |
| 71 | * 4. id value as an integer |
| 72 | */ |
Mark Dykes | e7810b5 | 2020-06-03 15:46:55 -0500 | [diff] [blame] | 73 | char ***tnnfifo; |
| 74 | char ***tfnamefifo; |
| 75 | int **tbiasfifo; |
mardyk01 | 7b51dbe | 2024-01-17 15:25:36 -0600 | [diff] [blame^] | 76 | int **tfidfifo; |
Mark Dykes | e7810b5 | 2020-06-03 15:46:55 -0500 | [diff] [blame] | 77 | |
| 78 | if (f3d->col == f3d->curr_col) { |
| 79 | f3d->col++; |
| 80 | f3d->curr_col++; |
| 81 | int *trow; |
| 82 | trow = GENMALLOC(f3d->col * sizeof(int)); |
| 83 | |
| 84 | /* |
| 85 | * return if error found |
| 86 | */ |
| 87 | if (mmod->memerror != 0) { |
| 88 | return; |
| 89 | } |
| 90 | |
| 91 | for (unsigned int i = 0U; (int)i < f3d->col - 1; i++) { |
| 92 | trow[i] = f3d->row[i]; |
| 93 | } |
| 94 | if (f3d->col > 1) { |
| 95 | GENFREE(f3d->row); |
| 96 | } |
| 97 | f3d->row = trow; |
| 98 | f3d->row[f3d->col - 1] = 1; |
| 99 | |
| 100 | /* |
mardyk01 | 7b51dbe | 2024-01-17 15:25:36 -0600 | [diff] [blame^] | 101 | * Start node creation for reading of device tree file |
Mark Dykes | e7810b5 | 2020-06-03 15:46:55 -0500 | [diff] [blame] | 102 | */ |
| 103 | tnnfifo = GENMALLOC(f3d->col * sizeof(char **)); |
| 104 | tfnamefifo = GENMALLOC(f3d->col * sizeof(char **)); |
| 105 | tbiasfifo = GENMALLOC((f3d->col) * sizeof(int *)); |
mardyk01 | 7b51dbe | 2024-01-17 15:25:36 -0600 | [diff] [blame^] | 106 | tfidfifo = GENMALLOC((f3d->col) * sizeof(int *)); |
Mark Dykes | e7810b5 | 2020-06-03 15:46:55 -0500 | [diff] [blame] | 107 | for (unsigned int i = 0U; (int)i < f3d->col; i++) { |
| 108 | tnnfifo[i] = GENMALLOC(f3d->row[i] * sizeof(char *)); |
| 109 | tfnamefifo[i] = GENMALLOC(f3d->row[i] * sizeof(char *)); |
| 110 | tbiasfifo[i] = GENMALLOC((f3d->row[i]) * sizeof(int)); |
mardyk01 | 7b51dbe | 2024-01-17 15:25:36 -0600 | [diff] [blame^] | 111 | tfidfifo[i] = GENMALLOC((f3d->row[i]) * sizeof(int)); |
Mark Dykes | e7810b5 | 2020-06-03 15:46:55 -0500 | [diff] [blame] | 112 | for (unsigned int j = 0U; (int)j < f3d->row[i]; j++) { |
| 113 | tnnfifo[i][j] = GENMALLOC(1 * sizeof(char[MAX_NAME_CHARS])); |
| 114 | tfnamefifo[i][j] = |
| 115 | GENMALLOC(1 * sizeof(char[MAX_NAME_CHARS])); |
| 116 | if (!((j == f3d->row[f3d->col - 1] - 1) && |
| 117 | (i == (f3d->col - 1)))) { |
| 118 | strlcpy(tnnfifo[i][j], f3d->nnfifo[i][j], MAX_NAME_CHARS); |
| 119 | strlcpy(tfnamefifo[i][j], |
| 120 | f3d->fnamefifo[i][j], MAX_NAME_CHARS); |
| 121 | tbiasfifo[i][j] = f3d->biasfifo[i][j]; |
mardyk01 | 7b51dbe | 2024-01-17 15:25:36 -0600 | [diff] [blame^] | 122 | tfidfifo[i][j] = f3d->fidfifo[i][j]; |
Mark Dykes | e7810b5 | 2020-06-03 15:46:55 -0500 | [diff] [blame] | 123 | } |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | /* |
| 128 | * Copy data from old raw data to new memory location |
| 129 | */ |
| 130 | strlcpy(tnnfifo[f3d->col - 1][f3d->row[f3d->col - 1] - 1], entry, |
| 131 | MAX_NAME_CHARS); |
| 132 | strlcpy(tfnamefifo[f3d->col - 1][f3d->row[f3d->col - 1] - 1], |
| 133 | "none", MAX_NAME_CHARS); |
| 134 | tbiasfifo[f3d->col - 1][f3d->row[f3d->col - 1] - 1] = 0; |
mardyk01 | 7b51dbe | 2024-01-17 15:25:36 -0600 | [diff] [blame^] | 135 | tfidfifo[f3d->col - 1][f3d->row[f3d->col - 1] - 1] = 0; |
Mark Dykes | e7810b5 | 2020-06-03 15:46:55 -0500 | [diff] [blame] | 136 | |
| 137 | /* |
| 138 | * Free the old raw data structres |
| 139 | */ |
| 140 | for (unsigned int i = 0U; (int)i < f3d->col - 1; i++) { |
| 141 | for (unsigned int j = 0U; (int)j < f3d->row[i]; j++) { |
| 142 | GENFREE(f3d->nnfifo[i][j]); |
| 143 | GENFREE(f3d->fnamefifo[i][j]); |
| 144 | } |
| 145 | GENFREE(f3d->nnfifo[i]); |
| 146 | GENFREE(f3d->fnamefifo[i]); |
| 147 | GENFREE(f3d->biasfifo[i]); |
mardyk01 | 7b51dbe | 2024-01-17 15:25:36 -0600 | [diff] [blame^] | 148 | GENFREE(f3d->fidfifo[i]); |
Mark Dykes | e7810b5 | 2020-06-03 15:46:55 -0500 | [diff] [blame] | 149 | } |
| 150 | if (f3d->col > 1) { |
| 151 | GENFREE(f3d->nnfifo); |
| 152 | GENFREE(f3d->fnamefifo); |
| 153 | GENFREE(f3d->biasfifo); |
mardyk01 | 7b51dbe | 2024-01-17 15:25:36 -0600 | [diff] [blame^] | 154 | GENFREE(f3d->fidfifo); |
Mark Dykes | e7810b5 | 2020-06-03 15:46:55 -0500 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | /* |
| 158 | * Point to new data |
| 159 | */ |
| 160 | f3d->nnfifo = tnnfifo; |
| 161 | f3d->fnamefifo = tfnamefifo; |
| 162 | f3d->biasfifo = tbiasfifo; |
mardyk01 | 7b51dbe | 2024-01-17 15:25:36 -0600 | [diff] [blame^] | 163 | f3d->fidfifo = tfidfifo; |
Mark Dykes | e7810b5 | 2020-06-03 15:46:55 -0500 | [diff] [blame] | 164 | } |
| 165 | if (f3d->col != f3d->curr_col) { |
| 166 | /* |
| 167 | * Adding new node to raw data |
| 168 | */ |
| 169 | f3d->col++; |
| 170 | f3d->row[f3d->col - 1]++; |
| 171 | |
| 172 | /* |
mardyk01 | 7b51dbe | 2024-01-17 15:25:36 -0600 | [diff] [blame^] | 173 | * Create new node form device tree file |
Mark Dykes | e7810b5 | 2020-06-03 15:46:55 -0500 | [diff] [blame] | 174 | */ |
| 175 | tnnfifo = GENMALLOC(f3d->col * sizeof(char **)); |
| 176 | tfnamefifo = GENMALLOC(f3d->col * sizeof(char **)); |
| 177 | tbiasfifo = GENMALLOC((f3d->col) * sizeof(int *)); |
mardyk01 | 7b51dbe | 2024-01-17 15:25:36 -0600 | [diff] [blame^] | 178 | tfidfifo = GENMALLOC((f3d->col) * sizeof(int *)); |
Mark Dykes | e7810b5 | 2020-06-03 15:46:55 -0500 | [diff] [blame] | 179 | for (unsigned int i = 0U; (int)i < f3d->col; i++) { |
| 180 | tnnfifo[i] = GENMALLOC(f3d->row[i] * sizeof(char *)); |
| 181 | tfnamefifo[i] = GENMALLOC(f3d->row[i] * sizeof(char *)); |
| 182 | tbiasfifo[i] = GENMALLOC((f3d->row[i]) * sizeof(int)); |
mardyk01 | 7b51dbe | 2024-01-17 15:25:36 -0600 | [diff] [blame^] | 183 | tfidfifo[i] = GENMALLOC((f3d->row[i]) * sizeof(int)); |
Mark Dykes | e7810b5 | 2020-06-03 15:46:55 -0500 | [diff] [blame] | 184 | for (unsigned int j = 0U; (int)j < f3d->row[i]; j++) { |
| 185 | tnnfifo[i][j] = GENMALLOC(1 * sizeof(char[MAX_NAME_CHARS])); |
| 186 | tfnamefifo[i][j] = |
| 187 | GENMALLOC(1 * sizeof(char[MAX_NAME_CHARS])); |
| 188 | if (!((j == f3d->row[f3d->col - 1] - 1) && |
| 189 | (i == (f3d->col - 1)))) { |
| 190 | strlcpy(tnnfifo[i][j], f3d->nnfifo[i][j], MAX_NAME_CHARS); |
| 191 | strlcpy(tfnamefifo[i][j], |
| 192 | f3d->fnamefifo[i][j], MAX_NAME_CHARS); |
| 193 | tbiasfifo[i][j] = f3d->biasfifo[i][j]; |
mardyk01 | 7b51dbe | 2024-01-17 15:25:36 -0600 | [diff] [blame^] | 194 | tfidfifo[i][j] = f3d->fidfifo[i][j]; |
Mark Dykes | e7810b5 | 2020-06-03 15:46:55 -0500 | [diff] [blame] | 195 | } |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | /* |
| 200 | * Copy data from old raw data to new memory location |
| 201 | */ |
| 202 | strlcpy(tnnfifo[f3d->col - 1][f3d->row[f3d->col - 1] - 1], entry, |
| 203 | MAX_NAME_CHARS); |
| 204 | strlcpy(tfnamefifo[f3d->col - 1][f3d->row[f3d->col - 1] - 1], |
| 205 | "none", MAX_NAME_CHARS); |
| 206 | tbiasfifo[f3d->col - 1][f3d->row[f3d->col - 1] - 1] = 0; |
mardyk01 | 7b51dbe | 2024-01-17 15:25:36 -0600 | [diff] [blame^] | 207 | tfidfifo[f3d->col - 1][f3d->row[f3d->col - 1] - 1] = 0; |
Mark Dykes | e7810b5 | 2020-06-03 15:46:55 -0500 | [diff] [blame] | 208 | |
| 209 | /* |
| 210 | * Free the old raw data structres |
| 211 | */ |
| 212 | for (unsigned int i = 0U; (int)i < f3d->col; i++) { |
| 213 | for (unsigned int j = 0U; (int)j < f3d->row[i]; j++) { |
| 214 | if (!((i == f3d->col - 1) && |
| 215 | (j == f3d->row[i] - 1))) { |
| 216 | GENFREE(f3d->nnfifo[i][j]); |
| 217 | GENFREE(f3d->fnamefifo[i][j]); |
| 218 | } |
| 219 | } |
| 220 | GENFREE(f3d->nnfifo[i]); |
| 221 | GENFREE(f3d->fnamefifo[i]); |
| 222 | GENFREE(f3d->biasfifo[i]); |
mardyk01 | 7b51dbe | 2024-01-17 15:25:36 -0600 | [diff] [blame^] | 223 | GENFREE(f3d->fidfifo[i]); |
Mark Dykes | e7810b5 | 2020-06-03 15:46:55 -0500 | [diff] [blame] | 224 | } |
| 225 | GENFREE(f3d->nnfifo); |
| 226 | GENFREE(f3d->fnamefifo); |
| 227 | GENFREE(f3d->biasfifo); |
mardyk01 | 7b51dbe | 2024-01-17 15:25:36 -0600 | [diff] [blame^] | 228 | GENFREE(f3d->fidfifo); |
Mark Dykes | e7810b5 | 2020-06-03 15:46:55 -0500 | [diff] [blame] | 229 | |
| 230 | /* |
| 231 | * Point to new data |
| 232 | */ |
| 233 | f3d->nnfifo = tnnfifo; |
| 234 | f3d->fnamefifo = tfnamefifo; |
| 235 | f3d->biasfifo = tbiasfifo; |
mardyk01 | 7b51dbe | 2024-01-17 15:25:36 -0600 | [diff] [blame^] | 236 | f3d->fidfifo = tfidfifo; |
Mark Dykes | e7810b5 | 2020-06-03 15:46:55 -0500 | [diff] [blame] | 237 | } |
| 238 | } |