Statistics
| Branch: | Revision:

root / include / hw / pci / pcie_aer.h @ f487b677

History | View | Annotate | Download (3.4 kB)

1 34e65944 Isaku Yamahata
/*
2 34e65944 Isaku Yamahata
 * pcie_aer.h
3 34e65944 Isaku Yamahata
 *
4 34e65944 Isaku Yamahata
 * Copyright (c) 2010 Isaku Yamahata <yamahata at valinux co jp>
5 34e65944 Isaku Yamahata
 *                    VA Linux Systems Japan K.K.
6 34e65944 Isaku Yamahata
 *
7 34e65944 Isaku Yamahata
 * This program is free software; you can redistribute it and/or modify
8 34e65944 Isaku Yamahata
 * it under the terms of the GNU General Public License as published by
9 34e65944 Isaku Yamahata
 * the Free Software Foundation; either version 2 of the License, or
10 34e65944 Isaku Yamahata
 * (at your option) any later version.
11 34e65944 Isaku Yamahata
 *
12 34e65944 Isaku Yamahata
 * This program is distributed in the hope that it will be useful,
13 34e65944 Isaku Yamahata
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 34e65944 Isaku Yamahata
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 34e65944 Isaku Yamahata
 * GNU General Public License for more details.
16 34e65944 Isaku Yamahata
 *
17 34e65944 Isaku Yamahata
 * You should have received a copy of the GNU General Public License along
18 34e65944 Isaku Yamahata
 * with this program; if not, see <http://www.gnu.org/licenses/>.
19 34e65944 Isaku Yamahata
 */
20 34e65944 Isaku Yamahata
21 34e65944 Isaku Yamahata
#ifndef QEMU_PCIE_AER_H
22 34e65944 Isaku Yamahata
#define QEMU_PCIE_AER_H
23 34e65944 Isaku Yamahata
24 c759b24f Michael S. Tsirkin
#include "hw/hw.h"
25 34e65944 Isaku Yamahata
26 34e65944 Isaku Yamahata
/* definitions which PCIExpressDevice uses */
27 34e65944 Isaku Yamahata
28 34e65944 Isaku Yamahata
/* AER log */
29 34e65944 Isaku Yamahata
struct PCIEAERLog {
30 34e65944 Isaku Yamahata
    /* This structure is saved/loaded.
31 34e65944 Isaku Yamahata
       So explicitly size them instead of unsigned int */
32 34e65944 Isaku Yamahata
33 34e65944 Isaku Yamahata
    /* the number of currently recorded log in log member */
34 34e65944 Isaku Yamahata
    uint16_t log_num;
35 34e65944 Isaku Yamahata
36 34e65944 Isaku Yamahata
    /*
37 34e65944 Isaku Yamahata
     * The maximum number of the log. Errors can be logged up to this.
38 34e65944 Isaku Yamahata
     *
39 34e65944 Isaku Yamahata
     * This is configurable property.
40 34e65944 Isaku Yamahata
     * The specified value will be clipped down to PCIE_AER_LOG_MAX_LIMIT
41 34e65944 Isaku Yamahata
     * to avoid unreasonable memory usage.
42 34e65944 Isaku Yamahata
     * I bet that 128 log size would be big enough, otherwise too many errors
43 34e65944 Isaku Yamahata
     * for system to function normaly. But could consecutive errors occur?
44 34e65944 Isaku Yamahata
     */
45 34e65944 Isaku Yamahata
#define PCIE_AER_LOG_MAX_DEFAULT        8
46 34e65944 Isaku Yamahata
#define PCIE_AER_LOG_MAX_LIMIT          128
47 34e65944 Isaku Yamahata
#define PCIE_AER_LOG_MAX_UNSET          0xffff
48 34e65944 Isaku Yamahata
    uint16_t log_max;
49 34e65944 Isaku Yamahata
50 34e65944 Isaku Yamahata
    /* Error log. log_max-sized array */
51 34e65944 Isaku Yamahata
    PCIEAERErr *log;
52 34e65944 Isaku Yamahata
};
53 34e65944 Isaku Yamahata
54 34e65944 Isaku Yamahata
/* aer error message: error signaling message has only error sevirity and
55 34e65944 Isaku Yamahata
   source id. See 2.2.8.3 error signaling messages */
