Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 1 | /* |
| 2 | * sconfig, coreboot device tree compiler |
| 3 | * |
| 4 | * Copyright (C) 2010 coresystems GmbH |
Stefan Reinauer | 2e78aa5 | 2016-05-07 01:11:14 -0700 | [diff] [blame] | 5 | * written by Patrick Georgi <patrick@georgi-clan.de> |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 15 | */ |
| 16 | |
Patrick Georgi | 2dbfcb7 | 2012-05-30 16:26:30 +0200 | [diff] [blame] | 17 | #include <ctype.h> |
Werner Zeh | ac14a40 | 2019-07-11 12:47:19 +0200 | [diff] [blame] | 18 | /* stat.h needs to be included before commonlib/helpers.h to avoid errors.*/ |
| 19 | #include <sys/stat.h> |
Kyösti Mälkki | e29a6ac | 2019-03-15 17:05:19 +0200 | [diff] [blame] | 20 | #include <commonlib/helpers.h> |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 21 | #include "sconfig.h" |
| 22 | #include "sconfig.tab.h" |
| 23 | |
Patrick Georgi | 7fc9e29 | 2010-07-15 15:59:07 +0000 | [diff] [blame] | 24 | extern int linenum; |
| 25 | |
Furquan Shaikh | 27efc50 | 2018-06-22 09:19:15 -0700 | [diff] [blame] | 26 | /* |
| 27 | * Maintains list of all the unique chip structures for the board. |
| 28 | * This is shared across base and override device trees since we need to |
| 29 | * generate headers for all chips added by both the trees. |
| 30 | */ |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 31 | static struct chip chip_header; |
Furquan Shaikh | 79e8412 | 2018-05-30 15:09:09 -0700 | [diff] [blame] | 32 | |
Kyösti Mälkki | 472d902 | 2011-12-05 20:33:55 +0200 | [diff] [blame] | 33 | typedef enum { |
Kyösti Mälkki | 1a2a6ee | 2012-03-18 20:19:28 +0200 | [diff] [blame] | 34 | UNSLASH, |
| 35 | SPLIT_1ST, |
| 36 | TO_LOWER, |
| 37 | TO_UPPER, |
| 38 | } translate_t; |
| 39 | |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 40 | /* |
| 41 | * Mainboard is assumed to have a root device whose bus is the parent of all the |
| 42 | * devices that are added by parsing the devicetree file. This device has a |
| 43 | * mainboard chip instance associated with it. |
| 44 | * |
| 45 | * |
| 46 | * |
| 47 | * +------------------------+ +----------------------+ |
Furquan Shaikh | de39fc7 | 2018-06-11 04:26:45 -0700 | [diff] [blame] | 48 | * | Root device | | Mainboard | |
| 49 | * +---------+ (base_root_dev) +--------------->+ instance + |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 50 | * | | | chip_instance | (mainboard_instance)| |
| 51 | * | +------------------------+ | | |
| 52 | * | | +----------------------+ |
| 53 | * | | bus | |
| 54 | * | parent v | |
| 55 | * | +-------------------+ | |
| 56 | * | | Root bus | | |
Furquan Shaikh | de39fc7 | 2018-06-11 04:26:45 -0700 | [diff] [blame] | 57 | * +----------->+ (base_root_bus) | | |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 58 | * | | | |
| 59 | * +-------------------+ | |
| 60 | * | | |
| 61 | * | children | chip |
| 62 | * v | |
| 63 | * X | |
| 64 | * (new devices will | |
| 65 | * be added here as | |
| 66 | * children) | |
| 67 | * | |
| 68 | * | |
| 69 | * | |
| 70 | * +-------+----------+ |
| 71 | * | | |
| 72 | * | Mainboard chip +----------->X (new chips will be |
| 73 | * | (mainboard_chip) | added here) |
| 74 | * | | |
| 75 | * +------------------+ |
| 76 | * |
| 77 | * |
| 78 | */ |
Furquan Shaikh | 39ac797 | 2018-06-21 18:44:32 -0700 | [diff] [blame] | 79 | |
| 80 | /* Root device of primary tree. */ |
Furquan Shaikh | de39fc7 | 2018-06-11 04:26:45 -0700 | [diff] [blame] | 81 | static struct device base_root_dev; |
Furquan Shaikh | 39ac797 | 2018-06-21 18:44:32 -0700 | [diff] [blame] | 82 | |
| 83 | /* Root device of override tree (if applicable). */ |
| 84 | static struct device override_root_dev; |
| 85 | |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 86 | static struct chip_instance mainboard_instance; |
| 87 | |
Furquan Shaikh | de39fc7 | 2018-06-11 04:26:45 -0700 | [diff] [blame] | 88 | static struct bus base_root_bus = { |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 89 | .id = 0, |
Furquan Shaikh | de39fc7 | 2018-06-11 04:26:45 -0700 | [diff] [blame] | 90 | .dev = &base_root_dev, |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 91 | }; |
| 92 | |
Furquan Shaikh | de39fc7 | 2018-06-11 04:26:45 -0700 | [diff] [blame] | 93 | static struct device base_root_dev = { |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 94 | .name = "dev_root", |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 95 | .chip_instance = &mainboard_instance, |
| 96 | .path = " .type = DEVICE_PATH_ROOT ", |
Furquan Shaikh | de39fc7 | 2018-06-11 04:26:45 -0700 | [diff] [blame] | 97 | .parent = &base_root_bus, |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 98 | .enabled = 1, |
Furquan Shaikh | de39fc7 | 2018-06-11 04:26:45 -0700 | [diff] [blame] | 99 | .bus = &base_root_bus, |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 100 | }; |
| 101 | |
Furquan Shaikh | 39ac797 | 2018-06-21 18:44:32 -0700 | [diff] [blame] | 102 | static struct bus override_root_bus = { |
| 103 | .id = 0, |
| 104 | .dev = &override_root_dev, |
| 105 | }; |
| 106 | |
| 107 | static struct device override_root_dev = { |
| 108 | .name = "override_root", |
Furquan Shaikh | 39ac797 | 2018-06-21 18:44:32 -0700 | [diff] [blame] | 109 | /* |
| 110 | * Override tree root device points to the same mainboard chip instance |
| 111 | * as the base tree root device. It should not cause any side-effects |
| 112 | * since the mainboard chip instance pointer in override tree will just |
| 113 | * be ignored. |
| 114 | */ |
| 115 | .chip_instance = &mainboard_instance, |
| 116 | .path = " .type = DEVICE_PATH_ROOT ", |
Furquan Shaikh | 39ac797 | 2018-06-21 18:44:32 -0700 | [diff] [blame] | 117 | .parent = &override_root_bus, |
| 118 | .enabled = 1, |
| 119 | .bus = &override_root_bus, |
| 120 | }; |
| 121 | |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 122 | static struct chip mainboard_chip = { |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 123 | .name = "mainboard", |
| 124 | .name_underscore = "mainboard", |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 125 | .instance = &mainboard_instance, |
| 126 | }; |
| 127 | |
| 128 | static struct chip_instance mainboard_instance = { |
| 129 | .id = 0, |
| 130 | .chip = &mainboard_chip, |
Furquan Shaikh | 27efc50 | 2018-06-22 09:19:15 -0700 | [diff] [blame] | 131 | .ref_count = 2, |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 132 | }; |
| 133 | |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 134 | /* 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] | 135 | struct bus *root_parent; |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 136 | |
Furquan Shaikh | 7398ded | 2018-06-03 10:42:49 -0700 | [diff] [blame] | 137 | struct queue_entry { |
Furquan Shaikh | 79e8412 | 2018-05-30 15:09:09 -0700 | [diff] [blame] | 138 | void *data; |
Furquan Shaikh | 7398ded | 2018-06-03 10:42:49 -0700 | [diff] [blame] | 139 | struct queue_entry *next; |
| 140 | struct queue_entry *prev; |
| 141 | }; |
Furquan Shaikh | 79e8412 | 2018-05-30 15:09:09 -0700 | [diff] [blame] | 142 | |
Furquan Shaikh | 369e1f0 | 2018-05-31 09:48:51 -0700 | [diff] [blame] | 143 | #define S_ALLOC(_s) s_alloc(__func__, _s) |
Furquan Shaikh | 79e8412 | 2018-05-30 15:09:09 -0700 | [diff] [blame] | 144 | |
Furquan Shaikh | 369e1f0 | 2018-05-31 09:48:51 -0700 | [diff] [blame] | 145 | static void *s_alloc(const char *f, size_t s) |
| 146 | { |
| 147 | void *data = calloc(1, s); |
| 148 | if (!data) { |
Maulik V Vaghela | 82e8c69 | 2018-06-08 10:32:08 +0530 | [diff] [blame] | 149 | fprintf(stderr, "%s: Failed to alloc mem!\n", f); |
Furquan Shaikh | 79e8412 | 2018-05-30 15:09:09 -0700 | [diff] [blame] | 150 | exit(1); |
| 151 | } |
Furquan Shaikh | 369e1f0 | 2018-05-31 09:48:51 -0700 | [diff] [blame] | 152 | return data; |
| 153 | } |
| 154 | |
Furquan Shaikh | 7398ded | 2018-06-03 10:42:49 -0700 | [diff] [blame] | 155 | static struct queue_entry *new_queue_entry(void *data) |
Furquan Shaikh | 369e1f0 | 2018-05-31 09:48:51 -0700 | [diff] [blame] | 156 | { |
Furquan Shaikh | 7398ded | 2018-06-03 10:42:49 -0700 | [diff] [blame] | 157 | struct queue_entry *e = S_ALLOC(sizeof(*e)); |
Furquan Shaikh | 79e8412 | 2018-05-30 15:09:09 -0700 | [diff] [blame] | 158 | |
| 159 | e->data = data; |
| 160 | e->next = e->prev = e; |
| 161 | return e; |
| 162 | } |
| 163 | |
Furquan Shaikh | 7398ded | 2018-06-03 10:42:49 -0700 | [diff] [blame] | 164 | static void enqueue_tail(struct queue_entry **q_head, void *data) |
Furquan Shaikh | 79e8412 | 2018-05-30 15:09:09 -0700 | [diff] [blame] | 165 | { |
Furquan Shaikh | 7398ded | 2018-06-03 10:42:49 -0700 | [diff] [blame] | 166 | struct queue_entry *tmp = new_queue_entry(data); |
| 167 | struct queue_entry *q = *q_head; |
Furquan Shaikh | 79e8412 | 2018-05-30 15:09:09 -0700 | [diff] [blame] | 168 | |
| 169 | if (!q) { |
Furquan Shaikh | 7398ded | 2018-06-03 10:42:49 -0700 | [diff] [blame] | 170 | *q_head = tmp; |
Furquan Shaikh | 79e8412 | 2018-05-30 15:09:09 -0700 | [diff] [blame] | 171 | return; |
| 172 | } |
| 173 | |
| 174 | q->prev->next = tmp; |
| 175 | tmp->prev = q->prev; |
| 176 | q->prev = tmp; |
| 177 | tmp->next = q; |
| 178 | } |
| 179 | |
Furquan Shaikh | 7398ded | 2018-06-03 10:42:49 -0700 | [diff] [blame] | 180 | static void *dequeue_tail(struct queue_entry **q_head) |
Furquan Shaikh | 79e8412 | 2018-05-30 15:09:09 -0700 | [diff] [blame] | 181 | { |
Furquan Shaikh | 7398ded | 2018-06-03 10:42:49 -0700 | [diff] [blame] | 182 | struct queue_entry *q = *q_head; |
| 183 | struct queue_entry *tmp; |
Furquan Shaikh | 79e8412 | 2018-05-30 15:09:09 -0700 | [diff] [blame] | 184 | void *data; |
| 185 | |
Furquan Shaikh | 7398ded | 2018-06-03 10:42:49 -0700 | [diff] [blame] | 186 | if (!q) |
| 187 | return NULL; |
| 188 | |
| 189 | tmp = q->prev; |
| 190 | |
Furquan Shaikh | 79e8412 | 2018-05-30 15:09:09 -0700 | [diff] [blame] | 191 | if (tmp == q) |
Furquan Shaikh | 7398ded | 2018-06-03 10:42:49 -0700 | [diff] [blame] | 192 | *q_head = NULL; |
Furquan Shaikh | 79e8412 | 2018-05-30 15:09:09 -0700 | [diff] [blame] | 193 | else { |
| 194 | tmp->prev->next = q; |
| 195 | q->prev = tmp->prev; |
| 196 | } |
| 197 | |
| 198 | data = tmp->data; |
| 199 | free(tmp); |
| 200 | |
| 201 | return data; |
| 202 | } |
| 203 | |
Furquan Shaikh | 7398ded | 2018-06-03 10:42:49 -0700 | [diff] [blame] | 204 | static void *dequeue_head(struct queue_entry **q_head) |
| 205 | { |
| 206 | struct queue_entry *q = *q_head; |
| 207 | struct queue_entry *tmp = q; |
| 208 | void *data; |
| 209 | |
| 210 | if (!q) |
| 211 | return NULL; |
| 212 | |
| 213 | if (q->next == q) |
| 214 | *q_head = NULL; |
| 215 | else { |
| 216 | q->next->prev = q->prev; |
| 217 | q->prev->next = q->next; |
| 218 | *q_head = q->next; |
| 219 | } |
| 220 | |
| 221 | data = tmp->data; |
| 222 | free(tmp); |
| 223 | |
| 224 | return data; |
| 225 | } |
| 226 | |
| 227 | static void *peek_queue_head(struct queue_entry *q_head) |
| 228 | { |
| 229 | if (!q_head) |
| 230 | return NULL; |
| 231 | |
| 232 | return q_head->data; |
| 233 | } |
| 234 | |
| 235 | static struct queue_entry *chip_q_head; |
| 236 | |
| 237 | void chip_enqueue_tail(void *data) |
| 238 | { |
| 239 | enqueue_tail(&chip_q_head, data); |
| 240 | } |
| 241 | |
| 242 | void *chip_dequeue_tail(void) |
| 243 | { |
| 244 | return dequeue_tail(&chip_q_head); |
| 245 | } |
| 246 | |
Martin Roth | bec0753 | 2016-08-05 18:32:18 -0600 | [diff] [blame] | 247 | int yywrap(void) |
| 248 | { |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 249 | return 1; |
| 250 | } |
| 251 | |
Martin Roth | bec0753 | 2016-08-05 18:32:18 -0600 | [diff] [blame] | 252 | void yyerror(char const *str) |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 253 | { |
Stefan Reinauer | 7c1f6b8 | 2010-08-16 18:21:56 +0000 | [diff] [blame] | 254 | extern char *yytext; |
Martin Roth | bec0753 | 2016-08-05 18:32:18 -0600 | [diff] [blame] | 255 | fprintf(stderr, "line %d: %s: %s\n", linenum + 1, yytext, str); |
Stefan Reinauer | 7c1f6b8 | 2010-08-16 18:21:56 +0000 | [diff] [blame] | 256 | exit(1); |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 257 | } |
| 258 | |
Martin Roth | bec0753 | 2016-08-05 18:32:18 -0600 | [diff] [blame] | 259 | char *translate_name(const char *str, translate_t mode) |
Kyösti Mälkki | 472d902 | 2011-12-05 20:33:55 +0200 | [diff] [blame] | 260 | { |
Kyösti Mälkki | 1a2a6ee | 2012-03-18 20:19:28 +0200 | [diff] [blame] | 261 | char *b, *c; |
| 262 | b = c = strdup(str); |
| 263 | while (c && *c) { |
| 264 | if ((mode == SPLIT_1ST) && (*c == '/')) { |
| 265 | *c = 0; |
| 266 | break; |
| 267 | } |
Martin Roth | bec0753 | 2016-08-05 18:32:18 -0600 | [diff] [blame] | 268 | if (*c == '/') |
| 269 | *c = '_'; |
| 270 | if (*c == '-') |
| 271 | *c = '_'; |
Kyösti Mälkki | 1a2a6ee | 2012-03-18 20:19:28 +0200 | [diff] [blame] | 272 | if (mode == TO_UPPER) |
Kyösti Mälkki | 472d902 | 2011-12-05 20:33:55 +0200 | [diff] [blame] | 273 | *c = toupper(*c); |
Kyösti Mälkki | 1a2a6ee | 2012-03-18 20:19:28 +0200 | [diff] [blame] | 274 | if (mode == TO_LOWER) |
| 275 | *c = tolower(*c); |
| 276 | c++; |
Kyösti Mälkki | 472d902 | 2011-12-05 20:33:55 +0200 | [diff] [blame] | 277 | } |
Kyösti Mälkki | 1a2a6ee | 2012-03-18 20:19:28 +0200 | [diff] [blame] | 278 | return b; |
Kyösti Mälkki | 472d902 | 2011-12-05 20:33:55 +0200 | [diff] [blame] | 279 | } |
| 280 | |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 281 | static struct chip *get_chip(char *path) |
Martin Roth | bec0753 | 2016-08-05 18:32:18 -0600 | [diff] [blame] | 282 | { |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 283 | struct chip *h = &chip_header; |
Furquan Shaikh | 79e8412 | 2018-05-30 15:09:09 -0700 | [diff] [blame] | 284 | |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 285 | while (h->next) { |
| 286 | int result = strcmp(path, h->next->name); |
| 287 | if (result == 0) |
| 288 | return h->next; |
| 289 | |
| 290 | if (result < 0) |
| 291 | break; |
| 292 | |
| 293 | h = h->next; |
| 294 | } |
| 295 | |
| 296 | struct chip *new_chip = S_ALLOC(sizeof(struct chip)); |
| 297 | new_chip->next = h->next; |
| 298 | h->next = new_chip; |
| 299 | |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 300 | new_chip->chiph_exists = 1; |
| 301 | new_chip->name = path; |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 302 | new_chip->name_underscore = translate_name(path, UNSLASH); |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 303 | |
| 304 | struct stat st; |
Furquan Shaikh | 369e1f0 | 2018-05-31 09:48:51 -0700 | [diff] [blame] | 305 | char *chip_h = S_ALLOC(strlen(path) + 18); |
Stefan Reinauer | 76c44ae | 2011-10-14 12:41:46 -0700 | [diff] [blame] | 306 | sprintf(chip_h, "src/%s", path); |
| 307 | if ((stat(chip_h, &st) == -1) && (errno == ENOENT)) { |
Patrick Georgi | 92bcaa2 | 2015-11-13 09:39:22 +0100 | [diff] [blame] | 308 | /* root_complex gets away without a separate directory, but |
| 309 | * exists on on pretty much all AMD chipsets. |
| 310 | */ |
| 311 | if (!strstr(path, "/root_complex")) { |
Kyösti Mälkki | 6aeb4a2 | 2013-06-11 17:00:11 +0300 | [diff] [blame] | 312 | fprintf(stderr, "ERROR: Chip component %s does not exist.\n", |
| 313 | path); |
| 314 | exit(1); |
| 315 | } |
Stefan Reinauer | 76c44ae | 2011-10-14 12:41:46 -0700 | [diff] [blame] | 316 | } |
| 317 | |
Martin Roth | 824255e | 2016-08-05 17:40:39 -0600 | [diff] [blame] | 318 | sprintf(chip_h, "src/%s/chip.h", path); |
Kyösti Mälkki | 472d902 | 2011-12-05 20:33:55 +0200 | [diff] [blame] | 319 | |
Martin Roth | 824255e | 2016-08-05 17:40:39 -0600 | [diff] [blame] | 320 | if ((stat(chip_h, &st) == -1) && (errno == ENOENT)) |
Martin Roth | bec0753 | 2016-08-05 18:32:18 -0600 | [diff] [blame] | 321 | new_chip->chiph_exists = 0; |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 322 | |
Patrick Georgi | 1f68880 | 2014-08-03 15:51:19 +0200 | [diff] [blame] | 323 | free(chip_h); |
Furquan Shaikh | 79e8412 | 2018-05-30 15:09:09 -0700 | [diff] [blame] | 324 | |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 325 | return new_chip; |
| 326 | } |
| 327 | |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 328 | struct chip_instance *new_chip_instance(char *path) |
| 329 | { |
| 330 | struct chip *chip = get_chip(path); |
| 331 | struct chip_instance *instance = S_ALLOC(sizeof(*instance)); |
| 332 | |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 333 | instance->chip = chip; |
| 334 | instance->next = chip->instance; |
| 335 | chip->instance = instance; |
| 336 | |
| 337 | return instance; |
| 338 | } |
| 339 | |
Furquan Shaikh | 27efc50 | 2018-06-22 09:19:15 -0700 | [diff] [blame] | 340 | static void delete_chip_instance(struct chip_instance *ins) |
| 341 | { |
| 342 | |
| 343 | if (ins->ref_count == 0) { |
| 344 | printf("ERROR: ref count for chip instance is zero!!\n"); |
| 345 | exit(1); |
| 346 | } |
| 347 | |
| 348 | if (--ins->ref_count) |
| 349 | return; |
| 350 | |
| 351 | struct chip *c = ins->chip; |
| 352 | |
| 353 | /* Get pointer to first instance of the chip. */ |
| 354 | struct chip_instance *i = c->instance; |
| 355 | |
| 356 | /* |
| 357 | * If chip instance to be deleted is the first instance, then update |
| 358 | * instance pointer of the chip as well. |
| 359 | */ |
| 360 | if (i == ins) { |
| 361 | c->instance = ins->next; |
| 362 | free(ins); |
| 363 | return; |
| 364 | } |
| 365 | |
| 366 | /* |
| 367 | * Loop through the instances list of the chip to find and remove the |
| 368 | * given instance. |
| 369 | */ |
| 370 | while (1) { |
| 371 | if (i == NULL) { |
| 372 | printf("ERROR: chip instance not found!\n"); |
| 373 | exit(1); |
| 374 | } |
| 375 | |
| 376 | if (i->next != ins) { |
| 377 | i = i->next; |
| 378 | continue; |
| 379 | } |
| 380 | |
| 381 | i->next = ins->next; |
| 382 | break; |
| 383 | } |
| 384 | |
| 385 | free(ins); |
| 386 | } |
| 387 | |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 388 | /* |
| 389 | * Allocate a new bus for the provided device. |
| 390 | * - If this is the first bus being allocated under this device, then its id |
| 391 | * is set to 0 and bus and last_bus are pointed to the newly allocated bus. |
| 392 | * - If this is not the first bus under this device, then its id is set to 1 |
| 393 | * plus the id of last bus and newly allocated bus is added to the list of |
| 394 | * buses under the device. last_bus is updated to point to the newly |
| 395 | * allocated bus. |
| 396 | */ |
| 397 | static void alloc_bus(struct device *dev) |
| 398 | { |
| 399 | struct bus *bus = S_ALLOC(sizeof(*bus)); |
| 400 | |
| 401 | bus->dev = dev; |
| 402 | |
| 403 | if (dev->last_bus == NULL) { |
| 404 | bus->id = 0; |
| 405 | dev->bus = bus; |
| 406 | } else { |
| 407 | bus->id = dev->last_bus->id + 1; |
| 408 | dev->last_bus->next_bus = bus; |
| 409 | } |
| 410 | |
| 411 | dev->last_bus = bus; |
| 412 | } |
| 413 | |
| 414 | /* |
| 415 | * Allocate a new device under the given parent. This function allocates a new |
| 416 | * device structure under the provided parent bus and allocates a bus structure |
| 417 | * under the newly allocated device. |
| 418 | */ |
| 419 | static struct device *alloc_dev(struct bus *parent) |
| 420 | { |
| 421 | struct device *dev = S_ALLOC(sizeof(*dev)); |
| 422 | |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 423 | dev->parent = parent; |
| 424 | dev->subsystem_vendor = -1; |
| 425 | dev->subsystem_device = -1; |
| 426 | |
| 427 | alloc_bus(dev); |
| 428 | |
| 429 | return dev; |
| 430 | } |
| 431 | |
| 432 | /* |
| 433 | * This function scans the children of given bus to see if any device matches |
| 434 | * the new device that is requested. |
| 435 | * |
| 436 | * Returns pointer to the node if found, else NULL. |
| 437 | */ |
| 438 | static struct device *get_dev(struct bus *parent, int path_a, int path_b, |
| 439 | int bustype, struct chip_instance *chip_instance) |
| 440 | { |
| 441 | struct device *child = parent->children; |
| 442 | |
| 443 | while (child) { |
| 444 | if ((child->path_a == path_a) && (child->path_b == path_b) && |
| 445 | (child->bustype == bustype) && |
| 446 | (child->chip_instance == chip_instance)) |
| 447 | return child; |
| 448 | |
| 449 | child = child->sibling; |
| 450 | } |
| 451 | |
| 452 | return NULL; |
| 453 | } |
| 454 | |
Furquan Shaikh | 27efc50 | 2018-06-22 09:19:15 -0700 | [diff] [blame] | 455 | /* |
| 456 | * Add given node as child of the provided parent. If this is the first child of |
| 457 | * the parent, update parent->children pointer as well. |
| 458 | */ |
| 459 | static void set_new_child(struct bus *parent, struct device *child) |
| 460 | { |
| 461 | struct device *c = parent->children; |
| 462 | if (c) { |
| 463 | while (c->sibling) |
| 464 | c = c->sibling; |
| 465 | c->sibling = child; |
| 466 | } else |
| 467 | parent->children = child; |
| 468 | |
| 469 | child->sibling = NULL; |
| 470 | child->parent = parent; |
| 471 | } |
| 472 | |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 473 | struct device *new_device(struct bus *parent, |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 474 | struct chip_instance *chip_instance, |
Furquan Shaikh | a9b6429 | 2018-05-31 07:52:00 -0700 | [diff] [blame] | 475 | const int bustype, const char *devnum, |
Hung-Te Lin | 936dbe1 | 2018-09-10 10:51:26 +0800 | [diff] [blame] | 476 | int status) |
Martin Roth | bec0753 | 2016-08-05 18:32:18 -0600 | [diff] [blame] | 477 | { |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 478 | char *tmp; |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 479 | int path_a; |
| 480 | int path_b = 0; |
| 481 | struct device *new_d; |
| 482 | |
| 483 | path_a = strtol(devnum, &tmp, 16); |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 484 | if (*tmp == '.') { |
| 485 | tmp++; |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 486 | path_b = strtol(tmp, NULL, 16); |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 487 | } |
| 488 | |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 489 | /* If device is found under parent, no need to allocate new device. */ |
| 490 | new_d = get_dev(parent, path_a, path_b, bustype, chip_instance); |
| 491 | if (new_d) { |
| 492 | alloc_bus(new_d); |
| 493 | return new_d; |
| 494 | } |
| 495 | |
| 496 | new_d = alloc_dev(parent); |
| 497 | |
| 498 | new_d->bustype = bustype; |
| 499 | |
| 500 | new_d->path_a = path_a; |
| 501 | new_d->path_b = path_b; |
| 502 | |
Hung-Te Lin | 936dbe1 | 2018-09-10 10:51:26 +0800 | [diff] [blame] | 503 | new_d->enabled = status & 0x01; |
| 504 | new_d->hidden = (status >> 1) & 0x01; |
Ronald G. Minnich | 466ca2c | 2019-10-22 02:02:24 +0000 | [diff] [blame] | 505 | new_d->mandatory = (status >> 2) & 0x01; |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 506 | new_d->chip_instance = chip_instance; |
Furquan Shaikh | 27efc50 | 2018-06-22 09:19:15 -0700 | [diff] [blame] | 507 | chip_instance->ref_count++; |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 508 | |
Furquan Shaikh | 27efc50 | 2018-06-22 09:19:15 -0700 | [diff] [blame] | 509 | set_new_child(parent, new_d); |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 510 | |
Furquan Shaikh | a9b6429 | 2018-05-31 07:52:00 -0700 | [diff] [blame] | 511 | switch (bustype) { |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 512 | case PCI: |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 513 | 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] | 514 | break; |
| 515 | |
| 516 | case PNP: |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 517 | 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] | 518 | break; |
| 519 | |
| 520 | case I2C: |
Duncan Laurie | b7ce5fe | 2016-05-07 19:49:37 -0700 | [diff] [blame] | 521 | 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] | 522 | break; |
| 523 | |
| 524 | case APIC: |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 525 | new_d->path = ".type=DEVICE_PATH_APIC,{.apic={ .apic_id = 0x%x }}"; |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 526 | break; |
| 527 | |
Stefan Reinauer | 0aa37c4 | 2013-02-12 15:20:54 -0800 | [diff] [blame] | 528 | case CPU_CLUSTER: |
| 529 | 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] | 530 | break; |
| 531 | |
Aaron Durbin | ffda804b | 2014-09-03 12:40:15 -0500 | [diff] [blame] | 532 | case CPU: |
| 533 | new_d->path = ".type=DEVICE_PATH_CPU,{.cpu={ .id = 0x%x }}"; |
| 534 | break; |
| 535 | |
Stefan Reinauer | 4aff445 | 2013-02-12 14:17:15 -0800 | [diff] [blame] | 536 | case DOMAIN: |
| 537 | new_d->path = ".type=DEVICE_PATH_DOMAIN,{.domain={ .domain = 0x%x }}"; |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 538 | break; |
| 539 | |
| 540 | case IOAPIC: |
| 541 | new_d->path = ".type=DEVICE_PATH_IOAPIC,{.ioapic={ .ioapic_id = 0x%x }}"; |
| 542 | break; |
Duncan Laurie | 4650f5b | 2016-05-07 20:01:34 -0700 | [diff] [blame] | 543 | |
| 544 | case GENERIC: |
| 545 | new_d->path = ".type=DEVICE_PATH_GENERIC,{.generic={ .id = 0x%x, .subid = 0x%x }}"; |
| 546 | break; |
Furquan Shaikh | e670029 | 2017-02-11 00:50:38 -0800 | [diff] [blame] | 547 | |
| 548 | case SPI: |
| 549 | new_d->path = ".type=DEVICE_PATH_SPI,{.spi={ .cs = 0x%x }}"; |
| 550 | break; |
| 551 | |
Duncan Laurie | bae9f85 | 2018-05-07 14:18:13 -0700 | [diff] [blame] | 552 | case USB: |
| 553 | new_d->path = ".type=DEVICE_PATH_USB,{.usb={ .port_type = %d, .port_id = %d }}"; |
| 554 | break; |
| 555 | |
Justin TerAvest | ca2ed9f | 2018-01-17 16:36:30 -0800 | [diff] [blame] | 556 | case MMIO: |
| 557 | new_d->path = ".type=DEVICE_PATH_MMIO,{.mmio={ .addr = 0x%x }}"; |
| 558 | break; |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 559 | } |
Justin TerAvest | ca2ed9f | 2018-01-17 16:36:30 -0800 | [diff] [blame] | 560 | |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 561 | return new_d; |
| 562 | } |
| 563 | |
Furquan Shaikh | 27efc50 | 2018-06-22 09:19:15 -0700 | [diff] [blame] | 564 | 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] | 565 | { |
Furquan Shaikh | 369e1f0 | 2018-05-31 09:48:51 -0700 | [diff] [blame] | 566 | struct resource *r = S_ALLOC(sizeof(struct resource)); |
| 567 | |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 568 | r->type = type; |
| 569 | r->index = index; |
| 570 | r->base = base; |
Patrick Georgi | 68befd5 | 2010-05-05 12:05:25 +0000 | [diff] [blame] | 571 | if (dev->res) { |
| 572 | struct resource *head = dev->res; |
Martin Roth | bec0753 | 2016-08-05 18:32:18 -0600 | [diff] [blame] | 573 | while (head->next) |
| 574 | head = head->next; |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 575 | head->next = r; |
| 576 | } else { |
Patrick Georgi | 68befd5 | 2010-05-05 12:05:25 +0000 | [diff] [blame] | 577 | dev->res = r; |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 578 | } |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 579 | } |
| 580 | |
Furquan Shaikh | 27efc50 | 2018-06-22 09:19:15 -0700 | [diff] [blame] | 581 | void add_resource(struct bus *bus, int type, int index, int base) |
| 582 | { |
| 583 | new_resource(bus->dev, type, index, base); |
| 584 | } |
| 585 | |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 586 | void add_register(struct chip_instance *chip_instance, char *name, char *val) |
Martin Roth | bec0753 | 2016-08-05 18:32:18 -0600 | [diff] [blame] | 587 | { |
Furquan Shaikh | 369e1f0 | 2018-05-31 09:48:51 -0700 | [diff] [blame] | 588 | struct reg *r = S_ALLOC(sizeof(struct reg)); |
| 589 | |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 590 | r->key = name; |
| 591 | r->value = val; |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 592 | if (chip_instance->reg) { |
| 593 | struct reg *head = chip_instance->reg; |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 594 | // sorting to be equal to sconfig's behaviour |
| 595 | int sort = strcmp(r->key, head->key); |
| 596 | if (sort == 0) { |
| 597 | printf("ERROR: duplicate 'register' key.\n"); |
| 598 | exit(1); |
| 599 | } |
Martin Roth | bec0753 | 2016-08-05 18:32:18 -0600 | [diff] [blame] | 600 | if (sort < 0) { |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 601 | r->next = head; |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 602 | chip_instance->reg = r; |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 603 | } else { |
Martin Roth | bec0753 | 2016-08-05 18:32:18 -0600 | [diff] [blame] | 604 | while ((head->next) |
| 605 | && (strcmp(head->next->key, r->key) < 0)) |
| 606 | head = head->next; |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 607 | r->next = head->next; |
| 608 | head->next = r; |
| 609 | } |
| 610 | } else { |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 611 | chip_instance->reg = r; |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 612 | } |
| 613 | } |
| 614 | |
Patrick Rudolph | ac24d3c | 2019-04-12 14:42:17 +0200 | [diff] [blame] | 615 | void add_slot_desc(struct bus *bus, char *type, char *length, char *designation, |
| 616 | char *data_width) |
| 617 | { |
| 618 | struct device *dev = bus->dev; |
| 619 | |
| 620 | if (dev->bustype != PCI && dev->bustype != DOMAIN) { |
| 621 | printf("ERROR: 'slot_type' only allowed for PCI devices\n"); |
| 622 | exit(1); |
| 623 | } |
| 624 | |
| 625 | dev->smbios_slot_type = type; |
| 626 | dev->smbios_slot_length = length; |
| 627 | dev->smbios_slot_data_width = data_width; |
| 628 | dev->smbios_slot_designation = designation; |
| 629 | } |
| 630 | |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 631 | void add_pci_subsystem_ids(struct bus *bus, int vendor, int device, |
Martin Roth | bec0753 | 2016-08-05 18:32:18 -0600 | [diff] [blame] | 632 | int inherit) |
Sven Schnelle | 270a908 | 2011-03-01 19:58:15 +0000 | [diff] [blame] | 633 | { |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 634 | struct device *dev = bus->dev; |
| 635 | |
Stefan Reinauer | 4aff445 | 2013-02-12 14:17:15 -0800 | [diff] [blame] | 636 | if (dev->bustype != PCI && dev->bustype != DOMAIN) { |
Sven Schnelle | 270a908 | 2011-03-01 19:58:15 +0000 | [diff] [blame] | 637 | printf("ERROR: 'subsystem' only allowed for PCI devices\n"); |
| 638 | exit(1); |
| 639 | } |
| 640 | |
| 641 | dev->subsystem_vendor = vendor; |
| 642 | dev->subsystem_device = device; |
| 643 | dev->inherit_subsystem = inherit; |
| 644 | } |
| 645 | |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 646 | void add_ioapic_info(struct bus *bus, int apicid, const char *_srcpin, |
Martin Roth | bec0753 | 2016-08-05 18:32:18 -0600 | [diff] [blame] | 647 | int irqpin) |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 648 | { |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 649 | int srcpin; |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 650 | struct device *dev = bus->dev; |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 651 | |
Martin Roth | bec0753 | 2016-08-05 18:32:18 -0600 | [diff] [blame] | 652 | if (!_srcpin || strlen(_srcpin) < 4 || strncasecmp(_srcpin, "INT", 3) || |
| 653 | _srcpin[3] < 'A' || _srcpin[3] > 'D') { |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 654 | printf("ERROR: malformed ioapic_irq args: %s\n", _srcpin); |
| 655 | exit(1); |
| 656 | } |
| 657 | |
| 658 | srcpin = _srcpin[3] - 'A'; |
| 659 | |
Stefan Reinauer | 4aff445 | 2013-02-12 14:17:15 -0800 | [diff] [blame] | 660 | if (dev->bustype != PCI && dev->bustype != DOMAIN) { |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 661 | printf("ERROR: ioapic config only allowed for PCI devices\n"); |
| 662 | exit(1); |
| 663 | } |
| 664 | |
| 665 | if (srcpin > 3) { |
Patrick Georgi | 116327e | 2012-07-20 12:47:06 +0200 | [diff] [blame] | 666 | printf("ERROR: srcpin '%d' invalid\n", srcpin); |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 667 | exit(1); |
| 668 | } |
| 669 | dev->pci_irq_info[srcpin].ioapic_irq_pin = irqpin; |
| 670 | dev->pci_irq_info[srcpin].ioapic_dst_id = apicid; |
| 671 | } |
| 672 | |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 673 | static int dev_has_children(struct device *dev) |
Martin Roth | bec0753 | 2016-08-05 18:32:18 -0600 | [diff] [blame] | 674 | { |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 675 | struct bus *bus = dev->bus; |
| 676 | |
| 677 | while (bus) { |
| 678 | if (bus->children) |
| 679 | return 1; |
| 680 | bus = bus->next_bus; |
| 681 | } |
| 682 | |
| 683 | return 0; |
| 684 | } |
| 685 | |
Nico Huber | 17e9bcb | 2019-09-20 12:05:51 +0200 | [diff] [blame] | 686 | 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] | 687 | { |
Furquan Shaikh | 4ebe953 | 2020-05-02 15:34:42 -0700 | [diff] [blame] | 688 | static int dev_id; |
| 689 | |
Furquan Shaikh | de39fc7 | 2018-06-11 04:26:45 -0700 | [diff] [blame] | 690 | if (ptr == &base_root_dev) { |
Kyösti Mälkki | 5ccce7c | 2019-03-15 10:04:11 +0200 | [diff] [blame] | 691 | fprintf(fil, "STORAGE struct bus %s_links[];\n", |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 692 | ptr->name); |
| 693 | return; |
| 694 | } |
| 695 | |
Furquan Shaikh | 4ebe953 | 2020-05-02 15:34:42 -0700 | [diff] [blame] | 696 | char *name = S_ALLOC(10); |
| 697 | sprintf(name, "_dev%d", dev_id++); |
| 698 | ptr->name = name; |
| 699 | |
Kyösti Mälkki | 5ccce7c | 2019-03-15 10:04:11 +0200 | [diff] [blame] | 700 | fprintf(fil, "STORAGE struct device %s;\n", ptr->name); |
Furquan Shaikh | 4ca3a8a | 2018-06-07 23:36:45 -0700 | [diff] [blame] | 701 | if (ptr->res) |
Kyösti Mälkki | 5ccce7c | 2019-03-15 10:04:11 +0200 | [diff] [blame] | 702 | fprintf(fil, "STORAGE struct resource %s_res[];\n", |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 703 | ptr->name); |
| 704 | if (dev_has_children(ptr)) |
Kyösti Mälkki | 5ccce7c | 2019-03-15 10:04:11 +0200 | [diff] [blame] | 705 | fprintf(fil, "STORAGE struct bus %s_links[];\n", |
Martin Roth | bec0753 | 2016-08-05 18:32:18 -0600 | [diff] [blame] | 706 | ptr->name); |
Stefan Reinauer | 57879c9 | 2012-07-31 16:47:25 -0700 | [diff] [blame] | 707 | |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 708 | if (next) |
| 709 | return; |
| 710 | |
| 711 | fprintf(fil, |
| 712 | "DEVTREE_CONST struct device * DEVTREE_CONST last_dev = &%s;\n", |
| 713 | ptr->name); |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 714 | } |
| 715 | |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 716 | static void emit_resources(FILE *fil, struct device *ptr) |
| 717 | { |
Furquan Shaikh | 4ca3a8a | 2018-06-07 23:36:45 -0700 | [diff] [blame] | 718 | if (ptr->res == NULL) |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 719 | return; |
| 720 | |
| 721 | int i = 1; |
Kyösti Mälkki | 5ccce7c | 2019-03-15 10:04:11 +0200 | [diff] [blame] | 722 | fprintf(fil, "STORAGE struct resource %s_res[] = {\n", ptr->name); |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 723 | struct resource *r = ptr->res; |
| 724 | while (r) { |
| 725 | fprintf(fil, |
| 726 | "\t\t{ .flags=IORESOURCE_FIXED | IORESOURCE_ASSIGNED | IORESOURCE_"); |
| 727 | if (r->type == IRQ) |
| 728 | fprintf(fil, "IRQ"); |
| 729 | if (r->type == DRQ) |
| 730 | fprintf(fil, "DRQ"); |
| 731 | if (r->type == IO) |
| 732 | fprintf(fil, "IO"); |
| 733 | fprintf(fil, ", .index=0x%x, .base=0x%x,", r->index, |
| 734 | r->base); |
| 735 | if (r->next) |
| 736 | fprintf(fil, ".next=&%s_res[%d]},\n", ptr->name, |
| 737 | i++); |
| 738 | else |
| 739 | fprintf(fil, ".next=NULL },\n"); |
| 740 | r = r->next; |
| 741 | } |
| 742 | |
| 743 | fprintf(fil, "\t };\n"); |
| 744 | } |
| 745 | |
| 746 | static void emit_bus(FILE *fil, struct bus *bus) |
| 747 | { |
| 748 | fprintf(fil, "\t\t[%d] = {\n", bus->id); |
| 749 | fprintf(fil, "\t\t\t.link_num = %d,\n", bus->id); |
| 750 | fprintf(fil, "\t\t\t.dev = &%s,\n", bus->dev->name); |
| 751 | if (bus->children) |
| 752 | fprintf(fil, "\t\t\t.children = &%s,\n", bus->children->name); |
| 753 | |
| 754 | if (bus->next_bus) |
| 755 | fprintf(fil, "\t\t\t.next=&%s_links[%d],\n", bus->dev->name, |
| 756 | bus->id + 1); |
| 757 | else |
| 758 | fprintf(fil, "\t\t\t.next = NULL,\n"); |
| 759 | fprintf(fil, "\t\t},\n"); |
| 760 | } |
| 761 | |
| 762 | static void emit_dev_links(FILE *fil, struct device *ptr) |
| 763 | { |
Kyösti Mälkki | 5ccce7c | 2019-03-15 10:04:11 +0200 | [diff] [blame] | 764 | fprintf(fil, "STORAGE struct bus %s_links[] = {\n", |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 765 | ptr->name); |
| 766 | |
| 767 | struct bus *bus = ptr->bus; |
| 768 | |
| 769 | while (bus) { |
| 770 | emit_bus(fil, bus); |
| 771 | bus = bus->next_bus; |
| 772 | } |
| 773 | |
| 774 | fprintf(fil, "\t};\n"); |
| 775 | } |
| 776 | |
Nico Huber | 17e9bcb | 2019-09-20 12:05:51 +0200 | [diff] [blame] | 777 | 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] | 778 | { |
| 779 | int pin; |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 780 | struct chip_instance *chip_ins = ptr->chip_instance; |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 781 | int has_children = dev_has_children(ptr); |
Furquan Shaikh | 79e8412 | 2018-05-30 15:09:09 -0700 | [diff] [blame] | 782 | |
Kyösti Mälkki | 5ccce7c | 2019-03-15 10:04:11 +0200 | [diff] [blame] | 783 | if (ptr == &base_root_dev) |
| 784 | fprintf(fil, "DEVTREE_CONST struct device %s = {\n", ptr->name); |
| 785 | else |
| 786 | fprintf(fil, "STORAGE struct device %s = {\n", ptr->name); |
| 787 | |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 788 | fprintf(fil, "#if !DEVTREE_EARLY\n"); |
Furquan Shaikh | 50ddc0b | 2018-06-23 00:59:31 -0700 | [diff] [blame] | 789 | |
| 790 | /* |
| 791 | * ops field is set to default_dev_ops_root only for the root |
| 792 | * device. For all other devices, it is set by the driver at runtime. |
| 793 | */ |
| 794 | if (ptr == &base_root_dev) |
| 795 | fprintf(fil, "\t.ops = &default_dev_ops_root,\n"); |
| 796 | else |
| 797 | fprintf(fil, "\t.ops = NULL,\n"); |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 798 | fprintf(fil, "#endif\n"); |
| 799 | fprintf(fil, "\t.bus = &%s_links[%d],\n", ptr->parent->dev->name, |
| 800 | ptr->parent->id); |
| 801 | fprintf(fil, "\t.path = {"); |
| 802 | fprintf(fil, ptr->path, ptr->path_a, ptr->path_b); |
| 803 | fprintf(fil, "},\n"); |
| 804 | fprintf(fil, "\t.enabled = %d,\n", ptr->enabled); |
Hung-Te Lin | 936dbe1 | 2018-09-10 10:51:26 +0800 | [diff] [blame] | 805 | fprintf(fil, "\t.hidden = %d,\n", ptr->hidden); |
Ronald G. Minnich | 466ca2c | 2019-10-22 02:02:24 +0000 | [diff] [blame] | 806 | fprintf(fil, "\t.mandatory = %d,\n", ptr->mandatory); |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 807 | fprintf(fil, "\t.on_mainboard = 1,\n"); |
| 808 | if (ptr->subsystem_vendor > 0) |
| 809 | fprintf(fil, "\t.subsystem_vendor = 0x%04x,\n", |
| 810 | ptr->subsystem_vendor); |
Sven Schnelle | 270a908 | 2011-03-01 19:58:15 +0000 | [diff] [blame] | 811 | |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 812 | if (ptr->subsystem_device > 0) |
| 813 | fprintf(fil, "\t.subsystem_device = 0x%04x,\n", |
| 814 | ptr->subsystem_device); |
| 815 | |
Furquan Shaikh | 4ca3a8a | 2018-06-07 23:36:45 -0700 | [diff] [blame] | 816 | if (ptr->res) { |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 817 | fprintf(fil, "\t.resource_list = &%s_res[0],\n", |
Martin Roth | bec0753 | 2016-08-05 18:32:18 -0600 | [diff] [blame] | 818 | ptr->name); |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 819 | } |
| 820 | if (has_children) |
| 821 | fprintf(fil, "\t.link_list = &%s_links[0],\n", |
| 822 | ptr->name); |
| 823 | else |
| 824 | fprintf(fil, "\t.link_list = NULL,\n"); |
| 825 | if (ptr->sibling) |
| 826 | fprintf(fil, "\t.sibling = &%s,\n", ptr->sibling->name); |
Aaron Durbin | d47afe9 | 2020-03-26 12:29:35 -0600 | [diff] [blame] | 827 | else |
| 828 | fprintf(fil, "\t.sibling = NULL,\n"); |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 829 | fprintf(fil, "#if !DEVTREE_EARLY\n"); |
Kyösti Mälkki | 1557a67 | 2019-06-30 10:51:31 +0300 | [diff] [blame] | 830 | for (pin = 0; pin < 4; pin++) { |
| 831 | if (ptr->pci_irq_info[pin].ioapic_irq_pin > 0) |
| 832 | fprintf(fil, |
| 833 | "\t.pci_irq_info[%d].ioapic_irq_pin = %d,\n", |
| 834 | pin, ptr->pci_irq_info[pin].ioapic_irq_pin); |
| 835 | |
| 836 | if (ptr->pci_irq_info[pin].ioapic_dst_id > 0) |
| 837 | fprintf(fil, |
| 838 | "\t.pci_irq_info[%d].ioapic_dst_id = %d,\n", |
| 839 | pin, ptr->pci_irq_info[pin].ioapic_dst_id); |
| 840 | } |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 841 | fprintf(fil, "\t.chip_ops = &%s_ops,\n", |
| 842 | chip_ins->chip->name_underscore); |
| 843 | if (chip_ins == &mainboard_instance) |
| 844 | fprintf(fil, "\t.name = mainboard_name,\n"); |
| 845 | fprintf(fil, "#endif\n"); |
| 846 | if (chip_ins->chip->chiph_exists) |
| 847 | fprintf(fil, "\t.chip_info = &%s_info_%d,\n", |
| 848 | chip_ins->chip->name_underscore, chip_ins->id); |
| 849 | if (next) |
Patrick Rudolph | ac24d3c | 2019-04-12 14:42:17 +0200 | [diff] [blame] | 850 | fprintf(fil, "\t.next=&%s,\n", next->name); |
| 851 | if (ptr->smbios_slot_type || ptr->smbios_slot_data_width || |
| 852 | ptr->smbios_slot_designation || ptr->smbios_slot_length) { |
| 853 | fprintf(fil, "#if !DEVTREE_EARLY\n"); |
| 854 | fprintf(fil, "#if CONFIG(GENERATE_SMBIOS_TABLES)\n"); |
| 855 | } |
| 856 | /* SMBIOS types start at 1, if zero it hasn't been set */ |
| 857 | if (ptr->smbios_slot_type) |
| 858 | fprintf(fil, "\t.smbios_slot_type = %s,\n", |
| 859 | ptr->smbios_slot_type); |
| 860 | if (ptr->smbios_slot_data_width) |
| 861 | fprintf(fil, "\t.smbios_slot_data_width = %s,\n", |
| 862 | ptr->smbios_slot_data_width); |
| 863 | if (ptr->smbios_slot_designation) |
| 864 | fprintf(fil, "\t.smbios_slot_designation = \"%s\",\n", |
| 865 | ptr->smbios_slot_designation); |
| 866 | if (ptr->smbios_slot_length) |
| 867 | fprintf(fil, "\t.smbios_slot_length = %s,\n", |
| 868 | ptr->smbios_slot_length); |
| 869 | if (ptr->smbios_slot_type || ptr->smbios_slot_data_width || |
| 870 | ptr->smbios_slot_designation || ptr->smbios_slot_length) { |
| 871 | fprintf(fil, "#endif\n"); |
| 872 | fprintf(fil, "#endif\n"); |
| 873 | } |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 874 | fprintf(fil, "};\n"); |
| 875 | |
| 876 | emit_resources(fil, ptr); |
| 877 | |
| 878 | if (has_children) |
| 879 | emit_dev_links(fil, ptr); |
| 880 | } |
| 881 | |
Nico Huber | 17e9bcb | 2019-09-20 12:05:51 +0200 | [diff] [blame] | 882 | 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] | 883 | { |
| 884 | /* Only devices on root bus here. */ |
Nico Huber | 17e9bcb | 2019-09-20 12:05:51 +0200 | [diff] [blame] | 885 | if (ptr->bustype == PCI && ptr->parent->dev->bustype == DOMAIN) { |
| 886 | fprintf(head, "extern DEVTREE_CONST struct device *DEVTREE_CONST __pci_0_%02x_%d;\n", |
| 887 | ptr->path_a, ptr->path_b); |
Kyösti Mälkki | 5e2a2cd | 2019-03-15 17:44:23 +0200 | [diff] [blame] | 888 | fprintf(fil, "DEVTREE_CONST struct device *DEVTREE_CONST __pci_0_%02x_%d = &%s;\n", |
| 889 | ptr->path_a, ptr->path_b, ptr->name); |
Nico Huber | 17e9bcb | 2019-09-20 12:05:51 +0200 | [diff] [blame] | 890 | } |
Kyösti Mälkki | 5e2a2cd | 2019-03-15 17:44:23 +0200 | [diff] [blame] | 891 | |
Nico Huber | 17e9bcb | 2019-09-20 12:05:51 +0200 | [diff] [blame] | 892 | if (ptr->bustype == PNP) { |
| 893 | fprintf(head, "extern DEVTREE_CONST struct device *DEVTREE_CONST __pnp_%04x_%02x;\n", |
| 894 | ptr->path_a, ptr->path_b); |
Kyösti Mälkki | 5e2a2cd | 2019-03-15 17:44:23 +0200 | [diff] [blame] | 895 | fprintf(fil, "DEVTREE_CONST struct device *DEVTREE_CONST __pnp_%04x_%02x = &%s;\n", |
| 896 | ptr->path_a, ptr->path_b, ptr->name); |
Nico Huber | 17e9bcb | 2019-09-20 12:05:51 +0200 | [diff] [blame] | 897 | } |
Kyösti Mälkki | 5e2a2cd | 2019-03-15 17:44:23 +0200 | [diff] [blame] | 898 | } |
| 899 | |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 900 | static void add_siblings_to_queue(struct queue_entry **bfs_q_head, |
| 901 | struct device *d) |
| 902 | { |
| 903 | while (d) { |
| 904 | enqueue_tail(bfs_q_head, d); |
| 905 | d = d->sibling; |
| 906 | } |
| 907 | } |
| 908 | |
| 909 | static void add_children_to_queue(struct queue_entry **bfs_q_head, |
| 910 | struct device *d) |
| 911 | { |
| 912 | struct bus *bus = d->bus; |
| 913 | |
| 914 | while (bus) { |
| 915 | if (bus->children) |
| 916 | add_siblings_to_queue(bfs_q_head, bus->children); |
| 917 | bus = bus->next_bus; |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 918 | } |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 919 | } |
| 920 | |
Nico Huber | 17e9bcb | 2019-09-20 12:05:51 +0200 | [diff] [blame] | 921 | static void walk_device_tree(FILE *fil, FILE *head, struct device *ptr, |
| 922 | void (*func)(FILE *, FILE *, struct device *, |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 923 | struct device *)) |
Martin Roth | bec0753 | 2016-08-05 18:32:18 -0600 | [diff] [blame] | 924 | { |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 925 | struct queue_entry *bfs_q_head = NULL; |
| 926 | |
| 927 | enqueue_tail(&bfs_q_head, ptr); |
| 928 | |
| 929 | while ((ptr = dequeue_head(&bfs_q_head))) { |
| 930 | add_children_to_queue(&bfs_q_head, ptr); |
Nico Huber | 17e9bcb | 2019-09-20 12:05:51 +0200 | [diff] [blame] | 931 | func(fil, head, ptr, peek_queue_head(bfs_q_head)); |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 932 | } |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 933 | } |
| 934 | |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 935 | static void emit_chip_headers(FILE *fil, struct chip *chip) |
Furquan Shaikh | a0cc5a6 | 2018-05-30 23:46:16 -0700 | [diff] [blame] | 936 | { |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 937 | struct chip *tmp = chip; |
Furquan Shaikh | a0cc5a6 | 2018-05-30 23:46:16 -0700 | [diff] [blame] | 938 | |
| 939 | fprintf(fil, "#include <device/device.h>\n"); |
| 940 | fprintf(fil, "#include <device/pci.h>\n"); |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 941 | |
| 942 | while (chip) { |
| 943 | if (chip->chiph_exists) |
| 944 | fprintf(fil, "#include \"%s/chip.h\"\n", chip->name); |
| 945 | chip = chip->next; |
Furquan Shaikh | a0cc5a6 | 2018-05-30 23:46:16 -0700 | [diff] [blame] | 946 | } |
| 947 | fprintf(fil, "\n#if !DEVTREE_EARLY\n"); |
| 948 | fprintf(fil, |
| 949 | "__attribute__((weak)) struct chip_operations mainboard_ops = {};\n"); |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 950 | |
| 951 | chip = tmp; |
| 952 | while (chip) { |
Furquan Shaikh | a0cc5a6 | 2018-05-30 23:46:16 -0700 | [diff] [blame] | 953 | fprintf(fil, |
| 954 | "__attribute__((weak)) struct chip_operations %s_ops = {};\n", |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 955 | chip->name_underscore); |
| 956 | chip = chip->next; |
Furquan Shaikh | a0cc5a6 | 2018-05-30 23:46:16 -0700 | [diff] [blame] | 957 | } |
| 958 | fprintf(fil, "#endif\n"); |
| 959 | } |
| 960 | |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 961 | static void emit_chip_instance(FILE *fil, struct chip_instance *instance) |
| 962 | { |
Kyösti Mälkki | 5ccce7c | 2019-03-15 10:04:11 +0200 | [diff] [blame] | 963 | fprintf(fil, "STORAGE struct %s_config %s_info_%d = {", |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 964 | instance->chip->name_underscore, |
| 965 | instance->chip->name_underscore, |
| 966 | instance->id); |
| 967 | |
| 968 | if (instance->reg) { |
| 969 | fprintf(fil, "\n"); |
| 970 | struct reg *r = instance->reg; |
| 971 | while (r) { |
| 972 | fprintf(fil, "\t.%s = %s,\n", r->key, r->value); |
| 973 | r = r->next; |
| 974 | } |
| 975 | } |
| 976 | fprintf(fil, "};\n\n"); |
| 977 | } |
| 978 | |
Furquan Shaikh | 79e8412 | 2018-05-30 15:09:09 -0700 | [diff] [blame] | 979 | static void emit_chips(FILE *fil) |
| 980 | { |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 981 | struct chip *chip = chip_header.next; |
| 982 | struct chip_instance *instance; |
Furquan Shaikh | 9f681d2 | 2020-05-02 15:51:02 -0700 | [diff] [blame^] | 983 | int chip_id; |
Furquan Shaikh | 79e8412 | 2018-05-30 15:09:09 -0700 | [diff] [blame] | 984 | |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 985 | emit_chip_headers(fil, chip); |
Furquan Shaikh | a0cc5a6 | 2018-05-30 23:46:16 -0700 | [diff] [blame] | 986 | |
Kyösti Mälkki | 5ccce7c | 2019-03-15 10:04:11 +0200 | [diff] [blame] | 987 | fprintf(fil, "\n#define STORAGE static __unused DEVTREE_CONST\n\n"); |
| 988 | |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 989 | for (; chip; chip = chip->next) { |
Furquan Shaikh | 79e8412 | 2018-05-30 15:09:09 -0700 | [diff] [blame] | 990 | if (!chip->chiph_exists) |
| 991 | continue; |
| 992 | |
Furquan Shaikh | 9f681d2 | 2020-05-02 15:51:02 -0700 | [diff] [blame^] | 993 | chip_id = 1; |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 994 | instance = chip->instance; |
| 995 | while (instance) { |
Furquan Shaikh | 9f681d2 | 2020-05-02 15:51:02 -0700 | [diff] [blame^] | 996 | instance->id = chip_id++; |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 997 | emit_chip_instance(fil, instance); |
| 998 | instance = instance->next; |
Furquan Shaikh | 79e8412 | 2018-05-30 15:09:09 -0700 | [diff] [blame] | 999 | } |
| 1000 | } |
| 1001 | } |
| 1002 | |
Nico Huber | 17e9bcb | 2019-09-20 12:05:51 +0200 | [diff] [blame] | 1003 | static void inherit_subsystem_ids(FILE *file, FILE *head, struct device *dev, |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 1004 | struct device *next) |
Sven Schnelle | 270a908 | 2011-03-01 19:58:15 +0000 | [diff] [blame] | 1005 | { |
| 1006 | struct device *p; |
Sven Schnelle | 270a908 | 2011-03-01 19:58:15 +0000 | [diff] [blame] | 1007 | |
| 1008 | if (dev->subsystem_vendor != -1 && dev->subsystem_device != -1) { |
| 1009 | /* user already gave us a subsystem vendor/device */ |
| 1010 | return; |
| 1011 | } |
| 1012 | |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 1013 | for (p = dev; p && p->parent->dev != p; p = p->parent->dev) { |
Sven Schnelle | 270a908 | 2011-03-01 19:58:15 +0000 | [diff] [blame] | 1014 | |
Stefan Reinauer | 4aff445 | 2013-02-12 14:17:15 -0800 | [diff] [blame] | 1015 | if (p->bustype != PCI && p->bustype != DOMAIN) |
Sven Schnelle | 270a908 | 2011-03-01 19:58:15 +0000 | [diff] [blame] | 1016 | continue; |
| 1017 | |
| 1018 | if (p->inherit_subsystem) { |
| 1019 | dev->subsystem_vendor = p->subsystem_vendor; |
| 1020 | dev->subsystem_device = p->subsystem_device; |
| 1021 | break; |
| 1022 | } |
| 1023 | } |
| 1024 | } |
| 1025 | |
Kyösti Mälkki | 472d902 | 2011-12-05 20:33:55 +0200 | [diff] [blame] | 1026 | static void usage(void) |
| 1027 | { |
Nico Huber | 17e9bcb | 2019-09-20 12:05:51 +0200 | [diff] [blame] | 1028 | printf("usage: sconfig devicetree_file output_file header_file [override_devicetree_file]\n"); |
Martin Roth | bec0753 | 2016-08-05 18:32:18 -0600 | [diff] [blame] | 1029 | exit(1); |
Kyösti Mälkki | 472d902 | 2011-12-05 20:33:55 +0200 | [diff] [blame] | 1030 | } |
| 1031 | |
Martin Roth | 3205170 | 2015-11-24 12:34:16 -0700 | [diff] [blame] | 1032 | enum { |
Martin Roth | c9c27bb | 2016-08-05 18:15:06 -0600 | [diff] [blame] | 1033 | DEVICEFILE_ARG = 1, |
Furquan Shaikh | 39ac797 | 2018-06-21 18:44:32 -0700 | [diff] [blame] | 1034 | OUTPUTFILE_ARG, |
Nico Huber | 17e9bcb | 2019-09-20 12:05:51 +0200 | [diff] [blame] | 1035 | HEADERFILE_ARG, |
Furquan Shaikh | 39ac797 | 2018-06-21 18:44:32 -0700 | [diff] [blame] | 1036 | OVERRIDE_DEVICEFILE_ARG, |
Martin Roth | bec0753 | 2016-08-05 18:32:18 -0600 | [diff] [blame] | 1037 | }; |
Martin Roth | 3205170 | 2015-11-24 12:34:16 -0700 | [diff] [blame] | 1038 | |
Nico Huber | 17e9bcb | 2019-09-20 12:05:51 +0200 | [diff] [blame] | 1039 | #define MANDATORY_ARG_COUNT 4 |
Furquan Shaikh | 39ac797 | 2018-06-21 18:44:32 -0700 | [diff] [blame] | 1040 | #define OPTIONAL_ARG_COUNT 1 |
| 1041 | #define TOTAL_ARG_COUNT (MANDATORY_ARG_COUNT + OPTIONAL_ARG_COUNT) |
Kyösti Mälkki | 472d902 | 2011-12-05 20:33:55 +0200 | [diff] [blame] | 1042 | |
Furquan Shaikh | de39fc7 | 2018-06-11 04:26:45 -0700 | [diff] [blame] | 1043 | static void parse_devicetree(const char *file, struct bus *parent) |
Martin Roth | bec0753 | 2016-08-05 18:32:18 -0600 | [diff] [blame] | 1044 | { |
Furquan Shaikh | de39fc7 | 2018-06-11 04:26:45 -0700 | [diff] [blame] | 1045 | FILE *filec = fopen(file, "r"); |
Stefan Reinauer | 7c1f6b8 | 2010-08-16 18:21:56 +0000 | [diff] [blame] | 1046 | if (!filec) { |
Stefan Reinauer | 7c1f6b8 | 2010-08-16 18:21:56 +0000 | [diff] [blame] | 1047 | perror(NULL); |
| 1048 | exit(1); |
| 1049 | } |
| 1050 | |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 1051 | yyrestart(filec); |
| 1052 | |
Furquan Shaikh | de39fc7 | 2018-06-11 04:26:45 -0700 | [diff] [blame] | 1053 | root_parent = parent; |
| 1054 | linenum = 0; |
| 1055 | |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 1056 | yyparse(); |
Stefan Reinauer | 7c1f6b8 | 2010-08-16 18:21:56 +0000 | [diff] [blame] | 1057 | |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 1058 | fclose(filec); |
Furquan Shaikh | de39fc7 | 2018-06-11 04:26:45 -0700 | [diff] [blame] | 1059 | } |
| 1060 | |
Furquan Shaikh | 27efc50 | 2018-06-22 09:19:15 -0700 | [diff] [blame] | 1061 | /* |
| 1062 | * Match device nodes from base and override tree to see if they are the same |
| 1063 | * node. |
| 1064 | */ |
| 1065 | static int device_match(struct device *a, struct device *b) |
| 1066 | { |
| 1067 | return ((a->path_a == b->path_a) && |
| 1068 | (a->path_b == b->path_b) && |
| 1069 | (a->bustype == b->bustype) && |
| 1070 | (a->chip_instance->chip == |
| 1071 | b->chip_instance->chip)); |
| 1072 | } |
| 1073 | |
| 1074 | /* |
Bill XIE | c61d415 | 2019-11-21 18:16:12 +0800 | [diff] [blame] | 1075 | * Match resource nodes from base and override tree to see if they are the same |
| 1076 | * node. |
| 1077 | */ |
| 1078 | static int res_match(struct resource *a, struct resource *b) |
| 1079 | { |
| 1080 | return ((a->type == b->type) && |
| 1081 | (a->index == b->index)); |
| 1082 | } |
| 1083 | |
| 1084 | /* |
Furquan Shaikh | 27efc50 | 2018-06-22 09:19:15 -0700 | [diff] [blame] | 1085 | * Walk through the override subtree in breadth-first manner starting at node to |
| 1086 | * see if chip_instance pointer of the node is same as chip_instance pointer of |
| 1087 | * override parent that is passed into the function. If yes, then update the |
| 1088 | * chip_instance pointer of the node to chip_instance pointer of the base |
| 1089 | * parent. |
| 1090 | */ |
| 1091 | static void update_chip_pointers(struct device *node, |
| 1092 | struct chip_instance *base_parent_ci, |
| 1093 | struct chip_instance *override_parent_ci) |
| 1094 | { |
| 1095 | struct queue_entry *q_head = NULL; |
| 1096 | |
| 1097 | enqueue_tail(&q_head, node); |
| 1098 | |
| 1099 | while ((node = dequeue_head(&q_head))) { |
| 1100 | if (node->chip_instance != override_parent_ci) |
| 1101 | continue; |
| 1102 | node->chip_instance = base_parent_ci; |
| 1103 | add_children_to_queue(&q_head, node); |
| 1104 | } |
| 1105 | } |
| 1106 | |
| 1107 | /* |
| 1108 | * Add resource to device. If resource is already present, then update its base |
| 1109 | * and index. If not, then add a new resource to the device. |
| 1110 | */ |
| 1111 | static void update_resource(struct device *dev, struct resource *res) |
| 1112 | { |
| 1113 | struct resource *base_res = dev->res; |
| 1114 | |
| 1115 | while (base_res) { |
Bill XIE | c61d415 | 2019-11-21 18:16:12 +0800 | [diff] [blame] | 1116 | if (res_match(base_res, res)) { |
Furquan Shaikh | 27efc50 | 2018-06-22 09:19:15 -0700 | [diff] [blame] | 1117 | base_res->base = res->base; |
| 1118 | return; |
| 1119 | } |
| 1120 | base_res = base_res->next; |
| 1121 | } |
| 1122 | |
| 1123 | new_resource(dev, res->type, res->index, res->base); |
| 1124 | } |
| 1125 | |
| 1126 | /* |
| 1127 | * Add register to chip instance. If register is already present, then update |
| 1128 | * its value. If not, then add a new register to the chip instance. |
| 1129 | */ |
| 1130 | static void update_register(struct chip_instance *c, struct reg *reg) |
| 1131 | { |
| 1132 | struct reg *base_reg = c->reg; |
| 1133 | |
| 1134 | while (base_reg) { |
| 1135 | if (!strcmp(base_reg->key, reg->key)) { |
| 1136 | base_reg->value = reg->value; |
| 1137 | return; |
| 1138 | } |
| 1139 | base_reg = base_reg->next; |
| 1140 | } |
| 1141 | |
| 1142 | add_register(c, reg->key, reg->value); |
| 1143 | } |
| 1144 | |
| 1145 | static void override_devicetree(struct bus *base_parent, |
| 1146 | struct bus *override_parent); |
| 1147 | |
| 1148 | /* |
| 1149 | * Update the base device properties using the properties of override device. In |
| 1150 | * addition to that, call override_devicetree for all the buses under the |
| 1151 | * override device. |
| 1152 | * |
| 1153 | * Override Rules: |
| 1154 | * +--------------------+--------------------------------------------+ |
| 1155 | * | | | |
| 1156 | * |struct device member| Rule | |
| 1157 | * | | | |
| 1158 | * +-----------------------------------------------------------------+ |
| 1159 | * | | | |
| 1160 | * | id | Unchanged. This is used to generate device | |
| 1161 | * | | structure name in static.c. So, no need to | |
| 1162 | * | | override. | |
| 1163 | * | | | |
| 1164 | * +-----------------------------------------------------------------+ |
| 1165 | * | | | |
| 1166 | * | enabled | Copy enabled state from override device. | |
| 1167 | * | | This allows variants to override device | |
| 1168 | * | | state. | |
| 1169 | * | | | |
| 1170 | * +-----------------------------------------------------------------+ |
| 1171 | * | | | |
| 1172 | * | subsystem_vendor | Copy from override device only if any one | |
| 1173 | * | subsystem_device | of the ids is non-zero. | |
| 1174 | * | | | |
| 1175 | * +-----------------------------------------------------------------+ |
| 1176 | * | | | |
| 1177 | * | inherit_subsystem | Copy from override device only if it is | |
| 1178 | * | | non-zero. This allows variant to only | |
| 1179 | * | | enable inherit flag for a device. | |
| 1180 | * | | | |
| 1181 | * +-----------------------------------------------------------------+ |
| 1182 | * | | | |
| 1183 | * | path | Unchanged since these are same for both | |
| 1184 | * | path_a | base and override device (Used for | |
| 1185 | * | path_b | matching devices). | |
| 1186 | * | | | |
| 1187 | * +-----------------------------------------------------------------+ |
| 1188 | * | | | |
| 1189 | * | bustype | Unchanged since this is same for both base | |
| 1190 | * | | and override device (User for matching | |
| 1191 | * | | devices). | |
| 1192 | * | | | |
| 1193 | * +-----------------------------------------------------------------+ |
| 1194 | * | | | |
| 1195 | * | pci_irq_info | Unchanged. | |
| 1196 | * | | | |
| 1197 | * +-----------------------------------------------------------------+ |
| 1198 | * | | | |
| 1199 | * | parent | Unchanged. This is meaningful only within | |
| 1200 | * | sibling | the parse tree, hence not being copied. | |
| 1201 | * | | | |
| 1202 | * +-----------------------------------------------------------------+ |
| 1203 | * | | | |
| 1204 | * | res | Each resource that is present in override | |
| 1205 | * | | device is copied over to base device: | |
Bill XIE | c61d415 | 2019-11-21 18:16:12 +0800 | [diff] [blame] | 1206 | * | | 1. If resource of same type and index is | |
| 1207 | * | | present in base device, then base of | |
| 1208 | * | | the resource is copied. | |
Furquan Shaikh | 27efc50 | 2018-06-22 09:19:15 -0700 | [diff] [blame] | 1209 | * | | 2. If not, then a new resource is allocated| |
| 1210 | * | | under the base device using type, index | |
| 1211 | * | | and base from override res. | |
| 1212 | * | | | |
| 1213 | * +-----------------------------------------------------------------+ |
| 1214 | * | | | |
| 1215 | * | chip_instance | Each register of chip_instance is copied | |
| 1216 | * | | over from override device to base device: | |
| 1217 | * | | 1. If register with same key is present in | |
| 1218 | * | | base device, then value of the register | |
| 1219 | * | | is copied. | |
| 1220 | * | | 2. If not, then a new register is allocated| |
| 1221 | * | | under the base chip_instance using key | |
| 1222 | * | | and value from override register. | |
| 1223 | * | | | |
| 1224 | * +-----------------------------------------------------------------+ |
| 1225 | * | | | |
| 1226 | * | bus | Recursively call override_devicetree on | |
| 1227 | * | last_bus | each bus of override device. It is assumed | |
| 1228 | * | | that bus with id X under base device | |
| 1229 | * | | to bus with id X under override device. If | |
| 1230 | * | | override device has more buses than base | |
| 1231 | * | | device, then new buses are allocated under | |
| 1232 | * | | base device. | |
| 1233 | * | | | |
| 1234 | * +-----------------------------------------------------------------+ |
| 1235 | */ |
| 1236 | static void update_device(struct device *base_dev, struct device *override_dev) |
| 1237 | { |
| 1238 | /* |
| 1239 | * Copy the enabled state of override device to base device. This allows |
| 1240 | * override tree to enable or disable a particular device. |
| 1241 | */ |
| 1242 | base_dev->enabled = override_dev->enabled; |
| 1243 | |
| 1244 | /* |
| 1245 | * Copy subsystem vendor and device ids from override device to base |
| 1246 | * device only if the ids are non-zero in override device. Else, honor |
| 1247 | * the values in base device. |
| 1248 | */ |
| 1249 | if (override_dev->subsystem_vendor || |
| 1250 | override_dev->subsystem_device) { |
| 1251 | base_dev->subsystem_vendor = override_dev->subsystem_vendor; |
| 1252 | base_dev->subsystem_device = override_dev->subsystem_device; |
| 1253 | } |
| 1254 | |
| 1255 | /* |
| 1256 | * Copy value of inherity_subsystem from override device to base device |
| 1257 | * only if it is non-zero in override device. This allows override |
| 1258 | * tree to only enable inhert flag for a device. |
| 1259 | */ |
| 1260 | if (override_dev->inherit_subsystem) |
| 1261 | base_dev->inherit_subsystem = override_dev->inherit_subsystem; |
| 1262 | |
| 1263 | /* |
| 1264 | * Copy resources of override device to base device. |
| 1265 | * 1. If resource is already present in base device, then index and base |
| 1266 | * of the resource will be copied over. |
| 1267 | * 2. If resource is not already present in base device, a new resource |
| 1268 | * will be allocated. |
| 1269 | */ |
| 1270 | struct resource *res = override_dev->res; |
| 1271 | while (res) { |
| 1272 | update_resource(base_dev, res); |
| 1273 | res = res->next; |
| 1274 | } |
| 1275 | |
| 1276 | /* |
| 1277 | * Copy registers of override chip instance to base chip instance. |
| 1278 | * 1. If register key is already present in base chip instance, then |
| 1279 | * value for the register is copied over. |
| 1280 | * 2. If register key is not already present in base chip instance, then |
| 1281 | * a new register will be allocated. |
| 1282 | */ |
| 1283 | struct reg *reg = override_dev->chip_instance->reg; |
| 1284 | while (reg) { |
| 1285 | update_register(base_dev->chip_instance, reg); |
| 1286 | reg = reg->next; |
| 1287 | } |
| 1288 | |
| 1289 | /* |
| 1290 | * Now that the device properties are all copied over, look at each bus |
| 1291 | * of the override device and run override_devicetree in a recursive |
| 1292 | * manner. The assumption here is that first bus of override device |
| 1293 | * corresponds to first bus of base device and so on. If base device has |
| 1294 | * lesser buses than override tree, then new buses are allocated for it. |
| 1295 | */ |
| 1296 | struct bus *override_bus = override_dev->bus; |
| 1297 | struct bus *base_bus = base_dev->bus; |
| 1298 | |
| 1299 | while (override_bus) { |
| 1300 | |
| 1301 | /* |
| 1302 | * If we have more buses in override tree device, then allocate |
| 1303 | * a new bus for the base tree device as well. |
| 1304 | */ |
| 1305 | if (!base_bus) { |
| 1306 | alloc_bus(base_dev); |
| 1307 | base_bus = base_dev->last_bus; |
| 1308 | } |
| 1309 | |
| 1310 | override_devicetree(base_dev->bus, override_dev->bus); |
| 1311 | |
| 1312 | override_bus = override_bus->next_bus; |
| 1313 | base_bus = base_bus->next_bus; |
| 1314 | } |
| 1315 | |
| 1316 | delete_chip_instance(override_dev->chip_instance); |
| 1317 | override_dev->chip_instance = NULL; |
| 1318 | } |
| 1319 | |
| 1320 | /* |
| 1321 | * Perform copy of device and properties from override parent to base parent. |
| 1322 | * This function walks through the override tree in a depth-first manner |
| 1323 | * performing following actions: |
| 1324 | * 1. If matching device is found in base tree, then copy the properties of |
| 1325 | * override device to base tree device. Call override_devicetree recursively on |
| 1326 | * the bus of override device. |
| 1327 | * 2. If matching device is not found in base tree, then set override tree |
| 1328 | * device as new child of base_parent and update the chip pointers in override |
| 1329 | * device subtree to ensure the nodes do not point to override tree chip |
| 1330 | * instance. |
| 1331 | */ |
| 1332 | static void override_devicetree(struct bus *base_parent, |
| 1333 | struct bus *override_parent) |
| 1334 | { |
| 1335 | struct device *base_child; |
| 1336 | struct device *override_child = override_parent->children; |
| 1337 | struct device *next_child; |
| 1338 | |
| 1339 | while (override_child) { |
| 1340 | |
| 1341 | /* Look for a matching device in base tree. */ |
| 1342 | for (base_child = base_parent->children; |
| 1343 | base_child; base_child = base_child->sibling) { |
| 1344 | if (device_match(base_child, override_child)) |
| 1345 | break; |
| 1346 | } |
| 1347 | |
| 1348 | next_child = override_child->sibling; |
| 1349 | |
| 1350 | /* |
| 1351 | * If matching device is found, copy properties of |
| 1352 | * override_child to base_child. |
| 1353 | */ |
| 1354 | if (base_child) |
| 1355 | update_device(base_child, override_child); |
| 1356 | else { |
| 1357 | /* |
| 1358 | * If matching device is not found, set override_child |
| 1359 | * as a new child of base_parent. |
| 1360 | */ |
| 1361 | set_new_child(base_parent, override_child); |
| 1362 | /* |
| 1363 | * Ensure all nodes in override tree pointing to |
| 1364 | * override parent chip_instance now point to base |
| 1365 | * parent chip_instance. |
| 1366 | */ |
| 1367 | update_chip_pointers(override_child, |
| 1368 | base_parent->dev->chip_instance, |
| 1369 | override_parent->dev->chip_instance); |
| 1370 | } |
| 1371 | |
| 1372 | override_child = next_child; |
| 1373 | } |
| 1374 | } |
| 1375 | |
Furquan Shaikh | de39fc7 | 2018-06-11 04:26:45 -0700 | [diff] [blame] | 1376 | int main(int argc, char **argv) |
| 1377 | { |
Furquan Shaikh | 39ac797 | 2018-06-21 18:44:32 -0700 | [diff] [blame] | 1378 | if ((argc < MANDATORY_ARG_COUNT) || (argc > TOTAL_ARG_COUNT)) |
Furquan Shaikh | de39fc7 | 2018-06-11 04:26:45 -0700 | [diff] [blame] | 1379 | usage(); |
| 1380 | |
Furquan Shaikh | 39ac797 | 2018-06-21 18:44:32 -0700 | [diff] [blame] | 1381 | const char *base_devtree = argv[DEVICEFILE_ARG]; |
| 1382 | const char *outputc = argv[OUTPUTFILE_ARG]; |
Nico Huber | 17e9bcb | 2019-09-20 12:05:51 +0200 | [diff] [blame] | 1383 | const char *outputh = argv[HEADERFILE_ARG]; |
Furquan Shaikh | 39ac797 | 2018-06-21 18:44:32 -0700 | [diff] [blame] | 1384 | const char *override_devtree; |
Furquan Shaikh | de39fc7 | 2018-06-11 04:26:45 -0700 | [diff] [blame] | 1385 | |
| 1386 | parse_devicetree(base_devtree, &base_root_bus); |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 1387 | |
Furquan Shaikh | 39ac797 | 2018-06-21 18:44:32 -0700 | [diff] [blame] | 1388 | if (argc == TOTAL_ARG_COUNT) { |
| 1389 | override_devtree = argv[OVERRIDE_DEVICEFILE_ARG]; |
| 1390 | parse_devicetree(override_devtree, &override_root_bus); |
Furquan Shaikh | 27efc50 | 2018-06-22 09:19:15 -0700 | [diff] [blame] | 1391 | |
Furquan Shaikh | 4d99b27 | 2019-04-11 15:13:25 -0700 | [diff] [blame] | 1392 | if (!dev_has_children(&override_root_dev)) { |
| 1393 | fprintf(stderr, "ERROR: Override tree needs at least one device!\n"); |
| 1394 | exit(1); |
| 1395 | } |
| 1396 | |
Furquan Shaikh | 27efc50 | 2018-06-22 09:19:15 -0700 | [diff] [blame] | 1397 | override_devicetree(&base_root_bus, &override_root_bus); |
Furquan Shaikh | 39ac797 | 2018-06-21 18:44:32 -0700 | [diff] [blame] | 1398 | } |
| 1399 | |
Kyösti Mälkki | 472d902 | 2011-12-05 20:33:55 +0200 | [diff] [blame] | 1400 | FILE *autogen = fopen(outputc, "w"); |
| 1401 | if (!autogen) { |
Martin Roth | bec0753 | 2016-08-05 18:32:18 -0600 | [diff] [blame] | 1402 | fprintf(stderr, "Could not open file '%s' for writing: ", |
| 1403 | outputc); |
Stefan Reinauer | 7c1f6b8 | 2010-08-16 18:21:56 +0000 | [diff] [blame] | 1404 | perror(NULL); |
| 1405 | exit(1); |
| 1406 | } |
| 1407 | |
Nico Huber | 17e9bcb | 2019-09-20 12:05:51 +0200 | [diff] [blame] | 1408 | FILE *autohead = fopen(outputh, "w"); |
| 1409 | if (!autohead) { |
| 1410 | fprintf(stderr, "Could not open file '%s' for writing: ", outputh); |
| 1411 | perror(NULL); |
| 1412 | fclose(autogen); |
| 1413 | exit(1); |
| 1414 | } |
| 1415 | fprintf(autohead, "#ifndef __STATIC_DEVICE_TREE_H\n"); |
| 1416 | fprintf(autohead, "#define __STATIC_DEVICE_TREE_H\n\n"); |
| 1417 | fprintf(autohead, "#include <device/device.h>\n\n"); |
| 1418 | |
Furquan Shaikh | 79e8412 | 2018-05-30 15:09:09 -0700 | [diff] [blame] | 1419 | emit_chips(autogen); |
| 1420 | |
Nico Huber | 17e9bcb | 2019-09-20 12:05:51 +0200 | [diff] [blame] | 1421 | walk_device_tree(autogen, autohead, &base_root_dev, inherit_subsystem_ids); |
Martin Roth | 824255e | 2016-08-05 17:40:39 -0600 | [diff] [blame] | 1422 | fprintf(autogen, "\n/* pass 0 */\n"); |
Nico Huber | 17e9bcb | 2019-09-20 12:05:51 +0200 | [diff] [blame] | 1423 | walk_device_tree(autogen, autohead, &base_root_dev, pass0); |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 1424 | fprintf(autogen, "\n/* pass 1 */\n"); |
Nico Huber | 17e9bcb | 2019-09-20 12:05:51 +0200 | [diff] [blame] | 1425 | walk_device_tree(autogen, autohead, &base_root_dev, pass1); |
Sven Schnelle | 270a908 | 2011-03-01 19:58:15 +0000 | [diff] [blame] | 1426 | |
Kyösti Mälkki | 5e2a2cd | 2019-03-15 17:44:23 +0200 | [diff] [blame] | 1427 | /* Expose static devicenames to global namespace. */ |
| 1428 | fprintf(autogen, "\n/* expose_device_names */\n"); |
Nico Huber | 17e9bcb | 2019-09-20 12:05:51 +0200 | [diff] [blame] | 1429 | walk_device_tree(autogen, autohead, &base_root_dev, expose_device_names); |
Kyösti Mälkki | 5e2a2cd | 2019-03-15 17:44:23 +0200 | [diff] [blame] | 1430 | |
Nico Huber | 17e9bcb | 2019-09-20 12:05:51 +0200 | [diff] [blame] | 1431 | fprintf(autohead, "\n#endif /* __STATIC_DEVICE_TREE_H */\n"); |
| 1432 | fclose(autohead); |
Kyösti Mälkki | 472d902 | 2011-12-05 20:33:55 +0200 | [diff] [blame] | 1433 | fclose(autogen); |
Stefan Reinauer | 7c1f6b8 | 2010-08-16 18:21:56 +0000 | [diff] [blame] | 1434 | |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 1435 | return 0; |
| 1436 | } |