xref: /openbmc/qemu/include/hw/pci/pcie_aer.h (revision d4c453f64824bbeec56c7e72aa83019a7db70d9e)
10d09e41aSPaolo Bonzini /*
20d09e41aSPaolo Bonzini  * pcie_aer.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_AER_H
220d09e41aSPaolo Bonzini #define QEMU_PCIE_AER_H
230d09e41aSPaolo Bonzini 
24ec150c7eSMarkus Armbruster #include "hw/pci/pci_regs.h"
250d09e41aSPaolo Bonzini 
260d09e41aSPaolo Bonzini /* definitions which PCIExpressDevice uses */
270d09e41aSPaolo Bonzini 
28*fe5943feSPaolo Bonzini /* error */
29*fe5943feSPaolo Bonzini typedef struct PCIEAERErr {
30*fe5943feSPaolo Bonzini     uint32_t status;    /* error status bits */
31*fe5943feSPaolo Bonzini     uint16_t source_id; /* bdf */
32*fe5943feSPaolo Bonzini 
33*fe5943feSPaolo Bonzini #define PCIE_AER_ERR_IS_CORRECTABLE     0x1     /* correctable/uncorrectable */
34*fe5943feSPaolo Bonzini #define PCIE_AER_ERR_MAYBE_ADVISORY     0x2     /* maybe advisory non-fatal */
35*fe5943feSPaolo Bonzini #define PCIE_AER_ERR_HEADER_VALID       0x4     /* TLP header is logged */
36*fe5943feSPaolo Bonzini #define PCIE_AER_ERR_TLP_PREFIX_PRESENT 0x8     /* TLP Prefix is logged */
37*fe5943feSPaolo Bonzini     uint16_t flags;
38*fe5943feSPaolo Bonzini 
39*fe5943feSPaolo Bonzini     uint32_t header[4]; /* TLP header */
40*fe5943feSPaolo Bonzini     uint32_t prefix[4]; /* TLP header prefix */
41*fe5943feSPaolo Bonzini } PCIEAERErr;
42*fe5943feSPaolo Bonzini 
430d09e41aSPaolo Bonzini /* AER log */
44*fe5943feSPaolo Bonzini typedef struct PCIEAERLog {
450d09e41aSPaolo Bonzini     /* This structure is saved/loaded.
460d09e41aSPaolo Bonzini        So explicitly size them instead of unsigned int */
470d09e41aSPaolo Bonzini 
480d09e41aSPaolo Bonzini     /* the number of currently recorded log in log member */
490d09e41aSPaolo Bonzini     uint16_t log_num;
500d09e41aSPaolo Bonzini 
510d09e41aSPaolo Bonzini     /*
520d09e41aSPaolo Bonzini      * The maximum number of the log. Errors can be logged up to this.
530d09e41aSPaolo Bonzini      *
540d09e41aSPaolo Bonzini      * This is configurable property.
550d09e41aSPaolo Bonzini      * The specified value will be clipped down to PCIE_AER_LOG_MAX_LIMIT
560d09e41aSPaolo Bonzini      * to avoid unreasonable memory usage.
570d09e41aSPaolo Bonzini      * I bet that 128 log size would be big enough, otherwise too many errors
58a1a62cedSMichael Tokarev      * for system to function normally. But could consecutive errors occur?
590d09e41aSPaolo Bonzini      */
600d09e41aSPaolo Bonzini #define PCIE_AER_LOG_MAX_DEFAULT        8
610d09e41aSPaolo Bonzini #define PCIE_AER_LOG_MAX_LIMIT          128
620d09e41aSPaolo Bonzini     uint16_t log_max;
630d09e41aSPaolo Bonzini 
640d09e41aSPaolo Bonzini     /* Error log. log_max-sized array */
650d09e41aSPaolo Bonzini     PCIEAERErr *log;
66*fe5943feSPaolo Bonzini } PCIEAERLog;
670d09e41aSPaolo Bonzini 
6898a2f30aSChen Fan /* aer error message: error signaling message has only error severity and
690d09e41aSPaolo Bonzini    source id. See 2.2.8.3 error signaling messages */
70*fe5943feSPaolo Bonzini typedef struct PCIEAERMsg {
710d09e41aSPaolo Bonzini     /*
720d09e41aSPaolo Bonzini      * PCI_ERR_ROOT_CMD_{COR, NONFATAL, FATAL}_EN
730d09e41aSPaolo Bonzini      * = PCI_EXP_DEVCTL_{CERE, NFERE, FERE}
740d09e41aSPaolo Bonzini      */
750d09e41aSPaolo Bonzini     uint32_t severity;
760d09e41aSPaolo Bonzini 
770d09e41aSPaolo Bonzini     uint16_t source_id; /* bdf */
78*fe5943feSPaolo Bonzini } PCIEAERMsg;
790d09e41aSPaolo Bonzini 
800d09e41aSPaolo Bonzini static inline bool
pcie_aer_msg_is_uncor(const PCIEAERMsg * msg)810d09e41aSPaolo Bonzini pcie_aer_msg_is_uncor(const PCIEAERMsg *msg)
820d09e41aSPaolo Bonzini {
830d09e41aSPaolo Bonzini     return msg->severity == PCI_ERR_ROOT_CMD_NONFATAL_EN ||
840d09e41aSPaolo Bonzini         msg->severity == PCI_ERR_ROOT_CMD_FATAL_EN;
850d09e41aSPaolo Bonzini }
860d09e41aSPaolo Bonzini 
870d09e41aSPaolo Bonzini extern const VMStateDescription vmstate_pcie_aer_log;
880d09e41aSPaolo Bonzini 
89f18c697bSDou Liyang int pcie_aer_init(PCIDevice *dev, uint8_t cap_ver, uint16_t offset,
90f18c697bSDou Liyang                   uint16_t size, Error **errp);
910d09e41aSPaolo Bonzini void pcie_aer_exit(PCIDevice *dev);
920d09e41aSPaolo Bonzini void pcie_aer_write_config(PCIDevice *dev,
930d09e41aSPaolo Bonzini                            uint32_t addr, uint32_t val, int len);
940d09e41aSPaolo Bonzini 
950d09e41aSPaolo Bonzini /* aer root port */
960d09e41aSPaolo Bonzini void pcie_aer_root_set_vector(PCIDevice *dev, unsigned int vector);
970d09e41aSPaolo Bonzini void pcie_aer_root_init(PCIDevice *dev);
980d09e41aSPaolo Bonzini void pcie_aer_root_reset(PCIDevice *dev);
990d09e41aSPaolo Bonzini void pcie_aer_root_write_config(PCIDevice *dev,
1000d09e41aSPaolo Bonzini                                 uint32_t addr, uint32_t val, int len,
1010d09e41aSPaolo Bonzini                                 uint32_t root_cmd_prev);
1020d09e41aSPaolo Bonzini 
1034a295211SJonathan Cameron int pcie_aer_inject_error(PCIDevice *dev, const PCIEAERErr *err);
1040d09e41aSPaolo Bonzini #endif /* QEMU_PCIE_AER_H */
105