| 
									
										
										
										
											2010-10-19 18:06:34 +09:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * pcie.h | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright (c) 2010 Isaku Yamahata <yamahata at valinux co jp> | 
					
						
							|  |  |  |  *                    VA Linux Systems Japan K.K. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or modify | 
					
						
							|  |  |  |  * it under the terms of the GNU General Public License as published by | 
					
						
							|  |  |  |  * the Free Software Foundation; either version 2 of the License, or | 
					
						
							|  |  |  |  * (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License along | 
					
						
							|  |  |  |  * with this program; if not, see <http://www.gnu.org/licenses/>.
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef QEMU_PCIE_H
 | 
					
						
							|  |  |  | #define QEMU_PCIE_H
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-12 23:05:42 +02:00
										 |  |  | #include "hw/pci/pci_regs.h"
 | 
					
						
							|  |  |  | #include "hw/pci/pcie_regs.h"
 | 
					
						
							|  |  |  | #include "hw/pci/pcie_aer.h"
 | 
					
						
							| 
									
										
										
										
											2022-02-17 18:44:50 +01:00
										 |  |  | #include "hw/pci/pcie_sriov.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-05 16:36:51 +01:00
										 |  |  | #include "hw/hotplug.h"
 | 
					
						
							| 
									
										
										
										
											2010-10-19 18:06:34 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-02 17:17:04 +02:00
										 |  |  | typedef struct PCIEPort PCIEPort; | 
					
						
							|  |  |  | typedef struct PCIESlot PCIESlot; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-19 18:06:34 +09:00
										 |  |  | typedef enum { | 
					
						
							|  |  |  |     /* these bits must match the bits in Slot Control/Status registers.
 | 
					
						
							|  |  |  |      * PCI_EXP_HP_EV_xxx = PCI_EXP_SLTCTL_xxxE = PCI_EXP_SLTSTA_xxx | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * Not all the bits of slot control register match with the ones of | 
					
						
							|  |  |  |      * slot status. Not some bits of slot status register is used to | 
					
						
							| 
									
										
										
										
											2011-04-28 17:20:38 +02:00
										 |  |  |      * show status, not to report event occurrence. | 
					
						
							| 
									
										
										
										
											2010-10-19 18:06:34 +09:00
										 |  |  |      * So such bits must be masked out when checking the software | 
					
						
							|  |  |  |      * notification condition. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     PCI_EXP_HP_EV_ABP           = PCI_EXP_SLTCTL_ABPE, | 
					
						
							|  |  |  |                                         /* attention button pressed */ | 
					
						
							|  |  |  |     PCI_EXP_HP_EV_PDC           = PCI_EXP_SLTCTL_PDCE, | 
					
						
							|  |  |  |                                         /* presence detect changed */ | 
					
						
							|  |  |  |     PCI_EXP_HP_EV_CCI           = PCI_EXP_SLTCTL_CCIE, | 
					
						
							|  |  |  |                                         /* command completed */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     PCI_EXP_HP_EV_SUPPORTED     = PCI_EXP_HP_EV_ABP | | 
					
						
							|  |  |  |                                   PCI_EXP_HP_EV_PDC | | 
					
						
							|  |  |  |                                   PCI_EXP_HP_EV_CCI, | 
					
						
							|  |  |  |                                                 /* supported event mask  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* events not listed aren't supported */ | 
					
						
							|  |  |  | } PCIExpressHotPlugEvent; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct PCIExpressDevice { | 
					
						
							|  |  |  |     /* Offset of express capability in config space */ | 
					
						
							|  |  |  |     uint8_t exp_cap; | 
					
						
							| 
									
										
										
										
											2017-02-20 22:43:13 +02:00
										 |  |  |     /* Offset of Power Management capability in config space */ | 
					
						
							|  |  |  |     uint8_t pm_cap; | 
					
						
							| 
									
										
										
										
											2010-10-19 18:06:34 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /* SLOT */ | 
					
						
							| 
									
										
										
										
											2010-10-25 07:46:47 +02:00
										 |  |  |     bool hpev_notified; /* Logical AND of conditions for hot plug event.
 | 
					
						
							|  |  |  |                          Following 6.7.3.4: | 
					
						
							|  |  |  |                          Software Notification of Hot-Plug Events, an interrupt | 
					
						
							|  |  |  |                          is sent whenever the logical and of these conditions | 
					
						
							|  |  |  |                          transitions from false to true. */ | 
					
						
							| 
									
										
										
										
											2010-11-16 17:26:09 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /* AER */ | 
					
						
							|  |  |  |     uint16_t aer_cap; | 
					
						
							|  |  |  |     PCIEAERLog aer_log; | 
					
						
							| 
									
										
										
										
											2016-12-30 18:09:15 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /* Offset of ATS capability in config space */ | 
					
						
							|  |  |  |     uint16_t ats_cap; | 
					
						
							| 
									
										
										
										
											2019-02-21 19:13:22 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /* ACS */ | 
					
						
							|  |  |  |     uint16_t acs_cap; | 
					
						
							| 
									
										
										
										
											2022-02-17 18:44:50 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /* SR/IOV */ | 
					
						
							|  |  |  |     uint16_t sriov_cap; | 
					
						
							|  |  |  |     PCIESriovPF sriov_pf; | 
					
						
							|  |  |  |     PCIESriovVF sriov_vf; | 
					
						
							| 
									
										
										
										
											2010-10-19 18:06:34 +09:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-23 17:32:48 +03:00
										 |  |  | #define COMPAT_PROP_PCP "power_controller_present"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-19 18:06:34 +09:00
										 |  |  | /* PCI express capability helper functions */ | 
					
						
							| 
									
										
										
										
											2017-06-27 14:16:52 +08:00
										 |  |  | int pcie_cap_init(PCIDevice *dev, uint8_t offset, uint8_t type, | 
					
						
							|  |  |  |                   uint8_t port, Error **errp); | 
					
						
							| 
									
										
										
										
											2016-06-01 11:23:33 +03:00
										 |  |  | int pcie_cap_v1_init(PCIDevice *dev, uint8_t offset, | 
					
						
							|  |  |  |                      uint8_t type, uint8_t port); | 
					
						
							| 
									
										
										
										
											2013-03-19 12:11:24 -06:00
										 |  |  | int pcie_endpoint_cap_init(PCIDevice *dev, uint8_t offset); | 
					
						
							| 
									
										
										
										
											2010-10-19 18:06:34 +09:00
										 |  |  | void pcie_cap_exit(PCIDevice *dev); | 
					
						
							| 
									
										
										
										
											2016-06-01 11:23:33 +03:00
										 |  |  | int pcie_endpoint_cap_v1_init(PCIDevice *dev, uint8_t offset); | 
					
						
							|  |  |  | void pcie_cap_v1_exit(PCIDevice *dev); | 
					
						
							| 
									
										
										
										
											2010-10-19 18:06:34 +09:00
										 |  |  | uint8_t pcie_cap_get_type(const PCIDevice *dev); | 
					
						
							| 
									
										
										
										
											2023-05-26 17:15:57 -06:00
										 |  |  | uint8_t pcie_cap_get_version(const PCIDevice *dev); | 
					
						
							| 
									
										
										
										
											2010-10-19 18:06:34 +09:00
										 |  |  | void pcie_cap_flags_set_vector(PCIDevice *dev, uint8_t vector); | 
					
						
							|  |  |  | uint8_t pcie_cap_flags_get_vector(PCIDevice *dev); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void pcie_cap_deverr_init(PCIDevice *dev); | 
					
						
							|  |  |  | void pcie_cap_deverr_reset(PCIDevice *dev); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-20 22:43:12 +02:00
										 |  |  | void pcie_cap_lnkctl_init(PCIDevice *dev); | 
					
						
							|  |  |  | void pcie_cap_lnkctl_reset(PCIDevice *dev); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-26 18:46:07 +01:00
										 |  |  | void pcie_cap_slot_init(PCIDevice *dev, PCIESlot *s); | 
					
						
							| 
									
										
										
										
											2010-10-19 18:06:34 +09:00
										 |  |  | void pcie_cap_slot_reset(PCIDevice *dev); | 
					
						
							| 
									
										
										
										
											2019-07-11 15:25:50 -04:00
										 |  |  | void pcie_cap_slot_get(PCIDevice *dev, uint16_t *slt_ctl, uint16_t *slt_sta); | 
					
						
							| 
									
										
										
										
											2019-07-01 05:29:51 -04:00
										 |  |  | void pcie_cap_slot_write_config(PCIDevice *dev, | 
					
						
							| 
									
										
										
										
											2019-07-11 15:25:50 -04:00
										 |  |  |                                 uint16_t old_slt_ctl, uint16_t old_slt_sta, | 
					
						
							| 
									
										
										
										
											2010-10-25 07:46:47 +02:00
										 |  |  |                                 uint32_t addr, uint32_t val, int len); | 
					
						
							|  |  |  | int pcie_cap_slot_post_load(void *opaque, int version_id); | 
					
						
							| 
									
										
										
										
											2010-10-19 18:06:34 +09:00
										 |  |  | void pcie_cap_slot_push_attention_button(PCIDevice *dev); | 
					
						
							| 
									
										
										
										
											2022-03-01 10:11:59 -05:00
										 |  |  | void pcie_cap_slot_enable_power(PCIDevice *dev); | 
					
						
							| 
									
										
										
										
											2010-10-19 18:06:34 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  | void pcie_cap_root_init(PCIDevice *dev); | 
					
						
							|  |  |  | void pcie_cap_root_reset(PCIDevice *dev); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void pcie_cap_flr_init(PCIDevice *dev); | 
					
						
							|  |  |  | void pcie_cap_flr_write_config(PCIDevice *dev, | 
					
						
							|  |  |  |                            uint32_t addr, uint32_t val, int len); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-24 15:32:18 +02:00
										 |  |  | /* ARI forwarding capability and control */ | 
					
						
							|  |  |  | void pcie_cap_arifwd_init(PCIDevice *dev); | 
					
						
							|  |  |  | void pcie_cap_arifwd_reset(PCIDevice *dev); | 
					
						
							|  |  |  | bool pcie_cap_is_arifwd_enabled(const PCIDevice *dev); | 
					
						
							| 
									
										
										
										
											2010-10-19 18:06:34 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* PCI express extended capability helper functions */ | 
					
						
							|  |  |  | uint16_t pcie_find_capability(PCIDevice *dev, uint16_t cap_id); | 
					
						
							|  |  |  | void pcie_add_capability(PCIDevice *dev, | 
					
						
							|  |  |  |                          uint16_t cap_id, uint8_t cap_ver, | 
					
						
							|  |  |  |                          uint16_t offset, uint16_t size); | 
					
						
							| 
									
										
										
										
											2018-12-12 12:38:55 -07:00
										 |  |  | void pcie_sync_bridge_lnk(PCIDevice *dev); | 
					
						
							| 
									
										
										
										
											2010-10-19 18:06:34 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-21 19:13:22 +01:00
										 |  |  | void pcie_acs_init(PCIDevice *dev, uint16_t offset); | 
					
						
							|  |  |  | void pcie_acs_reset(PCIDevice *dev); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-11 00:38:35 +09:00
										 |  |  | void pcie_ari_init(PCIDevice *dev, uint16_t offset); | 
					
						
							| 
									
										
										
										
											2016-06-01 11:23:34 +03:00
										 |  |  | void pcie_dev_ser_num_init(PCIDevice *dev, uint16_t offset, uint64_t ser_num); | 
					
						
							| 
									
										
										
										
											2021-04-06 12:03:30 +08:00
										 |  |  | void pcie_ats_init(PCIDevice *dev, uint16_t offset, bool aligned); | 
					
						
							| 
									
										
										
										
											2010-10-19 18:06:34 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-12 10:16:16 +01:00
										 |  |  | void pcie_cap_slot_pre_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, | 
					
						
							|  |  |  |                                Error **errp); | 
					
						
							| 
									
										
										
										
											2018-12-12 10:16:13 +01:00
										 |  |  | void pcie_cap_slot_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, | 
					
						
							|  |  |  |                            Error **errp); | 
					
						
							| 
									
										
										
										
											2018-12-12 10:16:20 +01:00
										 |  |  | void pcie_cap_slot_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, | 
					
						
							|  |  |  |                              Error **errp); | 
					
						
							| 
									
										
										
										
											2018-12-12 10:16:13 +01:00
										 |  |  | void pcie_cap_slot_unplug_request_cb(HotplugHandler *hotplug_dev, | 
					
						
							|  |  |  |                                      DeviceState *dev, Error **errp); | 
					
						
							| 
									
										
										
										
											2010-10-19 18:06:34 +09:00
										 |  |  | #endif /* QEMU_PCIE_H */
 |