| 1 |
|
| 2 |
|
| 3 |
#include <console/console.h> |
| 4 |
#include <device/pci.h> |
| 5 |
#include <arch/io.h> |
| 6 |
#include <device/pci_ops.h> |
| 7 |
#include "amd_pci_util.h" |
| 8 |
#include <pc80/i8259.h> |
| 9 |
#include "amd_pci_int_defs.h" |
| 10 |
#include "amd_pci_int_types.h" |
| 11 |
|
| 12 |
const struct pirq_struct * pirq_data_ptr = NULL; |
| 13 |
u32 pirq_data_size = 0; |
| 14 |
const u8 *intr_data_ptr = NULL; |
| 15 |
const u8 *picr_data_ptr = NULL; |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
u8 read_pci_int_idx(u8 index, int mode) |
| 22 |
{ |
| 23 |
outb((mode << 7) | index, PCI_INTR_INDEX); |
| 24 |
return inb(PCI_INTR_DATA); |
| 25 |
} |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
void write_pci_int_idx(u8 index, int mode, u8 data) |
| 32 |
{ |
| 33 |
outb((mode << 7) | index, PCI_INTR_INDEX); |
| 34 |
outb(data, PCI_INTR_DATA); |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
void write_pci_int_table(void) |
| 43 |
{ |
| 44 |
u8 byte; |
| 45 |
|
| 46 |
if (picr_data_ptr == NULL || intr_data_ptr == NULL) { |
| 47 |
printk(BIOS_ERR, "Warning: Can't write PCI_INTR 0xC00/0xC01 registers because\n" |
| 48 |
"'mainboard_picr_data' or 'mainboard_intr_data' tables are NULL\n"); |
| 49 |
return; |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
printk(BIOS_DEBUG, "PCI_INTR tables: Writing registers C00/C01 for PIC mode PCI IRQ routing:\n" |
| 54 |
"\tPCI_INTR_INDEX\t\tPCI_INTR_DATA\n"); |
| 55 |
for (byte = 0; byte < FCH_INT_TABLE_SIZE; byte++) { |
| 56 |
if (intr_types[byte]) { |
| 57 |
write_pci_int_idx(byte, 0, (u8)picr_data_ptr[byte]); |
| 58 |
printk(BIOS_DEBUG, "\t0x%02X %s\t: 0x%02X\n", |
| 59 |
byte, intr_types[byte], read_pci_int_idx(byte, 0)); |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
printk(BIOS_DEBUG, "PCI_INTR tables: Writing registers C00/C01 for APIC mode PCI IRQ routing:\n" |
| 65 |
"\tPCI_INTR_INDEX\t\tPCI_INTR_DATA\n"); |
| 66 |
for (byte = 0; byte < FCH_INT_TABLE_SIZE; byte++) { |
| 67 |
if (intr_types[byte]) { |
| 68 |
write_pci_int_idx(byte, 1, (u8)intr_data_ptr[byte]); |
| 69 |
printk(BIOS_DEBUG, "\t0x%02X %s\t: 0x%02X\n", |
| 70 |
byte, intr_types[byte], read_pci_int_idx(byte, 1)); |
| 71 |
} |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
void write_pci_cfg_irqs(void) |
| 81 |
{ |
| 82 |
struct device *dev = NULL; |
| 83 |
struct device *target_dev = NULL; |
| 84 |
u16 int_pin = 0; |
| 85 |
u16 target_pin = 0; |
| 86 |
u16 int_line = 0; |
| 87 |
u16 pci_intr_idx = 0; |
| 88 |
u16 devfn = 0; |
| 89 |
u32 i = 0; |
| 90 |
|
| 91 |
if (pirq_data_ptr == NULL) { |
| 92 |
printk(BIOS_WARNING, "Can't write PCI IRQ assignments because" |
| 93 |
" 'mainboard_pirq_data' structure does not exist\n"); |
| 94 |
return; |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
printk(BIOS_DEBUG, "PCI_CFG IRQ: Write PCI config space IRQ assignments\n"); |
| 99 |
|
| 100 |
for (dev = all_devices; dev; dev = dev->next) { |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
target_dev = NULL; |
| 106 |
target_pin = get_pci_irq_pins(dev, &target_dev); |
| 107 |
if (target_dev == NULL) |
| 108 |
continue; |
| 109 |
|
| 110 |
if (target_pin < 1) |
| 111 |
continue; |
| 112 |
|
| 113 |
|
| 114 |
int_pin = pci_read_config8(dev, PCI_INTERRUPT_PIN); |
| 115 |
if (int_pin < 1 || int_pin > 4) |
| 116 |
continue; |
| 117 |
|
| 118 |
devfn = target_dev->path.pci.devfn; |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
pci_intr_idx = 0xBAD; |
| 125 |
for (i = 0; i < pirq_data_size; i++) { |
| 126 |
if (pirq_data_ptr[i].devfn != devfn) |
| 127 |
continue; |
| 128 |
|
| 129 |
|
| 130 |
pci_intr_idx = pirq_data_ptr[i].PIN[target_pin - 1]; |
| 131 |
printk(BIOS_SPEW, "\tFound this device in pirq_data table entry %d\n", i); |
| 132 |
break; |
| 133 |
} |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
if (pci_intr_idx == 0xBAD) { |
| 140 |
printk(BIOS_SPEW, "PCI Devfn (0x%x) not found in pirq_data table\n", devfn); |
| 141 |
continue; |
| 142 |
} else if (pci_intr_idx == 0x1F) { |
| 143 |
printk(BIOS_SPEW, "Got index 0x1F (Not Connected), perhaps this device was defined wrong?\n"); |
| 144 |
continue; |
| 145 |
} else if (pci_intr_idx >= FCH_INT_TABLE_SIZE) { |
| 146 |
printk(BIOS_ERR, "%s: got 0xC00/0xC01 table index 0x%x, max is 0x%x\n", |
| 147 |
__func__, pci_intr_idx, FCH_INT_TABLE_SIZE); |
| 148 |
continue; |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
int_line = read_pci_int_idx(pci_intr_idx, 0); |
| 153 |
if (int_line == PIRQ_NC) { |
| 154 |
printk(BIOS_SPEW, "Got IRQ 0x1F (disabled), perhaps this device was defined wrong?\n"); |
| 155 |
continue; |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
pci_write_config8(dev, PCI_INTERRUPT_LINE, int_line); |
| 164 |
|
| 165 |
|
| 166 |
i8259_configure_irq_trigger(int_line, IRQ_LEVEL_TRIGGERED); |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
printk(BIOS_SPEW, "\tOrig INT_PIN\t: %d (%s)\n", |
| 172 |
int_pin, pin_to_str(int_pin)); |
| 173 |
|
| 174 |
printk(BIOS_SPEW, "\tPCI_INTR idx\t: 0x%02x (%s)\n" |
| 175 |
"\tINT_LINE\t: 0x%X (IRQ %d)\n", |
| 176 |
pci_intr_idx, intr_types[pci_intr_idx], int_line, int_line); |
| 177 |
} |
| 178 |
printk(BIOS_DEBUG, "PCI_CFG IRQ: Finished writing PCI config space IRQ assignments\n"); |
| 179 |
} |