Patrick Georgi | ea063cb | 2020-05-08 19:28:13 +0200 | [diff] [blame] | 1 | /* sconfig, coreboot device tree compiler */ |
Patrick Georgi | 7333a11 | 2020-05-08 20:48:04 +0200 | [diff] [blame] | 2 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 3 | |
Tim Wawrzynczak | ba4a490 | 2020-09-23 15:36:30 -0600 | [diff] [blame^] | 4 | #include <assert.h> |
Patrick Georgi | 2dbfcb7 | 2012-05-30 16:26:30 +0200 | [diff] [blame] | 5 | #include <ctype.h> |
Duncan Laurie | 51c8373 | 2020-06-09 11:20:29 -0700 | [diff] [blame] | 6 | #include <getopt.h> |
Werner Zeh | ac14a40 | 2019-07-11 12:47:19 +0200 | [diff] [blame] | 7 | /* stat.h needs to be included before commonlib/helpers.h to avoid errors.*/ |
Tim Wawrzynczak | ba4a490 | 2020-09-23 15:36:30 -0600 | [diff] [blame^] | 8 | #include <libgen.h> |
Werner Zeh | ac14a40 | 2019-07-11 12:47:19 +0200 | [diff] [blame] | 9 | #include <sys/stat.h> |
Kyösti Mälkki | e29a6ac | 2019-03-15 17:05:19 +0200 | [diff] [blame] | 10 | #include <commonlib/helpers.h> |
Duncan Laurie | 47b7b34 | 2020-05-15 15:39:08 -0700 | [diff] [blame] | 11 | #include <stdint.h> |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 12 | #include "sconfig.h" |
| 13 | #include "sconfig.tab.h" |
| 14 | |
Patrick Georgi | 7fc9e29 | 2010-07-15 15:59:07 +0000 | [diff] [blame] | 15 | extern int linenum; |
| 16 | |
Furquan Shaikh | 27efc50 | 2018-06-22 09:19:15 -0700 | [diff] [blame] | 17 | /* |
| 18 | * Maintains list of all the unique chip structures for the board. |
| 19 | * This is shared across base and override device trees since we need to |
| 20 | * generate headers for all chips added by both the trees. |
| 21 | */ |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 22 | static struct chip chip_header; |
Furquan Shaikh | 79e8412 | 2018-05-30 15:09:09 -0700 | [diff] [blame] | 23 | |
Kyösti Mälkki | 472d902 | 2011-12-05 20:33:55 +0200 | [diff] [blame] | 24 | typedef enum { |
Kyösti Mälkki | 1a2a6ee | 2012-03-18 20:19:28 +0200 | [diff] [blame] | 25 | UNSLASH, |
| 26 | SPLIT_1ST, |
| 27 | TO_LOWER, |
| 28 | TO_UPPER, |
| 29 | } translate_t; |
| 30 | |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 31 | /* |
| 32 | * Mainboard is assumed to have a root device whose bus is the parent of all the |
| 33 | * devices that are added by parsing the devicetree file. This device has a |
| 34 | * mainboard chip instance associated with it. |
| 35 | * |
| 36 | * |
| 37 | * |
| 38 | * +------------------------+ +----------------------+ |
Furquan Shaikh | de39fc7 | 2018-06-11 04:26:45 -0700 | [diff] [blame] | 39 | * | Root device | | Mainboard | |
| 40 | * +---------+ (base_root_dev) +--------------->+ instance + |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 41 | * | | | chip_instance | (mainboard_instance)| |
| 42 | * | +------------------------+ | | |
| 43 | * | | +----------------------+ |
| 44 | * | | bus | |
| 45 | * | parent v | |
| 46 | * | +-------------------+ | |
| 47 | * | | Root bus | | |
Furquan Shaikh | de39fc7 | 2018-06-11 04:26:45 -0700 | [diff] [blame] | 48 | * +----------->+ (base_root_bus) | | |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 49 | * | | | |
| 50 | * +-------------------+ | |
| 51 | * | | |
| 52 | * | children | chip |
| 53 | * v | |
| 54 | * X | |
| 55 | * (new devices will | |
| 56 | * be added here as | |
| 57 | * children) | |
| 58 | * | |
| 59 | * | |
| 60 | * | |
| 61 | * +-------+----------+ |
| 62 | * | | |
| 63 | * | Mainboard chip +----------->X (new chips will be |
| 64 | * | (mainboard_chip) | added here) |
| 65 | * | | |
| 66 | * +------------------+ |
| 67 | * |
| 68 | * |
| 69 | */ |
Furquan Shaikh | 39ac797 | 2018-06-21 18:44:32 -0700 | [diff] [blame] | 70 | |
| 71 | /* Root device of primary tree. */ |
Furquan Shaikh | de39fc7 | 2018-06-11 04:26:45 -0700 | [diff] [blame] | 72 | static struct device base_root_dev; |
Furquan Shaikh | 39ac797 | 2018-06-21 18:44:32 -0700 | [diff] [blame] | 73 | |
Duncan Laurie | e335c2e | 2020-07-29 16:28:43 -0700 | [diff] [blame] | 74 | /* Root device of chipset tree. */ |
| 75 | static struct device chipset_root_dev; |
| 76 | |
Furquan Shaikh | 39ac797 | 2018-06-21 18:44:32 -0700 | [diff] [blame] | 77 | /* Root device of override tree (if applicable). */ |
| 78 | static struct device override_root_dev; |
| 79 | |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 80 | static struct chip_instance mainboard_instance; |
| 81 | |
Furquan Shaikh | de39fc7 | 2018-06-11 04:26:45 -0700 | [diff] [blame] | 82 | static struct bus base_root_bus = { |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 83 | .id = 0, |
Furquan Shaikh | de39fc7 | 2018-06-11 04:26:45 -0700 | [diff] [blame] | 84 | .dev = &base_root_dev, |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 85 | }; |
| 86 | |
Furquan Shaikh | de39fc7 | 2018-06-11 04:26:45 -0700 | [diff] [blame] | 87 | static struct device base_root_dev = { |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 88 | .name = "dev_root", |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 89 | .chip_instance = &mainboard_instance, |
| 90 | .path = " .type = DEVICE_PATH_ROOT ", |
Furquan Shaikh | de39fc7 | 2018-06-11 04:26:45 -0700 | [diff] [blame] | 91 | .parent = &base_root_bus, |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 92 | .enabled = 1, |
Furquan Shaikh | de39fc7 | 2018-06-11 04:26:45 -0700 | [diff] [blame] | 93 | .bus = &base_root_bus, |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 94 | }; |
| 95 | |
Duncan Laurie | e335c2e | 2020-07-29 16:28:43 -0700 | [diff] [blame] | 96 | static struct bus chipset_root_bus = { |
| 97 | .id = 0, |
| 98 | .dev = &chipset_root_dev, |
| 99 | }; |
| 100 | |
| 101 | static struct device chipset_root_dev = { |
| 102 | .name = "chipset_root", |
| 103 | .chip_instance = &mainboard_instance, |
| 104 | .path = " .type = DEVICE_PATH_ROOT ", |
| 105 | .parent = &chipset_root_bus, |
| 106 | .enabled = 1, |
| 107 | .bus = &chipset_root_bus, |
| 108 | }; |
| 109 | |
Furquan Shaikh | 39ac797 | 2018-06-21 18:44:32 -0700 | [diff] [blame] | 110 | static struct bus override_root_bus = { |
| 111 | .id = 0, |
| 112 | .dev = &override_root_dev, |
| 113 | }; |
| 114 | |
| 115 | static struct device override_root_dev = { |
| 116 | .name = "override_root", |
Furquan Shaikh | 39ac797 | 2018-06-21 18:44:32 -0700 | [diff] [blame] | 117 | /* |
| 118 | * Override tree root device points to the same mainboard chip instance |
| 119 | * as the base tree root device. It should not cause any side-effects |
| 120 | * since the mainboard chip instance pointer in override tree will just |
| 121 | * be ignored. |
| 122 | */ |
| 123 | .chip_instance = &mainboard_instance, |
| 124 | .path = " .type = DEVICE_PATH_ROOT ", |
Furquan Shaikh | 39ac797 | 2018-06-21 18:44:32 -0700 | [diff] [blame] | 125 | .parent = &override_root_bus, |
| 126 | .enabled = 1, |
| 127 | .bus = &override_root_bus, |
| 128 | }; |
| 129 | |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 130 | static struct chip mainboard_chip = { |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 131 | .name = "mainboard", |
| 132 | .name_underscore = "mainboard", |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 133 | .instance = &mainboard_instance, |
| 134 | }; |
| 135 | |
| 136 | static struct chip_instance mainboard_instance = { |
| 137 | .id = 0, |
| 138 | .chip = &mainboard_chip, |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 139 | }; |
| 140 | |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 141 | /* This is the parent of all devices added by parsing the devicetree file. */ |
Furquan Shaikh | de39fc7 | 2018-06-11 04:26:45 -0700 | [diff] [blame] | 142 | struct bus *root_parent; |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 143 | |
Furquan Shaikh | 7398ded | 2018-06-03 10:42:49 -0700 | [diff] [blame] | 144 | struct queue_entry { |
Furquan Shaikh | 79e8412 | 2018-05-30 15:09:09 -0700 | [diff] [blame] | 145 | void *data; |
Furquan Shaikh | 7398ded | 2018-06-03 10:42:49 -0700 | [diff] [blame] | 146 | struct queue_entry *next; |
| 147 | struct queue_entry *prev; |
| 148 | }; |
Furquan Shaikh | 79e8412 | 2018-05-30 15:09:09 -0700 | [diff] [blame] | 149 | |
Furquan Shaikh | 369e1f0 | 2018-05-31 09:48:51 -0700 | [diff] [blame] | 150 | #define S_ALLOC(_s) s_alloc(__func__, _s) |
Furquan Shaikh | 79e8412 | 2018-05-30 15:09:09 -0700 | [diff] [blame] | 151 | |
Furquan Shaikh | 369e1f0 | 2018-05-31 09:48:51 -0700 | [diff] [blame] | 152 | static void *s_alloc(const char *f, size_t s) |
| 153 | { |
| 154 | void *data = calloc(1, s); |
| 155 | if (!data) { |
Maulik V Vaghela | 82e8c69 | 2018-06-08 10:32:08 +0530 | [diff] [blame] | 156 | fprintf(stderr, "%s: Failed to alloc mem!\n", f); |
Furquan Shaikh | 79e8412 | 2018-05-30 15:09:09 -0700 | [diff] [blame] | 157 | exit(1); |
| 158 | } |
Furquan Shaikh | 369e1f0 | 2018-05-31 09:48:51 -0700 | [diff] [blame] | 159 | return data; |
| 160 | } |
| 161 | |
Furquan Shaikh | 7398ded | 2018-06-03 10:42:49 -0700 | [diff] [blame] | 162 | static struct queue_entry *new_queue_entry(void *data) |
Furquan Shaikh | 369e1f0 | 2018-05-31 09:48:51 -0700 | [diff] [blame] | 163 | { |
Furquan Shaikh | 7398ded | 2018-06-03 10:42:49 -0700 | [diff] [blame] | 164 | struct queue_entry *e = S_ALLOC(sizeof(*e)); |
Furquan Shaikh | 79e8412 | 2018-05-30 15:09:09 -0700 | [diff] [blame] | 165 | |
| 166 | e->data = data; |
| 167 | e->next = e->prev = e; |
| 168 | return e; |
| 169 | } |
| 170 | |
Furquan Shaikh | 7398ded | 2018-06-03 10:42:49 -0700 | [diff] [blame] | 171 | static void enqueue_tail(struct queue_entry **q_head, void *data) |
Furquan Shaikh | 79e8412 | 2018-05-30 15:09:09 -0700 | [diff] [blame] | 172 | { |
Furquan Shaikh | 7398ded | 2018-06-03 10:42:49 -0700 | [diff] [blame] | 173 | struct queue_entry *tmp = new_queue_entry(data); |
| 174 | struct queue_entry *q = *q_head; |
Furquan Shaikh | 79e8412 | 2018-05-30 15:09:09 -0700 | [diff] [blame] | 175 | |
| 176 | if (!q) { |
Furquan Shaikh | 7398ded | 2018-06-03 10:42:49 -0700 | [diff] [blame] | 177 | *q_head = tmp; |
Furquan Shaikh | 79e8412 | 2018-05-30 15:09:09 -0700 | [diff] [blame] | 178 | return; |
| 179 | } |
| 180 | |
| 181 | q->prev->next = tmp; |
| 182 | tmp->prev = q->prev; |
| 183 | q->prev = tmp; |
| 184 | tmp->next = q; |
| 185 | } |
| 186 | |
Furquan Shaikh | 7398ded | 2018-06-03 10:42:49 -0700 | [diff] [blame] | 187 | static void *dequeue_tail(struct queue_entry **q_head) |
Furquan Shaikh | 79e8412 | 2018-05-30 15:09:09 -0700 | [diff] [blame] | 188 | { |
Furquan Shaikh | 7398ded | 2018-06-03 10:42:49 -0700 | [diff] [blame] | 189 | struct queue_entry *q = *q_head; |
| 190 | struct queue_entry *tmp; |
Furquan Shaikh | 79e8412 | 2018-05-30 15:09:09 -0700 | [diff] [blame] | 191 | void *data; |
| 192 | |
Furquan Shaikh | 7398ded | 2018-06-03 10:42:49 -0700 | [diff] [blame] | 193 | if (!q) |
| 194 | return NULL; |
| 195 | |
| 196 | tmp = q->prev; |
| 197 | |
Furquan Shaikh | 79e8412 | 2018-05-30 15:09:09 -0700 | [diff] [blame] | 198 | if (tmp == q) |
Furquan Shaikh | 7398ded | 2018-06-03 10:42:49 -0700 | [diff] [blame] | 199 | *q_head = NULL; |
Furquan Shaikh | 79e8412 | 2018-05-30 15:09:09 -0700 | [diff] [blame] | 200 | else { |
| 201 | tmp->prev->next = q; |
| 202 | q->prev = tmp->prev; |
| 203 | } |
| 204 | |
| 205 | data = tmp->data; |
| 206 | free(tmp); |
| 207 | |
| 208 | return data; |
| 209 | } |
| 210 | |
Furquan Shaikh | 7398ded | 2018-06-03 10:42:49 -0700 | [diff] [blame] | 211 | static void *dequeue_head(struct queue_entry **q_head) |
| 212 | { |
| 213 | struct queue_entry *q = *q_head; |
| 214 | struct queue_entry *tmp = q; |
| 215 | void *data; |
| 216 | |
| 217 | if (!q) |
| 218 | return NULL; |
| 219 | |
| 220 | if (q->next == q) |
| 221 | *q_head = NULL; |
| 222 | else { |
| 223 | q->next->prev = q->prev; |
| 224 | q->prev->next = q->next; |
| 225 | *q_head = q->next; |
| 226 | } |
| 227 | |
| 228 | data = tmp->data; |
| 229 | free(tmp); |
| 230 | |
| 231 | return data; |
| 232 | } |
| 233 | |
| 234 | static void *peek_queue_head(struct queue_entry *q_head) |
| 235 | { |
| 236 | if (!q_head) |
| 237 | return NULL; |
| 238 | |
| 239 | return q_head->data; |
| 240 | } |
| 241 | |
| 242 | static struct queue_entry *chip_q_head; |
| 243 | |
| 244 | void chip_enqueue_tail(void *data) |
| 245 | { |
| 246 | enqueue_tail(&chip_q_head, data); |
| 247 | } |
| 248 | |
| 249 | void *chip_dequeue_tail(void) |
| 250 | { |
| 251 | return dequeue_tail(&chip_q_head); |
| 252 | } |
| 253 | |
Martin Roth | bec0753 | 2016-08-05 18:32:18 -0600 | [diff] [blame] | 254 | int yywrap(void) |
| 255 | { |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 256 | return 1; |
| 257 | } |
| 258 | |
Martin Roth | bec0753 | 2016-08-05 18:32:18 -0600 | [diff] [blame] | 259 | void yyerror(char const *str) |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 260 | { |
Stefan Reinauer | 7c1f6b8 | 2010-08-16 18:21:56 +0000 | [diff] [blame] | 261 | extern char *yytext; |
Martin Roth | bec0753 | 2016-08-05 18:32:18 -0600 | [diff] [blame] | 262 | fprintf(stderr, "line %d: %s: %s\n", linenum + 1, yytext, str); |
Stefan Reinauer | 7c1f6b8 | 2010-08-16 18:21:56 +0000 | [diff] [blame] | 263 | exit(1); |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 264 | } |
| 265 | |
Martin Roth | bec0753 | 2016-08-05 18:32:18 -0600 | [diff] [blame] | 266 | char *translate_name(const char *str, translate_t mode) |
Kyösti Mälkki | 472d902 | 2011-12-05 20:33:55 +0200 | [diff] [blame] | 267 | { |
Kyösti Mälkki | 1a2a6ee | 2012-03-18 20:19:28 +0200 | [diff] [blame] | 268 | char *b, *c; |
| 269 | b = c = strdup(str); |
| 270 | while (c && *c) { |
| 271 | if ((mode == SPLIT_1ST) && (*c == '/')) { |
| 272 | *c = 0; |
| 273 | break; |
| 274 | } |
Martin Roth | bec0753 | 2016-08-05 18:32:18 -0600 | [diff] [blame] | 275 | if (*c == '/') |
| 276 | *c = '_'; |
| 277 | if (*c == '-') |
| 278 | *c = '_'; |
Kyösti Mälkki | 1a2a6ee | 2012-03-18 20:19:28 +0200 | [diff] [blame] | 279 | if (mode == TO_UPPER) |
Kyösti Mälkki | 472d902 | 2011-12-05 20:33:55 +0200 | [diff] [blame] | 280 | *c = toupper(*c); |
Kyösti Mälkki | 1a2a6ee | 2012-03-18 20:19:28 +0200 | [diff] [blame] | 281 | if (mode == TO_LOWER) |
| 282 | *c = tolower(*c); |
| 283 | c++; |
Kyösti Mälkki | 472d902 | 2011-12-05 20:33:55 +0200 | [diff] [blame] | 284 | } |
Kyösti Mälkki | 1a2a6ee | 2012-03-18 20:19:28 +0200 | [diff] [blame] | 285 | return b; |
Kyösti Mälkki | 472d902 | 2011-12-05 20:33:55 +0200 | [diff] [blame] | 286 | } |
| 287 | |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 288 | static struct chip *get_chip(char *path) |
Martin Roth | bec0753 | 2016-08-05 18:32:18 -0600 | [diff] [blame] | 289 | { |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 290 | struct chip *h = &chip_header; |
Furquan Shaikh | 79e8412 | 2018-05-30 15:09:09 -0700 | [diff] [blame] | 291 | |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 292 | while (h->next) { |
| 293 | int result = strcmp(path, h->next->name); |
| 294 | if (result == 0) |
| 295 | return h->next; |
| 296 | |
| 297 | if (result < 0) |
| 298 | break; |
| 299 | |
| 300 | h = h->next; |
| 301 | } |
| 302 | |
| 303 | struct chip *new_chip = S_ALLOC(sizeof(struct chip)); |
| 304 | new_chip->next = h->next; |
| 305 | h->next = new_chip; |
| 306 | |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 307 | new_chip->chiph_exists = 1; |
| 308 | new_chip->name = path; |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 309 | new_chip->name_underscore = translate_name(path, UNSLASH); |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 310 | |
| 311 | struct stat st; |
Furquan Shaikh | 369e1f0 | 2018-05-31 09:48:51 -0700 | [diff] [blame] | 312 | char *chip_h = S_ALLOC(strlen(path) + 18); |
Stefan Reinauer | 76c44ae | 2011-10-14 12:41:46 -0700 | [diff] [blame] | 313 | sprintf(chip_h, "src/%s", path); |
| 314 | if ((stat(chip_h, &st) == -1) && (errno == ENOENT)) { |
Patrick Georgi | 92bcaa2 | 2015-11-13 09:39:22 +0100 | [diff] [blame] | 315 | /* root_complex gets away without a separate directory, but |
| 316 | * exists on on pretty much all AMD chipsets. |
| 317 | */ |
| 318 | if (!strstr(path, "/root_complex")) { |
Kyösti Mälkki | 6aeb4a2 | 2013-06-11 17:00:11 +0300 | [diff] [blame] | 319 | fprintf(stderr, "ERROR: Chip component %s does not exist.\n", |
| 320 | path); |
| 321 | exit(1); |
| 322 | } |
Stefan Reinauer | 76c44ae | 2011-10-14 12:41:46 -0700 | [diff] [blame] | 323 | } |
| 324 | |
Martin Roth | 824255e | 2016-08-05 17:40:39 -0600 | [diff] [blame] | 325 | sprintf(chip_h, "src/%s/chip.h", path); |
Kyösti Mälkki | 472d902 | 2011-12-05 20:33:55 +0200 | [diff] [blame] | 326 | |
Martin Roth | 824255e | 2016-08-05 17:40:39 -0600 | [diff] [blame] | 327 | if ((stat(chip_h, &st) == -1) && (errno == ENOENT)) |
Martin Roth | bec0753 | 2016-08-05 18:32:18 -0600 | [diff] [blame] | 328 | new_chip->chiph_exists = 0; |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 329 | |
Patrick Georgi | 1f68880 | 2014-08-03 15:51:19 +0200 | [diff] [blame] | 330 | free(chip_h); |
Furquan Shaikh | 79e8412 | 2018-05-30 15:09:09 -0700 | [diff] [blame] | 331 | |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 332 | return new_chip; |
| 333 | } |
| 334 | |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 335 | struct chip_instance *new_chip_instance(char *path) |
| 336 | { |
| 337 | struct chip *chip = get_chip(path); |
| 338 | struct chip_instance *instance = S_ALLOC(sizeof(*instance)); |
| 339 | |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 340 | instance->chip = chip; |
| 341 | instance->next = chip->instance; |
| 342 | chip->instance = instance; |
| 343 | |
| 344 | return instance; |
| 345 | } |
| 346 | |
Duncan Laurie | 47b7b34 | 2020-05-15 15:39:08 -0700 | [diff] [blame] | 347 | /* List of fw_config fields added during parsing. */ |
| 348 | static struct fw_config_field *fw_config_fields; |
| 349 | |
| 350 | static struct fw_config_option *find_fw_config_option(struct fw_config_field *field, |
| 351 | const char *name) |
| 352 | { |
| 353 | struct fw_config_option *option = field->options; |
| 354 | |
| 355 | while (option && option->name) { |
| 356 | if (!strcmp(option->name, name)) |
| 357 | return option; |
| 358 | option = option->next; |
| 359 | } |
| 360 | return NULL; |
| 361 | } |
| 362 | |
| 363 | static struct fw_config_field *find_fw_config_field(const char *name) |
| 364 | { |
| 365 | struct fw_config_field *field = fw_config_fields; |
| 366 | |
| 367 | while (field && field->name) { |
| 368 | if (!strcmp(field->name, name)) |
| 369 | return field; |
| 370 | field = field->next; |
| 371 | } |
| 372 | return NULL; |
| 373 | } |
| 374 | |
| 375 | struct fw_config_field *get_fw_config_field(const char *name) |
| 376 | { |
| 377 | struct fw_config_field *field = find_fw_config_field(name); |
| 378 | |
| 379 | /* Fail if the field does not exist, new fields must be added with a mask. */ |
| 380 | if (!field) { |
| 381 | printf("ERROR: fw_config field not found: %s\n", name); |
| 382 | exit(1); |
| 383 | } |
| 384 | return field; |
| 385 | } |
| 386 | |
| 387 | static void append_fw_config_field(struct fw_config_field *add) |
| 388 | { |
| 389 | struct fw_config_field *field = fw_config_fields; |
| 390 | |
| 391 | if (!fw_config_fields) { |
| 392 | fw_config_fields = add; |
| 393 | } else { |
| 394 | while (field && field->next) |
| 395 | field = field->next; |
| 396 | field->next = add; |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | struct fw_config_field *new_fw_config_field(const char *name, |
| 401 | unsigned int start_bit, unsigned int end_bit) |
| 402 | { |
| 403 | struct fw_config_field *field = find_fw_config_field(name); |
| 404 | |
| 405 | /* Check that field is within 32bits. */ |
| 406 | if (start_bit > end_bit || end_bit > 31) { |
| 407 | printf("ERROR: fw_config field %s has invalid range %u-%u\n", name, |
| 408 | start_bit, end_bit); |
| 409 | exit(1); |
| 410 | } |
| 411 | |
| 412 | /* Don't allow re-defining a field, only adding new fields. */ |
| 413 | if (field) { |
| 414 | printf("ERROR: fw_config field %s[%u-%u] already exists with range %u-%u\n", |
| 415 | name, start_bit, end_bit, field->start_bit, field->end_bit); |
| 416 | exit(1); |
| 417 | } |
| 418 | |
| 419 | /* Check for overlap with an existing field. */ |
| 420 | field = fw_config_fields; |
| 421 | while (field) { |
| 422 | /* Check if the mask overlaps. */ |
| 423 | if (start_bit <= field->end_bit && end_bit >= field->start_bit) { |
| 424 | printf("ERROR: fw_config field %s[%u-%u] overlaps %s[%u-%u]\n", |
| 425 | name, start_bit, end_bit, |
| 426 | field->name, field->start_bit, field->end_bit); |
| 427 | exit(1); |
| 428 | } |
| 429 | field = field->next; |
| 430 | } |
| 431 | |
| 432 | field = S_ALLOC(sizeof(*field)); |
| 433 | field->name = name; |
| 434 | field->start_bit = start_bit; |
| 435 | field->end_bit = end_bit; |
| 436 | append_fw_config_field(field); |
| 437 | |
| 438 | return field; |
| 439 | } |
| 440 | |
| 441 | static void append_fw_config_option_to_field(struct fw_config_field *field, |
| 442 | struct fw_config_option *add) |
| 443 | { |
| 444 | struct fw_config_option *option = field->options; |
| 445 | |
| 446 | if (!option) { |
| 447 | field->options = add; |
| 448 | } else { |
| 449 | while (option && option->next) |
| 450 | option = option->next; |
| 451 | option->next = add; |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | void add_fw_config_option(struct fw_config_field *field, const char *name, unsigned int value) |
| 456 | { |
| 457 | struct fw_config_option *option; |
| 458 | uint32_t field_max_value; |
| 459 | |
| 460 | /* Check that option value fits within field mask. */ |
| 461 | field_max_value = (1 << (1 + field->end_bit - field->start_bit)) - 1; |
| 462 | if (value > field_max_value) { |
| 463 | printf("ERROR: fw_config option %s:%s value %u larger than field max %u\n", |
| 464 | field->name, name, value, field_max_value); |
| 465 | exit(1); |
| 466 | } |
| 467 | |
| 468 | /* Check for existing option with this name or value. */ |
| 469 | option = field->options; |
| 470 | while (option) { |
| 471 | if (!strcmp(option->name, name)) { |
| 472 | printf("ERROR: fw_config option name %s:%s already exists\n", |
| 473 | field->name, name); |
| 474 | exit(1); |
| 475 | } |
| 476 | /* Compare values. */ |
| 477 | if (value == option->value) { |
| 478 | printf("ERROR: fw_config option %s:%s[%u] redefined as %s\n", |
| 479 | field->name, option->name, value, name); |
| 480 | exit(1); |
| 481 | } |
| 482 | option = option->next; |
| 483 | } |
| 484 | |
| 485 | option = S_ALLOC(sizeof(*option)); |
| 486 | option->name = name; |
| 487 | option->value = value; |
| 488 | |
| 489 | /* Add option to the current field. */ |
| 490 | append_fw_config_option_to_field(field, option); |
| 491 | } |
| 492 | |
| 493 | static void append_fw_config_probe_to_dev(struct device *dev, struct fw_config_probe *add) |
| 494 | { |
| 495 | struct fw_config_probe *probe = dev->probe; |
| 496 | |
| 497 | if (!probe) { |
| 498 | dev->probe = add; |
| 499 | } else { |
| 500 | while (probe && probe->next) |
| 501 | probe = probe->next; |
| 502 | probe->next = add; |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | void add_fw_config_probe(struct bus *bus, const char *field, const char *option) |
| 507 | { |
| 508 | struct fw_config_probe *probe; |
| 509 | |
| 510 | probe = bus->dev->probe; |
| 511 | while (probe) { |
| 512 | if (!strcmp(probe->field, field) && !strcmp(probe->option, option)) { |
| 513 | printf("ERROR: fw_config probe %s:%s already exists\n", field, option); |
| 514 | exit(1); |
| 515 | } |
| 516 | probe = probe->next; |
| 517 | } |
| 518 | |
| 519 | probe = S_ALLOC(sizeof(*probe)); |
| 520 | probe->field = field; |
| 521 | probe->option = option; |
| 522 | |
| 523 | append_fw_config_probe_to_dev(bus->dev, probe); |
| 524 | } |
| 525 | |
| 526 | static void emit_fw_config(FILE *fil) |
| 527 | { |
| 528 | struct fw_config_field *field = fw_config_fields; |
| 529 | |
| 530 | if (!field) |
| 531 | return; |
| 532 | |
Duncan Laurie | 47b7b34 | 2020-05-15 15:39:08 -0700 | [diff] [blame] | 533 | while (field) { |
| 534 | struct fw_config_option *option = field->options; |
| 535 | uint32_t mask; |
| 536 | |
| 537 | fprintf(fil, "#define FW_CONFIG_FIELD_%s_NAME \"%s\"\n", |
| 538 | field->name, field->name); |
| 539 | |
| 540 | /* Compute mask from start and end bit. */ |
| 541 | mask = ((1 << (1 + field->end_bit - field->start_bit)) - 1); |
| 542 | mask <<= field->start_bit; |
| 543 | |
| 544 | fprintf(fil, "#define FW_CONFIG_FIELD_%s_MASK 0x%08x\n", |
| 545 | field->name, mask); |
| 546 | |
| 547 | while (option) { |
| 548 | fprintf(fil, "#define FW_CONFIG_FIELD_%s_OPTION_%s_NAME \"%s\"\n", |
| 549 | field->name, option->name, option->name); |
| 550 | fprintf(fil, "#define FW_CONFIG_FIELD_%s_OPTION_%s_VALUE 0x%08x\n", |
| 551 | field->name, option->name, option->value << field->start_bit); |
| 552 | |
| 553 | option = option->next; |
| 554 | } |
| 555 | |
| 556 | field = field->next; |
| 557 | } |
| 558 | |
| 559 | fprintf(fil, "\n"); |
| 560 | } |
| 561 | |
| 562 | static int emit_fw_config_probe(FILE *fil, struct device *dev) |
| 563 | { |
| 564 | struct fw_config_probe *probe = dev->probe; |
| 565 | |
| 566 | fprintf(fil, "STORAGE struct fw_config %s_probe_list[] = {\n", dev->name); |
| 567 | |
| 568 | while (probe) { |
| 569 | /* Find matching field. */ |
| 570 | struct fw_config_field *field; |
| 571 | struct fw_config_option *option; |
| 572 | uint32_t mask, value; |
| 573 | |
| 574 | field = find_fw_config_field(probe->field); |
| 575 | if (!field) { |
| 576 | printf("ERROR: fw_config_probe field %s not found\n", probe->field); |
| 577 | return -1; |
| 578 | } |
| 579 | option = find_fw_config_option(field, probe->option); |
| 580 | if (!option) { |
| 581 | printf("ERROR: fw_config_probe field %s option %s not found\n", |
| 582 | probe->field, probe->option); |
| 583 | return -1; |
| 584 | } |
| 585 | |
| 586 | /* Fill out the probe structure with values from emit_fw_config(). */ |
| 587 | fprintf(fil, "\t{\n"); |
| 588 | fprintf(fil, "\t\t.field_name = FW_CONFIG_FIELD_%s_NAME,\n", probe->field); |
| 589 | fprintf(fil, "\t\t.option_name = FW_CONFIG_FIELD_%s_OPTION_%s_NAME,\n", |
| 590 | probe->field, probe->option); |
| 591 | fprintf(fil, "\t\t.mask = FW_CONFIG_FIELD_%s_MASK,\n", probe->field); |
| 592 | fprintf(fil, "\t\t.value = FW_CONFIG_FIELD_%s_OPTION_%s_VALUE,\n", |
| 593 | probe->field, probe->option); |
| 594 | fprintf(fil, "\t},\n"); |
| 595 | |
| 596 | probe = probe->next; |
| 597 | } |
| 598 | |
| 599 | /* Add empty entry to mark end of list. */ |
| 600 | fprintf(fil, "\t{ }\n};\n"); |
| 601 | return 0; |
| 602 | } |
| 603 | |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 604 | /* |
| 605 | * Allocate a new bus for the provided device. |
| 606 | * - If this is the first bus being allocated under this device, then its id |
| 607 | * is set to 0 and bus and last_bus are pointed to the newly allocated bus. |
| 608 | * - If this is not the first bus under this device, then its id is set to 1 |
| 609 | * plus the id of last bus and newly allocated bus is added to the list of |
| 610 | * buses under the device. last_bus is updated to point to the newly |
| 611 | * allocated bus. |
| 612 | */ |
| 613 | static void alloc_bus(struct device *dev) |
| 614 | { |
| 615 | struct bus *bus = S_ALLOC(sizeof(*bus)); |
| 616 | |
| 617 | bus->dev = dev; |
| 618 | |
| 619 | if (dev->last_bus == NULL) { |
| 620 | bus->id = 0; |
| 621 | dev->bus = bus; |
| 622 | } else { |
| 623 | bus->id = dev->last_bus->id + 1; |
| 624 | dev->last_bus->next_bus = bus; |
| 625 | } |
| 626 | |
| 627 | dev->last_bus = bus; |
| 628 | } |
| 629 | |
| 630 | /* |
| 631 | * Allocate a new device under the given parent. This function allocates a new |
| 632 | * device structure under the provided parent bus and allocates a bus structure |
| 633 | * under the newly allocated device. |
| 634 | */ |
| 635 | static struct device *alloc_dev(struct bus *parent) |
| 636 | { |
| 637 | struct device *dev = S_ALLOC(sizeof(*dev)); |
| 638 | |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 639 | dev->parent = parent; |
| 640 | dev->subsystem_vendor = -1; |
| 641 | dev->subsystem_device = -1; |
| 642 | |
| 643 | alloc_bus(dev); |
| 644 | |
| 645 | return dev; |
| 646 | } |
| 647 | |
| 648 | /* |
| 649 | * This function scans the children of given bus to see if any device matches |
| 650 | * the new device that is requested. |
| 651 | * |
| 652 | * Returns pointer to the node if found, else NULL. |
| 653 | */ |
| 654 | static struct device *get_dev(struct bus *parent, int path_a, int path_b, |
| 655 | int bustype, struct chip_instance *chip_instance) |
| 656 | { |
| 657 | struct device *child = parent->children; |
| 658 | |
| 659 | while (child) { |
| 660 | if ((child->path_a == path_a) && (child->path_b == path_b) && |
| 661 | (child->bustype == bustype) && |
| 662 | (child->chip_instance == chip_instance)) |
| 663 | return child; |
| 664 | |
| 665 | child = child->sibling; |
| 666 | } |
| 667 | |
| 668 | return NULL; |
| 669 | } |
| 670 | |
Furquan Shaikh | 27efc50 | 2018-06-22 09:19:15 -0700 | [diff] [blame] | 671 | /* |
| 672 | * Add given node as child of the provided parent. If this is the first child of |
| 673 | * the parent, update parent->children pointer as well. |
| 674 | */ |
| 675 | static void set_new_child(struct bus *parent, struct device *child) |
| 676 | { |
| 677 | struct device *c = parent->children; |
| 678 | if (c) { |
| 679 | while (c->sibling) |
| 680 | c = c->sibling; |
| 681 | c->sibling = child; |
| 682 | } else |
| 683 | parent->children = child; |
| 684 | |
| 685 | child->sibling = NULL; |
| 686 | child->parent = parent; |
| 687 | } |
| 688 | |
Nico Huber | 8e1ea52 | 2020-06-03 10:20:07 -0700 | [diff] [blame] | 689 | static const struct device *find_alias(const struct device *const parent, |
| 690 | const char *const alias) |
| 691 | { |
| 692 | if (parent->alias && !strcmp(parent->alias, alias)) |
| 693 | return parent; |
| 694 | |
| 695 | const struct bus *bus; |
| 696 | for (bus = parent->bus; bus; bus = bus->next_bus) { |
| 697 | const struct device *child; |
| 698 | for (child = bus->children; child; child = child->sibling) { |
| 699 | const struct device *const ret = find_alias(child, alias); |
| 700 | if (ret) |
| 701 | return ret; |
| 702 | } |
| 703 | } |
| 704 | |
| 705 | return NULL; |
| 706 | } |
| 707 | |
Duncan Laurie | e335c2e | 2020-07-29 16:28:43 -0700 | [diff] [blame] | 708 | static struct device *new_device_with_path(struct bus *parent, |
| 709 | struct chip_instance *chip_instance, |
| 710 | const int bustype, int path_a, int path_b, |
| 711 | char *alias, int status) |
Martin Roth | bec0753 | 2016-08-05 18:32:18 -0600 | [diff] [blame] | 712 | { |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 713 | struct device *new_d; |
| 714 | |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 715 | /* If device is found under parent, no need to allocate new device. */ |
| 716 | new_d = get_dev(parent, path_a, path_b, bustype, chip_instance); |
| 717 | if (new_d) { |
| 718 | alloc_bus(new_d); |
| 719 | return new_d; |
| 720 | } |
| 721 | |
| 722 | new_d = alloc_dev(parent); |
| 723 | |
| 724 | new_d->bustype = bustype; |
| 725 | |
| 726 | new_d->path_a = path_a; |
| 727 | new_d->path_b = path_b; |
Nico Huber | 8e1ea52 | 2020-06-03 10:20:07 -0700 | [diff] [blame] | 728 | new_d->alias = alias; |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 729 | |
Hung-Te Lin | 936dbe1 | 2018-09-10 10:51:26 +0800 | [diff] [blame] | 730 | new_d->enabled = status & 0x01; |
| 731 | new_d->hidden = (status >> 1) & 0x01; |
Ronald G. Minnich | 466ca2c | 2019-10-22 02:02:24 +0000 | [diff] [blame] | 732 | new_d->mandatory = (status >> 2) & 0x01; |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 733 | new_d->chip_instance = chip_instance; |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 734 | |
Furquan Shaikh | 27efc50 | 2018-06-22 09:19:15 -0700 | [diff] [blame] | 735 | set_new_child(parent, new_d); |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 736 | |
Furquan Shaikh | a9b6429 | 2018-05-31 07:52:00 -0700 | [diff] [blame] | 737 | switch (bustype) { |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 738 | case PCI: |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 739 | new_d->path = ".type=DEVICE_PATH_PCI,{.pci={ .devfn = PCI_DEVFN(0x%x,%d)}}"; |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 740 | break; |
| 741 | |
| 742 | case PNP: |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 743 | new_d->path = ".type=DEVICE_PATH_PNP,{.pnp={ .port = 0x%x, .device = 0x%x }}"; |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 744 | break; |
| 745 | |
| 746 | case I2C: |
Duncan Laurie | b7ce5fe | 2016-05-07 19:49:37 -0700 | [diff] [blame] | 747 | new_d->path = ".type=DEVICE_PATH_I2C,{.i2c={ .device = 0x%x, .mode_10bit = %d }}"; |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 748 | break; |
| 749 | |
| 750 | case APIC: |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 751 | new_d->path = ".type=DEVICE_PATH_APIC,{.apic={ .apic_id = 0x%x }}"; |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 752 | break; |
| 753 | |
Stefan Reinauer | 0aa37c4 | 2013-02-12 15:20:54 -0800 | [diff] [blame] | 754 | case CPU_CLUSTER: |
| 755 | new_d->path = ".type=DEVICE_PATH_CPU_CLUSTER,{.cpu_cluster={ .cluster = 0x%x }}"; |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 756 | break; |
| 757 | |
Aaron Durbin | ffda804b | 2014-09-03 12:40:15 -0500 | [diff] [blame] | 758 | case CPU: |
| 759 | new_d->path = ".type=DEVICE_PATH_CPU,{.cpu={ .id = 0x%x }}"; |
| 760 | break; |
| 761 | |
Stefan Reinauer | 4aff445 | 2013-02-12 14:17:15 -0800 | [diff] [blame] | 762 | case DOMAIN: |
| 763 | new_d->path = ".type=DEVICE_PATH_DOMAIN,{.domain={ .domain = 0x%x }}"; |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 764 | break; |
| 765 | |
| 766 | case IOAPIC: |
| 767 | new_d->path = ".type=DEVICE_PATH_IOAPIC,{.ioapic={ .ioapic_id = 0x%x }}"; |
| 768 | break; |
Duncan Laurie | 4650f5b | 2016-05-07 20:01:34 -0700 | [diff] [blame] | 769 | |
| 770 | case GENERIC: |
| 771 | new_d->path = ".type=DEVICE_PATH_GENERIC,{.generic={ .id = 0x%x, .subid = 0x%x }}"; |
| 772 | break; |
Furquan Shaikh | e670029 | 2017-02-11 00:50:38 -0800 | [diff] [blame] | 773 | |
| 774 | case SPI: |
| 775 | new_d->path = ".type=DEVICE_PATH_SPI,{.spi={ .cs = 0x%x }}"; |
| 776 | break; |
| 777 | |
Duncan Laurie | bae9f85 | 2018-05-07 14:18:13 -0700 | [diff] [blame] | 778 | case USB: |
| 779 | new_d->path = ".type=DEVICE_PATH_USB,{.usb={ .port_type = %d, .port_id = %d }}"; |
| 780 | break; |
| 781 | |
Justin TerAvest | ca2ed9f | 2018-01-17 16:36:30 -0800 | [diff] [blame] | 782 | case MMIO: |
| 783 | new_d->path = ".type=DEVICE_PATH_MMIO,{.mmio={ .addr = 0x%x }}"; |
| 784 | break; |
Raul E Rangel | 3f3f53c | 2020-05-06 11:47:04 -0600 | [diff] [blame] | 785 | |
| 786 | case ESPI: |
| 787 | new_d->path = ".type=DEVICE_PATH_ESPI,{.espi={ .addr = 0x%x }}"; |
| 788 | break; |
| 789 | |
| 790 | case LPC: |
| 791 | new_d->path = ".type=DEVICE_PATH_LPC,{.lpc={ .addr = 0x%x }}"; |
| 792 | break; |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 793 | } |
Justin TerAvest | ca2ed9f | 2018-01-17 16:36:30 -0800 | [diff] [blame] | 794 | |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 795 | return new_d; |
| 796 | } |
| 797 | |
Duncan Laurie | e335c2e | 2020-07-29 16:28:43 -0700 | [diff] [blame] | 798 | struct device *new_device_reference(struct bus *parent, |
| 799 | struct chip_instance *chip_instance, |
| 800 | const char *reference, int status) |
| 801 | { |
| 802 | const struct device *dev = find_alias(&base_root_dev, reference); |
| 803 | |
| 804 | if (!dev) { |
| 805 | printf("ERROR: Unable to find device reference %s\n", reference); |
| 806 | exit(1); |
| 807 | } |
| 808 | |
| 809 | return new_device_with_path(parent, chip_instance, dev->bustype, dev->path_a, |
| 810 | dev->path_b, NULL, status); |
| 811 | } |
| 812 | |
| 813 | struct device *new_device_raw(struct bus *parent, |
| 814 | struct chip_instance *chip_instance, |
| 815 | const int bustype, const char *devnum, |
| 816 | char *alias, int status) |
| 817 | { |
| 818 | char *tmp; |
| 819 | int path_a; |
| 820 | int path_b = 0; |
| 821 | |
| 822 | /* Check for alias name conflicts. */ |
| 823 | if (alias && find_alias(root_parent->dev, alias)) { |
| 824 | printf("ERROR: Alias already exists: %s\n", alias); |
| 825 | exit(1); |
| 826 | } |
| 827 | |
| 828 | path_a = strtol(devnum, &tmp, 16); |
| 829 | if (*tmp == '.') { |
| 830 | tmp++; |
| 831 | path_b = strtol(tmp, NULL, 16); |
| 832 | } |
| 833 | |
| 834 | return new_device_with_path(parent, chip_instance, bustype, path_a, path_b, alias, |
| 835 | status); |
| 836 | } |
| 837 | |
Furquan Shaikh | 27efc50 | 2018-06-22 09:19:15 -0700 | [diff] [blame] | 838 | static void new_resource(struct device *dev, int type, int index, int base) |
Martin Roth | bec0753 | 2016-08-05 18:32:18 -0600 | [diff] [blame] | 839 | { |
Furquan Shaikh | 369e1f0 | 2018-05-31 09:48:51 -0700 | [diff] [blame] | 840 | struct resource *r = S_ALLOC(sizeof(struct resource)); |
| 841 | |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 842 | r->type = type; |
| 843 | r->index = index; |
| 844 | r->base = base; |
Patrick Georgi | 68befd5 | 2010-05-05 12:05:25 +0000 | [diff] [blame] | 845 | if (dev->res) { |
| 846 | struct resource *head = dev->res; |
Martin Roth | bec0753 | 2016-08-05 18:32:18 -0600 | [diff] [blame] | 847 | while (head->next) |
| 848 | head = head->next; |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 849 | head->next = r; |
| 850 | } else { |
Patrick Georgi | 68befd5 | 2010-05-05 12:05:25 +0000 | [diff] [blame] | 851 | dev->res = r; |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 852 | } |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 853 | } |
| 854 | |
Furquan Shaikh | 27efc50 | 2018-06-22 09:19:15 -0700 | [diff] [blame] | 855 | void add_resource(struct bus *bus, int type, int index, int base) |
| 856 | { |
| 857 | new_resource(bus->dev, type, index, base); |
| 858 | } |
| 859 | |
Nico Huber | d09459f | 2020-05-26 22:13:09 +0200 | [diff] [blame] | 860 | static void add_reg(struct reg **const head, char *const name, char *const val) |
Martin Roth | bec0753 | 2016-08-05 18:32:18 -0600 | [diff] [blame] | 861 | { |
Nico Huber | d09459f | 2020-05-26 22:13:09 +0200 | [diff] [blame] | 862 | struct reg *const r = S_ALLOC(sizeof(struct reg)); |
| 863 | struct reg *prev = NULL; |
| 864 | struct reg *cur; |
Furquan Shaikh | 369e1f0 | 2018-05-31 09:48:51 -0700 | [diff] [blame] | 865 | |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 866 | r->key = name; |
| 867 | r->value = val; |
Nico Huber | d09459f | 2020-05-26 22:13:09 +0200 | [diff] [blame] | 868 | |
| 869 | for (cur = *head; cur != NULL; prev = cur, cur = cur->next) { |
| 870 | const int sort = strcmp(r->key, cur->key); |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 871 | if (sort == 0) { |
| 872 | printf("ERROR: duplicate 'register' key.\n"); |
| 873 | exit(1); |
| 874 | } |
Nico Huber | d09459f | 2020-05-26 22:13:09 +0200 | [diff] [blame] | 875 | if (sort < 0) |
| 876 | break; |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 877 | } |
Nico Huber | d09459f | 2020-05-26 22:13:09 +0200 | [diff] [blame] | 878 | r->next = cur; |
| 879 | if (prev) |
| 880 | prev->next = r; |
| 881 | else |
| 882 | *head = r; |
| 883 | } |
| 884 | |
| 885 | void add_register(struct chip_instance *chip_instance, char *name, char *val) |
| 886 | { |
| 887 | add_reg(&chip_instance->reg, name, val); |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 888 | } |
| 889 | |
Nico Huber | 8e1ea52 | 2020-06-03 10:20:07 -0700 | [diff] [blame] | 890 | void add_reference(struct chip_instance *const chip_instance, |
| 891 | char *const name, char *const alias) |
| 892 | { |
| 893 | add_reg(&chip_instance->ref, name, alias); |
| 894 | } |
| 895 | |
| 896 | static void set_reference(struct chip_instance *const chip_instance, |
| 897 | char *const name, char *const alias) |
| 898 | { |
| 899 | const struct device *const dev = find_alias(&base_root_dev, alias); |
| 900 | if (!dev) { |
| 901 | printf("ERROR: Cannot find device alias '%s'.\n", alias); |
| 902 | exit(1); |
| 903 | } |
| 904 | |
| 905 | char *const ref_name = S_ALLOC(strlen(dev->name) + 2); |
| 906 | sprintf(ref_name, "&%s", dev->name); |
| 907 | add_register(chip_instance, name, ref_name); |
| 908 | } |
| 909 | |
| 910 | static void update_references(FILE *file, FILE *head, struct device *dev, |
| 911 | struct device *next) |
| 912 | { |
| 913 | struct reg *ref; |
| 914 | |
| 915 | for (ref = dev->chip_instance->ref; ref; ref = ref->next) |
| 916 | set_reference(dev->chip_instance, ref->key, ref->value); |
| 917 | } |
| 918 | |
Patrick Rudolph | ac24d3c | 2019-04-12 14:42:17 +0200 | [diff] [blame] | 919 | void add_slot_desc(struct bus *bus, char *type, char *length, char *designation, |
| 920 | char *data_width) |
| 921 | { |
| 922 | struct device *dev = bus->dev; |
| 923 | |
| 924 | if (dev->bustype != PCI && dev->bustype != DOMAIN) { |
| 925 | printf("ERROR: 'slot_type' only allowed for PCI devices\n"); |
| 926 | exit(1); |
| 927 | } |
| 928 | |
| 929 | dev->smbios_slot_type = type; |
| 930 | dev->smbios_slot_length = length; |
| 931 | dev->smbios_slot_data_width = data_width; |
| 932 | dev->smbios_slot_designation = designation; |
| 933 | } |
| 934 | |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 935 | void add_pci_subsystem_ids(struct bus *bus, int vendor, int device, |
Martin Roth | bec0753 | 2016-08-05 18:32:18 -0600 | [diff] [blame] | 936 | int inherit) |
Sven Schnelle | 270a908 | 2011-03-01 19:58:15 +0000 | [diff] [blame] | 937 | { |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 938 | struct device *dev = bus->dev; |
| 939 | |
Stefan Reinauer | 4aff445 | 2013-02-12 14:17:15 -0800 | [diff] [blame] | 940 | if (dev->bustype != PCI && dev->bustype != DOMAIN) { |
Sven Schnelle | 270a908 | 2011-03-01 19:58:15 +0000 | [diff] [blame] | 941 | printf("ERROR: 'subsystem' only allowed for PCI devices\n"); |
| 942 | exit(1); |
| 943 | } |
| 944 | |
| 945 | dev->subsystem_vendor = vendor; |
| 946 | dev->subsystem_device = device; |
| 947 | dev->inherit_subsystem = inherit; |
| 948 | } |
| 949 | |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 950 | void add_ioapic_info(struct bus *bus, int apicid, const char *_srcpin, |
Martin Roth | bec0753 | 2016-08-05 18:32:18 -0600 | [diff] [blame] | 951 | int irqpin) |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 952 | { |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 953 | int srcpin; |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 954 | struct device *dev = bus->dev; |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 955 | |
Martin Roth | bec0753 | 2016-08-05 18:32:18 -0600 | [diff] [blame] | 956 | if (!_srcpin || strlen(_srcpin) < 4 || strncasecmp(_srcpin, "INT", 3) || |
| 957 | _srcpin[3] < 'A' || _srcpin[3] > 'D') { |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 958 | printf("ERROR: malformed ioapic_irq args: %s\n", _srcpin); |
| 959 | exit(1); |
| 960 | } |
| 961 | |
| 962 | srcpin = _srcpin[3] - 'A'; |
| 963 | |
Stefan Reinauer | 4aff445 | 2013-02-12 14:17:15 -0800 | [diff] [blame] | 964 | if (dev->bustype != PCI && dev->bustype != DOMAIN) { |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 965 | printf("ERROR: ioapic config only allowed for PCI devices\n"); |
| 966 | exit(1); |
| 967 | } |
| 968 | |
| 969 | if (srcpin > 3) { |
Patrick Georgi | 116327e | 2012-07-20 12:47:06 +0200 | [diff] [blame] | 970 | printf("ERROR: srcpin '%d' invalid\n", srcpin); |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 971 | exit(1); |
| 972 | } |
| 973 | dev->pci_irq_info[srcpin].ioapic_irq_pin = irqpin; |
| 974 | dev->pci_irq_info[srcpin].ioapic_dst_id = apicid; |
| 975 | } |
| 976 | |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 977 | static int dev_has_children(struct device *dev) |
Martin Roth | bec0753 | 2016-08-05 18:32:18 -0600 | [diff] [blame] | 978 | { |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 979 | struct bus *bus = dev->bus; |
| 980 | |
| 981 | while (bus) { |
| 982 | if (bus->children) |
| 983 | return 1; |
| 984 | bus = bus->next_bus; |
| 985 | } |
| 986 | |
| 987 | return 0; |
| 988 | } |
| 989 | |
Nico Huber | 17e9bcb | 2019-09-20 12:05:51 +0200 | [diff] [blame] | 990 | static void pass0(FILE *fil, FILE *head, struct device *ptr, struct device *next) |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 991 | { |
Furquan Shaikh | 4ebe953 | 2020-05-02 15:34:42 -0700 | [diff] [blame] | 992 | static int dev_id; |
| 993 | |
Furquan Shaikh | de39fc7 | 2018-06-11 04:26:45 -0700 | [diff] [blame] | 994 | if (ptr == &base_root_dev) { |
Kyösti Mälkki | 5ccce7c | 2019-03-15 10:04:11 +0200 | [diff] [blame] | 995 | fprintf(fil, "STORAGE struct bus %s_links[];\n", |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 996 | ptr->name); |
| 997 | return; |
| 998 | } |
| 999 | |
Furquan Shaikh | 4ebe953 | 2020-05-02 15:34:42 -0700 | [diff] [blame] | 1000 | char *name = S_ALLOC(10); |
| 1001 | sprintf(name, "_dev%d", dev_id++); |
| 1002 | ptr->name = name; |
| 1003 | |
Kyösti Mälkki | 5ccce7c | 2019-03-15 10:04:11 +0200 | [diff] [blame] | 1004 | fprintf(fil, "STORAGE struct device %s;\n", ptr->name); |
Furquan Shaikh | 4ca3a8a | 2018-06-07 23:36:45 -0700 | [diff] [blame] | 1005 | if (ptr->res) |
Kyösti Mälkki | 5ccce7c | 2019-03-15 10:04:11 +0200 | [diff] [blame] | 1006 | fprintf(fil, "STORAGE struct resource %s_res[];\n", |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 1007 | ptr->name); |
| 1008 | if (dev_has_children(ptr)) |
Kyösti Mälkki | 5ccce7c | 2019-03-15 10:04:11 +0200 | [diff] [blame] | 1009 | fprintf(fil, "STORAGE struct bus %s_links[];\n", |
Martin Roth | bec0753 | 2016-08-05 18:32:18 -0600 | [diff] [blame] | 1010 | ptr->name); |
Stefan Reinauer | 57879c9 | 2012-07-31 16:47:25 -0700 | [diff] [blame] | 1011 | |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 1012 | if (next) |
| 1013 | return; |
| 1014 | |
| 1015 | fprintf(fil, |
| 1016 | "DEVTREE_CONST struct device * DEVTREE_CONST last_dev = &%s;\n", |
| 1017 | ptr->name); |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 1018 | } |
| 1019 | |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 1020 | static void emit_resources(FILE *fil, struct device *ptr) |
| 1021 | { |
Furquan Shaikh | 4ca3a8a | 2018-06-07 23:36:45 -0700 | [diff] [blame] | 1022 | if (ptr->res == NULL) |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 1023 | return; |
| 1024 | |
| 1025 | int i = 1; |
Kyösti Mälkki | 5ccce7c | 2019-03-15 10:04:11 +0200 | [diff] [blame] | 1026 | fprintf(fil, "STORAGE struct resource %s_res[] = {\n", ptr->name); |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 1027 | struct resource *r = ptr->res; |
| 1028 | while (r) { |
| 1029 | fprintf(fil, |
| 1030 | "\t\t{ .flags=IORESOURCE_FIXED | IORESOURCE_ASSIGNED | IORESOURCE_"); |
| 1031 | if (r->type == IRQ) |
| 1032 | fprintf(fil, "IRQ"); |
| 1033 | if (r->type == DRQ) |
| 1034 | fprintf(fil, "DRQ"); |
| 1035 | if (r->type == IO) |
| 1036 | fprintf(fil, "IO"); |
| 1037 | fprintf(fil, ", .index=0x%x, .base=0x%x,", r->index, |
| 1038 | r->base); |
| 1039 | if (r->next) |
| 1040 | fprintf(fil, ".next=&%s_res[%d]},\n", ptr->name, |
| 1041 | i++); |
| 1042 | else |
| 1043 | fprintf(fil, ".next=NULL },\n"); |
| 1044 | r = r->next; |
| 1045 | } |
| 1046 | |
| 1047 | fprintf(fil, "\t };\n"); |
| 1048 | } |
| 1049 | |
| 1050 | static void emit_bus(FILE *fil, struct bus *bus) |
| 1051 | { |
| 1052 | fprintf(fil, "\t\t[%d] = {\n", bus->id); |
| 1053 | fprintf(fil, "\t\t\t.link_num = %d,\n", bus->id); |
| 1054 | fprintf(fil, "\t\t\t.dev = &%s,\n", bus->dev->name); |
| 1055 | if (bus->children) |
| 1056 | fprintf(fil, "\t\t\t.children = &%s,\n", bus->children->name); |
| 1057 | |
| 1058 | if (bus->next_bus) |
| 1059 | fprintf(fil, "\t\t\t.next=&%s_links[%d],\n", bus->dev->name, |
| 1060 | bus->id + 1); |
| 1061 | else |
| 1062 | fprintf(fil, "\t\t\t.next = NULL,\n"); |
| 1063 | fprintf(fil, "\t\t},\n"); |
| 1064 | } |
| 1065 | |
| 1066 | static void emit_dev_links(FILE *fil, struct device *ptr) |
| 1067 | { |
Kyösti Mälkki | 5ccce7c | 2019-03-15 10:04:11 +0200 | [diff] [blame] | 1068 | fprintf(fil, "STORAGE struct bus %s_links[] = {\n", |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 1069 | ptr->name); |
| 1070 | |
| 1071 | struct bus *bus = ptr->bus; |
| 1072 | |
| 1073 | while (bus) { |
| 1074 | emit_bus(fil, bus); |
| 1075 | bus = bus->next_bus; |
| 1076 | } |
| 1077 | |
| 1078 | fprintf(fil, "\t};\n"); |
| 1079 | } |
| 1080 | |
Nico Huber | 17e9bcb | 2019-09-20 12:05:51 +0200 | [diff] [blame] | 1081 | static void pass1(FILE *fil, FILE *head, struct device *ptr, struct device *next) |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 1082 | { |
| 1083 | int pin; |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 1084 | struct chip_instance *chip_ins = ptr->chip_instance; |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 1085 | int has_children = dev_has_children(ptr); |
Furquan Shaikh | 79e8412 | 2018-05-30 15:09:09 -0700 | [diff] [blame] | 1086 | |
Furquan Shaikh | bbade24 | 2020-05-02 16:05:29 -0700 | [diff] [blame] | 1087 | /* |
| 1088 | * If the chip instance of device has base_chip_instance pointer set, then follow that |
| 1089 | * to update the chip instance for current device. |
| 1090 | */ |
| 1091 | if (chip_ins->base_chip_instance) |
| 1092 | chip_ins = chip_ins->base_chip_instance; |
| 1093 | |
Duncan Laurie | 47b7b34 | 2020-05-15 15:39:08 -0700 | [diff] [blame] | 1094 | /* Emit probe structures. */ |
| 1095 | if (ptr->probe && (emit_fw_config_probe(fil, ptr) < 0)) { |
Tim Wawrzynczak | ba4a490 | 2020-09-23 15:36:30 -0600 | [diff] [blame^] | 1096 | if (head) |
| 1097 | fclose(head); |
Duncan Laurie | 47b7b34 | 2020-05-15 15:39:08 -0700 | [diff] [blame] | 1098 | fclose(fil); |
| 1099 | exit(1); |
| 1100 | } |
| 1101 | |
Kyösti Mälkki | 5ccce7c | 2019-03-15 10:04:11 +0200 | [diff] [blame] | 1102 | if (ptr == &base_root_dev) |
| 1103 | fprintf(fil, "DEVTREE_CONST struct device %s = {\n", ptr->name); |
| 1104 | else |
| 1105 | fprintf(fil, "STORAGE struct device %s = {\n", ptr->name); |
| 1106 | |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 1107 | fprintf(fil, "#if !DEVTREE_EARLY\n"); |
Furquan Shaikh | 50ddc0b | 2018-06-23 00:59:31 -0700 | [diff] [blame] | 1108 | |
| 1109 | /* |
| 1110 | * ops field is set to default_dev_ops_root only for the root |
| 1111 | * device. For all other devices, it is set by the driver at runtime. |
| 1112 | */ |
| 1113 | if (ptr == &base_root_dev) |
| 1114 | fprintf(fil, "\t.ops = &default_dev_ops_root,\n"); |
| 1115 | else |
| 1116 | fprintf(fil, "\t.ops = NULL,\n"); |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 1117 | fprintf(fil, "#endif\n"); |
| 1118 | fprintf(fil, "\t.bus = &%s_links[%d],\n", ptr->parent->dev->name, |
| 1119 | ptr->parent->id); |
| 1120 | fprintf(fil, "\t.path = {"); |
| 1121 | fprintf(fil, ptr->path, ptr->path_a, ptr->path_b); |
| 1122 | fprintf(fil, "},\n"); |
| 1123 | fprintf(fil, "\t.enabled = %d,\n", ptr->enabled); |
Hung-Te Lin | 936dbe1 | 2018-09-10 10:51:26 +0800 | [diff] [blame] | 1124 | fprintf(fil, "\t.hidden = %d,\n", ptr->hidden); |
Ronald G. Minnich | 466ca2c | 2019-10-22 02:02:24 +0000 | [diff] [blame] | 1125 | fprintf(fil, "\t.mandatory = %d,\n", ptr->mandatory); |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 1126 | fprintf(fil, "\t.on_mainboard = 1,\n"); |
| 1127 | if (ptr->subsystem_vendor > 0) |
| 1128 | fprintf(fil, "\t.subsystem_vendor = 0x%04x,\n", |
| 1129 | ptr->subsystem_vendor); |
Sven Schnelle | 270a908 | 2011-03-01 19:58:15 +0000 | [diff] [blame] | 1130 | |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 1131 | if (ptr->subsystem_device > 0) |
| 1132 | fprintf(fil, "\t.subsystem_device = 0x%04x,\n", |
| 1133 | ptr->subsystem_device); |
| 1134 | |
Furquan Shaikh | 4ca3a8a | 2018-06-07 23:36:45 -0700 | [diff] [blame] | 1135 | if (ptr->res) { |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 1136 | fprintf(fil, "\t.resource_list = &%s_res[0],\n", |
Martin Roth | bec0753 | 2016-08-05 18:32:18 -0600 | [diff] [blame] | 1137 | ptr->name); |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 1138 | } |
| 1139 | if (has_children) |
| 1140 | fprintf(fil, "\t.link_list = &%s_links[0],\n", |
| 1141 | ptr->name); |
| 1142 | else |
| 1143 | fprintf(fil, "\t.link_list = NULL,\n"); |
| 1144 | if (ptr->sibling) |
| 1145 | fprintf(fil, "\t.sibling = &%s,\n", ptr->sibling->name); |
Aaron Durbin | d47afe9 | 2020-03-26 12:29:35 -0600 | [diff] [blame] | 1146 | else |
| 1147 | fprintf(fil, "\t.sibling = NULL,\n"); |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 1148 | fprintf(fil, "#if !DEVTREE_EARLY\n"); |
Duncan Laurie | 47b7b34 | 2020-05-15 15:39:08 -0700 | [diff] [blame] | 1149 | if (ptr->probe) |
| 1150 | fprintf(fil, "\t.probe_list = %s_probe_list,\n", ptr->name); |
Kyösti Mälkki | 1557a67 | 2019-06-30 10:51:31 +0300 | [diff] [blame] | 1151 | for (pin = 0; pin < 4; pin++) { |
| 1152 | if (ptr->pci_irq_info[pin].ioapic_irq_pin > 0) |
| 1153 | fprintf(fil, |
| 1154 | "\t.pci_irq_info[%d].ioapic_irq_pin = %d,\n", |
| 1155 | pin, ptr->pci_irq_info[pin].ioapic_irq_pin); |
| 1156 | |
| 1157 | if (ptr->pci_irq_info[pin].ioapic_dst_id > 0) |
| 1158 | fprintf(fil, |
| 1159 | "\t.pci_irq_info[%d].ioapic_dst_id = %d,\n", |
| 1160 | pin, ptr->pci_irq_info[pin].ioapic_dst_id); |
| 1161 | } |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 1162 | fprintf(fil, "\t.chip_ops = &%s_ops,\n", |
| 1163 | chip_ins->chip->name_underscore); |
| 1164 | if (chip_ins == &mainboard_instance) |
| 1165 | fprintf(fil, "\t.name = mainboard_name,\n"); |
| 1166 | fprintf(fil, "#endif\n"); |
| 1167 | if (chip_ins->chip->chiph_exists) |
| 1168 | fprintf(fil, "\t.chip_info = &%s_info_%d,\n", |
| 1169 | chip_ins->chip->name_underscore, chip_ins->id); |
| 1170 | if (next) |
Patrick Rudolph | ac24d3c | 2019-04-12 14:42:17 +0200 | [diff] [blame] | 1171 | fprintf(fil, "\t.next=&%s,\n", next->name); |
| 1172 | if (ptr->smbios_slot_type || ptr->smbios_slot_data_width || |
| 1173 | ptr->smbios_slot_designation || ptr->smbios_slot_length) { |
| 1174 | fprintf(fil, "#if !DEVTREE_EARLY\n"); |
| 1175 | fprintf(fil, "#if CONFIG(GENERATE_SMBIOS_TABLES)\n"); |
| 1176 | } |
| 1177 | /* SMBIOS types start at 1, if zero it hasn't been set */ |
| 1178 | if (ptr->smbios_slot_type) |
| 1179 | fprintf(fil, "\t.smbios_slot_type = %s,\n", |
| 1180 | ptr->smbios_slot_type); |
| 1181 | if (ptr->smbios_slot_data_width) |
| 1182 | fprintf(fil, "\t.smbios_slot_data_width = %s,\n", |
| 1183 | ptr->smbios_slot_data_width); |
| 1184 | if (ptr->smbios_slot_designation) |
| 1185 | fprintf(fil, "\t.smbios_slot_designation = \"%s\",\n", |
| 1186 | ptr->smbios_slot_designation); |
| 1187 | if (ptr->smbios_slot_length) |
| 1188 | fprintf(fil, "\t.smbios_slot_length = %s,\n", |
| 1189 | ptr->smbios_slot_length); |
| 1190 | if (ptr->smbios_slot_type || ptr->smbios_slot_data_width || |
| 1191 | ptr->smbios_slot_designation || ptr->smbios_slot_length) { |
| 1192 | fprintf(fil, "#endif\n"); |
| 1193 | fprintf(fil, "#endif\n"); |
| 1194 | } |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 1195 | fprintf(fil, "};\n"); |
| 1196 | |
| 1197 | emit_resources(fil, ptr); |
| 1198 | |
| 1199 | if (has_children) |
| 1200 | emit_dev_links(fil, ptr); |
| 1201 | } |
| 1202 | |
Nico Huber | 17e9bcb | 2019-09-20 12:05:51 +0200 | [diff] [blame] | 1203 | static void expose_device_names(FILE *fil, FILE *head, struct device *ptr, struct device *next) |
Kyösti Mälkki | 5e2a2cd | 2019-03-15 17:44:23 +0200 | [diff] [blame] | 1204 | { |
| 1205 | /* Only devices on root bus here. */ |
Nico Huber | 17e9bcb | 2019-09-20 12:05:51 +0200 | [diff] [blame] | 1206 | if (ptr->bustype == PCI && ptr->parent->dev->bustype == DOMAIN) { |
| 1207 | fprintf(head, "extern DEVTREE_CONST struct device *DEVTREE_CONST __pci_0_%02x_%d;\n", |
| 1208 | ptr->path_a, ptr->path_b); |
Kyösti Mälkki | 5e2a2cd | 2019-03-15 17:44:23 +0200 | [diff] [blame] | 1209 | fprintf(fil, "DEVTREE_CONST struct device *DEVTREE_CONST __pci_0_%02x_%d = &%s;\n", |
| 1210 | ptr->path_a, ptr->path_b, ptr->name); |
Nico Huber | 17e9bcb | 2019-09-20 12:05:51 +0200 | [diff] [blame] | 1211 | } |
Kyösti Mälkki | 5e2a2cd | 2019-03-15 17:44:23 +0200 | [diff] [blame] | 1212 | |
Nico Huber | 17e9bcb | 2019-09-20 12:05:51 +0200 | [diff] [blame] | 1213 | if (ptr->bustype == PNP) { |
| 1214 | fprintf(head, "extern DEVTREE_CONST struct device *DEVTREE_CONST __pnp_%04x_%02x;\n", |
| 1215 | ptr->path_a, ptr->path_b); |
Kyösti Mälkki | 5e2a2cd | 2019-03-15 17:44:23 +0200 | [diff] [blame] | 1216 | fprintf(fil, "DEVTREE_CONST struct device *DEVTREE_CONST __pnp_%04x_%02x = &%s;\n", |
| 1217 | ptr->path_a, ptr->path_b, ptr->name); |
Nico Huber | 17e9bcb | 2019-09-20 12:05:51 +0200 | [diff] [blame] | 1218 | } |
Kyösti Mälkki | 5e2a2cd | 2019-03-15 17:44:23 +0200 | [diff] [blame] | 1219 | } |
| 1220 | |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 1221 | static void add_siblings_to_queue(struct queue_entry **bfs_q_head, |
| 1222 | struct device *d) |
| 1223 | { |
| 1224 | while (d) { |
| 1225 | enqueue_tail(bfs_q_head, d); |
| 1226 | d = d->sibling; |
| 1227 | } |
| 1228 | } |
| 1229 | |
| 1230 | static void add_children_to_queue(struct queue_entry **bfs_q_head, |
| 1231 | struct device *d) |
| 1232 | { |
| 1233 | struct bus *bus = d->bus; |
| 1234 | |
| 1235 | while (bus) { |
| 1236 | if (bus->children) |
| 1237 | add_siblings_to_queue(bfs_q_head, bus->children); |
| 1238 | bus = bus->next_bus; |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 1239 | } |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 1240 | } |
| 1241 | |
Nico Huber | 17e9bcb | 2019-09-20 12:05:51 +0200 | [diff] [blame] | 1242 | static void walk_device_tree(FILE *fil, FILE *head, struct device *ptr, |
| 1243 | void (*func)(FILE *, FILE *, struct device *, |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 1244 | struct device *)) |
Martin Roth | bec0753 | 2016-08-05 18:32:18 -0600 | [diff] [blame] | 1245 | { |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 1246 | struct queue_entry *bfs_q_head = NULL; |
| 1247 | |
| 1248 | enqueue_tail(&bfs_q_head, ptr); |
| 1249 | |
| 1250 | while ((ptr = dequeue_head(&bfs_q_head))) { |
| 1251 | add_children_to_queue(&bfs_q_head, ptr); |
Nico Huber | 17e9bcb | 2019-09-20 12:05:51 +0200 | [diff] [blame] | 1252 | func(fil, head, ptr, peek_queue_head(bfs_q_head)); |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 1253 | } |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 1254 | } |
| 1255 | |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 1256 | static void emit_chip_headers(FILE *fil, struct chip *chip) |
Furquan Shaikh | a0cc5a6 | 2018-05-30 23:46:16 -0700 | [diff] [blame] | 1257 | { |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 1258 | struct chip *tmp = chip; |
Furquan Shaikh | a0cc5a6 | 2018-05-30 23:46:16 -0700 | [diff] [blame] | 1259 | |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 1260 | while (chip) { |
| 1261 | if (chip->chiph_exists) |
| 1262 | fprintf(fil, "#include \"%s/chip.h\"\n", chip->name); |
| 1263 | chip = chip->next; |
Furquan Shaikh | a0cc5a6 | 2018-05-30 23:46:16 -0700 | [diff] [blame] | 1264 | } |
| 1265 | fprintf(fil, "\n#if !DEVTREE_EARLY\n"); |
| 1266 | fprintf(fil, |
| 1267 | "__attribute__((weak)) struct chip_operations mainboard_ops = {};\n"); |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 1268 | |
| 1269 | chip = tmp; |
| 1270 | while (chip) { |
Kyösti Mälkki | b2a10f8 | 2019-08-17 06:28:40 +0300 | [diff] [blame] | 1271 | /* A lot of cpus do not define chip_operations at all, and the ones |
| 1272 | that do only initialise .name. */ |
| 1273 | if (strstr(chip->name_underscore, "cpu_") == chip->name_underscore) { |
| 1274 | fprintf(fil, |
| 1275 | "__attribute__((weak)) struct chip_operations %s_ops = {};\n", |
| 1276 | chip->name_underscore); |
| 1277 | } else { |
| 1278 | fprintf(fil, "extern struct chip_operations %s_ops;\n", |
| 1279 | chip->name_underscore); |
| 1280 | } |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 1281 | chip = chip->next; |
Furquan Shaikh | a0cc5a6 | 2018-05-30 23:46:16 -0700 | [diff] [blame] | 1282 | } |
| 1283 | fprintf(fil, "#endif\n"); |
| 1284 | } |
| 1285 | |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 1286 | static void emit_chip_instance(FILE *fil, struct chip_instance *instance) |
| 1287 | { |
Kyösti Mälkki | 5ccce7c | 2019-03-15 10:04:11 +0200 | [diff] [blame] | 1288 | fprintf(fil, "STORAGE struct %s_config %s_info_%d = {", |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 1289 | instance->chip->name_underscore, |
| 1290 | instance->chip->name_underscore, |
| 1291 | instance->id); |
| 1292 | |
| 1293 | if (instance->reg) { |
| 1294 | fprintf(fil, "\n"); |
| 1295 | struct reg *r = instance->reg; |
| 1296 | while (r) { |
| 1297 | fprintf(fil, "\t.%s = %s,\n", r->key, r->value); |
| 1298 | r = r->next; |
| 1299 | } |
| 1300 | } |
| 1301 | fprintf(fil, "};\n\n"); |
| 1302 | } |
| 1303 | |
Nico Huber | 8e1ea52 | 2020-06-03 10:20:07 -0700 | [diff] [blame] | 1304 | static void emit_chip_configs(FILE *fil) |
Furquan Shaikh | 79e8412 | 2018-05-30 15:09:09 -0700 | [diff] [blame] | 1305 | { |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 1306 | struct chip *chip = chip_header.next; |
| 1307 | struct chip_instance *instance; |
Furquan Shaikh | 9f681d2 | 2020-05-02 15:51:02 -0700 | [diff] [blame] | 1308 | int chip_id; |
Furquan Shaikh | 79e8412 | 2018-05-30 15:09:09 -0700 | [diff] [blame] | 1309 | |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 1310 | for (; chip; chip = chip->next) { |
Furquan Shaikh | 79e8412 | 2018-05-30 15:09:09 -0700 | [diff] [blame] | 1311 | if (!chip->chiph_exists) |
| 1312 | continue; |
| 1313 | |
Furquan Shaikh | 9f681d2 | 2020-05-02 15:51:02 -0700 | [diff] [blame] | 1314 | chip_id = 1; |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 1315 | instance = chip->instance; |
| 1316 | while (instance) { |
Furquan Shaikh | bbade24 | 2020-05-02 16:05:29 -0700 | [diff] [blame] | 1317 | /* |
| 1318 | * Emit this chip instance only if there is no forwarding pointer to the |
| 1319 | * base tree chip instance. |
| 1320 | */ |
| 1321 | if (instance->base_chip_instance == NULL) { |
| 1322 | instance->id = chip_id++; |
| 1323 | emit_chip_instance(fil, instance); |
| 1324 | } |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 1325 | instance = instance->next; |
Furquan Shaikh | 79e8412 | 2018-05-30 15:09:09 -0700 | [diff] [blame] | 1326 | } |
| 1327 | } |
| 1328 | } |
| 1329 | |
Nico Huber | 17e9bcb | 2019-09-20 12:05:51 +0200 | [diff] [blame] | 1330 | static void inherit_subsystem_ids(FILE *file, FILE *head, struct device *dev, |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 1331 | struct device *next) |
Sven Schnelle | 270a908 | 2011-03-01 19:58:15 +0000 | [diff] [blame] | 1332 | { |
| 1333 | struct device *p; |
Sven Schnelle | 270a908 | 2011-03-01 19:58:15 +0000 | [diff] [blame] | 1334 | |
| 1335 | if (dev->subsystem_vendor != -1 && dev->subsystem_device != -1) { |
| 1336 | /* user already gave us a subsystem vendor/device */ |
| 1337 | return; |
| 1338 | } |
| 1339 | |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 1340 | for (p = dev; p && p->parent->dev != p; p = p->parent->dev) { |
Sven Schnelle | 270a908 | 2011-03-01 19:58:15 +0000 | [diff] [blame] | 1341 | |
Stefan Reinauer | 4aff445 | 2013-02-12 14:17:15 -0800 | [diff] [blame] | 1342 | if (p->bustype != PCI && p->bustype != DOMAIN) |
Sven Schnelle | 270a908 | 2011-03-01 19:58:15 +0000 | [diff] [blame] | 1343 | continue; |
| 1344 | |
| 1345 | if (p->inherit_subsystem) { |
| 1346 | dev->subsystem_vendor = p->subsystem_vendor; |
| 1347 | dev->subsystem_device = p->subsystem_device; |
| 1348 | break; |
| 1349 | } |
| 1350 | } |
| 1351 | } |
| 1352 | |
Kyösti Mälkki | 472d902 | 2011-12-05 20:33:55 +0200 | [diff] [blame] | 1353 | static void usage(void) |
| 1354 | { |
Duncan Laurie | 51c8373 | 2020-06-09 11:20:29 -0700 | [diff] [blame] | 1355 | printf("usage: sconfig <options>\n"); |
| 1356 | printf(" -c | --output_c : Path to output static.c file (required)\n"); |
| 1357 | printf(" -r | --output_h : Path to header static.h file (required)\n"); |
Tim Wawrzynczak | ba4a490 | 2020-09-23 15:36:30 -0600 | [diff] [blame^] | 1358 | printf(" -d | --output_d : Path to header static_devices.h file (required)\n"); |
| 1359 | printf(" -f | --output_f : Path to header static_fw_config.h file (required)\n"); |
Duncan Laurie | 51c8373 | 2020-06-09 11:20:29 -0700 | [diff] [blame] | 1360 | printf(" -m | --mainboard_devtree : Path to mainboard devicetree file (required)\n"); |
| 1361 | printf(" -o | --override_devtree : Path to override devicetree file (optional)\n"); |
Duncan Laurie | e335c2e | 2020-07-29 16:28:43 -0700 | [diff] [blame] | 1362 | printf(" -p | --chipset_devtree : Path to chipset/SOC devicetree file (optional)\n"); |
Tim Wawrzynczak | ba4a490 | 2020-09-23 15:36:30 -0600 | [diff] [blame^] | 1363 | |
Martin Roth | bec0753 | 2016-08-05 18:32:18 -0600 | [diff] [blame] | 1364 | exit(1); |
Kyösti Mälkki | 472d902 | 2011-12-05 20:33:55 +0200 | [diff] [blame] | 1365 | } |
| 1366 | |
Furquan Shaikh | de39fc7 | 2018-06-11 04:26:45 -0700 | [diff] [blame] | 1367 | static void parse_devicetree(const char *file, struct bus *parent) |
Martin Roth | bec0753 | 2016-08-05 18:32:18 -0600 | [diff] [blame] | 1368 | { |
Furquan Shaikh | de39fc7 | 2018-06-11 04:26:45 -0700 | [diff] [blame] | 1369 | FILE *filec = fopen(file, "r"); |
Stefan Reinauer | 7c1f6b8 | 2010-08-16 18:21:56 +0000 | [diff] [blame] | 1370 | if (!filec) { |
Stefan Reinauer | 7c1f6b8 | 2010-08-16 18:21:56 +0000 | [diff] [blame] | 1371 | perror(NULL); |
| 1372 | exit(1); |
| 1373 | } |
| 1374 | |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 1375 | yyrestart(filec); |
| 1376 | |
Furquan Shaikh | de39fc7 | 2018-06-11 04:26:45 -0700 | [diff] [blame] | 1377 | root_parent = parent; |
| 1378 | linenum = 0; |
| 1379 | |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 1380 | yyparse(); |
Stefan Reinauer | 7c1f6b8 | 2010-08-16 18:21:56 +0000 | [diff] [blame] | 1381 | |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 1382 | fclose(filec); |
Furquan Shaikh | de39fc7 | 2018-06-11 04:26:45 -0700 | [diff] [blame] | 1383 | } |
| 1384 | |
Furquan Shaikh | 27efc50 | 2018-06-22 09:19:15 -0700 | [diff] [blame] | 1385 | /* |
| 1386 | * Match device nodes from base and override tree to see if they are the same |
| 1387 | * node. |
| 1388 | */ |
| 1389 | static int device_match(struct device *a, struct device *b) |
| 1390 | { |
| 1391 | return ((a->path_a == b->path_a) && |
| 1392 | (a->path_b == b->path_b) && |
| 1393 | (a->bustype == b->bustype) && |
| 1394 | (a->chip_instance->chip == |
| 1395 | b->chip_instance->chip)); |
| 1396 | } |
| 1397 | |
| 1398 | /* |
Bill XIE | c61d415 | 2019-11-21 18:16:12 +0800 | [diff] [blame] | 1399 | * Match resource nodes from base and override tree to see if they are the same |
| 1400 | * node. |
| 1401 | */ |
| 1402 | static int res_match(struct resource *a, struct resource *b) |
| 1403 | { |
| 1404 | return ((a->type == b->type) && |
| 1405 | (a->index == b->index)); |
| 1406 | } |
| 1407 | |
| 1408 | /* |
Furquan Shaikh | 27efc50 | 2018-06-22 09:19:15 -0700 | [diff] [blame] | 1409 | * Add resource to device. If resource is already present, then update its base |
| 1410 | * and index. If not, then add a new resource to the device. |
| 1411 | */ |
| 1412 | static void update_resource(struct device *dev, struct resource *res) |
| 1413 | { |
| 1414 | struct resource *base_res = dev->res; |
| 1415 | |
| 1416 | while (base_res) { |
Bill XIE | c61d415 | 2019-11-21 18:16:12 +0800 | [diff] [blame] | 1417 | if (res_match(base_res, res)) { |
Furquan Shaikh | 27efc50 | 2018-06-22 09:19:15 -0700 | [diff] [blame] | 1418 | base_res->base = res->base; |
| 1419 | return; |
| 1420 | } |
| 1421 | base_res = base_res->next; |
| 1422 | } |
| 1423 | |
| 1424 | new_resource(dev, res->type, res->index, res->base); |
| 1425 | } |
| 1426 | |
| 1427 | /* |
| 1428 | * Add register to chip instance. If register is already present, then update |
| 1429 | * its value. If not, then add a new register to the chip instance. |
| 1430 | */ |
Nico Huber | 8e1ea52 | 2020-06-03 10:20:07 -0700 | [diff] [blame] | 1431 | static void update_register(struct reg **const head, struct reg *reg) |
Furquan Shaikh | 27efc50 | 2018-06-22 09:19:15 -0700 | [diff] [blame] | 1432 | { |
Nico Huber | 8e1ea52 | 2020-06-03 10:20:07 -0700 | [diff] [blame] | 1433 | struct reg *base_reg = *head; |
Furquan Shaikh | 27efc50 | 2018-06-22 09:19:15 -0700 | [diff] [blame] | 1434 | |
| 1435 | while (base_reg) { |
| 1436 | if (!strcmp(base_reg->key, reg->key)) { |
| 1437 | base_reg->value = reg->value; |
| 1438 | return; |
| 1439 | } |
| 1440 | base_reg = base_reg->next; |
| 1441 | } |
| 1442 | |
Nico Huber | 8e1ea52 | 2020-06-03 10:20:07 -0700 | [diff] [blame] | 1443 | add_reg(head, reg->key, reg->value); |
Furquan Shaikh | 27efc50 | 2018-06-22 09:19:15 -0700 | [diff] [blame] | 1444 | } |
| 1445 | |
| 1446 | static void override_devicetree(struct bus *base_parent, |
| 1447 | struct bus *override_parent); |
| 1448 | |
| 1449 | /* |
| 1450 | * Update the base device properties using the properties of override device. In |
| 1451 | * addition to that, call override_devicetree for all the buses under the |
| 1452 | * override device. |
| 1453 | * |
| 1454 | * Override Rules: |
| 1455 | * +--------------------+--------------------------------------------+ |
| 1456 | * | | | |
| 1457 | * |struct device member| Rule | |
| 1458 | * | | | |
| 1459 | * +-----------------------------------------------------------------+ |
| 1460 | * | | | |
| 1461 | * | id | Unchanged. This is used to generate device | |
| 1462 | * | | structure name in static.c. So, no need to | |
| 1463 | * | | override. | |
| 1464 | * | | | |
| 1465 | * +-----------------------------------------------------------------+ |
| 1466 | * | | | |
| 1467 | * | enabled | Copy enabled state from override device. | |
| 1468 | * | | This allows variants to override device | |
| 1469 | * | | state. | |
| 1470 | * | | | |
| 1471 | * +-----------------------------------------------------------------+ |
| 1472 | * | | | |
| 1473 | * | subsystem_vendor | Copy from override device only if any one | |
| 1474 | * | subsystem_device | of the ids is non-zero. | |
| 1475 | * | | | |
| 1476 | * +-----------------------------------------------------------------+ |
| 1477 | * | | | |
| 1478 | * | inherit_subsystem | Copy from override device only if it is | |
| 1479 | * | | non-zero. This allows variant to only | |
| 1480 | * | | enable inherit flag for a device. | |
| 1481 | * | | | |
| 1482 | * +-----------------------------------------------------------------+ |
| 1483 | * | | | |
| 1484 | * | path | Unchanged since these are same for both | |
| 1485 | * | path_a | base and override device (Used for | |
| 1486 | * | path_b | matching devices). | |
| 1487 | * | | | |
| 1488 | * +-----------------------------------------------------------------+ |
| 1489 | * | | | |
| 1490 | * | bustype | Unchanged since this is same for both base | |
| 1491 | * | | and override device (User for matching | |
| 1492 | * | | devices). | |
| 1493 | * | | | |
| 1494 | * +-----------------------------------------------------------------+ |
| 1495 | * | | | |
| 1496 | * | pci_irq_info | Unchanged. | |
| 1497 | * | | | |
| 1498 | * +-----------------------------------------------------------------+ |
| 1499 | * | | | |
| 1500 | * | parent | Unchanged. This is meaningful only within | |
| 1501 | * | sibling | the parse tree, hence not being copied. | |
| 1502 | * | | | |
| 1503 | * +-----------------------------------------------------------------+ |
| 1504 | * | | | |
| 1505 | * | res | Each resource that is present in override | |
| 1506 | * | | device is copied over to base device: | |
Bill XIE | c61d415 | 2019-11-21 18:16:12 +0800 | [diff] [blame] | 1507 | * | | 1. If resource of same type and index is | |
| 1508 | * | | present in base device, then base of | |
| 1509 | * | | the resource is copied. | |
Furquan Shaikh | 27efc50 | 2018-06-22 09:19:15 -0700 | [diff] [blame] | 1510 | * | | 2. If not, then a new resource is allocated| |
| 1511 | * | | under the base device using type, index | |
| 1512 | * | | and base from override res. | |
| 1513 | * | | | |
| 1514 | * +-----------------------------------------------------------------+ |
| 1515 | * | | | |
Nico Huber | 8e1ea52 | 2020-06-03 10:20:07 -0700 | [diff] [blame] | 1516 | * | ref | Each reference that is present in override | |
| 1517 | * | | device is copied over to base device with | |
| 1518 | * | | the same rules as registers. | |
| 1519 | * | | | |
| 1520 | * +-----------------------------------------------------------------+ |
| 1521 | * | | | |
| 1522 | * | alias | Base device alias is copied to override. | |
| 1523 | * | | Override devices cannot change/remove an | |
| 1524 | * | | existing alias, but they can add an alias | |
| 1525 | * | | if one does not exist. | |
| 1526 | * | | | |
| 1527 | * +-----------------------------------------------------------------+ |
| 1528 | * | | | |
Furquan Shaikh | 27efc50 | 2018-06-22 09:19:15 -0700 | [diff] [blame] | 1529 | * | chip_instance | Each register of chip_instance is copied | |
| 1530 | * | | over from override device to base device: | |
| 1531 | * | | 1. If register with same key is present in | |
| 1532 | * | | base device, then value of the register | |
| 1533 | * | | is copied. | |
| 1534 | * | | 2. If not, then a new register is allocated| |
| 1535 | * | | under the base chip_instance using key | |
| 1536 | * | | and value from override register. | |
| 1537 | * | | | |
| 1538 | * +-----------------------------------------------------------------+ |
| 1539 | * | | | |
| 1540 | * | bus | Recursively call override_devicetree on | |
| 1541 | * | last_bus | each bus of override device. It is assumed | |
| 1542 | * | | that bus with id X under base device | |
| 1543 | * | | to bus with id X under override device. If | |
| 1544 | * | | override device has more buses than base | |
| 1545 | * | | device, then new buses are allocated under | |
| 1546 | * | | base device. | |
| 1547 | * | | | |
| 1548 | * +-----------------------------------------------------------------+ |
| 1549 | */ |
| 1550 | static void update_device(struct device *base_dev, struct device *override_dev) |
| 1551 | { |
| 1552 | /* |
| 1553 | * Copy the enabled state of override device to base device. This allows |
| 1554 | * override tree to enable or disable a particular device. |
| 1555 | */ |
| 1556 | base_dev->enabled = override_dev->enabled; |
| 1557 | |
| 1558 | /* |
| 1559 | * Copy subsystem vendor and device ids from override device to base |
| 1560 | * device only if the ids are non-zero in override device. Else, honor |
| 1561 | * the values in base device. |
| 1562 | */ |
| 1563 | if (override_dev->subsystem_vendor || |
| 1564 | override_dev->subsystem_device) { |
| 1565 | base_dev->subsystem_vendor = override_dev->subsystem_vendor; |
| 1566 | base_dev->subsystem_device = override_dev->subsystem_device; |
| 1567 | } |
| 1568 | |
| 1569 | /* |
| 1570 | * Copy value of inherity_subsystem from override device to base device |
| 1571 | * only if it is non-zero in override device. This allows override |
| 1572 | * tree to only enable inhert flag for a device. |
| 1573 | */ |
| 1574 | if (override_dev->inherit_subsystem) |
| 1575 | base_dev->inherit_subsystem = override_dev->inherit_subsystem; |
| 1576 | |
| 1577 | /* |
| 1578 | * Copy resources of override device to base device. |
| 1579 | * 1. If resource is already present in base device, then index and base |
| 1580 | * of the resource will be copied over. |
| 1581 | * 2. If resource is not already present in base device, a new resource |
| 1582 | * will be allocated. |
| 1583 | */ |
| 1584 | struct resource *res = override_dev->res; |
| 1585 | while (res) { |
| 1586 | update_resource(base_dev, res); |
| 1587 | res = res->next; |
| 1588 | } |
| 1589 | |
| 1590 | /* |
| 1591 | * Copy registers of override chip instance to base chip instance. |
| 1592 | * 1. If register key is already present in base chip instance, then |
| 1593 | * value for the register is copied over. |
| 1594 | * 2. If register key is not already present in base chip instance, then |
| 1595 | * a new register will be allocated. |
| 1596 | */ |
| 1597 | struct reg *reg = override_dev->chip_instance->reg; |
| 1598 | while (reg) { |
Nico Huber | 8e1ea52 | 2020-06-03 10:20:07 -0700 | [diff] [blame] | 1599 | update_register(&base_dev->chip_instance->reg, reg); |
Furquan Shaikh | 27efc50 | 2018-06-22 09:19:15 -0700 | [diff] [blame] | 1600 | reg = reg->next; |
| 1601 | } |
| 1602 | |
Nico Huber | 8e1ea52 | 2020-06-03 10:20:07 -0700 | [diff] [blame] | 1603 | /* Copy references just as with registers. */ |
| 1604 | reg = override_dev->chip_instance->ref; |
| 1605 | while (reg) { |
| 1606 | update_register(&base_dev->chip_instance->ref, reg); |
| 1607 | reg = reg->next; |
| 1608 | } |
| 1609 | |
| 1610 | /* Check for alias name conflicts. */ |
| 1611 | if (override_dev->alias && find_alias(&base_root_dev, override_dev->alias)) { |
| 1612 | printf("ERROR: alias already exists: %s\n", override_dev->alias); |
| 1613 | exit(1); |
| 1614 | } |
| 1615 | |
| 1616 | /* |
| 1617 | * Copy alias from base device. |
| 1618 | * |
| 1619 | * Override devices cannot change/remove an existing alias, |
| 1620 | * but they can add an alias to a device if one does not exist yet. |
| 1621 | */ |
| 1622 | if (base_dev->alias) |
| 1623 | override_dev->alias = base_dev->alias; |
| 1624 | else |
| 1625 | base_dev->alias = override_dev->alias; |
| 1626 | |
Furquan Shaikh | 27efc50 | 2018-06-22 09:19:15 -0700 | [diff] [blame] | 1627 | /* |
Duncan Laurie | 47b7b34 | 2020-05-15 15:39:08 -0700 | [diff] [blame] | 1628 | * Use probe list from override device in place of base device, in order |
| 1629 | * to allow an override to remove a probe from the base device. |
| 1630 | */ |
| 1631 | base_dev->probe = override_dev->probe; |
| 1632 | |
| 1633 | /* |
Furquan Shaikh | bbade24 | 2020-05-02 16:05:29 -0700 | [diff] [blame] | 1634 | * Update base_chip_instance member in chip instance of override tree to forward it to |
| 1635 | * the chip instance in base tree. |
| 1636 | */ |
| 1637 | override_dev->chip_instance->base_chip_instance = base_dev->chip_instance; |
| 1638 | |
| 1639 | /* |
Furquan Shaikh | 27efc50 | 2018-06-22 09:19:15 -0700 | [diff] [blame] | 1640 | * Now that the device properties are all copied over, look at each bus |
| 1641 | * of the override device and run override_devicetree in a recursive |
| 1642 | * manner. The assumption here is that first bus of override device |
| 1643 | * corresponds to first bus of base device and so on. If base device has |
| 1644 | * lesser buses than override tree, then new buses are allocated for it. |
| 1645 | */ |
| 1646 | struct bus *override_bus = override_dev->bus; |
| 1647 | struct bus *base_bus = base_dev->bus; |
| 1648 | |
| 1649 | while (override_bus) { |
| 1650 | |
| 1651 | /* |
| 1652 | * If we have more buses in override tree device, then allocate |
| 1653 | * a new bus for the base tree device as well. |
| 1654 | */ |
| 1655 | if (!base_bus) { |
| 1656 | alloc_bus(base_dev); |
| 1657 | base_bus = base_dev->last_bus; |
| 1658 | } |
| 1659 | |
| 1660 | override_devicetree(base_dev->bus, override_dev->bus); |
| 1661 | |
| 1662 | override_bus = override_bus->next_bus; |
| 1663 | base_bus = base_bus->next_bus; |
| 1664 | } |
Furquan Shaikh | 27efc50 | 2018-06-22 09:19:15 -0700 | [diff] [blame] | 1665 | } |
| 1666 | |
| 1667 | /* |
| 1668 | * Perform copy of device and properties from override parent to base parent. |
| 1669 | * This function walks through the override tree in a depth-first manner |
| 1670 | * performing following actions: |
| 1671 | * 1. If matching device is found in base tree, then copy the properties of |
| 1672 | * override device to base tree device. Call override_devicetree recursively on |
| 1673 | * the bus of override device. |
| 1674 | * 2. If matching device is not found in base tree, then set override tree |
| 1675 | * device as new child of base_parent and update the chip pointers in override |
| 1676 | * device subtree to ensure the nodes do not point to override tree chip |
| 1677 | * instance. |
| 1678 | */ |
| 1679 | static void override_devicetree(struct bus *base_parent, |
| 1680 | struct bus *override_parent) |
| 1681 | { |
| 1682 | struct device *base_child; |
| 1683 | struct device *override_child = override_parent->children; |
| 1684 | struct device *next_child; |
| 1685 | |
| 1686 | while (override_child) { |
| 1687 | |
| 1688 | /* Look for a matching device in base tree. */ |
| 1689 | for (base_child = base_parent->children; |
| 1690 | base_child; base_child = base_child->sibling) { |
| 1691 | if (device_match(base_child, override_child)) |
| 1692 | break; |
| 1693 | } |
| 1694 | |
| 1695 | next_child = override_child->sibling; |
| 1696 | |
| 1697 | /* |
| 1698 | * If matching device is found, copy properties of |
| 1699 | * override_child to base_child. |
| 1700 | */ |
| 1701 | if (base_child) |
| 1702 | update_device(base_child, override_child); |
| 1703 | else { |
| 1704 | /* |
| 1705 | * If matching device is not found, set override_child |
| 1706 | * as a new child of base_parent. |
| 1707 | */ |
| 1708 | set_new_child(base_parent, override_child); |
Furquan Shaikh | 27efc50 | 2018-06-22 09:19:15 -0700 | [diff] [blame] | 1709 | } |
| 1710 | |
| 1711 | override_child = next_child; |
| 1712 | } |
| 1713 | } |
| 1714 | |
Duncan Laurie | cbd0bd8 | 2020-06-09 11:24:10 -0700 | [diff] [blame] | 1715 | static void parse_override_devicetree(const char *file, struct device *dev) |
| 1716 | { |
| 1717 | parse_devicetree(file, dev->bus); |
| 1718 | |
| 1719 | if (!dev_has_children(dev)) { |
| 1720 | fprintf(stderr, "ERROR: Override tree needs at least one device!\n"); |
| 1721 | exit(1); |
| 1722 | } |
| 1723 | |
| 1724 | override_devicetree(&base_root_bus, dev->bus); |
| 1725 | } |
| 1726 | |
Tim Wawrzynczak | ba4a490 | 2020-09-23 15:36:30 -0600 | [diff] [blame^] | 1727 | static void generate_outputh(FILE *f, const char *fw_conf_header, const char *device_header) |
| 1728 | { |
| 1729 | fprintf(f, "#ifndef __STATIC_DEVICE_TREE_H\n"); |
| 1730 | fprintf(f, "#define __STATIC_DEVICE_TREE_H\n\n"); |
| 1731 | |
| 1732 | fprintf(f, "#include <%s>\n", fw_conf_header); |
| 1733 | fprintf(f, "#include <%s>\n\n", device_header); |
| 1734 | |
| 1735 | fprintf(f, "\n#endif /* __STATIC_DEVICE_TREE_H */\n"); |
| 1736 | } |
| 1737 | |
| 1738 | static void generate_outputc(FILE *f, const char *static_header) |
| 1739 | { |
| 1740 | fprintf(f, "#include <device/device.h>\n"); |
| 1741 | fprintf(f, "#include <device/pci.h>\n"); |
| 1742 | fprintf(f, "#include <fw_config.h>\n"); |
| 1743 | fprintf(f, "#include <%s>\n", static_header); |
| 1744 | emit_chip_headers(f, chip_header.next); |
| 1745 | fprintf(f, "\n#define STORAGE static __unused DEVTREE_CONST\n\n"); |
| 1746 | |
| 1747 | walk_device_tree(NULL, NULL, &base_root_dev, inherit_subsystem_ids); |
| 1748 | fprintf(f, "\n/* pass 0 */\n"); |
| 1749 | walk_device_tree(f, NULL, &base_root_dev, pass0); |
| 1750 | walk_device_tree(NULL, NULL, &base_root_dev, update_references); |
| 1751 | fprintf(f, "\n/* chip configs */\n"); |
| 1752 | emit_chip_configs(f); |
| 1753 | fprintf(f, "\n/* pass 1 */\n"); |
| 1754 | walk_device_tree(f, NULL, &base_root_dev, pass1); |
| 1755 | } |
| 1756 | |
| 1757 | static void generate_outputd(FILE *gen, FILE *dev) |
| 1758 | { |
| 1759 | fprintf(dev, "#ifndef __STATIC_DEVICES_H\n"); |
| 1760 | fprintf(dev, "#define __STATIC_DEVICES_H\n\n"); |
| 1761 | fprintf(dev, "#include <device/device.h>\n\n"); |
| 1762 | fprintf(dev, "/* expose_device_names */\n"); |
| 1763 | walk_device_tree(gen, dev, &base_root_dev, expose_device_names); |
| 1764 | fprintf(dev, "\n#endif /* __STATIC_DEVICE_NAMES_H */\n"); |
| 1765 | } |
| 1766 | |
| 1767 | static void generate_outputf(FILE *f) |
| 1768 | { |
| 1769 | fprintf(f, "#ifndef __STATIC_FW_CONFIG_H\n"); |
| 1770 | fprintf(f, "#define __STATIC_FW_CONFIG_H\n\n"); |
| 1771 | emit_fw_config(f); |
| 1772 | fprintf(f, "\n#endif /* __STATIC_FW_CONFIG_H */\n"); |
| 1773 | } |
| 1774 | |
Furquan Shaikh | de39fc7 | 2018-06-11 04:26:45 -0700 | [diff] [blame] | 1775 | int main(int argc, char **argv) |
| 1776 | { |
Duncan Laurie | 51c8373 | 2020-06-09 11:20:29 -0700 | [diff] [blame] | 1777 | static const struct option long_options[] = { |
| 1778 | { "mainboard_devtree", 1, NULL, 'm' }, |
| 1779 | { "override_devtree", 1, NULL, 'o' }, |
Duncan Laurie | e335c2e | 2020-07-29 16:28:43 -0700 | [diff] [blame] | 1780 | { "chipset_devtree", 1, NULL, 'p' }, |
Duncan Laurie | 51c8373 | 2020-06-09 11:20:29 -0700 | [diff] [blame] | 1781 | { "output_c", 1, NULL, 'c' }, |
| 1782 | { "output_h", 1, NULL, 'r' }, |
Tim Wawrzynczak | ba4a490 | 2020-09-23 15:36:30 -0600 | [diff] [blame^] | 1783 | { "output_d", 1, NULL, 'd' }, |
| 1784 | { "output_f", 1, NULL, 'f' }, |
Duncan Laurie | 51c8373 | 2020-06-09 11:20:29 -0700 | [diff] [blame] | 1785 | { "help", 1, NULL, 'h' }, |
| 1786 | { } |
| 1787 | }; |
| 1788 | const char *override_devtree = NULL; |
| 1789 | const char *base_devtree = NULL; |
Duncan Laurie | e335c2e | 2020-07-29 16:28:43 -0700 | [diff] [blame] | 1790 | const char *chipset_devtree = NULL; |
Duncan Laurie | 51c8373 | 2020-06-09 11:20:29 -0700 | [diff] [blame] | 1791 | const char *outputc = NULL; |
| 1792 | const char *outputh = NULL; |
Tim Wawrzynczak | ba4a490 | 2020-09-23 15:36:30 -0600 | [diff] [blame^] | 1793 | const char *outputd = NULL; |
| 1794 | const char *outputf = NULL; |
Duncan Laurie | 51c8373 | 2020-06-09 11:20:29 -0700 | [diff] [blame] | 1795 | int opt, option_index; |
Furquan Shaikh | de39fc7 | 2018-06-11 04:26:45 -0700 | [diff] [blame] | 1796 | |
Tim Wawrzynczak | ba4a490 | 2020-09-23 15:36:30 -0600 | [diff] [blame^] | 1797 | while ((opt = getopt_long(argc, argv, "m:o:p:c:r:d:f:h", long_options, |
Duncan Laurie | 51c8373 | 2020-06-09 11:20:29 -0700 | [diff] [blame] | 1798 | &option_index)) != EOF) { |
| 1799 | switch (opt) { |
| 1800 | case 'm': |
| 1801 | base_devtree = strdup(optarg); |
| 1802 | break; |
| 1803 | case 'o': |
| 1804 | override_devtree = strdup(optarg); |
| 1805 | break; |
Duncan Laurie | e335c2e | 2020-07-29 16:28:43 -0700 | [diff] [blame] | 1806 | case 'p': |
| 1807 | chipset_devtree = strdup(optarg); |
| 1808 | break; |
Duncan Laurie | 51c8373 | 2020-06-09 11:20:29 -0700 | [diff] [blame] | 1809 | case 'c': |
| 1810 | outputc = strdup(optarg); |
| 1811 | break; |
| 1812 | case 'r': |
| 1813 | outputh = strdup(optarg); |
| 1814 | break; |
Tim Wawrzynczak | ba4a490 | 2020-09-23 15:36:30 -0600 | [diff] [blame^] | 1815 | case 'd': |
| 1816 | outputd = strdup(optarg); |
| 1817 | break; |
| 1818 | case 'f': |
| 1819 | outputf = strdup(optarg); |
| 1820 | break; |
Duncan Laurie | 51c8373 | 2020-06-09 11:20:29 -0700 | [diff] [blame] | 1821 | case 'h': |
| 1822 | default: |
| 1823 | usage(); |
| 1824 | } |
| 1825 | } |
| 1826 | |
Tim Wawrzynczak | ba4a490 | 2020-09-23 15:36:30 -0600 | [diff] [blame^] | 1827 | if (!base_devtree || !outputc || !outputh || !outputd || !outputf) |
Duncan Laurie | 51c8373 | 2020-06-09 11:20:29 -0700 | [diff] [blame] | 1828 | usage(); |
Furquan Shaikh | de39fc7 | 2018-06-11 04:26:45 -0700 | [diff] [blame] | 1829 | |
Duncan Laurie | e335c2e | 2020-07-29 16:28:43 -0700 | [diff] [blame] | 1830 | if (chipset_devtree) { |
| 1831 | /* Use the chipset devicetree as the base, then override |
| 1832 | with the mainboard "base" devicetree. */ |
| 1833 | parse_devicetree(chipset_devtree, &base_root_bus); |
| 1834 | parse_override_devicetree(base_devtree, &chipset_root_dev); |
| 1835 | } else { |
| 1836 | parse_devicetree(base_devtree, &base_root_bus); |
| 1837 | } |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 1838 | |
Duncan Laurie | cbd0bd8 | 2020-06-09 11:24:10 -0700 | [diff] [blame] | 1839 | if (override_devtree) |
| 1840 | parse_override_devicetree(override_devtree, &override_root_dev); |
Furquan Shaikh | 39ac797 | 2018-06-21 18:44:32 -0700 | [diff] [blame] | 1841 | |
Kyösti Mälkki | 472d902 | 2011-12-05 20:33:55 +0200 | [diff] [blame] | 1842 | FILE *autogen = fopen(outputc, "w"); |
| 1843 | if (!autogen) { |
Martin Roth | bec0753 | 2016-08-05 18:32:18 -0600 | [diff] [blame] | 1844 | fprintf(stderr, "Could not open file '%s' for writing: ", |
| 1845 | outputc); |
Stefan Reinauer | 7c1f6b8 | 2010-08-16 18:21:56 +0000 | [diff] [blame] | 1846 | perror(NULL); |
| 1847 | exit(1); |
| 1848 | } |
| 1849 | |
Nico Huber | 17e9bcb | 2019-09-20 12:05:51 +0200 | [diff] [blame] | 1850 | FILE *autohead = fopen(outputh, "w"); |
| 1851 | if (!autohead) { |
| 1852 | fprintf(stderr, "Could not open file '%s' for writing: ", outputh); |
| 1853 | perror(NULL); |
| 1854 | fclose(autogen); |
| 1855 | exit(1); |
| 1856 | } |
Nico Huber | 17e9bcb | 2019-09-20 12:05:51 +0200 | [diff] [blame] | 1857 | |
Tim Wawrzynczak | ba4a490 | 2020-09-23 15:36:30 -0600 | [diff] [blame^] | 1858 | FILE *autodev = fopen(outputd, "w"); |
| 1859 | if (!autodev) { |
| 1860 | fprintf(stderr, "Could not open file '%s' for writing: ", outputd); |
| 1861 | perror(NULL); |
| 1862 | fclose(autogen); |
| 1863 | fclose(autohead); |
| 1864 | exit(1); |
| 1865 | } |
Furquan Shaikh | 79e8412 | 2018-05-30 15:09:09 -0700 | [diff] [blame] | 1866 | |
Tim Wawrzynczak | ba4a490 | 2020-09-23 15:36:30 -0600 | [diff] [blame^] | 1867 | FILE *autofwconf = fopen(outputf, "w"); |
| 1868 | if (!autofwconf) { |
| 1869 | fprintf(stderr, "Could not open file '%s' for writing: ", outputf); |
| 1870 | perror(NULL); |
| 1871 | fclose(autogen); |
| 1872 | fclose(autohead); |
| 1873 | fclose(autodev); |
| 1874 | exit(1); |
| 1875 | } |
Sven Schnelle | 270a908 | 2011-03-01 19:58:15 +0000 | [diff] [blame] | 1876 | |
Tim Wawrzynczak | ba4a490 | 2020-09-23 15:36:30 -0600 | [diff] [blame^] | 1877 | char *f = strdup(outputf); |
| 1878 | assert(f); |
| 1879 | char *d = strdup(outputd); |
| 1880 | assert(d); |
| 1881 | char *h = strdup(outputh); |
| 1882 | assert(h); |
Kyösti Mälkki | 5e2a2cd | 2019-03-15 17:44:23 +0200 | [diff] [blame] | 1883 | |
Tim Wawrzynczak | ba4a490 | 2020-09-23 15:36:30 -0600 | [diff] [blame^] | 1884 | const char *fw_conf_header = basename(f); |
| 1885 | const char *device_header = basename(d); |
| 1886 | const char *static_header = basename(h); |
| 1887 | |
| 1888 | generate_outputh(autohead, fw_conf_header, device_header); |
| 1889 | generate_outputc(autogen, static_header); |
| 1890 | generate_outputd(autogen, autodev); |
| 1891 | generate_outputf(autofwconf); |
| 1892 | |
Nico Huber | 17e9bcb | 2019-09-20 12:05:51 +0200 | [diff] [blame] | 1893 | fclose(autohead); |
Kyösti Mälkki | 472d902 | 2011-12-05 20:33:55 +0200 | [diff] [blame] | 1894 | fclose(autogen); |
Tim Wawrzynczak | ba4a490 | 2020-09-23 15:36:30 -0600 | [diff] [blame^] | 1895 | fclose(autodev); |
| 1896 | fclose(autofwconf); |
| 1897 | free(f); |
| 1898 | free(d); |
| 1899 | free(h); |
Stefan Reinauer | 7c1f6b8 | 2010-08-16 18:21:56 +0000 | [diff] [blame] | 1900 | |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 1901 | return 0; |
| 1902 | } |