Statistics
| Branch: | Revision:

root / hw / ioh3420.c @ f5654039

History | View | Annotate | Download (6.8 kB)

1 8135aeed Isaku Yamahata
/*
2 8135aeed Isaku Yamahata
 * ioh3420.c
3 8135aeed Isaku Yamahata
 * Intel X58 north bridge IOH
4 8135aeed Isaku Yamahata
 * PCI Express root port device id 3420
5 8135aeed Isaku Yamahata
 *
6 8135aeed Isaku Yamahata
 * Copyright (c) 2010 Isaku Yamahata <yamahata at valinux co jp>
7 8135aeed Isaku Yamahata
 *                    VA Linux Systems Japan K.K.
8 8135aeed Isaku Yamahata
 *
9 8135aeed Isaku Yamahata
 * This program is free software; you can redistribute it and/or modify
10 8135aeed Isaku Yamahata
 * it under the terms of the GNU General Public License as published by
11 8135aeed Isaku Yamahata
 * the Free Software Foundation; either version 2 of the License, or
12 8135aeed Isaku Yamahata
 * (at your option) any later version.
13 8135aeed Isaku Yamahata
 *
14 8135aeed Isaku Yamahata
 * This program is distributed in the hope that it will be useful,
15 8135aeed Isaku Yamahata
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 8135aeed Isaku Yamahata
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 8135aeed Isaku Yamahata
 * GNU General Public License for more details.
18 8135aeed Isaku Yamahata
 *
19 8135aeed Isaku Yamahata
 * You should have received a copy of the GNU General Public License along
20 8135aeed Isaku Yamahata
 * with this program; if not, see <http://www.gnu.org/licenses/>.
21 8135aeed Isaku Yamahata
 */
22 8135aeed Isaku Yamahata
23 8135aeed Isaku Yamahata
#include "pci_ids.h"
24 8135aeed Isaku Yamahata
#include "msi.h"
25 8135aeed Isaku Yamahata
#include "pcie.h"
26 8135aeed Isaku Yamahata
#include "ioh3420.h"
27 8135aeed Isaku Yamahata
28 8135aeed Isaku Yamahata
#define PCI_DEVICE_ID_IOH_EPORT         0x3420  /* D0:F0 express mode */
29 8135aeed Isaku Yamahata
#define PCI_DEVICE_ID_IOH_REV           0x2
30 8135aeed Isaku Yamahata
#define IOH_EP_SSVID_OFFSET             0x40
31 8135aeed Isaku Yamahata
#define IOH_EP_SSVID_SVID               PCI_VENDOR_ID_INTEL
32 8135aeed Isaku Yamahata
#define IOH_EP_SSVID_SSID               0
33 8135aeed Isaku Yamahata
#define IOH_EP_MSI_OFFSET               0x60
34 8135aeed Isaku Yamahata
#define IOH_EP_MSI_SUPPORTED_FLAGS      PCI_MSI_FLAGS_MASKBIT
35 8135aeed Isaku Yamahata
#define IOH_EP_MSI_NR_VECTOR            2
36 8135aeed Isaku Yamahata
#define IOH_EP_EXP_OFFSET               0x90
37 8135aeed Isaku Yamahata
#define IOH_EP_AER_OFFSET               0x100
38 8135aeed Isaku Yamahata
39 61620c2f Isaku Yamahata
/*
40 61620c2f Isaku Yamahata
 * If two MSI vector are allocated, Advanced Error Interrupt Message Number
41 61620c2f Isaku Yamahata
 * is 1. otherwise 0.
42 61620c2f Isaku Yamahata
 * 17.12.5.10 RPERRSTS,  32:27 bit Advanced Error Interrupt Message Number.
43 61620c2f Isaku Yamahata
 */
