Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1 | #include <console/console.h> |
| 2 | #include <arch/pirq_routing.h> |
| 3 | #include <string.h> |
| 4 | |
Greg Watson | 9f46132 | 2004-03-23 17:41:15 +0000 | [diff] [blame] | 5 | #if (DEBUG==1 && HAVE_PIRQ_TABLE==1) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 6 | void check_pirq_routing_table(void) |
| 7 | { |
Eric Biederman | 8cd55d7 | 2003-04-24 06:56:37 +0000 | [diff] [blame] | 8 | const uint8_t *addr; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 9 | const struct irq_routing_table *rt; |
| 10 | int i; |
Eric Biederman | 8cd55d7 | 2003-04-24 06:56:37 +0000 | [diff] [blame] | 11 | uint8_t sum; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 12 | |
| 13 | printk_info("Checking IRQ routing tables...\n"); |
| 14 | |
Eric Biederman | 8cd55d7 | 2003-04-24 06:56:37 +0000 | [diff] [blame] | 15 | #if defined(IRQ_SLOT_COUNT) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 16 | if (sizeof(intel_irq_routing_table) != intel_irq_routing_table.size) { |
Stefan Reinauer | 40cba39 | 2003-10-28 17:02:10 +0000 | [diff] [blame] | 17 | printk_warning("Inconsistent IRQ routing table size (0x%x/0x%x)\n", |
Li-Ta Lo | 8e79fc3 | 2004-04-15 17:33:21 +0000 | [diff] [blame^] | 18 | sizeof(intel_irq_routing_table), |
| 19 | intel_irq_routing_table.size |
| 20 | ); |
Stefan Reinauer | 40cba39 | 2003-10-28 17:02:10 +0000 | [diff] [blame] | 21 | intel_irq_routing_table.size=sizeof(intel_irq_routing_table); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 22 | } |
| 23 | #endif |
| 24 | |
| 25 | rt = &intel_irq_routing_table; |
Eric Biederman | 8cd55d7 | 2003-04-24 06:56:37 +0000 | [diff] [blame] | 26 | addr = (uint8_t *)rt; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 27 | |
| 28 | sum = 0; |
| 29 | for (i = 0; i < rt->size; i++) |
| 30 | sum += addr[i]; |
| 31 | |
| 32 | printk_debug("%s:%6d:%s() - irq_routing_table located at: 0x%p\n", |
Li-Ta Lo | 8e79fc3 | 2004-04-15 17:33:21 +0000 | [diff] [blame^] | 33 | __FILE__, __LINE__, __FUNCTION__, addr); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 34 | |
Eric Biederman | eb00fa5 | 2003-04-25 02:02:25 +0000 | [diff] [blame] | 35 | |
| 36 | sum = rt->checksum - sum; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 37 | |
| 38 | if (sum != rt->checksum) { |
| 39 | printk_warning("%s:%6d:%s() - " |
Li-Ta Lo | 8e79fc3 | 2004-04-15 17:33:21 +0000 | [diff] [blame^] | 40 | "checksum is: 0x%02x but should be: 0x%02x\n", |
| 41 | __FILE__, __LINE__, __FUNCTION__, rt->checksum, sum); |
Stefan Reinauer | 40cba39 | 2003-10-28 17:02:10 +0000 | [diff] [blame] | 42 | rt->checksum = sum; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | if (rt->signature != PIRQ_SIGNATURE || rt->version != PIRQ_VERSION || |
| 46 | rt->size % 16 || rt->size < sizeof(struct irq_routing_table)) { |
| 47 | printk_warning("%s:%6d:%s() - " |
Li-Ta Lo | 8e79fc3 | 2004-04-15 17:33:21 +0000 | [diff] [blame^] | 48 | "Interrupt Routing Table not valid\n", |
| 49 | __FILE__, __LINE__, __FUNCTION__); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 50 | return; |
| 51 | } |
| 52 | |
| 53 | sum = 0; |
| 54 | for (i=0; i<rt->size; i++) |
| 55 | sum += addr[i]; |
| 56 | |
| 57 | if (sum) { |
| 58 | printk_warning("%s:%6d:%s() - " |
Li-Ta Lo | 8e79fc3 | 2004-04-15 17:33:21 +0000 | [diff] [blame^] | 59 | "checksum error in irq routing table\n", |
| 60 | __FILE__, __LINE__, __FUNCTION__); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | printk_info("done.\n"); |
| 64 | } |
| 65 | |
| 66 | int verify_copy_pirq_routing_table(unsigned long addr) |
| 67 | { |
| 68 | int i; |
Eric Biederman | 8cd55d7 | 2003-04-24 06:56:37 +0000 | [diff] [blame] | 69 | uint8_t *rt_orig, *rt_curr; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 70 | |
Eric Biederman | 8cd55d7 | 2003-04-24 06:56:37 +0000 | [diff] [blame] | 71 | rt_curr = (uint8_t*)addr; |
| 72 | rt_orig = (uint8_t*)&intel_irq_routing_table; |
Stefan Reinauer | abf9fea | 2004-01-26 10:54:44 +0000 | [diff] [blame] | 73 | printk_info("Verifing copy of IRQ routing tables at 0x%x...", addr); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 74 | for (i = 0; i < intel_irq_routing_table.size; i++) { |
| 75 | if (*(rt_curr + i) != *(rt_orig + i)) { |
| 76 | printk_info("failed\n"); |
| 77 | return -1; |
| 78 | } |
| 79 | } |
Stefan Reinauer | abf9fea | 2004-01-26 10:54:44 +0000 | [diff] [blame] | 80 | printk_info("done\n"); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 81 | return 0; |
| 82 | } |
| 83 | #else |
| 84 | #define verify_copy_pirq_routing_table(addr) |
| 85 | #endif |
| 86 | |
Greg Watson | 9f46132 | 2004-03-23 17:41:15 +0000 | [diff] [blame] | 87 | #if HAVE_PIRQ_TABLE==1 |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 88 | unsigned long copy_pirq_routing_table(unsigned long addr) |
| 89 | { |
| 90 | /* Align the table to be 16 byte aligned. */ |
| 91 | addr += 15; |
| 92 | addr &= ~15; |
| 93 | |
| 94 | /* This table must be betweeen 0xf0000 & 0x100000 */ |
| 95 | printk_info("Copying IRQ routing tables to 0x%x...", addr); |
| 96 | memcpy((void *)addr, &intel_irq_routing_table, intel_irq_routing_table.size); |
| 97 | printk_info("done.\n"); |
| 98 | verify_copy_pirq_routing_table(addr); |
| 99 | return addr + intel_irq_routing_table.size; |
| 100 | } |
Greg Watson | 9f46132 | 2004-03-23 17:41:15 +0000 | [diff] [blame] | 101 | #endif |