seperate code generation
[coreboot.git] / util / getpir / getpir.c
1 /* getpir.c : This software is released under GPL
2    For Linuxbios use only
3    Aug 26 2001 , Nikolai Vladychevski, <niko@isl.net.mx>
4 */
5
6 #include <stdio.h>
7 #include <sys/mman.h>
8
9 #include <arch/pirq_routing.h>
10
11 #define O_RDONLY 0x00
12
13 static struct irq_routing_table *probe_table(int fd_mem)
14 {
15         char *ptr, signature[] = "$PIR";
16         struct irq_routing_table *rt;
17
18         ptr =  mmap(0, 0x10000, PROT_READ, MAP_SHARED,
19                     fd_mem, (off_t) 0xf0000);
20
21         rt = (struct irq_routing_table *) memmem(ptr, 0xFFFF, signature, 4);
22
23         if (rt != NULL) {
24                 printf("Found PCI IRQ Routing table signature at 0x%04x of system memory\n",
25                        (char *) rt - ptr + 0xf0000);
26         } else {
27                 printf("No PCI IRQ Routing table signature in the memory\n");           
28                 exit(1);
29         }
30         return rt;
31 }
32
33 main()
34 {
35         int fd_mem;
36         struct irq_routing_table *rt;
37
38         if (getuid()) {
39                 perror("Run me as root, I need access to /dev/mem");
40                 exit(1);
41         }
42         fd_mem = open("/dev/mem", O_RDONLY);
43
44         printf("Probing PIRQ table in memory\n");
45         rt = probe_table(fd_mem);
46
47         printf("Validating..\n");
48         if (!calc_checksum(rt))
49                 printf("Checksum is ok!\n");
50
51         printf("Creating irq_tables.c .....\n");
52         code_gen("irq_tables.c", rt);
53
54         close(fd_mem);
55
56         printf("Done, you can move the file to the LinuxBios tree now.\n");
57 }