]> git.proxmox.com Git - mirror_qemu.git/blame - hw/pci-bridge/ioh3420.c
vfio: make the 4 bytes aligned for capability size
[mirror_qemu.git] / hw / pci-bridge / ioh3420.c
CommitLineData
8135aeed
IY
1/*
2 * ioh3420.c
3 * Intel X58 north bridge IOH
4 * PCI Express root port device id 3420
5 *
6 * Copyright (c) 2010 Isaku Yamahata <yamahata at valinux co jp>
7 * VA Linux Systems Japan K.K.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, see <http://www.gnu.org/licenses/>.
21 */
22
97d5408f 23#include "qemu/osdep.h"
83c9f4ca
PB
24#include "hw/pci/pci_ids.h"
25#include "hw/pci/msi.h"
26#include "hw/pci/pcie.h"
47b43a1f 27#include "ioh3420.h"
8135aeed
IY
28
29#define PCI_DEVICE_ID_IOH_EPORT 0x3420 /* D0:F0 express mode */
30#define PCI_DEVICE_ID_IOH_REV 0x2
31#define IOH_EP_SSVID_OFFSET 0x40
32#define IOH_EP_SSVID_SVID PCI_VENDOR_ID_INTEL
33#define IOH_EP_SSVID_SSID 0
34#define IOH_EP_MSI_OFFSET 0x60
35#define IOH_EP_MSI_SUPPORTED_FLAGS PCI_MSI_FLAGS_MASKBIT
36#define IOH_EP_MSI_NR_VECTOR 2
37#define IOH_EP_EXP_OFFSET 0x90
38#define IOH_EP_AER_OFFSET 0x100
39
61620c2f
IY
40/*
41 * If two MSI vector are allocated, Advanced Error Interrupt Message Number
42 * is 1. otherwise 0.
43 * 17.12.5.10 RPERRSTS, 32:27 bit Advanced Error Interrupt Message Number.
44 */
45static uint8_t ioh3420_aer_vector(const PCIDevice *d)
46{
47 switch (msi_nr_vectors_allocated(d)) {
48 case 1:
49 return 0;
50 case 2:
51 return 1;
52 case 4:
53 case 8:
54 case 16:
55 case 32:
56 default:
57 break;
58 }
59 abort();
60 return 0;
61}
62
63static void ioh3420_aer_vector_update(PCIDevice *d)
64{
65 pcie_aer_root_set_vector(d, ioh3420_aer_vector(d));
66}
67
8135aeed
IY
68static void ioh3420_write_config(PCIDevice *d,
69 uint32_t address, uint32_t val, int len)
70{
61620c2f
IY
71 uint32_t root_cmd =
72 pci_get_long(d->config + d->exp.aer_cap + PCI_ERR_ROOT_COMMAND);
73
8135aeed 74 pci_bridge_write_config(d, address, val, len);
61620c2f 75 ioh3420_aer_vector_update(d);
6bde6aaa 76 pcie_cap_slot_write_config(d, address, val, len);
61620c2f
IY
77 pcie_aer_write_config(d, address, val, len);
78 pcie_aer_root_write_config(d, address, val, len, root_cmd);
8135aeed
IY
79}
80
81static void ioh3420_reset(DeviceState *qdev)
82{
40021f08 83 PCIDevice *d = PCI_DEVICE(qdev);
cbd2d434 84
61620c2f 85 ioh3420_aer_vector_update(d);
8135aeed
IY
86 pcie_cap_root_reset(d);
87 pcie_cap_deverr_reset(d);
88 pcie_cap_slot_reset(d);
a74b8702 89 pcie_cap_arifwd_reset(d);
61620c2f 90 pcie_aer_root_reset(d);
8135aeed
IY
91 pci_bridge_reset(qdev);
92 pci_bridge_disable_base_limit(d);
8135aeed
IY
93}
94
95static int ioh3420_initfn(PCIDevice *d)
96{
bcb75750
AF
97 PCIEPort *p = PCIE_PORT(d);
98 PCIESlot *s = PCIE_SLOT(d);
8135aeed
IY
99 int rc;
100
9cfaa007 101 pci_bridge_initfn(d, TYPE_PCIE_BUS);
8135aeed
IY
102 pcie_port_init_reg(d);
103
8135aeed
IY
104 rc = pci_bridge_ssvid_init(d, IOH_EP_SSVID_OFFSET,
105 IOH_EP_SSVID_SVID, IOH_EP_SSVID_SSID);
106 if (rc < 0) {
61620c2f 107 goto err_bridge;
8135aeed
IY
108 }
109 rc = msi_init(d, IOH_EP_MSI_OFFSET, IOH_EP_MSI_NR_VECTOR,
110 IOH_EP_MSI_SUPPORTED_FLAGS & PCI_MSI_FLAGS_64BIT,
111 IOH_EP_MSI_SUPPORTED_FLAGS & PCI_MSI_FLAGS_MASKBIT);
112 if (rc < 0) {
61620c2f 113 goto err_bridge;
8135aeed
IY
114 }
115 rc = pcie_cap_init(d, IOH_EP_EXP_OFFSET, PCI_EXP_TYPE_ROOT_PORT, p->port);
116 if (rc < 0) {
61620c2f 117 goto err_msi;
8135aeed 118 }
821be9db 119
a74b8702 120 pcie_cap_arifwd_init(d);
8135aeed
IY
121 pcie_cap_deverr_init(d);
122 pcie_cap_slot_init(d, s->slot);
123 pcie_chassis_create(s->chassis);
124 rc = pcie_chassis_add_slot(s);
125 if (rc < 0) {
61620c2f 126 goto err_pcie_cap;
8135aeed
IY
127 }
128 pcie_cap_root_init(d);
61620c2f
IY
129 rc = pcie_aer_init(d, IOH_EP_AER_OFFSET);
130 if (rc < 0) {
131 goto err;
132 }
133 pcie_aer_root_init(d);
134 ioh3420_aer_vector_update(d);
8135aeed 135 return 0;
61620c2f
IY
136
137err:
138 pcie_chassis_del_slot(s);
139err_pcie_cap:
140 pcie_cap_exit(d);
141err_msi:
142 msi_uninit(d);
143err_bridge:
f90c2bcd 144 pci_bridge_exitfn(d);
61620c2f 145 return rc;
8135aeed
IY
146}
147
f90c2bcd 148static void ioh3420_exitfn(PCIDevice *d)
8135aeed 149{
bcb75750 150 PCIESlot *s = PCIE_SLOT(d);
61620c2f
IY
151
152 pcie_aer_exit(d);
153 pcie_chassis_del_slot(s);
8135aeed 154 pcie_cap_exit(d);
61620c2f 155 msi_uninit(d);
f90c2bcd 156 pci_bridge_exitfn(d);
8135aeed
IY
157}
158
f23b6bdc
MA
159static Property ioh3420_props[] = {
160 DEFINE_PROP_BIT(COMPAT_PROP_PCP, PCIDevice, cap_present,
161 QEMU_PCIE_SLTCAP_PCP_BITNR, true),
162 DEFINE_PROP_END_OF_LIST()
163};
164
8135aeed
IY
165static const VMStateDescription vmstate_ioh3420 = {
166 .name = "ioh-3240-express-root-port",
167 .version_id = 1,
168 .minimum_version_id = 1,
6bde6aaa 169 .post_load = pcie_cap_slot_post_load,
8135aeed 170 .fields = (VMStateField[]) {
bcb75750
AF
171 VMSTATE_PCIE_DEVICE(parent_obj.parent_obj.parent_obj, PCIESlot),
172 VMSTATE_STRUCT(parent_obj.parent_obj.parent_obj.exp.aer_log,
173 PCIESlot, 0, vmstate_pcie_aer_log, PCIEAERLog),
8135aeed
IY
174 VMSTATE_END_OF_LIST()
175 }
176};
177
40021f08
AL
178static void ioh3420_class_init(ObjectClass *klass, void *data)
179{
39bffca2 180 DeviceClass *dc = DEVICE_CLASS(klass);
40021f08
AL
181 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
182
183 k->is_express = 1;
184 k->is_bridge = 1;
185 k->config_write = ioh3420_write_config;
186 k->init = ioh3420_initfn;
187 k->exit = ioh3420_exitfn;
188 k->vendor_id = PCI_VENDOR_ID_INTEL;
189 k->device_id = PCI_DEVICE_ID_IOH_EPORT;
190 k->revision = PCI_DEVICE_ID_IOH_REV;
125ee0ed 191 set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
39bffca2
AL
192 dc->desc = "Intel IOH device id 3420 PCIE Root Port";
193 dc->reset = ioh3420_reset;
194 dc->vmsd = &vmstate_ioh3420;
f23b6bdc 195 dc->props = ioh3420_props;
40021f08
AL
196}
197
8c43a6f0 198static const TypeInfo ioh3420_info = {
39bffca2 199 .name = "ioh3420",
bcb75750 200 .parent = TYPE_PCIE_SLOT,
39bffca2 201 .class_init = ioh3420_class_init,
8135aeed
IY
202};
203
83f7d43a 204static void ioh3420_register_types(void)
8135aeed 205{
39bffca2 206 type_register_static(&ioh3420_info);
8135aeed
IY
207}
208
83f7d43a 209type_init(ioh3420_register_types)
8135aeed
IY
210
211/*
212 * Local variables:
213 * c-indent-level: 4
214 * c-basic-offset: 4
215 * tab-width: 8
216 * indent-tab-mode: nil
217 * End:
218 */