44 61620c2f Isaku Yamahata
static uint8_t ioh3420_aer_vector(const PCIDevice *d)
45 61620c2f Isaku Yamahata
{
46 61620c2f Isaku Yamahata
    switch (msi_nr_vectors_allocated(d)) {
47 61620c2f Isaku Yamahata
    case 1:
48 61620c2f Isaku Yamahata
        return 0;
49 61620c2f Isaku Yamahata
    case 2:
50 61620c2f Isaku Yamahata
        return 1;
51 61620c2f Isaku Yamahata
    case 4:
52 61620c2f Isaku Yamahata
    case 8:
53 61620c2f Isaku Yamahata
    case 16:
54 61620c2f Isaku Yamahata
    case 32:
55 61620c2f Isaku Yamahata
    default:
56 61620c2f Isaku Yamahata
        break;
57 61620c2f Isaku Yamahata
    }
58 61620c2f Isaku Yamahata
    abort();
59 61620c2f Isaku Yamahata
    return 0;
60 61620c2f Isaku Yamahata
}
61 61620c2f Isaku Yamahata
62 61620c2f Isaku Yamahata
static void ioh3420_aer_vector_update(PCIDevice *d)
63 61620c2f Isaku Yamahata
{
64 61620c2f Isaku Yamahata
    pcie_aer_root_set_vector(d, ioh3420_aer_vector(d));
65 61620c2f Isaku Yamahata
}
66 61620c2f Isaku Yamahata
67 8135aeed Isaku Yamahata
static void ioh3420_write_config(PCIDevice *d,
68 8135aeed Isaku Yamahata
                                   uint32_t address, uint32_t val, int len)
