Bin Meng | 2229c4c | 2015-05-07 21:34:08 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com> |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <pci.h> |
Bin Meng | ceb9793 | 2015-05-11 07:36:30 +0800 | [diff] [blame] | 9 | #include <pci_rom.h> |
Bin Meng | 2229c4c | 2015-05-07 21:34:08 +0800 | [diff] [blame] | 10 | |
| 11 | DECLARE_GLOBAL_DATA_PTR; |
| 12 | |
| 13 | void board_pci_setup_hose(struct pci_controller *hose) |
| 14 | { |
| 15 | hose->first_busno = 0; |
| 16 | hose->last_busno = 0; |
| 17 | |
| 18 | /* PCI memory space */ |
| 19 | pci_set_region(hose->regions + 0, |
| 20 | CONFIG_PCI_MEM_BUS, |
| 21 | CONFIG_PCI_MEM_PHYS, |
| 22 | CONFIG_PCI_MEM_SIZE, |
| 23 | PCI_REGION_MEM); |
| 24 | |
| 25 | /* PCI IO space */ |
| 26 | pci_set_region(hose->regions + 1, |
| 27 | CONFIG_PCI_IO_BUS, |
| 28 | CONFIG_PCI_IO_PHYS, |
| 29 | CONFIG_PCI_IO_SIZE, |
| 30 | PCI_REGION_IO); |
| 31 | |
| 32 | pci_set_region(hose->regions + 2, |
| 33 | CONFIG_PCI_PREF_BUS, |
| 34 | CONFIG_PCI_PREF_PHYS, |
| 35 | CONFIG_PCI_PREF_SIZE, |
| 36 | PCI_REGION_PREFETCH); |
| 37 | |
| 38 | pci_set_region(hose->regions + 3, |
| 39 | 0, |
| 40 | 0, |
| 41 | gd->ram_size, |
| 42 | PCI_REGION_MEM | PCI_REGION_SYS_MEMORY); |
| 43 | |
| 44 | hose->region_count = 4; |
| 45 | } |
| 46 | |
| 47 | int board_pci_post_scan(struct pci_controller *hose) |
| 48 | { |
Bin Meng | ceb9793 | 2015-05-11 07:36:30 +0800 | [diff] [blame] | 49 | int ret = 0; |
| 50 | ulong start; |
| 51 | pci_dev_t bdf; |
| 52 | struct pci_device_id graphic_card[] = { { 0x1234, 0x1111 } }; |
| 53 | |
| 54 | /* |
| 55 | * QEMU emulated graphic card shows in the PCI configuration space with |
| 56 | * PCI vendor id and device id as an artificial pair 0x1234:0x1111. |
| 57 | * It is on PCI bus 0, function 0, but device number is not consistent |
| 58 | * for the two x86 targets it supports. For i440FX and PIIX chipset |
| 59 | * board, it shows as device 2, while for Q35 and ICH9 chipset board, |
| 60 | * it shows as device 1. Here we locate its bdf at run-time based on |
| 61 | * its vendor id and device id pair so we can support both boards. |
| 62 | */ |
| 63 | bdf = pci_find_devices(graphic_card, 0); |
| 64 | if (bdf != -1) { |
| 65 | start = get_timer(0); |
| 66 | ret = pci_run_vga_bios(bdf, NULL, PCI_ROM_USE_NATIVE); |
| 67 | debug("BIOS ran in %lums\n", get_timer(start)); |
| 68 | } |
| 69 | |
| 70 | return ret; |
Bin Meng | 2229c4c | 2015-05-07 21:34:08 +0800 | [diff] [blame] | 71 | } |