Statistics
| Branch: | Revision:

root / hw / pci-bridge / xio3130_downstream.c @ f487b677

History | View | Annotate | Download (6.4 kB)

1 48ebf2f9 Isaku Yamahata
/*
2 48ebf2f9 Isaku Yamahata
 * x3130_downstream.c
3 48ebf2f9 Isaku Yamahata
 * TI X3130 pci express downstream port switch
4 48ebf2f9 Isaku Yamahata
 *
5 48ebf2f9 Isaku Yamahata
 * Copyright (c) 2010 Isaku Yamahata <yamahata at valinux co jp>
6 48ebf2f9 Isaku Yamahata
 *                    VA Linux Systems Japan K.K.
7 48ebf2f9 Isaku Yamahata
 *
8 48ebf2f9 Isaku Yamahata
 * This program is free software; you can redistribute it and/or modify
9 48ebf2f9 Isaku Yamahata
 * it under the terms of the GNU General Public License as published by
10 48ebf2f9 Isaku Yamahata
 * the Free Software Foundation; either version 2 of the License, or
11 48ebf2f9 Isaku Yamahata
 * (at your option) any later version.
12 48ebf2f9 Isaku Yamahata
 *
13 48ebf2f9 Isaku Yamahata
 * This program is distributed in the hope that it will be useful,
14 48ebf2f9 Isaku Yamahata
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 48ebf2f9 Isaku Yamahata
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 48ebf2f9 Isaku Yamahata
 * GNU General Public License for more details.
17 48ebf2f9 Isaku Yamahata
 *
18 48ebf2f9 Isaku Yamahata
 * You should have received a copy of the GNU General Public License along
19 48ebf2f9 Isaku Yamahata
 * with this program; if not, see <http://www.gnu.org/licenses/>.
20 48ebf2f9 Isaku Yamahata
 */
21 48ebf2f9 Isaku Yamahata
22 83c9f4ca Paolo Bonzini
#include "hw/pci/pci_ids.h"
23 83c9f4ca Paolo Bonzini
#include "hw/pci/msi.h"
24 83c9f4ca Paolo Bonzini
#include "hw/pci/pcie.h"
25 47b43a1f Paolo Bonzini
#include "xio3130_downstream.h"
26 48ebf2f9 Isaku Yamahata
27 48ebf2f9 Isaku Yamahata
#define PCI_DEVICE_ID_TI_XIO3130D       0x8233  /* downstream port */
28 48ebf2f9 Isaku Yamahata
#define XIO3130_REVISION                0x1
29 48ebf2f9 Isaku Yamahata
#define XIO3130_MSI_OFFSET              0x70
30 48ebf2f9 Isaku Yamahata
#define XIO3130_MSI_SUPPORTED_FLAGS     PCI_MSI_FLAGS_64BIT
31 48ebf2f9 Isaku Yamahata
#define XIO3130_MSI_NR_VECTOR           1
32 48ebf2f9 Isaku Yamahata
#define XIO3130_SSVID_OFFSET            0x80
33 48ebf2f9 Isaku Yamahata
#define XIO3130_SSVID_SVID              0
34 48ebf2f9 Isaku Yamahata
#define XIO3130_SSVID_SSID              0
35 48ebf2f9 Isaku Yamahata
#define XIO3130_EXP_OFFSET              0x90
36 48ebf2f9 Isaku Yamahata
#define XIO3130_AER_OFFSET              0x100
37 48ebf2f9 Isaku Yamahata
38 48ebf2f9 Isaku Yamahata
static void xio3130_downstream_write_config(PCIDevice *d, uint32_t address,
39 48ebf2f9 Isaku Yamahata
                                         uint32_t val, int len)
