]> git.proxmox.com Git - mirror_qemu.git/blame - hw/pci-bridge/ioh3420.c
Merge remote-tracking branch 'remotes/mst/tags/for_upstream' into staging
[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"
cd1f0ca2 27#include "hw/pci/pcie_port.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
fed23cb4 63static int ioh3420_interrupts_init(PCIDevice *d, Error **errp)
61620c2f 64{
8135aeed 65 int rc;
52ea63de 66
8135aeed
IY
67 rc = msi_init(d, IOH_EP_MSI_OFFSET, IOH_EP_MSI_NR_VECTOR,
68 IOH_EP_MSI_SUPPORTED_FLAGS & PCI_MSI_FLAGS_64BIT,
fed23cb4 69 IOH_EP_MSI_SUPPORTED_FLAGS & PCI_MSI_FLAGS_MASKBIT,
06592d7e 70 errp);
8135aeed 71 if (rc < 0) {
1108b2f8 72 assert(rc == -ENOTSUP);
8135aeed 73 }
52ea63de 74
61620c2f 75 return rc;
8135aeed
IY
76}
77
fed23cb4 78static void ioh3420_interrupts_uninit(PCIDevice *d)
8135aeed 79{
61620c2f 80 msi_uninit(d);
8135aeed
IY
81}
82
8135aeed
IY
83static const VMStateDescription vmstate_ioh3420 = {
84 .name = "ioh-3240-express-root-port",
9d6b9db1 85 .priority = MIG_PRI_PCI_BUS,
8135aeed
IY
86 .version_id = 1,
87 .minimum_version_id = 1,
6bde6aaa 88 .post_load = pcie_cap_slot_post_load,
8135aeed 89 .fields = (VMStateField[]) {
20daa90a 90 VMSTATE_PCI_DEVICE(parent_obj.parent_obj.parent_obj, PCIESlot),
bcb75750
AF
91 VMSTATE_STRUCT(parent_obj.parent_obj.parent_obj.exp.aer_log,
92 PCIESlot, 0, vmstate_pcie_aer_log, PCIEAERLog),
8135aeed
IY
93 VMSTATE_END_OF_LIST()
94 }
95};
96
40021f08
AL
97static void ioh3420_class_init(ObjectClass *klass, void *data)
98{
39bffca2 99 DeviceClass *dc = DEVICE_CLASS(klass);
40021f08 100 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
fed23cb4 101 PCIERootPortClass *rpc = PCIE_ROOT_PORT_CLASS(klass);
40021f08 102
40021f08
AL
103 k->vendor_id = PCI_VENDOR_ID_INTEL;
104 k->device_id = PCI_DEVICE_ID_IOH_EPORT;
105 k->revision = PCI_DEVICE_ID_IOH_REV;
39bffca2 106 dc->desc = "Intel IOH device id 3420 PCIE Root Port";
39bffca2 107 dc->vmsd = &vmstate_ioh3420;
fed23cb4
MA
108 rpc->aer_vector = ioh3420_aer_vector;
109 rpc->interrupts_init = ioh3420_interrupts_init;
110 rpc->interrupts_uninit = ioh3420_interrupts_uninit;
111 rpc->exp_offset = IOH_EP_EXP_OFFSET;
112 rpc->aer_offset = IOH_EP_AER_OFFSET;
113 rpc->ssvid_offset = IOH_EP_SSVID_OFFSET;
114 rpc->ssid = IOH_EP_SSVID_SSID;
40021f08
AL
115}
116
8c43a6f0 117static const TypeInfo ioh3420_info = {
39bffca2 118 .name = "ioh3420",
fed23cb4 119 .parent = TYPE_PCIE_ROOT_PORT,
39bffca2 120 .class_init = ioh3420_class_init,
8135aeed
IY
121};
122
83f7d43a 123static void ioh3420_register_types(void)
8135aeed 124{
39bffca2 125 type_register_static(&ioh3420_info);
8135aeed
IY
126}
127
83f7d43a 128type_init(ioh3420_register_types)