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