Statistics
| Branch: | Revision:

root / hw / ioh3420.c @ 8135aeed

History | View | Annotate | Download (5.3 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 8135aeed Isaku Yamahata
static void ioh3420_write_config(PCIDevice *d,
40 8135aeed Isaku Yamahata
                                   uint32_t address, uint32_t val, int len)
41 8135aeed Isaku Yamahata
{
42 8135aeed Isaku Yamahata
    uint16_t sltctl =
43 8135aeed Isaku Yamahata
        pci_get_word(d->config + d->exp.exp_cap + PCI_EXP_SLTCTL);
44 8135aeed Isaku Yamahata
45 8135aeed Isaku Yamahata
    pci_bridge_write_config(d, address, val, len);
46 8135aeed Isaku Yamahata
    msi_write_config(d, address, val, len);
47 8135aeed Isaku Yamahata
    pcie_cap_slot_write_config(d, address, val, len, sltctl);
48 8135aeed Isaku Yamahata
    /* TODO: AER */
49 8135aeed Isaku Yamahata
}
50 8135aeed Isaku Yamahata
51 8135aeed Isaku Yamahata
static void ioh3420_reset(DeviceState *qdev)
52 8135aeed Isaku Yamahata
{
53 8135aeed Isaku Yamahata
    PCIDevice *d = DO_UPCAST(PCIDevice, qdev, qdev);
54 8135aeed Isaku Yamahata
    msi_reset(d);
55 8135aeed Isaku Yamahata
    pcie_cap_root_reset(d);
56 8135aeed Isaku Yamahata
    pcie_cap_deverr_reset(d);
57 8135aeed Isaku Yamahata
    pcie_cap_slot_reset(d);
58 8135aeed Isaku Yamahata
    pci_bridge_reset(qdev);
59 8135aeed Isaku Yamahata
    pci_bridge_disable_base_limit(d);
60 8135aeed Isaku Yamahata
    /* TODO: AER */
61 8135aeed Isaku Yamahata
}
62 8135aeed Isaku Yamahata
63 8135aeed Isaku Yamahata
static int ioh3420_initfn(PCIDevice *d)
64 8135aeed Isaku Yamahata
{
65 8135aeed Isaku Yamahata
    PCIBridge* br = DO_UPCAST(PCIBridge, dev, d);
66 8135aeed Isaku Yamahata
    PCIEPort *p = DO_UPCAST(PCIEPort, br, br);
67 8135aeed Isaku Yamahata
    PCIESlot *s = DO_UPCAST(PCIESlot, port, p);
68 8135aeed Isaku Yamahata
    int rc;
69 8135aeed Isaku Yamahata
70 8135aeed Isaku Yamahata
    rc = pci_bridge_initfn(d);
71 8135aeed Isaku Yamahata
    if (rc < 0) {
72 8135aeed Isaku Yamahata
        return rc;
73 8135aeed Isaku Yamahata
    }
74 8135aeed Isaku Yamahata
75 8135aeed Isaku Yamahata
    d->config[PCI_REVISION_ID] = PCI_DEVICE_ID_IOH_REV;
76 8135aeed Isaku Yamahata
    pcie_port_init_reg(d);
77 8135aeed Isaku Yamahata
78 8135aeed Isaku Yamahata
    pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_INTEL);
79 8135aeed Isaku Yamahata
    pci_config_set_device_id(d->config, PCI_DEVICE_ID_IOH_EPORT);
80 8135aeed Isaku Yamahata
81 8135aeed Isaku Yamahata
    rc = pci_bridge_ssvid_init(d, IOH_EP_SSVID_OFFSET,
82 8135aeed Isaku Yamahata
                               IOH_EP_SSVID_SVID, IOH_EP_SSVID_SSID);
83 8135aeed Isaku Yamahata
    if (rc < 0) {
84 8135aeed Isaku Yamahata
        return rc;
85 8135aeed Isaku Yamahata
    }
86 8135aeed Isaku Yamahata
    rc = msi_init(d, IOH_EP_MSI_OFFSET, IOH_EP_MSI_NR_VECTOR,
87 8135aeed Isaku Yamahata
                  IOH_EP_MSI_SUPPORTED_FLAGS & PCI_MSI_FLAGS_64BIT,
88 8135aeed Isaku Yamahata
                  IOH_EP_MSI_SUPPORTED_FLAGS & PCI_MSI_FLAGS_MASKBIT);
89 8135aeed Isaku Yamahata
    if (rc < 0) {
90 8135aeed Isaku Yamahata
        return rc;
91 8135aeed Isaku Yamahata
    }
92 8135aeed Isaku Yamahata
    rc = pcie_cap_init(d, IOH_EP_EXP_OFFSET, PCI_EXP_TYPE_ROOT_PORT, p->port);
93 8135aeed Isaku Yamahata
    if (rc < 0) {
94 8135aeed Isaku Yamahata
        return rc;
95 8135aeed Isaku Yamahata
    }
96 8135aeed Isaku Yamahata
    pcie_cap_deverr_init(d);
97 8135aeed Isaku Yamahata
    pcie_cap_slot_init(d, s->slot);
98 8135aeed Isaku Yamahata
    pcie_chassis_create(s->chassis);
99 8135aeed Isaku Yamahata
    rc = pcie_chassis_add_slot(s);
100 8135aeed Isaku Yamahata
    if (rc < 0) {
101 8135aeed Isaku Yamahata
        return rc;
102 8135aeed Isaku Yamahata
    }
103 8135aeed Isaku Yamahata
    pcie_cap_root_init(d);
104 8135aeed Isaku Yamahata
    /* TODO: AER */
105 8135aeed Isaku Yamahata
    return 0;
106 8135aeed Isaku Yamahata
}
107 8135aeed Isaku Yamahata
108 8135aeed Isaku Yamahata
static int ioh3420_exitfn(PCIDevice *d)
109 8135aeed Isaku Yamahata
{
110 8135aeed Isaku Yamahata
    /* TODO: AER */
111 8135aeed Isaku Yamahata
    msi_uninit(d);
112 8135aeed Isaku Yamahata
    pcie_cap_exit(d);
113 8135aeed Isaku Yamahata
    return pci_bridge_exitfn(d);
114 8135aeed Isaku Yamahata
}
115 8135aeed Isaku Yamahata
116 8135aeed Isaku Yamahata
PCIESlot *ioh3420_init(PCIBus *bus, int devfn, bool multifunction,
117 8135aeed Isaku Yamahata
                         const char *bus_name, pci_map_irq_fn map_irq,
118 8135aeed Isaku Yamahata
                         uint8_t port, uint8_t chassis, uint16_t slot)
