Statistics
| Branch: | Revision:

root / hw / pci / pcie_port.c @ 34b5d2c6

History | View | Annotate | Download (4.7 kB)

1 bc20ba98 Isaku Yamahata
/*
2 bc20ba98 Isaku Yamahata
 * pcie_port.c
3 bc20ba98 Isaku Yamahata
 *
4 bc20ba98 Isaku Yamahata
 * Copyright (c) 2010 Isaku Yamahata <yamahata at valinux co jp>
5 bc20ba98 Isaku Yamahata
 *                    VA Linux Systems Japan K.K.
6 bc20ba98 Isaku Yamahata
 *
7 bc20ba98 Isaku Yamahata
 * This program is free software; you can redistribute it and/or modify
8 bc20ba98 Isaku Yamahata
 * it under the terms of the GNU General Public License as published by
9 bc20ba98 Isaku Yamahata
 * the Free Software Foundation; either version 2 of the License, or
10 bc20ba98 Isaku Yamahata
 * (at your option) any later version.
11 bc20ba98 Isaku Yamahata
 *
12 bc20ba98 Isaku Yamahata
 * This program is distributed in the hope that it will be useful,
13 bc20ba98 Isaku Yamahata
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 bc20ba98 Isaku Yamahata
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 bc20ba98 Isaku Yamahata
 * GNU General Public License for more details.
16 bc20ba98 Isaku Yamahata
 *
17 bc20ba98 Isaku Yamahata
 * You should have received a copy of the GNU General Public License along
18 bc20ba98 Isaku Yamahata
 * with this program; if not, see <http://www.gnu.org/licenses/>.
19 bc20ba98 Isaku Yamahata
 */
20 bc20ba98 Isaku Yamahata
21 c759b24f Michael S. Tsirkin
#include "hw/pci/pcie_port.h"
22 bc20ba98 Isaku Yamahata
23 bc20ba98 Isaku Yamahata
void pcie_port_init_reg(PCIDevice *d)
24 bc20ba98 Isaku Yamahata
{
25 bc20ba98 Isaku Yamahata
    /* Unlike pci bridge,
26 bc20ba98 Isaku Yamahata
       66MHz and fast back to back don't apply to pci express port. */
27 bc20ba98 Isaku Yamahata
    pci_set_word(d->config + PCI_STATUS, 0);
28 bc20ba98 Isaku Yamahata
    pci_set_word(d->config + PCI_SEC_STATUS, 0);
29 bc20ba98 Isaku Yamahata
30 45eb768c Michael S. Tsirkin
    /*
31 45eb768c Michael S. Tsirkin
     * Unlike conventional pci bridge, for some bits the spec states:
32 45eb768c Michael S. Tsirkin
     * Does not apply to PCI Express and must be hardwired to 0.
33 45eb768c Michael S. Tsirkin
     */
34 45eb768c Michael S. Tsirkin
    pci_word_test_and_clear_mask(d->wmask + PCI_BRIDGE_CONTROL,
35 45eb768c Michael S. Tsirkin
                                 PCI_BRIDGE_CTL_MASTER_ABORT |
36 45eb768c Michael S. Tsirkin
                                 PCI_BRIDGE_CTL_FAST_BACK |
37 45eb768c Michael S. Tsirkin
                                 PCI_BRIDGE_CTL_DISCARD |
38 45eb768c Michael S. Tsirkin
                                 PCI_BRIDGE_CTL_SEC_DISCARD |
39 45eb768c Michael S. Tsirkin
                                 PCI_BRIDGE_CTL_DISCARD_STATUS |
40 45eb768c Michael S. Tsirkin
                                 PCI_BRIDGE_CTL_DISCARD_SERR);
41 bc20ba98 Isaku Yamahata
}
42 bc20ba98 Isaku Yamahata
43 bc20ba98 Isaku Yamahata
/**************************************************************************
44 bc20ba98 Isaku Yamahata
 * (chassis number, pcie physical slot number) -> pcie slot conversion
45 bc20ba98 Isaku Yamahata
 */
