vmxnet3: remove unnecessary internal msi state flag
[qemu.git] / hw / pci-bridge / ioh3420.c
blob93c6f0b7a2dd3dda5a58cf5bc69c1cac8f7b5a5d
1 /*
2 * ioh3420.c
3 * Intel X58 north bridge IOH
4 * PCI Express root port device id 3420
6 * Copyright (c) 2010 Isaku Yamahata <yamahata at valinux co jp>
7 * VA Linux Systems Japan K.K.
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.
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.
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/>.
23 #include "qemu/osdep.h"
24 #include "hw/pci/pci_ids.h"
25 #include "hw/pci/msi.h"
26 #include "hw/pci/pcie.h"
27 #include "ioh3420.h"
28 #include "qapi/error.h"
30 #define PCI_DEVICE_ID_IOH_EPORT 0x3420 /* D0:F0 express mode */
31 #define PCI_DEVICE_ID_IOH_REV 0x2
32 #define IOH_EP_SSVID_OFFSET 0x40
33 #define IOH_EP_SSVID_SVID PCI_VENDOR_ID_INTEL
34 #define IOH_EP_SSVID_SSID 0
35 #define IOH_EP_MSI_OFFSET 0x60
36 #define IOH_EP_MSI_SUPPORTED_FLAGS PCI_MSI_FLAGS_MASKBIT
37 #define IOH_EP_MSI_NR_VECTOR 2
38 #define IOH_EP_EXP_OFFSET 0x90
39 #define IOH_EP_AER_OFFSET 0x100
42 * If two MSI vector are allocated, Advanced Error Interrupt Message Number
43 * is 1. otherwise 0.
44 * 17.12.5.10 RPERRSTS, 32:27 bit Advanced Error Interrupt Message Number.
46 static uint8_t ioh3420_aer_vector(const PCIDevice *d)
48 switch (msi_nr_vectors_allocated(d)) {
49 case 1:
50 return 0;
51 case 2:
52 return 1;
53 case 4:
54 case 8:
55 case 16:
56 case 32:
57 default:
58 break;
60 abort();
61 return 0;
64 static void ioh3420_aer_vector_update(PCIDevice *d)
66 pcie_aer_root_set_vector(d, ioh3420_aer_vector(d));
69 static void ioh3420_write_config(PCIDevice *d,
70 uint32_t address, uint32_t val, int len)
72 uint32_t root_cmd =
73 pci_get_long(d->config + d->exp.aer_cap + PCI_ERR_ROOT_COMMAND);
75 pci_bridge_write_config(d, address, val, len);
76 ioh3420_aer_vector_update(d);
77 pcie_cap_slot_write_config(d, address, val, len);
78 pcie_aer_write_config(d, address, val, len);
79 pcie_aer_root_write_config(d, address, val, len, root_cmd);
82 static void ioh3420_reset(DeviceState *qdev)
84 PCIDevice *d = PCI_DEVICE(qdev);
86 ioh3420_aer_vector_update(d);
87 pcie_cap_root_reset(d);
88 pcie_cap_deverr_reset(d);
89 pcie_cap_slot_reset(d);
90 pcie_cap_arifwd_reset(d);
91 pcie_aer_root_reset(d);
92 pci_bridge_reset(qdev);
93 pci_bridge_disable_base_limit(d);
96 static int ioh3420_initfn(PCIDevice *d)
98 PCIEPort *p = PCIE_PORT(d);
99 PCIESlot *s = PCIE_SLOT(d);
100 int rc;
101 Error *err = NULL;
103 pci_bridge_initfn(d, TYPE_PCIE_BUS);
104 pcie_port_init_reg(d);
106 rc = pci_bridge_ssvid_init(d, IOH_EP_SSVID_OFFSET,
107 IOH_EP_SSVID_SVID, IOH_EP_SSVID_SSID);
108 if (rc < 0) {
109 goto err_bridge;
112 rc = msi_init(d, IOH_EP_MSI_OFFSET, IOH_EP_MSI_NR_VECTOR,
113 IOH_EP_MSI_SUPPORTED_FLAGS & PCI_MSI_FLAGS_64BIT,
114 IOH_EP_MSI_SUPPORTED_FLAGS & PCI_MSI_FLAGS_MASKBIT, &err);
115 if (rc < 0) {
116 assert(rc == -ENOTSUP);
117 error_report_err(err);
118 goto err_bridge;
121 rc = pcie_cap_init(d, IOH_EP_EXP_OFFSET, PCI_EXP_TYPE_ROOT_PORT, p->port);
122 if (rc < 0) {
123 goto err_msi;
126 pcie_cap_arifwd_init(d);
127 pcie_cap_deverr_init(d);
128 pcie_cap_slot_init(d, s->slot);
129 pcie_cap_root_init(d);
131 pcie_chassis_create(s->chassis);
132 rc = pcie_chassis_add_slot(s);
133 if (rc < 0) {
134 goto err_pcie_cap;
137 rc = pcie_aer_init(d, IOH_EP_AER_OFFSET, PCI_ERR_SIZEOF);
138 if (rc < 0) {
139 goto err;
141 pcie_aer_root_init(d);
142 ioh3420_aer_vector_update(d);
144 return 0;
146 err:
147 pcie_chassis_del_slot(s);
148 err_pcie_cap:
149 pcie_cap_exit(d);
150 err_msi:
151 msi_uninit(d);
152 err_bridge:
153 pci_bridge_exitfn(d);
154 return rc;
157 static void ioh3420_exitfn(PCIDevice *d)
159 PCIESlot *s = PCIE_SLOT(d);
161 pcie_aer_exit(d);
162 pcie_chassis_del_slot(s);
163 pcie_cap_exit(d);
164 msi_uninit(d);
165 pci_bridge_exitfn(d);
168 static Property ioh3420_props[] = {
169 DEFINE_PROP_BIT(COMPAT_PROP_PCP, PCIDevice, cap_present,
170 QEMU_PCIE_SLTCAP_PCP_BITNR, true),
171 DEFINE_PROP_END_OF_LIST()
174 static const VMStateDescription vmstate_ioh3420 = {
175 .name = "ioh-3240-express-root-port",
176 .version_id = 1,
177 .minimum_version_id = 1,
178 .post_load = pcie_cap_slot_post_load,
179 .fields = (VMStateField[]) {
180 VMSTATE_PCIE_DEVICE(parent_obj.parent_obj.parent_obj, PCIESlot),
181 VMSTATE_STRUCT(parent_obj.parent_obj.parent_obj.exp.aer_log,
182 PCIESlot, 0, vmstate_pcie_aer_log, PCIEAERLog),
183 VMSTATE_END_OF_LIST()
187 static void ioh3420_class_init(ObjectClass *klass, void *data)
189 DeviceClass *dc = DEVICE_CLASS(klass);
190 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
192 k->is_express = 1;
193 k->is_bridge = 1;
194 k->config_write = ioh3420_write_config;
195 k->init = ioh3420_initfn;
196 k->exit = ioh3420_exitfn;
197 k->vendor_id = PCI_VENDOR_ID_INTEL;
198 k->device_id = PCI_DEVICE_ID_IOH_EPORT;
199 k->revision = PCI_DEVICE_ID_IOH_REV;
200 set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
201 dc->desc = "Intel IOH device id 3420 PCIE Root Port";
202 dc->reset = ioh3420_reset;
203 dc->vmsd = &vmstate_ioh3420;
204 dc->props = ioh3420_props;
207 static const TypeInfo ioh3420_info = {
208 .name = "ioh3420",
209 .parent = TYPE_PCIE_SLOT,
210 .class_init = ioh3420_class_init,
213 static void ioh3420_register_types(void)
215 type_register_static(&ioh3420_info);
218 type_init(ioh3420_register_types)
221 * Local variables:
222 * c-indent-level: 4
223 * c-basic-offset: 4
224 * tab-width: 8
225 * indent-tab-mode: nil
226 * End: