]> git.proxmox.com Git - qemu.git/blame - include/hw/pci/pcie.h
hw/pcie: AER and hot-plug events must use device's interrupt
[qemu.git] / include / hw / pci / pcie.h
CommitLineData
0428527c
IY
1/*
2 * pcie.h
3 *
4 * Copyright (c) 2010 Isaku Yamahata <yamahata at valinux co jp>
5 * VA Linux Systems Japan K.K.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifndef QEMU_PCIE_H
22#define QEMU_PCIE_H
23
c759b24f
MT
24#include "hw/hw.h"
25#include "hw/pci/pci_regs.h"
26#include "hw/pci/pcie_regs.h"
27#include "hw/pci/pcie_aer.h"
0428527c
IY
28
29typedef enum {
30 /* for attention and power indicator */
31 PCI_EXP_HP_IND_RESERVED = PCI_EXP_SLTCTL_IND_RESERVED,
32 PCI_EXP_HP_IND_ON = PCI_EXP_SLTCTL_IND_ON,
33 PCI_EXP_HP_IND_BLINK = PCI_EXP_SLTCTL_IND_BLINK,
34 PCI_EXP_HP_IND_OFF = PCI_EXP_SLTCTL_IND_OFF,
35} PCIExpressIndicator;
36
37typedef enum {
38 /* these bits must match the bits in Slot Control/Status registers.
39 * PCI_EXP_HP_EV_xxx = PCI_EXP_SLTCTL_xxxE = PCI_EXP_SLTSTA_xxx
40 *
41 * Not all the bits of slot control register match with the ones of
42 * slot status. Not some bits of slot status register is used to
a1c7273b 43 * show status, not to report event occurrence.
0428527c
IY
44 * So such bits must be masked out when checking the software
45 * notification condition.
46 */
47 PCI_EXP_HP_EV_ABP = PCI_EXP_SLTCTL_ABPE,
48 /* attention button pressed */
49 PCI_EXP_HP_EV_PDC = PCI_EXP_SLTCTL_PDCE,
50 /* presence detect changed */
51 PCI_EXP_HP_EV_CCI = PCI_EXP_SLTCTL_CCIE,
52 /* command completed */
53
54 PCI_EXP_HP_EV_SUPPORTED = PCI_EXP_HP_EV_ABP |
55 PCI_EXP_HP_EV_PDC |
56 PCI_EXP_HP_EV_CCI,
57 /* supported event mask */
58
59 /* events not listed aren't supported */
60} PCIExpressHotPlugEvent;
61
62struct PCIExpressDevice {
63 /* Offset of express capability in config space */
64 uint8_t exp_cap;
65
0428527c 66 /* SLOT */
6bde6aaa
MT
67 bool hpev_notified; /* Logical AND of conditions for hot plug event.
68 Following 6.7.3.4:
69 Software Notification of Hot-Plug Events, an interrupt
70 is sent whenever the logical and of these conditions
71 transitions from false to true. */
34e65944
IY
72
73 /* AER */
74 uint16_t aer_cap;
75 PCIEAERLog aer_log;
0428527c
IY
76};
77
78/* PCI express capability helper functions */
79int pcie_cap_init(PCIDevice *dev, uint8_t offset, uint8_t type, uint8_t port);
6214e73c 80int pcie_endpoint_cap_init(PCIDevice *dev, uint8_t offset);
0428527c
IY
81void pcie_cap_exit(PCIDevice *dev);
82uint8_t pcie_cap_get_type(const PCIDevice *dev);
83void pcie_cap_flags_set_vector(PCIDevice *dev, uint8_t vector);
84uint8_t pcie_cap_flags_get_vector(PCIDevice *dev);
85
86void pcie_cap_deverr_init(PCIDevice *dev);
87void pcie_cap_deverr_reset(PCIDevice *dev);
88
89void pcie_cap_slot_init(PCIDevice *dev, uint16_t slot);
90void pcie_cap_slot_reset(PCIDevice *dev);
91void pcie_cap_slot_write_config(PCIDevice *dev,
6bde6aaa
MT
92 uint32_t addr, uint32_t val, int len);
93int pcie_cap_slot_post_load(void *opaque, int version_id);
0428527c
IY
94void pcie_cap_slot_push_attention_button(PCIDevice *dev);
95
96void pcie_cap_root_init(PCIDevice *dev);
97void pcie_cap_root_reset(PCIDevice *dev);
98
99void pcie_cap_flr_init(PCIDevice *dev);
100void pcie_cap_flr_write_config(PCIDevice *dev,
101 uint32_t addr, uint32_t val, int len);
102
103void pcie_cap_ari_init(PCIDevice *dev);
104void pcie_cap_ari_reset(PCIDevice *dev);
105bool pcie_cap_is_ari_enabled(const PCIDevice *dev);
106
107/* PCI express extended capability helper functions */
108uint16_t pcie_find_capability(PCIDevice *dev, uint16_t cap_id);
109void pcie_add_capability(PCIDevice *dev,
110 uint16_t cap_id, uint8_t cap_ver,
111 uint16_t offset, uint16_t size);
112
113void pcie_ari_init(PCIDevice *dev, uint16_t offset, uint16_t nextfn);
114
701a8f76
PB
115extern const VMStateDescription vmstate_pcie_device;
116
117#define VMSTATE_PCIE_DEVICE(_field, _state) { \
118 .name = (stringify(_field)), \
701a8f76
PB
119 .size = sizeof(PCIDevice), \
120 .vmsd = &vmstate_pcie_device, \
121 .flags = VMS_STRUCT, \
122 .offset = vmstate_offset_value(_state, _field, PCIDevice), \
123}
124
0428527c 125#endif /* QEMU_PCIE_H */