40 48ebf2f9 Isaku Yamahata
{
41 48ebf2f9 Isaku Yamahata
    pci_bridge_write_config(d, address, val, len);
42 48ebf2f9 Isaku Yamahata
    pcie_cap_flr_write_config(d, address, val, len);
43 6bde6aaa Michael S. Tsirkin
    pcie_cap_slot_write_config(d, address, val, len);
44 09b926d4 Isaku Yamahata
    pcie_aer_write_config(d, address, val, len);
45 48ebf2f9 Isaku Yamahata
}
46 48ebf2f9 Isaku Yamahata
47 48ebf2f9 Isaku Yamahata
static void xio3130_downstream_reset(DeviceState *qdev)
48 48ebf2f9 Isaku Yamahata
{
49 40021f08 Anthony Liguori
    PCIDevice *d = PCI_DEVICE(qdev);
50 cbd2d434 Jan Kiszka
51 48ebf2f9 Isaku Yamahata
    pcie_cap_deverr_reset(d);
52 48ebf2f9 Isaku Yamahata
    pcie_cap_slot_reset(d);
53 48ebf2f9 Isaku Yamahata
    pcie_cap_ari_reset(d);
54 48ebf2f9 Isaku Yamahata
    pci_bridge_reset(qdev);
55 48ebf2f9 Isaku Yamahata
}
56 48ebf2f9 Isaku Yamahata
57 48ebf2f9 Isaku Yamahata
static int xio3130_downstream_initfn(PCIDevice *d)
58 48ebf2f9 Isaku Yamahata
{
59 48ebf2f9 Isaku Yamahata
    PCIBridge* br = DO_UPCAST(PCIBridge, dev, d);
60 48ebf2f9 Isaku Yamahata
    PCIEPort *p = DO_UPCAST(PCIEPort, br, br);
61 48ebf2f9 Isaku Yamahata
    PCIESlot *s = DO_UPCAST(PCIESlot, port, p);
62 48ebf2f9 Isaku Yamahata
    int rc;
63 48ebf2f9 Isaku Yamahata
64 afb661eb Alex Williamson
    rc = pci_bridge_initfn(d, TYPE_PCIE_BUS);
65 48ebf2f9 Isaku Yamahata
    if (rc < 0) {
66 48ebf2f9 Isaku Yamahata
        return rc;
67 48ebf2f9 Isaku Yamahata
    }
68 48ebf2f9 Isaku Yamahata
69 48ebf2f9 Isaku Yamahata
    pcie_port_init_reg(d);
70 48ebf2f9 Isaku Yamahata
71 48ebf2f9 Isaku Yamahata
    rc = msi_init(d, XIO3130_MSI_OFFSET, XIO3130_MSI_NR_VECTOR,
72 48ebf2f9 Isaku Yamahata
                  XIO3130_MSI_SUPPORTED_FLAGS & PCI_MSI_FLAGS_64BIT,
73 48ebf2f9 Isaku Yamahata
                  XIO3130_MSI_SUPPORTED_FLAGS & PCI_MSI_FLAGS_MASKBIT);
74 48ebf2f9 Isaku Yamahata
    if (rc < 0) {
75 09b926d4 Isaku Yamahata
        goto err_bridge;
76 48ebf2f9 Isaku Yamahata
    }
77 48ebf2f9 Isaku Yamahata
    rc = pci_bridge_ssvid_init(d, XIO3130_SSVID_OFFSET,
78 48ebf2f9 Isaku Yamahata
                               XIO3130_SSVID_SVID, XIO3130_SSVID_SSID);
79 48ebf2f9 Isaku Yamahata
    if (rc < 0) {
80 09b926d4 Isaku Yamahata
        goto err_bridge;
81 48ebf2f9 Isaku Yamahata
    }
82 48ebf2f9 Isaku Yamahata
    rc = pcie_cap_init(d, XIO3130_EXP_OFFSET, PCI_EXP_TYPE_DOWNSTREAM,
83 48ebf2f9 Isaku Yamahata
                       p->port);
84 48ebf2f9 Isaku Yamahata
    if (rc < 0) {
85 09b926d4 Isaku Yamahata
        goto err_msi;
86 48ebf2f9 Isaku Yamahata
    }
87 0ead87c8 Isaku Yamahata
    pcie_cap_flr_init(d);
88 48ebf2f9 Isaku Yamahata
    pcie_cap_deverr_init(d);
89 48ebf2f9 Isaku Yamahata
    pcie_cap_slot_init(d, s->slot);
90 48ebf2f9 Isaku Yamahata
    pcie_chassis_create(s->chassis);
91 48ebf2f9 Isaku Yamahata
    rc = pcie_chassis_add_slot(s);
92 48ebf2f9 Isaku Yamahata
    if (rc < 0) {
93 09b926d4 Isaku Yamahata
        goto err_pcie_cap;
94 48ebf2f9 Isaku Yamahata
    }
95 48ebf2f9 Isaku Yamahata
    pcie_cap_ari_init(d);
96 09b926d4 Isaku Yamahata
    rc = pcie_aer_init(d, XIO3130_AER_OFFSET);
97 09b926d4 Isaku Yamahata
    if (rc < 0) {
98 09b926d4 Isaku Yamahata
        goto err;
99 09b926d4 Isaku Yamahata
    }
100 48ebf2f9 Isaku Yamahata
101 48ebf2f9 Isaku Yamahata
    return 0;
102 09b926d4 Isaku Yamahata
103 09b926d4 Isaku Yamahata
err:
104 09b926d4 Isaku Yamahata
    pcie_chassis_del_slot(s);
105 09b926d4 Isaku Yamahata
err_pcie_cap:
106 09b926d4 Isaku Yamahata
    pcie_cap_exit(d);
107 09b926d4 Isaku Yamahata
err_msi:
108 09b926d4 Isaku Yamahata
    msi_uninit(d);
109 09b926d4 Isaku Yamahata
err_bridge:
110 f90c2bcd Alex Williamson
    pci_bridge_exitfn(d);
111 09b926d4 Isaku Yamahata
    return rc;
112 48ebf2f9 Isaku Yamahata
}
113 48ebf2f9 Isaku Yamahata
114 f90c2bcd Alex Williamson
static void xio3130_downstream_exitfn(PCIDevice *d)
115 48ebf2f9 Isaku Yamahata
{
116 09b926d4 Isaku Yamahata
    PCIBridge* br = DO_UPCAST(PCIBridge, dev, d);
117 09b926d4 Isaku Yamahata
    PCIEPort *p = DO_UPCAST(PCIEPort, br, br);
118 09b926d4 Isaku Yamahata
    PCIESlot *s = DO_UPCAST(PCIESlot, port, p);
119 09b926d4 Isaku Yamahata
120 09b926d4 Isaku Yamahata
    pcie_aer_exit(d);
121 09b926d4 Isaku Yamahata
    pcie_chassis_del_slot(s);
122 48ebf2f9 Isaku Yamahata
    pcie_cap_exit(d);
123 09b926d4 Isaku Yamahata
    msi_uninit(d);
124 f90c2bcd Alex Williamson
    pci_bridge_exitfn(d);
125 48ebf2f9 Isaku Yamahata
}
126 48ebf2f9 Isaku Yamahata
127 48ebf2f9 Isaku Yamahata
PCIESlot *xio3130_downstream_init(PCIBus *bus, int devfn, bool multifunction,
128 48ebf2f9 Isaku Yamahata
                                  const char *bus_name, pci_map_irq_fn map_irq,
129 48ebf2f9 Isaku Yamahata
                                  uint8_t port, uint8_t chassis,
130 48ebf2f9 Isaku Yamahata
                                  uint16_t slot)
