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 |
| 5 | * written by Patrick Georgi <patrick.georgi@coresystems.de> |
| 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. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA |
| 19 | */ |
| 20 | |
Patrick Georgi | 2dbfcb7 | 2012-05-30 16:26:30 +0200 | [diff] [blame] | 21 | #include <ctype.h> |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 22 | #include "sconfig.h" |
| 23 | #include "sconfig.tab.h" |
| 24 | |
Patrick Georgi | 7fc9e29 | 2010-07-15 15:59:07 +0000 | [diff] [blame] | 25 | extern int linenum; |
| 26 | |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 27 | struct device *head, *lastdev; |
| 28 | |
| 29 | struct header headers; |
| 30 | |
| 31 | static int devcount = 0; |
| 32 | |
Kyösti Mälkki | 472d902 | 2011-12-05 20:33:55 +0200 | [diff] [blame] | 33 | typedef enum { |
| 34 | STATIC_MODE, |
| 35 | BOOTBLOCK_MODE, |
| 36 | KCONFIG_MODE |
| 37 | } scan_t; |
| 38 | |
| 39 | static scan_t scan_mode = STATIC_MODE; |
| 40 | |
Kyösti Mälkki | 1a2a6ee | 2012-03-18 20:19:28 +0200 | [diff] [blame] | 41 | typedef enum { |
| 42 | UNSLASH, |
| 43 | SPLIT_1ST, |
| 44 | TO_LOWER, |
| 45 | TO_UPPER, |
| 46 | } translate_t; |
| 47 | |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 48 | static struct device root; |
| 49 | static struct device mainboard = { |
| 50 | .name = "mainboard", |
| 51 | .name_underscore = "mainboard", |
| 52 | .id = 0, |
| 53 | .chip = &mainboard, |
| 54 | .type = chip, |
Stefan Reinauer | 188e3c2 | 2012-07-26 12:46:48 -0700 | [diff] [blame] | 55 | #ifdef MAINBOARDS_HAVE_CHIP_H |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 56 | .chiph_exists = 1, |
Stefan Reinauer | 188e3c2 | 2012-07-26 12:46:48 -0700 | [diff] [blame] | 57 | #else |
| 58 | .chiph_exists = 0, |
| 59 | #endif |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 60 | .children = &root |
| 61 | }; |
| 62 | |
| 63 | static struct device root = { |
| 64 | .name = "dev_root", |
| 65 | .name_underscore = "dev_root", |
| 66 | .id = 0, |
| 67 | .chip = &mainboard, |
| 68 | .type = device, |
| 69 | .path = " .type = DEVICE_PATH_ROOT ", |
| 70 | .ops = "&default_dev_ops_root", |
| 71 | .parent = &root, |
| 72 | .bus = &root, |
| 73 | .enabled = 1 |
| 74 | }; |
| 75 | |
Patrick Georgi | 68befd5 | 2010-05-05 12:05:25 +0000 | [diff] [blame] | 76 | static struct device *new_dev(struct device *parent, struct device *bus) { |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 77 | struct device *dev = malloc(sizeof(struct device)); |
| 78 | memset(dev, 0, sizeof(struct device)); |
| 79 | dev->id = ++devcount; |
Patrick Georgi | 68befd5 | 2010-05-05 12:05:25 +0000 | [diff] [blame] | 80 | dev->parent = parent; |
| 81 | dev->bus = bus; |
Sven Schnelle | 270a908 | 2011-03-01 19:58:15 +0000 | [diff] [blame] | 82 | dev->subsystem_vendor = -1; |
| 83 | dev->subsystem_device = -1; |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 84 | head->next = dev; |
| 85 | head = dev; |
| 86 | return dev; |
| 87 | } |
| 88 | |
| 89 | static int device_match(struct device *a, struct device *b) { |
| 90 | if ((a->bustype == b->bustype) && (a->bus == b->bus) && (a->path_a == b->path_a) && (a->path_b == b->path_b)) |
| 91 | return 1; |
| 92 | return 0; |
| 93 | } |
| 94 | |
| 95 | void fold_in(struct device *parent) { |
| 96 | struct device *child = parent->children; |
| 97 | struct device *latest = 0; |
| 98 | while (child != latest) { |
| 99 | if (child->children) { |
| 100 | if (!latest) latest = child->children; |
| 101 | parent->latestchild->next_sibling = child->children; |
| 102 | parent->latestchild = child->latestchild; |
| 103 | } |
| 104 | child = child->next_sibling; |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | int yywrap(void) { |
| 109 | return 1; |
| 110 | } |
| 111 | |
| 112 | void yyerror (char const *str) |
| 113 | { |
Stefan Reinauer | 7c1f6b8 | 2010-08-16 18:21:56 +0000 | [diff] [blame] | 114 | extern char *yytext; |
| 115 | fprintf (stderr, "line %d: %s: %s\n", linenum + 1, yytext, str); |
| 116 | exit(1); |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | void postprocess_devtree(void) { |
| 120 | root.next_sibling = root.children; |
| 121 | root.next_sibling->next_sibling = root.next_sibling->children; |
| 122 | |
| 123 | struct device *dev = &root; |
| 124 | while (dev) { |
| 125 | /* skip "chip" elements in children chain */ |
| 126 | while (dev->children && (dev->children->type == chip)) dev->children = dev->children->children; |
| 127 | /* skip "chip" elements and functions of the same device in sibling chain */ |
| 128 | while (dev->sibling && dev->sibling->used) dev->sibling = dev->sibling->sibling; |
| 129 | /* If end of chain, and parent is a chip, move on */ |
| 130 | if (!dev->sibling && (dev->parent->type == chip)) dev->sibling = dev->parent->sibling; |
| 131 | /* skip chips */ |
| 132 | while (dev->sibling && dev->sibling->type == chip) dev->sibling = dev->sibling->children; |
| 133 | /* skip duplicate function elements in nextdev chain */ |
| 134 | while (dev->nextdev && dev->nextdev->used) dev->nextdev = dev->nextdev->nextdev; |
| 135 | dev = dev->next_sibling; |
| 136 | } |
| 137 | } |
| 138 | |
Kyösti Mälkki | 1a2a6ee | 2012-03-18 20:19:28 +0200 | [diff] [blame] | 139 | char * translate_name(const char *str, translate_t mode) |
Kyösti Mälkki | 472d902 | 2011-12-05 20:33:55 +0200 | [diff] [blame] | 140 | { |
Kyösti Mälkki | 1a2a6ee | 2012-03-18 20:19:28 +0200 | [diff] [blame] | 141 | char *b, *c; |
| 142 | b = c = strdup(str); |
| 143 | while (c && *c) { |
| 144 | if ((mode == SPLIT_1ST) && (*c == '/')) { |
| 145 | *c = 0; |
| 146 | break; |
| 147 | } |
Kyösti Mälkki | 472d902 | 2011-12-05 20:33:55 +0200 | [diff] [blame] | 148 | if (*c == '/') *c = '_'; |
| 149 | if (*c == '-') *c = '_'; |
Kyösti Mälkki | 1a2a6ee | 2012-03-18 20:19:28 +0200 | [diff] [blame] | 150 | if (mode == TO_UPPER) |
Kyösti Mälkki | 472d902 | 2011-12-05 20:33:55 +0200 | [diff] [blame] | 151 | *c = toupper(*c); |
Kyösti Mälkki | 1a2a6ee | 2012-03-18 20:19:28 +0200 | [diff] [blame] | 152 | if (mode == TO_LOWER) |
| 153 | *c = tolower(*c); |
| 154 | c++; |
Kyösti Mälkki | 472d902 | 2011-12-05 20:33:55 +0200 | [diff] [blame] | 155 | } |
Kyösti Mälkki | 1a2a6ee | 2012-03-18 20:19:28 +0200 | [diff] [blame] | 156 | return b; |
Kyösti Mälkki | 472d902 | 2011-12-05 20:33:55 +0200 | [diff] [blame] | 157 | } |
| 158 | |
Patrick Georgi | 68befd5 | 2010-05-05 12:05:25 +0000 | [diff] [blame] | 159 | struct device *new_chip(struct device *parent, struct device *bus, char *path) { |
| 160 | struct device *new_chip = new_dev(parent, bus); |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 161 | new_chip->chiph_exists = 1; |
| 162 | new_chip->name = path; |
Kyösti Mälkki | 1a2a6ee | 2012-03-18 20:19:28 +0200 | [diff] [blame] | 163 | new_chip->name_underscore = translate_name(new_chip->name, UNSLASH); |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 164 | new_chip->type = chip; |
| 165 | new_chip->chip = new_chip; |
| 166 | |
| 167 | struct stat st; |
Kyösti Mälkki | 472d902 | 2011-12-05 20:33:55 +0200 | [diff] [blame] | 168 | char *chip_h = malloc(strlen(path)+18); |
Stefan Reinauer | 76c44ae | 2011-10-14 12:41:46 -0700 | [diff] [blame] | 169 | sprintf(chip_h, "src/%s", path); |
| 170 | if ((stat(chip_h, &st) == -1) && (errno == ENOENT)) { |
| 171 | fprintf(stderr, "ERROR: Chip component %s does not exist.\n", |
| 172 | path); |
| 173 | exit(1); |
| 174 | } |
| 175 | |
Kyösti Mälkki | 472d902 | 2011-12-05 20:33:55 +0200 | [diff] [blame] | 176 | if (scan_mode == STATIC_MODE) |
| 177 | sprintf(chip_h, "src/%s/chip.h", path); |
| 178 | else if (scan_mode == BOOTBLOCK_MODE) |
| 179 | sprintf(chip_h, "src/%s/bootblock.c", path); |
| 180 | |
| 181 | if ((scan_mode == STATIC_MODE) || (scan_mode == BOOTBLOCK_MODE)) { |
| 182 | if ((stat(chip_h, &st) == -1) && (errno == ENOENT)) |
| 183 | new_chip->chiph_exists = 0; |
| 184 | } |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 185 | |
Patrick Georgi | 68befd5 | 2010-05-05 12:05:25 +0000 | [diff] [blame] | 186 | if (parent->latestchild) { |
| 187 | parent->latestchild->next_sibling = new_chip; |
| 188 | parent->latestchild->sibling = new_chip; |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 189 | } |
Patrick Georgi | 68befd5 | 2010-05-05 12:05:25 +0000 | [diff] [blame] | 190 | parent->latestchild = new_chip; |
| 191 | if (!parent->children) |
| 192 | parent->children = new_chip; |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 193 | return new_chip; |
| 194 | } |
| 195 | |
| 196 | void add_header(struct device *dev) { |
Kyösti Mälkki | aada2e1 | 2012-10-07 15:08:32 +0200 | [diff] [blame] | 197 | int include_exists = 0; |
| 198 | struct header *h = &headers; |
| 199 | while (h->next) { |
| 200 | int result = strcmp(dev->name, h->next->name); |
| 201 | if (result == 0) { |
| 202 | include_exists = 1; |
| 203 | break; |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 204 | } |
Kyösti Mälkki | aada2e1 | 2012-10-07 15:08:32 +0200 | [diff] [blame] | 205 | if (result < 0) break; |
| 206 | h = h->next; |
| 207 | } |
| 208 | if (!include_exists) { |
| 209 | struct header *tmp = h->next; |
| 210 | h->next = malloc(sizeof(struct header)); |
| 211 | memset(h->next, 0, sizeof(struct header)); |
| 212 | h->next->chiph_exists = dev->chiph_exists; |
| 213 | h->next->name = dev->name; |
| 214 | h->next->next = tmp; |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 215 | } |
| 216 | } |
| 217 | |
Patrick Georgi | 68befd5 | 2010-05-05 12:05:25 +0000 | [diff] [blame] | 218 | struct device *new_device(struct device *parent, struct device *busdev, const int bus, const char *devnum, int enabled) { |
| 219 | struct device *new_d = new_dev(parent, busdev); |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 220 | new_d->bustype = bus; |
| 221 | |
| 222 | char *tmp; |
| 223 | new_d->path_a = strtol(strdup(devnum), &tmp, 16); |
| 224 | if (*tmp == '.') { |
| 225 | tmp++; |
| 226 | new_d->path_b = strtol(tmp, NULL, 16); |
| 227 | } |
| 228 | |
| 229 | char *name = malloc(10); |
| 230 | sprintf(name, "_dev%d", new_d->id); |
| 231 | new_d->name = name; |
| 232 | new_d->name_underscore = name; // shouldn't be necessary, but avoid 0-ptr |
| 233 | new_d->type = device; |
| 234 | new_d->enabled = enabled; |
| 235 | new_d->chip = new_d->parent->chip; |
| 236 | |
Patrick Georgi | 68befd5 | 2010-05-05 12:05:25 +0000 | [diff] [blame] | 237 | if (parent->latestchild) { |
| 238 | parent->latestchild->next_sibling = new_d; |
| 239 | parent->latestchild->sibling = new_d; |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 240 | } |
Patrick Georgi | 68befd5 | 2010-05-05 12:05:25 +0000 | [diff] [blame] | 241 | parent->latestchild = new_d; |
| 242 | if (!parent->children) |
| 243 | parent->children = new_d; |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 244 | |
| 245 | lastdev->nextdev = new_d; |
| 246 | lastdev = new_d; |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 247 | |
| 248 | switch(bus) { |
| 249 | case PCI: |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 250 | 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] | 251 | break; |
| 252 | |
| 253 | case PNP: |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 254 | 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] | 255 | break; |
| 256 | |
| 257 | case I2C: |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 258 | new_d->path = ".type=DEVICE_PATH_I2C,{.i2c={ .device = 0x%x }}"; |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 259 | break; |
| 260 | |
| 261 | case APIC: |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 262 | new_d->path = ".type=DEVICE_PATH_APIC,{.apic={ .apic_id = 0x%x }}"; |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 263 | break; |
| 264 | |
| 265 | case APIC_CLUSTER: |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 266 | new_d->path = ".type=DEVICE_PATH_APIC_CLUSTER,{.apic_cluster={ .cluster = 0x%x }}"; |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 267 | break; |
| 268 | |
| 269 | case PCI_DOMAIN: |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 270 | new_d->path = ".type=DEVICE_PATH_PCI_DOMAIN,{.pci_domain={ .domain = 0x%x }}"; |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 271 | break; |
| 272 | |
| 273 | case IOAPIC: |
| 274 | new_d->path = ".type=DEVICE_PATH_IOAPIC,{.ioapic={ .ioapic_id = 0x%x }}"; |
| 275 | break; |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 276 | } |
| 277 | return new_d; |
| 278 | } |
| 279 | |
| 280 | void alias_siblings(struct device *d) { |
| 281 | while (d) { |
| 282 | int link = 0; |
| 283 | struct device *cmp = d->next_sibling; |
| 284 | while (cmp && (cmp->bus == d->bus) && (cmp->path_a == d->path_a) && (cmp->path_b == d->path_b)) { |
| 285 | if (cmp->type==device && !cmp->used) { |
| 286 | if (device_match(d, cmp)) { |
| 287 | d->multidev = 1; |
| 288 | |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 289 | cmp->id = d->id; |
| 290 | cmp->name = d->name; |
| 291 | cmp->used = 1; |
| 292 | cmp->link = ++link; |
| 293 | } |
| 294 | } |
| 295 | cmp = cmp->next_sibling; |
| 296 | } |
| 297 | d = d->next_sibling; |
| 298 | } |
| 299 | } |
| 300 | |
Patrick Georgi | 68befd5 | 2010-05-05 12:05:25 +0000 | [diff] [blame] | 301 | void add_resource(struct device *dev, int type, int index, int base) { |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 302 | struct resource *r = malloc(sizeof(struct resource)); |
| 303 | memset (r, 0, sizeof(struct resource)); |
| 304 | r->type = type; |
| 305 | r->index = index; |
| 306 | r->base = base; |
Patrick Georgi | 68befd5 | 2010-05-05 12:05:25 +0000 | [diff] [blame] | 307 | if (dev->res) { |
| 308 | struct resource *head = dev->res; |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 309 | while (head->next) head = head->next; |
| 310 | head->next = r; |
| 311 | } else { |
Patrick Georgi | 68befd5 | 2010-05-05 12:05:25 +0000 | [diff] [blame] | 312 | dev->res = r; |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 313 | } |
Patrick Georgi | 68befd5 | 2010-05-05 12:05:25 +0000 | [diff] [blame] | 314 | dev->rescnt++; |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 315 | } |
| 316 | |
Patrick Georgi | 68befd5 | 2010-05-05 12:05:25 +0000 | [diff] [blame] | 317 | void add_register(struct device *dev, char *name, char *val) { |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 318 | struct reg *r = malloc(sizeof(struct reg)); |
| 319 | memset (r, 0, sizeof(struct reg)); |
| 320 | r->key = name; |
| 321 | r->value = val; |
Patrick Georgi | 68befd5 | 2010-05-05 12:05:25 +0000 | [diff] [blame] | 322 | if (dev->reg) { |
| 323 | struct reg *head = dev->reg; |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 324 | // sorting to be equal to sconfig's behaviour |
| 325 | int sort = strcmp(r->key, head->key); |
| 326 | if (sort == 0) { |
| 327 | printf("ERROR: duplicate 'register' key.\n"); |
| 328 | exit(1); |
| 329 | } |
| 330 | if (sort<0) { |
| 331 | r->next = head; |
Patrick Georgi | 68befd5 | 2010-05-05 12:05:25 +0000 | [diff] [blame] | 332 | dev->reg = r; |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 333 | } else { |
| 334 | while ((head->next) && (strcmp(head->next->key, r->key)<0)) head = head->next; |
| 335 | r->next = head->next; |
| 336 | head->next = r; |
| 337 | } |
| 338 | } else { |
Patrick Georgi | 68befd5 | 2010-05-05 12:05:25 +0000 | [diff] [blame] | 339 | dev->reg = r; |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 340 | } |
| 341 | } |
| 342 | |
Sven Schnelle | 270a908 | 2011-03-01 19:58:15 +0000 | [diff] [blame] | 343 | void add_pci_subsystem_ids(struct device *dev, int vendor, int device, int inherit) |
| 344 | { |
| 345 | if (dev->bustype != PCI && dev->bustype != PCI_DOMAIN) { |
| 346 | printf("ERROR: 'subsystem' only allowed for PCI devices\n"); |
| 347 | exit(1); |
| 348 | } |
| 349 | |
| 350 | dev->subsystem_vendor = vendor; |
| 351 | dev->subsystem_device = device; |
| 352 | dev->inherit_subsystem = inherit; |
| 353 | } |
| 354 | |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 355 | void add_ioapic_info(struct device *dev, int apicid, const char *_srcpin, int irqpin) |
| 356 | { |
| 357 | |
| 358 | int srcpin; |
| 359 | |
| 360 | if (!_srcpin || strlen(_srcpin) < 4 ||strncasecmp(_srcpin, "INT", 3) || |
| 361 | _srcpin[3] < 'A' || _srcpin[3] > 'D') { |
| 362 | printf("ERROR: malformed ioapic_irq args: %s\n", _srcpin); |
| 363 | exit(1); |
| 364 | } |
| 365 | |
| 366 | srcpin = _srcpin[3] - 'A'; |
| 367 | |
| 368 | if (dev->bustype != PCI && dev->bustype != PCI_DOMAIN) { |
| 369 | printf("ERROR: ioapic config only allowed for PCI devices\n"); |
| 370 | exit(1); |
| 371 | } |
| 372 | |
| 373 | if (srcpin > 3) { |
Patrick Georgi | 116327e | 2012-07-20 12:47:06 +0200 | [diff] [blame] | 374 | printf("ERROR: srcpin '%d' invalid\n", srcpin); |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 375 | exit(1); |
| 376 | } |
| 377 | dev->pci_irq_info[srcpin].ioapic_irq_pin = irqpin; |
| 378 | dev->pci_irq_info[srcpin].ioapic_dst_id = apicid; |
| 379 | } |
| 380 | |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 381 | static void pass0(FILE *fil, struct device *ptr) { |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 382 | if (ptr->type == device && ptr->id == 0) |
Stefan Reinauer | 57879c9 | 2012-07-31 16:47:25 -0700 | [diff] [blame] | 383 | fprintf(fil, "ROMSTAGE_CONST struct bus %s_links[];\n", ptr->name); |
| 384 | |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 385 | if ((ptr->type == device) && (ptr->id != 0) && (!ptr->used)) { |
Stefan Reinauer | 57879c9 | 2012-07-31 16:47:25 -0700 | [diff] [blame] | 386 | fprintf(fil, "ROMSTAGE_CONST static struct device %s;\n", ptr->name); |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 387 | if (ptr->rescnt > 0) |
Stefan Reinauer | 57879c9 | 2012-07-31 16:47:25 -0700 | [diff] [blame] | 388 | fprintf(fil, "ROMSTAGE_CONST struct resource %s_res[];\n", ptr->name); |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 389 | if (ptr->children || ptr->multidev) |
Stefan Reinauer | 57879c9 | 2012-07-31 16:47:25 -0700 | [diff] [blame] | 390 | fprintf(fil, "ROMSTAGE_CONST struct bus %s_links[];\n", |
| 391 | ptr->name); |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 392 | } |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 393 | } |
| 394 | |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 395 | static void pass1(FILE *fil, struct device *ptr) |
| 396 | { |
| 397 | int pin; |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 398 | if (!ptr->used && (ptr->type == device)) { |
Stefan Reinauer | df61dd2 | 2010-08-09 12:02:00 +0000 | [diff] [blame] | 399 | if (ptr->id != 0) |
Patrick Georgi | 2dbfcb7 | 2012-05-30 16:26:30 +0200 | [diff] [blame] | 400 | fprintf(fil, "static "); |
Stefan Reinauer | 57879c9 | 2012-07-31 16:47:25 -0700 | [diff] [blame] | 401 | fprintf(fil, "ROMSTAGE_CONST struct device %s = {\n", ptr->name); |
| 402 | fprintf(fil, "#ifndef __PRE_RAM__\n"); |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 403 | fprintf(fil, "\t.ops = %s,\n", (ptr->ops)?(ptr->ops):"0"); |
Stefan Reinauer | 57879c9 | 2012-07-31 16:47:25 -0700 | [diff] [blame] | 404 | fprintf(fil, "#endif\n"); |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 405 | fprintf(fil, "\t.bus = &%s_links[%d],\n", ptr->bus->name, ptr->bus->link); |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 406 | fprintf(fil, "\t.path = {"); |
| 407 | fprintf(fil, ptr->path, ptr->path_a, ptr->path_b); |
| 408 | fprintf(fil, "},\n"); |
| 409 | fprintf(fil, "\t.enabled = %d,\n", ptr->enabled); |
| 410 | fprintf(fil, "\t.on_mainboard = 1,\n"); |
Sven Schnelle | 270a908 | 2011-03-01 19:58:15 +0000 | [diff] [blame] | 411 | if (ptr->subsystem_vendor > 0) |
| 412 | fprintf(fil, "\t.subsystem_vendor = 0x%04x,\n", ptr->subsystem_vendor); |
| 413 | |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 414 | for(pin = 0; pin < 4; pin++) { |
| 415 | if (ptr->pci_irq_info[pin].ioapic_irq_pin > 0) |
| 416 | fprintf(fil, "\t.pci_irq_info[%d].ioapic_irq_pin = %d,\n", pin, ptr->pci_irq_info[pin].ioapic_irq_pin); |
| 417 | |
| 418 | if (ptr->pci_irq_info[pin].ioapic_dst_id > 0) |
| 419 | fprintf(fil, "\t.pci_irq_info[%d].ioapic_dst_id = %d,\n", pin, ptr->pci_irq_info[pin].ioapic_dst_id); |
| 420 | } |
| 421 | |
Sven Schnelle | 270a908 | 2011-03-01 19:58:15 +0000 | [diff] [blame] | 422 | if (ptr->subsystem_device > 0) |
| 423 | fprintf(fil, "\t.subsystem_device = 0x%04x,\n", ptr->subsystem_device); |
| 424 | |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 425 | if (ptr->rescnt > 0) { |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 426 | fprintf(fil, "\t.resource_list = &%s_res[0],\n", ptr->name); |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 427 | } |
| 428 | int link = 0; |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 429 | if (ptr->children || ptr->multidev) |
| 430 | fprintf(fil, "\t.link_list = &%s_links[0],\n", ptr->name); |
| 431 | else |
Patrick Georgi | 2dbfcb7 | 2012-05-30 16:26:30 +0200 | [diff] [blame] | 432 | fprintf(fil, "\t.link_list = NULL,\n"); |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 433 | if (ptr->sibling) |
| 434 | fprintf(fil, "\t.sibling = &%s,\n", ptr->sibling->name); |
Kyösti Mälkki | aada2e1 | 2012-10-07 15:08:32 +0200 | [diff] [blame] | 435 | fprintf(fil, "#ifndef __PRE_RAM__\n"); |
| 436 | fprintf(fil, "\t.chip_ops = &%s_ops,\n", ptr->chip->name_underscore); |
Kyösti Mälkki | a93c3fe | 2012-10-09 22:28:56 +0300 | [diff] [blame] | 437 | if (ptr->chip->chip == &mainboard) |
| 438 | fprintf(fil, "\t.name = mainboard_name,\n"); |
Kyösti Mälkki | aada2e1 | 2012-10-07 15:08:32 +0200 | [diff] [blame] | 439 | fprintf(fil, "#endif\n"); |
| 440 | if (ptr->chip->chiph_exists) |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 441 | fprintf(fil, "\t.chip_info = &%s_info_%d,\n", ptr->chip->name_underscore, ptr->chip->id); |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 442 | if (ptr->nextdev) |
| 443 | fprintf(fil, "\t.next=&%s\n", ptr->nextdev->name); |
| 444 | fprintf(fil, "};\n"); |
| 445 | } |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 446 | if (ptr->rescnt > 0) { |
| 447 | int i=1; |
Stefan Reinauer | 57879c9 | 2012-07-31 16:47:25 -0700 | [diff] [blame] | 448 | fprintf(fil, "ROMSTAGE_CONST struct resource %s_res[] = {\n", |
| 449 | ptr->name); |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 450 | struct resource *r = ptr->res; |
| 451 | while (r) { |
| 452 | fprintf(fil, "\t\t{ .flags=IORESOURCE_FIXED | IORESOURCE_ASSIGNED | IORESOURCE_"); |
| 453 | if (r->type == IRQ) fprintf(fil, "IRQ"); |
| 454 | if (r->type == DRQ) fprintf(fil, "DRQ"); |
| 455 | if (r->type == IO) fprintf(fil, "IO"); |
| 456 | fprintf(fil, ", .index=0x%x, .base=0x%x,", r->index, r->base); |
| 457 | if (r->next) |
| 458 | fprintf(fil, ".next=&%s_res[%d]},\n", ptr->name, i++); |
| 459 | else |
| 460 | fprintf(fil, ".next=NULL },\n"); |
| 461 | r = r->next; |
| 462 | } |
| 463 | fprintf(fil, "\t };\n"); |
| 464 | } |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 465 | if (!ptr->used && ptr->type == device && (ptr->children || ptr->multidev)) { |
Stefan Reinauer | 57879c9 | 2012-07-31 16:47:25 -0700 | [diff] [blame] | 466 | fprintf(fil, "ROMSTAGE_CONST struct bus %s_links[] = {\n", ptr->name); |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 467 | if (ptr->multidev) { |
| 468 | struct device *d = ptr; |
| 469 | while (d) { |
| 470 | if (device_match(d, ptr)) { |
| 471 | fprintf(fil, "\t\t[%d] = {\n", d->link); |
| 472 | fprintf(fil, "\t\t\t.link_num = %d,\n", d->link); |
| 473 | fprintf(fil, "\t\t\t.dev = &%s,\n", d->name); |
| 474 | if (d->children) |
| 475 | fprintf(fil, "\t\t\t.children = &%s,\n", d->children->name); |
Myles Watson | 1965a23 | 2010-06-10 04:06:52 +0000 | [diff] [blame] | 476 | if (d->next_sibling && device_match(d->next_sibling, ptr)) |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 477 | fprintf(fil, "\t\t\t.next=&%s_links[%d],\n", d->name, d->link+1); |
| 478 | else |
| 479 | fprintf(fil, "\t\t\t.next = NULL,\n"); |
| 480 | fprintf(fil, "\t\t},\n"); |
| 481 | } |
| 482 | d = d->next_sibling; |
| 483 | } |
| 484 | } else { |
| 485 | if (ptr->children) { |
| 486 | fprintf(fil, "\t\t[0] = {\n"); |
| 487 | fprintf(fil, "\t\t\t.link_num = 0,\n"); |
| 488 | fprintf(fil, "\t\t\t.dev = &%s,\n", ptr->name); |
| 489 | fprintf(fil, "\t\t\t.children = &%s,\n", ptr->children->name); |
| 490 | fprintf(fil, "\t\t\t.next = NULL,\n"); |
| 491 | fprintf(fil, "\t\t},\n"); |
| 492 | } |
| 493 | } |
| 494 | fprintf(fil, "\t};\n"); |
| 495 | } |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 496 | if ((ptr->type == chip) && (ptr->chiph_exists)) { |
| 497 | if (ptr->reg) { |
Stefan Reinauer | 57879c9 | 2012-07-31 16:47:25 -0700 | [diff] [blame] | 498 | fprintf(fil, "ROMSTAGE_CONST struct %s_config ROMSTAGE_CONST %s_info_%d = {\n", |
| 499 | ptr->name_underscore, ptr->name_underscore, |
| 500 | ptr->id); |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 501 | struct reg *r = ptr->reg; |
| 502 | while (r) { |
| 503 | fprintf(fil, "\t.%s = %s,\n", r->key, r->value); |
| 504 | r = r->next; |
| 505 | } |
| 506 | fprintf(fil, "};\n\n"); |
| 507 | } else { |
Stefan Reinauer | 57879c9 | 2012-07-31 16:47:25 -0700 | [diff] [blame] | 508 | fprintf(fil, "ROMSTAGE_CONST struct %s_config ROMSTAGE_CONST %s_info_%d = { };\n", |
Kyösti Mälkki | 472d902 | 2011-12-05 20:33:55 +0200 | [diff] [blame] | 509 | ptr->name_underscore, ptr->name_underscore, ptr->id); |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 510 | } |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | static void walk_device_tree(FILE *fil, struct device *ptr, void (*func)(FILE *, struct device*), struct device *chips) { |
| 515 | do { |
| 516 | func(fil, ptr); |
| 517 | ptr = ptr->next_sibling; |
| 518 | } while (ptr); |
| 519 | } |
| 520 | |
Sven Schnelle | 270a908 | 2011-03-01 19:58:15 +0000 | [diff] [blame] | 521 | static void inherit_subsystem_ids(FILE *file, struct device *dev) |
| 522 | { |
| 523 | struct device *p; |
Sven Schnelle | 270a908 | 2011-03-01 19:58:15 +0000 | [diff] [blame] | 524 | |
| 525 | if (dev->subsystem_vendor != -1 && dev->subsystem_device != -1) { |
| 526 | /* user already gave us a subsystem vendor/device */ |
| 527 | return; |
| 528 | } |
| 529 | |
Sylvain "ythier" Hitier | 5325a48 | 2011-03-01 21:57:11 +0000 | [diff] [blame] | 530 | for(p = dev; p && p != p->parent; p = p->parent) { |
Sven Schnelle | 270a908 | 2011-03-01 19:58:15 +0000 | [diff] [blame] | 531 | |
| 532 | if (p->bustype != PCI && p->bustype != PCI_DOMAIN) |
| 533 | continue; |
| 534 | |
| 535 | if (p->inherit_subsystem) { |
| 536 | dev->subsystem_vendor = p->subsystem_vendor; |
| 537 | dev->subsystem_device = p->subsystem_device; |
| 538 | break; |
| 539 | } |
| 540 | } |
| 541 | } |
| 542 | |
Kyösti Mälkki | 472d902 | 2011-12-05 20:33:55 +0200 | [diff] [blame] | 543 | static void usage(void) |
| 544 | { |
| 545 | printf("usage: sconfig vendor/mainboard outputdir [-{s|b|k} outputfile]\n"); |
| 546 | printf("\t-s file\tcreate ramstage static device map\n"); |
| 547 | printf("\t-b file\tcreate bootblock init_mainboard()\n"); |
| 548 | printf("\t-k file\tcreate Kconfig devicetree section\n"); |
| 549 | printf("Defaults to \"-s static.c\" if no {s|b|k} specified.\n"); |
| 550 | exit (1); |
| 551 | } |
| 552 | |
| 553 | |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 554 | int main(int argc, char** argv) { |
Kyösti Mälkki | 472d902 | 2011-12-05 20:33:55 +0200 | [diff] [blame] | 555 | if (argc < 3) |
| 556 | usage(); |
| 557 | |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 558 | char *mainboard=argv[1]; |
| 559 | char *outputdir=argv[2]; |
| 560 | char *devtree=malloc(strlen(mainboard)+30); |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 561 | sprintf(devtree, "src/mainboard/%s/devicetree.cb", mainboard); |
Kyösti Mälkki | 472d902 | 2011-12-05 20:33:55 +0200 | [diff] [blame] | 562 | char *outputc; |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 563 | |
Kyösti Mälkki | 472d902 | 2011-12-05 20:33:55 +0200 | [diff] [blame] | 564 | if (argc == 3) { |
| 565 | scan_mode = STATIC_MODE; |
| 566 | outputc=malloc(strlen(outputdir)+20); |
| 567 | sprintf(outputc, "%s/static.c", outputdir); |
| 568 | } else if ((argc == 5) && (argv[3][0] == '-') && (argv[3][2] == 0)) { |
| 569 | |
| 570 | switch (argv[3][1]) { |
| 571 | case 's': |
| 572 | scan_mode = STATIC_MODE; |
| 573 | break; |
| 574 | case 'b': |
| 575 | scan_mode = BOOTBLOCK_MODE; |
| 576 | break; |
| 577 | case 'k': |
| 578 | scan_mode = KCONFIG_MODE; |
| 579 | break; |
| 580 | default: |
| 581 | usage(); |
| 582 | break; |
| 583 | } |
| 584 | char *outputfile=argv[4]; |
| 585 | |
| 586 | outputc=malloc(strlen(outputdir)+strlen(outputfile)+2); |
| 587 | sprintf(outputc, "%s/%s", outputdir, outputfile); |
| 588 | } |
| 589 | |
| 590 | headers.next = 0; |
Stefan Reinauer | 188e3c2 | 2012-07-26 12:46:48 -0700 | [diff] [blame] | 591 | #ifdef MAINBOARDS_HAVE_CHIP_H |
Kyösti Mälkki | 472d902 | 2011-12-05 20:33:55 +0200 | [diff] [blame] | 592 | if (scan_mode == STATIC_MODE) { |
| 593 | headers.next = malloc(sizeof(struct header)); |
| 594 | headers.next->name = malloc(strlen(mainboard)+12); |
| 595 | headers.next->next = 0; |
| 596 | sprintf(headers.next->name, "mainboard/%s", mainboard); |
| 597 | } |
Stefan Reinauer | 188e3c2 | 2012-07-26 12:46:48 -0700 | [diff] [blame] | 598 | #endif |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 599 | |
| 600 | FILE *filec = fopen(devtree, "r"); |
Stefan Reinauer | 7c1f6b8 | 2010-08-16 18:21:56 +0000 | [diff] [blame] | 601 | if (!filec) { |
| 602 | fprintf(stderr, "Could not open file '%s' for reading: ", devtree); |
| 603 | perror(NULL); |
| 604 | exit(1); |
| 605 | } |
| 606 | |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 607 | yyrestart(filec); |
| 608 | |
Patrick Georgi | 68befd5 | 2010-05-05 12:05:25 +0000 | [diff] [blame] | 609 | lastdev = head = &root; |
Stefan Reinauer | 7c1f6b8 | 2010-08-16 18:21:56 +0000 | [diff] [blame] | 610 | |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 611 | yyparse(); |
Stefan Reinauer | 7c1f6b8 | 2010-08-16 18:21:56 +0000 | [diff] [blame] | 612 | |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 613 | fclose(filec); |
| 614 | |
| 615 | if ((head->type == chip) && (!head->chiph_exists)) { |
| 616 | struct device *tmp = head; |
| 617 | head = &root; |
| 618 | while (head->next != tmp) head = head->next; |
| 619 | } |
| 620 | |
Kyösti Mälkki | 472d902 | 2011-12-05 20:33:55 +0200 | [diff] [blame] | 621 | FILE *autogen = fopen(outputc, "w"); |
| 622 | if (!autogen) { |
Stefan Reinauer | 7c1f6b8 | 2010-08-16 18:21:56 +0000 | [diff] [blame] | 623 | fprintf(stderr, "Could not open file '%s' for writing: ", outputc); |
| 624 | perror(NULL); |
| 625 | exit(1); |
| 626 | } |
| 627 | |
Kyösti Mälkki | 472d902 | 2011-12-05 20:33:55 +0200 | [diff] [blame] | 628 | struct header *h; |
| 629 | if (scan_mode == STATIC_MODE) { |
| 630 | |
| 631 | fprintf(autogen, "#include <device/device.h>\n"); |
| 632 | fprintf(autogen, "#include <device/pci.h>\n"); |
| 633 | h = &headers; |
| 634 | while (h->next) { |
| 635 | h = h->next; |
Kyösti Mälkki | aada2e1 | 2012-10-07 15:08:32 +0200 | [diff] [blame] | 636 | if (h->chiph_exists) |
| 637 | fprintf(autogen, "#include \"%s/chip.h\"\n", h->name); |
Kyösti Mälkki | 472d902 | 2011-12-05 20:33:55 +0200 | [diff] [blame] | 638 | } |
Kyösti Mälkki | aada2e1 | 2012-10-07 15:08:32 +0200 | [diff] [blame] | 639 | fprintf(autogen, "\n#ifndef __PRE_RAM__\n"); |
Kyösti Mälkki | fee73df | 2012-08-21 11:37:11 +0300 | [diff] [blame] | 640 | h = &headers; |
| 641 | while (h->next) { |
| 642 | h = h->next; |
Kyösti Mälkki | 1a2a6ee | 2012-03-18 20:19:28 +0200 | [diff] [blame] | 643 | char *name_underscore = translate_name(h->name, UNSLASH); |
Kyösti Mälkki | fee73df | 2012-08-21 11:37:11 +0300 | [diff] [blame] | 644 | fprintf(autogen, "extern struct chip_operations %s_ops;\n", name_underscore); |
| 645 | free(name_underscore); |
| 646 | } |
Kyösti Mälkki | aada2e1 | 2012-10-07 15:08:32 +0200 | [diff] [blame] | 647 | fprintf(autogen, "#endif\n"); |
Kyösti Mälkki | 472d902 | 2011-12-05 20:33:55 +0200 | [diff] [blame] | 648 | |
| 649 | walk_device_tree(autogen, &root, inherit_subsystem_ids, NULL); |
| 650 | fprintf(autogen, "\n/* pass 0 */\n"); |
| 651 | walk_device_tree(autogen, &root, pass0, NULL); |
Stefan Reinauer | 188e3c2 | 2012-07-26 12:46:48 -0700 | [diff] [blame] | 652 | fprintf(autogen, "\n/* pass 1 */\n" |
Stefan Reinauer | 57879c9 | 2012-07-31 16:47:25 -0700 | [diff] [blame] | 653 | "ROMSTAGE_CONST struct device * ROMSTAGE_CONST last_dev = &%s;\n", lastdev->name); |
Stefan Reinauer | 188e3c2 | 2012-07-26 12:46:48 -0700 | [diff] [blame] | 654 | #ifdef MAINBOARDS_HAVE_CHIP_H |
Stefan Reinauer | 57879c9 | 2012-07-31 16:47:25 -0700 | [diff] [blame] | 655 | fprintf(autogen, "static ROMSTAGE_CONST struct mainboard_config ROMSTAGE_CONST mainboard_info_0;\n"); |
Stefan Reinauer | a675d49 | 2012-08-07 14:50:47 -0700 | [diff] [blame] | 656 | #else |
| 657 | fprintf(autogen, "extern struct chip_operations mainboard_ops;\n"); |
Stefan Reinauer | 188e3c2 | 2012-07-26 12:46:48 -0700 | [diff] [blame] | 658 | #endif |
Kyösti Mälkki | 472d902 | 2011-12-05 20:33:55 +0200 | [diff] [blame] | 659 | walk_device_tree(autogen, &root, pass1, NULL); |
| 660 | |
| 661 | } else if (scan_mode == BOOTBLOCK_MODE) { |
| 662 | h = &headers; |
| 663 | while (h->next) { |
| 664 | h = h->next; |
| 665 | fprintf(autogen, "#include \"%s/bootblock.c\"\n", h->name); |
| 666 | } |
| 667 | |
| 668 | fprintf(autogen, "\n#if CONFIG_HAS_MAINBOARD_BOOTBLOCK\n"); |
| 669 | fprintf(autogen, "#include \"mainboard/%s/bootblock.c\"\n", mainboard); |
| 670 | fprintf(autogen, "#else\n"); |
| 671 | fprintf(autogen, "static unsigned long init_mainboard(int bsp_cpu)\n{\n"); |
| 672 | fprintf(autogen, "\tif (! bsp_cpu) return 0;\n"); |
| 673 | h = &headers; |
| 674 | while (h->next) { |
| 675 | h = h->next; |
Kyösti Mälkki | 1a2a6ee | 2012-03-18 20:19:28 +0200 | [diff] [blame] | 676 | char * buf = translate_name(h->name, UNSLASH); |
| 677 | if (buf) { |
| 678 | fprintf(autogen, "\tinit_%s();\n", buf); |
| 679 | free(buf); |
| 680 | } |
Kyösti Mälkki | 472d902 | 2011-12-05 20:33:55 +0200 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | fprintf(autogen, "\treturn 0;\n}\n"); |
| 684 | fprintf(autogen, "#endif\n"); |
| 685 | |
| 686 | } else if (scan_mode == KCONFIG_MODE) { |
| 687 | fprintf(autogen, "\nconfig MAINBOARD_DIR\n\tstring\n"); |
| 688 | fprintf(autogen, "\tdefault %s\n", mainboard); |
| 689 | |
| 690 | fprintf(autogen, "\nconfig MAINBOARD_DEVTREE\n\tdef_bool y\n"); |
| 691 | h = &headers; |
| 692 | while (h->next) { |
| 693 | h = h->next; |
Kyösti Mälkki | 1a2a6ee | 2012-03-18 20:19:28 +0200 | [diff] [blame] | 694 | char * buf = translate_name(h->name, TO_UPPER); |
| 695 | if (buf) { |
| 696 | fprintf(autogen, "\tselect %s\n", buf); |
| 697 | free(buf); |
| 698 | } |
Kyösti Mälkki | 472d902 | 2011-12-05 20:33:55 +0200 | [diff] [blame] | 699 | } |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 700 | } |
Sven Schnelle | 270a908 | 2011-03-01 19:58:15 +0000 | [diff] [blame] | 701 | |
Kyösti Mälkki | 472d902 | 2011-12-05 20:33:55 +0200 | [diff] [blame] | 702 | fclose(autogen); |
Stefan Reinauer | 7c1f6b8 | 2010-08-16 18:21:56 +0000 | [diff] [blame] | 703 | |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 704 | return 0; |
| 705 | } |