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 25edf5ca5dSMarkus 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; 53*b07bf7b7SIsaku Yamahata bool has_smm_ranges; 5401c9742dSMarkus Armbruster Range pci_hole; 55401f2f3eSEfimov Vasily uint64_t below_4g_mem_size; 56401f2f3eSEfimov Vasily uint64_t above_4g_mem_size; 5739848901SIgor Mammedov uint64_t pci_hole64_size; 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 77df2d8b3eSIsaku Yamahata /* PCI configuration */ 78df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE "MCH" 79df2d8b3eSIsaku Yamahata 80df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_CONFIG_ADDR 0xcf8 81df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_CONFIG_DATA 0xcfc 82df2d8b3eSIsaku Yamahata 83df2d8b3eSIsaku Yamahata /* D0:F0 configuration space */ 84451f7846SRichard W.M. Jones #define MCH_HOST_BRIDGE_REVISION_DEFAULT 0x0 85df2d8b3eSIsaku Yamahata 862f295167SLaszlo Ersek #define MCH_HOST_BRIDGE_EXT_TSEG_MBYTES 0x50 872f295167SLaszlo Ersek #define MCH_HOST_BRIDGE_EXT_TSEG_MBYTES_SIZE 2 882f295167SLaszlo Ersek #define MCH_HOST_BRIDGE_EXT_TSEG_MBYTES_QUERY 0xffff 892f295167SLaszlo Ersek #define MCH_HOST_BRIDGE_EXT_TSEG_MBYTES_MAX 0xfff 902f295167SLaszlo Ersek 91f404220eSIgor Mammedov #define MCH_HOST_BRIDGE_SMBASE_SIZE (128 * KiB) 92f404220eSIgor Mammedov #define MCH_HOST_BRIDGE_SMBASE_ADDR 0x30000 93f404220eSIgor Mammedov #define MCH_HOST_BRIDGE_F_SMBASE 0x9c 94f404220eSIgor Mammedov #define MCH_HOST_BRIDGE_F_SMBASE_QUERY 0xff 95f404220eSIgor Mammedov #define MCH_HOST_BRIDGE_F_SMBASE_IN_RAM 0x01 96f404220eSIgor Mammedov #define MCH_HOST_BRIDGE_F_SMBASE_LCK 0x02 97f404220eSIgor Mammedov 98df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR 0x60 /* 64bit register */ 99df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_SIZE 8 /* 64bit register */ 100df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_DEFAULT 0xb0000000 1013459a625SMichael S. Tsirkin #define MCH_HOST_BRIDGE_PCIEXBAR_MAX (0x10000000) /* 256M */ 102df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_ADMSK Q35_MASK(64, 35, 28) 103df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_128ADMSK ((uint64_t)(1 << 26)) 104df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_64ADMSK ((uint64_t)(1 << 25)) 105df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_LENGTH_MASK ((uint64_t)(0x3 << 1)) 106df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_LENGTH_256M ((uint64_t)(0x0 << 1)) 107df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_LENGTH_128M ((uint64_t)(0x1 << 1)) 108df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_LENGTH_64M ((uint64_t)(0x2 << 1)) 109df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_LENGTH_RVD ((uint64_t)(0x3 << 1)) 110df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAREN ((uint64_t)1) 111df2d8b3eSIsaku Yamahata 112df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_NB 7 113df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_SIZE 7 114df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM0 0x90 115df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_BIOS_AREA 0xf0000 116df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_AREA_SIZE 0x10000 /* 16KB */ 117df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM1 0x91 118df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_EXPAN_AREA 0xc0000 119df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_EXPAN_SIZE 0x04000 120df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM2 0x92 121df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM3 0x93 122df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM4 0x94 123df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_EXBIOS_AREA 0xe0000 124df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_EXBIOS_SIZE 0x04000 125df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM5 0x95 126df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM6 0x96 127df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_WE_HI ((uint8_t)(0x2 << 4)) 128df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_RE_HI ((uint8_t)(0x1 << 4)) 129df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_HI_MASK ((uint8_t)(0x3 << 4)) 130df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_WE_LO ((uint8_t)0x2) 131df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_RE_LO ((uint8_t)0x1) 132df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_LO_MASK ((uint8_t)0x3) 133df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_WE ((uint8_t)0x2) 134df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_RE ((uint8_t)0x1) 135df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_MASK ((uint8_t)0x3) 136df2d8b3eSIsaku Yamahata 137263cf436SBALATON Zoltan #define MCH_HOST_BRIDGE_SMRAM 0x9d 13864130fa4SPaolo Bonzini #define MCH_HOST_BRIDGE_SMRAM_SIZE 2 139df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_SMRAM_D_OPEN ((uint8_t)(1 << 6)) 140df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_SMRAM_D_CLS ((uint8_t)(1 << 5)) 141df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_SMRAM_D_LCK ((uint8_t)(1 << 4)) 142df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_SMRAM_G_SMRAME ((uint8_t)(1 << 3)) 143df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_SMRAM_C_BASE_SEG_MASK ((uint8_t)0x7) 144df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_SMRAM_C_BASE_SEG ((uint8_t)0x2) /* hardwired to b010 */ 145df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_SMRAM_C_BASE 0xa0000 146df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_SMRAM_C_END 0xc0000 147df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_SMRAM_C_SIZE 0x20000 148df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_UPPER_SYSTEM_BIOS_END 0x100000 14977447524SGerd Hoffmann #define MCH_HOST_BRIDGE_SMRAM_DEFAULT \ 15077447524SGerd Hoffmann MCH_HOST_BRIDGE_SMRAM_C_BASE_SEG 151b66a67d7SGerd Hoffmann #define MCH_HOST_BRIDGE_SMRAM_WMASK \ 152b66a67d7SGerd Hoffmann (MCH_HOST_BRIDGE_SMRAM_D_OPEN | \ 153b66a67d7SGerd Hoffmann MCH_HOST_BRIDGE_SMRAM_D_CLS | \ 154b66a67d7SGerd Hoffmann MCH_HOST_BRIDGE_SMRAM_D_LCK | \ 155b66a67d7SGerd Hoffmann MCH_HOST_BRIDGE_SMRAM_G_SMRAME) 15668c77acfSGerd Hoffmann #define MCH_HOST_BRIDGE_SMRAM_WMASK_LCK \ 15768c77acfSGerd Hoffmann MCH_HOST_BRIDGE_SMRAM_D_CLS 158df2d8b3eSIsaku Yamahata 159df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_ESMRAMC 0x9e 16064130fa4SPaolo Bonzini #define MCH_HOST_BRIDGE_ESMRAMC_H_SMRAME ((uint8_t)(1 << 7)) 16164130fa4SPaolo Bonzini #define MCH_HOST_BRIDGE_ESMRAMC_E_SMERR ((uint8_t)(1 << 6)) 16264130fa4SPaolo Bonzini #define MCH_HOST_BRIDGE_ESMRAMC_SM_CACHE ((uint8_t)(1 << 5)) 16364130fa4SPaolo Bonzini #define MCH_HOST_BRIDGE_ESMRAMC_SM_L1 ((uint8_t)(1 << 4)) 16464130fa4SPaolo Bonzini #define MCH_HOST_BRIDGE_ESMRAMC_SM_L2 ((uint8_t)(1 << 3)) 165263cf436SBALATON Zoltan #define MCH_HOST_BRIDGE_ESMRAMC_TSEG_SZ_MASK ((uint8_t)(0x3 << 1)) 166263cf436SBALATON Zoltan #define MCH_HOST_BRIDGE_ESMRAMC_TSEG_SZ_1MB ((uint8_t)(0x0 << 1)) 167263cf436SBALATON Zoltan #define MCH_HOST_BRIDGE_ESMRAMC_TSEG_SZ_2MB ((uint8_t)(0x1 << 1)) 168263cf436SBALATON Zoltan #define MCH_HOST_BRIDGE_ESMRAMC_TSEG_SZ_8MB ((uint8_t)(0x2 << 1)) 169263cf436SBALATON Zoltan #define MCH_HOST_BRIDGE_ESMRAMC_T_EN ((uint8_t)1) 17077447524SGerd Hoffmann #define MCH_HOST_BRIDGE_ESMRAMC_DEFAULT \ 17177447524SGerd Hoffmann (MCH_HOST_BRIDGE_ESMRAMC_SM_CACHE | \ 17277447524SGerd Hoffmann MCH_HOST_BRIDGE_ESMRAMC_SM_L1 | \ 17377447524SGerd Hoffmann MCH_HOST_BRIDGE_ESMRAMC_SM_L2) 174b66a67d7SGerd Hoffmann #define MCH_HOST_BRIDGE_ESMRAMC_WMASK \ 175b66a67d7SGerd Hoffmann (MCH_HOST_BRIDGE_ESMRAMC_H_SMRAME | \ 176b66a67d7SGerd Hoffmann MCH_HOST_BRIDGE_ESMRAMC_TSEG_SZ_MASK | \ 177b66a67d7SGerd Hoffmann MCH_HOST_BRIDGE_ESMRAMC_T_EN) 17868c77acfSGerd Hoffmann #define MCH_HOST_BRIDGE_ESMRAMC_WMASK_LCK 0 179df2d8b3eSIsaku Yamahata 180df2d8b3eSIsaku Yamahata /* D1:F0 PCIE* port*/ 181df2d8b3eSIsaku Yamahata #define MCH_PCIE_DEV 1 182df2d8b3eSIsaku Yamahata #define MCH_PCIE_FUNC 0 183df2d8b3eSIsaku Yamahata 184cfc13df4SPeter Xu /* 1855bb8590dSStefan Weil * Arbitrary but unique BNF number for IOAPIC device. 186cfc13df4SPeter Xu * 187cfc13df4SPeter Xu * TODO: make sure there would have no conflict with real PCI bus 188cfc13df4SPeter Xu */ 189cfc13df4SPeter Xu #define Q35_PSEUDO_BUS_PLATFORM (0xff) 190cfc13df4SPeter Xu #define Q35_PSEUDO_DEVFN_IOAPIC (0x00) 191cfc13df4SPeter Xu 192df2d8b3eSIsaku Yamahata #endif /* HW_Q35_H */ 193