Kevin O'Connor | 0525d29 | 2008-07-04 06:18:30 -0400 | [diff] [blame] | 1 | // Initialize PCI devices (on emulators) |
| 2 | // |
| 3 | // Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net> |
| 4 | // Copyright (C) 2006 Fabrice Bellard |
| 5 | // |
Kevin O'Connor | b1b7c2a | 2009-01-15 20:52:58 -0500 | [diff] [blame] | 6 | // This file may be distributed under the terms of the GNU LGPLv3 license. |
Kevin O'Connor | 0525d29 | 2008-07-04 06:18:30 -0400 | [diff] [blame] | 7 | |
| 8 | #include "util.h" // dprintf |
Kevin O'Connor | be19cdc | 2008-11-09 15:33:47 -0500 | [diff] [blame] | 9 | #include "pci.h" // pci_config_readl |
Kevin O'Connor | 2ed2f58 | 2008-11-08 15:53:36 -0500 | [diff] [blame] | 10 | #include "pci_ids.h" // PCI_VENDOR_ID_INTEL |
| 11 | #include "pci_regs.h" // PCI_COMMAND |
Kevin O'Connor | 4bc4997 | 2012-05-13 22:58:08 -0400 | [diff] [blame] | 12 | #include "ioport.h" // PORT_ATA1_CMD_BASE |
| 13 | #include "config.h" // CONFIG_* |
Isaku Yamahata | 72a590e | 2012-11-28 10:17:33 +0100 | [diff] [blame] | 14 | #include "memmap.h" // add_e820 |
Kevin O'Connor | f85e4bc | 2013-02-19 01:33:45 -0500 | [diff] [blame] | 15 | #include "paravirt.h" // RamSize |
Kevin O'Connor | aab4215 | 2013-06-08 21:51:46 -0400 | [diff] [blame^] | 16 | #include "dev-q35.h" // Q35_HOST_BRIDGE_PCIEXBAR_ADDR |
| 17 | #include "list.h" // struct hlist_node |
Isaku Yamahata | 72a590e | 2012-11-28 10:17:33 +0100 | [diff] [blame] | 18 | |
| 19 | /* PM Timer ticks per second (HZ) */ |
| 20 | #define PM_TIMER_FREQUENCY 3579545 |
Kevin O'Connor | 0525d29 | 2008-07-04 06:18:30 -0400 | [diff] [blame] | 21 | |
Alexey Korolev | 5fa24b5 | 2012-04-18 17:31:58 +1200 | [diff] [blame] | 22 | #define PCI_DEVICE_MEM_MIN 0x1000 |
Gerd Hoffmann | 82b39b2 | 2011-07-11 09:20:28 +0200 | [diff] [blame] | 23 | #define PCI_BRIDGE_IO_MIN 0x1000 |
| 24 | #define PCI_BRIDGE_MEM_MIN 0x100000 |
Isaku Yamahata | af0963d | 2010-06-22 17:57:53 +0900 | [diff] [blame] | 25 | |
Gerd Hoffmann | 82b39b2 | 2011-07-11 09:20:28 +0200 | [diff] [blame] | 26 | enum pci_region_type { |
| 27 | PCI_REGION_TYPE_IO, |
| 28 | PCI_REGION_TYPE_MEM, |
| 29 | PCI_REGION_TYPE_PREFMEM, |
| 30 | PCI_REGION_TYPE_COUNT, |
| 31 | }; |
| 32 | |
| 33 | static const char *region_type_name[] = { |
| 34 | [ PCI_REGION_TYPE_IO ] = "io", |
| 35 | [ PCI_REGION_TYPE_MEM ] = "mem", |
| 36 | [ PCI_REGION_TYPE_PREFMEM ] = "prefmem", |
| 37 | }; |
| 38 | |
Gerd Hoffmann | e55c4e8 | 2012-06-07 10:34:32 +0200 | [diff] [blame] | 39 | u64 pcimem_start = BUILD_PCIMEM_START; |
| 40 | u64 pcimem_end = BUILD_PCIMEM_END; |
| 41 | u64 pcimem64_start = BUILD_PCIMEM64_START; |
| 42 | u64 pcimem64_end = BUILD_PCIMEM64_END; |
| 43 | |
Alexey Korolev | fa51bcd | 2012-04-18 17:21:19 +1200 | [diff] [blame] | 44 | struct pci_region_entry { |
| 45 | struct pci_device *dev; |
| 46 | int bar; |
Alexey Korolev | 030288f | 2012-04-19 17:44:55 +1200 | [diff] [blame] | 47 | u64 size; |
| 48 | u64 align; |
Alexey Korolev | fa51bcd | 2012-04-18 17:21:19 +1200 | [diff] [blame] | 49 | int is64; |
| 50 | enum pci_region_type type; |
Kevin O'Connor | aab4215 | 2013-06-08 21:51:46 -0400 | [diff] [blame^] | 51 | struct hlist_node node; |
Alexey Korolev | fa51bcd | 2012-04-18 17:21:19 +1200 | [diff] [blame] | 52 | }; |
| 53 | |
Alexey Korolev | 35a770f | 2012-04-19 17:47:19 +1200 | [diff] [blame] | 54 | struct pci_region { |
Alexey Korolev | 35a770f | 2012-04-19 17:47:19 +1200 | [diff] [blame] | 55 | /* pci region assignments */ |
| 56 | u64 base; |
Kevin O'Connor | aab4215 | 2013-06-08 21:51:46 -0400 | [diff] [blame^] | 57 | struct hlist_head list; |
Alexey Korolev | 35a770f | 2012-04-19 17:47:19 +1200 | [diff] [blame] | 58 | }; |
| 59 | |
Kevin O'Connor | b725dcb | 2011-10-15 11:53:38 -0400 | [diff] [blame] | 60 | struct pci_bus { |
Alexey Korolev | 35a770f | 2012-04-19 17:47:19 +1200 | [diff] [blame] | 61 | struct pci_region r[PCI_REGION_TYPE_COUNT]; |
Kevin O'Connor | 2c4c211 | 2011-10-15 11:42:48 -0400 | [diff] [blame] | 62 | struct pci_device *bus_dev; |
Kevin O'Connor | b725dcb | 2011-10-15 11:53:38 -0400 | [diff] [blame] | 63 | }; |
Gerd Hoffmann | 82b39b2 | 2011-07-11 09:20:28 +0200 | [diff] [blame] | 64 | |
Kevin O'Connor | cbbdcf2 | 2011-10-01 13:13:29 -0400 | [diff] [blame] | 65 | static u32 pci_bar(struct pci_device *pci, int region_num) |
Isaku Yamahata | a65821d | 2010-06-22 17:57:50 +0900 | [diff] [blame] | 66 | { |
| 67 | if (region_num != PCI_ROM_SLOT) { |
| 68 | return PCI_BASE_ADDRESS_0 + region_num * 4; |
| 69 | } |
Isaku Yamahata | 5d0de15 | 2010-06-22 17:57:51 +0900 | [diff] [blame] | 70 | |
| 71 | #define PCI_HEADER_TYPE_MULTI_FUNCTION 0x80 |
Kevin O'Connor | cbbdcf2 | 2011-10-01 13:13:29 -0400 | [diff] [blame] | 72 | u8 type = pci->header_type & ~PCI_HEADER_TYPE_MULTI_FUNCTION; |
Isaku Yamahata | 5d0de15 | 2010-06-22 17:57:51 +0900 | [diff] [blame] | 73 | return type == PCI_HEADER_TYPE_BRIDGE ? PCI_ROM_ADDRESS1 : PCI_ROM_ADDRESS; |
Isaku Yamahata | a65821d | 2010-06-22 17:57:50 +0900 | [diff] [blame] | 74 | } |
| 75 | |
Kevin O'Connor | cbbdcf2 | 2011-10-01 13:13:29 -0400 | [diff] [blame] | 76 | static void |
Alexey Korolev | 030288f | 2012-04-19 17:44:55 +1200 | [diff] [blame] | 77 | pci_set_io_region_addr(struct pci_device *pci, int bar, u64 addr, int is64) |
Kevin O'Connor | 0525d29 | 2008-07-04 06:18:30 -0400 | [diff] [blame] | 78 | { |
Alexey Korolev | 030288f | 2012-04-19 17:44:55 +1200 | [diff] [blame] | 79 | u32 ofs = pci_bar(pci, bar); |
| 80 | pci_config_writel(pci->bdf, ofs, addr); |
| 81 | if (is64) |
| 82 | pci_config_writel(pci->bdf, ofs + 4, addr >> 32); |
Isaku Yamahata | b9e4721 | 2010-06-22 17:57:47 +0900 | [diff] [blame] | 83 | } |
| 84 | |
Kevin O'Connor | 5bab7e6 | 2011-10-01 11:33:31 -0400 | [diff] [blame] | 85 | |
| 86 | /**************************************************************** |
| 87 | * Misc. device init |
| 88 | ****************************************************************/ |
| 89 | |
| 90 | /* host irqs corresponding to PCI irqs A-D */ |
| 91 | const u8 pci_irqs[4] = { |
| 92 | 10, 10, 11, 11 |
| 93 | }; |
| 94 | |
Alex Williamson | dbb7a66 | 2013-02-21 09:12:23 -0700 | [diff] [blame] | 95 | static int dummy_pci_slot_get_irq(struct pci_device *pci, int pin) |
| 96 | { |
| 97 | dprintf(1, "pci_slot_get_irq called with unknown routing\n"); |
| 98 | |
| 99 | return 0xff; /* PCI defined "unknown" or "no connection" for x86 */ |
| 100 | } |
| 101 | |
| 102 | static int (*pci_slot_get_irq)(struct pci_device *pci, int pin) = |
| 103 | dummy_pci_slot_get_irq; |
Alex Williamson | b949040 | 2013-02-15 14:11:41 -0700 | [diff] [blame] | 104 | |
Kevin O'Connor | 0ce2138 | 2011-10-01 14:52:35 -0400 | [diff] [blame] | 105 | // Return the global irq number corresponding to a host bus device irq pin. |
Alex Williamson | b949040 | 2013-02-15 14:11:41 -0700 | [diff] [blame] | 106 | static int piix_pci_slot_get_irq(struct pci_device *pci, int pin) |
Kevin O'Connor | 0525d29 | 2008-07-04 06:18:30 -0400 | [diff] [blame] | 107 | { |
Gerd Hoffmann | 0c8f58d | 2012-05-04 17:33:36 +0200 | [diff] [blame] | 108 | int slot_addend = 0; |
| 109 | |
| 110 | while (pci->parent != NULL) { |
| 111 | slot_addend += pci_bdf_to_dev(pci->bdf); |
| 112 | pci = pci->parent; |
| 113 | } |
| 114 | slot_addend += pci_bdf_to_dev(pci->bdf) - 1; |
Kevin O'Connor | 0ce2138 | 2011-10-01 14:52:35 -0400 | [diff] [blame] | 115 | return pci_irqs[(pin - 1 + slot_addend) & 3]; |
Kevin O'Connor | 0525d29 | 2008-07-04 06:18:30 -0400 | [diff] [blame] | 116 | } |
| 117 | |
Alex Williamson | b949040 | 2013-02-15 14:11:41 -0700 | [diff] [blame] | 118 | static int mch_pci_slot_get_irq(struct pci_device *pci, int pin) |
| 119 | { |
| 120 | int irq, slot, pin_addend = 0; |
| 121 | |
| 122 | while (pci->parent != NULL) { |
| 123 | pin_addend += pci_bdf_to_dev(pci->bdf); |
| 124 | pci = pci->parent; |
| 125 | } |
| 126 | slot = pci_bdf_to_dev(pci->bdf); |
| 127 | |
| 128 | switch (slot) { |
| 129 | /* Slots 0-24 rotate slot:pin mapping similar to piix above, but |
| 130 | with a different starting index - see q35-acpi-dsdt.dsl */ |
| 131 | case 0 ... 24: |
| 132 | irq = pci_irqs[(pin - 1 + pin_addend + slot) & 3]; |
| 133 | break; |
| 134 | /* Slots 25-31 all use LNKA mapping (or LNKE, but A:D = E:H) */ |
| 135 | case 25 ... 31: |
| 136 | irq = pci_irqs[(pin - 1 + pin_addend) & 3]; |
| 137 | break; |
| 138 | } |
| 139 | |
| 140 | return irq; |
| 141 | } |
| 142 | |
Kevin O'Connor | 6e4583c | 2011-06-19 10:09:26 -0400 | [diff] [blame] | 143 | /* PIIX3/PIIX4 PCI to ISA bridge */ |
Kevin O'Connor | d83c87b | 2013-01-21 01:14:12 -0500 | [diff] [blame] | 144 | static void piix_isa_bridge_setup(struct pci_device *pci, void *arg) |
Kevin O'Connor | 6e4583c | 2011-06-19 10:09:26 -0400 | [diff] [blame] | 145 | { |
| 146 | int i, irq; |
| 147 | u8 elcr[2]; |
| 148 | |
| 149 | elcr[0] = 0x00; |
| 150 | elcr[1] = 0x00; |
| 151 | for (i = 0; i < 4; i++) { |
| 152 | irq = pci_irqs[i]; |
| 153 | /* set to trigger level */ |
| 154 | elcr[irq >> 3] |= (1 << (irq & 7)); |
| 155 | /* activate irq remapping in PIIX */ |
Kevin O'Connor | 278b19f | 2011-06-21 22:41:15 -0400 | [diff] [blame] | 156 | pci_config_writeb(pci->bdf, 0x60 + i, irq); |
Kevin O'Connor | 6e4583c | 2011-06-19 10:09:26 -0400 | [diff] [blame] | 157 | } |
| 158 | outb(elcr[0], 0x4d0); |
| 159 | outb(elcr[1], 0x4d1); |
| 160 | dprintf(1, "PIIX3/PIIX4 init: elcr=%02x %02x\n", elcr[0], elcr[1]); |
| 161 | } |
| 162 | |
Isaku Yamahata | 72a590e | 2012-11-28 10:17:33 +0100 | [diff] [blame] | 163 | /* ICH9 LPC PCI to ISA bridge */ |
| 164 | /* PCI_VENDOR_ID_INTEL && PCI_DEVICE_ID_INTEL_ICH9_LPC */ |
Kevin O'Connor | d83c87b | 2013-01-21 01:14:12 -0500 | [diff] [blame] | 165 | void mch_isa_bridge_setup(struct pci_device *dev, void *arg) |
Isaku Yamahata | 72a590e | 2012-11-28 10:17:33 +0100 | [diff] [blame] | 166 | { |
| 167 | u16 bdf = dev->bdf; |
| 168 | int i, irq; |
| 169 | u8 elcr[2]; |
| 170 | |
| 171 | elcr[0] = 0x00; |
| 172 | elcr[1] = 0x00; |
| 173 | |
| 174 | for (i = 0; i < 4; i++) { |
| 175 | irq = pci_irqs[i]; |
| 176 | /* set to trigger level */ |
| 177 | elcr[irq >> 3] |= (1 << (irq & 7)); |
| 178 | |
| 179 | /* activate irq remapping in LPC */ |
| 180 | |
| 181 | /* PIRQ[A-D] routing */ |
Alex Williamson | 555a213 | 2013-02-15 14:11:35 -0700 | [diff] [blame] | 182 | pci_config_writeb(bdf, ICH9_LPC_PIRQA_ROUT + i, irq); |
Isaku Yamahata | 72a590e | 2012-11-28 10:17:33 +0100 | [diff] [blame] | 183 | /* PIRQ[E-H] routing */ |
Alex Williamson | 555a213 | 2013-02-15 14:11:35 -0700 | [diff] [blame] | 184 | pci_config_writeb(bdf, ICH9_LPC_PIRQE_ROUT + i, irq); |
Isaku Yamahata | 72a590e | 2012-11-28 10:17:33 +0100 | [diff] [blame] | 185 | } |
| 186 | outb(elcr[0], ICH9_LPC_PORT_ELCR1); |
| 187 | outb(elcr[1], ICH9_LPC_PORT_ELCR2); |
| 188 | dprintf(1, "Q35 LPC init: elcr=%02x %02x\n", elcr[0], elcr[1]); |
| 189 | |
| 190 | /* pm io base */ |
| 191 | pci_config_writel(bdf, ICH9_LPC_PMBASE, |
| 192 | PORT_ACPI_PM_BASE | ICH9_LPC_PMBASE_RTE); |
| 193 | |
| 194 | /* acpi enable, SCI: IRQ9 000b = irq9*/ |
| 195 | pci_config_writeb(bdf, ICH9_LPC_ACPI_CTRL, ICH9_LPC_ACPI_CTRL_ACPI_EN); |
| 196 | |
Kevin O'Connor | d83c87b | 2013-01-21 01:14:12 -0500 | [diff] [blame] | 197 | pmtimer_setup(PORT_ACPI_PM_BASE + 0x08, PM_TIMER_FREQUENCY / 1000); |
Isaku Yamahata | 72a590e | 2012-11-28 10:17:33 +0100 | [diff] [blame] | 198 | } |
| 199 | |
Kevin O'Connor | d83c87b | 2013-01-21 01:14:12 -0500 | [diff] [blame] | 200 | static void storage_ide_setup(struct pci_device *pci, void *arg) |
Kevin O'Connor | 0d6b8d5 | 2010-07-10 13:12:37 -0400 | [diff] [blame] | 201 | { |
| 202 | /* IDE: we map it as in ISA mode */ |
Alexey Korolev | 030288f | 2012-04-19 17:44:55 +1200 | [diff] [blame] | 203 | pci_set_io_region_addr(pci, 0, PORT_ATA1_CMD_BASE, 0); |
| 204 | pci_set_io_region_addr(pci, 1, PORT_ATA1_CTRL_BASE, 0); |
| 205 | pci_set_io_region_addr(pci, 2, PORT_ATA2_CMD_BASE, 0); |
| 206 | pci_set_io_region_addr(pci, 3, PORT_ATA2_CTRL_BASE, 0); |
Kevin O'Connor | 0d6b8d5 | 2010-07-10 13:12:37 -0400 | [diff] [blame] | 207 | } |
| 208 | |
Kevin O'Connor | 6e4583c | 2011-06-19 10:09:26 -0400 | [diff] [blame] | 209 | /* PIIX3/PIIX4 IDE */ |
Kevin O'Connor | d83c87b | 2013-01-21 01:14:12 -0500 | [diff] [blame] | 210 | static void piix_ide_setup(struct pci_device *pci, void *arg) |
Kevin O'Connor | 6e4583c | 2011-06-19 10:09:26 -0400 | [diff] [blame] | 211 | { |
Kevin O'Connor | 278b19f | 2011-06-21 22:41:15 -0400 | [diff] [blame] | 212 | u16 bdf = pci->bdf; |
Kevin O'Connor | 6e4583c | 2011-06-19 10:09:26 -0400 | [diff] [blame] | 213 | pci_config_writew(bdf, 0x40, 0x8000); // enable IDE0 |
| 214 | pci_config_writew(bdf, 0x42, 0x8000); // enable IDE1 |
Kevin O'Connor | 6e4583c | 2011-06-19 10:09:26 -0400 | [diff] [blame] | 215 | } |
| 216 | |
Kevin O'Connor | d83c87b | 2013-01-21 01:14:12 -0500 | [diff] [blame] | 217 | static void pic_ibm_setup(struct pci_device *pci, void *arg) |
Kevin O'Connor | 0d6b8d5 | 2010-07-10 13:12:37 -0400 | [diff] [blame] | 218 | { |
| 219 | /* PIC, IBM, MPIC & MPIC2 */ |
Alexey Korolev | 030288f | 2012-04-19 17:44:55 +1200 | [diff] [blame] | 220 | pci_set_io_region_addr(pci, 0, 0x80800000 + 0x00040000, 0); |
Kevin O'Connor | 0d6b8d5 | 2010-07-10 13:12:37 -0400 | [diff] [blame] | 221 | } |
| 222 | |
Kevin O'Connor | d83c87b | 2013-01-21 01:14:12 -0500 | [diff] [blame] | 223 | static void apple_macio_setup(struct pci_device *pci, void *arg) |
Kevin O'Connor | 0d6b8d5 | 2010-07-10 13:12:37 -0400 | [diff] [blame] | 224 | { |
| 225 | /* macio bridge */ |
Alexey Korolev | 030288f | 2012-04-19 17:44:55 +1200 | [diff] [blame] | 226 | pci_set_io_region_addr(pci, 0, 0x80800000, 0); |
Kevin O'Connor | 0d6b8d5 | 2010-07-10 13:12:37 -0400 | [diff] [blame] | 227 | } |
| 228 | |
Kevin O'Connor | 6e4583c | 2011-06-19 10:09:26 -0400 | [diff] [blame] | 229 | /* PIIX4 Power Management device (for ACPI) */ |
Kevin O'Connor | d83c87b | 2013-01-21 01:14:12 -0500 | [diff] [blame] | 230 | static void piix4_pm_setup(struct pci_device *pci, void *arg) |
Kevin O'Connor | 6e4583c | 2011-06-19 10:09:26 -0400 | [diff] [blame] | 231 | { |
Kevin O'Connor | 278b19f | 2011-06-21 22:41:15 -0400 | [diff] [blame] | 232 | u16 bdf = pci->bdf; |
Kevin O'Connor | 6e4583c | 2011-06-19 10:09:26 -0400 | [diff] [blame] | 233 | // acpi sci is hardwired to 9 |
| 234 | pci_config_writeb(bdf, PCI_INTERRUPT_LINE, 9); |
| 235 | |
| 236 | pci_config_writel(bdf, 0x40, PORT_ACPI_PM_BASE | 1); |
| 237 | pci_config_writeb(bdf, 0x80, 0x01); /* enable PM io space */ |
| 238 | pci_config_writel(bdf, 0x90, PORT_SMB_BASE | 1); |
| 239 | pci_config_writeb(bdf, 0xd2, 0x09); /* enable SMBus io space */ |
Gerd Hoffmann | 455a7c8 | 2012-09-06 08:01:00 +0200 | [diff] [blame] | 240 | |
Kevin O'Connor | d83c87b | 2013-01-21 01:14:12 -0500 | [diff] [blame] | 241 | pmtimer_setup(PORT_ACPI_PM_BASE + 0x08, PM_TIMER_FREQUENCY / 1000); |
Kevin O'Connor | 6e4583c | 2011-06-19 10:09:26 -0400 | [diff] [blame] | 242 | } |
| 243 | |
Isaku Yamahata | 72a590e | 2012-11-28 10:17:33 +0100 | [diff] [blame] | 244 | /* ICH9 SMBUS */ |
| 245 | /* PCI_VENDOR_ID_INTEL && PCI_DEVICE_ID_INTEL_ICH9_SMBUS */ |
Kevin O'Connor | d83c87b | 2013-01-21 01:14:12 -0500 | [diff] [blame] | 246 | void ich9_smbus_setup(struct pci_device *dev, void *arg) |
Isaku Yamahata | 72a590e | 2012-11-28 10:17:33 +0100 | [diff] [blame] | 247 | { |
| 248 | u16 bdf = dev->bdf; |
| 249 | /* map smbus into io space */ |
| 250 | pci_config_writel(bdf, ICH9_SMB_SMB_BASE, |
| 251 | PORT_SMB_BASE | PCI_BASE_ADDRESS_SPACE_IO); |
| 252 | |
| 253 | /* enable SMBus */ |
| 254 | pci_config_writeb(bdf, ICH9_SMB_HOSTC, ICH9_SMB_HOSTC_HST_EN); |
| 255 | } |
| 256 | |
Kevin O'Connor | 0d6b8d5 | 2010-07-10 13:12:37 -0400 | [diff] [blame] | 257 | static const struct pci_device_id pci_device_tbl[] = { |
Kevin O'Connor | 31dcfb0 | 2012-11-20 20:29:26 -0500 | [diff] [blame] | 258 | /* PIIX3/PIIX4 PCI to ISA bridge */ |
| 259 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371SB_0, |
Kevin O'Connor | d83c87b | 2013-01-21 01:14:12 -0500 | [diff] [blame] | 260 | piix_isa_bridge_setup), |
Kevin O'Connor | 31dcfb0 | 2012-11-20 20:29:26 -0500 | [diff] [blame] | 261 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_0, |
Kevin O'Connor | d83c87b | 2013-01-21 01:14:12 -0500 | [diff] [blame] | 262 | piix_isa_bridge_setup), |
Isaku Yamahata | 72a590e | 2012-11-28 10:17:33 +0100 | [diff] [blame] | 263 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH9_LPC, |
Kevin O'Connor | d83c87b | 2013-01-21 01:14:12 -0500 | [diff] [blame] | 264 | mch_isa_bridge_setup), |
Kevin O'Connor | 31dcfb0 | 2012-11-20 20:29:26 -0500 | [diff] [blame] | 265 | |
| 266 | /* STORAGE IDE */ |
| 267 | PCI_DEVICE_CLASS(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371SB_1, |
Kevin O'Connor | d83c87b | 2013-01-21 01:14:12 -0500 | [diff] [blame] | 268 | PCI_CLASS_STORAGE_IDE, piix_ide_setup), |
Kevin O'Connor | 31dcfb0 | 2012-11-20 20:29:26 -0500 | [diff] [blame] | 269 | PCI_DEVICE_CLASS(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB, |
Kevin O'Connor | d83c87b | 2013-01-21 01:14:12 -0500 | [diff] [blame] | 270 | PCI_CLASS_STORAGE_IDE, piix_ide_setup), |
Kevin O'Connor | 31dcfb0 | 2012-11-20 20:29:26 -0500 | [diff] [blame] | 271 | PCI_DEVICE_CLASS(PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_IDE, |
Kevin O'Connor | d83c87b | 2013-01-21 01:14:12 -0500 | [diff] [blame] | 272 | storage_ide_setup), |
Kevin O'Connor | 31dcfb0 | 2012-11-20 20:29:26 -0500 | [diff] [blame] | 273 | |
| 274 | /* PIC, IBM, MIPC & MPIC2 */ |
| 275 | PCI_DEVICE_CLASS(PCI_VENDOR_ID_IBM, 0x0046, PCI_CLASS_SYSTEM_PIC, |
Kevin O'Connor | d83c87b | 2013-01-21 01:14:12 -0500 | [diff] [blame] | 276 | pic_ibm_setup), |
Kevin O'Connor | 31dcfb0 | 2012-11-20 20:29:26 -0500 | [diff] [blame] | 277 | PCI_DEVICE_CLASS(PCI_VENDOR_ID_IBM, 0xFFFF, PCI_CLASS_SYSTEM_PIC, |
Kevin O'Connor | d83c87b | 2013-01-21 01:14:12 -0500 | [diff] [blame] | 278 | pic_ibm_setup), |
Kevin O'Connor | 31dcfb0 | 2012-11-20 20:29:26 -0500 | [diff] [blame] | 279 | |
Kevin O'Connor | 0d6b8d5 | 2010-07-10 13:12:37 -0400 | [diff] [blame] | 280 | /* PIIX4 Power Management device (for ACPI) */ |
| 281 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3, |
Kevin O'Connor | d83c87b | 2013-01-21 01:14:12 -0500 | [diff] [blame] | 282 | piix4_pm_setup), |
Isaku Yamahata | 72a590e | 2012-11-28 10:17:33 +0100 | [diff] [blame] | 283 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH9_SMBUS, |
Kevin O'Connor | d83c87b | 2013-01-21 01:14:12 -0500 | [diff] [blame] | 284 | ich9_smbus_setup), |
Kevin O'Connor | 0d6b8d5 | 2010-07-10 13:12:37 -0400 | [diff] [blame] | 285 | |
Kevin O'Connor | 31dcfb0 | 2012-11-20 20:29:26 -0500 | [diff] [blame] | 286 | /* 0xff00 */ |
Kevin O'Connor | d83c87b | 2013-01-21 01:14:12 -0500 | [diff] [blame] | 287 | PCI_DEVICE_CLASS(PCI_VENDOR_ID_APPLE, 0x0017, 0xff00, apple_macio_setup), |
| 288 | PCI_DEVICE_CLASS(PCI_VENDOR_ID_APPLE, 0x0022, 0xff00, apple_macio_setup), |
Kevin O'Connor | 31dcfb0 | 2012-11-20 20:29:26 -0500 | [diff] [blame] | 289 | |
Kevin O'Connor | 0d6b8d5 | 2010-07-10 13:12:37 -0400 | [diff] [blame] | 290 | PCI_DEVICE_END, |
| 291 | }; |
| 292 | |
Kevin O'Connor | 278b19f | 2011-06-21 22:41:15 -0400 | [diff] [blame] | 293 | static void pci_bios_init_device(struct pci_device *pci) |
Kevin O'Connor | 0525d29 | 2008-07-04 06:18:30 -0400 | [diff] [blame] | 294 | { |
Kevin O'Connor | 278b19f | 2011-06-21 22:41:15 -0400 | [diff] [blame] | 295 | u16 bdf = pci->bdf; |
Kevin O'Connor | 99e37c4 | 2011-10-01 10:47:21 -0400 | [diff] [blame] | 296 | dprintf(1, "PCI: init bdf=%02x:%02x.%x id=%04x:%04x\n" |
| 297 | , pci_bdf_to_bus(bdf), pci_bdf_to_dev(bdf), pci_bdf_to_fn(bdf) |
Kevin O'Connor | 278b19f | 2011-06-21 22:41:15 -0400 | [diff] [blame] | 298 | , pci->vendor, pci->device); |
Kevin O'Connor | 0ce2138 | 2011-10-01 14:52:35 -0400 | [diff] [blame] | 299 | |
Kevin O'Connor | 0525d29 | 2008-07-04 06:18:30 -0400 | [diff] [blame] | 300 | /* map the interrupt */ |
Kevin O'Connor | 0ce2138 | 2011-10-01 14:52:35 -0400 | [diff] [blame] | 301 | int pin = pci_config_readb(bdf, PCI_INTERRUPT_PIN); |
| 302 | if (pin != 0) |
Gerd Hoffmann | 0c8f58d | 2012-05-04 17:33:36 +0200 | [diff] [blame] | 303 | pci_config_writeb(bdf, PCI_INTERRUPT_LINE, pci_slot_get_irq(pci, pin)); |
Kevin O'Connor | 0525d29 | 2008-07-04 06:18:30 -0400 | [diff] [blame] | 304 | |
Kevin O'Connor | 278b19f | 2011-06-21 22:41:15 -0400 | [diff] [blame] | 305 | pci_init_device(pci_device_tbl, pci, NULL); |
Kevin O'Connor | 31dcfb0 | 2012-11-20 20:29:26 -0500 | [diff] [blame] | 306 | |
| 307 | /* enable memory mappings */ |
Isaku Yamahata | d146ab8 | 2012-11-28 10:17:32 +0100 | [diff] [blame] | 308 | pci_config_maskw(bdf, PCI_COMMAND, 0, |
| 309 | PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_SERR); |
Kevin O'Connor | 0525d29 | 2008-07-04 06:18:30 -0400 | [diff] [blame] | 310 | } |
| 311 | |
Kevin O'Connor | 3f2288f | 2011-10-15 12:02:14 -0400 | [diff] [blame] | 312 | static void pci_bios_init_devices(void) |
Isaku Yamahata | af0963d | 2010-06-22 17:57:53 +0900 | [diff] [blame] | 313 | { |
Kevin O'Connor | 278b19f | 2011-06-21 22:41:15 -0400 | [diff] [blame] | 314 | struct pci_device *pci; |
| 315 | foreachpci(pci) { |
Kevin O'Connor | 278b19f | 2011-06-21 22:41:15 -0400 | [diff] [blame] | 316 | pci_bios_init_device(pci); |
Isaku Yamahata | af0963d | 2010-06-22 17:57:53 +0900 | [diff] [blame] | 317 | } |
| 318 | } |
| 319 | |
Alex Williamson | 7adfd71 | 2013-03-20 10:58:47 -0600 | [diff] [blame] | 320 | static void pci_enable_default_vga(void) |
| 321 | { |
| 322 | struct pci_device *pci; |
| 323 | |
| 324 | foreachpci(pci) { |
| 325 | if (is_pci_vga(pci)) { |
| 326 | dprintf(1, "PCI: Using %02x:%02x.%x for primary VGA\n", |
| 327 | pci_bdf_to_bus(pci->bdf), pci_bdf_to_dev(pci->bdf), |
| 328 | pci_bdf_to_fn(pci->bdf)); |
| 329 | return; |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | pci = pci_find_class(PCI_CLASS_DISPLAY_VGA); |
| 334 | if (!pci) { |
| 335 | dprintf(1, "PCI: No VGA devices found\n"); |
| 336 | return; |
| 337 | } |
| 338 | |
| 339 | dprintf(1, "PCI: Enabling %02x:%02x.%x for primary VGA\n", |
| 340 | pci_bdf_to_bus(pci->bdf), pci_bdf_to_dev(pci->bdf), |
| 341 | pci_bdf_to_fn(pci->bdf)); |
| 342 | |
| 343 | pci_config_maskw(pci->bdf, PCI_COMMAND, 0, |
| 344 | PCI_COMMAND_IO | PCI_COMMAND_MEMORY); |
| 345 | |
| 346 | while (pci->parent) { |
| 347 | pci = pci->parent; |
| 348 | |
| 349 | dprintf(1, "PCI: Setting VGA enable on bridge %02x:%02x.%x\n", |
| 350 | pci_bdf_to_bus(pci->bdf), pci_bdf_to_dev(pci->bdf), |
| 351 | pci_bdf_to_fn(pci->bdf)); |
| 352 | |
| 353 | pci_config_maskw(pci->bdf, PCI_BRIDGE_CONTROL, 0, PCI_BRIDGE_CTL_VGA); |
| 354 | pci_config_maskw(pci->bdf, PCI_COMMAND, 0, |
| 355 | PCI_COMMAND_IO | PCI_COMMAND_MEMORY); |
| 356 | } |
| 357 | } |
Kevin O'Connor | 5bab7e6 | 2011-10-01 11:33:31 -0400 | [diff] [blame] | 358 | |
| 359 | /**************************************************************** |
Kevin O'Connor | b1c35f2 | 2012-11-26 11:05:32 -0500 | [diff] [blame] | 360 | * Platform device initialization |
| 361 | ****************************************************************/ |
| 362 | |
Kevin O'Connor | d83c87b | 2013-01-21 01:14:12 -0500 | [diff] [blame] | 363 | void i440fx_mem_addr_setup(struct pci_device *dev, void *arg) |
Kevin O'Connor | b1c35f2 | 2012-11-26 11:05:32 -0500 | [diff] [blame] | 364 | { |
| 365 | if (RamSize <= 0x80000000) |
| 366 | pcimem_start = 0x80000000; |
| 367 | else if (RamSize <= 0xc0000000) |
| 368 | pcimem_start = 0xc0000000; |
Alex Williamson | b949040 | 2013-02-15 14:11:41 -0700 | [diff] [blame] | 369 | |
| 370 | pci_slot_get_irq = piix_pci_slot_get_irq; |
Kevin O'Connor | b1c35f2 | 2012-11-26 11:05:32 -0500 | [diff] [blame] | 371 | } |
| 372 | |
Kevin O'Connor | d83c87b | 2013-01-21 01:14:12 -0500 | [diff] [blame] | 373 | void mch_mem_addr_setup(struct pci_device *dev, void *arg) |
Isaku Yamahata | 72a590e | 2012-11-28 10:17:33 +0100 | [diff] [blame] | 374 | { |
| 375 | u64 addr = Q35_HOST_BRIDGE_PCIEXBAR_ADDR; |
| 376 | u32 size = Q35_HOST_BRIDGE_PCIEXBAR_SIZE; |
| 377 | |
| 378 | /* setup mmconfig */ |
| 379 | u16 bdf = dev->bdf; |
| 380 | u32 upper = addr >> 32; |
| 381 | u32 lower = (addr & 0xffffffff) | Q35_HOST_BRIDGE_PCIEXBAREN; |
| 382 | pci_config_writel(bdf, Q35_HOST_BRIDGE_PCIEXBAR, 0); |
| 383 | pci_config_writel(bdf, Q35_HOST_BRIDGE_PCIEXBAR + 4, upper); |
| 384 | pci_config_writel(bdf, Q35_HOST_BRIDGE_PCIEXBAR, lower); |
| 385 | add_e820(addr, size, E820_RESERVED); |
| 386 | |
| 387 | /* setup pci i/o window (above mmconfig) */ |
| 388 | pcimem_start = addr + size; |
Alex Williamson | b949040 | 2013-02-15 14:11:41 -0700 | [diff] [blame] | 389 | |
| 390 | pci_slot_get_irq = mch_pci_slot_get_irq; |
Isaku Yamahata | 72a590e | 2012-11-28 10:17:33 +0100 | [diff] [blame] | 391 | } |
| 392 | |
Kevin O'Connor | b1c35f2 | 2012-11-26 11:05:32 -0500 | [diff] [blame] | 393 | static const struct pci_device_id pci_platform_tbl[] = { |
| 394 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82441, |
Kevin O'Connor | d83c87b | 2013-01-21 01:14:12 -0500 | [diff] [blame] | 395 | i440fx_mem_addr_setup), |
Isaku Yamahata | 72a590e | 2012-11-28 10:17:33 +0100 | [diff] [blame] | 396 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_Q35_MCH, |
Kevin O'Connor | d83c87b | 2013-01-21 01:14:12 -0500 | [diff] [blame] | 397 | mch_mem_addr_setup), |
Kevin O'Connor | b1c35f2 | 2012-11-26 11:05:32 -0500 | [diff] [blame] | 398 | PCI_DEVICE_END |
| 399 | }; |
| 400 | |
| 401 | static void pci_bios_init_platform(void) |
| 402 | { |
| 403 | struct pci_device *pci; |
| 404 | foreachpci(pci) { |
| 405 | pci_init_device(pci_platform_tbl, pci, NULL); |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | |
| 410 | /**************************************************************** |
Kevin O'Connor | 5bab7e6 | 2011-10-01 11:33:31 -0400 | [diff] [blame] | 411 | * Bus initialization |
| 412 | ****************************************************************/ |
| 413 | |
Isaku Yamahata | f441666 | 2010-06-22 17:57:52 +0900 | [diff] [blame] | 414 | static void |
| 415 | pci_bios_init_bus_rec(int bus, u8 *pci_bus) |
| 416 | { |
Kevin O'Connor | 2b333e4 | 2011-07-02 14:49:41 -0400 | [diff] [blame] | 417 | int bdf; |
Isaku Yamahata | f441666 | 2010-06-22 17:57:52 +0900 | [diff] [blame] | 418 | u16 class; |
| 419 | |
| 420 | dprintf(1, "PCI: %s bus = 0x%x\n", __func__, bus); |
| 421 | |
| 422 | /* prevent accidental access to unintended devices */ |
Kevin O'Connor | 2b333e4 | 2011-07-02 14:49:41 -0400 | [diff] [blame] | 423 | foreachbdf(bdf, bus) { |
Isaku Yamahata | f441666 | 2010-06-22 17:57:52 +0900 | [diff] [blame] | 424 | class = pci_config_readw(bdf, PCI_CLASS_DEVICE); |
| 425 | if (class == PCI_CLASS_BRIDGE_PCI) { |
| 426 | pci_config_writeb(bdf, PCI_SECONDARY_BUS, 255); |
| 427 | pci_config_writeb(bdf, PCI_SUBORDINATE_BUS, 0); |
| 428 | } |
| 429 | } |
| 430 | |
Kevin O'Connor | 2b333e4 | 2011-07-02 14:49:41 -0400 | [diff] [blame] | 431 | foreachbdf(bdf, bus) { |
Isaku Yamahata | f441666 | 2010-06-22 17:57:52 +0900 | [diff] [blame] | 432 | class = pci_config_readw(bdf, PCI_CLASS_DEVICE); |
| 433 | if (class != PCI_CLASS_BRIDGE_PCI) { |
| 434 | continue; |
| 435 | } |
| 436 | dprintf(1, "PCI: %s bdf = 0x%x\n", __func__, bdf); |
| 437 | |
| 438 | u8 pribus = pci_config_readb(bdf, PCI_PRIMARY_BUS); |
| 439 | if (pribus != bus) { |
| 440 | dprintf(1, "PCI: primary bus = 0x%x -> 0x%x\n", pribus, bus); |
| 441 | pci_config_writeb(bdf, PCI_PRIMARY_BUS, bus); |
| 442 | } else { |
| 443 | dprintf(1, "PCI: primary bus = 0x%x\n", pribus); |
| 444 | } |
| 445 | |
| 446 | u8 secbus = pci_config_readb(bdf, PCI_SECONDARY_BUS); |
| 447 | (*pci_bus)++; |
| 448 | if (*pci_bus != secbus) { |
| 449 | dprintf(1, "PCI: secondary bus = 0x%x -> 0x%x\n", |
| 450 | secbus, *pci_bus); |
| 451 | secbus = *pci_bus; |
| 452 | pci_config_writeb(bdf, PCI_SECONDARY_BUS, secbus); |
| 453 | } else { |
| 454 | dprintf(1, "PCI: secondary bus = 0x%x\n", secbus); |
| 455 | } |
| 456 | |
| 457 | /* set to max for access to all subordinate buses. |
| 458 | later set it to accurate value */ |
| 459 | u8 subbus = pci_config_readb(bdf, PCI_SUBORDINATE_BUS); |
| 460 | pci_config_writeb(bdf, PCI_SUBORDINATE_BUS, 255); |
| 461 | |
| 462 | pci_bios_init_bus_rec(secbus, pci_bus); |
| 463 | |
| 464 | if (subbus != *pci_bus) { |
| 465 | dprintf(1, "PCI: subordinate bus = 0x%x -> 0x%x\n", |
| 466 | subbus, *pci_bus); |
| 467 | subbus = *pci_bus; |
| 468 | } else { |
| 469 | dprintf(1, "PCI: subordinate bus = 0x%x\n", subbus); |
| 470 | } |
| 471 | pci_config_writeb(bdf, PCI_SUBORDINATE_BUS, subbus); |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | static void |
| 476 | pci_bios_init_bus(void) |
| 477 | { |
| 478 | u8 pci_bus = 0; |
| 479 | pci_bios_init_bus_rec(0 /* host bus */, &pci_bus); |
Gerd Hoffmann | 82b39b2 | 2011-07-11 09:20:28 +0200 | [diff] [blame] | 480 | } |
| 481 | |
Kevin O'Connor | 5bab7e6 | 2011-10-01 11:33:31 -0400 | [diff] [blame] | 482 | |
| 483 | /**************************************************************** |
| 484 | * Bus sizing |
| 485 | ****************************************************************/ |
| 486 | |
Kevin O'Connor | cbbdcf2 | 2011-10-01 13:13:29 -0400 | [diff] [blame] | 487 | static void |
Alexey Korolev | 030288f | 2012-04-19 17:44:55 +1200 | [diff] [blame] | 488 | pci_bios_get_bar(struct pci_device *pci, int bar, |
| 489 | int *ptype, u64 *psize, int *pis64) |
Gerd Hoffmann | 82b39b2 | 2011-07-11 09:20:28 +0200 | [diff] [blame] | 490 | { |
Kevin O'Connor | cbbdcf2 | 2011-10-01 13:13:29 -0400 | [diff] [blame] | 491 | u32 ofs = pci_bar(pci, bar); |
| 492 | u16 bdf = pci->bdf; |
Gerd Hoffmann | 82b39b2 | 2011-07-11 09:20:28 +0200 | [diff] [blame] | 493 | u32 old = pci_config_readl(bdf, ofs); |
Alexey Korolev | 030288f | 2012-04-19 17:44:55 +1200 | [diff] [blame] | 494 | int is64 = 0, type = PCI_REGION_TYPE_MEM; |
| 495 | u64 mask; |
Gerd Hoffmann | 82b39b2 | 2011-07-11 09:20:28 +0200 | [diff] [blame] | 496 | |
| 497 | if (bar == PCI_ROM_SLOT) { |
| 498 | mask = PCI_ROM_ADDRESS_MASK; |
| 499 | pci_config_writel(bdf, ofs, mask); |
| 500 | } else { |
Alexey Korolev | 030288f | 2012-04-19 17:44:55 +1200 | [diff] [blame] | 501 | if (old & PCI_BASE_ADDRESS_SPACE_IO) { |
Gerd Hoffmann | 82b39b2 | 2011-07-11 09:20:28 +0200 | [diff] [blame] | 502 | mask = PCI_BASE_ADDRESS_IO_MASK; |
Alexey Korolev | 030288f | 2012-04-19 17:44:55 +1200 | [diff] [blame] | 503 | type = PCI_REGION_TYPE_IO; |
| 504 | } else { |
Gerd Hoffmann | 82b39b2 | 2011-07-11 09:20:28 +0200 | [diff] [blame] | 505 | mask = PCI_BASE_ADDRESS_MEM_MASK; |
Alexey Korolev | 030288f | 2012-04-19 17:44:55 +1200 | [diff] [blame] | 506 | if (old & PCI_BASE_ADDRESS_MEM_PREFETCH) |
| 507 | type = PCI_REGION_TYPE_PREFMEM; |
| 508 | is64 = ((old & PCI_BASE_ADDRESS_MEM_TYPE_MASK) |
| 509 | == PCI_BASE_ADDRESS_MEM_TYPE_64); |
| 510 | } |
Gerd Hoffmann | 82b39b2 | 2011-07-11 09:20:28 +0200 | [diff] [blame] | 511 | pci_config_writel(bdf, ofs, ~0); |
| 512 | } |
Alexey Korolev | 030288f | 2012-04-19 17:44:55 +1200 | [diff] [blame] | 513 | u64 val = pci_config_readl(bdf, ofs); |
Gerd Hoffmann | 82b39b2 | 2011-07-11 09:20:28 +0200 | [diff] [blame] | 514 | pci_config_writel(bdf, ofs, old); |
Alexey Korolev | 030288f | 2012-04-19 17:44:55 +1200 | [diff] [blame] | 515 | if (is64) { |
| 516 | u32 hold = pci_config_readl(bdf, ofs + 4); |
| 517 | pci_config_writel(bdf, ofs + 4, ~0); |
| 518 | u32 high = pci_config_readl(bdf, ofs + 4); |
| 519 | pci_config_writel(bdf, ofs + 4, hold); |
| 520 | val |= ((u64)high << 32); |
| 521 | mask |= ((u64)0xffffffff << 32); |
| 522 | *psize = (~(val & mask)) + 1; |
| 523 | } else { |
| 524 | *psize = ((~(val & mask)) + 1) & 0xffffffff; |
| 525 | } |
| 526 | *ptype = type; |
| 527 | *pis64 = is64; |
Gerd Hoffmann | 82b39b2 | 2011-07-11 09:20:28 +0200 | [diff] [blame] | 528 | } |
| 529 | |
Alexey Korolev | ac0cd58 | 2012-04-19 17:48:54 +1200 | [diff] [blame] | 530 | static int pci_bios_bridge_region_is64(struct pci_region *r, |
| 531 | struct pci_device *pci, int type) |
| 532 | { |
| 533 | if (type != PCI_REGION_TYPE_PREFMEM) |
| 534 | return 0; |
| 535 | u32 pmem = pci_config_readl(pci->bdf, PCI_PREF_MEMORY_BASE); |
| 536 | if (!pmem) { |
| 537 | pci_config_writel(pci->bdf, PCI_PREF_MEMORY_BASE, 0xfff0fff0); |
| 538 | pmem = pci_config_readl(pci->bdf, PCI_PREF_MEMORY_BASE); |
| 539 | pci_config_writel(pci->bdf, PCI_PREF_MEMORY_BASE, 0x0); |
| 540 | } |
| 541 | if ((pmem & PCI_PREF_RANGE_TYPE_MASK) != PCI_PREF_RANGE_TYPE_64) |
| 542 | return 0; |
Kevin O'Connor | aab4215 | 2013-06-08 21:51:46 -0400 | [diff] [blame^] | 543 | struct pci_region_entry *entry; |
| 544 | hlist_for_each_entry(entry, &r->list, node) { |
Alexey Korolev | ac0cd58 | 2012-04-19 17:48:54 +1200 | [diff] [blame] | 545 | if (!entry->is64) |
| 546 | return 0; |
Alexey Korolev | ac0cd58 | 2012-04-19 17:48:54 +1200 | [diff] [blame] | 547 | } |
| 548 | return 1; |
| 549 | } |
| 550 | |
Alexey Korolev | 37c111f | 2012-04-26 16:51:05 +1200 | [diff] [blame] | 551 | static u64 pci_region_align(struct pci_region *r) |
| 552 | { |
Kevin O'Connor | aab4215 | 2013-06-08 21:51:46 -0400 | [diff] [blame^] | 553 | struct pci_region_entry *entry; |
| 554 | hlist_for_each_entry(entry, &r->list, node) { |
| 555 | // The first entry in the sorted list has the largest alignment |
| 556 | return entry->align; |
| 557 | } |
| 558 | return 1; |
Alexey Korolev | 37c111f | 2012-04-26 16:51:05 +1200 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | static u64 pci_region_sum(struct pci_region *r) |
| 562 | { |
Alexey Korolev | 37c111f | 2012-04-26 16:51:05 +1200 | [diff] [blame] | 563 | u64 sum = 0; |
Kevin O'Connor | aab4215 | 2013-06-08 21:51:46 -0400 | [diff] [blame^] | 564 | struct pci_region_entry *entry; |
| 565 | hlist_for_each_entry(entry, &r->list, node) { |
Alexey Korolev | 37c111f | 2012-04-26 16:51:05 +1200 | [diff] [blame] | 566 | sum += entry->size; |
Kevin O'Connor | e5d71ca | 2012-04-26 22:04:34 -0400 | [diff] [blame] | 567 | } |
| 568 | return sum; |
Alexey Korolev | 37c111f | 2012-04-26 16:51:05 +1200 | [diff] [blame] | 569 | } |
| 570 | |
Alexey Korolev | e5e5f96 | 2012-04-26 17:01:59 +1200 | [diff] [blame] | 571 | static void pci_region_migrate_64bit_entries(struct pci_region *from, |
| 572 | struct pci_region *to) |
| 573 | { |
Kevin O'Connor | aab4215 | 2013-06-08 21:51:46 -0400 | [diff] [blame^] | 574 | struct hlist_node **pprev, **last = &to->list.first; |
| 575 | struct pci_region_entry *entry; |
| 576 | hlist_for_each_entry_safe(entry, pprev, &from->list, node) { |
| 577 | if (!entry->is64) |
Kevin O'Connor | d630d14 | 2012-04-26 22:20:56 -0400 | [diff] [blame] | 578 | continue; |
Kevin O'Connor | d630d14 | 2012-04-26 22:20:56 -0400 | [diff] [blame] | 579 | // Move from source list to destination list. |
Kevin O'Connor | aab4215 | 2013-06-08 21:51:46 -0400 | [diff] [blame^] | 580 | hlist_del(&entry->node); |
| 581 | hlist_add(&entry->node, last); |
Alexey Korolev | e5e5f96 | 2012-04-26 17:01:59 +1200 | [diff] [blame] | 582 | } |
| 583 | } |
| 584 | |
Alexey Korolev | fa51bcd | 2012-04-18 17:21:19 +1200 | [diff] [blame] | 585 | static struct pci_region_entry * |
| 586 | pci_region_create_entry(struct pci_bus *bus, struct pci_device *dev, |
Alexey Korolev | 030288f | 2012-04-19 17:44:55 +1200 | [diff] [blame] | 587 | int bar, u64 size, u64 align, int type, int is64) |
Gerd Hoffmann | 82b39b2 | 2011-07-11 09:20:28 +0200 | [diff] [blame] | 588 | { |
Alexey Korolev | fa51bcd | 2012-04-18 17:21:19 +1200 | [diff] [blame] | 589 | struct pci_region_entry *entry = malloc_tmp(sizeof(*entry)); |
| 590 | if (!entry) { |
| 591 | warn_noalloc(); |
| 592 | return NULL; |
| 593 | } |
| 594 | memset(entry, 0, sizeof(*entry)); |
| 595 | entry->dev = dev; |
| 596 | entry->bar = bar; |
| 597 | entry->size = size; |
Kevin O'Connor | 3d1bc9d | 2012-04-01 12:30:32 -0400 | [diff] [blame] | 598 | entry->align = align; |
Alexey Korolev | fa51bcd | 2012-04-18 17:21:19 +1200 | [diff] [blame] | 599 | entry->is64 = is64; |
| 600 | entry->type = type; |
| 601 | // Insert into list in sorted order. |
Kevin O'Connor | aab4215 | 2013-06-08 21:51:46 -0400 | [diff] [blame^] | 602 | struct hlist_node **pprev; |
| 603 | struct pci_region_entry *pos; |
| 604 | hlist_for_each_entry_safe(pos, pprev, &bus->r[type].list, node) { |
Kevin O'Connor | 3d1bc9d | 2012-04-01 12:30:32 -0400 | [diff] [blame] | 605 | if (pos->align < align || (pos->align == align && pos->size < size)) |
Alexey Korolev | fa51bcd | 2012-04-18 17:21:19 +1200 | [diff] [blame] | 606 | break; |
| 607 | } |
Kevin O'Connor | aab4215 | 2013-06-08 21:51:46 -0400 | [diff] [blame^] | 608 | hlist_add(&entry->node, pprev); |
Alexey Korolev | fa51bcd | 2012-04-18 17:21:19 +1200 | [diff] [blame] | 609 | return entry; |
Gerd Hoffmann | 82b39b2 | 2011-07-11 09:20:28 +0200 | [diff] [blame] | 610 | } |
| 611 | |
Alexey Korolev | fa51bcd | 2012-04-18 17:21:19 +1200 | [diff] [blame] | 612 | static int pci_bios_check_devices(struct pci_bus *busses) |
Gerd Hoffmann | 82b39b2 | 2011-07-11 09:20:28 +0200 | [diff] [blame] | 613 | { |
Kevin O'Connor | 2c4c211 | 2011-10-15 11:42:48 -0400 | [diff] [blame] | 614 | dprintf(1, "PCI: check devices\n"); |
| 615 | |
| 616 | // Calculate resources needed for regular (non-bus) devices. |
| 617 | struct pci_device *pci; |
| 618 | foreachpci(pci) { |
Alexey Korolev | 1a9f47f | 2012-04-19 17:40:13 +1200 | [diff] [blame] | 619 | if (pci->class == PCI_CLASS_BRIDGE_PCI) |
Kevin O'Connor | 2c4c211 | 2011-10-15 11:42:48 -0400 | [diff] [blame] | 620 | busses[pci->secondary_bus].bus_dev = pci; |
Alexey Korolev | 1a9f47f | 2012-04-19 17:40:13 +1200 | [diff] [blame] | 621 | |
Kevin O'Connor | 2c4c211 | 2011-10-15 11:42:48 -0400 | [diff] [blame] | 622 | struct pci_bus *bus = &busses[pci_bdf_to_bus(pci->bdf)]; |
| 623 | int i; |
| 624 | for (i = 0; i < PCI_NUM_REGIONS; i++) { |
Alexey Korolev | 1a9f47f | 2012-04-19 17:40:13 +1200 | [diff] [blame] | 625 | if ((pci->class == PCI_CLASS_BRIDGE_PCI) && |
| 626 | (i >= PCI_BRIDGE_NUM_REGIONS && i < PCI_ROM_SLOT)) |
| 627 | continue; |
Alexey Korolev | 030288f | 2012-04-19 17:44:55 +1200 | [diff] [blame] | 628 | int type, is64; |
| 629 | u64 size; |
| 630 | pci_bios_get_bar(pci, i, &type, &size, &is64); |
| 631 | if (size == 0) |
Kevin O'Connor | 2c4c211 | 2011-10-15 11:42:48 -0400 | [diff] [blame] | 632 | continue; |
| 633 | |
Alexey Korolev | 5fa24b5 | 2012-04-18 17:31:58 +1200 | [diff] [blame] | 634 | if (type != PCI_REGION_TYPE_IO && size < PCI_DEVICE_MEM_MIN) |
| 635 | size = PCI_DEVICE_MEM_MIN; |
Alexey Korolev | fa51bcd | 2012-04-18 17:21:19 +1200 | [diff] [blame] | 636 | struct pci_region_entry *entry = pci_region_create_entry( |
Kevin O'Connor | 3d1bc9d | 2012-04-01 12:30:32 -0400 | [diff] [blame] | 637 | bus, pci, i, size, size, type, is64); |
Alexey Korolev | fa51bcd | 2012-04-18 17:21:19 +1200 | [diff] [blame] | 638 | if (!entry) |
| 639 | return -1; |
Kevin O'Connor | 2c4c211 | 2011-10-15 11:42:48 -0400 | [diff] [blame] | 640 | |
Alexey Korolev | fa51bcd | 2012-04-18 17:21:19 +1200 | [diff] [blame] | 641 | if (is64) |
Kevin O'Connor | 2c4c211 | 2011-10-15 11:42:48 -0400 | [diff] [blame] | 642 | i++; |
| 643 | } |
| 644 | } |
| 645 | |
| 646 | // Propagate required bus resources to parent busses. |
| 647 | int secondary_bus; |
| 648 | for (secondary_bus=MaxPCIBus; secondary_bus>0; secondary_bus--) { |
| 649 | struct pci_bus *s = &busses[secondary_bus]; |
| 650 | if (!s->bus_dev) |
| 651 | continue; |
| 652 | struct pci_bus *parent = &busses[pci_bdf_to_bus(s->bus_dev->bdf)]; |
Kevin O'Connor | cbbdcf2 | 2011-10-01 13:13:29 -0400 | [diff] [blame] | 653 | int type; |
Gerd Hoffmann | 82b39b2 | 2011-07-11 09:20:28 +0200 | [diff] [blame] | 654 | for (type = 0; type < PCI_REGION_TYPE_COUNT; type++) { |
Alexey Korolev | 030288f | 2012-04-19 17:44:55 +1200 | [diff] [blame] | 655 | u64 align = (type == PCI_REGION_TYPE_IO) ? |
Gerd Hoffmann | 82b39b2 | 2011-07-11 09:20:28 +0200 | [diff] [blame] | 656 | PCI_BRIDGE_IO_MIN : PCI_BRIDGE_MEM_MIN; |
Alexey Korolev | 37c111f | 2012-04-26 16:51:05 +1200 | [diff] [blame] | 657 | if (pci_region_align(&s->r[type]) > align) |
| 658 | align = pci_region_align(&s->r[type]); |
| 659 | u64 sum = pci_region_sum(&s->r[type]); |
| 660 | u64 size = ALIGN(sum, align); |
Alexey Korolev | ac0cd58 | 2012-04-19 17:48:54 +1200 | [diff] [blame] | 661 | int is64 = pci_bios_bridge_region_is64(&s->r[type], |
| 662 | s->bus_dev, type); |
Alexey Korolev | fa51bcd | 2012-04-18 17:21:19 +1200 | [diff] [blame] | 663 | // entry->bar is -1 if the entry represents a bridge region |
| 664 | struct pci_region_entry *entry = pci_region_create_entry( |
Alexey Korolev | ac0cd58 | 2012-04-19 17:48:54 +1200 | [diff] [blame] | 665 | parent, s->bus_dev, -1, size, align, type, is64); |
Alexey Korolev | fa51bcd | 2012-04-18 17:21:19 +1200 | [diff] [blame] | 666 | if (!entry) |
| 667 | return -1; |
Alexey Korolev | 030288f | 2012-04-19 17:44:55 +1200 | [diff] [blame] | 668 | dprintf(1, "PCI: secondary bus %d size %08llx type %s\n", |
Alexey Korolev | f3c2b06 | 2012-04-18 17:26:43 +1200 | [diff] [blame] | 669 | entry->dev->secondary_bus, size, |
| 670 | region_type_name[entry->type]); |
Gerd Hoffmann | 82b39b2 | 2011-07-11 09:20:28 +0200 | [diff] [blame] | 671 | } |
Kevin O'Connor | 5bab7e6 | 2011-10-01 11:33:31 -0400 | [diff] [blame] | 672 | } |
Alexey Korolev | fa51bcd | 2012-04-18 17:21:19 +1200 | [diff] [blame] | 673 | return 0; |
Kevin O'Connor | 5bab7e6 | 2011-10-01 11:33:31 -0400 | [diff] [blame] | 674 | } |
| 675 | |
Kevin O'Connor | e5d71ca | 2012-04-26 22:04:34 -0400 | [diff] [blame] | 676 | |
| 677 | /**************************************************************** |
| 678 | * BAR assignment |
| 679 | ****************************************************************/ |
| 680 | |
Kevin O'Connor | a8dcc5b | 2011-10-01 12:08:57 -0400 | [diff] [blame] | 681 | // Setup region bases (given the regions' size and alignment) |
Alexey Korolev | e5e5f96 | 2012-04-26 17:01:59 +1200 | [diff] [blame] | 682 | static int pci_bios_init_root_regions(struct pci_bus *bus) |
Kevin O'Connor | 5bab7e6 | 2011-10-01 11:33:31 -0400 | [diff] [blame] | 683 | { |
Kevin O'Connor | 5bab7e6 | 2011-10-01 11:33:31 -0400 | [diff] [blame] | 684 | bus->r[PCI_REGION_TYPE_IO].base = 0xc000; |
| 685 | |
Alexey Korolev | 37c111f | 2012-04-26 16:51:05 +1200 | [diff] [blame] | 686 | struct pci_region *r_end = &bus->r[PCI_REGION_TYPE_PREFMEM]; |
| 687 | struct pci_region *r_start = &bus->r[PCI_REGION_TYPE_MEM]; |
| 688 | |
| 689 | if (pci_region_align(r_start) < pci_region_align(r_end)) { |
Kevin O'Connor | 3d1bc9d | 2012-04-01 12:30:32 -0400 | [diff] [blame] | 690 | // Swap regions to improve alignment. |
Alexey Korolev | 37c111f | 2012-04-26 16:51:05 +1200 | [diff] [blame] | 691 | r_end = r_start; |
| 692 | r_start = &bus->r[PCI_REGION_TYPE_PREFMEM]; |
Kevin O'Connor | 5bab7e6 | 2011-10-01 11:33:31 -0400 | [diff] [blame] | 693 | } |
Alexey Korolev | 37c111f | 2012-04-26 16:51:05 +1200 | [diff] [blame] | 694 | u64 sum = pci_region_sum(r_end); |
| 695 | u64 align = pci_region_align(r_end); |
Gerd Hoffmann | e55c4e8 | 2012-06-07 10:34:32 +0200 | [diff] [blame] | 696 | r_end->base = ALIGN_DOWN((pcimem_end - sum), align); |
Alexey Korolev | 37c111f | 2012-04-26 16:51:05 +1200 | [diff] [blame] | 697 | sum = pci_region_sum(r_start); |
| 698 | align = pci_region_align(r_start); |
| 699 | r_start->base = ALIGN_DOWN((r_end->base - sum), align); |
| 700 | |
Gerd Hoffmann | e55c4e8 | 2012-06-07 10:34:32 +0200 | [diff] [blame] | 701 | if ((r_start->base < pcimem_start) || |
| 702 | (r_start->base > pcimem_end)) |
Kevin O'Connor | a8dcc5b | 2011-10-01 12:08:57 -0400 | [diff] [blame] | 703 | // Memory range requested is larger than available. |
Alexey Korolev | e5e5f96 | 2012-04-26 17:01:59 +1200 | [diff] [blame] | 704 | return -1; |
| 705 | return 0; |
Kevin O'Connor | 5bab7e6 | 2011-10-01 11:33:31 -0400 | [diff] [blame] | 706 | } |
| 707 | |
Kevin O'Connor | 5bab7e6 | 2011-10-01 11:33:31 -0400 | [diff] [blame] | 708 | #define PCI_IO_SHIFT 8 |
| 709 | #define PCI_MEMORY_SHIFT 16 |
| 710 | #define PCI_PREF_MEMORY_SHIFT 16 |
| 711 | |
Alexey Korolev | fa51bcd | 2012-04-18 17:21:19 +1200 | [diff] [blame] | 712 | static void |
Alexey Korolev | 35a770f | 2012-04-19 17:47:19 +1200 | [diff] [blame] | 713 | pci_region_map_one_entry(struct pci_region_entry *entry, u64 addr) |
Alexey Korolev | fa51bcd | 2012-04-18 17:21:19 +1200 | [diff] [blame] | 714 | { |
| 715 | u16 bdf = entry->dev->bdf; |
Alexey Korolev | fa51bcd | 2012-04-18 17:21:19 +1200 | [diff] [blame] | 716 | if (entry->bar >= 0) { |
Alexey Korolev | fa51bcd | 2012-04-18 17:21:19 +1200 | [diff] [blame] | 717 | dprintf(1, "PCI: map device bdf=%02x:%02x.%x" |
Alexey Korolev | 030288f | 2012-04-19 17:44:55 +1200 | [diff] [blame] | 718 | " bar %d, addr %08llx, size %08llx [%s]\n", |
Alexey Korolev | fa51bcd | 2012-04-18 17:21:19 +1200 | [diff] [blame] | 719 | pci_bdf_to_bus(bdf), pci_bdf_to_dev(bdf), pci_bdf_to_fn(bdf), |
| 720 | entry->bar, addr, entry->size, region_type_name[entry->type]); |
| 721 | |
Alexey Korolev | 030288f | 2012-04-19 17:44:55 +1200 | [diff] [blame] | 722 | pci_set_io_region_addr(entry->dev, entry->bar, addr, entry->is64); |
Alexey Korolev | 3a29716 | 2012-04-18 17:22:29 +1200 | [diff] [blame] | 723 | return; |
| 724 | } |
| 725 | |
Alexey Korolev | 030288f | 2012-04-19 17:44:55 +1200 | [diff] [blame] | 726 | u64 limit = addr + entry->size - 1; |
Alexey Korolev | 3a29716 | 2012-04-18 17:22:29 +1200 | [diff] [blame] | 727 | if (entry->type == PCI_REGION_TYPE_IO) { |
| 728 | pci_config_writeb(bdf, PCI_IO_BASE, addr >> PCI_IO_SHIFT); |
| 729 | pci_config_writew(bdf, PCI_IO_BASE_UPPER16, 0); |
| 730 | pci_config_writeb(bdf, PCI_IO_LIMIT, limit >> PCI_IO_SHIFT); |
| 731 | pci_config_writew(bdf, PCI_IO_LIMIT_UPPER16, 0); |
| 732 | } |
| 733 | if (entry->type == PCI_REGION_TYPE_MEM) { |
| 734 | pci_config_writew(bdf, PCI_MEMORY_BASE, addr >> PCI_MEMORY_SHIFT); |
| 735 | pci_config_writew(bdf, PCI_MEMORY_LIMIT, limit >> PCI_MEMORY_SHIFT); |
| 736 | } |
| 737 | if (entry->type == PCI_REGION_TYPE_PREFMEM) { |
| 738 | pci_config_writew(bdf, PCI_PREF_MEMORY_BASE, addr >> PCI_PREF_MEMORY_SHIFT); |
| 739 | pci_config_writew(bdf, PCI_PREF_MEMORY_LIMIT, limit >> PCI_PREF_MEMORY_SHIFT); |
Alexey Korolev | 030288f | 2012-04-19 17:44:55 +1200 | [diff] [blame] | 740 | pci_config_writel(bdf, PCI_PREF_BASE_UPPER32, addr >> 32); |
| 741 | pci_config_writel(bdf, PCI_PREF_LIMIT_UPPER32, limit >> 32); |
Alexey Korolev | fa51bcd | 2012-04-18 17:21:19 +1200 | [diff] [blame] | 742 | } |
| 743 | } |
| 744 | |
Alexey Korolev | 35a770f | 2012-04-19 17:47:19 +1200 | [diff] [blame] | 745 | static void pci_region_map_entries(struct pci_bus *busses, struct pci_region *r) |
| 746 | { |
Kevin O'Connor | aab4215 | 2013-06-08 21:51:46 -0400 | [diff] [blame^] | 747 | struct hlist_node **pprev; |
| 748 | struct pci_region_entry *entry; |
| 749 | hlist_for_each_entry_safe(entry, pprev, &r->list, node) { |
Alexey Korolev | 35a770f | 2012-04-19 17:47:19 +1200 | [diff] [blame] | 750 | u64 addr = r->base; |
| 751 | r->base += entry->size; |
| 752 | if (entry->bar == -1) |
| 753 | // Update bus base address if entry is a bridge region |
| 754 | busses[entry->dev->secondary_bus].r[entry->type].base = addr; |
| 755 | pci_region_map_one_entry(entry, addr); |
Kevin O'Connor | aab4215 | 2013-06-08 21:51:46 -0400 | [diff] [blame^] | 756 | hlist_del(&entry->node); |
Alexey Korolev | 35a770f | 2012-04-19 17:47:19 +1200 | [diff] [blame] | 757 | free(entry); |
Alexey Korolev | 35a770f | 2012-04-19 17:47:19 +1200 | [diff] [blame] | 758 | } |
| 759 | } |
| 760 | |
Kevin O'Connor | b725dcb | 2011-10-15 11:53:38 -0400 | [diff] [blame] | 761 | static void pci_bios_map_devices(struct pci_bus *busses) |
Gerd Hoffmann | 82b39b2 | 2011-07-11 09:20:28 +0200 | [diff] [blame] | 762 | { |
Alexey Korolev | e5e5f96 | 2012-04-26 17:01:59 +1200 | [diff] [blame] | 763 | if (pci_bios_init_root_regions(busses)) { |
| 764 | struct pci_region r64_mem, r64_pref; |
Kevin O'Connor | aab4215 | 2013-06-08 21:51:46 -0400 | [diff] [blame^] | 765 | r64_mem.list.first = NULL; |
| 766 | r64_pref.list.first = NULL; |
Alexey Korolev | e5e5f96 | 2012-04-26 17:01:59 +1200 | [diff] [blame] | 767 | pci_region_migrate_64bit_entries(&busses[0].r[PCI_REGION_TYPE_MEM], |
| 768 | &r64_mem); |
| 769 | pci_region_migrate_64bit_entries(&busses[0].r[PCI_REGION_TYPE_PREFMEM], |
| 770 | &r64_pref); |
| 771 | |
| 772 | if (pci_bios_init_root_regions(busses)) |
| 773 | panic("PCI: out of 32bit address space\n"); |
| 774 | |
Gerd Hoffmann | 5283b2e | 2012-06-12 09:27:15 +0200 | [diff] [blame] | 775 | u64 sum_mem = pci_region_sum(&r64_mem); |
| 776 | u64 sum_pref = pci_region_sum(&r64_pref); |
| 777 | u64 align_mem = pci_region_align(&r64_mem); |
| 778 | u64 align_pref = pci_region_align(&r64_pref); |
| 779 | |
| 780 | r64_mem.base = ALIGN(0x100000000LL + RamSizeOver4G, align_mem); |
| 781 | r64_pref.base = ALIGN(r64_mem.base + sum_mem, align_pref); |
| 782 | pcimem64_start = r64_mem.base; |
| 783 | pcimem64_end = r64_pref.base + sum_pref; |
| 784 | |
Alexey Korolev | e5e5f96 | 2012-04-26 17:01:59 +1200 | [diff] [blame] | 785 | pci_region_map_entries(busses, &r64_mem); |
| 786 | pci_region_map_entries(busses, &r64_pref); |
Gerd Hoffmann | 5283b2e | 2012-06-12 09:27:15 +0200 | [diff] [blame] | 787 | } else { |
| 788 | // no bars mapped high -> drop 64bit window (see dsdt) |
| 789 | pcimem64_start = 0; |
Alexey Korolev | e5e5f96 | 2012-04-26 17:01:59 +1200 | [diff] [blame] | 790 | } |
Kevin O'Connor | 2c4c211 | 2011-10-15 11:42:48 -0400 | [diff] [blame] | 791 | // Map regions on each device. |
Alexey Korolev | fa51bcd | 2012-04-18 17:21:19 +1200 | [diff] [blame] | 792 | int bus; |
| 793 | for (bus = 0; bus<=MaxPCIBus; bus++) { |
| 794 | int type; |
Alexey Korolev | 35a770f | 2012-04-19 17:47:19 +1200 | [diff] [blame] | 795 | for (type = 0; type < PCI_REGION_TYPE_COUNT; type++) |
| 796 | pci_region_map_entries(busses, &busses[bus].r[type]); |
Gerd Hoffmann | 82b39b2 | 2011-07-11 09:20:28 +0200 | [diff] [blame] | 797 | } |
| 798 | } |
| 799 | |
Gerd Hoffmann | 82b39b2 | 2011-07-11 09:20:28 +0200 | [diff] [blame] | 800 | |
Kevin O'Connor | 5bab7e6 | 2011-10-01 11:33:31 -0400 | [diff] [blame] | 801 | /**************************************************************** |
| 802 | * Main setup code |
| 803 | ****************************************************************/ |
Isaku Yamahata | f441666 | 2010-06-22 17:57:52 +0900 | [diff] [blame] | 804 | |
Kevin O'Connor | 0525d29 | 2008-07-04 06:18:30 -0400 | [diff] [blame] | 805 | void |
Kevin O'Connor | 40f5b5a | 2009-09-13 10:46:57 -0400 | [diff] [blame] | 806 | pci_setup(void) |
Kevin O'Connor | 0525d29 | 2008-07-04 06:18:30 -0400 | [diff] [blame] | 807 | { |
Kevin O'Connor | a2a86e2 | 2013-02-13 19:35:12 -0500 | [diff] [blame] | 808 | if (!CONFIG_QEMU) |
Kevin O'Connor | 0525d29 | 2008-07-04 06:18:30 -0400 | [diff] [blame] | 809 | return; |
| 810 | |
Kevin O'Connor | 40f5b5a | 2009-09-13 10:46:57 -0400 | [diff] [blame] | 811 | dprintf(3, "pci setup\n"); |
| 812 | |
Gerd Hoffmann | 82b39b2 | 2011-07-11 09:20:28 +0200 | [diff] [blame] | 813 | dprintf(1, "=== PCI bus & bridge init ===\n"); |
Jan Kiszka | 58e6b3f | 2011-09-21 08:16:21 +0200 | [diff] [blame] | 814 | if (pci_probe_host() != 0) { |
| 815 | return; |
| 816 | } |
Isaku Yamahata | f441666 | 2010-06-22 17:57:52 +0900 | [diff] [blame] | 817 | pci_bios_init_bus(); |
| 818 | |
Gerd Hoffmann | 82b39b2 | 2011-07-11 09:20:28 +0200 | [diff] [blame] | 819 | dprintf(1, "=== PCI device probing ===\n"); |
Jan Kiszka | 58e6b3f | 2011-09-21 08:16:21 +0200 | [diff] [blame] | 820 | pci_probe_devices(); |
Kevin O'Connor | 37956dd | 2011-06-21 22:22:58 -0400 | [diff] [blame] | 821 | |
Kevin O'Connor | b1c35f2 | 2012-11-26 11:05:32 -0500 | [diff] [blame] | 822 | pcimem_start = RamSize; |
| 823 | pci_bios_init_platform(); |
| 824 | |
Gerd Hoffmann | 82b39b2 | 2011-07-11 09:20:28 +0200 | [diff] [blame] | 825 | dprintf(1, "=== PCI new allocation pass #1 ===\n"); |
Kevin O'Connor | b725dcb | 2011-10-15 11:53:38 -0400 | [diff] [blame] | 826 | struct pci_bus *busses = malloc_tmp(sizeof(*busses) * (MaxPCIBus + 1)); |
Kevin O'Connor | 28a20e1 | 2011-10-15 11:07:30 -0400 | [diff] [blame] | 827 | if (!busses) { |
| 828 | warn_noalloc(); |
| 829 | return; |
| 830 | } |
| 831 | memset(busses, 0, sizeof(*busses) * (MaxPCIBus + 1)); |
Alexey Korolev | fa51bcd | 2012-04-18 17:21:19 +1200 | [diff] [blame] | 832 | if (pci_bios_check_devices(busses)) |
| 833 | return; |
| 834 | |
Gerd Hoffmann | 82b39b2 | 2011-07-11 09:20:28 +0200 | [diff] [blame] | 835 | dprintf(1, "=== PCI new allocation pass #2 ===\n"); |
Kevin O'Connor | b725dcb | 2011-10-15 11:53:38 -0400 | [diff] [blame] | 836 | pci_bios_map_devices(busses); |
Gerd Hoffmann | 82b39b2 | 2011-07-11 09:20:28 +0200 | [diff] [blame] | 837 | |
Kevin O'Connor | 3f2288f | 2011-10-15 12:02:14 -0400 | [diff] [blame] | 838 | pci_bios_init_devices(); |
Gerd Hoffmann | 8e30147 | 2011-08-09 17:22:42 +0200 | [diff] [blame] | 839 | |
Gerd Hoffmann | 82b39b2 | 2011-07-11 09:20:28 +0200 | [diff] [blame] | 840 | free(busses); |
Alex Williamson | 7adfd71 | 2013-03-20 10:58:47 -0600 | [diff] [blame] | 841 | |
| 842 | pci_enable_default_vga(); |
Kevin O'Connor | 0525d29 | 2008-07-04 06:18:30 -0400 | [diff] [blame] | 843 | } |