69 8135aeed Isaku Yamahata
{
70 61620c2f Isaku Yamahata
    uint32_t root_cmd =
71 61620c2f Isaku Yamahata
        pci_get_long(d->config + d->exp.aer_cap + PCI_ERR_ROOT_COMMAND);
72 61620c2f Isaku Yamahata
73 8135aeed Isaku Yamahata
    pci_bridge_write_config(d, address, val, len);
74 8135aeed Isaku Yamahata
    msi_write_config(d, address, val, len);
75 61620c2f Isaku Yamahata
    ioh3420_aer_vector_update(d);
76 6bde6aaa Michael S. Tsirkin
    pcie_cap_slot_write_config(d, address, val, len);
77 61620c2f Isaku Yamahata
    pcie_aer_write_config(d, address, val, len);
78 61620c2f Isaku Yamahata
    pcie_aer_root_write_config(d, address, val, len, root_cmd);
79 8135aeed Isaku Yamahata
}
80 8135aeed Isaku Yamahata
81 8135aeed Isaku Yamahata
static void ioh3420_reset(DeviceState *qdev)
82 8135aeed Isaku Yamahata
{
83 8135aeed Isaku Yamahata
    PCIDevice *d = DO_UPCAST(PCIDevice, qdev, qdev);
84 8135aeed Isaku Yamahata
    msi_reset(d);
85 61620c2f Isaku Yamahata
    ioh3420_aer_vector_update(d);
86 8135aeed Isaku Yamahata
    pcie_cap_root_reset(d);
87 8135aeed Isaku Yamahata
    pcie_cap_deverr_reset(d);
88 8135aeed Isaku Yamahata
    pcie_cap_slot_reset(d);
89 61620c2f Isaku Yamahata
    pcie_aer_root_reset(d);
90 8135aeed Isaku Yamahata
    pci_bridge_reset(qdev);
91 8135aeed Isaku Yamahata
    pci_bridge_disable_base_limit(d);
92 8135aeed Isaku Yamahata
}
93 8135aeed Isaku Yamahata
94 8135aeed Isaku Yamahata
static int ioh3420_initfn(PCIDevice *d)
95 8135aeed Isaku Yamahata
{
96 8135aeed Isaku Yamahata
    PCIBridge* br = DO_UPCAST(PCIBridge, dev, d);
97 8135aeed Isaku Yamahata
    PCIEPort *p = DO_UPCAST(PCIEPort, br, br);
98 8135aeed Isaku Yamahata
    PCIESlot *s = DO_UPCAST(PCIESlot, port, p);
99 8135aeed Isaku Yamahata
    int rc;
100 61620c2f Isaku Yamahata
    int tmp;
101 8135aeed Isaku Yamahata
102 8135aeed Isaku Yamahata
    rc = pci_bridge_initfn(d);
103 8135aeed Isaku Yamahata
    if (rc < 0) {
104 8135aeed Isaku Yamahata
        return rc;
105 8135aeed Isaku Yamahata
    }
106 8135aeed Isaku Yamahata
107 8135aeed Isaku Yamahata
    pcie_port_init_reg(d);
108 8135aeed Isaku Yamahata
109 8135aeed Isaku Yamahata
    rc = pci_bridge_ssvid_init(d, IOH_EP_SSVID_OFFSET,
110 8135aeed Isaku Yamahata
                               IOH_EP_SSVID_SVID, IOH_EP_SSVID_SSID);
111 8135aeed Isaku Yamahata
    if (rc < 0) {
112 61620c2f Isaku Yamahata
        goto err_bridge;
113 8135aeed Isaku Yamahata
    }
114 8135aeed Isaku Yamahata
    rc = msi_init(d, IOH_EP_MSI_OFFSET, IOH_EP_MSI_NR_VECTOR,
115 8135aeed Isaku Yamahata
                  IOH_EP_MSI_SUPPORTED_FLAGS & PCI_MSI_FLAGS_64BIT,
116 8135aeed Isaku Yamahata
                  IOH_EP_MSI_SUPPORTED_FLAGS & PCI_MSI_FLAGS_MASKBIT);
117 8135aeed Isaku Yamahata
    if (rc < 0) {
118 61620c2f Isaku Yamahata
        goto err_bridge;
119 8135aeed Isaku Yamahata
    }
120 8135aeed Isaku Yamahata
    rc = pcie_cap_init(d, IOH_EP_EXP_OFFSET, PCI_EXP_TYPE_ROOT_PORT, p->port);
121 8135aeed Isaku Yamahata
    if (rc < 0) {
122 61620c2f Isaku Yamahata
        goto err_msi;
123 8135aeed Isaku Yamahata
    }
124 8135aeed Isaku Yamahata
    pcie_cap_deverr_init(d);
125 8135aeed Isaku Yamahata
    pcie_cap_slot_init(d, s->slot);
126 8135aeed Isaku Yamahata
    pcie_chassis_create(s->chassis);
127 8135aeed Isaku Yamahata
    rc = pcie_chassis_add_slot(s);
128 8135aeed Isaku Yamahata
    if (rc < 0) {
129 61620c2f Isaku Yamahata
        goto err_pcie_cap;
130 8135aeed Isaku Yamahata
        return rc;
131 8135aeed Isaku Yamahata
    }
132 8135aeed Isaku Yamahata
    pcie_cap_root_init(d);
133 61620c2f Isaku Yamahata
    rc = pcie_aer_init(d, IOH_EP_AER_OFFSET);
134 61620c2f Isaku Yamahata
    if (rc < 0) {
135 61620c2f Isaku Yamahata
        goto err;
136 61620c2f Isaku Yamahata
    }
137 61620c2f Isaku Yamahata
    pcie_aer_root_init(d);
138 61620c2f Isaku Yamahata
    ioh3420_aer_vector_update(d);
139 8135aeed Isaku Yamahata
    return 0;
140 61620c2f Isaku Yamahata
141 61620c2f Isaku Yamahata
err:
142 61620c2f Isaku Yamahata
    pcie_chassis_del_slot(s);
143 61620c2f Isaku Yamahata
err_pcie_cap:
144 61620c2f Isaku Yamahata
    pcie_cap_exit(d);
145 61620c2f Isaku Yamahata
err_msi:
146 61620c2f Isaku Yamahata
    msi_uninit(d);
147 61620c2f Isaku Yamahata
err_bridge:
148 61620c2f Isaku Yamahata
    tmp = pci_bridge_exitfn(d);
149 61620c2f Isaku Yamahata
    assert(!tmp);
150 61620c2f Isaku Yamahata
    return rc;
151 8135aeed Isaku Yamahata
}
152 8135aeed Isaku Yamahata
153 8135aeed Isaku Yamahata
static int ioh3420_exitfn(PCIDevice *d)
154 8135aeed Isaku Yamahata
{
155 61620c2f Isaku Yamahata
    PCIBridge* br = DO_UPCAST(PCIBridge, dev, d);
156 61620c2f Isaku Yamahata
    PCIEPort *p = DO_UPCAST(PCIEPort, br, br);
157 61620c2f Isaku Yamahata
    PCIESlot *s = DO_UPCAST(PCIESlot, port, p);
158 61620c2f Isaku Yamahata
159 61620c2f Isaku Yamahata
    pcie_aer_exit(d);
160 61620c2f Isaku Yamahata
    pcie_chassis_del_slot(s);
161 8135aeed Isaku Yamahata
    pcie_cap_exit(d);
162 61620c2f Isaku Yamahata
    msi_uninit(d);
163 8135aeed Isaku Yamahata
    return pci_bridge_exitfn(d);
164 8135aeed Isaku Yamahata
}
165 8135aeed Isaku Yamahata
166 8135aeed Isaku Yamahata
PCIESlot *ioh3420_init(PCIBus *bus, int devfn, bool multifunction,
167 8135aeed Isaku Yamahata
                         const char *bus_name, pci_map_irq_fn map_irq,
168 8135aeed Isaku Yamahata
                         uint8_t port, uint8_t chassis, uint16_t slot)
