10428527cSIsaku Yamahata /* 20428527cSIsaku Yamahata * pcie.h 30428527cSIsaku Yamahata * 40428527cSIsaku Yamahata * Copyright (c) 2010 Isaku Yamahata <yamahata at valinux co jp> 50428527cSIsaku Yamahata * VA Linux Systems Japan K.K. 60428527cSIsaku Yamahata * 70428527cSIsaku Yamahata * This program is free software; you can redistribute it and/or modify 80428527cSIsaku Yamahata * it under the terms of the GNU General Public License as published by 90428527cSIsaku Yamahata * the Free Software Foundation; either version 2 of the License, or 100428527cSIsaku Yamahata * (at your option) any later version. 110428527cSIsaku Yamahata * 120428527cSIsaku Yamahata * This program is distributed in the hope that it will be useful, 130428527cSIsaku Yamahata * but WITHOUT ANY WARRANTY; without even the implied warranty of 140428527cSIsaku Yamahata * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 150428527cSIsaku Yamahata * GNU General Public License for more details. 160428527cSIsaku Yamahata * 170428527cSIsaku Yamahata * You should have received a copy of the GNU General Public License along 180428527cSIsaku Yamahata * with this program; if not, see <http://www.gnu.org/licenses/>. 190428527cSIsaku Yamahata */ 200428527cSIsaku Yamahata 210428527cSIsaku Yamahata #ifndef QEMU_PCIE_H 220428527cSIsaku Yamahata #define QEMU_PCIE_H 230428527cSIsaku Yamahata 24c759b24fSMichael S. Tsirkin #include "hw/pci/pci_regs.h" 25c759b24fSMichael S. Tsirkin #include "hw/pci/pcie_regs.h" 26c759b24fSMichael S. Tsirkin #include "hw/pci/pcie_aer.h" 277c0fa8dfSKnut Omang #include "hw/pci/pcie_sriov.h" 28a66e657eSIgor Mammedov #include "hw/hotplug.h" 290428527cSIsaku Yamahata 30fe5943feSPaolo Bonzini typedef struct PCIEPort PCIEPort; 31fe5943feSPaolo Bonzini typedef struct PCIESlot PCIESlot; 32fe5943feSPaolo Bonzini 330428527cSIsaku Yamahata typedef enum { 340428527cSIsaku Yamahata /* these bits must match the bits in Slot Control/Status registers. 350428527cSIsaku Yamahata * PCI_EXP_HP_EV_xxx = PCI_EXP_SLTCTL_xxxE = PCI_EXP_SLTSTA_xxx 360428527cSIsaku Yamahata * 370428527cSIsaku Yamahata * Not all the bits of slot control register match with the ones of 380428527cSIsaku Yamahata * slot status. Not some bits of slot status register is used to 39a1c7273bSStefan Weil * show status, not to report event occurrence. 400428527cSIsaku Yamahata * So such bits must be masked out when checking the software 410428527cSIsaku Yamahata * notification condition. 420428527cSIsaku Yamahata */ 430428527cSIsaku Yamahata PCI_EXP_HP_EV_ABP = PCI_EXP_SLTCTL_ABPE, 440428527cSIsaku Yamahata /* attention button pressed */ 450428527cSIsaku Yamahata PCI_EXP_HP_EV_PDC = PCI_EXP_SLTCTL_PDCE, 460428527cSIsaku Yamahata /* presence detect changed */ 470428527cSIsaku Yamahata PCI_EXP_HP_EV_CCI = PCI_EXP_SLTCTL_CCIE, 480428527cSIsaku Yamahata /* command completed */ 490428527cSIsaku Yamahata 500428527cSIsaku Yamahata PCI_EXP_HP_EV_SUPPORTED = PCI_EXP_HP_EV_ABP | 510428527cSIsaku Yamahata PCI_EXP_HP_EV_PDC | 520428527cSIsaku Yamahata PCI_EXP_HP_EV_CCI, 530428527cSIsaku Yamahata /* supported event mask */ 540428527cSIsaku Yamahata 550428527cSIsaku Yamahata /* events not listed aren't supported */ 560428527cSIsaku Yamahata } PCIExpressHotPlugEvent; 570428527cSIsaku Yamahata 580428527cSIsaku Yamahata struct PCIExpressDevice { 590428527cSIsaku Yamahata /* Offset of express capability in config space */ 600428527cSIsaku Yamahata uint8_t exp_cap; 610428527cSIsaku Yamahata 620428527cSIsaku Yamahata /* SLOT */ 636bde6aaaSMichael S. Tsirkin bool hpev_notified; /* Logical AND of conditions for hot plug event. 646bde6aaaSMichael S. Tsirkin Following 6.7.3.4: 656bde6aaaSMichael S. Tsirkin Software Notification of Hot-Plug Events, an interrupt 666bde6aaaSMichael S. Tsirkin is sent whenever the logical and of these conditions 676bde6aaaSMichael S. Tsirkin transitions from false to true. */ 6834e65944SIsaku Yamahata 6934e65944SIsaku Yamahata /* AER */ 7034e65944SIsaku Yamahata uint16_t aer_cap; 7134e65944SIsaku Yamahata PCIEAERLog aer_log; 72615c4ed2SJason Wang 73dcad6cb2SCLEMENT MATHIEU--DRIF /* Offset of ATS, PRI and PASID capabilities in config space */ 74615c4ed2SJason Wang uint16_t ats_cap; 75a8d178e1SCLEMENT MATHIEU--DRIF uint16_t pasid_cap; 76dcad6cb2SCLEMENT MATHIEU--DRIF uint16_t pri_cap; 77db891a9bSKnut Omang 78db891a9bSKnut Omang /* ACS */ 79db891a9bSKnut Omang uint16_t acs_cap; 807c0fa8dfSKnut Omang 817c0fa8dfSKnut Omang /* SR/IOV */ 827c0fa8dfSKnut Omang uint16_t sriov_cap; 837c0fa8dfSKnut Omang PCIESriovPF sriov_pf; 847c0fa8dfSKnut Omang PCIESriovVF sriov_vf; 850428527cSIsaku Yamahata }; 860428527cSIsaku Yamahata 87f23b6bdcSMarcel Apfelbaum #define COMPAT_PROP_PCP "power_controller_present" 88f23b6bdcSMarcel Apfelbaum 890428527cSIsaku Yamahata /* PCI express capability helper functions */ 90f8cd1b02SMao Zhongyi int pcie_cap_init(PCIDevice *dev, uint8_t offset, uint8_t type, 91f8cd1b02SMao Zhongyi uint8_t port, Error **errp); 926383292aSDmitry Fleytman int pcie_cap_v1_init(PCIDevice *dev, uint8_t offset, 936383292aSDmitry Fleytman uint8_t type, uint8_t port); 946214e73cSAlex Williamson int pcie_endpoint_cap_init(PCIDevice *dev, uint8_t offset); 950428527cSIsaku Yamahata void pcie_cap_exit(PCIDevice *dev); 966383292aSDmitry Fleytman int pcie_endpoint_cap_v1_init(PCIDevice *dev, uint8_t offset); 976383292aSDmitry Fleytman void pcie_cap_v1_exit(PCIDevice *dev); 980428527cSIsaku Yamahata uint8_t pcie_cap_get_type(const PCIDevice *dev); 99cf2916f6SAlex Williamson uint8_t pcie_cap_get_version(const PCIDevice *dev); 1000428527cSIsaku Yamahata void pcie_cap_flags_set_vector(PCIDevice *dev, uint8_t vector); 1010428527cSIsaku Yamahata uint8_t pcie_cap_flags_get_vector(PCIDevice *dev); 1020428527cSIsaku Yamahata 1030428527cSIsaku Yamahata void pcie_cap_deverr_init(PCIDevice *dev); 1040428527cSIsaku Yamahata void pcie_cap_deverr_reset(PCIDevice *dev); 1050428527cSIsaku Yamahata 106d584f1b9SMarcel Apfelbaum void pcie_cap_lnkctl_init(PCIDevice *dev); 107d584f1b9SMarcel Apfelbaum void pcie_cap_lnkctl_reset(PCIDevice *dev); 108d584f1b9SMarcel Apfelbaum 109530a0963SJulia Suvorova void pcie_cap_slot_init(PCIDevice *dev, PCIESlot *s); 1100428527cSIsaku Yamahata void pcie_cap_slot_reset(PCIDevice *dev); 1114d90b7a0SMichael S. Tsirkin void pcie_cap_slot_get(PCIDevice *dev, uint16_t *slt_ctl, uint16_t *slt_sta); 112d85d65ccSMichael S. Tsirkin void pcie_cap_slot_write_config(PCIDevice *dev, 1134d90b7a0SMichael S. Tsirkin uint16_t old_slt_ctl, uint16_t old_slt_sta, 1146bde6aaaSMichael S. Tsirkin uint32_t addr, uint32_t val, int len); 1156bde6aaaSMichael S. Tsirkin int pcie_cap_slot_post_load(void *opaque, int version_id); 1160428527cSIsaku Yamahata void pcie_cap_slot_push_attention_button(PCIDevice *dev); 1176b0969f1SIgor Mammedov void pcie_cap_slot_enable_power(PCIDevice *dev); 1180428527cSIsaku Yamahata 1190428527cSIsaku Yamahata void pcie_cap_root_init(PCIDevice *dev); 1200428527cSIsaku Yamahata void pcie_cap_root_reset(PCIDevice *dev); 1210428527cSIsaku Yamahata 1220428527cSIsaku Yamahata void pcie_cap_flr_init(PCIDevice *dev); 1230428527cSIsaku Yamahata void pcie_cap_flr_write_config(PCIDevice *dev, 1240428527cSIsaku Yamahata uint32_t addr, uint32_t val, int len); 1250428527cSIsaku Yamahata 126821be9dbSKnut Omang /* ARI forwarding capability and control */ 127821be9dbSKnut Omang void pcie_cap_arifwd_init(PCIDevice *dev); 128821be9dbSKnut Omang void pcie_cap_arifwd_reset(PCIDevice *dev); 129821be9dbSKnut Omang bool pcie_cap_is_arifwd_enabled(const PCIDevice *dev); 1300428527cSIsaku Yamahata 1310428527cSIsaku Yamahata /* PCI express extended capability helper functions */ 1320428527cSIsaku Yamahata uint16_t pcie_find_capability(PCIDevice *dev, uint16_t cap_id); 1330428527cSIsaku Yamahata void pcie_add_capability(PCIDevice *dev, 1340428527cSIsaku Yamahata uint16_t cap_id, uint8_t cap_ver, 1350428527cSIsaku Yamahata uint16_t offset, uint16_t size); 136727b4866SAlex Williamson void pcie_sync_bridge_lnk(PCIDevice *dev); 1370428527cSIsaku Yamahata 138db891a9bSKnut Omang void pcie_acs_init(PCIDevice *dev, uint16_t offset); 139db891a9bSKnut Omang void pcie_acs_reset(PCIDevice *dev); 140db891a9bSKnut Omang 141445416e3SAkihiko Odaki void pcie_ari_init(PCIDevice *dev, uint16_t offset); 142b56b9285SDmitry Fleytman void pcie_dev_ser_num_init(PCIDevice *dev, uint16_t offset, uint64_t ser_num); 143d83f46d1SJason Wang void pcie_ats_init(PCIDevice *dev, uint16_t offset, bool aligned); 144ea3f0ebcSJonathan Cameron void pcie_cap_fill_link_ep_usp(PCIDevice *dev, PCIExpLinkWidth width, 145ea3f0ebcSJonathan Cameron PCIExpLinkSpeed speed); 1460428527cSIsaku Yamahata 147b9731850SDavid Hildenbrand void pcie_cap_slot_pre_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, 148b9731850SDavid Hildenbrand Error **errp); 1495571727aSDavid Hildenbrand void pcie_cap_slot_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, 150a66e657eSIgor Mammedov Error **errp); 151a1952d01SDavid Hildenbrand void pcie_cap_slot_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, 152a1952d01SDavid Hildenbrand Error **errp); 1535571727aSDavid Hildenbrand void pcie_cap_slot_unplug_request_cb(HotplugHandler *hotplug_dev, 15414d5a28fSIgor Mammedov DeviceState *dev, Error **errp); 155a8d178e1SCLEMENT MATHIEU--DRIF 156a8d178e1SCLEMENT MATHIEU--DRIF void pcie_pasid_init(PCIDevice *dev, uint16_t offset, uint8_t pasid_width, 157a8d178e1SCLEMENT MATHIEU--DRIF bool exec_perm, bool priv_mod); 158dcad6cb2SCLEMENT MATHIEU--DRIF void pcie_pri_init(PCIDevice *dev, uint16_t offset, uint32_t outstanding_pr_cap, 159dcad6cb2SCLEMENT MATHIEU--DRIF bool prg_response_pasid_req); 1601e82e8a8SCLEMENT MATHIEU--DRIF 161*5be8cf79SCLEMENT MATHIEU--DRIF bool pcie_pri_enabled(const PCIDevice *dev); 1621e82e8a8SCLEMENT MATHIEU--DRIF bool pcie_pasid_enabled(const PCIDevice *dev); 1636a3ae6a2SCLEMENT MATHIEU--DRIF bool pcie_ats_enabled(const PCIDevice *dev); 1640428527cSIsaku Yamahata #endif /* QEMU_PCIE_H */ 165