xref: /qemu/include/hw/pci/pci_bridge.h (revision b2999ed8ad6d9793b8310a1c7138a0232f637d1d)
1783753fdSIsaku Yamahata /*
2783753fdSIsaku Yamahata  * QEMU PCI bridge
3783753fdSIsaku Yamahata  *
4783753fdSIsaku Yamahata  * Copyright (c) 2004 Fabrice Bellard
5783753fdSIsaku Yamahata  *
6783753fdSIsaku Yamahata  * This program is free software; you can redistribute it and/or modify
7783753fdSIsaku Yamahata  * it under the terms of the GNU General Public License as published by
8783753fdSIsaku Yamahata  * the Free Software Foundation; either version 2 of the License, or
9783753fdSIsaku Yamahata  * (at your option) any later version.
10783753fdSIsaku Yamahata  *
11783753fdSIsaku Yamahata  * This program is distributed in the hope that it will be useful,
12783753fdSIsaku Yamahata  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13783753fdSIsaku Yamahata  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14783753fdSIsaku Yamahata  * GNU General Public License for more details.
15783753fdSIsaku Yamahata  *
16783753fdSIsaku Yamahata  * You should have received a copy of the GNU General Public License
17783753fdSIsaku Yamahata  * along with this program; if not, write to the Free Software
18783753fdSIsaku Yamahata  * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19783753fdSIsaku Yamahata  *
20783753fdSIsaku Yamahata  * split out pci bus specific stuff from pci.[hc] to pci_bridge.[hc]
21783753fdSIsaku Yamahata  * Copyright (c) 2009 Isaku Yamahata <yamahata at valinux co jp>
22783753fdSIsaku Yamahata  *                    VA Linux Systems Japan K.K.
23783753fdSIsaku Yamahata  *
24783753fdSIsaku Yamahata  */
25783753fdSIsaku Yamahata 
26783753fdSIsaku Yamahata #ifndef QEMU_PCI_BRIDGE_H
27783753fdSIsaku Yamahata #define QEMU_PCI_BRIDGE_H
28783753fdSIsaku Yamahata 
29edf5ca5dSMarkus Armbruster #include "hw/pci/pci_device.h"
30791bf3c8SDavid Gibson #include "hw/pci/pci_bus.h"
313d6a69b6SBen Widawsky #include "hw/cxl/cxl.h"
32db1015e9SEduardo Habkost #include "qom/object.h"
33791bf3c8SDavid Gibson 
34791bf3c8SDavid Gibson typedef struct PCIBridgeWindows PCIBridgeWindows;
35791bf3c8SDavid Gibson 
36791bf3c8SDavid Gibson /*
37791bf3c8SDavid Gibson  * Aliases for each of the address space windows that the bridge
38791bf3c8SDavid Gibson  * can forward. Mapped into the bridge's parent's address space,
39791bf3c8SDavid Gibson  * as subregions.
40791bf3c8SDavid Gibson  */
41791bf3c8SDavid Gibson struct PCIBridgeWindows {
42791bf3c8SDavid Gibson     MemoryRegion alias_pref_mem;
43791bf3c8SDavid Gibson     MemoryRegion alias_mem;
44791bf3c8SDavid Gibson     MemoryRegion alias_io;
45791bf3c8SDavid Gibson     /*
46791bf3c8SDavid Gibson      * When bridge control VGA forwarding is enabled, bridges will
47791bf3c8SDavid Gibson      * provide positive decode on the PCI VGA defined I/O port and
48791bf3c8SDavid Gibson      * MMIO ranges.  When enabled forwarding is only qualified on the
49791bf3c8SDavid Gibson      * I/O and memory enable bits in the bridge command register.
50791bf3c8SDavid Gibson      */
51791bf3c8SDavid Gibson     MemoryRegion alias_vga[QEMU_PCI_VGA_NUM_REGIONS];
52791bf3c8SDavid Gibson };
53791bf3c8SDavid Gibson 
54791bf3c8SDavid Gibson #define TYPE_PCI_BRIDGE "base-pci-bridge"
558063396bSEduardo Habkost OBJECT_DECLARE_SIMPLE_TYPE(PCIBridge, PCI_BRIDGE)
56ad494274SIgor Mammedov #define IS_PCI_BRIDGE(dev) object_dynamic_cast(OBJECT(dev), TYPE_PCI_BRIDGE)
57791bf3c8SDavid Gibson 
58791bf3c8SDavid Gibson struct PCIBridge {
59791bf3c8SDavid Gibson     /*< private >*/
60791bf3c8SDavid Gibson     PCIDevice parent_obj;
61791bf3c8SDavid Gibson     /*< public >*/
62791bf3c8SDavid Gibson 
63791bf3c8SDavid Gibson     /* private member */
64791bf3c8SDavid Gibson     PCIBus sec_bus;
65791bf3c8SDavid Gibson     /*
66791bf3c8SDavid Gibson      * Memory regions for the bridge's address spaces.  These regions are not
67791bf3c8SDavid Gibson      * directly added to system_memory/system_io or its descendants.
68791bf3c8SDavid Gibson      * Bridge's secondary bus points to these, so that devices
69791bf3c8SDavid Gibson      * under the bridge see these regions as its address spaces.
70791bf3c8SDavid Gibson      * The regions are as large as the entire address space -
71791bf3c8SDavid Gibson      * they don't take into account any windows.
72791bf3c8SDavid Gibson      */
73791bf3c8SDavid Gibson     MemoryRegion address_space_mem;
74791bf3c8SDavid Gibson     MemoryRegion address_space_io;
75791bf3c8SDavid Gibson 
76*b2999ed8SJonathan Cameron     PCIBridgeWindows windows;
77791bf3c8SDavid Gibson 
78791bf3c8SDavid Gibson     pci_map_irq_fn map_irq;
79791bf3c8SDavid Gibson     const char *bus_name;
80791bf3c8SDavid Gibson };
81783753fdSIsaku Yamahata 
823cf0ecb3SLaszlo Ersek #define PCI_BRIDGE_DEV_PROP_CHASSIS_NR "chassis_nr"
837a7c6a41SLaszlo Ersek #define PCI_BRIDGE_DEV_PROP_MSI        "msi"
844e5c9bfeSLaszlo Ersek #define PCI_BRIDGE_DEV_PROP_SHPC       "shpc"
853d6a69b6SBen Widawsky typedef struct CXLHost CXLHost;
863d6a69b6SBen Widawsky 
87c28db9e0SJonathan Cameron typedef struct PXBDev {
883d6a69b6SBen Widawsky     /*< private >*/
893d6a69b6SBen Widawsky     PCIDevice parent_obj;
903d6a69b6SBen Widawsky     /*< public >*/
913d6a69b6SBen Widawsky 
923d6a69b6SBen Widawsky     uint8_t bus_nr;
933d6a69b6SBen Widawsky     uint16_t numa_node;
943d6a69b6SBen Widawsky     bool bypass_iommu;
95c28db9e0SJonathan Cameron } PXBDev;
963d6a69b6SBen Widawsky 
97c28db9e0SJonathan Cameron typedef struct PXBPCIEDev {
98c28db9e0SJonathan Cameron     /*< private >*/
99c28db9e0SJonathan Cameron     PXBDev parent_obj;
100c28db9e0SJonathan Cameron } PXBPCIEDev;
101c28db9e0SJonathan Cameron 
102c28db9e0SJonathan Cameron #define TYPE_PXB_DEV "pxb"
103c28db9e0SJonathan Cameron OBJECT_DECLARE_SIMPLE_TYPE(PXBDev, PXB_DEV)
104c28db9e0SJonathan Cameron 
105c28db9e0SJonathan Cameron typedef struct PXBCXLDev {
106c28db9e0SJonathan Cameron     /*< private >*/
107c28db9e0SJonathan Cameron     PXBPCIEDev parent_obj;
108c28db9e0SJonathan Cameron     /*< public >*/
109c28db9e0SJonathan Cameron 
110c28db9e0SJonathan Cameron     bool hdm_for_passthrough;
111c28db9e0SJonathan Cameron     CXLHost *cxl_host_bridge; /* Pointer to a CXLHost */
112c28db9e0SJonathan Cameron } PXBCXLDev;
113c28db9e0SJonathan Cameron 
114c28db9e0SJonathan Cameron #define TYPE_PXB_CXL_DEV "pxb-cxl"
115c28db9e0SJonathan Cameron OBJECT_DECLARE_SIMPLE_TYPE(PXBCXLDev, PXB_CXL_DEV)
1163cf0ecb3SLaszlo Ersek 
117f4c817e0SIsaku Yamahata int pci_bridge_ssvid_init(PCIDevice *dev, uint8_t offset,
118f8cd1b02SMao Zhongyi                           uint16_t svid, uint16_t ssid,
119f8cd1b02SMao Zhongyi                           Error **errp);
120f4c817e0SIsaku Yamahata 
121783753fdSIsaku Yamahata PCIDevice *pci_bridge_get_device(PCIBus *bus);
12268f79994SIsaku Yamahata PCIBus *pci_bridge_get_sec_bus(PCIBridge *br);
123783753fdSIsaku Yamahata 
12468f79994SIsaku Yamahata pcibus_t pci_bridge_get_base(const PCIDevice *bridge, uint8_t type);
12568f79994SIsaku Yamahata pcibus_t pci_bridge_get_limit(const PCIDevice *bridge, uint8_t type);
126783753fdSIsaku Yamahata 
127e78e9ae4SDon Koch void pci_bridge_update_mappings(PCIBridge *br);
12868f79994SIsaku Yamahata void pci_bridge_write_config(PCIDevice *d,
12968f79994SIsaku Yamahata                              uint32_t address, uint32_t val, int len);
1300208def1SIsaku Yamahata void pci_bridge_disable_base_limit(PCIDevice *dev);
13168f79994SIsaku Yamahata void pci_bridge_reset(DeviceState *qdev);
13268f79994SIsaku Yamahata 
1339cfaa007SCao jin void pci_bridge_initfn(PCIDevice *pci_dev, const char *typename);
134f90c2bcdSAlex Williamson void pci_bridge_exitfn(PCIDevice *pci_dev);
13568f79994SIsaku Yamahata 
13662b76563SDavid Hildenbrand void pci_bridge_dev_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
13762b76563SDavid Hildenbrand                             Error **errp);
1388f560cdcSDavid Hildenbrand void pci_bridge_dev_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
1398f560cdcSDavid Hildenbrand                               Error **errp);
14062b76563SDavid Hildenbrand void pci_bridge_dev_unplug_request_cb(HotplugHandler *hotplug_dev,
14162b76563SDavid Hildenbrand                                       DeviceState *dev, Error **errp);
14268f79994SIsaku Yamahata 
14368f79994SIsaku Yamahata /*
14468f79994SIsaku Yamahata  * before qdev initialization(qdev_init()), this function sets bus_name and
145b7709d0eSJulia Suvorova  * map_irq callback which are necessary for pci_bridge_initfn() to
14668f79994SIsaku Yamahata  * initialize bus.
14768f79994SIsaku Yamahata  */
14868f79994SIsaku Yamahata void pci_bridge_map_irq(PCIBridge *br, const char* bus_name,
14968f79994SIsaku Yamahata                         pci_map_irq_fn map_irq);
150783753fdSIsaku Yamahata 
15145eb768cSMichael S. Tsirkin /* TODO: add this define to pci_regs.h in linux and then in qemu. */
15245eb768cSMichael S. Tsirkin #define  PCI_BRIDGE_CTL_VGA_16BIT       0x10    /* VGA 16-bit decode */
15345eb768cSMichael S. Tsirkin #define  PCI_BRIDGE_CTL_DISCARD         0x100   /* Primary discard timer */
15445eb768cSMichael S. Tsirkin #define  PCI_BRIDGE_CTL_SEC_DISCARD     0x200   /* Secondary discard timer */
15545eb768cSMichael S. Tsirkin #define  PCI_BRIDGE_CTL_DISCARD_STATUS  0x400   /* Discard timer status */
15645eb768cSMichael S. Tsirkin #define  PCI_BRIDGE_CTL_DISCARD_SERR    0x800   /* Discard timer SERR# enable */
15745eb768cSMichael S. Tsirkin 
15870e1ee59SAleksandr Bezzubikov typedef struct PCIBridgeQemuCap {
15970e1ee59SAleksandr Bezzubikov     uint8_t id;     /* Standard PCI capability header field */
16070e1ee59SAleksandr Bezzubikov     uint8_t next;   /* Standard PCI capability header field */
16170e1ee59SAleksandr Bezzubikov     uint8_t len;    /* Standard PCI vendor-specific capability header field */
16270e1ee59SAleksandr Bezzubikov     uint8_t type;   /* Red Hat vendor-specific capability type.
16370e1ee59SAleksandr Bezzubikov                        Types are defined with REDHAT_PCI_CAP_ prefix */
16470e1ee59SAleksandr Bezzubikov 
16570e1ee59SAleksandr Bezzubikov     uint32_t bus_res;   /* Minimum number of buses to reserve */
16670e1ee59SAleksandr Bezzubikov     uint64_t io;        /* IO space to reserve */
16770e1ee59SAleksandr Bezzubikov     uint32_t mem;       /* Non-prefetchable memory to reserve */
16870e1ee59SAleksandr Bezzubikov     /* At most one of the following two fields may be set to a value
16970e1ee59SAleksandr Bezzubikov      * different from -1 */
17070e1ee59SAleksandr Bezzubikov     uint32_t mem_pref_32; /* Prefetchable memory to reserve (32-bit MMIO) */
17170e1ee59SAleksandr Bezzubikov     uint64_t mem_pref_64; /* Prefetchable memory to reserve (64-bit MMIO) */
17270e1ee59SAleksandr Bezzubikov } PCIBridgeQemuCap;
17370e1ee59SAleksandr Bezzubikov 
174efe84f03SLaurent Vivier #define REDHAT_PCI_CAP_TYPE_OFFSET      3
17570e1ee59SAleksandr Bezzubikov #define REDHAT_PCI_CAP_RESOURCE_RESERVE 1
17670e1ee59SAleksandr Bezzubikov 
1779e899399SJing Liu /*
1789e899399SJing Liu  * PCI BUS/IO/MEM/PREFMEM additional resources recorded as a
1799e899399SJing Liu  * capability in PCI configuration space to reserve on firmware init.
1809e899399SJing Liu  */
1819e899399SJing Liu typedef struct PCIResReserve {
1829e899399SJing Liu     uint32_t bus;
1839e899399SJing Liu     uint64_t io;
1849e899399SJing Liu     uint64_t mem_non_pref;
1859e899399SJing Liu     uint64_t mem_pref_32;
1869e899399SJing Liu     uint64_t mem_pref_64;
1879e899399SJing Liu } PCIResReserve;
1889e899399SJing Liu 
189efe84f03SLaurent Vivier #define REDHAT_PCI_CAP_RES_RESERVE_BUS_RES     4
190efe84f03SLaurent Vivier #define REDHAT_PCI_CAP_RES_RESERVE_IO          8
191efe84f03SLaurent Vivier #define REDHAT_PCI_CAP_RES_RESERVE_MEM         16
192efe84f03SLaurent Vivier #define REDHAT_PCI_CAP_RES_RESERVE_PREF_MEM_32 20
193efe84f03SLaurent Vivier #define REDHAT_PCI_CAP_RES_RESERVE_PREF_MEM_64 24
194efe84f03SLaurent Vivier #define REDHAT_PCI_CAP_RES_RESERVE_CAP_SIZE    32
195efe84f03SLaurent Vivier 
19670e1ee59SAleksandr Bezzubikov int pci_bridge_qemu_reserve_cap_init(PCIDevice *dev, int cap_offset,
1979e899399SJing Liu                                PCIResReserve res_reserve, Error **errp);
19870e1ee59SAleksandr Bezzubikov 
199783753fdSIsaku Yamahata #endif /* QEMU_PCI_BRIDGE_H */
200