xref: /qemu/include/hw/pci-host/q35.h (revision 577aa4895a138782d426be592aa3c41ecf28a2c2)
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 
250d09e41aSPaolo Bonzini #include "hw/isa/isa.h"
2683c9f4caSPaolo Bonzini #include "hw/sysbus.h"
270d09e41aSPaolo Bonzini #include "hw/i386/pc.h"
280d09e41aSPaolo Bonzini #include "hw/isa/apm.h"
2983c9f4caSPaolo Bonzini #include "hw/pci/pci.h"
3083c9f4caSPaolo Bonzini #include "hw/pci/pcie_host.h"
310d09e41aSPaolo Bonzini #include "hw/acpi/acpi.h"
320d09e41aSPaolo Bonzini #include "hw/acpi/ich9.h"
330d09e41aSPaolo Bonzini #include "hw/pci-host/pam.h"
34a52a7fdfSLe Tan #include "hw/i386/intel_iommu.h"
35f404220eSIgor Mammedov #include "qemu/units.h"
36*577aa489SPhilippe Mathieu-Daudé #include "qemu/range.h"
37df2d8b3eSIsaku Yamahata 
38df2d8b3eSIsaku Yamahata #define TYPE_Q35_HOST_DEVICE "q35-pcihost"
39df2d8b3eSIsaku Yamahata #define Q35_HOST_DEVICE(obj) \
40df2d8b3eSIsaku Yamahata      OBJECT_CHECK(Q35PCIHost, (obj), TYPE_Q35_HOST_DEVICE)
41df2d8b3eSIsaku Yamahata 
42df2d8b3eSIsaku Yamahata #define TYPE_MCH_PCI_DEVICE "mch"
43df2d8b3eSIsaku Yamahata #define MCH_PCI_DEVICE(obj) \
44df2d8b3eSIsaku Yamahata      OBJECT_CHECK(MCHPCIState, (obj), TYPE_MCH_PCI_DEVICE)
45df2d8b3eSIsaku Yamahata 
46df2d8b3eSIsaku Yamahata typedef struct MCHPCIState {
47ce88812fSHu Tao     /*< private >*/
48ce88812fSHu Tao     PCIDevice parent_obj;
49ce88812fSHu Tao     /*< public >*/
50ce88812fSHu Tao 
51df2d8b3eSIsaku Yamahata     MemoryRegion *ram_memory;
52df2d8b3eSIsaku Yamahata     MemoryRegion *pci_address_space;
53df2d8b3eSIsaku Yamahata     MemoryRegion *system_memory;
54df2d8b3eSIsaku Yamahata     MemoryRegion *address_space_io;
55df2d8b3eSIsaku Yamahata     PAMMemoryRegion pam_regions[13];
5664130fa4SPaolo Bonzini     MemoryRegion smram_region, open_high_smram;
5764130fa4SPaolo Bonzini     MemoryRegion smram, low_smram, high_smram;
58bafc90bdSGerd Hoffmann     MemoryRegion tseg_blackhole, tseg_window;
59f404220eSIgor Mammedov     MemoryRegion smbase_blackhole, smbase_window;
60f404220eSIgor Mammedov     bool has_smram_at_smbase;
6101c9742dSMarkus Armbruster     Range pci_hole;
62401f2f3eSEfimov Vasily     uint64_t below_4g_mem_size;
63401f2f3eSEfimov Vasily     uint64_t above_4g_mem_size;
6439848901SIgor Mammedov     uint64_t pci_hole64_size;
6504c7d8b8SCole Robinson     uint32_t short_root_bus;
662f295167SLaszlo Ersek     uint16_t ext_tseg_mbytes;
67df2d8b3eSIsaku Yamahata } MCHPCIState;
68df2d8b3eSIsaku Yamahata 
69df2d8b3eSIsaku Yamahata typedef struct Q35PCIHost {
70ce88812fSHu Tao     /*< private >*/
71ce88812fSHu Tao     PCIExpressHost parent_obj;
72ce88812fSHu Tao     /*< public >*/
73ce88812fSHu Tao 
749fa99d25SMarcel Apfelbaum     bool pci_hole64_fix;
75df2d8b3eSIsaku Yamahata     MCHPCIState mch;
76df2d8b3eSIsaku Yamahata } Q35PCIHost;
77df2d8b3eSIsaku Yamahata 
78df2d8b3eSIsaku Yamahata #define Q35_MASK(bit, ms_bit, ls_bit) \
79df2d8b3eSIsaku Yamahata ((uint##bit##_t)(((1ULL << ((ms_bit) + 1)) - 1) & ~((1ULL << ls_bit) - 1)))
80df2d8b3eSIsaku Yamahata 
81df2d8b3eSIsaku Yamahata /*
82df2d8b3eSIsaku Yamahata  * gmch part
83df2d8b3eSIsaku Yamahata  */
84df2d8b3eSIsaku Yamahata 
85401f2f3eSEfimov Vasily #define MCH_HOST_PROP_RAM_MEM "ram-mem"
86401f2f3eSEfimov Vasily #define MCH_HOST_PROP_PCI_MEM "pci-mem"
87401f2f3eSEfimov Vasily #define MCH_HOST_PROP_SYSTEM_MEM "system-mem"
88401f2f3eSEfimov Vasily #define MCH_HOST_PROP_IO_MEM "io-mem"
89401f2f3eSEfimov Vasily 
90df2d8b3eSIsaku Yamahata /* PCI configuration */
91df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE                        "MCH"
92df2d8b3eSIsaku Yamahata 
93df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_CONFIG_ADDR            0xcf8
94df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_CONFIG_DATA            0xcfc
95df2d8b3eSIsaku Yamahata 
96df2d8b3eSIsaku Yamahata /* D0:F0 configuration space */
97451f7846SRichard W.M. Jones #define MCH_HOST_BRIDGE_REVISION_DEFAULT       0x0
98df2d8b3eSIsaku Yamahata 
992f295167SLaszlo Ersek #define MCH_HOST_BRIDGE_EXT_TSEG_MBYTES        0x50
1002f295167SLaszlo Ersek #define MCH_HOST_BRIDGE_EXT_TSEG_MBYTES_SIZE   2
1012f295167SLaszlo Ersek #define MCH_HOST_BRIDGE_EXT_TSEG_MBYTES_QUERY  0xffff
1022f295167SLaszlo Ersek #define MCH_HOST_BRIDGE_EXT_TSEG_MBYTES_MAX    0xfff
1032f295167SLaszlo Ersek 
104f404220eSIgor Mammedov #define MCH_HOST_BRIDGE_SMBASE_SIZE            (128 * KiB)
105f404220eSIgor Mammedov #define MCH_HOST_BRIDGE_SMBASE_ADDR            0x30000
106f404220eSIgor Mammedov #define MCH_HOST_BRIDGE_F_SMBASE               0x9c
107f404220eSIgor Mammedov #define MCH_HOST_BRIDGE_F_SMBASE_QUERY         0xff
108f404220eSIgor Mammedov #define MCH_HOST_BRIDGE_F_SMBASE_IN_RAM        0x01
109f404220eSIgor Mammedov #define MCH_HOST_BRIDGE_F_SMBASE_LCK           0x02
110f404220eSIgor Mammedov 
111df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR               0x60    /* 64bit register */
112df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_SIZE          8       /* 64bit register */
113df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_DEFAULT       0xb0000000
1143459a625SMichael S. Tsirkin #define MCH_HOST_BRIDGE_PCIEXBAR_MAX           (0x10000000) /* 256M */
115df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_ADMSK         Q35_MASK(64, 35, 28)
116df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_128ADMSK      ((uint64_t)(1 << 26))
117df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_64ADMSK       ((uint64_t)(1 << 25))
118df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_LENGTH_MASK   ((uint64_t)(0x3 << 1))
119df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_LENGTH_256M   ((uint64_t)(0x0 << 1))
120df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_LENGTH_128M   ((uint64_t)(0x1 << 1))
121df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_LENGTH_64M    ((uint64_t)(0x2 << 1))
122df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_LENGTH_RVD    ((uint64_t)(0x3 << 1))
123df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAREN             ((uint64_t)1)
124df2d8b3eSIsaku Yamahata 
125df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_NB                 7
126df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_SIZE               7
127df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM0                   0x90
128df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_BIOS_AREA          0xf0000
129df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_AREA_SIZE          0x10000 /* 16KB */
130df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM1                   0x91
131df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_EXPAN_AREA         0xc0000
132df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_EXPAN_SIZE         0x04000
133df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM2                   0x92
134df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM3                   0x93
135df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM4                   0x94
136df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_EXBIOS_AREA        0xe0000
137df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_EXBIOS_SIZE        0x04000
138df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM5                   0x95
139df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM6                   0x96
140df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_WE_HI              ((uint8_t)(0x2 << 4))
141df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_RE_HI              ((uint8_t)(0x1 << 4))
142df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_HI_MASK            ((uint8_t)(0x3 << 4))
143df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_WE_LO              ((uint8_t)0x2)
144df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_RE_LO              ((uint8_t)0x1)
145df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_LO_MASK            ((uint8_t)0x3)
146df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_WE                 ((uint8_t)0x2)
147df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_RE                 ((uint8_t)0x1)
148df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_MASK               ((uint8_t)0x3)
149df2d8b3eSIsaku Yamahata 
150263cf436SBALATON Zoltan #define MCH_HOST_BRIDGE_SMRAM                  0x9d
15164130fa4SPaolo Bonzini #define MCH_HOST_BRIDGE_SMRAM_SIZE             2
152df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_SMRAM_D_OPEN           ((uint8_t)(1 << 6))
153df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_SMRAM_D_CLS            ((uint8_t)(1 << 5))
154df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_SMRAM_D_LCK            ((uint8_t)(1 << 4))
155df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_SMRAM_G_SMRAME         ((uint8_t)(1 << 3))
156df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_SMRAM_C_BASE_SEG_MASK  ((uint8_t)0x7)
157df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_SMRAM_C_BASE_SEG       ((uint8_t)0x2)  /* hardwired to b010 */
158df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_SMRAM_C_BASE           0xa0000
159df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_SMRAM_C_END            0xc0000
160df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_SMRAM_C_SIZE           0x20000
161df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_UPPER_SYSTEM_BIOS_END  0x100000
16277447524SGerd Hoffmann #define MCH_HOST_BRIDGE_SMRAM_DEFAULT           \
16377447524SGerd Hoffmann     MCH_HOST_BRIDGE_SMRAM_C_BASE_SEG
164b66a67d7SGerd Hoffmann #define MCH_HOST_BRIDGE_SMRAM_WMASK             \
165b66a67d7SGerd Hoffmann     (MCH_HOST_BRIDGE_SMRAM_D_OPEN |             \
166b66a67d7SGerd Hoffmann      MCH_HOST_BRIDGE_SMRAM_D_CLS |              \
167b66a67d7SGerd Hoffmann      MCH_HOST_BRIDGE_SMRAM_D_LCK |              \
168b66a67d7SGerd Hoffmann      MCH_HOST_BRIDGE_SMRAM_G_SMRAME)
16968c77acfSGerd Hoffmann #define MCH_HOST_BRIDGE_SMRAM_WMASK_LCK         \
17068c77acfSGerd Hoffmann     MCH_HOST_BRIDGE_SMRAM_D_CLS
171df2d8b3eSIsaku Yamahata 
172df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_ESMRAMC                0x9e
17364130fa4SPaolo Bonzini #define MCH_HOST_BRIDGE_ESMRAMC_H_SMRAME       ((uint8_t)(1 << 7))
17464130fa4SPaolo Bonzini #define MCH_HOST_BRIDGE_ESMRAMC_E_SMERR        ((uint8_t)(1 << 6))
17564130fa4SPaolo Bonzini #define MCH_HOST_BRIDGE_ESMRAMC_SM_CACHE       ((uint8_t)(1 << 5))
17664130fa4SPaolo Bonzini #define MCH_HOST_BRIDGE_ESMRAMC_SM_L1          ((uint8_t)(1 << 4))
17764130fa4SPaolo Bonzini #define MCH_HOST_BRIDGE_ESMRAMC_SM_L2          ((uint8_t)(1 << 3))
178263cf436SBALATON Zoltan #define MCH_HOST_BRIDGE_ESMRAMC_TSEG_SZ_MASK   ((uint8_t)(0x3 << 1))
179263cf436SBALATON Zoltan #define MCH_HOST_BRIDGE_ESMRAMC_TSEG_SZ_1MB    ((uint8_t)(0x0 << 1))
180263cf436SBALATON Zoltan #define MCH_HOST_BRIDGE_ESMRAMC_TSEG_SZ_2MB    ((uint8_t)(0x1 << 1))
181263cf436SBALATON Zoltan #define MCH_HOST_BRIDGE_ESMRAMC_TSEG_SZ_8MB    ((uint8_t)(0x2 << 1))
182263cf436SBALATON Zoltan #define MCH_HOST_BRIDGE_ESMRAMC_T_EN           ((uint8_t)1)
18377447524SGerd Hoffmann #define MCH_HOST_BRIDGE_ESMRAMC_DEFAULT \
18477447524SGerd Hoffmann     (MCH_HOST_BRIDGE_ESMRAMC_SM_CACHE | \
18577447524SGerd Hoffmann      MCH_HOST_BRIDGE_ESMRAMC_SM_L1 |    \
18677447524SGerd Hoffmann      MCH_HOST_BRIDGE_ESMRAMC_SM_L2)
187b66a67d7SGerd Hoffmann #define MCH_HOST_BRIDGE_ESMRAMC_WMASK               \
188b66a67d7SGerd Hoffmann     (MCH_HOST_BRIDGE_ESMRAMC_H_SMRAME |             \
189b66a67d7SGerd Hoffmann      MCH_HOST_BRIDGE_ESMRAMC_TSEG_SZ_MASK |         \
190b66a67d7SGerd Hoffmann      MCH_HOST_BRIDGE_ESMRAMC_T_EN)
19168c77acfSGerd Hoffmann #define MCH_HOST_BRIDGE_ESMRAMC_WMASK_LCK     0
192df2d8b3eSIsaku Yamahata 
193df2d8b3eSIsaku Yamahata /* D1:F0 PCIE* port*/
194df2d8b3eSIsaku Yamahata #define MCH_PCIE_DEV                           1
195df2d8b3eSIsaku Yamahata #define MCH_PCIE_FUNC                          0
196df2d8b3eSIsaku Yamahata 
1976f1426abSMichael S. Tsirkin uint64_t mch_mcfg_base(void);
1986f1426abSMichael S. Tsirkin 
199cfc13df4SPeter Xu /*
2005bb8590dSStefan Weil  * Arbitrary but unique BNF number for IOAPIC device.
201cfc13df4SPeter Xu  *
202cfc13df4SPeter Xu  * TODO: make sure there would have no conflict with real PCI bus
203cfc13df4SPeter Xu  */
204cfc13df4SPeter Xu #define Q35_PSEUDO_BUS_PLATFORM         (0xff)
205cfc13df4SPeter Xu #define Q35_PSEUDO_DEVFN_IOAPIC         (0x00)
206cfc13df4SPeter Xu 
207df2d8b3eSIsaku Yamahata #endif /* HW_Q35_H */
208