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 * 18df2d8b3eSIsaku Yamahata * You should have received a copy of the GNU Lesser General Public 19df2d8b3eSIsaku Yamahata * License along with this library; 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 2583c9f4caSPaolo Bonzini #include "hw/hw.h" 260d09e41aSPaolo Bonzini #include "hw/isa/isa.h" 2783c9f4caSPaolo Bonzini #include "hw/sysbus.h" 280d09e41aSPaolo Bonzini #include "hw/i386/pc.h" 290d09e41aSPaolo Bonzini #include "hw/isa/apm.h" 3083c9f4caSPaolo Bonzini #include "hw/pci/pci.h" 3183c9f4caSPaolo Bonzini #include "hw/pci/pcie_host.h" 320d09e41aSPaolo Bonzini #include "hw/acpi/acpi.h" 330d09e41aSPaolo Bonzini #include "hw/acpi/ich9.h" 340d09e41aSPaolo Bonzini #include "hw/pci-host/pam.h" 35a52a7fdfSLe Tan #include "hw/i386/intel_iommu.h" 36df2d8b3eSIsaku Yamahata 37df2d8b3eSIsaku Yamahata #define TYPE_Q35_HOST_DEVICE "q35-pcihost" 38df2d8b3eSIsaku Yamahata #define Q35_HOST_DEVICE(obj) \ 39df2d8b3eSIsaku Yamahata OBJECT_CHECK(Q35PCIHost, (obj), TYPE_Q35_HOST_DEVICE) 40df2d8b3eSIsaku Yamahata 41df2d8b3eSIsaku Yamahata #define TYPE_MCH_PCI_DEVICE "mch" 42df2d8b3eSIsaku Yamahata #define MCH_PCI_DEVICE(obj) \ 43df2d8b3eSIsaku Yamahata OBJECT_CHECK(MCHPCIState, (obj), TYPE_MCH_PCI_DEVICE) 44df2d8b3eSIsaku Yamahata 45df2d8b3eSIsaku Yamahata typedef struct MCHPCIState { 46ce88812fSHu Tao /*< private >*/ 47ce88812fSHu Tao PCIDevice parent_obj; 48ce88812fSHu Tao /*< public >*/ 49ce88812fSHu Tao 50df2d8b3eSIsaku Yamahata MemoryRegion *ram_memory; 51df2d8b3eSIsaku Yamahata MemoryRegion *pci_address_space; 52df2d8b3eSIsaku Yamahata MemoryRegion *system_memory; 53df2d8b3eSIsaku Yamahata MemoryRegion *address_space_io; 54df2d8b3eSIsaku Yamahata PAMMemoryRegion pam_regions[13]; 5564130fa4SPaolo Bonzini MemoryRegion smram_region, open_high_smram; 5664130fa4SPaolo Bonzini MemoryRegion smram, low_smram, high_smram; 5739848901SIgor Mammedov PcPciInfo pci_info; 58df2d8b3eSIsaku Yamahata ram_addr_t below_4g_mem_size; 59df2d8b3eSIsaku Yamahata ram_addr_t above_4g_mem_size; 6039848901SIgor Mammedov uint64_t pci_hole64_size; 613459a625SMichael S. Tsirkin PcGuestInfo *guest_info; 6204c7d8b8SCole Robinson uint32_t short_root_bus; 63a52a7fdfSLe Tan IntelIOMMUState *iommu; 64df2d8b3eSIsaku Yamahata } MCHPCIState; 65df2d8b3eSIsaku Yamahata 66df2d8b3eSIsaku Yamahata typedef struct Q35PCIHost { 67ce88812fSHu Tao /*< private >*/ 68ce88812fSHu Tao PCIExpressHost parent_obj; 69ce88812fSHu Tao /*< public >*/ 70ce88812fSHu Tao 71df2d8b3eSIsaku Yamahata MCHPCIState mch; 72df2d8b3eSIsaku Yamahata } Q35PCIHost; 73df2d8b3eSIsaku Yamahata 74df2d8b3eSIsaku Yamahata #define Q35_MASK(bit, ms_bit, ls_bit) \ 75df2d8b3eSIsaku Yamahata ((uint##bit##_t)(((1ULL << ((ms_bit) + 1)) - 1) & ~((1ULL << ls_bit) - 1))) 76df2d8b3eSIsaku Yamahata 77df2d8b3eSIsaku Yamahata /* 78df2d8b3eSIsaku Yamahata * gmch part 79df2d8b3eSIsaku Yamahata */ 80df2d8b3eSIsaku Yamahata 81df2d8b3eSIsaku Yamahata /* PCI configuration */ 82df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE "MCH" 83df2d8b3eSIsaku Yamahata 84df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_CONFIG_ADDR 0xcf8 85df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_CONFIG_DATA 0xcfc 86df2d8b3eSIsaku Yamahata 87df2d8b3eSIsaku Yamahata /* D0:F0 configuration space */ 88451f7846SRichard W.M. Jones #define MCH_HOST_BRIDGE_REVISION_DEFAULT 0x0 89df2d8b3eSIsaku Yamahata 90df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR 0x60 /* 64bit register */ 91df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_SIZE 8 /* 64bit register */ 92df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_DEFAULT 0xb0000000 933459a625SMichael S. Tsirkin #define MCH_HOST_BRIDGE_PCIEXBAR_MAX (0x10000000) /* 256M */ 94df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_ADMSK Q35_MASK(64, 35, 28) 95df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_128ADMSK ((uint64_t)(1 << 26)) 96df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_64ADMSK ((uint64_t)(1 << 25)) 97df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_LENGTH_MASK ((uint64_t)(0x3 << 1)) 98df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_LENGTH_256M ((uint64_t)(0x0 << 1)) 99df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_LENGTH_128M ((uint64_t)(0x1 << 1)) 100df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_LENGTH_64M ((uint64_t)(0x2 << 1)) 101df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_LENGTH_RVD ((uint64_t)(0x3 << 1)) 102df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAREN ((uint64_t)1) 103df2d8b3eSIsaku Yamahata 104df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_NB 7 105df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_SIZE 7 106df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM0 0x90 107df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_BIOS_AREA 0xf0000 108df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_AREA_SIZE 0x10000 /* 16KB */ 109df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM1 0x91 110df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_EXPAN_AREA 0xc0000 111df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_EXPAN_SIZE 0x04000 112df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM2 0x92 113df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM3 0x93 114df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM4 0x94 115df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_EXBIOS_AREA 0xe0000 116df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_EXBIOS_SIZE 0x04000 117df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM5 0x95 118df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM6 0x96 119df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_WE_HI ((uint8_t)(0x2 << 4)) 120df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_RE_HI ((uint8_t)(0x1 << 4)) 121df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_HI_MASK ((uint8_t)(0x3 << 4)) 122df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_WE_LO ((uint8_t)0x2) 123df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_RE_LO ((uint8_t)0x1) 124df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_LO_MASK ((uint8_t)0x3) 125df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_WE ((uint8_t)0x2) 126df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_RE ((uint8_t)0x1) 127df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_MASK ((uint8_t)0x3) 128df2d8b3eSIsaku Yamahata 129263cf436SBALATON Zoltan #define MCH_HOST_BRIDGE_SMRAM 0x9d 13064130fa4SPaolo Bonzini #define MCH_HOST_BRIDGE_SMRAM_SIZE 2 131df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_SMRAM_D_OPEN ((uint8_t)(1 << 6)) 132df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_SMRAM_D_CLS ((uint8_t)(1 << 5)) 133df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_SMRAM_D_LCK ((uint8_t)(1 << 4)) 134df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_SMRAM_G_SMRAME ((uint8_t)(1 << 3)) 135df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_SMRAM_C_BASE_SEG_MASK ((uint8_t)0x7) 136df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_SMRAM_C_BASE_SEG ((uint8_t)0x2) /* hardwired to b010 */ 137df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_SMRAM_C_BASE 0xa0000 138df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_SMRAM_C_END 0xc0000 139df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_SMRAM_C_SIZE 0x20000 140df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_UPPER_SYSTEM_BIOS_END 0x100000 14177447524SGerd Hoffmann #define MCH_HOST_BRIDGE_SMRAM_DEFAULT \ 14277447524SGerd Hoffmann MCH_HOST_BRIDGE_SMRAM_C_BASE_SEG 143*b66a67d7SGerd Hoffmann #define MCH_HOST_BRIDGE_SMRAM_WMASK \ 144*b66a67d7SGerd Hoffmann (MCH_HOST_BRIDGE_SMRAM_D_OPEN | \ 145*b66a67d7SGerd Hoffmann MCH_HOST_BRIDGE_SMRAM_D_CLS | \ 146*b66a67d7SGerd Hoffmann MCH_HOST_BRIDGE_SMRAM_D_LCK | \ 147*b66a67d7SGerd Hoffmann MCH_HOST_BRIDGE_SMRAM_G_SMRAME) 148df2d8b3eSIsaku Yamahata 149df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_ESMRAMC 0x9e 15064130fa4SPaolo Bonzini #define MCH_HOST_BRIDGE_ESMRAMC_H_SMRAME ((uint8_t)(1 << 7)) 15164130fa4SPaolo Bonzini #define MCH_HOST_BRIDGE_ESMRAMC_E_SMERR ((uint8_t)(1 << 6)) 15264130fa4SPaolo Bonzini #define MCH_HOST_BRIDGE_ESMRAMC_SM_CACHE ((uint8_t)(1 << 5)) 15364130fa4SPaolo Bonzini #define MCH_HOST_BRIDGE_ESMRAMC_SM_L1 ((uint8_t)(1 << 4)) 15464130fa4SPaolo Bonzini #define MCH_HOST_BRIDGE_ESMRAMC_SM_L2 ((uint8_t)(1 << 3)) 155263cf436SBALATON Zoltan #define MCH_HOST_BRIDGE_ESMRAMC_TSEG_SZ_MASK ((uint8_t)(0x3 << 1)) 156263cf436SBALATON Zoltan #define MCH_HOST_BRIDGE_ESMRAMC_TSEG_SZ_1MB ((uint8_t)(0x0 << 1)) 157263cf436SBALATON Zoltan #define MCH_HOST_BRIDGE_ESMRAMC_TSEG_SZ_2MB ((uint8_t)(0x1 << 1)) 158263cf436SBALATON Zoltan #define MCH_HOST_BRIDGE_ESMRAMC_TSEG_SZ_8MB ((uint8_t)(0x2 << 1)) 159263cf436SBALATON Zoltan #define MCH_HOST_BRIDGE_ESMRAMC_T_EN ((uint8_t)1) 16077447524SGerd Hoffmann #define MCH_HOST_BRIDGE_ESMRAMC_DEFAULT \ 16177447524SGerd Hoffmann (MCH_HOST_BRIDGE_ESMRAMC_SM_CACHE | \ 16277447524SGerd Hoffmann MCH_HOST_BRIDGE_ESMRAMC_SM_L1 | \ 16377447524SGerd Hoffmann MCH_HOST_BRIDGE_ESMRAMC_SM_L2) 164*b66a67d7SGerd Hoffmann #define MCH_HOST_BRIDGE_ESMRAMC_WMASK \ 165*b66a67d7SGerd Hoffmann (MCH_HOST_BRIDGE_ESMRAMC_H_SMRAME | \ 166*b66a67d7SGerd Hoffmann MCH_HOST_BRIDGE_ESMRAMC_TSEG_SZ_MASK | \ 167*b66a67d7SGerd Hoffmann MCH_HOST_BRIDGE_ESMRAMC_T_EN) 168df2d8b3eSIsaku Yamahata 169df2d8b3eSIsaku Yamahata /* D1:F0 PCIE* port*/ 170df2d8b3eSIsaku Yamahata #define MCH_PCIE_DEV 1 171df2d8b3eSIsaku Yamahata #define MCH_PCIE_FUNC 0 172df2d8b3eSIsaku Yamahata 1736f1426abSMichael S. Tsirkin uint64_t mch_mcfg_base(void); 1746f1426abSMichael S. Tsirkin 175df2d8b3eSIsaku Yamahata #endif /* HW_Q35_H */ 176