xref: /qemu/include/hw/pci/pcie_host.h (revision fc524567087c2537b5103cdfc1d41e4f442892b6)
1a9f49946SIsaku Yamahata /*
2a9f49946SIsaku Yamahata  * pcie_host.h
3a9f49946SIsaku Yamahata  *
4a9f49946SIsaku Yamahata  * Copyright (c) 2009 Isaku Yamahata <yamahata at valinux co jp>
5a9f49946SIsaku Yamahata  *                    VA Linux Systems Japan K.K.
6a9f49946SIsaku Yamahata  *
7a9f49946SIsaku Yamahata  * This program is free software; you can redistribute it and/or modify
8a9f49946SIsaku Yamahata  * it under the terms of the GNU General Public License as published by
9a9f49946SIsaku Yamahata  * the Free Software Foundation; either version 2 of the License, or
10a9f49946SIsaku Yamahata  * (at your option) any later version.
11a9f49946SIsaku Yamahata 
12a9f49946SIsaku Yamahata  * This program is distributed in the hope that it will be useful,
13a9f49946SIsaku Yamahata  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14a9f49946SIsaku Yamahata  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15a9f49946SIsaku Yamahata  * GNU General Public License for more details.
16a9f49946SIsaku Yamahata 
17a9f49946SIsaku Yamahata  * You should have received a copy of the GNU General Public License along
1870539e18SBlue Swirl  * with this program; if not, see <http://www.gnu.org/licenses/>.
19a9f49946SIsaku Yamahata  */
20a9f49946SIsaku Yamahata 
21a9f49946SIsaku Yamahata #ifndef PCIE_HOST_H
22a9f49946SIsaku Yamahata #define PCIE_HOST_H
23a9f49946SIsaku Yamahata 
24c759b24fSMichael S. Tsirkin #include "hw/pci/pci_host.h"
25*8be545baSRichard Henderson #include "system/memory.h"
26db1015e9SEduardo Habkost #include "qom/object.h"
27a9f49946SIsaku Yamahata 
28bc927e48SJason Baron #define TYPE_PCIE_HOST_BRIDGE "pcie-host-bridge"
298063396bSEduardo Habkost OBJECT_DECLARE_SIMPLE_TYPE(PCIExpressHost, PCIE_HOST_BRIDGE)
30bc927e48SJason Baron 
3187f65245SMichael S. Tsirkin #define PCIE_HOST_MCFG_BASE "MCFG"
32cbcaf79eSMichael S. Tsirkin #define PCIE_HOST_MCFG_SIZE "mcfg_size"
3387f65245SMichael S. Tsirkin 
34079e3e70SMichael S. Tsirkin /* pcie_host::base_addr == PCIE_BASE_ADDR_UNMAPPED when it isn't mapped. */
35079e3e70SMichael S. Tsirkin #define PCIE_BASE_ADDR_UNMAPPED  ((hwaddr)-1ULL)
36079e3e70SMichael S. Tsirkin 
37fb47a2e9SIsaku Yamahata struct PCIExpressHost {
38a9f49946SIsaku Yamahata     PCIHostState pci;
39a9f49946SIsaku Yamahata 
40a9f49946SIsaku Yamahata     /* express part */
41a9f49946SIsaku Yamahata 
42a9f49946SIsaku Yamahata     /* base address where MMCONFIG area is mapped. */
43a8170e5eSAvi Kivity     hwaddr  base_addr;
44a9f49946SIsaku Yamahata 
45a9f49946SIsaku Yamahata     /* the size of MMCONFIG area. It's host bridge dependent */
46a8170e5eSAvi Kivity     hwaddr  size;
47a9f49946SIsaku Yamahata 
48c76f990eSAvi Kivity     /* MMCONFIG mmio area */
49c76f990eSAvi Kivity     MemoryRegion mmio;
50fb47a2e9SIsaku Yamahata };
51a9f49946SIsaku Yamahata 
52a9f49946SIsaku Yamahata void pcie_host_mmcfg_unmap(PCIExpressHost *e);
5327fb9688SAlexander Graf void pcie_host_mmcfg_init(PCIExpressHost *e, uint32_t size);
54c702ddb8SJason Baron void pcie_host_mmcfg_map(PCIExpressHost *e, hwaddr addr, uint32_t size);
55a9f49946SIsaku Yamahata void pcie_host_mmcfg_update(PCIExpressHost *e,
56a9f49946SIsaku Yamahata                             int enable,
57c702ddb8SJason Baron                             hwaddr addr,
58c702ddb8SJason Baron                             uint32_t size);
59a9f49946SIsaku Yamahata 
606f6d2823SMichael S. Tsirkin /*
616f6d2823SMichael S. Tsirkin  * PCI express ECAM (Enhanced Configuration Address Mapping) format.
626f6d2823SMichael S. Tsirkin  * AKA mmcfg address
638e58f6ecSFrancisco Iglesias  * bit 20 - 27: bus number
646f6d2823SMichael S. Tsirkin  * bit 15 - 19: device number
656f6d2823SMichael S. Tsirkin  * bit 12 - 14: function number
666f6d2823SMichael S. Tsirkin  * bit  0 - 11: offset in configuration space of a given device
676f6d2823SMichael S. Tsirkin  */
681f1a7b22SFrancisco Iglesias #define PCIE_MMCFG_SIZE_MAX             (1ULL << 28)
696f6d2823SMichael S. Tsirkin #define PCIE_MMCFG_SIZE_MIN             (1ULL << 20)
706f6d2823SMichael S. Tsirkin #define PCIE_MMCFG_BUS_BIT              20
718e58f6ecSFrancisco Iglesias #define PCIE_MMCFG_BUS_MASK             0xff
726f6d2823SMichael S. Tsirkin #define PCIE_MMCFG_DEVFN_BIT            12
736f6d2823SMichael S. Tsirkin #define PCIE_MMCFG_DEVFN_MASK           0xff
746f6d2823SMichael S. Tsirkin #define PCIE_MMCFG_CONFOFFSET_MASK      0xfff
756f6d2823SMichael S. Tsirkin #define PCIE_MMCFG_BUS(addr)            (((addr) >> PCIE_MMCFG_BUS_BIT) & \
766f6d2823SMichael S. Tsirkin                                          PCIE_MMCFG_BUS_MASK)
776f6d2823SMichael S. Tsirkin #define PCIE_MMCFG_DEVFN(addr)          (((addr) >> PCIE_MMCFG_DEVFN_BIT) & \
786f6d2823SMichael S. Tsirkin                                          PCIE_MMCFG_DEVFN_MASK)
796f6d2823SMichael S. Tsirkin #define PCIE_MMCFG_CONFOFFSET(addr)     ((addr) & PCIE_MMCFG_CONFOFFSET_MASK)
806f6d2823SMichael S. Tsirkin 
81a9f49946SIsaku Yamahata #endif /* PCIE_HOST_H */
82