seperate checksum and code generating code.
[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         FILE *fpir;
37         struct irq_routing_table *rt;
38
39         if (getuid()) {
40                 perror("Run me as root, I need access to /dev/mem");
41                 exit(1);
42         }
43         fd_mem = open("/dev/mem", O_RDONLY);
44
45         printf("Probing PIRQ table in memory\n");
46         rt = probe_table(fd_mem);
47
48         printf("Validating..\n");
49         if (!calc_checksum(rt))
50                 printf("Checksum is ok!\n");
51
52         printf("Creating irq_tables.c .....\n");
53         fpir = fopen("irq_tables.c", "w");
54         if (!fpir) {
55                 printf("Failed creating file!\n");
56                 exit(2);
57         }
58         code_gen(fpir, rt);
59         fclose(fpir);
60
61         close(fd_mem);
62
63         printf("Done, you can move the file to the LinuxBios tree now.\n");
64 }