131 48ebf2f9 Isaku Yamahata
{
132 48ebf2f9 Isaku Yamahata
    PCIDevice *d;
133 48ebf2f9 Isaku Yamahata
    PCIBridge *br;
134 48ebf2f9 Isaku Yamahata
    DeviceState *qdev;
135 48ebf2f9 Isaku Yamahata
136 48ebf2f9 Isaku Yamahata
    d = pci_create_multifunction(bus, devfn, multifunction,
137 48ebf2f9 Isaku Yamahata
                                 "xio3130-downstream");
138 48ebf2f9 Isaku Yamahata
    if (!d) {
139 48ebf2f9 Isaku Yamahata
        return NULL;
140 48ebf2f9 Isaku Yamahata
    }
141 48ebf2f9 Isaku Yamahata
    br = DO_UPCAST(PCIBridge, dev, d);
142 48ebf2f9 Isaku Yamahata
143 48ebf2f9 Isaku Yamahata
    qdev = &br->dev.qdev;
144 48ebf2f9 Isaku Yamahata
    pci_bridge_map_irq(br, bus_name, map_irq);
145 48ebf2f9 Isaku Yamahata
    qdev_prop_set_uint8(qdev, "port", port);
146 48ebf2f9 Isaku Yamahata
    qdev_prop_set_uint8(qdev, "chassis", chassis);
147 48ebf2f9 Isaku Yamahata
    qdev_prop_set_uint16(qdev, "slot", slot);
148 48ebf2f9 Isaku Yamahata
    qdev_init_nofail(qdev);
149 48ebf2f9 Isaku Yamahata
150 48ebf2f9 Isaku Yamahata
    return DO_UPCAST(PCIESlot, port, DO_UPCAST(PCIEPort, br, br));
151 48ebf2f9 Isaku Yamahata
}
152 48ebf2f9 Isaku Yamahata
153 48ebf2f9 Isaku Yamahata
static const VMStateDescription vmstate_xio3130_downstream = {
154 48ebf2f9 Isaku Yamahata
    .name = "xio3130-express-downstream-port",
155 48ebf2f9 Isaku Yamahata
    .version_id = 1,
156 48ebf2f9 Isaku Yamahata
    .minimum_version_id = 1,
157 48ebf2f9 Isaku Yamahata
    .minimum_version_id_old = 1,
158 6bde6aaa Michael S. Tsirkin
    .post_load = pcie_cap_slot_post_load,
159 48ebf2f9 Isaku Yamahata
    .fields = (VMStateField[]) {
160 48ebf2f9 Isaku Yamahata
        VMSTATE_PCIE_DEVICE(port.br.dev, PCIESlot),
161 09b926d4 Isaku Yamahata
        VMSTATE_STRUCT(port.br.dev.exp.aer_log, PCIESlot, 0,
162 09b926d4 Isaku Yamahata
                       vmstate_pcie_aer_log, PCIEAERLog),
163 48ebf2f9 Isaku Yamahata
        VMSTATE_END_OF_LIST()
164 48ebf2f9 Isaku Yamahata
    }
165 48ebf2f9 Isaku Yamahata
};
166 48ebf2f9 Isaku Yamahata
167 40021f08 Anthony Liguori
static Property xio3130_downstream_properties[] = {
168 40021f08 Anthony Liguori
    DEFINE_PROP_UINT8("port", PCIESlot, port.port, 0),
169 40021f08 Anthony Liguori
    DEFINE_PROP_UINT8("chassis", PCIESlot, chassis, 0),
170 40021f08 Anthony Liguori
    DEFINE_PROP_UINT16("slot", PCIESlot, slot, 0),
171 40021f08 Anthony Liguori
    DEFINE_PROP_UINT16("aer_log_max", PCIESlot,
172 40021f08 Anthony Liguori
    port.br.dev.exp.aer_log.log_max,
173 40021f08 Anthony Liguori
    PCIE_AER_LOG_MAX_DEFAULT),
174 40021f08 Anthony Liguori
    DEFINE_PROP_END_OF_LIST(),
175 40021f08 Anthony Liguori
};
176 40021f08 Anthony Liguori
177 40021f08 Anthony Liguori
static void xio3130_downstream_class_init(ObjectClass *klass, void *data)
178 40021f08 Anthony Liguori
{
179 39bffca2 Anthony Liguori
    DeviceClass *dc = DEVICE_CLASS(klass);
180 40021f08 Anthony Liguori
    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
181 40021f08 Anthony Liguori
182 40021f08 Anthony Liguori
    k->is_express = 1;
183 40021f08 Anthony Liguori
    k->is_bridge = 1;
184 40021f08 Anthony Liguori
    k->config_write = xio3130_downstream_write_config;
185 40021f08 Anthony Liguori
    k->init = xio3130_downstream_initfn;
186 40021f08 Anthony Liguori
    k->exit = xio3130_downstream_exitfn;
187 40021f08 Anthony Liguori
    k->vendor_id = PCI_VENDOR_ID_TI;
188 40021f08 Anthony Liguori
    k->device_id = PCI_DEVICE_ID_TI_XIO3130D;
189 40021f08 Anthony Liguori
    k->revision = XIO3130_REVISION;
190 39bffca2 Anthony Liguori
    dc->desc = "TI X3130 Downstream Port of PCI Express Switch";
191 39bffca2 Anthony Liguori
    dc->reset = xio3130_downstream_reset;
192 39bffca2 Anthony Liguori
    dc->vmsd = &vmstate_xio3130_downstream;
193 39bffca2 Anthony Liguori
    dc->props = xio3130_downstream_properties;
194 40021f08 Anthony Liguori
}
195 40021f08 Anthony Liguori
196 8c43a6f0 Andreas Färber
static const TypeInfo xio3130_downstream_info = {
197 39bffca2 Anthony Liguori
    .name          = "xio3130-downstream",
198 39bffca2 Anthony Liguori
    .parent        = TYPE_PCI_DEVICE,
199 39bffca2 Anthony Liguori
    .instance_size = sizeof(PCIESlot),
200 39bffca2 Anthony Liguori
    .class_init    = xio3130_downstream_class_init,
201 48ebf2f9 Isaku Yamahata
};
202 48ebf2f9 Isaku Yamahata
203 83f7d43a Andreas Färber
static void xio3130_downstream_register_types(void)
204 48ebf2f9 Isaku Yamahata
{
205 39bffca2 Anthony Liguori
    type_register_static(&xio3130_downstream_info);
206 48ebf2f9 Isaku Yamahata
}
207 48ebf2f9 Isaku Yamahata
208 83f7d43a Andreas Färber
type_init(xio3130_downstream_register_types)
209 48ebf2f9 Isaku Yamahata
210 48ebf2f9 Isaku Yamahata
/*
211 48ebf2f9 Isaku Yamahata
 * Local variables:
212 48ebf2f9 Isaku Yamahata
 *  c-indent-level: 4
213 48ebf2f9 Isaku Yamahata
 *  c-basic-offset: 4
214 48ebf2f9 Isaku Yamahata
 *  tab-width: 8
215 48ebf2f9 Isaku Yamahata
 *  indent-tab-mode: nil
216 48ebf2f9 Isaku Yamahata
 * End:
217 48ebf2f9 Isaku Yamahata
 */