blob: 2b1feda95e408d5ae38f92e1cc361a86fed9abaa [file] [log] [blame]
Patrick Georgiea063cb2020-05-08 19:28:13 +02001/* sconfig, coreboot device tree compiler */
Patrick Georgi7333a112020-05-08 20:48:04 +02002/* SPDX-License-Identifier: GPL-2.0-only */
Patrick Georgi114e7b22010-05-05 11:19:50 +00003
Tim Wawrzynczakba4a4902020-09-23 15:36:30 -06004#include <assert.h>
Patrick Georgi2dbfcb72012-05-30 16:26:30 +02005#include <ctype.h>
Duncan Laurie51c83732020-06-09 11:20:29 -07006#include <getopt.h>
Tim Wawrzynczak24b4af62020-10-01 15:41:31 -06007#include <inttypes.h>
Tim Wawrzynczakba4a4902020-09-23 15:36:30 -06008#include <libgen.h>
Tim Wawrzynczak24b4af62020-10-01 15:41:31 -06009/* stat.h needs to be included before commonlib/helpers.h to avoid errors.*/
Werner Zehac14a402019-07-11 12:47:19 +020010#include <sys/stat.h>
Kyösti Mälkkie29a6ac2019-03-15 17:05:19 +020011#include <commonlib/helpers.h>
Duncan Laurie47b7b342020-05-15 15:39:08 -070012#include <stdint.h>
Patrick Georgi114e7b22010-05-05 11:19:50 +000013#include "sconfig.h"
14#include "sconfig.tab.h"
15
Patrick Georgi7fc9e292010-07-15 15:59:07 +000016extern int linenum;
17
Furquan Shaikh27efc502018-06-22 09:19:15 -070018/*
19 * Maintains list of all the unique chip structures for the board.
20 * This is shared across base and override device trees since we need to
21 * generate headers for all chips added by both the trees.
22 */
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -070023static struct chip chip_header;
Furquan Shaikh79e84122018-05-30 15:09:09 -070024
Kyösti Mälkki472d9022011-12-05 20:33:55 +020025typedef enum {
Kyösti Mälkki1a2a6ee2012-03-18 20:19:28 +020026 UNSLASH,
27 SPLIT_1ST,
28 TO_LOWER,
29 TO_UPPER,
30} translate_t;
31
Furquan Shaikh93198262018-06-03 04:22:17 -070032/*
33 * Mainboard is assumed to have a root device whose bus is the parent of all the
34 * devices that are added by parsing the devicetree file. This device has a
35 * mainboard chip instance associated with it.
36 *
37 *
38 *
39 * +------------------------+ +----------------------+
Furquan Shaikhde39fc72018-06-11 04:26:45 -070040 * | Root device | | Mainboard |
41 * +---------+ (base_root_dev) +--------------->+ instance +
Furquan Shaikh93198262018-06-03 04:22:17 -070042 * | | | chip_instance | (mainboard_instance)|
43 * | +------------------------+ | |
44 * | | +----------------------+
45 * | | bus |
46 * | parent v |
47 * | +-------------------+ |
48 * | | Root bus | |
Furquan Shaikhde39fc72018-06-11 04:26:45 -070049 * +----------->+ (base_root_bus) | |
Furquan Shaikh93198262018-06-03 04:22:17 -070050 * | | |
51 * +-------------------+ |
52 * | |
53 * | children | chip
54 * v |
55 * X |
56 * (new devices will |
57 * be added here as |
58 * children) |
59 * |
60 * |
61 * |
62 * +-------+----------+
63 * | |
64 * | Mainboard chip +----------->X (new chips will be
65 * | (mainboard_chip) | added here)
66 * | |
67 * +------------------+
68 *
69 *
70 */
Furquan Shaikh39ac7972018-06-21 18:44:32 -070071
72/* Root device of primary tree. */
Furquan Shaikhde39fc72018-06-11 04:26:45 -070073static struct device base_root_dev;
Furquan Shaikh39ac7972018-06-21 18:44:32 -070074
Duncan Lauriee335c2e2020-07-29 16:28:43 -070075/* Root device of chipset tree. */
76static struct device chipset_root_dev;
77
Furquan Shaikh39ac7972018-06-21 18:44:32 -070078/* Root device of override tree (if applicable). */
79static struct device override_root_dev;
80
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -070081static struct chip_instance mainboard_instance;
82
Furquan Shaikhde39fc72018-06-11 04:26:45 -070083static struct bus base_root_bus = {
Furquan Shaikh93198262018-06-03 04:22:17 -070084 .id = 0,
Furquan Shaikhde39fc72018-06-11 04:26:45 -070085 .dev = &base_root_dev,
Furquan Shaikh93198262018-06-03 04:22:17 -070086};
87
Furquan Shaikhde39fc72018-06-11 04:26:45 -070088static struct device base_root_dev = {
Furquan Shaikh93198262018-06-03 04:22:17 -070089 .name = "dev_root",
Furquan Shaikh93198262018-06-03 04:22:17 -070090 .chip_instance = &mainboard_instance,
91 .path = " .type = DEVICE_PATH_ROOT ",
Furquan Shaikhde39fc72018-06-11 04:26:45 -070092 .parent = &base_root_bus,
Furquan Shaikh93198262018-06-03 04:22:17 -070093 .enabled = 1,
Furquan Shaikhde39fc72018-06-11 04:26:45 -070094 .bus = &base_root_bus,
Furquan Shaikh93198262018-06-03 04:22:17 -070095};
96
Duncan Lauriee335c2e2020-07-29 16:28:43 -070097static struct bus chipset_root_bus = {
98 .id = 0,
99 .dev = &chipset_root_dev,
100};
101
102static struct device chipset_root_dev = {
103 .name = "chipset_root",
104 .chip_instance = &mainboard_instance,
105 .path = " .type = DEVICE_PATH_ROOT ",
106 .parent = &chipset_root_bus,
107 .enabled = 1,
108 .bus = &chipset_root_bus,
109};
110
Furquan Shaikh39ac7972018-06-21 18:44:32 -0700111static struct bus override_root_bus = {
112 .id = 0,
113 .dev = &override_root_dev,
114};
115
116static struct device override_root_dev = {
117 .name = "override_root",
Furquan Shaikh39ac7972018-06-21 18:44:32 -0700118 /*
119 * Override tree root device points to the same mainboard chip instance
120 * as the base tree root device. It should not cause any side-effects
121 * since the mainboard chip instance pointer in override tree will just
122 * be ignored.
123 */
124 .chip_instance = &mainboard_instance,
125 .path = " .type = DEVICE_PATH_ROOT ",
Furquan Shaikh39ac7972018-06-21 18:44:32 -0700126 .parent = &override_root_bus,
127 .enabled = 1,
128 .bus = &override_root_bus,
129};
130
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -0700131static struct chip mainboard_chip = {
Patrick Georgi114e7b22010-05-05 11:19:50 +0000132 .name = "mainboard",
133 .name_underscore = "mainboard",
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -0700134 .instance = &mainboard_instance,
135};
136
137static struct chip_instance mainboard_instance = {
138 .id = 0,
139 .chip = &mainboard_chip,
Patrick Georgi114e7b22010-05-05 11:19:50 +0000140};
141
Furquan Shaikh93198262018-06-03 04:22:17 -0700142/* This is the parent of all devices added by parsing the devicetree file. */
Furquan Shaikhde39fc72018-06-11 04:26:45 -0700143struct bus *root_parent;
Patrick Georgi114e7b22010-05-05 11:19:50 +0000144
Furquan Shaikh7398ded2018-06-03 10:42:49 -0700145struct queue_entry {
Furquan Shaikh79e84122018-05-30 15:09:09 -0700146 void *data;
Furquan Shaikh7398ded2018-06-03 10:42:49 -0700147 struct queue_entry *next;
148 struct queue_entry *prev;
149};
Furquan Shaikh79e84122018-05-30 15:09:09 -0700150
Furquan Shaikh369e1f02018-05-31 09:48:51 -0700151#define S_ALLOC(_s) s_alloc(__func__, _s)
Furquan Shaikh79e84122018-05-30 15:09:09 -0700152
Furquan Shaikh369e1f02018-05-31 09:48:51 -0700153static void *s_alloc(const char *f, size_t s)
154{
155 void *data = calloc(1, s);
156 if (!data) {
Maulik V Vaghela82e8c692018-06-08 10:32:08 +0530157 fprintf(stderr, "%s: Failed to alloc mem!\n", f);
Furquan Shaikh79e84122018-05-30 15:09:09 -0700158 exit(1);
159 }
Furquan Shaikh369e1f02018-05-31 09:48:51 -0700160 return data;
161}
162
Furquan Shaikh7398ded2018-06-03 10:42:49 -0700163static struct queue_entry *new_queue_entry(void *data)
Furquan Shaikh369e1f02018-05-31 09:48:51 -0700164{
Furquan Shaikh7398ded2018-06-03 10:42:49 -0700165 struct queue_entry *e = S_ALLOC(sizeof(*e));
Furquan Shaikh79e84122018-05-30 15:09:09 -0700166
167 e->data = data;
168 e->next = e->prev = e;
169 return e;
170}
171
Furquan Shaikh7398ded2018-06-03 10:42:49 -0700172static void enqueue_tail(struct queue_entry **q_head, void *data)
Furquan Shaikh79e84122018-05-30 15:09:09 -0700173{
Furquan Shaikh7398ded2018-06-03 10:42:49 -0700174 struct queue_entry *tmp = new_queue_entry(data);
175 struct queue_entry *q = *q_head;
Furquan Shaikh79e84122018-05-30 15:09:09 -0700176
177 if (!q) {
Furquan Shaikh7398ded2018-06-03 10:42:49 -0700178 *q_head = tmp;
Furquan Shaikh79e84122018-05-30 15:09:09 -0700179 return;
180 }
181
182 q->prev->next = tmp;
183 tmp->prev = q->prev;
184 q->prev = tmp;
185 tmp->next = q;
186}
187
Furquan Shaikh7398ded2018-06-03 10:42:49 -0700188static void *dequeue_tail(struct queue_entry **q_head)
Furquan Shaikh79e84122018-05-30 15:09:09 -0700189{
Furquan Shaikh7398ded2018-06-03 10:42:49 -0700190 struct queue_entry *q = *q_head;
191 struct queue_entry *tmp;
Furquan Shaikh79e84122018-05-30 15:09:09 -0700192 void *data;
193
Furquan Shaikh7398ded2018-06-03 10:42:49 -0700194 if (!q)
195 return NULL;
196
197 tmp = q->prev;
198
Furquan Shaikh79e84122018-05-30 15:09:09 -0700199 if (tmp == q)
Furquan Shaikh7398ded2018-06-03 10:42:49 -0700200 *q_head = NULL;
Furquan Shaikh79e84122018-05-30 15:09:09 -0700201 else {
202 tmp->prev->next = q;
203 q->prev = tmp->prev;
204 }
205
206 data = tmp->data;
207 free(tmp);
208
209 return data;
210}
211
Furquan Shaikh7398ded2018-06-03 10:42:49 -0700212static void *dequeue_head(struct queue_entry **q_head)
213{
214 struct queue_entry *q = *q_head;
215 struct queue_entry *tmp = q;
216 void *data;
217
218 if (!q)
219 return NULL;
220
221 if (q->next == q)
222 *q_head = NULL;
223 else {
224 q->next->prev = q->prev;
225 q->prev->next = q->next;
226 *q_head = q->next;
227 }
228
229 data = tmp->data;
230 free(tmp);
231
232 return data;
233}
234
235static void *peek_queue_head(struct queue_entry *q_head)
236{
237 if (!q_head)
238 return NULL;
239
240 return q_head->data;
241}
242
243static struct queue_entry *chip_q_head;
244
245void chip_enqueue_tail(void *data)
246{
247 enqueue_tail(&chip_q_head, data);
248}
249
250void *chip_dequeue_tail(void)
251{
252 return dequeue_tail(&chip_q_head);
253}
254
Martin Rothbec07532016-08-05 18:32:18 -0600255int yywrap(void)
256{
Patrick Georgi114e7b22010-05-05 11:19:50 +0000257 return 1;
258}
259
Martin Rothbec07532016-08-05 18:32:18 -0600260void yyerror(char const *str)
Patrick Georgi114e7b22010-05-05 11:19:50 +0000261{
Stefan Reinauer7c1f6b82010-08-16 18:21:56 +0000262 extern char *yytext;
Martin Rothbec07532016-08-05 18:32:18 -0600263 fprintf(stderr, "line %d: %s: %s\n", linenum + 1, yytext, str);
Stefan Reinauer7c1f6b82010-08-16 18:21:56 +0000264 exit(1);
Patrick Georgi114e7b22010-05-05 11:19:50 +0000265}
266
Martin Rothbec07532016-08-05 18:32:18 -0600267char *translate_name(const char *str, translate_t mode)
Kyösti Mälkki472d9022011-12-05 20:33:55 +0200268{
Kyösti Mälkki1a2a6ee2012-03-18 20:19:28 +0200269 char *b, *c;
270 b = c = strdup(str);
271 while (c && *c) {
272 if ((mode == SPLIT_1ST) && (*c == '/')) {
273 *c = 0;
274 break;
275 }
Martin Rothbec07532016-08-05 18:32:18 -0600276 if (*c == '/')
277 *c = '_';
278 if (*c == '-')
279 *c = '_';
Kyösti Mälkki1a2a6ee2012-03-18 20:19:28 +0200280 if (mode == TO_UPPER)
Kyösti Mälkki472d9022011-12-05 20:33:55 +0200281 *c = toupper(*c);
Kyösti Mälkki1a2a6ee2012-03-18 20:19:28 +0200282 if (mode == TO_LOWER)
283 *c = tolower(*c);
284 c++;
Kyösti Mälkki472d9022011-12-05 20:33:55 +0200285 }
Kyösti Mälkki1a2a6ee2012-03-18 20:19:28 +0200286 return b;
Kyösti Mälkki472d9022011-12-05 20:33:55 +0200287}
288
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -0700289static struct chip *get_chip(char *path)
Martin Rothbec07532016-08-05 18:32:18 -0600290{
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -0700291 struct chip *h = &chip_header;
Furquan Shaikh79e84122018-05-30 15:09:09 -0700292
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -0700293 while (h->next) {
294 int result = strcmp(path, h->next->name);
295 if (result == 0)
296 return h->next;
297
298 if (result < 0)
299 break;
300
301 h = h->next;
302 }
303
304 struct chip *new_chip = S_ALLOC(sizeof(struct chip));
305 new_chip->next = h->next;
306 h->next = new_chip;
307
Patrick Georgi114e7b22010-05-05 11:19:50 +0000308 new_chip->chiph_exists = 1;
309 new_chip->name = path;
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -0700310 new_chip->name_underscore = translate_name(path, UNSLASH);
Patrick Georgi114e7b22010-05-05 11:19:50 +0000311
312 struct stat st;
Furquan Shaikh369e1f02018-05-31 09:48:51 -0700313 char *chip_h = S_ALLOC(strlen(path) + 18);
Stefan Reinauer76c44ae2011-10-14 12:41:46 -0700314 sprintf(chip_h, "src/%s", path);
315 if ((stat(chip_h, &st) == -1) && (errno == ENOENT)) {
Patrick Georgi92bcaa22015-11-13 09:39:22 +0100316 /* root_complex gets away without a separate directory, but
317 * exists on on pretty much all AMD chipsets.
318 */
319 if (!strstr(path, "/root_complex")) {
Kyösti Mälkki6aeb4a22013-06-11 17:00:11 +0300320 fprintf(stderr, "ERROR: Chip component %s does not exist.\n",
321 path);
322 exit(1);
323 }
Stefan Reinauer76c44ae2011-10-14 12:41:46 -0700324 }
325
Martin Roth824255e2016-08-05 17:40:39 -0600326 sprintf(chip_h, "src/%s/chip.h", path);
Kyösti Mälkki472d9022011-12-05 20:33:55 +0200327
Martin Roth824255e2016-08-05 17:40:39 -0600328 if ((stat(chip_h, &st) == -1) && (errno == ENOENT))
Martin Rothbec07532016-08-05 18:32:18 -0600329 new_chip->chiph_exists = 0;
Patrick Georgi114e7b22010-05-05 11:19:50 +0000330
Patrick Georgi1f688802014-08-03 15:51:19 +0200331 free(chip_h);
Furquan Shaikh79e84122018-05-30 15:09:09 -0700332
Patrick Georgi114e7b22010-05-05 11:19:50 +0000333 return new_chip;
334}
335
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -0700336struct chip_instance *new_chip_instance(char *path)
337{
338 struct chip *chip = get_chip(path);
339 struct chip_instance *instance = S_ALLOC(sizeof(*instance));
340
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -0700341 instance->chip = chip;
342 instance->next = chip->instance;
343 chip->instance = instance;
344
345 return instance;
346}
347
Duncan Laurie47b7b342020-05-15 15:39:08 -0700348/* List of fw_config fields added during parsing. */
349static struct fw_config_field *fw_config_fields;
350
351static struct fw_config_option *find_fw_config_option(struct fw_config_field *field,
352 const char *name)
353{
354 struct fw_config_option *option = field->options;
355
356 while (option && option->name) {
357 if (!strcmp(option->name, name))
358 return option;
359 option = option->next;
360 }
361 return NULL;
362}
363
364static struct fw_config_field *find_fw_config_field(const char *name)
365{
366 struct fw_config_field *field = fw_config_fields;
367
368 while (field && field->name) {
369 if (!strcmp(field->name, name))
370 return field;
371 field = field->next;
372 }
373 return NULL;
374}
375
376struct fw_config_field *get_fw_config_field(const char *name)
377{
378 struct fw_config_field *field = find_fw_config_field(name);
379
380 /* Fail if the field does not exist, new fields must be added with a mask. */
381 if (!field) {
382 printf("ERROR: fw_config field not found: %s\n", name);
383 exit(1);
384 }
385 return field;
386}
387
388static void append_fw_config_field(struct fw_config_field *add)
389{
390 struct fw_config_field *field = fw_config_fields;
391
392 if (!fw_config_fields) {
393 fw_config_fields = add;
394 } else {
395 while (field && field->next)
396 field = field->next;
397 field->next = add;
398 }
399}
400
Tim Wawrzynczak13e240c2021-04-28 14:03:07 -0600401void append_fw_config_bits(struct fw_config_field_bits **bits,
402 unsigned int start_bit, unsigned int end_bit)
403{
404 struct fw_config_field_bits *new_bits = S_ALLOC(sizeof(*new_bits));
405 new_bits->start_bit = start_bit;
406 new_bits->end_bit = end_bit;
407 new_bits->next = NULL;
408
409 if (*bits == NULL) {
410 *bits = new_bits;
411 return;
412 }
413
414 struct fw_config_field_bits *tmp = *bits;
415 while (tmp->next)
416 tmp = tmp->next;
417
418 tmp->next = new_bits;
419}
420
421int fw_config_masks_overlap(struct fw_config_field *existing,
422 unsigned int start_bit, unsigned int end_bit)
423{
424 struct fw_config_field_bits *bits = existing->bits;
425 while (bits) {
426 if (start_bit <= bits->end_bit && end_bit >= bits->start_bit) {
427 printf("ERROR: fw_config field [%u-%u] overlaps %s[%u-%u]\n",
428 start_bit, end_bit,
429 existing->name, bits->start_bit, bits->end_bit);
430 return 1;
431 }
432 bits = bits->next;
433 }
434
435 return 0;
436}
437
438struct fw_config_field *new_fw_config_field(const char *name, struct fw_config_field_bits *bits)
Duncan Laurie47b7b342020-05-15 15:39:08 -0700439{
440 struct fw_config_field *field = find_fw_config_field(name);
Tim Wawrzynczak13e240c2021-04-28 14:03:07 -0600441 struct fw_config_field_bits *tmp;
Duncan Laurie47b7b342020-05-15 15:39:08 -0700442
443 /* Don't allow re-defining a field, only adding new fields. */
444 if (field) {
Tim Wawrzynczak13e240c2021-04-28 14:03:07 -0600445 printf("ERROR: fw_config field %s already exists\n", name);
Duncan Laurie47b7b342020-05-15 15:39:08 -0700446 exit(1);
447 }
448
Tim Wawrzynczak13e240c2021-04-28 14:03:07 -0600449 /* Check that each field is within 64 bits. */
450 tmp = bits;
451 while (tmp) {
452 if (tmp->start_bit > tmp->end_bit || tmp->end_bit > 63) {
Tim Wawrzynczak54c36622021-05-04 10:08:10 -0600453 printf("ERROR: fw_config field %s has invalid range %u-%u\n", name,
Tim Wawrzynczak13e240c2021-04-28 14:03:07 -0600454 tmp->start_bit, tmp->end_bit);
Duncan Laurie47b7b342020-05-15 15:39:08 -0700455 exit(1);
456 }
Tim Wawrzynczak13e240c2021-04-28 14:03:07 -0600457
458 /* Check for overlap with an existing field. */
459 struct fw_config_field *existing = fw_config_fields;
460 while (existing) {
461 if (fw_config_masks_overlap(existing, tmp->start_bit, tmp->end_bit))
462 exit(1);
463 existing = existing->next;
464 }
465
466 tmp = tmp->next;
Duncan Laurie47b7b342020-05-15 15:39:08 -0700467 }
468
469 field = S_ALLOC(sizeof(*field));
470 field->name = name;
Tim Wawrzynczak13e240c2021-04-28 14:03:07 -0600471 field->bits = bits;
Duncan Laurie47b7b342020-05-15 15:39:08 -0700472 append_fw_config_field(field);
473
474 return field;
475}
476
477static void append_fw_config_option_to_field(struct fw_config_field *field,
478 struct fw_config_option *add)
479{
480 struct fw_config_option *option = field->options;
481
482 if (!option) {
483 field->options = add;
484 } else {
485 while (option && option->next)
486 option = option->next;
487 option->next = add;
488 }
489}
490
Tim Wawrzynczak13e240c2021-04-28 14:03:07 -0600491static uint64_t calc_max_field_value(const struct fw_config_field *field)
492{
493 unsigned int bit_count = 0;
494
495 const struct fw_config_field_bits *bits = field->bits;
496 while (bits) {
497 bit_count += 1 + bits->end_bit - bits->start_bit;
498 bits = bits->next;
499 };
500
501 return (1ull << bit_count) - 1ull;
502}
503
Tim Wawrzynczak24b4af62020-10-01 15:41:31 -0600504void add_fw_config_option(struct fw_config_field *field, const char *name, uint64_t value)
Duncan Laurie47b7b342020-05-15 15:39:08 -0700505{
506 struct fw_config_option *option;
Duncan Laurie47b7b342020-05-15 15:39:08 -0700507
508 /* Check that option value fits within field mask. */
Tim Wawrzynczak13e240c2021-04-28 14:03:07 -0600509 uint64_t field_max_value = calc_max_field_value(field);
Duncan Laurie47b7b342020-05-15 15:39:08 -0700510 if (value > field_max_value) {
Tim Wawrzynczak24b4af62020-10-01 15:41:31 -0600511 printf("ERROR: fw_config option %s:%s value %" PRIx64 " larger than field max %"
512 PRIx64 "\n",
Duncan Laurie47b7b342020-05-15 15:39:08 -0700513 field->name, name, value, field_max_value);
514 exit(1);
515 }
516
517 /* Check for existing option with this name or value. */
518 option = field->options;
519 while (option) {
520 if (!strcmp(option->name, name)) {
521 printf("ERROR: fw_config option name %s:%s already exists\n",
522 field->name, name);
523 exit(1);
524 }
525 /* Compare values. */
526 if (value == option->value) {
Tim Wawrzynczak24b4af62020-10-01 15:41:31 -0600527 printf("ERROR: fw_config option %s:%s[%" PRIx64 "] redefined as %s\n",
Duncan Laurie47b7b342020-05-15 15:39:08 -0700528 field->name, option->name, value, name);
529 exit(1);
530 }
531 option = option->next;
532 }
533
534 option = S_ALLOC(sizeof(*option));
535 option->name = name;
536 option->value = value;
537
538 /* Add option to the current field. */
539 append_fw_config_option_to_field(field, option);
540}
541
542static void append_fw_config_probe_to_dev(struct device *dev, struct fw_config_probe *add)
543{
544 struct fw_config_probe *probe = dev->probe;
545
546 if (!probe) {
547 dev->probe = add;
548 } else {
549 while (probe && probe->next)
550 probe = probe->next;
551 probe->next = add;
552 }
553}
554
Furquan Shaikhb9c22e02021-08-23 23:23:23 -0700555static int check_probe_exists(struct fw_config_probe *probe, const char *field,
556 const char *option)
557{
558 while (probe) {
559 if (!strcmp(probe->field, field) && !strcmp(probe->option, option)) {
560 return 1;
561 }
562 probe = probe->next;
563 }
564
565 return 0;
566}
567
Duncan Laurie47b7b342020-05-15 15:39:08 -0700568void add_fw_config_probe(struct bus *bus, const char *field, const char *option)
569{
570 struct fw_config_probe *probe;
571
Furquan Shaikhb9c22e02021-08-23 23:23:23 -0700572 if (check_probe_exists(bus->dev->probe, field, option)) {
573 printf("ERROR: fw_config probe %s:%s already exists\n", field, option);
574 exit(1);
Duncan Laurie47b7b342020-05-15 15:39:08 -0700575 }
576
577 probe = S_ALLOC(sizeof(*probe));
578 probe->field = field;
579 probe->option = option;
580
581 append_fw_config_probe_to_dev(bus->dev, probe);
582}
583
Tim Wawrzynczak13e240c2021-04-28 14:03:07 -0600584static uint64_t compute_fw_config_mask(const struct fw_config_field_bits *bits)
585{
586 uint64_t mask = 0;
587
588 while (bits) {
589 /* Compute mask from start and end bit. */
590 uint64_t tmp = ((1ull << (1ull + bits->end_bit - bits->start_bit)) - 1ull);
591 tmp <<= bits->start_bit;
592 mask |= tmp;
593 bits = bits->next;
594 }
595
596 return mask;
597}
598
599static unsigned int bits_width(const struct fw_config_field_bits *bits)
600{
601 return 1 + bits->end_bit - bits->start_bit;
602}
603
604static uint64_t calc_option_value(const struct fw_config_field *field,
605 const struct fw_config_option *option)
606{
607 uint64_t value = 0;
608 uint64_t original = option->value;
609
610 struct fw_config_field_bits *bits = field->bits;
611 while (bits) {
612 const unsigned int width = bits_width(bits);
613 const uint64_t orig_mask = (1ull << width) - 1ull;
614 const uint64_t orig = (original & orig_mask);
615 value |= (orig << bits->start_bit);
616
617 original >>= width;
618 bits = bits->next;
619 }
620
621 return value;
622}
623
Duncan Laurie47b7b342020-05-15 15:39:08 -0700624static void emit_fw_config(FILE *fil)
625{
626 struct fw_config_field *field = fw_config_fields;
627
628 if (!field)
629 return;
630
Duncan Laurie47b7b342020-05-15 15:39:08 -0700631 while (field) {
632 struct fw_config_option *option = field->options;
Tim Wawrzynczak24b4af62020-10-01 15:41:31 -0600633 uint64_t mask;
Duncan Laurie47b7b342020-05-15 15:39:08 -0700634
635 fprintf(fil, "#define FW_CONFIG_FIELD_%s_NAME \"%s\"\n",
636 field->name, field->name);
637
Tim Wawrzynczak13e240c2021-04-28 14:03:07 -0600638 mask = compute_fw_config_mask(field->bits);
Tim Wawrzynczak24b4af62020-10-01 15:41:31 -0600639 fprintf(fil, "#define FW_CONFIG_FIELD_%s_MASK 0x%" PRIx64 "\n",
Duncan Laurie47b7b342020-05-15 15:39:08 -0700640 field->name, mask);
641
642 while (option) {
Tim Wawrzynczak13e240c2021-04-28 14:03:07 -0600643 const uint64_t value = calc_option_value(field, option);
Duncan Laurie47b7b342020-05-15 15:39:08 -0700644 fprintf(fil, "#define FW_CONFIG_FIELD_%s_OPTION_%s_NAME \"%s\"\n",
645 field->name, option->name, option->name);
Tim Wawrzynczak24b4af62020-10-01 15:41:31 -0600646 fprintf(fil, "#define FW_CONFIG_FIELD_%s_OPTION_%s_VALUE 0x%"
Tim Wawrzynczak13e240c2021-04-28 14:03:07 -0600647 PRIx64 "\n", field->name, option->name, value);
Duncan Laurie47b7b342020-05-15 15:39:08 -0700648 option = option->next;
649 }
650
651 field = field->next;
652 }
653
654 fprintf(fil, "\n");
655}
656
657static int emit_fw_config_probe(FILE *fil, struct device *dev)
658{
659 struct fw_config_probe *probe = dev->probe;
660
661 fprintf(fil, "STORAGE struct fw_config %s_probe_list[] = {\n", dev->name);
662
663 while (probe) {
664 /* Find matching field. */
665 struct fw_config_field *field;
666 struct fw_config_option *option;
Tim Wawrzynczak24b4af62020-10-01 15:41:31 -0600667 uint64_t mask, value;
Duncan Laurie47b7b342020-05-15 15:39:08 -0700668
669 field = find_fw_config_field(probe->field);
670 if (!field) {
671 printf("ERROR: fw_config_probe field %s not found\n", probe->field);
672 return -1;
673 }
674 option = find_fw_config_option(field, probe->option);
675 if (!option) {
676 printf("ERROR: fw_config_probe field %s option %s not found\n",
677 probe->field, probe->option);
678 return -1;
679 }
680
681 /* Fill out the probe structure with values from emit_fw_config(). */
682 fprintf(fil, "\t{\n");
683 fprintf(fil, "\t\t.field_name = FW_CONFIG_FIELD_%s_NAME,\n", probe->field);
684 fprintf(fil, "\t\t.option_name = FW_CONFIG_FIELD_%s_OPTION_%s_NAME,\n",
685 probe->field, probe->option);
686 fprintf(fil, "\t\t.mask = FW_CONFIG_FIELD_%s_MASK,\n", probe->field);
687 fprintf(fil, "\t\t.value = FW_CONFIG_FIELD_%s_OPTION_%s_VALUE,\n",
688 probe->field, probe->option);
689 fprintf(fil, "\t},\n");
690
691 probe = probe->next;
692 }
693
694 /* Add empty entry to mark end of list. */
695 fprintf(fil, "\t{ }\n};\n");
696 return 0;
697}
698
Furquan Shaikh93198262018-06-03 04:22:17 -0700699/*
700 * Allocate a new bus for the provided device.
701 * - If this is the first bus being allocated under this device, then its id
702 * is set to 0 and bus and last_bus are pointed to the newly allocated bus.
703 * - If this is not the first bus under this device, then its id is set to 1
704 * plus the id of last bus and newly allocated bus is added to the list of
705 * buses under the device. last_bus is updated to point to the newly
706 * allocated bus.
707 */
708static void alloc_bus(struct device *dev)
709{
710 struct bus *bus = S_ALLOC(sizeof(*bus));
711
712 bus->dev = dev;
713
714 if (dev->last_bus == NULL) {
715 bus->id = 0;
716 dev->bus = bus;
717 } else {
718 bus->id = dev->last_bus->id + 1;
719 dev->last_bus->next_bus = bus;
720 }
721
722 dev->last_bus = bus;
723}
724
725/*
726 * Allocate a new device under the given parent. This function allocates a new
727 * device structure under the provided parent bus and allocates a bus structure
728 * under the newly allocated device.
729 */
730static struct device *alloc_dev(struct bus *parent)
731{
732 struct device *dev = S_ALLOC(sizeof(*dev));
733
Furquan Shaikh93198262018-06-03 04:22:17 -0700734 dev->parent = parent;
735 dev->subsystem_vendor = -1;
736 dev->subsystem_device = -1;
737
738 alloc_bus(dev);
739
740 return dev;
741}
742
743/*
744 * This function scans the children of given bus to see if any device matches
745 * the new device that is requested.
746 *
747 * Returns pointer to the node if found, else NULL.
748 */
749static struct device *get_dev(struct bus *parent, int path_a, int path_b,
750 int bustype, struct chip_instance *chip_instance)
751{
752 struct device *child = parent->children;
753
754 while (child) {
755 if ((child->path_a == path_a) && (child->path_b == path_b) &&
756 (child->bustype == bustype) &&
757 (child->chip_instance == chip_instance))
758 return child;
759
760 child = child->sibling;
761 }
762
763 return NULL;
764}
765
Furquan Shaikh27efc502018-06-22 09:19:15 -0700766/*
767 * Add given node as child of the provided parent. If this is the first child of
768 * the parent, update parent->children pointer as well.
769 */
770static void set_new_child(struct bus *parent, struct device *child)
771{
772 struct device *c = parent->children;
773 if (c) {
774 while (c->sibling)
775 c = c->sibling;
776 c->sibling = child;
777 } else
778 parent->children = child;
779
780 child->sibling = NULL;
781 child->parent = parent;
782}
783
Nico Huber8e1ea522020-06-03 10:20:07 -0700784static const struct device *find_alias(const struct device *const parent,
785 const char *const alias)
786{
787 if (parent->alias && !strcmp(parent->alias, alias))
788 return parent;
789
790 const struct bus *bus;
791 for (bus = parent->bus; bus; bus = bus->next_bus) {
792 const struct device *child;
793 for (child = bus->children; child; child = child->sibling) {
794 const struct device *const ret = find_alias(child, alias);
795 if (ret)
796 return ret;
797 }
798 }
799
800 return NULL;
801}
802
Duncan Lauriee335c2e2020-07-29 16:28:43 -0700803static struct device *new_device_with_path(struct bus *parent,
804 struct chip_instance *chip_instance,
805 const int bustype, int path_a, int path_b,
806 char *alias, int status)
Martin Rothbec07532016-08-05 18:32:18 -0600807{
Furquan Shaikh93198262018-06-03 04:22:17 -0700808 struct device *new_d;
809
Furquan Shaikh93198262018-06-03 04:22:17 -0700810 /* If device is found under parent, no need to allocate new device. */
811 new_d = get_dev(parent, path_a, path_b, bustype, chip_instance);
812 if (new_d) {
813 alloc_bus(new_d);
814 return new_d;
815 }
816
817 new_d = alloc_dev(parent);
818
819 new_d->bustype = bustype;
820
821 new_d->path_a = path_a;
822 new_d->path_b = path_b;
Nico Huber8e1ea522020-06-03 10:20:07 -0700823 new_d->alias = alias;
Furquan Shaikh93198262018-06-03 04:22:17 -0700824
Hung-Te Lin936dbe12018-09-10 10:51:26 +0800825 new_d->enabled = status & 0x01;
826 new_d->hidden = (status >> 1) & 0x01;
Ronald G. Minnich466ca2c2019-10-22 02:02:24 +0000827 new_d->mandatory = (status >> 2) & 0x01;
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -0700828 new_d->chip_instance = chip_instance;
Patrick Georgi114e7b22010-05-05 11:19:50 +0000829
Furquan Shaikh27efc502018-06-22 09:19:15 -0700830 set_new_child(parent, new_d);
Patrick Georgi114e7b22010-05-05 11:19:50 +0000831
Furquan Shaikha9b64292018-05-31 07:52:00 -0700832 switch (bustype) {
Sven Schnelle0fa50a12012-06-21 22:19:48 +0200833 case PCI:
Patrick Georgi114e7b22010-05-05 11:19:50 +0000834 new_d->path = ".type=DEVICE_PATH_PCI,{.pci={ .devfn = PCI_DEVFN(0x%x,%d)}}";
Sven Schnelle0fa50a12012-06-21 22:19:48 +0200835 break;
836
837 case PNP:
Patrick Georgi114e7b22010-05-05 11:19:50 +0000838 new_d->path = ".type=DEVICE_PATH_PNP,{.pnp={ .port = 0x%x, .device = 0x%x }}";
Sven Schnelle0fa50a12012-06-21 22:19:48 +0200839 break;
840
841 case I2C:
Duncan Laurieb7ce5fe2016-05-07 19:49:37 -0700842 new_d->path = ".type=DEVICE_PATH_I2C,{.i2c={ .device = 0x%x, .mode_10bit = %d }}";
Sven Schnelle0fa50a12012-06-21 22:19:48 +0200843 break;
844
845 case APIC:
Patrick Georgi114e7b22010-05-05 11:19:50 +0000846 new_d->path = ".type=DEVICE_PATH_APIC,{.apic={ .apic_id = 0x%x }}";
Sven Schnelle0fa50a12012-06-21 22:19:48 +0200847 break;
848
Stefan Reinauer0aa37c42013-02-12 15:20:54 -0800849 case CPU_CLUSTER:
850 new_d->path = ".type=DEVICE_PATH_CPU_CLUSTER,{.cpu_cluster={ .cluster = 0x%x }}";
Sven Schnelle0fa50a12012-06-21 22:19:48 +0200851 break;
852
Aaron Durbinffda804b2014-09-03 12:40:15 -0500853 case CPU:
854 new_d->path = ".type=DEVICE_PATH_CPU,{.cpu={ .id = 0x%x }}";
855 break;
856
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800857 case DOMAIN:
858 new_d->path = ".type=DEVICE_PATH_DOMAIN,{.domain={ .domain = 0x%x }}";
Sven Schnelle0fa50a12012-06-21 22:19:48 +0200859 break;
860
861 case IOAPIC:
862 new_d->path = ".type=DEVICE_PATH_IOAPIC,{.ioapic={ .ioapic_id = 0x%x }}";
863 break;
Duncan Laurie4650f5b2016-05-07 20:01:34 -0700864
865 case GENERIC:
866 new_d->path = ".type=DEVICE_PATH_GENERIC,{.generic={ .id = 0x%x, .subid = 0x%x }}";
867 break;
Furquan Shaikhe6700292017-02-11 00:50:38 -0800868
869 case SPI:
870 new_d->path = ".type=DEVICE_PATH_SPI,{.spi={ .cs = 0x%x }}";
871 break;
872
Duncan Lauriebae9f852018-05-07 14:18:13 -0700873 case USB:
874 new_d->path = ".type=DEVICE_PATH_USB,{.usb={ .port_type = %d, .port_id = %d }}";
875 break;
876
Justin TerAvestca2ed9f2018-01-17 16:36:30 -0800877 case MMIO:
878 new_d->path = ".type=DEVICE_PATH_MMIO,{.mmio={ .addr = 0x%x }}";
879 break;
Raul E Rangel3f3f53c2020-05-06 11:47:04 -0600880
Michael Niewöhnerdbb667a2020-12-11 21:26:02 +0100881 case GPIO:
882 new_d->path = ".type=DEVICE_PATH_GPIO,{.gpio={ .id = 0x%x }}";
883 break;
Patrick Georgi114e7b22010-05-05 11:19:50 +0000884 }
Justin TerAvestca2ed9f2018-01-17 16:36:30 -0800885
Patrick Georgi114e7b22010-05-05 11:19:50 +0000886 return new_d;
887}
888
Duncan Lauriee335c2e2020-07-29 16:28:43 -0700889struct device *new_device_reference(struct bus *parent,
890 struct chip_instance *chip_instance,
891 const char *reference, int status)
892{
893 const struct device *dev = find_alias(&base_root_dev, reference);
894
895 if (!dev) {
896 printf("ERROR: Unable to find device reference %s\n", reference);
897 exit(1);
898 }
899
900 return new_device_with_path(parent, chip_instance, dev->bustype, dev->path_a,
901 dev->path_b, NULL, status);
902}
903
904struct device *new_device_raw(struct bus *parent,
905 struct chip_instance *chip_instance,
906 const int bustype, const char *devnum,
907 char *alias, int status)
908{
909 char *tmp;
910 int path_a;
911 int path_b = 0;
912
913 /* Check for alias name conflicts. */
914 if (alias && find_alias(root_parent->dev, alias)) {
915 printf("ERROR: Alias already exists: %s\n", alias);
916 exit(1);
917 }
918
919 path_a = strtol(devnum, &tmp, 16);
920 if (*tmp == '.') {
921 tmp++;
922 path_b = strtol(tmp, NULL, 16);
923 }
924
925 return new_device_with_path(parent, chip_instance, bustype, path_a, path_b, alias,
926 status);
927}
928
Furquan Shaikh27efc502018-06-22 09:19:15 -0700929static void new_resource(struct device *dev, int type, int index, int base)
Martin Rothbec07532016-08-05 18:32:18 -0600930{
Furquan Shaikh369e1f02018-05-31 09:48:51 -0700931 struct resource *r = S_ALLOC(sizeof(struct resource));
932
Patrick Georgi114e7b22010-05-05 11:19:50 +0000933 r->type = type;
934 r->index = index;
935 r->base = base;
Patrick Georgi68befd52010-05-05 12:05:25 +0000936 if (dev->res) {
937 struct resource *head = dev->res;
Martin Rothbec07532016-08-05 18:32:18 -0600938 while (head->next)
939 head = head->next;
Patrick Georgi114e7b22010-05-05 11:19:50 +0000940 head->next = r;
941 } else {
Patrick Georgi68befd52010-05-05 12:05:25 +0000942 dev->res = r;
Patrick Georgi114e7b22010-05-05 11:19:50 +0000943 }
Patrick Georgi114e7b22010-05-05 11:19:50 +0000944}
945
Furquan Shaikh27efc502018-06-22 09:19:15 -0700946void add_resource(struct bus *bus, int type, int index, int base)
947{
948 new_resource(bus->dev, type, index, base);
949}
950
Nico Huberd09459f2020-05-26 22:13:09 +0200951static void add_reg(struct reg **const head, char *const name, char *const val)
Martin Rothbec07532016-08-05 18:32:18 -0600952{
Nico Huberd09459f2020-05-26 22:13:09 +0200953 struct reg *const r = S_ALLOC(sizeof(struct reg));
954 struct reg *prev = NULL;
955 struct reg *cur;
Furquan Shaikh369e1f02018-05-31 09:48:51 -0700956
Patrick Georgi114e7b22010-05-05 11:19:50 +0000957 r->key = name;
958 r->value = val;
Nico Huberd09459f2020-05-26 22:13:09 +0200959
960 for (cur = *head; cur != NULL; prev = cur, cur = cur->next) {
961 const int sort = strcmp(r->key, cur->key);
Patrick Georgi114e7b22010-05-05 11:19:50 +0000962 if (sort == 0) {
Patrick Georgi51933122020-11-02 18:08:14 +0100963 printf("ERROR: duplicate 'register' key '%s'.\n", r->key);
Patrick Georgi114e7b22010-05-05 11:19:50 +0000964 exit(1);
965 }
Nico Huberd09459f2020-05-26 22:13:09 +0200966 if (sort < 0)
967 break;
Patrick Georgi114e7b22010-05-05 11:19:50 +0000968 }
Nico Huberd09459f2020-05-26 22:13:09 +0200969 r->next = cur;
970 if (prev)
971 prev->next = r;
972 else
973 *head = r;
974}
975
976void add_register(struct chip_instance *chip_instance, char *name, char *val)
977{
978 add_reg(&chip_instance->reg, name, val);
Patrick Georgi114e7b22010-05-05 11:19:50 +0000979}
980
Nico Huber8e1ea522020-06-03 10:20:07 -0700981void add_reference(struct chip_instance *const chip_instance,
982 char *const name, char *const alias)
983{
984 add_reg(&chip_instance->ref, name, alias);
985}
986
987static void set_reference(struct chip_instance *const chip_instance,
988 char *const name, char *const alias)
989{
990 const struct device *const dev = find_alias(&base_root_dev, alias);
991 if (!dev) {
992 printf("ERROR: Cannot find device alias '%s'.\n", alias);
993 exit(1);
994 }
995
996 char *const ref_name = S_ALLOC(strlen(dev->name) + 2);
997 sprintf(ref_name, "&%s", dev->name);
998 add_register(chip_instance, name, ref_name);
999}
1000
1001static void update_references(FILE *file, FILE *head, struct device *dev,
1002 struct device *next)
1003{
1004 struct reg *ref;
1005
1006 for (ref = dev->chip_instance->ref; ref; ref = ref->next)
1007 set_reference(dev->chip_instance, ref->key, ref->value);
1008}
1009
Patrick Rudolphac24d3c2019-04-12 14:42:17 +02001010void add_slot_desc(struct bus *bus, char *type, char *length, char *designation,
1011 char *data_width)
1012{
1013 struct device *dev = bus->dev;
1014
1015 if (dev->bustype != PCI && dev->bustype != DOMAIN) {
1016 printf("ERROR: 'slot_type' only allowed for PCI devices\n");
1017 exit(1);
1018 }
1019
1020 dev->smbios_slot_type = type;
1021 dev->smbios_slot_length = length;
1022 dev->smbios_slot_data_width = data_width;
1023 dev->smbios_slot_designation = designation;
1024}
1025
Furquan Shaikh93198262018-06-03 04:22:17 -07001026void add_pci_subsystem_ids(struct bus *bus, int vendor, int device,
Martin Rothbec07532016-08-05 18:32:18 -06001027 int inherit)
Sven Schnelle270a9082011-03-01 19:58:15 +00001028{
Furquan Shaikh93198262018-06-03 04:22:17 -07001029 struct device *dev = bus->dev;
1030
Stefan Reinauer4aff4452013-02-12 14:17:15 -08001031 if (dev->bustype != PCI && dev->bustype != DOMAIN) {
Sven Schnelle270a9082011-03-01 19:58:15 +00001032 printf("ERROR: 'subsystem' only allowed for PCI devices\n");
1033 exit(1);
1034 }
1035
1036 dev->subsystem_vendor = vendor;
1037 dev->subsystem_device = device;
1038 dev->inherit_subsystem = inherit;
1039}
1040
Furquan Shaikh93198262018-06-03 04:22:17 -07001041void add_ioapic_info(struct bus *bus, int apicid, const char *_srcpin,
Martin Rothbec07532016-08-05 18:32:18 -06001042 int irqpin)
Sven Schnelle0fa50a12012-06-21 22:19:48 +02001043{
Sven Schnelle0fa50a12012-06-21 22:19:48 +02001044 int srcpin;
Furquan Shaikh93198262018-06-03 04:22:17 -07001045 struct device *dev = bus->dev;
Sven Schnelle0fa50a12012-06-21 22:19:48 +02001046
Martin Rothbec07532016-08-05 18:32:18 -06001047 if (!_srcpin || strlen(_srcpin) < 4 || strncasecmp(_srcpin, "INT", 3) ||
1048 _srcpin[3] < 'A' || _srcpin[3] > 'D') {
Sven Schnelle0fa50a12012-06-21 22:19:48 +02001049 printf("ERROR: malformed ioapic_irq args: %s\n", _srcpin);
1050 exit(1);
1051 }
1052
1053 srcpin = _srcpin[3] - 'A';
1054
Stefan Reinauer4aff4452013-02-12 14:17:15 -08001055 if (dev->bustype != PCI && dev->bustype != DOMAIN) {
Sven Schnelle0fa50a12012-06-21 22:19:48 +02001056 printf("ERROR: ioapic config only allowed for PCI devices\n");
1057 exit(1);
1058 }
1059
1060 if (srcpin > 3) {
Patrick Georgi116327e2012-07-20 12:47:06 +02001061 printf("ERROR: srcpin '%d' invalid\n", srcpin);
Sven Schnelle0fa50a12012-06-21 22:19:48 +02001062 exit(1);
1063 }
1064 dev->pci_irq_info[srcpin].ioapic_irq_pin = irqpin;
1065 dev->pci_irq_info[srcpin].ioapic_dst_id = apicid;
1066}
1067
Furquan Shaikh93198262018-06-03 04:22:17 -07001068static int dev_has_children(struct device *dev)
Martin Rothbec07532016-08-05 18:32:18 -06001069{
Furquan Shaikh93198262018-06-03 04:22:17 -07001070 struct bus *bus = dev->bus;
1071
1072 while (bus) {
1073 if (bus->children)
1074 return 1;
1075 bus = bus->next_bus;
1076 }
1077
1078 return 0;
1079}
1080
Nico Huber17e9bcb2019-09-20 12:05:51 +02001081static void pass0(FILE *fil, FILE *head, struct device *ptr, struct device *next)
Furquan Shaikh93198262018-06-03 04:22:17 -07001082{
Furquan Shaikh4ebe9532020-05-02 15:34:42 -07001083 static int dev_id;
1084
Furquan Shaikhde39fc72018-06-11 04:26:45 -07001085 if (ptr == &base_root_dev) {
Kyösti Mälkki5ccce7c2019-03-15 10:04:11 +02001086 fprintf(fil, "STORAGE struct bus %s_links[];\n",
Furquan Shaikh93198262018-06-03 04:22:17 -07001087 ptr->name);
1088 return;
1089 }
1090
Furquan Shaikh4ebe9532020-05-02 15:34:42 -07001091 char *name = S_ALLOC(10);
1092 sprintf(name, "_dev%d", dev_id++);
1093 ptr->name = name;
1094
Kyösti Mälkki5ccce7c2019-03-15 10:04:11 +02001095 fprintf(fil, "STORAGE struct device %s;\n", ptr->name);
Furquan Shaikh4ca3a8a2018-06-07 23:36:45 -07001096 if (ptr->res)
Kyösti Mälkki5ccce7c2019-03-15 10:04:11 +02001097 fprintf(fil, "STORAGE struct resource %s_res[];\n",
Furquan Shaikh93198262018-06-03 04:22:17 -07001098 ptr->name);
1099 if (dev_has_children(ptr))
Kyösti Mälkki5ccce7c2019-03-15 10:04:11 +02001100 fprintf(fil, "STORAGE struct bus %s_links[];\n",
Martin Rothbec07532016-08-05 18:32:18 -06001101 ptr->name);
Stefan Reinauer57879c92012-07-31 16:47:25 -07001102
Furquan Shaikh93198262018-06-03 04:22:17 -07001103 if (next)
1104 return;
1105
1106 fprintf(fil,
1107 "DEVTREE_CONST struct device * DEVTREE_CONST last_dev = &%s;\n",
1108 ptr->name);
Patrick Georgi114e7b22010-05-05 11:19:50 +00001109}
1110
Angel Ponsd56d2a82021-09-03 16:55:25 +02001111static void emit_smbios_data(FILE *fil, struct device *ptr)
1112{
1113 fprintf(fil, "#if !DEVTREE_EARLY\n");
1114 fprintf(fil, "#if CONFIG(GENERATE_SMBIOS_TABLES)\n");
1115
1116 /* SMBIOS types start at 1, if zero it hasn't been set */
1117 if (ptr->smbios_slot_type)
1118 fprintf(fil, "\t.smbios_slot_type = %s,\n",
1119 ptr->smbios_slot_type);
1120 if (ptr->smbios_slot_data_width)
1121 fprintf(fil, "\t.smbios_slot_data_width = %s,\n",
1122 ptr->smbios_slot_data_width);
1123 if (ptr->smbios_slot_designation)
1124 fprintf(fil, "\t.smbios_slot_designation = \"%s\",\n",
1125 ptr->smbios_slot_designation);
1126 if (ptr->smbios_slot_length)
1127 fprintf(fil, "\t.smbios_slot_length = %s,\n",
1128 ptr->smbios_slot_length);
1129
1130 fprintf(fil, "#endif\n");
1131 fprintf(fil, "#endif\n");
1132}
1133
Furquan Shaikh93198262018-06-03 04:22:17 -07001134static void emit_resources(FILE *fil, struct device *ptr)
1135{
Furquan Shaikh4ca3a8a2018-06-07 23:36:45 -07001136 if (ptr->res == NULL)
Furquan Shaikh93198262018-06-03 04:22:17 -07001137 return;
1138
1139 int i = 1;
Kyösti Mälkki5ccce7c2019-03-15 10:04:11 +02001140 fprintf(fil, "STORAGE struct resource %s_res[] = {\n", ptr->name);
Furquan Shaikh93198262018-06-03 04:22:17 -07001141 struct resource *r = ptr->res;
1142 while (r) {
1143 fprintf(fil,
1144 "\t\t{ .flags=IORESOURCE_FIXED | IORESOURCE_ASSIGNED | IORESOURCE_");
1145 if (r->type == IRQ)
1146 fprintf(fil, "IRQ");
1147 if (r->type == DRQ)
1148 fprintf(fil, "DRQ");
1149 if (r->type == IO)
1150 fprintf(fil, "IO");
1151 fprintf(fil, ", .index=0x%x, .base=0x%x,", r->index,
1152 r->base);
1153 if (r->next)
1154 fprintf(fil, ".next=&%s_res[%d]},\n", ptr->name,
1155 i++);
1156 else
1157 fprintf(fil, ".next=NULL },\n");
1158 r = r->next;
1159 }
1160
1161 fprintf(fil, "\t };\n");
1162}
1163
1164static void emit_bus(FILE *fil, struct bus *bus)
1165{
1166 fprintf(fil, "\t\t[%d] = {\n", bus->id);
1167 fprintf(fil, "\t\t\t.link_num = %d,\n", bus->id);
1168 fprintf(fil, "\t\t\t.dev = &%s,\n", bus->dev->name);
1169 if (bus->children)
1170 fprintf(fil, "\t\t\t.children = &%s,\n", bus->children->name);
1171
1172 if (bus->next_bus)
1173 fprintf(fil, "\t\t\t.next=&%s_links[%d],\n", bus->dev->name,
1174 bus->id + 1);
1175 else
1176 fprintf(fil, "\t\t\t.next = NULL,\n");
1177 fprintf(fil, "\t\t},\n");
1178}
1179
1180static void emit_dev_links(FILE *fil, struct device *ptr)
1181{
Kyösti Mälkki5ccce7c2019-03-15 10:04:11 +02001182 fprintf(fil, "STORAGE struct bus %s_links[] = {\n",
Furquan Shaikh93198262018-06-03 04:22:17 -07001183 ptr->name);
1184
1185 struct bus *bus = ptr->bus;
1186
1187 while (bus) {
1188 emit_bus(fil, bus);
1189 bus = bus->next_bus;
1190 }
1191
1192 fprintf(fil, "\t};\n");
1193}
1194
Furquan Shaikhfceca922021-01-06 22:36:59 -08001195static struct chip_instance *get_chip_instance(const struct device *dev)
Sven Schnelle0fa50a12012-06-21 22:19:48 +02001196{
Furquan Shaikhfceca922021-01-06 22:36:59 -08001197 struct chip_instance *chip_ins = dev->chip_instance;
Furquan Shaikhbbade242020-05-02 16:05:29 -07001198 /*
1199 * If the chip instance of device has base_chip_instance pointer set, then follow that
1200 * to update the chip instance for current device.
1201 */
1202 if (chip_ins->base_chip_instance)
1203 chip_ins = chip_ins->base_chip_instance;
1204
Furquan Shaikhfceca922021-01-06 22:36:59 -08001205 return chip_ins;
1206}
1207
1208static void pass1(FILE *fil, FILE *head, struct device *ptr, struct device *next)
1209{
1210 int pin;
1211 struct chip_instance *chip_ins = get_chip_instance(ptr);
1212 int has_children = dev_has_children(ptr);
1213
Duncan Laurie47b7b342020-05-15 15:39:08 -07001214 /* Emit probe structures. */
1215 if (ptr->probe && (emit_fw_config_probe(fil, ptr) < 0)) {
Tim Wawrzynczakba4a4902020-09-23 15:36:30 -06001216 if (head)
1217 fclose(head);
Duncan Laurie47b7b342020-05-15 15:39:08 -07001218 fclose(fil);
1219 exit(1);
1220 }
1221
Kyösti Mälkki5ccce7c2019-03-15 10:04:11 +02001222 if (ptr == &base_root_dev)
1223 fprintf(fil, "DEVTREE_CONST struct device %s = {\n", ptr->name);
1224 else
1225 fprintf(fil, "STORAGE struct device %s = {\n", ptr->name);
1226
Furquan Shaikh93198262018-06-03 04:22:17 -07001227 fprintf(fil, "#if !DEVTREE_EARLY\n");
Furquan Shaikh50ddc0b2018-06-23 00:59:31 -07001228
1229 /*
1230 * ops field is set to default_dev_ops_root only for the root
1231 * device. For all other devices, it is set by the driver at runtime.
1232 */
1233 if (ptr == &base_root_dev)
1234 fprintf(fil, "\t.ops = &default_dev_ops_root,\n");
1235 else
1236 fprintf(fil, "\t.ops = NULL,\n");
Furquan Shaikh93198262018-06-03 04:22:17 -07001237 fprintf(fil, "#endif\n");
1238 fprintf(fil, "\t.bus = &%s_links[%d],\n", ptr->parent->dev->name,
1239 ptr->parent->id);
1240 fprintf(fil, "\t.path = {");
1241 fprintf(fil, ptr->path, ptr->path_a, ptr->path_b);
1242 fprintf(fil, "},\n");
1243 fprintf(fil, "\t.enabled = %d,\n", ptr->enabled);
Hung-Te Lin936dbe12018-09-10 10:51:26 +08001244 fprintf(fil, "\t.hidden = %d,\n", ptr->hidden);
Ronald G. Minnich466ca2c2019-10-22 02:02:24 +00001245 fprintf(fil, "\t.mandatory = %d,\n", ptr->mandatory);
Furquan Shaikh93198262018-06-03 04:22:17 -07001246 fprintf(fil, "\t.on_mainboard = 1,\n");
1247 if (ptr->subsystem_vendor > 0)
1248 fprintf(fil, "\t.subsystem_vendor = 0x%04x,\n",
1249 ptr->subsystem_vendor);
Sven Schnelle270a9082011-03-01 19:58:15 +00001250
Furquan Shaikh93198262018-06-03 04:22:17 -07001251 if (ptr->subsystem_device > 0)
1252 fprintf(fil, "\t.subsystem_device = 0x%04x,\n",
1253 ptr->subsystem_device);
1254
Furquan Shaikh4ca3a8a2018-06-07 23:36:45 -07001255 if (ptr->res) {
Furquan Shaikh93198262018-06-03 04:22:17 -07001256 fprintf(fil, "\t.resource_list = &%s_res[0],\n",
Martin Rothbec07532016-08-05 18:32:18 -06001257 ptr->name);
Furquan Shaikh93198262018-06-03 04:22:17 -07001258 }
1259 if (has_children)
1260 fprintf(fil, "\t.link_list = &%s_links[0],\n",
1261 ptr->name);
1262 else
1263 fprintf(fil, "\t.link_list = NULL,\n");
1264 if (ptr->sibling)
1265 fprintf(fil, "\t.sibling = &%s,\n", ptr->sibling->name);
Aaron Durbind47afe92020-03-26 12:29:35 -06001266 else
1267 fprintf(fil, "\t.sibling = NULL,\n");
Duncan Laurie47b7b342020-05-15 15:39:08 -07001268 if (ptr->probe)
1269 fprintf(fil, "\t.probe_list = %s_probe_list,\n", ptr->name);
Furquan Shaikhe59ad2e2021-05-22 07:36:58 -07001270 fprintf(fil, "#if !DEVTREE_EARLY\n");
Kyösti Mälkki1557a672019-06-30 10:51:31 +03001271 for (pin = 0; pin < 4; pin++) {
1272 if (ptr->pci_irq_info[pin].ioapic_irq_pin > 0)
1273 fprintf(fil,
1274 "\t.pci_irq_info[%d].ioapic_irq_pin = %d,\n",
1275 pin, ptr->pci_irq_info[pin].ioapic_irq_pin);
1276
1277 if (ptr->pci_irq_info[pin].ioapic_dst_id > 0)
1278 fprintf(fil,
1279 "\t.pci_irq_info[%d].ioapic_dst_id = %d,\n",
1280 pin, ptr->pci_irq_info[pin].ioapic_dst_id);
1281 }
Furquan Shaikh93198262018-06-03 04:22:17 -07001282 fprintf(fil, "\t.chip_ops = &%s_ops,\n",
1283 chip_ins->chip->name_underscore);
1284 if (chip_ins == &mainboard_instance)
1285 fprintf(fil, "\t.name = mainboard_name,\n");
1286 fprintf(fil, "#endif\n");
1287 if (chip_ins->chip->chiph_exists)
1288 fprintf(fil, "\t.chip_info = &%s_info_%d,\n",
1289 chip_ins->chip->name_underscore, chip_ins->id);
1290 if (next)
Patrick Rudolphac24d3c2019-04-12 14:42:17 +02001291 fprintf(fil, "\t.next=&%s,\n", next->name);
Angel Ponsd56d2a82021-09-03 16:55:25 +02001292
1293 emit_smbios_data(fil, ptr);
1294
Furquan Shaikh93198262018-06-03 04:22:17 -07001295 fprintf(fil, "};\n");
1296
1297 emit_resources(fil, ptr);
1298
1299 if (has_children)
1300 emit_dev_links(fil, ptr);
1301}
1302
Nico Huber17e9bcb2019-09-20 12:05:51 +02001303static void expose_device_names(FILE *fil, FILE *head, struct device *ptr, struct device *next)
Kyösti Mälkki5e2a2cd2019-03-15 17:44:23 +02001304{
Furquan Shaikhfceca922021-01-06 22:36:59 -08001305 struct chip_instance *chip_ins = get_chip_instance(ptr);
1306
Kyösti Mälkki5e2a2cd2019-03-15 17:44:23 +02001307 /* Only devices on root bus here. */
Nico Huber17e9bcb2019-09-20 12:05:51 +02001308 if (ptr->bustype == PCI && ptr->parent->dev->bustype == DOMAIN) {
Furquan Shaikh708f25e2021-01-08 09:54:54 -08001309 fprintf(head, "extern DEVTREE_CONST struct device *const __pci_0_%02x_%d;\n",
Nico Huber17e9bcb2019-09-20 12:05:51 +02001310 ptr->path_a, ptr->path_b);
Furquan Shaikh708f25e2021-01-08 09:54:54 -08001311 fprintf(fil, "DEVTREE_CONST struct device *const __pci_0_%02x_%d = &%s;\n",
Kyösti Mälkki5e2a2cd2019-03-15 17:44:23 +02001312 ptr->path_a, ptr->path_b, ptr->name);
Furquan Shaikhfceca922021-01-06 22:36:59 -08001313
1314 if (chip_ins->chip->chiph_exists) {
1315 fprintf(head, "extern DEVTREE_CONST void *const __pci_0_%02x_%d_config;\n",
1316 ptr->path_a, ptr->path_b);
1317 fprintf(fil, "DEVTREE_CONST void *const __pci_0_%02x_%d_config = &%s_info_%d;\n",
1318 ptr->path_a, ptr->path_b, chip_ins->chip->name_underscore, chip_ins->id);
1319 }
Nico Huber17e9bcb2019-09-20 12:05:51 +02001320 }
Kyösti Mälkki5e2a2cd2019-03-15 17:44:23 +02001321
Nico Huber17e9bcb2019-09-20 12:05:51 +02001322 if (ptr->bustype == PNP) {
Furquan Shaikh708f25e2021-01-08 09:54:54 -08001323 fprintf(head, "extern DEVTREE_CONST struct device *const __pnp_%04x_%02x;\n",
Nico Huber17e9bcb2019-09-20 12:05:51 +02001324 ptr->path_a, ptr->path_b);
Furquan Shaikh708f25e2021-01-08 09:54:54 -08001325 fprintf(fil, "DEVTREE_CONST struct device *const __pnp_%04x_%02x = &%s;\n",
Kyösti Mälkki5e2a2cd2019-03-15 17:44:23 +02001326 ptr->path_a, ptr->path_b, ptr->name);
Nico Huber17e9bcb2019-09-20 12:05:51 +02001327 }
Kyösti Mälkki5e2a2cd2019-03-15 17:44:23 +02001328}
1329
Furquan Shaikh93198262018-06-03 04:22:17 -07001330static void add_siblings_to_queue(struct queue_entry **bfs_q_head,
1331 struct device *d)
1332{
1333 while (d) {
1334 enqueue_tail(bfs_q_head, d);
1335 d = d->sibling;
1336 }
1337}
1338
1339static void add_children_to_queue(struct queue_entry **bfs_q_head,
1340 struct device *d)
1341{
1342 struct bus *bus = d->bus;
1343
1344 while (bus) {
1345 if (bus->children)
1346 add_siblings_to_queue(bfs_q_head, bus->children);
1347 bus = bus->next_bus;
Myles Watson894a3472010-06-09 22:41:35 +00001348 }
Patrick Georgi114e7b22010-05-05 11:19:50 +00001349}
1350
Nico Huber17e9bcb2019-09-20 12:05:51 +02001351static void walk_device_tree(FILE *fil, FILE *head, struct device *ptr,
1352 void (*func)(FILE *, FILE *, struct device *,
Furquan Shaikh93198262018-06-03 04:22:17 -07001353 struct device *))
Martin Rothbec07532016-08-05 18:32:18 -06001354{
Furquan Shaikh93198262018-06-03 04:22:17 -07001355 struct queue_entry *bfs_q_head = NULL;
1356
1357 enqueue_tail(&bfs_q_head, ptr);
1358
1359 while ((ptr = dequeue_head(&bfs_q_head))) {
1360 add_children_to_queue(&bfs_q_head, ptr);
Nico Huber17e9bcb2019-09-20 12:05:51 +02001361 func(fil, head, ptr, peek_queue_head(bfs_q_head));
Furquan Shaikh93198262018-06-03 04:22:17 -07001362 }
Patrick Georgi114e7b22010-05-05 11:19:50 +00001363}
1364
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -07001365static void emit_chip_headers(FILE *fil, struct chip *chip)
Furquan Shaikha0cc5a62018-05-30 23:46:16 -07001366{
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -07001367 struct chip *tmp = chip;
Furquan Shaikha0cc5a62018-05-30 23:46:16 -07001368
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -07001369 while (chip) {
1370 if (chip->chiph_exists)
1371 fprintf(fil, "#include \"%s/chip.h\"\n", chip->name);
1372 chip = chip->next;
Furquan Shaikha0cc5a62018-05-30 23:46:16 -07001373 }
1374 fprintf(fil, "\n#if !DEVTREE_EARLY\n");
1375 fprintf(fil,
1376 "__attribute__((weak)) struct chip_operations mainboard_ops = {};\n");
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -07001377
1378 chip = tmp;
1379 while (chip) {
Kyösti Mälkkib2a10f82019-08-17 06:28:40 +03001380 /* A lot of cpus do not define chip_operations at all, and the ones
1381 that do only initialise .name. */
1382 if (strstr(chip->name_underscore, "cpu_") == chip->name_underscore) {
1383 fprintf(fil,
1384 "__attribute__((weak)) struct chip_operations %s_ops = {};\n",
1385 chip->name_underscore);
1386 } else {
1387 fprintf(fil, "extern struct chip_operations %s_ops;\n",
1388 chip->name_underscore);
1389 }
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -07001390 chip = chip->next;
Furquan Shaikha0cc5a62018-05-30 23:46:16 -07001391 }
1392 fprintf(fil, "#endif\n");
1393}
1394
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -07001395static void emit_chip_instance(FILE *fil, struct chip_instance *instance)
1396{
Kyösti Mälkki5ccce7c2019-03-15 10:04:11 +02001397 fprintf(fil, "STORAGE struct %s_config %s_info_%d = {",
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -07001398 instance->chip->name_underscore,
1399 instance->chip->name_underscore,
1400 instance->id);
1401
1402 if (instance->reg) {
1403 fprintf(fil, "\n");
1404 struct reg *r = instance->reg;
1405 while (r) {
1406 fprintf(fil, "\t.%s = %s,\n", r->key, r->value);
1407 r = r->next;
1408 }
1409 }
1410 fprintf(fil, "};\n\n");
1411}
1412
Nico Huber8e1ea522020-06-03 10:20:07 -07001413static void emit_chip_configs(FILE *fil)
Furquan Shaikh79e84122018-05-30 15:09:09 -07001414{
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -07001415 struct chip *chip = chip_header.next;
1416 struct chip_instance *instance;
Furquan Shaikh9f681d22020-05-02 15:51:02 -07001417 int chip_id;
Furquan Shaikh79e84122018-05-30 15:09:09 -07001418
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -07001419 for (; chip; chip = chip->next) {
Furquan Shaikh79e84122018-05-30 15:09:09 -07001420 if (!chip->chiph_exists)
1421 continue;
1422
Furquan Shaikh9f681d22020-05-02 15:51:02 -07001423 chip_id = 1;
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -07001424 instance = chip->instance;
1425 while (instance) {
Furquan Shaikhbbade242020-05-02 16:05:29 -07001426 /*
1427 * Emit this chip instance only if there is no forwarding pointer to the
1428 * base tree chip instance.
1429 */
1430 if (instance->base_chip_instance == NULL) {
1431 instance->id = chip_id++;
1432 emit_chip_instance(fil, instance);
1433 }
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -07001434 instance = instance->next;
Furquan Shaikh79e84122018-05-30 15:09:09 -07001435 }
1436 }
1437}
1438
Nico Huber17e9bcb2019-09-20 12:05:51 +02001439static void inherit_subsystem_ids(FILE *file, FILE *head, struct device *dev,
Furquan Shaikh93198262018-06-03 04:22:17 -07001440 struct device *next)
Sven Schnelle270a9082011-03-01 19:58:15 +00001441{
1442 struct device *p;
Sven Schnelle270a9082011-03-01 19:58:15 +00001443
1444 if (dev->subsystem_vendor != -1 && dev->subsystem_device != -1) {
1445 /* user already gave us a subsystem vendor/device */
1446 return;
1447 }
1448
Furquan Shaikh93198262018-06-03 04:22:17 -07001449 for (p = dev; p && p->parent->dev != p; p = p->parent->dev) {
Sven Schnelle270a9082011-03-01 19:58:15 +00001450
Stefan Reinauer4aff4452013-02-12 14:17:15 -08001451 if (p->bustype != PCI && p->bustype != DOMAIN)
Sven Schnelle270a9082011-03-01 19:58:15 +00001452 continue;
1453
1454 if (p->inherit_subsystem) {
1455 dev->subsystem_vendor = p->subsystem_vendor;
1456 dev->subsystem_device = p->subsystem_device;
1457 break;
1458 }
1459 }
1460}
1461
Kyösti Mälkki472d9022011-12-05 20:33:55 +02001462static void usage(void)
1463{
Duncan Laurie51c83732020-06-09 11:20:29 -07001464 printf("usage: sconfig <options>\n");
1465 printf(" -c | --output_c : Path to output static.c file (required)\n");
1466 printf(" -r | --output_h : Path to header static.h file (required)\n");
Tim Wawrzynczakba4a4902020-09-23 15:36:30 -06001467 printf(" -d | --output_d : Path to header static_devices.h file (required)\n");
1468 printf(" -f | --output_f : Path to header static_fw_config.h file (required)\n");
Duncan Laurie51c83732020-06-09 11:20:29 -07001469 printf(" -m | --mainboard_devtree : Path to mainboard devicetree file (required)\n");
1470 printf(" -o | --override_devtree : Path to override devicetree file (optional)\n");
Duncan Lauriee335c2e2020-07-29 16:28:43 -07001471 printf(" -p | --chipset_devtree : Path to chipset/SOC devicetree file (optional)\n");
Tim Wawrzynczakba4a4902020-09-23 15:36:30 -06001472
Martin Rothbec07532016-08-05 18:32:18 -06001473 exit(1);
Kyösti Mälkki472d9022011-12-05 20:33:55 +02001474}
1475
Furquan Shaikhde39fc72018-06-11 04:26:45 -07001476static void parse_devicetree(const char *file, struct bus *parent)
Martin Rothbec07532016-08-05 18:32:18 -06001477{
Furquan Shaikhde39fc72018-06-11 04:26:45 -07001478 FILE *filec = fopen(file, "r");
Stefan Reinauer7c1f6b82010-08-16 18:21:56 +00001479 if (!filec) {
Stefan Reinauer7c1f6b82010-08-16 18:21:56 +00001480 perror(NULL);
1481 exit(1);
1482 }
1483
Patrick Georgi114e7b22010-05-05 11:19:50 +00001484 yyrestart(filec);
1485
Furquan Shaikhde39fc72018-06-11 04:26:45 -07001486 root_parent = parent;
1487 linenum = 0;
1488
Patrick Georgi114e7b22010-05-05 11:19:50 +00001489 yyparse();
Stefan Reinauer7c1f6b82010-08-16 18:21:56 +00001490
Patrick Georgi114e7b22010-05-05 11:19:50 +00001491 fclose(filec);
Furquan Shaikhde39fc72018-06-11 04:26:45 -07001492}
1493
Furquan Shaikhb9c22e02021-08-23 23:23:23 -07001494static int device_probe_count(struct fw_config_probe *probe)
1495{
1496 int count = 0;
1497 while (probe) {
1498 probe = probe->next;
1499 count++;
1500 }
1501
1502 return count;
1503}
1504
1505/*
1506 * When overriding devices, use the following rules:
1507 * 1. If probe count matches and:
1508 * a. Entire probe list matches for both devices -> Same device, override.
1509 * b. No probe entries match -> Different devices, do not override.
1510 * c. Partial list matches -> Bad device tree entries, fail build.
1511 *
1512 * 2. If probe counts do not match and:
1513 * a. No probe entries match -> Different devices, do not override.
1514 * b. Partial list matches -> Bad device tree entries, fail build.
1515 */
1516static int device_probes_match(struct device *a, struct device *b)
1517{
1518 struct fw_config_probe *a_probe = a->probe;
1519 struct fw_config_probe *b_probe = b->probe;
1520 int a_probe_count = device_probe_count(a_probe);
1521 int b_probe_count = device_probe_count(b_probe);
1522 int match_count = 0;
1523
1524 while (a_probe) {
1525 if (check_probe_exists(b_probe, a_probe->field, a_probe->option))
1526 match_count++;
1527 a_probe = a_probe->next;
1528 }
1529
1530 if ((a_probe_count == b_probe_count) && (a_probe_count == match_count))
1531 return 1;
1532
1533 if (match_count) {
1534 printf("ERROR: devices with overlapping probes: ");
1535 printf(a->path, a->path_a, a->path_b);
1536 printf(b->path, b->path_a, b->path_b);
1537 printf("\n");
1538 exit(1);
1539 }
1540
1541 return 0;
1542}
1543
Furquan Shaikh27efc502018-06-22 09:19:15 -07001544/*
1545 * Match device nodes from base and override tree to see if they are the same
1546 * node.
1547 */
1548static int device_match(struct device *a, struct device *b)
1549{
1550 return ((a->path_a == b->path_a) &&
1551 (a->path_b == b->path_b) &&
1552 (a->bustype == b->bustype) &&
1553 (a->chip_instance->chip ==
1554 b->chip_instance->chip));
1555}
1556
1557/*
Bill XIEc61d4152019-11-21 18:16:12 +08001558 * Match resource nodes from base and override tree to see if they are the same
1559 * node.
1560 */
1561static int res_match(struct resource *a, struct resource *b)
1562{
1563 return ((a->type == b->type) &&
1564 (a->index == b->index));
1565}
1566
1567/*
Furquan Shaikh27efc502018-06-22 09:19:15 -07001568 * Add resource to device. If resource is already present, then update its base
1569 * and index. If not, then add a new resource to the device.
1570 */
1571static void update_resource(struct device *dev, struct resource *res)
1572{
1573 struct resource *base_res = dev->res;
1574
1575 while (base_res) {
Bill XIEc61d4152019-11-21 18:16:12 +08001576 if (res_match(base_res, res)) {
Furquan Shaikh27efc502018-06-22 09:19:15 -07001577 base_res->base = res->base;
1578 return;
1579 }
1580 base_res = base_res->next;
1581 }
1582
1583 new_resource(dev, res->type, res->index, res->base);
1584}
1585
1586/*
1587 * Add register to chip instance. If register is already present, then update
1588 * its value. If not, then add a new register to the chip instance.
1589 */
Nico Huber8e1ea522020-06-03 10:20:07 -07001590static void update_register(struct reg **const head, struct reg *reg)
Furquan Shaikh27efc502018-06-22 09:19:15 -07001591{
Nico Huber8e1ea522020-06-03 10:20:07 -07001592 struct reg *base_reg = *head;
Furquan Shaikh27efc502018-06-22 09:19:15 -07001593
1594 while (base_reg) {
1595 if (!strcmp(base_reg->key, reg->key)) {
1596 base_reg->value = reg->value;
1597 return;
1598 }
1599 base_reg = base_reg->next;
1600 }
1601
Nico Huber8e1ea522020-06-03 10:20:07 -07001602 add_reg(head, reg->key, reg->value);
Furquan Shaikh27efc502018-06-22 09:19:15 -07001603}
1604
1605static void override_devicetree(struct bus *base_parent,
1606 struct bus *override_parent);
1607
1608/*
1609 * Update the base device properties using the properties of override device. In
1610 * addition to that, call override_devicetree for all the buses under the
1611 * override device.
1612 *
1613 * Override Rules:
1614 * +--------------------+--------------------------------------------+
1615 * | | |
1616 * |struct device member| Rule |
1617 * | | |
1618 * +-----------------------------------------------------------------+
1619 * | | |
1620 * | id | Unchanged. This is used to generate device |
1621 * | | structure name in static.c. So, no need to |
1622 * | | override. |
1623 * | | |
1624 * +-----------------------------------------------------------------+
1625 * | | |
1626 * | enabled | Copy enabled state from override device. |
1627 * | | This allows variants to override device |
1628 * | | state. |
1629 * | | |
1630 * +-----------------------------------------------------------------+
1631 * | | |
1632 * | subsystem_vendor | Copy from override device only if any one |
1633 * | subsystem_device | of the ids is non-zero. |
1634 * | | |
1635 * +-----------------------------------------------------------------+
1636 * | | |
1637 * | inherit_subsystem | Copy from override device only if it is |
1638 * | | non-zero. This allows variant to only |
1639 * | | enable inherit flag for a device. |
1640 * | | |
1641 * +-----------------------------------------------------------------+
1642 * | | |
1643 * | path | Unchanged since these are same for both |
1644 * | path_a | base and override device (Used for |
1645 * | path_b | matching devices). |
1646 * | | |
1647 * +-----------------------------------------------------------------+
1648 * | | |
1649 * | bustype | Unchanged since this is same for both base |
1650 * | | and override device (User for matching |
1651 * | | devices). |
1652 * | | |
1653 * +-----------------------------------------------------------------+
1654 * | | |
1655 * | pci_irq_info | Unchanged. |
1656 * | | |
1657 * +-----------------------------------------------------------------+
1658 * | | |
1659 * | parent | Unchanged. This is meaningful only within |
1660 * | sibling | the parse tree, hence not being copied. |
1661 * | | |
1662 * +-----------------------------------------------------------------+
1663 * | | |
1664 * | res | Each resource that is present in override |
1665 * | | device is copied over to base device: |
Bill XIEc61d4152019-11-21 18:16:12 +08001666 * | | 1. If resource of same type and index is |
1667 * | | present in base device, then base of |
1668 * | | the resource is copied. |
Furquan Shaikh27efc502018-06-22 09:19:15 -07001669 * | | 2. If not, then a new resource is allocated|
1670 * | | under the base device using type, index |
1671 * | | and base from override res. |
1672 * | | |
1673 * +-----------------------------------------------------------------+
1674 * | | |
Nico Huber8e1ea522020-06-03 10:20:07 -07001675 * | ref | Each reference that is present in override |
1676 * | | device is copied over to base device with |
1677 * | | the same rules as registers. |
1678 * | | |
1679 * +-----------------------------------------------------------------+
1680 * | | |
1681 * | alias | Base device alias is copied to override. |
1682 * | | Override devices cannot change/remove an |
1683 * | | existing alias, but they can add an alias |
1684 * | | if one does not exist. |
1685 * | | |
1686 * +-----------------------------------------------------------------+
1687 * | | |
Frans Hendriks3a7db272021-01-20 07:40:05 +01001688 * | smbios_slot info | Copy SMBIOS slot information from override.|
1689 * | | This allows variants to override PCI(e) |
1690 * | | slot information in SMBIOS tables. |
1691 * | | |
1692 * +-----------------------------------------------------------------+
1693 * | | |
Furquan Shaikh27efc502018-06-22 09:19:15 -07001694 * | chip_instance | Each register of chip_instance is copied |
1695 * | | over from override device to base device: |
1696 * | | 1. If register with same key is present in |
1697 * | | base device, then value of the register |
1698 * | | is copied. |
1699 * | | 2. If not, then a new register is allocated|
1700 * | | under the base chip_instance using key |
1701 * | | and value from override register. |
1702 * | | |
1703 * +-----------------------------------------------------------------+
1704 * | | |
1705 * | bus | Recursively call override_devicetree on |
1706 * | last_bus | each bus of override device. It is assumed |
1707 * | | that bus with id X under base device |
1708 * | | to bus with id X under override device. If |
1709 * | | override device has more buses than base |
1710 * | | device, then new buses are allocated under |
1711 * | | base device. |
1712 * | | |
1713 * +-----------------------------------------------------------------+
1714 */
1715static void update_device(struct device *base_dev, struct device *override_dev)
1716{
1717 /*
1718 * Copy the enabled state of override device to base device. This allows
1719 * override tree to enable or disable a particular device.
1720 */
1721 base_dev->enabled = override_dev->enabled;
1722
1723 /*
Duncan Laurie7f6a4842020-10-28 14:22:34 -07001724 * Copy the hidden state of override device to base device. This allows
1725 * override tree to hide or unhide a particular device.
1726 */
1727 base_dev->hidden = override_dev->hidden;
1728
1729 /*
Furquan Shaikh27efc502018-06-22 09:19:15 -07001730 * Copy subsystem vendor and device ids from override device to base
1731 * device only if the ids are non-zero in override device. Else, honor
1732 * the values in base device.
1733 */
1734 if (override_dev->subsystem_vendor ||
1735 override_dev->subsystem_device) {
1736 base_dev->subsystem_vendor = override_dev->subsystem_vendor;
1737 base_dev->subsystem_device = override_dev->subsystem_device;
1738 }
1739
1740 /*
1741 * Copy value of inherity_subsystem from override device to base device
1742 * only if it is non-zero in override device. This allows override
1743 * tree to only enable inhert flag for a device.
1744 */
1745 if (override_dev->inherit_subsystem)
1746 base_dev->inherit_subsystem = override_dev->inherit_subsystem;
1747
1748 /*
1749 * Copy resources of override device to base device.
1750 * 1. If resource is already present in base device, then index and base
1751 * of the resource will be copied over.
1752 * 2. If resource is not already present in base device, a new resource
1753 * will be allocated.
1754 */
1755 struct resource *res = override_dev->res;
1756 while (res) {
1757 update_resource(base_dev, res);
1758 res = res->next;
1759 }
1760
1761 /*
1762 * Copy registers of override chip instance to base chip instance.
1763 * 1. If register key is already present in base chip instance, then
1764 * value for the register is copied over.
1765 * 2. If register key is not already present in base chip instance, then
1766 * a new register will be allocated.
1767 */
1768 struct reg *reg = override_dev->chip_instance->reg;
1769 while (reg) {
Nico Huber8e1ea522020-06-03 10:20:07 -07001770 update_register(&base_dev->chip_instance->reg, reg);
Furquan Shaikh27efc502018-06-22 09:19:15 -07001771 reg = reg->next;
1772 }
1773
Nico Huber8e1ea522020-06-03 10:20:07 -07001774 /* Copy references just as with registers. */
1775 reg = override_dev->chip_instance->ref;
1776 while (reg) {
1777 update_register(&base_dev->chip_instance->ref, reg);
1778 reg = reg->next;
1779 }
1780
1781 /* Check for alias name conflicts. */
1782 if (override_dev->alias && find_alias(&base_root_dev, override_dev->alias)) {
1783 printf("ERROR: alias already exists: %s\n", override_dev->alias);
1784 exit(1);
1785 }
1786
1787 /*
1788 * Copy alias from base device.
1789 *
1790 * Override devices cannot change/remove an existing alias,
1791 * but they can add an alias to a device if one does not exist yet.
1792 */
1793 if (base_dev->alias)
1794 override_dev->alias = base_dev->alias;
1795 else
1796 base_dev->alias = override_dev->alias;
1797
Furquan Shaikh27efc502018-06-22 09:19:15 -07001798 /*
Duncan Laurie47b7b342020-05-15 15:39:08 -07001799 * Use probe list from override device in place of base device, in order
1800 * to allow an override to remove a probe from the base device.
1801 */
1802 base_dev->probe = override_dev->probe;
1803
Frans Hendriks3a7db272021-01-20 07:40:05 +01001804 /* Copy SMBIOS slot information from base device */
1805 base_dev->smbios_slot_type = override_dev->smbios_slot_type;
1806 base_dev->smbios_slot_length = override_dev->smbios_slot_length;
1807 base_dev->smbios_slot_data_width = override_dev->smbios_slot_data_width;
1808 base_dev->smbios_slot_designation = override_dev->smbios_slot_designation;
1809
Duncan Laurie47b7b342020-05-15 15:39:08 -07001810 /*
Furquan Shaikhbbade242020-05-02 16:05:29 -07001811 * Update base_chip_instance member in chip instance of override tree to forward it to
1812 * the chip instance in base tree.
1813 */
Furquan Shaikh9d1bf812021-02-17 19:07:18 -08001814 override_dev->chip_instance->base_chip_instance = get_chip_instance(base_dev);
Furquan Shaikhbbade242020-05-02 16:05:29 -07001815
1816 /*
Furquan Shaikh27efc502018-06-22 09:19:15 -07001817 * Now that the device properties are all copied over, look at each bus
1818 * of the override device and run override_devicetree in a recursive
1819 * manner. The assumption here is that first bus of override device
1820 * corresponds to first bus of base device and so on. If base device has
1821 * lesser buses than override tree, then new buses are allocated for it.
1822 */
1823 struct bus *override_bus = override_dev->bus;
1824 struct bus *base_bus = base_dev->bus;
1825
1826 while (override_bus) {
1827
1828 /*
1829 * If we have more buses in override tree device, then allocate
1830 * a new bus for the base tree device as well.
1831 */
1832 if (!base_bus) {
1833 alloc_bus(base_dev);
1834 base_bus = base_dev->last_bus;
1835 }
1836
1837 override_devicetree(base_dev->bus, override_dev->bus);
1838
1839 override_bus = override_bus->next_bus;
1840 base_bus = base_bus->next_bus;
1841 }
Furquan Shaikh27efc502018-06-22 09:19:15 -07001842}
1843
1844/*
1845 * Perform copy of device and properties from override parent to base parent.
1846 * This function walks through the override tree in a depth-first manner
1847 * performing following actions:
1848 * 1. If matching device is found in base tree, then copy the properties of
1849 * override device to base tree device. Call override_devicetree recursively on
1850 * the bus of override device.
1851 * 2. If matching device is not found in base tree, then set override tree
1852 * device as new child of base_parent and update the chip pointers in override
1853 * device subtree to ensure the nodes do not point to override tree chip
1854 * instance.
1855 */
1856static void override_devicetree(struct bus *base_parent,
1857 struct bus *override_parent)
1858{
1859 struct device *base_child;
1860 struct device *override_child = override_parent->children;
1861 struct device *next_child;
1862
1863 while (override_child) {
1864
1865 /* Look for a matching device in base tree. */
1866 for (base_child = base_parent->children;
1867 base_child; base_child = base_child->sibling) {
Furquan Shaikhb9c22e02021-08-23 23:23:23 -07001868 if (!device_match(base_child, override_child))
1869 continue;
1870 /* If base device has no probe statement, nothing else to compare. */
1871 if (base_child->probe == NULL)
1872 break;
1873 /*
1874 * If base device has probe statements, ensure that all probe conditions
1875 * match for base and override device.
1876 */
1877 if (device_probes_match(base_child, override_child))
Furquan Shaikh27efc502018-06-22 09:19:15 -07001878 break;
1879 }
1880
1881 next_child = override_child->sibling;
1882
1883 /*
1884 * If matching device is found, copy properties of
1885 * override_child to base_child.
1886 */
1887 if (base_child)
1888 update_device(base_child, override_child);
1889 else {
1890 /*
1891 * If matching device is not found, set override_child
1892 * as a new child of base_parent.
1893 */
1894 set_new_child(base_parent, override_child);
Furquan Shaikh27efc502018-06-22 09:19:15 -07001895 }
1896
1897 override_child = next_child;
1898 }
1899}
1900
Duncan Lauriecbd0bd82020-06-09 11:24:10 -07001901static void parse_override_devicetree(const char *file, struct device *dev)
1902{
1903 parse_devicetree(file, dev->bus);
1904
1905 if (!dev_has_children(dev)) {
1906 fprintf(stderr, "ERROR: Override tree needs at least one device!\n");
1907 exit(1);
1908 }
1909
1910 override_devicetree(&base_root_bus, dev->bus);
1911}
1912
Tim Wawrzynczakba4a4902020-09-23 15:36:30 -06001913static void generate_outputh(FILE *f, const char *fw_conf_header, const char *device_header)
1914{
1915 fprintf(f, "#ifndef __STATIC_DEVICE_TREE_H\n");
1916 fprintf(f, "#define __STATIC_DEVICE_TREE_H\n\n");
1917
1918 fprintf(f, "#include <%s>\n", fw_conf_header);
1919 fprintf(f, "#include <%s>\n\n", device_header);
1920
1921 fprintf(f, "\n#endif /* __STATIC_DEVICE_TREE_H */\n");
1922}
1923
1924static void generate_outputc(FILE *f, const char *static_header)
1925{
1926 fprintf(f, "#include <device/device.h>\n");
1927 fprintf(f, "#include <device/pci.h>\n");
1928 fprintf(f, "#include <fw_config.h>\n");
1929 fprintf(f, "#include <%s>\n", static_header);
1930 emit_chip_headers(f, chip_header.next);
1931 fprintf(f, "\n#define STORAGE static __unused DEVTREE_CONST\n\n");
1932
1933 walk_device_tree(NULL, NULL, &base_root_dev, inherit_subsystem_ids);
1934 fprintf(f, "\n/* pass 0 */\n");
1935 walk_device_tree(f, NULL, &base_root_dev, pass0);
1936 walk_device_tree(NULL, NULL, &base_root_dev, update_references);
1937 fprintf(f, "\n/* chip configs */\n");
1938 emit_chip_configs(f);
1939 fprintf(f, "\n/* pass 1 */\n");
1940 walk_device_tree(f, NULL, &base_root_dev, pass1);
1941}
1942
1943static void generate_outputd(FILE *gen, FILE *dev)
1944{
1945 fprintf(dev, "#ifndef __STATIC_DEVICES_H\n");
1946 fprintf(dev, "#define __STATIC_DEVICES_H\n\n");
1947 fprintf(dev, "#include <device/device.h>\n\n");
1948 fprintf(dev, "/* expose_device_names */\n");
1949 walk_device_tree(gen, dev, &base_root_dev, expose_device_names);
1950 fprintf(dev, "\n#endif /* __STATIC_DEVICE_NAMES_H */\n");
1951}
1952
1953static void generate_outputf(FILE *f)
1954{
1955 fprintf(f, "#ifndef __STATIC_FW_CONFIG_H\n");
1956 fprintf(f, "#define __STATIC_FW_CONFIG_H\n\n");
1957 emit_fw_config(f);
1958 fprintf(f, "\n#endif /* __STATIC_FW_CONFIG_H */\n");
1959}
1960
Furquan Shaikhde39fc72018-06-11 04:26:45 -07001961int main(int argc, char **argv)
1962{
Duncan Laurie51c83732020-06-09 11:20:29 -07001963 static const struct option long_options[] = {
1964 { "mainboard_devtree", 1, NULL, 'm' },
1965 { "override_devtree", 1, NULL, 'o' },
Duncan Lauriee335c2e2020-07-29 16:28:43 -07001966 { "chipset_devtree", 1, NULL, 'p' },
Duncan Laurie51c83732020-06-09 11:20:29 -07001967 { "output_c", 1, NULL, 'c' },
1968 { "output_h", 1, NULL, 'r' },
Tim Wawrzynczakba4a4902020-09-23 15:36:30 -06001969 { "output_d", 1, NULL, 'd' },
1970 { "output_f", 1, NULL, 'f' },
Duncan Laurie51c83732020-06-09 11:20:29 -07001971 { "help", 1, NULL, 'h' },
1972 { }
1973 };
1974 const char *override_devtree = NULL;
1975 const char *base_devtree = NULL;
Duncan Lauriee335c2e2020-07-29 16:28:43 -07001976 const char *chipset_devtree = NULL;
Duncan Laurie51c83732020-06-09 11:20:29 -07001977 const char *outputc = NULL;
1978 const char *outputh = NULL;
Tim Wawrzynczakba4a4902020-09-23 15:36:30 -06001979 const char *outputd = NULL;
1980 const char *outputf = NULL;
Duncan Laurie51c83732020-06-09 11:20:29 -07001981 int opt, option_index;
Furquan Shaikhde39fc72018-06-11 04:26:45 -07001982
Tim Wawrzynczakba4a4902020-09-23 15:36:30 -06001983 while ((opt = getopt_long(argc, argv, "m:o:p:c:r:d:f:h", long_options,
Duncan Laurie51c83732020-06-09 11:20:29 -07001984 &option_index)) != EOF) {
1985 switch (opt) {
1986 case 'm':
1987 base_devtree = strdup(optarg);
1988 break;
1989 case 'o':
1990 override_devtree = strdup(optarg);
1991 break;
Duncan Lauriee335c2e2020-07-29 16:28:43 -07001992 case 'p':
1993 chipset_devtree = strdup(optarg);
1994 break;
Duncan Laurie51c83732020-06-09 11:20:29 -07001995 case 'c':
1996 outputc = strdup(optarg);
1997 break;
1998 case 'r':
1999 outputh = strdup(optarg);
2000 break;
Tim Wawrzynczakba4a4902020-09-23 15:36:30 -06002001 case 'd':
2002 outputd = strdup(optarg);
2003 break;
2004 case 'f':
2005 outputf = strdup(optarg);
2006 break;
Duncan Laurie51c83732020-06-09 11:20:29 -07002007 case 'h':
2008 default:
2009 usage();
2010 }
2011 }
2012
Tim Wawrzynczakba4a4902020-09-23 15:36:30 -06002013 if (!base_devtree || !outputc || !outputh || !outputd || !outputf)
Duncan Laurie51c83732020-06-09 11:20:29 -07002014 usage();
Furquan Shaikhde39fc72018-06-11 04:26:45 -07002015
Duncan Lauriee335c2e2020-07-29 16:28:43 -07002016 if (chipset_devtree) {
2017 /* Use the chipset devicetree as the base, then override
2018 with the mainboard "base" devicetree. */
2019 parse_devicetree(chipset_devtree, &base_root_bus);
2020 parse_override_devicetree(base_devtree, &chipset_root_dev);
2021 } else {
2022 parse_devicetree(base_devtree, &base_root_bus);
2023 }
Patrick Georgi114e7b22010-05-05 11:19:50 +00002024
Duncan Lauriecbd0bd82020-06-09 11:24:10 -07002025 if (override_devtree)
2026 parse_override_devicetree(override_devtree, &override_root_dev);
Furquan Shaikh39ac7972018-06-21 18:44:32 -07002027
Tim Wawrzynczak13e240c2021-04-28 14:03:07 -06002028
Kyösti Mälkki472d9022011-12-05 20:33:55 +02002029 FILE *autogen = fopen(outputc, "w");
2030 if (!autogen) {
Martin Rothbec07532016-08-05 18:32:18 -06002031 fprintf(stderr, "Could not open file '%s' for writing: ",
2032 outputc);
Stefan Reinauer7c1f6b82010-08-16 18:21:56 +00002033 perror(NULL);
2034 exit(1);
2035 }
2036
Nico Huber17e9bcb2019-09-20 12:05:51 +02002037 FILE *autohead = fopen(outputh, "w");
2038 if (!autohead) {
2039 fprintf(stderr, "Could not open file '%s' for writing: ", outputh);
2040 perror(NULL);
2041 fclose(autogen);
2042 exit(1);
2043 }
Nico Huber17e9bcb2019-09-20 12:05:51 +02002044
Tim Wawrzynczakba4a4902020-09-23 15:36:30 -06002045 FILE *autodev = fopen(outputd, "w");
2046 if (!autodev) {
2047 fprintf(stderr, "Could not open file '%s' for writing: ", outputd);
2048 perror(NULL);
2049 fclose(autogen);
2050 fclose(autohead);
2051 exit(1);
2052 }
Furquan Shaikh79e84122018-05-30 15:09:09 -07002053
Tim Wawrzynczakba4a4902020-09-23 15:36:30 -06002054 FILE *autofwconf = fopen(outputf, "w");
2055 if (!autofwconf) {
2056 fprintf(stderr, "Could not open file '%s' for writing: ", outputf);
2057 perror(NULL);
2058 fclose(autogen);
2059 fclose(autohead);
2060 fclose(autodev);
2061 exit(1);
2062 }
Sven Schnelle270a9082011-03-01 19:58:15 +00002063
Tim Wawrzynczakba4a4902020-09-23 15:36:30 -06002064 char *f = strdup(outputf);
2065 assert(f);
2066 char *d = strdup(outputd);
2067 assert(d);
2068 char *h = strdup(outputh);
2069 assert(h);
Kyösti Mälkki5e2a2cd2019-03-15 17:44:23 +02002070
Tim Wawrzynczakba4a4902020-09-23 15:36:30 -06002071 const char *fw_conf_header = basename(f);
2072 const char *device_header = basename(d);
2073 const char *static_header = basename(h);
2074
2075 generate_outputh(autohead, fw_conf_header, device_header);
2076 generate_outputc(autogen, static_header);
2077 generate_outputd(autogen, autodev);
2078 generate_outputf(autofwconf);
2079
Nico Huber17e9bcb2019-09-20 12:05:51 +02002080 fclose(autohead);
Kyösti Mälkki472d9022011-12-05 20:33:55 +02002081 fclose(autogen);
Tim Wawrzynczakba4a4902020-09-23 15:36:30 -06002082 fclose(autodev);
2083 fclose(autofwconf);
2084 free(f);
2085 free(d);
2086 free(h);
Stefan Reinauer7c1f6b82010-08-16 18:21:56 +00002087
Patrick Georgi114e7b22010-05-05 11:19:50 +00002088 return 0;
2089}