diff options
author | Mohamed Mansoor <mansoor@iwavesystems.com> | 2009-09-26 16:18:22 +0000 |
---|---|---|
committer | Stefan Reinauer <stepan@openbios.org> | 2009-09-26 16:18:22 +0000 |
commit | bde683ce9fcc346096a07222047fa5a16aa74243 (patch) | |
tree | 41fcbdcd15c911a4cb41e460f534defd4880034f /util/getpir/getpir.c | |
parent | 5db685fedfe7f291719c90088bbf7618b31f3da6 (diff) |
This patch changes following in getpir application.
1 - Moved the check sum validation to probe_table function.
2 - Proper handling of resources allocated.
3 - Signature check is done in 16 byte boundaries.
4 - irq_tables.c file is created only if a valid PIRQ table is found.
5 – Makefile and README file are modified accordingly.
Signed-off-by: Mohamed Mansoor <mansoor@iwavesystems.com>
Acked-by: Stefan Reinauer <stepan@coresystems.de>
git-svn-id: svn://svn.coreboot.org/coreboot/trunk@4680 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Diffstat (limited to 'util/getpir/getpir.c')
-rw-r--r-- | util/getpir/getpir.c | 53 |
1 files changed, 31 insertions, 22 deletions
diff --git a/util/getpir/getpir.c b/util/getpir/getpir.c index d0ad978a40..6fc3a95d8a 100644 --- a/util/getpir/getpir.c +++ b/util/getpir/getpir.c @@ -28,31 +28,45 @@ static struct irq_routing_table *probe_table(int fd_mem) { char *ptr, signature[] = "$PIR"; struct irq_routing_table *rt; + int size = 16; - ptr = mmap(0, 0x10000, PROT_READ, MAP_SHARED, - fd_mem, (off_t) 0xf0000); + ptr = mmap(0, 0x10000, PROT_READ, MAP_SHARED, + fd_mem, (off_t) 0xf0000); if (ptr == MAP_FAILED) { perror("Mapping system memory failed: "); - exit(1); + return NULL; } - rt = (struct irq_routing_table *) memmem(ptr, 0xFFFF, signature, 4); - - if (rt != NULL) { - printf("Found PCI IRQ routing table signature at %p.\n", - (void *)((char *)rt - ptr + 0xf0000)); - } else { + 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) { printf("No PCI IRQ routing table signature found.\n"); - exit(1); + munmap(ptr, 0x10000); + return NULL; } + return rt; } int main(void) { int fd_mem; - struct irq_routing_table *rt; + struct irq_routing_table *rt; if (getuid()) { fprintf(stderr, "Run me as root, I need access to " MEM_DEV ".\n"); @@ -66,19 +80,14 @@ int main(void) printf("Probing PIRQ table in memory.\n"); rt = probe_table(fd_mem); - - printf("Validating... "); - if (!calc_checksum(rt)) - printf("checksum is ok.\n"); - else - printf("checksum is wrong.\n"); - - printf("Creating irq_tables.c ...\n"); - code_gen("irq_tables.c", rt); - + 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"); + } close(fd_mem); - printf("Done, you can move the file to the coreboot tree now.\n"); return 0; } |