46 bc20ba98 Isaku Yamahata
struct PCIEChassis {
47 bc20ba98 Isaku Yamahata
    uint8_t     number;
48 bc20ba98 Isaku Yamahata
49 bc20ba98 Isaku Yamahata
    QLIST_HEAD(, PCIESlot) slots;
50 bc20ba98 Isaku Yamahata
    QLIST_ENTRY(PCIEChassis) next;
51 bc20ba98 Isaku Yamahata
};
52 bc20ba98 Isaku Yamahata
53 bc20ba98 Isaku Yamahata
static QLIST_HEAD(, PCIEChassis) chassis = QLIST_HEAD_INITIALIZER(chassis);
54 bc20ba98 Isaku Yamahata
55 bc20ba98 Isaku Yamahata
static struct PCIEChassis *pcie_chassis_find(uint8_t chassis_number)
56 bc20ba98 Isaku Yamahata
{
57 bc20ba98 Isaku Yamahata
    struct PCIEChassis *c;
58 bc20ba98 Isaku Yamahata
    QLIST_FOREACH(c, &chassis, next) {
59 bc20ba98 Isaku Yamahata
        if (c->number == chassis_number) {
60 bc20ba98 Isaku Yamahata
            break;
61 bc20ba98 Isaku Yamahata
        }
62 bc20ba98 Isaku Yamahata
    }
63 bc20ba98 Isaku Yamahata
    return c;
64 bc20ba98 Isaku Yamahata
}
65 bc20ba98 Isaku Yamahata
66 bc20ba98 Isaku Yamahata
void pcie_chassis_create(uint8_t chassis_number)
67 bc20ba98 Isaku Yamahata
{
68 bc20ba98 Isaku Yamahata
    struct PCIEChassis *c;
69 bc20ba98 Isaku Yamahata
    c = pcie_chassis_find(chassis_number);
70 bc20ba98 Isaku Yamahata
    if (c) {
71 bc20ba98 Isaku Yamahata
        return;
72 bc20ba98 Isaku Yamahata
    }
73 7267c094 Anthony Liguori
    c = g_malloc0(sizeof(*c));
74 bc20ba98 Isaku Yamahata
    c->number = chassis_number;
75 bc20ba98 Isaku Yamahata
    QLIST_INIT(&c->slots);
76 bc20ba98 Isaku Yamahata
    QLIST_INSERT_HEAD(&chassis, c, next);
77 bc20ba98 Isaku Yamahata
}
78 bc20ba98 Isaku Yamahata
79 bc20ba98 Isaku Yamahata
static PCIESlot *pcie_chassis_find_slot_with_chassis(struct PCIEChassis *c,
80 bc20ba98 Isaku Yamahata
                                                     uint8_t slot)
