2004-04-13 23:06:45 +02:00
|
|
|
/* getpir.c : This software is released under GPL
|
2008-01-18 16:34:24 +01:00
|
|
|
* For coreboot use only
|
2007-04-11 20:44:42 +02:00
|
|
|
* Aug 26 2001 , Nikolai Vladychevski, <niko@isl.net.mx>
|
|
|
|
* 2007.04.09 Jeremy Jackson <jerj@coplanar.net>
|
|
|
|
* updated for amd64 and general 64 bit portability
|
|
|
|
*/
|
2004-04-13 23:06:45 +02:00
|
|
|
|
|
|
|
#include <stdio.h>
|
2007-04-11 20:44:42 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
2004-04-15 00:24:50 +02:00
|
|
|
#include <sys/mman.h>
|
2007-04-11 20:44:42 +02:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2004-04-13 23:06:45 +02:00
|
|
|
|
2007-04-11 20:44:42 +02:00
|
|
|
#include "pirq_routing.h"
|
|
|
|
#include "checksum.h"
|
|
|
|
#include "code_gen.h"
|
2004-04-13 23:06:45 +02:00
|
|
|
|
2007-04-11 20:44:42 +02:00
|
|
|
#if defined (__sun) && (defined(__i386) || defined(__amd64))
|
|
|
|
# define MEM_DEV "/dev/xsvc"
|
|
|
|
#else
|
|
|
|
# define MEM_DEV "/dev/mem"
|
|
|
|
#endif
|
2004-04-13 23:06:45 +02:00
|
|
|
|
2004-04-15 00:24:50 +02:00
|
|
|
static struct irq_routing_table *probe_table(int fd_mem)
|
2004-04-13 23:06:45 +02:00
|
|
|
{
|
2004-04-15 00:24:50 +02:00
|
|
|
char *ptr, signature[] = "$PIR";
|
|
|
|
struct irq_routing_table *rt;
|
2009-09-26 18:18:22 +02:00
|
|
|
int size = 16;
|
2004-04-15 00:24:50 +02:00
|
|
|
|
2009-09-26 18:18:22 +02:00
|
|
|
ptr = mmap(0, 0x10000, PROT_READ, MAP_SHARED,
|
|
|
|
fd_mem, (off_t) 0xf0000);
|
2004-04-15 00:24:50 +02:00
|
|
|
|
2007-04-11 20:44:42 +02:00
|
|
|
if (ptr == MAP_FAILED) {
|
|
|
|
perror("Mapping system memory failed: ");
|
2009-09-26 18:18:22 +02:00
|
|
|
return NULL;
|
2007-04-11 20:44:42 +02:00
|
|
|
}
|
|
|
|
|
2009-09-26 18:18:22 +02:00
|
|
|
do {
|
|
|
|
rt = (struct irq_routing_table *) memmem(ptr + size, 16, signature, 4);
|
|
|
|
if (rt != NULL) {
|
|
|
|
printf("Found PCI IRQ routing table signature at %p.\n",
|
|
|
|
(void *) ((char *) rt - ptr + 0xf0000));
|
|
|
|
printf("Validating... ");
|
|
|
|
if (!calc_checksum(rt)) {
|
|
|
|
printf("checksum is ok.\n");
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
printf("checksum is wrong.\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
size += 16;
|
|
|
|
} while (size < 0xFFFF);
|
|
|
|
|
|
|
|
if (size >= 0xFFFF) {
|
2007-04-11 20:44:42 +02:00
|
|
|
printf("No PCI IRQ routing table signature found.\n");
|
2009-09-26 18:18:22 +02:00
|
|
|
munmap(ptr, 0x10000);
|
|
|
|
return NULL;
|
2004-04-13 23:06:45 +02:00
|
|
|
}
|
2009-09-26 18:18:22 +02:00
|
|
|
|
2004-04-15 00:24:50 +02:00
|
|
|
return rt;
|
2004-04-13 23:06:45 +02:00
|
|
|
}
|
|
|
|
|
2007-04-11 20:44:42 +02:00
|
|
|
int main(void)
|
2004-04-13 23:06:45 +02:00
|
|
|
{
|
2004-04-15 00:24:50 +02:00
|
|
|
int fd_mem;
|
2009-09-26 18:18:22 +02:00
|
|
|
struct irq_routing_table *rt;
|
2004-04-13 23:06:45 +02:00
|
|
|
|
|
|
|
if (getuid()) {
|
2007-04-11 20:44:42 +02:00
|
|
|
fprintf(stderr, "Run me as root, I need access to " MEM_DEV ".\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
fd_mem = open(MEM_DEV, O_RDONLY);
|
|
|
|
if (fd_mem < 0) {
|
|
|
|
perror("Could not open " MEM_DEV ":");
|
2004-04-13 23:06:45 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2007-04-11 20:44:42 +02:00
|
|
|
printf("Probing PIRQ table in memory.\n");
|
2004-04-15 00:24:50 +02:00
|
|
|
rt = probe_table(fd_mem);
|
2009-09-26 18:18:22 +02:00
|
|
|
if (rt != NULL) {
|
|
|
|
printf("Creating irq_tables.c ...\n");
|
|
|
|
code_gen("irq_tables.c", rt);
|
|
|
|
printf
|
|
|
|
("Done, you can move the file to the coreboot tree now.\n");
|
|
|
|
}
|
2004-04-15 00:24:50 +02:00
|
|
|
close(fd_mem);
|
|
|
|
|
2007-04-11 20:44:42 +02:00
|
|
|
|
|
|
|
return 0;
|
2004-04-13 23:06:45 +02:00
|
|
|
}
|