xref: /qemu/include/hw/pci-host/q35.h (revision 5bb8590d376094ea7d28fc54d7ab0c1f22906f03)
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;
57bafc90bdSGerd Hoffmann     MemoryRegion tseg_blackhole, tseg_window;
5801c9742dSMarkus Armbruster     Range pci_hole;
59401f2f3eSEfimov Vasily     uint64_t below_4g_mem_size;
60401f2f3eSEfimov Vasily     uint64_t above_4g_mem_size;
6139848901SIgor Mammedov     uint64_t pci_hole64_size;
6204c7d8b8SCole Robinson     uint32_t short_root_bus;
63df2d8b3eSIsaku Yamahata } MCHPCIState;
64df2d8b3eSIsaku Yamahata 
65df2d8b3eSIsaku Yamahata typedef struct Q35PCIHost {
66ce88812fSHu Tao     /*< private >*/
67ce88812fSHu Tao     PCIExpressHost parent_obj;
68ce88812fSHu Tao     /*< public >*/
69ce88812fSHu Tao 
70df2d8b3eSIsaku Yamahata     MCHPCIState mch;
71df2d8b3eSIsaku Yamahata } Q35PCIHost;
72df2d8b3eSIsaku Yamahata 
73df2d8b3eSIsaku Yamahata #define Q35_MASK(bit, ms_bit, ls_bit) \
74df2d8b3eSIsaku Yamahata ((uint##bit##_t)(((1ULL << ((ms_bit) + 1)) - 1) & ~((1ULL << ls_bit) - 1)))
75df2d8b3eSIsaku Yamahata 
76df2d8b3eSIsaku Yamahata /*
77df2d8b3eSIsaku Yamahata  * gmch part
78df2d8b3eSIsaku Yamahata  */
79df2d8b3eSIsaku Yamahata 
80401f2f3eSEfimov Vasily #define MCH_HOST_PROP_RAM_MEM "ram-mem"
81401f2f3eSEfimov Vasily #define MCH_HOST_PROP_PCI_MEM "pci-mem"
82401f2f3eSEfimov Vasily #define MCH_HOST_PROP_SYSTEM_MEM "system-mem"
83401f2f3eSEfimov Vasily #define MCH_HOST_PROP_IO_MEM "io-mem"
84401f2f3eSEfimov Vasily 
85df2d8b3eSIsaku Yamahata /* PCI configuration */
86df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE                        "MCH"
87df2d8b3eSIsaku Yamahata 
88df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_CONFIG_ADDR            0xcf8
89df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_CONFIG_DATA            0xcfc
90df2d8b3eSIsaku Yamahata 
91df2d8b3eSIsaku Yamahata /* D0:F0 configuration space */
92451f7846SRichard W.M. Jones #define MCH_HOST_BRIDGE_REVISION_DEFAULT       0x0
93df2d8b3eSIsaku Yamahata 
94df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR               0x60    /* 64bit register */
95df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_SIZE          8       /* 64bit register */
96df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_DEFAULT       0xb0000000
973459a625SMichael S. Tsirkin #define MCH_HOST_BRIDGE_PCIEXBAR_MAX           (0x10000000) /* 256M */
98df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_ADMSK         Q35_MASK(64, 35, 28)
99df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_128ADMSK      ((uint64_t)(1 << 26))
100df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_64ADMSK       ((uint64_t)(1 << 25))
101df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_LENGTH_MASK   ((uint64_t)(0x3 << 1))
102df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_LENGTH_256M   ((uint64_t)(0x0 << 1))
103df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_LENGTH_128M   ((uint64_t)(0x1 << 1))
104df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_LENGTH_64M    ((uint64_t)(0x2 << 1))
105df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAR_LENGTH_RVD    ((uint64_t)(0x3 << 1))
106df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PCIEXBAREN             ((uint64_t)1)
107df2d8b3eSIsaku Yamahata 
108df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_NB                 7
109df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_SIZE               7
110df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM0                   0x90
111df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_BIOS_AREA          0xf0000
112df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_AREA_SIZE          0x10000 /* 16KB */
113df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM1                   0x91
114df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_EXPAN_AREA         0xc0000
115df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_EXPAN_SIZE         0x04000
116df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM2                   0x92
117df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM3                   0x93
118df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM4                   0x94
119df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_EXBIOS_AREA        0xe0000
120df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_EXBIOS_SIZE        0x04000
121df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM5                   0x95
122df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM6                   0x96
123df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_WE_HI              ((uint8_t)(0x2 << 4))
124df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_RE_HI              ((uint8_t)(0x1 << 4))
125df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_HI_MASK            ((uint8_t)(0x3 << 4))
126df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_WE_LO              ((uint8_t)0x2)
127df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_RE_LO              ((uint8_t)0x1)
128df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_LO_MASK            ((uint8_t)0x3)
129df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_WE                 ((uint8_t)0x2)
130df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_RE                 ((uint8_t)0x1)
131df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_PAM_MASK               ((uint8_t)0x3)
132df2d8b3eSIsaku Yamahata 
133263cf436SBALATON Zoltan #define MCH_HOST_BRIDGE_SMRAM                  0x9d
13464130fa4SPaolo Bonzini #define MCH_HOST_BRIDGE_SMRAM_SIZE             2
135df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_SMRAM_D_OPEN           ((uint8_t)(1 << 6))
136df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_SMRAM_D_CLS            ((uint8_t)(1 << 5))
137df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_SMRAM_D_LCK            ((uint8_t)(1 << 4))
138df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_SMRAM_G_SMRAME         ((uint8_t)(1 << 3))
139df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_SMRAM_C_BASE_SEG_MASK  ((uint8_t)0x7)
140df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_SMRAM_C_BASE_SEG       ((uint8_t)0x2)  /* hardwired to b010 */
141df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_SMRAM_C_BASE           0xa0000
142df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_SMRAM_C_END            0xc0000
143df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_SMRAM_C_SIZE           0x20000
144df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_UPPER_SYSTEM_BIOS_END  0x100000
14577447524SGerd Hoffmann #define MCH_HOST_BRIDGE_SMRAM_DEFAULT           \
14677447524SGerd Hoffmann     MCH_HOST_BRIDGE_SMRAM_C_BASE_SEG
147b66a67d7SGerd Hoffmann #define MCH_HOST_BRIDGE_SMRAM_WMASK             \
148b66a67d7SGerd Hoffmann     (MCH_HOST_BRIDGE_SMRAM_D_OPEN |             \
149b66a67d7SGerd Hoffmann      MCH_HOST_BRIDGE_SMRAM_D_CLS |              \
150b66a67d7SGerd Hoffmann      MCH_HOST_BRIDGE_SMRAM_D_LCK |              \
151b66a67d7SGerd Hoffmann      MCH_HOST_BRIDGE_SMRAM_G_SMRAME)
15268c77acfSGerd Hoffmann #define MCH_HOST_BRIDGE_SMRAM_WMASK_LCK         \
15368c77acfSGerd Hoffmann     MCH_HOST_BRIDGE_SMRAM_D_CLS
154df2d8b3eSIsaku Yamahata 
155df2d8b3eSIsaku Yamahata #define MCH_HOST_BRIDGE_ESMRAMC                0x9e
15664130fa4SPaolo Bonzini #define MCH_HOST_BRIDGE_ESMRAMC_H_SMRAME       ((uint8_t)(1 << 7))
15764130fa4SPaolo Bonzini #define MCH_HOST_BRIDGE_ESMRAMC_E_SMERR        ((uint8_t)(1 << 6))
15864130fa4SPaolo Bonzini #define MCH_HOST_BRIDGE_ESMRAMC_SM_CACHE       ((uint8_t)(1 << 5))
15964130fa4SPaolo Bonzini #define MCH_HOST_BRIDGE_ESMRAMC_SM_L1          ((uint8_t)(1 << 4))
16064130fa4SPaolo Bonzini #define MCH_HOST_BRIDGE_ESMRAMC_SM_L2          ((uint8_t)(1 << 3))
161263cf436SBALATON Zoltan #define MCH_HOST_BRIDGE_ESMRAMC_TSEG_SZ_MASK   ((uint8_t)(0x3 << 1))
162263cf436SBALATON Zoltan #define MCH_HOST_BRIDGE_ESMRAMC_TSEG_SZ_1MB    ((uint8_t)(0x0 << 1))
163263cf436SBALATON Zoltan #define MCH_HOST_BRIDGE_ESMRAMC_TSEG_SZ_2MB    ((uint8_t)(0x1 << 1))
164263cf436SBALATON Zoltan #define MCH_HOST_BRIDGE_ESMRAMC_TSEG_SZ_8MB    ((uint8_t)(0x2 << 1))
165263cf436SBALATON Zoltan #define MCH_HOST_BRIDGE_ESMRAMC_T_EN           ((uint8_t)1)
16677447524SGerd Hoffmann #define MCH_HOST_BRIDGE_ESMRAMC_DEFAULT \
16777447524SGerd Hoffmann     (MCH_HOST_BRIDGE_ESMRAMC_SM_CACHE | \
16877447524SGerd Hoffmann      MCH_HOST_BRIDGE_ESMRAMC_SM_L1 |    \
16977447524SGerd Hoffmann      MCH_HOST_BRIDGE_ESMRAMC_SM_L2)
170b66a67d7SGerd Hoffmann #define MCH_HOST_BRIDGE_ESMRAMC_WMASK               \
171b66a67d7SGerd Hoffmann     (MCH_HOST_BRIDGE_ESMRAMC_H_SMRAME |             \
172b66a67d7SGerd Hoffmann      MCH_HOST_BRIDGE_ESMRAMC_TSEG_SZ_MASK |         \
173b66a67d7SGerd Hoffmann      MCH_HOST_BRIDGE_ESMRAMC_T_EN)
17468c77acfSGerd Hoffmann #define MCH_HOST_BRIDGE_ESMRAMC_WMASK_LCK     0
175df2d8b3eSIsaku Yamahata 
176df2d8b3eSIsaku Yamahata /* D1:F0 PCIE* port*/
177df2d8b3eSIsaku Yamahata #define MCH_PCIE_DEV                           1
178df2d8b3eSIsaku Yamahata #define MCH_PCIE_FUNC                          0
179df2d8b3eSIsaku Yamahata 
1806f1426abSMichael S. Tsirkin uint64_t mch_mcfg_base(void);
1816f1426abSMichael S. Tsirkin 
182cfc13df4SPeter Xu /*
183*5bb8590dSStefan Weil  * Arbitrary but unique BNF number for IOAPIC device.
184cfc13df4SPeter Xu  *
185cfc13df4SPeter Xu  * TODO: make sure there would have no conflict with real PCI bus
186cfc13df4SPeter Xu  */
187cfc13df4SPeter Xu #define Q35_PSEUDO_BUS_PLATFORM         (0xff)
188cfc13df4SPeter Xu #define Q35_PSEUDO_DEVFN_IOAPIC         (0x00)
189cfc13df4SPeter Xu 
190df2d8b3eSIsaku Yamahata #endif /* HW_Q35_H */
191