119 8135aeed Isaku Yamahata
{
120 8135aeed Isaku Yamahata
    PCIDevice *d;
121 8135aeed Isaku Yamahata
    PCIBridge *br;
122 8135aeed Isaku Yamahata
    DeviceState *qdev;
123 8135aeed Isaku Yamahata
124 8135aeed Isaku Yamahata
    d = pci_create_multifunction(bus, devfn, multifunction, "ioh3420");
125 8135aeed Isaku Yamahata
    if (!d) {
126 8135aeed Isaku Yamahata
        return NULL;
127 8135aeed Isaku Yamahata
    }
128 8135aeed Isaku Yamahata
    br = DO_UPCAST(PCIBridge, dev, d);
129 8135aeed Isaku Yamahata
130 8135aeed Isaku Yamahata
    qdev = &br->dev.qdev;
131 8135aeed Isaku Yamahata
    pci_bridge_map_irq(br, bus_name, map_irq);
132 8135aeed Isaku Yamahata
    qdev_prop_set_uint8(qdev, "port", port);
133 8135aeed Isaku Yamahata
    qdev_prop_set_uint8(qdev, "chassis", chassis);
134 8135aeed Isaku Yamahata
    qdev_prop_set_uint16(qdev, "slot", slot);
135 8135aeed Isaku Yamahata
    qdev_init_nofail(qdev);
136 8135aeed Isaku Yamahata
137 8135aeed Isaku Yamahata
    return DO_UPCAST(PCIESlot, port, DO_UPCAST(PCIEPort, br, br));
138 8135aeed Isaku Yamahata
}
139 8135aeed Isaku Yamahata
140 8135aeed Isaku Yamahata
static const VMStateDescription vmstate_ioh3420 = {
141 8135aeed Isaku Yamahata
    .name = "ioh-3240-express-root-port",
142 8135aeed Isaku Yamahata
    .version_id = 1,
143 8135aeed Isaku Yamahata
    .minimum_version_id = 1,
144 8135aeed Isaku Yamahata
    .minimum_version_id_old = 1,
145 8135aeed Isaku Yamahata
    .fields = (VMStateField[]) {
146 8135aeed Isaku Yamahata
        VMSTATE_PCIE_DEVICE(port.br.dev, PCIESlot),
147 8135aeed Isaku Yamahata
        /* TODO: AER */
148 8135aeed Isaku Yamahata
        VMSTATE_END_OF_LIST()
149 8135aeed Isaku Yamahata
    }
150 8135aeed Isaku Yamahata
};
151 8135aeed Isaku Yamahata
152 8135aeed Isaku Yamahata
static PCIDeviceInfo ioh3420_info = {
153 8135aeed Isaku Yamahata
    .qdev.name = "ioh3420",
154 8135aeed Isaku Yamahata
    .qdev.desc = "Intel IOH device id 3420 PCIE Root Port",
155 8135aeed Isaku Yamahata
    .qdev.size = sizeof(PCIESlot),
156 8135aeed Isaku Yamahata
    .qdev.reset = ioh3420_reset,
157 8135aeed Isaku Yamahata
    .qdev.vmsd = &vmstate_ioh3420,
158 8135aeed Isaku Yamahata
159 8135aeed Isaku Yamahata
    .is_express = 1,
160 8135aeed Isaku Yamahata
    .is_bridge = 1,
161 8135aeed Isaku Yamahata
    .config_write = ioh3420_write_config,
162 8135aeed Isaku Yamahata
    .init = ioh3420_initfn,
163 8135aeed Isaku Yamahata
    .exit = ioh3420_exitfn,
164 8135aeed Isaku Yamahata
165 8135aeed Isaku Yamahata
    .qdev.props = (Property[]) {
166 8135aeed Isaku Yamahata
        DEFINE_PROP_UINT8("port", PCIESlot, port.port, 0),
167 8135aeed Isaku Yamahata
        DEFINE_PROP_UINT8("chassis", PCIESlot, chassis, 0),
168 8135aeed Isaku Yamahata
        DEFINE_PROP_UINT16("slot", PCIESlot, slot, 0),
169 8135aeed Isaku Yamahata
        /* TODO: AER */
170 8135aeed Isaku Yamahata
        DEFINE_PROP_END_OF_LIST(),
171 8135aeed Isaku Yamahata
    }
172 8135aeed Isaku Yamahata
};
173 8135aeed Isaku Yamahata
174 8135aeed Isaku Yamahata
static void ioh3420_register(void)
175 8135aeed Isaku Yamahata
{
176 8135aeed Isaku Yamahata
    pci_qdev_register(&ioh3420_info);
177 8135aeed Isaku Yamahata
}
178 8135aeed Isaku Yamahata
179 8135aeed Isaku Yamahata
device_init(ioh3420_register);
180 8135aeed Isaku Yamahata
181 8135aeed Isaku Yamahata
/*
182 8135aeed Isaku Yamahata
 * Local variables:
183 8135aeed Isaku Yamahata
 *  c-indent-level: 4
184 8135aeed Isaku Yamahata
 *  c-basic-offset: 4
185 8135aeed Isaku Yamahata
 *  tab-width: 8
186 8135aeed Isaku Yamahata
 *  indent-tab-mode: nil
187 8135aeed Isaku Yamahata
 * End:
188 8135aeed Isaku Yamahata
 */