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/hw.h" 25c759b24fSMichael S. Tsirkin #include "hw/pci/pci_regs.h" 26c759b24fSMichael S. Tsirkin #include "hw/pci/pcie_regs.h" 27c759b24fSMichael S. Tsirkin #include "hw/pci/pcie_aer.h" 28a66e657eSIgor Mammedov #include "hw/hotplug.h" 290428527cSIsaku Yamahata 300428527cSIsaku Yamahata typedef enum { 310428527cSIsaku Yamahata /* for attention and power indicator */ 320428527cSIsaku Yamahata PCI_EXP_HP_IND_RESERVED = PCI_EXP_SLTCTL_IND_RESERVED, 330428527cSIsaku Yamahata PCI_EXP_HP_IND_ON = PCI_EXP_SLTCTL_IND_ON, 340428527cSIsaku Yamahata PCI_EXP_HP_IND_BLINK = PCI_EXP_SLTCTL_IND_BLINK, 350428527cSIsaku Yamahata PCI_EXP_HP_IND_OFF = PCI_EXP_SLTCTL_IND_OFF, 360428527cSIsaku Yamahata } PCIExpressIndicator; 370428527cSIsaku Yamahata 380428527cSIsaku Yamahata typedef enum { 390428527cSIsaku Yamahata /* these bits must match the bits in Slot Control/Status registers. 400428527cSIsaku Yamahata * PCI_EXP_HP_EV_xxx = PCI_EXP_SLTCTL_xxxE = PCI_EXP_SLTSTA_xxx 410428527cSIsaku Yamahata * 420428527cSIsaku Yamahata * Not all the bits of slot control register match with the ones of 430428527cSIsaku Yamahata * slot status. Not some bits of slot status register is used to 44a1c7273bSStefan Weil * show status, not to report event occurrence. 450428527cSIsaku Yamahata * So such bits must be masked out when checking the software 460428527cSIsaku Yamahata * notification condition. 470428527cSIsaku Yamahata */ 480428527cSIsaku Yamahata PCI_EXP_HP_EV_ABP = PCI_EXP_SLTCTL_ABPE, 490428527cSIsaku Yamahata /* attention button pressed */ 500428527cSIsaku Yamahata PCI_EXP_HP_EV_PDC = PCI_EXP_SLTCTL_PDCE, 510428527cSIsaku Yamahata /* presence detect changed */ 520428527cSIsaku Yamahata PCI_EXP_HP_EV_CCI = PCI_EXP_SLTCTL_CCIE, 530428527cSIsaku Yamahata /* command completed */ 540428527cSIsaku Yamahata 550428527cSIsaku Yamahata PCI_EXP_HP_EV_SUPPORTED = PCI_EXP_HP_EV_ABP | 560428527cSIsaku Yamahata PCI_EXP_HP_EV_PDC | 570428527cSIsaku Yamahata PCI_EXP_HP_EV_CCI, 580428527cSIsaku Yamahata /* supported event mask */ 590428527cSIsaku Yamahata 600428527cSIsaku Yamahata /* events not listed aren't supported */ 610428527cSIsaku Yamahata } PCIExpressHotPlugEvent; 620428527cSIsaku Yamahata 630428527cSIsaku Yamahata struct PCIExpressDevice { 640428527cSIsaku Yamahata /* Offset of express capability in config space */ 650428527cSIsaku Yamahata uint8_t exp_cap; 660428527cSIsaku Yamahata 670428527cSIsaku Yamahata /* SLOT */ 686bde6aaaSMichael S. Tsirkin bool hpev_notified; /* Logical AND of conditions for hot plug event. 696bde6aaaSMichael S. Tsirkin Following 6.7.3.4: 706bde6aaaSMichael S. Tsirkin Software Notification of Hot-Plug Events, an interrupt 716bde6aaaSMichael S. Tsirkin is sent whenever the logical and of these conditions 726bde6aaaSMichael S. Tsirkin transitions from false to true. */ 7334e65944SIsaku Yamahata 7434e65944SIsaku Yamahata /* AER */ 7534e65944SIsaku Yamahata uint16_t aer_cap; 7634e65944SIsaku Yamahata PCIEAERLog aer_log; 77615c4ed2SJason Wang 78615c4ed2SJason Wang /* Offset of ATS capability in config space */ 79615c4ed2SJason Wang uint16_t ats_cap; 800428527cSIsaku Yamahata }; 810428527cSIsaku Yamahata 82f23b6bdcSMarcel Apfelbaum #define COMPAT_PROP_PCP "power_controller_present" 83f23b6bdcSMarcel Apfelbaum 840428527cSIsaku Yamahata /* PCI express capability helper functions */ 850428527cSIsaku Yamahata int pcie_cap_init(PCIDevice *dev, uint8_t offset, uint8_t type, uint8_t port); 866383292aSDmitry Fleytman int pcie_cap_v1_init(PCIDevice *dev, uint8_t offset, 876383292aSDmitry Fleytman uint8_t type, uint8_t port); 886214e73cSAlex Williamson int pcie_endpoint_cap_init(PCIDevice *dev, uint8_t offset); 890428527cSIsaku Yamahata void pcie_cap_exit(PCIDevice *dev); 906383292aSDmitry Fleytman int pcie_endpoint_cap_v1_init(PCIDevice *dev, uint8_t offset); 916383292aSDmitry Fleytman void pcie_cap_v1_exit(PCIDevice *dev); 920428527cSIsaku Yamahata uint8_t pcie_cap_get_type(const PCIDevice *dev); 930428527cSIsaku Yamahata void pcie_cap_flags_set_vector(PCIDevice *dev, uint8_t vector); 940428527cSIsaku Yamahata uint8_t pcie_cap_flags_get_vector(PCIDevice *dev); 950428527cSIsaku Yamahata 960428527cSIsaku Yamahata void pcie_cap_deverr_init(PCIDevice *dev); 970428527cSIsaku Yamahata void pcie_cap_deverr_reset(PCIDevice *dev); 980428527cSIsaku Yamahata 99*d584f1b9SMarcel Apfelbaum void pcie_cap_lnkctl_init(PCIDevice *dev); 100*d584f1b9SMarcel Apfelbaum void pcie_cap_lnkctl_reset(PCIDevice *dev); 101*d584f1b9SMarcel Apfelbaum 1020428527cSIsaku Yamahata void pcie_cap_slot_init(PCIDevice *dev, uint16_t slot); 1030428527cSIsaku Yamahata void pcie_cap_slot_reset(PCIDevice *dev); 1040428527cSIsaku Yamahata void pcie_cap_slot_write_config(PCIDevice *dev, 1056bde6aaaSMichael S. Tsirkin uint32_t addr, uint32_t val, int len); 1066bde6aaaSMichael S. Tsirkin int pcie_cap_slot_post_load(void *opaque, int version_id); 1070428527cSIsaku Yamahata void pcie_cap_slot_push_attention_button(PCIDevice *dev); 1080428527cSIsaku Yamahata 1090428527cSIsaku Yamahata void pcie_cap_root_init(PCIDevice *dev); 1100428527cSIsaku Yamahata void pcie_cap_root_reset(PCIDevice *dev); 1110428527cSIsaku Yamahata 1120428527cSIsaku Yamahata void pcie_cap_flr_init(PCIDevice *dev); 1130428527cSIsaku Yamahata void pcie_cap_flr_write_config(PCIDevice *dev, 1140428527cSIsaku Yamahata uint32_t addr, uint32_t val, int len); 1150428527cSIsaku Yamahata 116821be9dbSKnut Omang /* ARI forwarding capability and control */ 117821be9dbSKnut Omang void pcie_cap_arifwd_init(PCIDevice *dev); 118821be9dbSKnut Omang void pcie_cap_arifwd_reset(PCIDevice *dev); 119821be9dbSKnut Omang bool pcie_cap_is_arifwd_enabled(const PCIDevice *dev); 1200428527cSIsaku Yamahata 1210428527cSIsaku Yamahata /* PCI express extended capability helper functions */ 1220428527cSIsaku Yamahata uint16_t pcie_find_capability(PCIDevice *dev, uint16_t cap_id); 1230428527cSIsaku Yamahata void pcie_add_capability(PCIDevice *dev, 1240428527cSIsaku Yamahata uint16_t cap_id, uint8_t cap_ver, 1250428527cSIsaku Yamahata uint16_t offset, uint16_t size); 1260428527cSIsaku Yamahata 1270428527cSIsaku Yamahata void pcie_ari_init(PCIDevice *dev, uint16_t offset, uint16_t nextfn); 128b56b9285SDmitry Fleytman void pcie_dev_ser_num_init(PCIDevice *dev, uint16_t offset, uint64_t ser_num); 129615c4ed2SJason Wang void pcie_ats_init(PCIDevice *dev, uint16_t offset); 1300428527cSIsaku Yamahata 131a66e657eSIgor Mammedov void pcie_cap_slot_hotplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, 132a66e657eSIgor Mammedov Error **errp); 13314d5a28fSIgor Mammedov void pcie_cap_slot_hot_unplug_request_cb(HotplugHandler *hotplug_dev, 13414d5a28fSIgor Mammedov DeviceState *dev, Error **errp); 1350428527cSIsaku Yamahata #endif /* QEMU_PCIE_H */ 136