81 bc20ba98 Isaku Yamahata
{
82 bc20ba98 Isaku Yamahata
    PCIESlot *s;
83 bc20ba98 Isaku Yamahata
    QLIST_FOREACH(s, &c->slots, next) {
84 bc20ba98 Isaku Yamahata
        if (s->slot == slot) {
85 bc20ba98 Isaku Yamahata
            break;
86 bc20ba98 Isaku Yamahata
        }
87 bc20ba98 Isaku Yamahata
    }
88 bc20ba98 Isaku Yamahata
    return s;
89 bc20ba98 Isaku Yamahata
}
90 bc20ba98 Isaku Yamahata
91 bc20ba98 Isaku Yamahata
PCIESlot *pcie_chassis_find_slot(uint8_t chassis_number, uint16_t slot)
92 bc20ba98 Isaku Yamahata
{
93 bc20ba98 Isaku Yamahata
    struct PCIEChassis *c;
94 bc20ba98 Isaku Yamahata
    c = pcie_chassis_find(chassis_number);
95 bc20ba98 Isaku Yamahata
    if (!c) {
96 bc20ba98 Isaku Yamahata
        return NULL;
97 bc20ba98 Isaku Yamahata
    }
98 bc20ba98 Isaku Yamahata
    return pcie_chassis_find_slot_with_chassis(c, slot);
99 bc20ba98 Isaku Yamahata
}
100 bc20ba98 Isaku Yamahata
101 bc20ba98 Isaku Yamahata
int pcie_chassis_add_slot(struct PCIESlot *slot)
102 bc20ba98 Isaku Yamahata
{
103 bc20ba98 Isaku Yamahata
    struct PCIEChassis *c;
104 bc20ba98 Isaku Yamahata
    c = pcie_chassis_find(slot->chassis);
105 bc20ba98 Isaku Yamahata
    if (!c) {
106 bc20ba98 Isaku Yamahata
        return -ENODEV;
107 bc20ba98 Isaku Yamahata
    }
108 bc20ba98 Isaku Yamahata
    if (pcie_chassis_find_slot_with_chassis(c, slot->slot)) {
109 bc20ba98 Isaku Yamahata
        return -EBUSY;
110 bc20ba98 Isaku Yamahata
    }
111 bc20ba98 Isaku Yamahata
    QLIST_INSERT_HEAD(&c->slots, slot, next);
112 bc20ba98 Isaku Yamahata
    return 0;
113 bc20ba98 Isaku Yamahata
}
114 bc20ba98 Isaku Yamahata
115 bc20ba98 Isaku Yamahata
void pcie_chassis_del_slot(PCIESlot *s)
116 bc20ba98 Isaku Yamahata
{
117 bc20ba98 Isaku Yamahata
    QLIST_REMOVE(s, next);
118 bc20ba98 Isaku Yamahata
}
119 bcb75750 Andreas Färber
120 bcb75750 Andreas Färber
static Property pcie_port_props[] = {
121 bcb75750 Andreas Färber
    DEFINE_PROP_UINT8("port", PCIEPort, port, 0),
122 bcb75750 Andreas Färber
    DEFINE_PROP_UINT16("aer_log_max", PCIEPort,
123 bcb75750 Andreas Färber
                       parent_obj.parent_obj.exp.aer_log.log_max,
124 bcb75750 Andreas Färber
                       PCIE_AER_LOG_MAX_DEFAULT),
125 bcb75750 Andreas Färber
    DEFINE_PROP_END_OF_LIST()
126 bcb75750 Andreas Färber
};
127 bcb75750 Andreas Färber
128 bcb75750 Andreas Färber
static void pcie_port_class_init(ObjectClass *oc, void *data)
129 bcb75750 Andreas Färber
{
130 bcb75750 Andreas Färber
    DeviceClass *dc = DEVICE_CLASS(oc);
131 bcb75750 Andreas Färber
132 bcb75750 Andreas Färber
    dc->props = pcie_port_props;
133 bcb75750 Andreas Färber
}
134 bcb75750 Andreas Färber
135 bcb75750 Andreas Färber
static const TypeInfo pcie_port_type_info = {
136 bcb75750 Andreas Färber
    .name = TYPE_PCIE_PORT,
137 bcb75750 Andreas Färber
    .parent = TYPE_PCI_BRIDGE,
138 bcb75750 Andreas Färber
    .instance_size = sizeof(PCIEPort),
139 bcb75750 Andreas Färber
    .abstract = true,
140 bcb75750 Andreas Färber
    .class_init = pcie_port_class_init,
141 bcb75750 Andreas Färber
};
142 bcb75750 Andreas Färber
143 bcb75750 Andreas Färber
static Property pcie_slot_props[] = {
144 bcb75750 Andreas Färber
    DEFINE_PROP_UINT8("chassis", PCIESlot, chassis, 0),
145 bcb75750 Andreas Färber
    DEFINE_PROP_UINT16("slot", PCIESlot, slot, 0),
146 bcb75750 Andreas Färber
    DEFINE_PROP_END_OF_LIST()
147 bcb75750 Andreas Färber
};
148 bcb75750 Andreas Färber
149 bcb75750 Andreas Färber
static void pcie_slot_class_init(ObjectClass *oc, void *data)
150 bcb75750 Andreas Färber
{
151 bcb75750 Andreas Färber
    DeviceClass *dc = DEVICE_CLASS(oc);
152 bcb75750 Andreas Färber
153 bcb75750 Andreas Färber
    dc->props = pcie_slot_props;
154 bcb75750 Andreas Färber
}
155 bcb75750 Andreas Färber
156 bcb75750 Andreas Färber
static const TypeInfo pcie_slot_type_info = {
157 bcb75750 Andreas Färber
    .name = TYPE_PCIE_SLOT,
158 bcb75750 Andreas Färber
    .parent = TYPE_PCIE_PORT,
159 bcb75750 Andreas Färber
    .instance_size = sizeof(PCIESlot),
160 bcb75750 Andreas Färber
    .abstract = true,
161 bcb75750 Andreas Färber
    .class_init = pcie_slot_class_init,
162 bcb75750 Andreas Färber
};
163 bcb75750 Andreas Färber
164 bcb75750 Andreas Färber
static void pcie_port_register_types(void)
165 bcb75750 Andreas Färber
{
166 bcb75750 Andreas Färber
    type_register_static(&pcie_port_type_info);
167 bcb75750 Andreas Färber
    type_register_static(&pcie_slot_type_info);
168 bcb75750 Andreas Färber
}
169 bcb75750 Andreas Färber
170 bcb75750 Andreas Färber
type_init(pcie_port_register_types)