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