summaryrefslogtreecommitdiff
path: root/util/getpir/getpir.c
blob: 5bcdd452a3b7b503858390d375807e4fe6e24058 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* getpir.c : This software is released under GPL
   For Linuxbios use only
   Aug 26 2001 , Nikolai Vladychevski, <niko@isl.net.mx>
*/

#include <stdio.h>
#include <sys/mman.h>

#include <arch/pirq_routing.h>

#define O_RDONLY 0x00

static struct irq_routing_table *probe_table(int fd_mem)
{
	char *ptr, signature[] = "$PIR";
	struct irq_routing_table *rt;

	ptr =  mmap(0, 0x10000, PROT_READ, MAP_SHARED,
		    fd_mem, (off_t) 0xf0000);

	rt = (struct irq_routing_table *) memmem(ptr, 0xFFFF, signature, 4);

	if (rt != NULL) {
		printf("Found PCI IRQ Routing table signature at 0x%04x of system memory\n",
		       (char *) rt - ptr + 0xf0000);
	} else {
		printf("No PCI IRQ Routing table signature in the memory\n");		
		exit(1);
	}
	return rt;
}

main()
{
	int fd_mem;
	FILE *fpir;
 	struct irq_routing_table *rt;

	if (getuid()) {
		perror("Run me as root, I need access to /dev/mem");
		exit(1);
	}
	fd_mem = open("/dev/mem", O_RDONLY);

	printf("Probing PIRQ table in memory\n");
	rt = probe_table(fd_mem);

	printf("Validating..\n");
	if (!calc_checksum(rt))
		printf("Checksum is ok!\n");

	printf("Creating irq_tables.c .....\n");
	fpir = fopen("irq_tables.c", "w");
	if (!fpir) {
		printf("Failed creating file!\n");
		exit(2);
	}
	code_gen(fpir, rt);
	fclose(fpir);

	close(fd_mem);

	printf("Done, you can move the file to the LinuxBios tree now.\n");
}