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
This commit is contained in:
Jeremy Jackson 2007-04-11 18:44:42 +00:00 committed by Stefan Reinauer
parent 4880353e03
commit 46d65e85a1
8 changed files with 130 additions and 51 deletions

View File

@ -1,33 +1,25 @@
# change to the path of your linuxbios tree #
#LINUXBIOSROOT=/home/rminnich/src//freebios/ #
LINUXBIOSROOT=../.. #
INCLUDEPATH=$(LINUXBIOSROOT)/src/arch/i386/include CC=gcc
INCLUDE2=$(LINUXBIOSROOT)/src/include CFLAGS=-O2 -D_GNU_SOURCE -DGETPIR -Wall
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
all: getpir checkpir all: getpir checkpir
./checkpir
getpir: getpir.o checksum.o code_gen.o
$(CC) $(CFLAGS) -o getpir $^
checkpir: checkpir.c checksum.o irq_tables.o checkpir: checkpir.c checksum.o irq_tables.o
gcc -o checkpir -I$(INCLUDEPATH) -I$(INCLUDE2) irq_tables.o checksum.o checkpir.c $(CC) $(CFLAGS) -o checkpir $^
checksum.o: checksum.c irq_tables.c: getpir
gcc -c -I$(INCLUDEPATH) -I$(INCLUDE2) checksum.c ./getpir
irq_tables.o: irq_tables.c
gcc -c -I$(INCLUDEPATH) -I$(INCLUDE2) irq_tables.c
clean: clean:
rm -f getpir checkpir *.o *~ rm -f getpir checkpir *.o *~
cleantable: distclean: clean
rm -f irq_table.o rm -f irq_tables.o irq_tables.c
test: checkpir
./checkpir ;\
exit 0;

View File

@ -1,16 +1,15 @@
/* checkpir.c : This software is released under GPL /* checkpir.c : This software is released under GPL
For Linuxbios use only * For LinuxBIOS use only
Aug 26 2001 , Nikolai Vladychevski, <niko@isl.net.mx> * Aug 26 2001 , Nikolai Vladychevski, <niko@isl.net.mx>
*/ */
#include <stdio.h> #include <stdio.h>
#include <arch/pirq_routing.h> #include "pirq_routing.h"
#include "checksum.h" #include "checksum.h"
struct irq_routing_table *rt; struct irq_routing_table *rt;
main() int main(void)
{ {
uint8_t sum, newsum; uint8_t sum, newsum;
@ -21,11 +20,12 @@ main()
printf("(no other tests are done)\n"); printf("(no other tests are done)\n");
if (!sum) { 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 { } else {
newsum = rt->checksum - sum; newsum = rt->checksum - sum;
printf("BAD CHECKSUM for IRQ Routing table !!!!\n"); printf("BAD CHECKSUM for IRQ Routing table !!!!\n");
printf("If you want to make it valid, change the checksum to: %#x\n", printf("If you want to make it valid, change the checksum to: %#x\n",
newsum); newsum);
} }
return 0;
} }

View File

@ -1,5 +1,4 @@
#include <arch/pirq_routing.h> #include "pirq_routing.h"
#include "checksum.h" #include "checksum.h"
int calc_checksum(struct irq_routing_table *rt) int calc_checksum(struct irq_routing_table *rt)

View File

@ -1,6 +1,6 @@
#ifndef __CHECKSUM_H__ #ifndef __CHECKSUM_H__
#define __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__ */

View File

@ -1,12 +1,17 @@
#include <stdio.h> #include <stdio.h>
#include <arch/pirq_routing.h> #include <stdlib.h>
#include "pirq_routing.h"
static char *preamble[] = { 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", "/* 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", " * Contains the IRQ Routing Table dumped directly from your memory, which BIOS sets up\n",
" *\n", " *\n",
" * Documentation at : http://www.microsoft.com/hwdev/busbios/PCIIRQ.HTM\n*/\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", "const struct irq_routing_table intel_irq_routing_table = {\n",
"\tPIRQ_SIGNATURE, /* u32 signature */\n", "\tPIRQ_SIGNATURE, /* u32 signature */\n",
"\tPIRQ_VERSION, /* u16 version */\n", "\tPIRQ_VERSION, /* u16 version */\n",

6
util/getpir/code_gen.h Normal file
View File

@ -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__ */

View File

@ -1,14 +1,28 @@
/* getpir.c : This software is released under GPL /* getpir.c : This software is released under GPL
For Linuxbios use only * For LinuxBIOS use only
Aug 26 2001 , Nikolai Vladychevski, <niko@isl.net.mx> * 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.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) 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, ptr = mmap(0, 0x10000, PROT_READ, MAP_SHARED,
fd_mem, (off_t) 0xf0000); 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); rt = (struct irq_routing_table *) memmem(ptr, 0xFFFF, signature, 4);
if (rt != NULL) { if (rt != NULL) {
printf("Found PCI IRQ Routing table signature at 0x%04x of system memory\n", printf("Found PCI IRQ routing table signature at %p.\n",
(char *) rt - ptr + 0xf0000); (void *)((char *)rt - ptr + 0xf0000));
} else { } else {
printf("No PCI IRQ Routing table signature in the memory\n"); printf("No PCI IRQ routing table signature found.\n");
exit(1); exit(1);
} }
return rt; return rt;
} }
main() int main(void)
{ {
int fd_mem; int fd_mem;
struct irq_routing_table *rt; struct irq_routing_table *rt;
if (getuid()) { 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); 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); rt = probe_table(fd_mem);
printf("Validating..\n"); printf("Validating... ");
if (!calc_checksum(rt)) 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); code_gen("irq_tables.c", rt);
close(fd_mem); 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;
} }

View File

@ -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 */