seperate code generation
[coreboot.git] / util / getpir / code_gen.c
1 #include <stdio.h>
2 #include <arch/pirq_routing.h>
3
4 static char *preamble[] = {
5         "/* This file was generated by getpir.c, do not modify! \n   (but if you do, please run checkpir on it to verify)\n",
6         " * Contains the IRQ Routing Table dumped directly from your memory, which BIOS sets up\n",
7         " *\n",
8         " * Documentation at : http://www.microsoft.com/hwdev/busbios/PCIIRQ.HTM\n*/\n\n",
9         "#include <arch/pirq_routing.h>\n\n",
10         "const struct irq_routing_table intel_irq_routing_table = {\n",
11         "\tPIRQ_SIGNATURE,  /* u32 signature */\n",
12         "\tPIRQ_VERSION,    /* u16 version   */\n",
13         0
14 };
15
16 void code_gen(char *filename, struct irq_routing_table *rt)
17 {
18         char **code = preamble;
19         struct irq_info *se_arr = (struct irq_info *) ((char *) rt + 32);
20         int i, ts = (rt->size - 32) / 16;
21         FILE *fpir;
22
23         if ((fpir = fopen(filename, "w")) == NULL) {
24                 printf("Failed creating file!\n");
25                 exit(2);
26         }
27
28         while (*code)
29                 fprintf(fpir, "%s", *code++);
30
31         fprintf(fpir, "\t32+16*%d,       /* there can be total %d devices on the bus */\n",
32                 ts, ts);
33         fprintf(fpir, "\t0x%02x,                 /* Where the interrupt router lies (bus) */\n",
34                 rt->rtr_bus);
35         fprintf(fpir, "\t(0x%02x<<3)|0x%01x,   /* Where the interrupt router lies (dev) */\n",
36                 rt->rtr_devfn >> 3, rt->rtr_devfn & 7);
37         fprintf(fpir, "\t%#x,            /* IRQs devoted exclusively to PCI usage */\n",
38                 rt->exclusive_irqs);
39         fprintf(fpir, "\t%#x,            /* Vendor */\n", rt->rtr_vendor);
40         fprintf(fpir, "\t%#x,            /* Device */\n", rt->rtr_device);
41         fprintf(fpir, "\t%#x,            /* Crap (miniport) */\n",
42                 rt->miniport_data);
43         fprintf(fpir, "\t{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* u8 rfu[11] */\n");
44         fprintf(fpir, "\t%#x,         /*  u8 checksum , this hase to set to some value that would give 0 after the sum of all bytes for this structure (including checksum) */\n",
45                 rt->checksum);
46         fprintf(fpir, "\t{\n");
47         fprintf(fpir, "\t\t/* bus,     dev|fn,   {link, bitmap}, {link, bitmap}, {link, bitmap}, {link, bitmap},  slot, rfu */\n");
48         for (i = 0; i < ts; i++) {
49                 fprintf(fpir, "\t\t{0x%02x,(0x%02x<<3)|0x%01x, {{0x%02x, 0x%04x}, {0x%02x, 0x%04x}, {0x%02x, 0x%04x}, {0x%02x, 0x0%04x}}, 0x%x, 0x%x},\n",
50                         (se_arr+i)->bus, (se_arr+i)->devfn >> 3,
51                         (se_arr+i)->devfn & 7, (se_arr+i)->irq[0].link,
52                         (se_arr+i)->irq[0].bitmap, (se_arr+i)->irq[1].link,
53                         (se_arr+i)->irq[1].bitmap, (se_arr+i)->irq[2].link,
54                         (se_arr+i)->irq[2].bitmap, (se_arr+i)->irq[3].link,
55                         (se_arr+i)->irq[3].bitmap, (se_arr+i)->slot,
56                         (se_arr+i)->rfu);
57         }
58         fprintf(fpir, "\t}\n");
59         fprintf(fpir, "};\n");
60
61         fclose(fpir);
62 }