1df2d8b3eSIsaku Yamahata /* 2df2d8b3eSIsaku Yamahata * q35.h 3df2d8b3eSIsaku Yamahata * 4df2d8b3eSIsaku Yamahata * Copyright (c) 2009 Isaku Yamahata <yamahata at valinux co jp> 5df2d8b3eSIsaku Yamahata * VA Linux Systems Japan K.K. 6df2d8b3eSIsaku Yamahata * Copyright (C) 2012 Jason Baron <jbaron@redhat.com> 7df2d8b3eSIsaku Yamahata * 8df2d8b3eSIsaku Yamahata * This program is free software; you can redistribute it and/or modify 9df2d8b3eSIsaku Yamahata * it under the terms of the GNU General Public License as published by 10df2d8b3eSIsaku Yamahata * the Free Software Foundation; either version 2 of the License, or 11df2d8b3eSIsaku Yamahata * (at your option) any later version. 12df2d8b3eSIsaku Yamahata * 13df2d8b3eSIsaku Yamahata * This program is distributed in the hope that it will be useful, 14df2d8b3eSIsaku Yamahata * but WITHOUT ANY WARRANTY; without even the implied warranty of 15df2d8b3eSIsaku Yamahata * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16df2d8b3eSIsaku Yamahata * GNU General Public License for more details. 17df2d8b3eSIsaku Yamahata * 18e361a772SThomas Huth * You should have received a copy of the GNU General Public License 19e361a772SThomas Huth * along with this program; if not, see <http://www.gnu.org/licenses/> 20df2d8b3eSIsaku Yamahata */ 21df2d8b3eSIsaku Yamahata 22df2d8b3eSIsaku Yamahata #ifndef HW_Q35_H 23df2d8b3eSIsaku Yamahata #define HW_Q35_H 24df2d8b3eSIsaku Yamahata 25*edf5ca5dSMarkus Armbruster #include "hw/pci/pci_device.h" 2683c9f4caSPaolo Bonzini #include "hw/pci/pcie_host.h" 270d09e41aSPaolo Bonzini #include "hw/pci-host/pam.h" 28f404220eSIgor Mammedov #include "qemu/units.h" 29577aa489SPhilippe Mathieu-Daudé #include "qemu/range.h" 30db1015e9SEduardo Habkost #include "qom/object.h" 31df2d8b3eSIsaku Yamahata 32df2d8b3eSIsaku Yamahata #define TYPE_Q35_HOST_DEVICE "q35-pcihost" 338063396bSEduardo Habkost OBJECT_DECLARE_SIMPLE_TYPE(Q35PCIHost, Q35_HOST_DEVICE) 34df2d8b3eSIsaku Yamahata 35df2d8b3eSIsaku Yamahata #define TYPE_MCH_PCI_DEVICE "mch" 368063396bSEduardo Habkost OBJECT_DECLARE_SIMPLE_TYPE(MCHPCIState, MCH_PCI_DEVICE) 37df2d8b3eSIsaku Yamahata 38db1015e9SEduardo Habkost struct MCHPCIState { 39ce88812fSHu Tao /*< private >*/ 40ce88812fSHu Tao PCIDevice parent_obj; 41ce88812fSHu Tao /*< public >*/ 42ce88812fSHu Tao 43df2d8b3eSIsaku Yamahata MemoryRegion *ram_memory; 44df2d8b3eSIsaku Yamahata MemoryRegion *pci_address_space; 45df2d8b3eSIsaku Yamahata MemoryRegion *system_memory; 46df2d8b3eSIsaku Yamahata MemoryRegion *address_space_io; 47f6a3c86eSPhilippe Mathieu-Daudé PAMMemoryRegion pam_regions[PAM_REGIONS_COUNT]; 4864130fa4SPaolo Bonzini MemoryRegion smram_region, open_high_smram; 4964130fa4SPaolo Bonzini MemoryRegion smram, low_smram, high_smram; 50bafc90bdSGerd Hoffmann MemoryRegion tseg_blackhole, tseg_window; 51f404220eSIgor Mammedov MemoryRegion smbase_blackhole, smbase_window; 52f404220eSIgor Mammedov bool has_smram_at_smbase; 5301c9742dSMarkus Armbruster Range pci_hole; 54401f2f3eSEfimov Vasily uint64_t below_4g_mem_size; 55401f2f3eSEfimov Vasily uint64_t above_4g_mem_size; 5639848901SIgor Mammedov uint64_t pci_hole64_size; 5704c7d8b8SCole Robinson uint32_t short_root_bus; 582f295167SLaszlo Ersek uint16_t ext_tseg_mbytes; 59db1015e9SEduardo Habkost }; 60df2d8b3eSIsaku Yamahata 61db1015e9SEduardo Habkost struct Q35PCIHost { 62ce88812fSHu Tao /*< private >*/ 63ce88812fSHu Tao PCIExpressHost parent_obj; 64ce88812fSHu Tao /*< public >*/ 65ce88812fSHu Tao 669fa99d25SMarcel Apfelbaum bool pci_hole64_fix; 67df2d8b3eSIsaku Yamahata MCHPCIState mch; 68db1015e9SEduardo Habkost }; 69df2d8b3eSIsaku Yamahata 70df2d8b3eSIsaku Yamahata #define Q35_MASK(bit, ms_bit, ls_bit) \ 71df2d8b3eSIsaku Yamahata ((uint##bit##_t)(((1ULL << ((ms_bit) + 1)) - 1) & ~((1ULL << ls_bit) - 1))) 72df2d8b3eSIsaku Yamahata 73df2d8b3eSIsaku Yamahata /* 74df2d8b3eSIsaku Yamahata * gmch part 75df2d8b3eSIsaku Yamahata */ 76df2d8b3eSIsaku Yamahata 77401f2f3eSEfimov Vasily #define MCH_HOST_PROP_RAM_MEM "ram-mem" 78401f2f3eSEfimov Vasily #define MCH_HOST_PROP_PCI_MEM "pci-mem" 79401f2f3eSEfimov Vasily #define MCH_HOST_PROP_SYSTEM_MEM "system-mem" 80401f2f3eSEfimov Vasily #define MCH_HOST_PROP_IO_MEM "io-mem" 81401f2f3eSEfimov Vasily 82df2d8b3eSIsaku Yamahata /* PCI configuration */ 83df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE "MCH" 84df2d8b3eSIsaku Yamahata 85df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_CONFIG_ADDR 0xcf8 86df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_CONFIG_DATA 0xcfc 87df2d8b3eSIsaku Yamahata 88df2d8b3eSIsaku Yamahata /* D0:F0 configuration space */ 89451f7846SRichard W.M. Jones #define MCH_HOST_BRIDGE_REVISION_DEFAULT 0x0 90df2d8b3eSIsaku Yamahata 912f295167SLaszlo Ersek #define MCH_HOST_BRIDGE_EXT_TSEG_MBYTES 0x50 922f295167SLaszlo Ersek #define MCH_HOST_BRIDGE_EXT_TSEG_MBYTES_SIZE 2 932f295167SLaszlo Ersek #define MCH_HOST_BRIDGE_EXT_TSEG_MBYTES_QUERY 0xffff 942f295167SLaszlo Ersek #define MCH_HOST_BRIDGE_EXT_TSEG_MBYTES_MAX 0xfff 952f295167SLaszlo Ersek 96f404220eSIgor Mammedov #define MCH_HOST_BRIDGE_SMBASE_SIZE (128 * KiB) 97f404220eSIgor Mammedov #define MCH_HOST_BRIDGE_SMBASE_ADDR 0x30000 98f404220eSIgor Mammedov #define MCH_HOST_BRIDGE_F_SMBASE 0x9c 99f404220eSIgor Mammedov #define MCH_HOST_BRIDGE_F_SMBASE_QUERY 0xff 100f404220eSIgor Mammedov #define MCH_HOST_BRIDGE_F_SMBASE_IN_RAM 0x01 101f404220eSIgor Mammedov #define MCH_HOST_BRIDGE_F_SMBASE_LCK 0x02 102f404220eSIgor Mammedov 103df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR 0x60 /* 64bit register */ 104df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_SIZE 8 /* 64bit register */ 105df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_DEFAULT 0xb0000000 1063459a625SMichael S. Tsirkin #define MCH_HOST_BRIDGE_PCIEXBAR_MAX (0x10000000) /* 256M */ 107df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_ADMSK Q35_MASK(64, 35, 28) 108df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_128ADMSK ((uint64_t)(1 << 26)) 109df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_64ADMSK ((uint64_t)(1 << 25)) 110df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_LENGTH_MASK ((uint64_t)(0x3 << 1)) 111df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_LENGTH_256M ((uint64_t)(0x0 << 1)) 112df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_LENGTH_128M ((uint64_t)(0x1 << 1)) 113df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_LENGTH_64M ((uint64_t)(0x2 << 1)) 114df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_LENGTH_RVD ((uint64_t)(0x3 << 1)) 115df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAREN ((uint64_t)1) 116df2d8b3eSIsaku Yamahata 117df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_NB 7 118df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_SIZE 7 119df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM0 0x90 120df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_BIOS_AREA 0xf0000 121df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_AREA_SIZE 0x10000 /* 16KB */ 122df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM1 0x91 123df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_EXPAN_AREA 0xc0000 124df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_EXPAN_SIZE 0x04000 125df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM2 0x92 126df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM3 0x93 127df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM4 0x94 128df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_EXBIOS_AREA 0xe0000 129df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_EXBIOS_SIZE 0x04000 130df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM5 0x95 131df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM6 0x96 132df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_WE_HI ((uint8_t)(0x2 << 4)) 133df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_RE_HI ((uint8_t)(0x1 << 4)) 134df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_HI_MASK ((uint8_t)(0x3 << 4)) 135df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_WE_LO ((uint8_t)0x2) 136df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_RE_LO ((uint8_t)0x1) 137df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_LO_MASK ((uint8_t)0x3) 138df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_WE ((uint8_t)0x2) 139df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_RE ((uint8_t)0x1) 140df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_MASK ((uint8_t)0x3) 141df2d8b3eSIsaku Yamahata 142263cf436SBALATON Zoltan #define MCH_HOST_BRIDGE_SMRAM 0x9d 14364130fa4SPaolo Bonzini #define MCH_HOST_BRIDGE_SMRAM_SIZE 2 144df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_SMRAM_D_OPEN ((uint8_t)(1 << 6)) 145df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_SMRAM_D_CLS ((uint8_t)(1 << 5)) 146df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_SMRAM_D_LCK ((uint8_t)(1 << 4)) 147df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_SMRAM_G_SMRAME ((uint8_t)(1 << 3)) 148df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_SMRAM_C_BASE_SEG_MASK ((uint8_t)0x7) 149df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_SMRAM_C_BASE_SEG ((uint8_t)0x2) /* hardwired to b010 */ 150df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_SMRAM_C_BASE 0xa0000 151df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_SMRAM_C_END 0xc0000 152df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_SMRAM_C_SIZE 0x20000 153df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_UPPER_SYSTEM_BIOS_END 0x100000 15477447524SGerd Hoffmann #define MCH_HOST_BRIDGE_SMRAM_DEFAULT \ 15577447524SGerd Hoffmann MCH_HOST_BRIDGE_SMRAM_C_BASE_SEG 156b66a67d7SGerd Hoffmann #define MCH_HOST_BRIDGE_SMRAM_WMASK \ 157b66a67d7SGerd Hoffmann (MCH_HOST_BRIDGE_SMRAM_D_OPEN | \ 158b66a67d7SGerd Hoffmann MCH_HOST_BRIDGE_SMRAM_D_CLS | \ 159b66a67d7SGerd Hoffmann MCH_HOST_BRIDGE_SMRAM_D_LCK | \ 160b66a67d7SGerd Hoffmann MCH_HOST_BRIDGE_SMRAM_G_SMRAME) 16168c77acfSGerd Hoffmann #define MCH_HOST_BRIDGE_SMRAM_WMASK_LCK \ 16268c77acfSGerd Hoffmann MCH_HOST_BRIDGE_SMRAM_D_CLS 163df2d8b3eSIsaku Yamahata 164df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_ESMRAMC 0x9e 16564130fa4SPaolo Bonzini #define MCH_HOST_BRIDGE_ESMRAMC_H_SMRAME ((uint8_t)(1 << 7)) 16664130fa4SPaolo Bonzini #define MCH_HOST_BRIDGE_ESMRAMC_E_SMERR ((uint8_t)(1 << 6)) 16764130fa4SPaolo Bonzini #define MCH_HOST_BRIDGE_ESMRAMC_SM_CACHE ((uint8_t)(1 << 5)) 16864130fa4SPaolo Bonzini #define MCH_HOST_BRIDGE_ESMRAMC_SM_L1 ((uint8_t)(1 << 4)) 16964130fa4SPaolo Bonzini #define MCH_HOST_BRIDGE_ESMRAMC_SM_L2 ((uint8_t)(1 << 3)) 170263cf436SBALATON Zoltan #define MCH_HOST_BRIDGE_ESMRAMC_TSEG_SZ_MASK ((uint8_t)(0x3 << 1)) 171263cf436SBALATON Zoltan #define MCH_HOST_BRIDGE_ESMRAMC_TSEG_SZ_1MB ((uint8_t)(0x0 << 1)) 172263cf436SBALATON Zoltan #define MCH_HOST_BRIDGE_ESMRAMC_TSEG_SZ_2MB ((uint8_t)(0x1 << 1)) 173263cf436SBALATON Zoltan #define MCH_HOST_BRIDGE_ESMRAMC_TSEG_SZ_8MB ((uint8_t)(0x2 << 1)) 174263cf436SBALATON Zoltan #define MCH_HOST_BRIDGE_ESMRAMC_T_EN ((uint8_t)1) 17577447524SGerd Hoffmann #define MCH_HOST_BRIDGE_ESMRAMC_DEFAULT \ 17677447524SGerd Hoffmann (MCH_HOST_BRIDGE_ESMRAMC_SM_CACHE | \ 17777447524SGerd Hoffmann MCH_HOST_BRIDGE_ESMRAMC_SM_L1 | \ 17877447524SGerd Hoffmann MCH_HOST_BRIDGE_ESMRAMC_SM_L2) 179b66a67d7SGerd Hoffmann #define MCH_HOST_BRIDGE_ESMRAMC_WMASK \ 180b66a67d7SGerd Hoffmann (MCH_HOST_BRIDGE_ESMRAMC_H_SMRAME | \ 181b66a67d7SGerd Hoffmann MCH_HOST_BRIDGE_ESMRAMC_TSEG_SZ_MASK | \ 182b66a67d7SGerd Hoffmann MCH_HOST_BRIDGE_ESMRAMC_T_EN) 18368c77acfSGerd Hoffmann #define MCH_HOST_BRIDGE_ESMRAMC_WMASK_LCK 0 184df2d8b3eSIsaku Yamahata 185df2d8b3eSIsaku Yamahata /* D1:F0 PCIE* port*/ 186df2d8b3eSIsaku Yamahata #define MCH_PCIE_DEV 1 187df2d8b3eSIsaku Yamahata #define MCH_PCIE_FUNC 0 188df2d8b3eSIsaku Yamahata 1896f1426abSMichael S. Tsirkin uint64_t mch_mcfg_base(void); 1906f1426abSMichael S. Tsirkin 191cfc13df4SPeter Xu /* 1925bb8590dSStefan Weil * Arbitrary but unique BNF number for IOAPIC device. 193cfc13df4SPeter Xu * 194cfc13df4SPeter Xu * TODO: make sure there would have no conflict with real PCI bus 195cfc13df4SPeter Xu */ 196cfc13df4SPeter Xu #define Q35_PSEUDO_BUS_PLATFORM (0xff) 197cfc13df4SPeter Xu #define Q35_PSEUDO_DEVFN_IOAPIC (0x00) 198cfc13df4SPeter Xu 199df2d8b3eSIsaku Yamahata #endif /* HW_Q35_H */ 200