Statistics
| Branch: | Revision:

root / hw / pcie.h @ 8ca209ad

History | View | Annotate | Download (4.8 kB)

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