10d09e41aSPaolo Bonzini /* 20d09e41aSPaolo Bonzini * pcie.h 30d09e41aSPaolo Bonzini * 40d09e41aSPaolo Bonzini * Copyright (c) 2010 Isaku Yamahata <yamahata at valinux co jp> 50d09e41aSPaolo Bonzini * VA Linux Systems Japan K.K. 60d09e41aSPaolo Bonzini * 70d09e41aSPaolo Bonzini * This program is free software; you can redistribute it and/or modify 80d09e41aSPaolo Bonzini * it under the terms of the GNU General Public License as published by 90d09e41aSPaolo Bonzini * the Free Software Foundation; either version 2 of the License, or 100d09e41aSPaolo Bonzini * (at your option) any later version. 110d09e41aSPaolo Bonzini * 120d09e41aSPaolo Bonzini * This program is distributed in the hope that it will be useful, 130d09e41aSPaolo Bonzini * but WITHOUT ANY WARRANTY; without even the implied warranty of 140d09e41aSPaolo Bonzini * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 150d09e41aSPaolo Bonzini * GNU General Public License for more details. 160d09e41aSPaolo Bonzini * 170d09e41aSPaolo Bonzini * You should have received a copy of the GNU General Public License along 180d09e41aSPaolo Bonzini * with this program; if not, see <http://www.gnu.org/licenses/>. 190d09e41aSPaolo Bonzini */ 200d09e41aSPaolo Bonzini 210d09e41aSPaolo Bonzini #ifndef QEMU_PCIE_H 220d09e41aSPaolo Bonzini #define QEMU_PCIE_H 230d09e41aSPaolo Bonzini 240d09e41aSPaolo Bonzini #include "hw/pci/pci_regs.h" 250d09e41aSPaolo Bonzini #include "hw/pci/pcie_regs.h" 260d09e41aSPaolo Bonzini #include "hw/pci/pcie_aer.h" 277c0fa8dfSKnut Omang #include "hw/pci/pcie_sriov.h" 28a66e657eSIgor Mammedov #include "hw/hotplug.h" 290d09e41aSPaolo Bonzini 300d09e41aSPaolo Bonzini typedef enum { 310d09e41aSPaolo Bonzini /* these bits must match the bits in Slot Control/Status registers. 320d09e41aSPaolo Bonzini * PCI_EXP_HP_EV_xxx = PCI_EXP_SLTCTL_xxxE = PCI_EXP_SLTSTA_xxx 330d09e41aSPaolo Bonzini * 340d09e41aSPaolo Bonzini * Not all the bits of slot control register match with the ones of 350d09e41aSPaolo Bonzini * slot status. Not some bits of slot status register is used to 360d09e41aSPaolo Bonzini * show status, not to report event occurrence. 370d09e41aSPaolo Bonzini * So such bits must be masked out when checking the software 380d09e41aSPaolo Bonzini * notification condition. 390d09e41aSPaolo Bonzini */ 400d09e41aSPaolo Bonzini PCI_EXP_HP_EV_ABP = PCI_EXP_SLTCTL_ABPE, 410d09e41aSPaolo Bonzini /* attention button pressed */ 420d09e41aSPaolo Bonzini PCI_EXP_HP_EV_PDC = PCI_EXP_SLTCTL_PDCE, 430d09e41aSPaolo Bonzini /* presence detect changed */ 440d09e41aSPaolo Bonzini PCI_EXP_HP_EV_CCI = PCI_EXP_SLTCTL_CCIE, 450d09e41aSPaolo Bonzini /* command completed */ 460d09e41aSPaolo Bonzini 470d09e41aSPaolo Bonzini PCI_EXP_HP_EV_SUPPORTED = PCI_EXP_HP_EV_ABP | 480d09e41aSPaolo Bonzini PCI_EXP_HP_EV_PDC | 490d09e41aSPaolo Bonzini PCI_EXP_HP_EV_CCI, 500d09e41aSPaolo Bonzini /* supported event mask */ 510d09e41aSPaolo Bonzini 520d09e41aSPaolo Bonzini /* events not listed aren't supported */ 530d09e41aSPaolo Bonzini } PCIExpressHotPlugEvent; 540d09e41aSPaolo Bonzini 550d09e41aSPaolo Bonzini struct PCIExpressDevice { 560d09e41aSPaolo Bonzini /* Offset of express capability in config space */ 570d09e41aSPaolo Bonzini uint8_t exp_cap; 5827ce0f3aSMarcel Apfelbaum /* Offset of Power Management capability in config space */ 5927ce0f3aSMarcel Apfelbaum uint8_t pm_cap; 600d09e41aSPaolo Bonzini 610d09e41aSPaolo Bonzini /* SLOT */ 620d09e41aSPaolo Bonzini bool hpev_notified; /* Logical AND of conditions for hot plug event. 630d09e41aSPaolo Bonzini Following 6.7.3.4: 640d09e41aSPaolo Bonzini Software Notification of Hot-Plug Events, an interrupt 650d09e41aSPaolo Bonzini is sent whenever the logical and of these conditions 660d09e41aSPaolo Bonzini transitions from false to true. */ 670d09e41aSPaolo Bonzini 680d09e41aSPaolo Bonzini /* AER */ 690d09e41aSPaolo Bonzini uint16_t aer_cap; 700d09e41aSPaolo Bonzini PCIEAERLog aer_log; 71615c4ed2SJason Wang 72615c4ed2SJason Wang /* Offset of ATS capability in config space */ 73615c4ed2SJason Wang uint16_t ats_cap; 74db891a9bSKnut Omang 75db891a9bSKnut Omang /* ACS */ 76db891a9bSKnut Omang uint16_t acs_cap; 777c0fa8dfSKnut Omang 787c0fa8dfSKnut Omang /* SR/IOV */ 797c0fa8dfSKnut Omang uint16_t sriov_cap; 807c0fa8dfSKnut Omang PCIESriovPF sriov_pf; 817c0fa8dfSKnut Omang PCIESriovVF sriov_vf; 820d09e41aSPaolo Bonzini }; 830d09e41aSPaolo Bonzini 84f23b6bdcSMarcel Apfelbaum #define COMPAT_PROP_PCP "power_controller_present" 85f23b6bdcSMarcel Apfelbaum 860d09e41aSPaolo Bonzini /* PCI express capability helper functions */ 87f8cd1b02SMao Zhongyi int pcie_cap_init(PCIDevice *dev, uint8_t offset, uint8_t type, 88f8cd1b02SMao Zhongyi uint8_t port, Error **errp); 896383292aSDmitry Fleytman int pcie_cap_v1_init(PCIDevice *dev, uint8_t offset, 906383292aSDmitry Fleytman uint8_t type, uint8_t port); 910d09e41aSPaolo Bonzini int pcie_endpoint_cap_init(PCIDevice *dev, uint8_t offset); 920d09e41aSPaolo Bonzini void pcie_cap_exit(PCIDevice *dev); 936383292aSDmitry Fleytman int pcie_endpoint_cap_v1_init(PCIDevice *dev, uint8_t offset); 946383292aSDmitry Fleytman void pcie_cap_v1_exit(PCIDevice *dev); 950d09e41aSPaolo Bonzini uint8_t pcie_cap_get_type(const PCIDevice *dev); 96*cf2916f6SAlex Williamson uint8_t pcie_cap_get_version(const PCIDevice *dev); 970d09e41aSPaolo Bonzini void pcie_cap_flags_set_vector(PCIDevice *dev, uint8_t vector); 980d09e41aSPaolo Bonzini uint8_t pcie_cap_flags_get_vector(PCIDevice *dev); 990d09e41aSPaolo Bonzini 1000d09e41aSPaolo Bonzini void pcie_cap_deverr_init(PCIDevice *dev); 1010d09e41aSPaolo Bonzini void pcie_cap_deverr_reset(PCIDevice *dev); 1020d09e41aSPaolo Bonzini 103d584f1b9SMarcel Apfelbaum void pcie_cap_lnkctl_init(PCIDevice *dev); 104d584f1b9SMarcel Apfelbaum void pcie_cap_lnkctl_reset(PCIDevice *dev); 105d584f1b9SMarcel Apfelbaum 106530a0963SJulia Suvorova void pcie_cap_slot_init(PCIDevice *dev, PCIESlot *s); 1070d09e41aSPaolo Bonzini void pcie_cap_slot_reset(PCIDevice *dev); 1084d90b7a0SMichael S. Tsirkin void pcie_cap_slot_get(PCIDevice *dev, uint16_t *slt_ctl, uint16_t *slt_sta); 109d85d65ccSMichael S. Tsirkin void pcie_cap_slot_write_config(PCIDevice *dev, 1104d90b7a0SMichael S. Tsirkin uint16_t old_slt_ctl, uint16_t old_slt_sta, 1110d09e41aSPaolo Bonzini uint32_t addr, uint32_t val, int len); 1120d09e41aSPaolo Bonzini int pcie_cap_slot_post_load(void *opaque, int version_id); 1130d09e41aSPaolo Bonzini void pcie_cap_slot_push_attention_button(PCIDevice *dev); 1146b0969f1SIgor Mammedov void pcie_cap_slot_enable_power(PCIDevice *dev); 1150d09e41aSPaolo Bonzini 1160d09e41aSPaolo Bonzini void pcie_cap_root_init(PCIDevice *dev); 1170d09e41aSPaolo Bonzini void pcie_cap_root_reset(PCIDevice *dev); 1180d09e41aSPaolo Bonzini 1190d09e41aSPaolo Bonzini void pcie_cap_flr_init(PCIDevice *dev); 1200d09e41aSPaolo Bonzini void pcie_cap_flr_write_config(PCIDevice *dev, 1210d09e41aSPaolo Bonzini uint32_t addr, uint32_t val, int len); 1220d09e41aSPaolo Bonzini 123821be9dbSKnut Omang /* ARI forwarding capability and control */ 124821be9dbSKnut Omang void pcie_cap_arifwd_init(PCIDevice *dev); 125821be9dbSKnut Omang void pcie_cap_arifwd_reset(PCIDevice *dev); 126821be9dbSKnut Omang bool pcie_cap_is_arifwd_enabled(const PCIDevice *dev); 1270d09e41aSPaolo Bonzini 1280d09e41aSPaolo Bonzini /* PCI express extended capability helper functions */ 1290d09e41aSPaolo Bonzini uint16_t pcie_find_capability(PCIDevice *dev, uint16_t cap_id); 1300d09e41aSPaolo Bonzini void pcie_add_capability(PCIDevice *dev, 1310d09e41aSPaolo Bonzini uint16_t cap_id, uint8_t cap_ver, 1320d09e41aSPaolo Bonzini uint16_t offset, uint16_t size); 133727b4866SAlex Williamson void pcie_sync_bridge_lnk(PCIDevice *dev); 1340d09e41aSPaolo Bonzini 135db891a9bSKnut Omang void pcie_acs_init(PCIDevice *dev, uint16_t offset); 136db891a9bSKnut Omang void pcie_acs_reset(PCIDevice *dev); 137db891a9bSKnut Omang 1380d09e41aSPaolo Bonzini void pcie_ari_init(PCIDevice *dev, uint16_t offset, uint16_t nextfn); 139b56b9285SDmitry Fleytman void pcie_dev_ser_num_init(PCIDevice *dev, uint16_t offset, uint64_t ser_num); 140d83f46d1SJason Wang void pcie_ats_init(PCIDevice *dev, uint16_t offset, bool aligned); 1410d09e41aSPaolo Bonzini 142b9731850SDavid Hildenbrand void pcie_cap_slot_pre_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, 143b9731850SDavid Hildenbrand Error **errp); 1445571727aSDavid Hildenbrand void pcie_cap_slot_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, 145a66e657eSIgor Mammedov Error **errp); 146a1952d01SDavid Hildenbrand void pcie_cap_slot_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, 147a1952d01SDavid Hildenbrand Error **errp); 1485571727aSDavid Hildenbrand void pcie_cap_slot_unplug_request_cb(HotplugHandler *hotplug_dev, 14914d5a28fSIgor Mammedov DeviceState *dev, Error **errp); 1500d09e41aSPaolo Bonzini #endif /* QEMU_PCIE_H */ 151