| 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 <amdblocks/amd_pci_util.h> |
| 8 |
#include <pc80/i8259.h> |
| 9 |
#include <soc/amd_pci_int_defs.h> |
| 10 |
#include <string.h> |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
static uint8_t fch_pic_routing[FCH_IRQ_ROUTING_ENTRIES]; |
| 21 |
static uint8_t fch_apic_routing[FCH_IRQ_ROUTING_ENTRIES]; |
| 22 |
|
| 23 |
const struct pirq_struct *pirq_data_ptr; |
| 24 |
u32 pirq_data_size; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
u8 read_pci_int_idx(u8 index, int mode) |
| 31 |
{ |
| 32 |
outb((mode << 7) | index, PCI_INTR_INDEX); |
| 33 |
return inb(PCI_INTR_DATA); |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
void write_pci_int_idx(u8 index, int mode, u8 data) |
| 41 |
{ |
| 42 |
outb((mode << 7) | index, PCI_INTR_INDEX); |
| 43 |
outb(data, PCI_INTR_DATA); |
| 44 |
} |
| 45 |
|
| 46 |
static void init_fch_irq_map_tables(void) |
| 47 |
{ |
| 48 |
const struct fch_irq_routing *mb_irq_map; |
| 49 |
size_t mb_fch_irq_mapping_table_size; |
| 50 |
size_t i; |
| 51 |
|
| 52 |
mb_irq_map = mb_get_fch_irq_mapping(&mb_fch_irq_mapping_table_size); |
| 53 |
|
| 54 |
memset(fch_pic_routing, PIRQ_NC, sizeof(fch_pic_routing)); |
| 55 |
memset(fch_apic_routing, PIRQ_NC, sizeof(fch_apic_routing)); |
| 56 |
|
| 57 |
for (i = 0; i < mb_fch_irq_mapping_table_size; i++) { |
| 58 |
if (mb_irq_map[i].intr_index >= FCH_IRQ_ROUTING_ENTRIES) { |
| 59 |
printk(BIOS_WARNING, |
| 60 |
"Invalid IRQ index %u in FCH IRQ routing table entry %zu\n", |
| 61 |
mb_irq_map[i].intr_index, i); |
| 62 |
continue; |
| 63 |
} |
| 64 |
fch_pic_routing[mb_irq_map[i].intr_index] = mb_irq_map[i].pic_irq_num; |
| 65 |
fch_apic_routing[mb_irq_map[i].intr_index] = mb_irq_map[i].apic_irq_num; |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
void write_pci_int_table(void) |
| 75 |
{ |
| 76 |
uint8_t byte; |
| 77 |
size_t i, limit; |
| 78 |
const struct irq_idx_name *idx_name; |
| 79 |
|
| 80 |
init_fch_irq_map_tables(); |
| 81 |
|
| 82 |
idx_name = sb_get_apic_reg_association(&limit); |
| 83 |
if (idx_name == NULL) { |
| 84 |
printk(BIOS_ERR, "Warning: Can't write PCI_INTR 0xC00/0xC01" |
| 85 |
" registers because\n" |
| 86 |
" 'irq_association'\ntables is NULL\n"); |
| 87 |
return; |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
printk(BIOS_DEBUG, "PCI_INTR tables: Writing registers C00/C01 for" |
| 92 |
" PCI IRQ routing:\n" |
| 93 |
"PCI_INTR_INDEX\tname\t\t PIC mode" |
| 94 |
"\tAPIC mode\n"); |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
for (i = 0 ; i < limit; i++) { |
| 102 |
byte = idx_name[i].index; |
| 103 |
write_pci_int_idx(byte, 0, fch_pic_routing[byte]); |
| 104 |
printk(BIOS_DEBUG, "0x%02X\t\t%-20s 0x%02X\t", |
| 105 |
byte, idx_name[i].name, |
| 106 |
read_pci_int_idx(byte, 0)); |
| 107 |
write_pci_int_idx(byte, 1, fch_apic_routing[byte]); |
| 108 |
printk(BIOS_DEBUG, "0x%02X\n", read_pci_int_idx(byte, 1)); |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
void write_pci_cfg_irqs(void) |
| 118 |
{ |
| 119 |
struct device *dev = NULL; |
| 120 |
struct device *target_dev = NULL; |
| 121 |
|
| 122 |
u16 int_pin = 0; |
| 123 |
u16 target_pin = 0; |
| 124 |
u16 int_line = 0; |
| 125 |
u16 pci_intr_idx = 0; |
| 126 |
u16 devfn = 0; |
| 127 |
u32 i = 0; |
| 128 |
size_t limit; |
| 129 |
const struct irq_idx_name *idx_name; |
| 130 |
|
| 131 |
idx_name = sb_get_apic_reg_association(&limit); |
| 132 |
if (pirq_data_ptr == NULL) { |
| 133 |
printk(BIOS_WARNING, "Can't write PCI IRQ assignments" |
| 134 |
" because 'mainboard_pirq_data' structure does" |
| 135 |
" not exist\n"); |
| 136 |
return; |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
printk(BIOS_DEBUG, "PCI_CFG IRQ: Write PCI config space IRQ" |
| 141 |
" assignments\n"); |
| 142 |
|
| 143 |
for (dev = all_devices ; dev ; dev = dev->next) { |
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
target_dev = NULL; |
| 149 |
target_pin = get_pci_irq_pins(dev, &target_dev); |
| 150 |
if (target_dev == NULL) |
| 151 |
continue; |
| 152 |
|
| 153 |
if (target_pin < 1) |
| 154 |
continue; |
| 155 |
|
| 156 |
|
| 157 |
int_pin = pci_read_config8(dev, PCI_INTERRUPT_PIN); |
| 158 |
if (int_pin < 1 || int_pin > 4) |
| 159 |
continue; |
| 160 |
|
| 161 |
devfn = target_dev->path.pci.devfn; |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
pci_intr_idx = 0xbad; |
| 168 |
for (i = 0 ; i < pirq_data_size ; i++) { |
| 169 |
if (pirq_data_ptr[i].devfn != devfn) |
| 170 |
continue; |
| 171 |
|
| 172 |
|
| 173 |
pci_intr_idx = pirq_data_ptr[i].PIN[target_pin - 1]; |
| 174 |
printk(BIOS_SPEW, "\tFound this device in pirq_data" |
| 175 |
" table entry %d\n", i); |
| 176 |
break; |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
if (pci_intr_idx == 0xbad) { |
| 184 |
|
| 185 |
printk(BIOS_SPEW, "PCI Devfn (0x%x) not found in" |
| 186 |
" pirq_data table\n", devfn); |
| 187 |
continue; |
| 188 |
} else if (pci_intr_idx == 0x1f) { |
| 189 |
|
| 190 |
printk(BIOS_SPEW, "Got index 0x1F (Not Connected)," |
| 191 |
" perhaps this device was" |
| 192 |
" defined wrong?\n"); |
| 193 |
continue; |
| 194 |
} |
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
for (i = 0; i < limit; i++) { |
| 200 |
if (idx_name[i].index == pci_intr_idx) |
| 201 |
break; |
| 202 |
} |
| 203 |
if (i == limit) { |
| 204 |
printk(BIOS_SPEW, "Got register index 0x%02x" |
| 205 |
" undefined in table irq_idx_name,\n" |
| 206 |
" perhaps this device was" |
| 207 |
" defined wrong?\n", pci_intr_idx); |
| 208 |
continue; |
| 209 |
} |
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
int_line = read_pci_int_idx(pci_intr_idx, 0); |
| 215 |
if (int_line == PIRQ_NC) { |
| 216 |
printk(BIOS_SPEW, "Got IRQ 0x1F (disabled), perhaps" |
| 217 |
" this device was defined wrong?\n"); |
| 218 |
continue; |
| 219 |
} |
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
pci_write_config8(dev, PCI_INTERRUPT_LINE, int_line); |
| 227 |
|
| 228 |
|
| 229 |
i8259_configure_irq_trigger(int_line, IRQ_LEVEL_TRIGGERED); |
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
printk(BIOS_SPEW, "\tOrig INT_PIN\t: %d (%s)\n", |
| 235 |
int_pin, pin_to_str(int_pin)); |
| 236 |
printk(BIOS_SPEW, "\tPCI_INTR idx\t: 0x%02x (%s)\n" |
| 237 |
"\tINT_LINE\t: 0x%X (IRQ %d)\n", |
| 238 |
pci_intr_idx, idx_name[i].name, |
| 239 |
int_line, int_line); |
| 240 |
} |
| 241 |
printk(BIOS_DEBUG, "PCI_CFG IRQ: Finished writing PCI config space" |
| 242 |
" IRQ assignments\n"); |
| 243 |
} |