-/* Line 1675 of yacc.c */
-#line 340 "/home/Patrick/work/coreboot/util/sconfig/sconfig.y"
-
-void pass0(FILE *fil, struct device *ptr) {
- if ((ptr->type == device) && (ptr->id != 0) && (!ptr->used))
- fprintf(fil, "struct device %s;\n", ptr->name);
- if ((ptr->type == device) && (ptr->id != 0) && ptr->used)
- fprintf(fil, "struct device %s;\n", ptr->aliased_name);
-}
-
-void pass1(FILE *fil, struct device *ptr) {
- if (!ptr->used && (ptr->type == device)) {
- fprintf(fil, "struct device %s = {\n", ptr->name);
- fprintf(fil, "\t.ops = %s,\n", (ptr->ops)?(ptr->ops):"0");
- fprintf(fil, "\t.bus = &%s.link[%d],\n", ptr->bus->name, ptr->bus->link);
- fprintf(fil, "\t.path = {");
- fprintf(fil, ptr->path, ptr->path_a, ptr->path_b);
- fprintf(fil, "},\n");
- fprintf(fil, "\t.enabled = %d,\n", ptr->enabled);
- fprintf(fil, "\t.on_mainboard = 1,\n");
- if (ptr->rescnt > 0) {
- fprintf(fil, "\t.resources = %d,\n", ptr->rescnt);
- fprintf(fil, "\t.resource = {\n");
- struct resource *r = ptr->res;
- while (r) {
- fprintf(fil, "\t\t{ .flags=IORESOURCE_FIXED | IORESOURCE_ASSIGNED | IORESOURCE_");
- if (r->type == IRQ) fprintf(fil, "IRQ");
- if (r->type == DRQ) fprintf(fil, "DRQ");
- if (r->type == IO) fprintf(fil, "IO");
- fprintf(fil, ", .index=0x%x, .base=0x%x},\n", r->index, r->base);
- r = r->next;
- }
- fprintf(fil, "\t },\n");
- }
- int link = 0;
- fprintf(fil, "\t.link = {\n");
- if (ptr->multidev) {
- struct device *d = ptr;
- while (d) {
- if (device_match(d, ptr)) {
- fprintf(fil, "\t\t[%d] = {\n", d->link);
- fprintf(fil, "\t\t\t.link = %d,\n", d->link);
- fprintf(fil, "\t\t\t.dev = &%s,\n", d->name);
- if (d->children)
- fprintf(fil, "\t\t\t.children = &%s,\n", d->children->name);
- fprintf(fil, "\t\t},\n");
- link++;
- }
- d = d->next_sibling;
- }
- } else {
- if (ptr->children) {
- fprintf(fil, "\t\t[0] = {\n");
- fprintf(fil, "\t\t\t.link = 0,\n");
- fprintf(fil, "\t\t\t.dev = &%s,\n", ptr->name);
- fprintf(fil, "\t\t\t.children = &%s,\n", ptr->children->name);
- fprintf(fil, "\t\t},\n");
- link++;
- }
- }
- fprintf(fil, "\t},\n");
- fprintf(fil, "\t.links = %d,\n", link);
- if (ptr->sibling)
- fprintf(fil, "\t.sibling = &%s,\n", ptr->sibling->name);
- if (ptr->chip->chiph_exists) {
- fprintf(fil, "\t.chip_ops = &%s_ops,\n", ptr->chip->name_underscore);
- fprintf(fil, "\t.chip_info = &%s_info_%d,\n", ptr->chip->name_underscore, ptr->chip->id);
- }
- if (ptr->nextdev)
- fprintf(fil, "\t.next=&%s\n", ptr->nextdev->name);
- fprintf(fil, "};\n");
- }
- if ((ptr->type == chip) && (ptr->chiph_exists)) {
- if (ptr->reg) {
- fprintf(fil, "struct %s_config %s_info_%d\t= {\n", ptr->name_underscore, ptr->name_underscore, ptr->id);
- struct reg *r = ptr->reg;
- while (r) {
- fprintf(fil, "\t.%s = %s,\n", r->key, r->value);
- r = r->next;
- }
- fprintf(fil, "};\n\n");
- } else {
- fprintf(fil, "struct %s_config %s_info_%d;\n", ptr->name_underscore, ptr->name_underscore, ptr->id);
- }
- }
-}
-
-void walk_device_tree(FILE *fil, struct device *ptr, void (*func)(FILE *, struct device*), struct device *chips) {
- do {
- func(fil, ptr);
- ptr = ptr->next_sibling;
- } while (ptr);
-}
-
-struct device mainboard = {
- .name = "mainboard",
- .name_underscore = "mainboard",
- .id = 0,
- .chip = &mainboard,
- .type = chip,
- .chiph_exists = 1,
- .children = &root
-};
-
-struct device root = {
- .name = "dev_root",
- .name_underscore = "dev_root",
- .id = 0,
- .chip = &mainboard,
- .type = device,
- .path = " .type = DEVICE_PATH_ROOT ",
- .ops = "&default_dev_ops_root",
- .parent = &root,
- .bus = &root,
- .enabled = 1
-};
-
-int main(int argc, char** argv) {
- if (argc != 3) {
- printf("usage: sconfig vendor/mainboard outputdir\n");
- return 1;
- }
- char *mainboard=argv[1];
- char *outputdir=argv[2];
- char *devtree=malloc(strlen(mainboard)+30);
- char *outputc=malloc(strlen(outputdir)+10);
- sprintf(devtree, "src/mainboard/%s/devicetree.cb", mainboard);
- sprintf(outputc, "%s/static.c", outputdir);
-
- headers.next = malloc(sizeof(struct header));
- headers.next->name = malloc(strlen(mainboard)+12);
- headers.next->next = 0;
- sprintf(headers.next->name, "mainboard/%s", mainboard);
-
- FILE *filec = fopen(devtree, "r");
- yyrestart(filec);
-
- FILE *staticc = fopen(outputc, "w");
-
- cur_bus = cur_parent = lastdev = head = &root;
- yyparse();
- fclose(filec);
-
- if ((head->type == chip) && (!head->chiph_exists)) {
- struct device *tmp = head;
- head = &root;
- while (head->next != tmp) head = head->next;
- }
-
- fprintf(staticc, "#include <device/device.h>\n");
- fprintf(staticc, "#include <device/pci.h>\n");
- struct header *h = &headers;
- while (h->next) {
- h = h->next;
- fprintf(staticc, "#include \"%s/chip.h\"\n", h->name);
- }
- fprintf(staticc, "\n/* pass 0 */\n");
- walk_device_tree(staticc, &root, pass0, NULL);
- fprintf(staticc, "\n/* pass 1 */\nstruct mainboard_config mainboard_info_0;\nstruct device **last_dev_p = &%s.next;\n", lastdev->name);
- walk_device_tree(staticc, &root, pass1, NULL);