169 8135aeed Isaku Yamahata
{
170 8135aeed Isaku Yamahata
    PCIDevice *d;
171 8135aeed Isaku Yamahata
    PCIBridge *br;
172 8135aeed Isaku Yamahata
    DeviceState *qdev;
173 8135aeed Isaku Yamahata
174 8135aeed Isaku Yamahata
    d = pci_create_multifunction(bus, devfn, multifunction, "ioh3420");
175 8135aeed Isaku Yamahata
    if (!d) {
176 8135aeed Isaku Yamahata
        return NULL;
177 8135aeed Isaku Yamahata
    }
178 8135aeed Isaku Yamahata
    br = DO_UPCAST(PCIBridge, dev, d);
179 8135aeed Isaku Yamahata
180 8135aeed Isaku Yamahata
    qdev = &br->dev.qdev;
181 8135aeed Isaku Yamahata
    pci_bridge_map_irq(br, bus_name, map_irq);
182 8135aeed Isaku Yamahata
    qdev_prop_set_uint8(qdev, "port", port);
183 8135aeed Isaku Yamahata
    qdev_prop_set_uint8(qdev, "chassis", chassis);
184 8135aeed Isaku Yamahata
    qdev_prop_set_uint16(qdev, "slot", slot);
185 8135aeed Isaku Yamahata
    qdev_init_nofail(qdev);
186 8135aeed Isaku Yamahata
187 8135aeed Isaku Yamahata
    return DO_UPCAST(PCIESlot, port, DO_UPCAST(PCIEPort, br, br));
188 8135aeed Isaku Yamahata
}
189 8135aeed Isaku Yamahata
190 8135aeed Isaku Yamahata
static const VMStateDescription vmstate_ioh3420 = {
191 8135aeed Isaku Yamahata
    .name = "ioh-3240-express-root-port",
192 8135aeed Isaku Yamahata
    .version_id = 1,
193 8135aeed Isaku Yamahata
    .minimum_version_id = 1,
194 8135aeed Isaku Yamahata
    .minimum_version_id_old = 1,
195 6bde6aaa Michael S. Tsirkin
    .post_load = pcie_cap_slot_post_load,
196 8135aeed Isaku Yamahata
    .fields = (VMStateField[]) {
197 8135aeed Isaku Yamahata
        VMSTATE_PCIE_DEVICE(port.br.dev, PCIESlot),
198 61620c2f Isaku Yamahata
        VMSTATE_STRUCT(port.br.dev.exp.aer_log, PCIESlot, 0,
199 61620c2f Isaku Yamahata
                       vmstate_pcie_aer_log, PCIEAERLog),
200 8135aeed Isaku Yamahata
        VMSTATE_END_OF_LIST()
201 8135aeed Isaku Yamahata
    }
202 8135aeed Isaku Yamahata
};
203 8135aeed Isaku Yamahata
204 8135aeed Isaku Yamahata
static PCIDeviceInfo ioh3420_info = {
205 8135aeed Isaku Yamahata
    .qdev.name = "ioh3420",
206 8135aeed Isaku Yamahata
    .qdev.desc = "Intel IOH device id 3420 PCIE Root Port",
207 8135aeed Isaku Yamahata
    .qdev.size = sizeof(PCIESlot),
208 8135aeed Isaku Yamahata
    .qdev.reset = ioh3420_reset,
209 8135aeed Isaku Yamahata
    .qdev.vmsd = &vmstate_ioh3420,
210 8135aeed Isaku Yamahata
211 8135aeed Isaku Yamahata
    .is_express = 1,
212 8135aeed Isaku Yamahata
    .is_bridge = 1,
213 8135aeed Isaku Yamahata
    .config_write = ioh3420_write_config,
214 8135aeed Isaku Yamahata
    .init = ioh3420_initfn,
215 8135aeed Isaku Yamahata
    .exit = ioh3420_exitfn,
216 3d0b1e70 Isaku Yamahata
    .vendor_id = PCI_VENDOR_ID_INTEL,
217 3d0b1e70 Isaku Yamahata
    .device_id = PCI_DEVICE_ID_IOH_EPORT,
218 3d0b1e70 Isaku Yamahata
    .revision = PCI_DEVICE_ID_IOH_REV,
219 8135aeed Isaku Yamahata
220 8135aeed Isaku Yamahata
    .qdev.props = (Property[]) {
221 8135aeed Isaku Yamahata
        DEFINE_PROP_UINT8("port", PCIESlot, port.port, 0),
222 8135aeed Isaku Yamahata
        DEFINE_PROP_UINT8("chassis", PCIESlot, chassis, 0),
223 8135aeed Isaku Yamahata
        DEFINE_PROP_UINT16("slot", PCIESlot, slot, 0),
224 61620c2f Isaku Yamahata
        DEFINE_PROP_UINT16("aer_log_max", PCIESlot,
225 61620c2f Isaku Yamahata
                           port.br.dev.exp.aer_log.log_max,
226 61620c2f Isaku Yamahata
                           PCIE_AER_LOG_MAX_DEFAULT),
227 8135aeed Isaku Yamahata
        DEFINE_PROP_END_OF_LIST(),
228 8135aeed Isaku Yamahata
    }
229 8135aeed Isaku Yamahata
};
230 8135aeed Isaku Yamahata
231 8135aeed Isaku Yamahata
static void ioh3420_register(void)
232 8135aeed Isaku Yamahata
{
233 8135aeed Isaku Yamahata
    pci_qdev_register(&ioh3420_info);
234 8135aeed Isaku Yamahata
}
235 8135aeed Isaku Yamahata
236 8135aeed Isaku Yamahata
device_init(ioh3420_register);
237 8135aeed Isaku Yamahata
238 8135aeed Isaku Yamahata
/*
239 8135aeed Isaku Yamahata
 * Local variables:
240 8135aeed Isaku Yamahata
 *  c-indent-level: 4
241 8135aeed Isaku Yamahata
 *  c-basic-offset: 4
242 8135aeed Isaku Yamahata
 *  tab-width: 8
243 8135aeed Isaku Yamahata
 *  indent-tab-mode: nil
244 8135aeed Isaku Yamahata
 * End:
245 8135aeed Isaku Yamahata
 */