56 34e65944 Isaku Yamahata
struct PCIEAERMsg {
57 34e65944 Isaku Yamahata
    /*
58 34e65944 Isaku Yamahata
     * PCI_ERR_ROOT_CMD_{COR, NONFATAL, FATAL}_EN
59 34e65944 Isaku Yamahata
     * = PCI_EXP_DEVCTL_{CERE, NFERE, FERE}
60 34e65944 Isaku Yamahata
     */
61 34e65944 Isaku Yamahata
    uint32_t severity;
62 34e65944 Isaku Yamahata
63 34e65944 Isaku Yamahata
    uint16_t source_id; /* bdf */
64 34e65944 Isaku Yamahata
};
65 34e65944 Isaku Yamahata
66 34e65944 Isaku Yamahata
static inline bool
67 34e65944 Isaku Yamahata
pcie_aer_msg_is_uncor(const PCIEAERMsg *msg)
68 34e65944 Isaku Yamahata
{
69 34e65944 Isaku Yamahata
    return msg->severity == PCI_ERR_ROOT_CMD_NONFATAL_EN ||
70 34e65944 Isaku Yamahata
        msg->severity == PCI_ERR_ROOT_CMD_FATAL_EN;
71 34e65944 Isaku Yamahata
}
72 34e65944 Isaku Yamahata
73 34e65944 Isaku Yamahata
/* error */
74 34e65944 Isaku Yamahata
struct PCIEAERErr {
75 34e65944 Isaku Yamahata
    uint32_t status;    /* error status bits */
76 34e65944 Isaku Yamahata
    uint16_t source_id; /* bdf */
77 34e65944 Isaku Yamahata
78 34e65944 Isaku Yamahata
#define PCIE_AER_ERR_IS_CORRECTABLE     0x1     /* correctable/uncorrectable */
79 34e65944 Isaku Yamahata
#define PCIE_AER_ERR_MAYBE_ADVISORY     0x2     /* maybe advisory non-fatal */
80 34e65944 Isaku Yamahata
#define PCIE_AER_ERR_HEADER_VALID       0x4     /* TLP header is logged */
81 34e65944 Isaku Yamahata
#define PCIE_AER_ERR_TLP_PREFIX_PRESENT 0x8     /* TLP Prefix is logged */
82 34e65944 Isaku Yamahata
    uint16_t flags;
83 34e65944 Isaku Yamahata
84 34e65944 Isaku Yamahata
    uint32_t header[4]; /* TLP header */
85 34e65944 Isaku Yamahata
    uint32_t prefix[4]; /* TLP header prefix */
86 34e65944 Isaku Yamahata
};
87 34e65944 Isaku Yamahata
88 34e65944 Isaku Yamahata
extern const VMStateDescription vmstate_pcie_aer_log;
89 34e65944 Isaku Yamahata
90 34e65944 Isaku Yamahata
int pcie_aer_init(PCIDevice *dev, uint16_t offset);
91 34e65944 Isaku Yamahata
void pcie_aer_exit(PCIDevice *dev);
92 34e65944 Isaku Yamahata
void pcie_aer_write_config(PCIDevice *dev,
93 34e65944 Isaku Yamahata
                           uint32_t addr, uint32_t val, int len);
94 34e65944 Isaku Yamahata
95 34e65944 Isaku Yamahata
/* aer root port */
96 34e65944 Isaku Yamahata
void pcie_aer_root_set_vector(PCIDevice *dev, unsigned int vector);
97 34e65944 Isaku Yamahata
void pcie_aer_root_init(PCIDevice *dev);
98 34e65944 Isaku Yamahata
void pcie_aer_root_reset(PCIDevice *dev);
99 34e65944 Isaku Yamahata
void pcie_aer_root_write_config(PCIDevice *dev,
100 34e65944 Isaku Yamahata
                                uint32_t addr, uint32_t val, int len,
101 34e65944 Isaku Yamahata
                                uint32_t root_cmd_prev);
102 34e65944 Isaku Yamahata
103 34e65944 Isaku Yamahata
/* error injection */
104 34e65944 Isaku Yamahata
int pcie_aer_inject_error(PCIDevice *dev, const PCIEAERErr *err);
105 34e65944 Isaku Yamahata
106 34e65944 Isaku Yamahata
#endif /* QEMU_PCIE_AER_H */