diff options
author | Jeremy Jackson <jerj@coplanar.net> | 2007-04-11 18:44:42 +0000 |
---|---|---|
committer | Stefan Reinauer <stepan@openbios.org> | 2007-04-11 18:44:42 +0000 |
commit | 46d65e85a1c0449f86497264d5958b3d85784767 (patch) | |
tree | 5cdc08216595f7de00c1df21ddc0d188d39b022e /util/getpir | |
parent | 4880353e03c62baacecaf634bc66c91be423f853 (diff) | |
download | coreboot-46d65e85a1c0449f86497264d5958b3d85784767.tar.xz |
Jeremy Jackson wrote:
I'm guessing nobody has tried compiling it with 64bit userspace?
Patch makes it compile cleanly and stops a "SEGV instead of working"
issue.
I also added a few checks for errors on system calls.
Signed-off-by: Jeremy Jackson <jerj@coplanar.net>
Reworked and
Acked-by: Stefan Reinauer <stepan@coresystems.de>
git-svn-id: svn://svn.coreboot.org/coreboot/trunk@2602 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Diffstat (limited to 'util/getpir')
-rw-r--r-- | util/getpir/Makefile | 36 | ||||
-rw-r--r-- | util/getpir/checkpir.c | 14 | ||||
-rw-r--r-- | util/getpir/checksum.c | 3 | ||||
-rw-r--r-- | util/getpir/checksum.h | 4 | ||||
-rw-r--r-- | util/getpir/code_gen.c | 9 | ||||
-rw-r--r-- | util/getpir/code_gen.h | 6 | ||||
-rw-r--r-- | util/getpir/getpir.c | 59 | ||||
-rw-r--r-- | util/getpir/pirq_routing.h | 50 |
8 files changed, 130 insertions, 51 deletions
diff --git a/util/getpir/Makefile b/util/getpir/Makefile index 07a6625c75..13bf47efc9 100644 --- a/util/getpir/Makefile +++ b/util/getpir/Makefile @@ -1,33 +1,25 @@ -# change to the path of your linuxbios tree -#LINUXBIOSROOT=/home/rminnich/src//freebios/ -LINUXBIOSROOT=../.. +# +# +# -INCLUDEPATH=$(LINUXBIOSROOT)/src/arch/i386/include -INCLUDE2=$(LINUXBIOSROOT)/src/include - -getpir: getpir.c checksum.o code_gen.o - gcc -o getpir -I$(INCLUDEPATH) -I$(INCLUDE2) getpir.c checksum.o code_gen.o - -code_gen.o: code_gen.c - gcc -c -I$(INCLUDEPATH) -I$(INCLUDE2) code_gen.c +CC=gcc +CFLAGS=-O2 -D_GNU_SOURCE -DGETPIR -Wall all: getpir checkpir + ./checkpir -checkpir: checkpir.c checksum.o irq_tables.o - gcc -o checkpir -I$(INCLUDEPATH) -I$(INCLUDE2) irq_tables.o checksum.o checkpir.c +getpir: getpir.o checksum.o code_gen.o + $(CC) $(CFLAGS) -o getpir $^ -checksum.o: checksum.c - gcc -c -I$(INCLUDEPATH) -I$(INCLUDE2) checksum.c +checkpir: checkpir.c checksum.o irq_tables.o + $(CC) $(CFLAGS) -o checkpir $^ -irq_tables.o: irq_tables.c - gcc -c -I$(INCLUDEPATH) -I$(INCLUDE2) irq_tables.c +irq_tables.c: getpir + ./getpir clean: rm -f getpir checkpir *.o *~ -cleantable: - rm -f irq_table.o +distclean: clean + rm -f irq_tables.o irq_tables.c -test: checkpir - ./checkpir ;\ - exit 0; diff --git a/util/getpir/checkpir.c b/util/getpir/checkpir.c index 2a738e78a4..6a9a79fa28 100644 --- a/util/getpir/checkpir.c +++ b/util/getpir/checkpir.c @@ -1,16 +1,15 @@ /* checkpir.c : This software is released under GPL - For Linuxbios use only - Aug 26 2001 , Nikolai Vladychevski, <niko@isl.net.mx> -*/ + * For LinuxBIOS use only + * Aug 26 2001 , Nikolai Vladychevski, <niko@isl.net.mx> + */ #include <stdio.h> -#include <arch/pirq_routing.h> - +#include "pirq_routing.h" #include "checksum.h" struct irq_routing_table *rt; -main() +int main(void) { uint8_t sum, newsum; @@ -21,11 +20,12 @@ main() printf("(no other tests are done)\n"); if (!sum) { - printf("Checksum for IRQ Routing table is ok. You can use it in LinuxBios now\n"); + printf("Checksum for IRQ Routing table is ok. You can use irq_tables.c in LinuxBIOS now.\n"); } else { newsum = rt->checksum - sum; printf("BAD CHECKSUM for IRQ Routing table !!!!\n"); printf("If you want to make it valid, change the checksum to: %#x\n", newsum); } + return 0; } diff --git a/util/getpir/checksum.c b/util/getpir/checksum.c index a202f90912..bcf342573f 100644 --- a/util/getpir/checksum.c +++ b/util/getpir/checksum.c @@ -1,5 +1,4 @@ -#include <arch/pirq_routing.h> - +#include "pirq_routing.h" #include "checksum.h" int calc_checksum(struct irq_routing_table *rt) diff --git a/util/getpir/checksum.h b/util/getpir/checksum.h index b5de899845..2acc433b75 100644 --- a/util/getpir/checksum.h +++ b/util/getpir/checksum.h @@ -1,6 +1,6 @@ #ifndef __CHECKSUM_H__ #define __CHECKSUM_H__ -extern int calc_checksum(struct irq_routing_table *rt); +int calc_checksum(struct irq_routing_table *rt); -#endif /* __CHECKSUN_H__ */ +#endif /* __CHECKSUM_H__ */ diff --git a/util/getpir/code_gen.c b/util/getpir/code_gen.c index 150d083d86..a458eae27a 100644 --- a/util/getpir/code_gen.c +++ b/util/getpir/code_gen.c @@ -1,12 +1,17 @@ #include <stdio.h> -#include <arch/pirq_routing.h> +#include <stdlib.h> +#include "pirq_routing.h" static char *preamble[] = { "/* This file was generated by getpir.c, do not modify! \n (but if you do, please run checkpir on it to verify)\n", " * Contains the IRQ Routing Table dumped directly from your memory, which BIOS sets up\n", " *\n", " * Documentation at : http://www.microsoft.com/hwdev/busbios/PCIIRQ.HTM\n*/\n\n", - "#include <arch/pirq_routing.h>\n\n", + "#ifdef GETPIR\n", + "#include \"pirq_routing.h\"\n", + "#else\n" + "#include <arch/pirq_routing.h>\n", + "#endif\n\n" "const struct irq_routing_table intel_irq_routing_table = {\n", "\tPIRQ_SIGNATURE, /* u32 signature */\n", "\tPIRQ_VERSION, /* u16 version */\n", diff --git a/util/getpir/code_gen.h b/util/getpir/code_gen.h new file mode 100644 index 0000000000..93bdaec74f --- /dev/null +++ b/util/getpir/code_gen.h @@ -0,0 +1,6 @@ +#ifndef __CODE_GEN_H__ +#define __CODE_GEN_H__ + +void code_gen(char *filename, struct irq_routing_table *rt); + +#endif /* __CODE_GEN_H__ */ diff --git a/util/getpir/getpir.c b/util/getpir/getpir.c index 7f08af6f6a..12b4a20f22 100644 --- a/util/getpir/getpir.c +++ b/util/getpir/getpir.c @@ -1,14 +1,28 @@ /* getpir.c : This software is released under GPL - For Linuxbios use only - Aug 26 2001 , Nikolai Vladychevski, <niko@isl.net.mx> -*/ + * For LinuxBIOS use only + * 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 + */ #include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <fcntl.h> #include <sys/mman.h> +#include <sys/types.h> +#include <sys/stat.h> -#include <arch/pirq_routing.h> +#include "pirq_routing.h" +#include "checksum.h" +#include "code_gen.h" -#define O_RDONLY 0x00 +#if defined (__sun) && (defined(__i386) || defined(__amd64)) +# define MEM_DEV "/dev/xsvc" +#else +# define MEM_DEV "/dev/mem" +#endif static struct irq_routing_table *probe_table(int fd_mem) { @@ -18,40 +32,53 @@ static struct irq_routing_table *probe_table(int fd_mem) ptr = mmap(0, 0x10000, PROT_READ, MAP_SHARED, fd_mem, (off_t) 0xf0000); + if (ptr == MAP_FAILED) { + perror("Mapping system memory failed: "); + exit(1); + } + 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); + printf("Found PCI IRQ routing table signature at %p.\n", + (void *)((char *)rt - ptr + 0xf0000)); } else { - printf("No PCI IRQ Routing table signature in the memory\n"); + printf("No PCI IRQ routing table signature found.\n"); exit(1); } return rt; } -main() +int main(void) { int fd_mem; struct irq_routing_table *rt; if (getuid()) { - perror("Run me as root, I need access to /dev/mem"); + 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 ":"); exit(1); } - fd_mem = open("/dev/mem", O_RDONLY); - printf("Probing PIRQ table in memory\n"); + printf("Probing PIRQ table in memory.\n"); rt = probe_table(fd_mem); - printf("Validating..\n"); + printf("Validating... "); if (!calc_checksum(rt)) - printf("Checksum is ok!\n"); + printf("checksum is ok.\n"); + else + printf("checksum is wrong.\n"); - printf("Creating irq_tables.c .....\n"); + printf("Creating irq_tables.c ...\n"); code_gen("irq_tables.c", rt); close(fd_mem); - printf("Done, you can move the file to the LinuxBios tree now.\n"); + printf("Done, you can move the file to the LinuxBIOS tree now.\n"); + + return 0; } diff --git a/util/getpir/pirq_routing.h b/util/getpir/pirq_routing.h new file mode 100644 index 0000000000..ef6fbeed0d --- /dev/null +++ b/util/getpir/pirq_routing.h @@ -0,0 +1,50 @@ +#ifndef ARCH_PIRQ_ROUTING_H +#define ARCH_PIRQ_ROUTING_H + +#include <stdint.h> + +#define PIRQ_SIGNATURE (('$' << 0) + ('P' << 8) + ('I' << 16) + ('R' << 24)) +#define PIRQ_VERSION 0x0100 + +struct irq_info { + uint8_t bus, devfn; /* Bus, device and function */ + struct { + uint8_t link; /* IRQ line ID, chipset dependent, 0=not routed */ + uint16_t bitmap; /* Available IRQs */ + } __attribute__((packed)) irq[4]; + uint8_t slot; /* Slot number, 0=onboard */ + uint8_t rfu; +} __attribute__((packed)); + +#if defined(IRQ_SLOT_COUNT) +#define IRQ_SLOTS_COUNT IRQ_SLOT_COUNT +#elif (__GNUC__ < 3) +#define IRQ_SLOTS_COUNT 1 +#else +#define IRQ_SLOTS_COUNT +#endif + +struct irq_routing_table { + uint32_t signature; /* PIRQ_SIGNATURE should be here */ + uint16_t version; /* PIRQ_VERSION */ + uint16_t size; /* Table size in bytes */ + uint8_t rtr_bus, rtr_devfn; /* Where the interrupt router lies */ + uint16_t exclusive_irqs; /* IRQs devoted exclusively to PCI usage */ + uint16_t rtr_vendor, rtr_device; /* Vendor and device ID of interrupt router */ + uint32_t miniport_data; /* Crap */ + uint8_t rfu[11]; + uint8_t checksum; /* Modulo 256 checksum must give zero */ + struct irq_info slots[IRQ_SLOTS_COUNT]; +} __attribute__((packed)); + +extern const struct irq_routing_table intel_irq_routing_table; + +#if HAVE_PIRQ_TABLE==1 +unsigned long copy_pirq_routing_table(unsigned long start); +unsigned long write_pirq_routing_table(unsigned long start); +#else +#define copy_pirq_routing_table(start) (start) +#define write_pirq_routing_table(start) (start) +#endif + +#endif /* ARCH_PIRQ_ROUTING_H */ |