blob: 5bcdd452a3b7b503858390d375807e4fe6e24058 [file] [log] [blame]
Li-Ta Lofd8f02f2004-04-13 21:06:45 +00001/* 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
Li-Ta Lofd8f02f2004-04-13 21:06:45 +00006#include <stdio.h>
Li-Ta Lo6463ae72004-04-14 22:24:50 +00007#include <sys/mman.h>
Li-Ta Lofd8f02f2004-04-13 21:06:45 +00008
Li-Ta Lo6c4c0042004-04-13 23:19:27 +00009#include <arch/pirq_routing.h>
Li-Ta Lofd8f02f2004-04-13 21:06:45 +000010
Li-Ta Lo6463ae72004-04-14 22:24:50 +000011#define O_RDONLY 0x00
Li-Ta Lofd8f02f2004-04-13 21:06:45 +000012
Li-Ta Lo6463ae72004-04-14 22:24:50 +000013static struct irq_routing_table *probe_table(int fd_mem)
Li-Ta Lofd8f02f2004-04-13 21:06:45 +000014{
Li-Ta Lo6463ae72004-04-14 22:24:50 +000015 char *ptr, signature[] = "$PIR";
16 struct irq_routing_table *rt;
Li-Ta Lofd8f02f2004-04-13 21:06:45 +000017
Li-Ta Lo6463ae72004-04-14 22:24:50 +000018 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);
Li-Ta Lofd8f02f2004-04-13 21:06:45 +000029 }
Li-Ta Lo6463ae72004-04-14 22:24:50 +000030 return rt;
Li-Ta Lofd8f02f2004-04-13 21:06:45 +000031}
32
33main()
34{
Li-Ta Lo6463ae72004-04-14 22:24:50 +000035 int fd_mem;
36 FILE *fpir;
37 struct irq_routing_table *rt;
Li-Ta Lofd8f02f2004-04-13 21:06:45 +000038
39 if (getuid()) {
40 perror("Run me as root, I need access to /dev/mem");
41 exit(1);
42 }
Li-Ta Lo6463ae72004-04-14 22:24:50 +000043 fd_mem = open("/dev/mem", O_RDONLY);
Li-Ta Lofd8f02f2004-04-13 21:06:45 +000044
Li-Ta Lo6463ae72004-04-14 22:24:50 +000045 printf("Probing PIRQ table in memory\n");
46 rt = probe_table(fd_mem);
Li-Ta Lofd8f02f2004-04-13 21:06:45 +000047
Li-Ta Lo6463ae72004-04-14 22:24:50 +000048 printf("Validating..\n");
49 if (!calc_checksum(rt))
Li-Ta Lofd8f02f2004-04-13 21:06:45 +000050 printf("Checksum is ok!\n");
Li-Ta Lofd8f02f2004-04-13 21:06:45 +000051
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 }
Li-Ta Lo6463ae72004-04-14 22:24:50 +000058 code_gen(fpir, rt);
Li-Ta Lofd8f02f2004-04-13 21:06:45 +000059 fclose(fpir);
Li-Ta Lo6463ae72004-04-14 22:24:50 +000060
61 close(fd_mem);
62
Li-Ta Lofd8f02f2004-04-13 21:06:45 +000063 printf("Done, you can move the file to the LinuxBios tree now.\n");
64}