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