root / hw / ioh3420.c @ 735e77ec
History | View | Annotate | Download (6.9 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 | d->config[PCI_REVISION_ID] = PCI_DEVICE_ID_IOH_REV; |
108 | 8135aeed | Isaku Yamahata | pcie_port_init_reg(d); |
109 | 8135aeed | Isaku Yamahata | |
110 | 8135aeed | Isaku Yamahata | pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_INTEL); |
111 | 8135aeed | Isaku Yamahata | pci_config_set_device_id(d->config, PCI_DEVICE_ID_IOH_EPORT); |
112 | 8135aeed | Isaku Yamahata | |
113 | 8135aeed | Isaku Yamahata | rc = pci_bridge_ssvid_init(d, IOH_EP_SSVID_OFFSET, |
114 | 8135aeed | Isaku Yamahata | IOH_EP_SSVID_SVID, IOH_EP_SSVID_SSID); |
115 | 8135aeed | Isaku Yamahata | if (rc < 0) { |
116 | 61620c2f | Isaku Yamahata | goto err_bridge;
|
117 | 8135aeed | Isaku Yamahata | } |
118 | 8135aeed | Isaku Yamahata | rc = msi_init(d, IOH_EP_MSI_OFFSET, IOH_EP_MSI_NR_VECTOR, |
119 | 8135aeed | Isaku Yamahata | IOH_EP_MSI_SUPPORTED_FLAGS & PCI_MSI_FLAGS_64BIT, |
120 | 8135aeed | Isaku Yamahata | IOH_EP_MSI_SUPPORTED_FLAGS & PCI_MSI_FLAGS_MASKBIT); |
121 | 8135aeed | Isaku Yamahata | if (rc < 0) { |
122 | 61620c2f | Isaku Yamahata | goto err_bridge;
|
123 | 8135aeed | Isaku Yamahata | } |
124 | 8135aeed | Isaku Yamahata | rc = pcie_cap_init(d, IOH_EP_EXP_OFFSET, PCI_EXP_TYPE_ROOT_PORT, p->port); |
125 | 8135aeed | Isaku Yamahata | if (rc < 0) { |
126 | 61620c2f | Isaku Yamahata | goto err_msi;
|
127 | 8135aeed | Isaku Yamahata | } |
128 | 8135aeed | Isaku Yamahata | pcie_cap_deverr_init(d); |
129 | 8135aeed | Isaku Yamahata | pcie_cap_slot_init(d, s->slot); |
130 | 8135aeed | Isaku Yamahata | pcie_chassis_create(s->chassis); |
131 | 8135aeed | Isaku Yamahata | rc = pcie_chassis_add_slot(s); |
132 | 8135aeed | Isaku Yamahata | if (rc < 0) { |
133 | 61620c2f | Isaku Yamahata | goto err_pcie_cap;
|
134 | 8135aeed | Isaku Yamahata | return rc;
|
135 | 8135aeed | Isaku Yamahata | } |
136 | 8135aeed | Isaku Yamahata | pcie_cap_root_init(d); |
137 | 61620c2f | Isaku Yamahata | rc = pcie_aer_init(d, IOH_EP_AER_OFFSET); |
138 | 61620c2f | Isaku Yamahata | if (rc < 0) { |
139 | 61620c2f | Isaku Yamahata | goto err;
|
140 | 61620c2f | Isaku Yamahata | } |
141 | 61620c2f | Isaku Yamahata | pcie_aer_root_init(d); |
142 | 61620c2f | Isaku Yamahata | ioh3420_aer_vector_update(d); |
143 | 8135aeed | Isaku Yamahata | return 0; |
144 | 61620c2f | Isaku Yamahata | |
145 | 61620c2f | Isaku Yamahata | err:
|
146 | 61620c2f | Isaku Yamahata | pcie_chassis_del_slot(s); |
147 | 61620c2f | Isaku Yamahata | err_pcie_cap:
|
148 | 61620c2f | Isaku Yamahata | pcie_cap_exit(d); |
149 | 61620c2f | Isaku Yamahata | err_msi:
|
150 | 61620c2f | Isaku Yamahata | msi_uninit(d); |
151 | 61620c2f | Isaku Yamahata | err_bridge:
|
152 | 61620c2f | Isaku Yamahata | tmp = pci_bridge_exitfn(d); |
153 | 61620c2f | Isaku Yamahata | assert(!tmp); |
154 | 61620c2f | Isaku Yamahata | return rc;
|
155 | 8135aeed | Isaku Yamahata | } |
156 | 8135aeed | Isaku Yamahata | |
157 | 8135aeed | Isaku Yamahata | static int ioh3420_exitfn(PCIDevice *d) |
158 | 8135aeed | Isaku Yamahata | { |
159 | 61620c2f | Isaku Yamahata | PCIBridge* br = DO_UPCAST(PCIBridge, dev, d); |
160 | 61620c2f | Isaku Yamahata | PCIEPort *p = DO_UPCAST(PCIEPort, br, br); |
161 | 61620c2f | Isaku Yamahata | PCIESlot *s = DO_UPCAST(PCIESlot, port, p); |
162 | 61620c2f | Isaku Yamahata | |
163 | 61620c2f | Isaku Yamahata | pcie_aer_exit(d); |
164 | 61620c2f | Isaku Yamahata | pcie_chassis_del_slot(s); |
165 | 8135aeed | Isaku Yamahata | pcie_cap_exit(d); |
166 | 61620c2f | Isaku Yamahata | msi_uninit(d); |
167 | 8135aeed | Isaku Yamahata | return pci_bridge_exitfn(d);
|
168 | 8135aeed | Isaku Yamahata | } |
169 | 8135aeed | Isaku Yamahata | |
170 | 8135aeed | Isaku Yamahata | PCIESlot *ioh3420_init(PCIBus *bus, int devfn, bool multifunction, |
171 | 8135aeed | Isaku Yamahata | const char *bus_name, pci_map_irq_fn map_irq, |
172 | 8135aeed | Isaku Yamahata | uint8_t port, uint8_t chassis, uint16_t slot) |
173 | 8135aeed | Isaku Yamahata | { |
174 | 8135aeed | Isaku Yamahata | PCIDevice *d; |
175 | 8135aeed | Isaku Yamahata | PCIBridge *br; |
176 | 8135aeed | Isaku Yamahata | DeviceState *qdev; |
177 | 8135aeed | Isaku Yamahata | |
178 | 8135aeed | Isaku Yamahata | d = pci_create_multifunction(bus, devfn, multifunction, "ioh3420");
|
179 | 8135aeed | Isaku Yamahata | if (!d) {
|
180 | 8135aeed | Isaku Yamahata | return NULL; |
181 | 8135aeed | Isaku Yamahata | } |
182 | 8135aeed | Isaku Yamahata | br = DO_UPCAST(PCIBridge, dev, d); |
183 | 8135aeed | Isaku Yamahata | |
184 | 8135aeed | Isaku Yamahata | qdev = &br->dev.qdev; |
185 | 8135aeed | Isaku Yamahata | pci_bridge_map_irq(br, bus_name, map_irq); |
186 | 8135aeed | Isaku Yamahata | qdev_prop_set_uint8(qdev, "port", port);
|
187 | 8135aeed | Isaku Yamahata | qdev_prop_set_uint8(qdev, "chassis", chassis);
|
188 | 8135aeed | Isaku Yamahata | qdev_prop_set_uint16(qdev, "slot", slot);
|
189 | 8135aeed | Isaku Yamahata | qdev_init_nofail(qdev); |
190 | 8135aeed | Isaku Yamahata | |
191 | 8135aeed | Isaku Yamahata | return DO_UPCAST(PCIESlot, port, DO_UPCAST(PCIEPort, br, br));
|
192 | 8135aeed | Isaku Yamahata | } |
193 | 8135aeed | Isaku Yamahata | |
194 | 8135aeed | Isaku Yamahata | static const VMStateDescription vmstate_ioh3420 = { |
195 | 8135aeed | Isaku Yamahata | .name = "ioh-3240-express-root-port",
|
196 | 8135aeed | Isaku Yamahata | .version_id = 1,
|
197 | 8135aeed | Isaku Yamahata | .minimum_version_id = 1,
|
198 | 8135aeed | Isaku Yamahata | .minimum_version_id_old = 1,
|
199 | 6bde6aaa | Michael S. Tsirkin | .post_load = pcie_cap_slot_post_load, |
200 | 8135aeed | Isaku Yamahata | .fields = (VMStateField[]) { |
201 | 8135aeed | Isaku Yamahata | VMSTATE_PCIE_DEVICE(port.br.dev, PCIESlot), |
202 | 61620c2f | Isaku Yamahata | VMSTATE_STRUCT(port.br.dev.exp.aer_log, PCIESlot, 0,
|
203 | 61620c2f | Isaku Yamahata | vmstate_pcie_aer_log, PCIEAERLog), |
204 | 8135aeed | Isaku Yamahata | VMSTATE_END_OF_LIST() |
205 | 8135aeed | Isaku Yamahata | } |
206 | 8135aeed | Isaku Yamahata | }; |
207 | 8135aeed | Isaku Yamahata | |
208 | 8135aeed | Isaku Yamahata | static PCIDeviceInfo ioh3420_info = {
|
209 | 8135aeed | Isaku Yamahata | .qdev.name = "ioh3420",
|
210 | 8135aeed | Isaku Yamahata | .qdev.desc = "Intel IOH device id 3420 PCIE Root Port",
|
211 | 8135aeed | Isaku Yamahata | .qdev.size = sizeof(PCIESlot),
|
212 | 8135aeed | Isaku Yamahata | .qdev.reset = ioh3420_reset, |
213 | 8135aeed | Isaku Yamahata | .qdev.vmsd = &vmstate_ioh3420, |
214 | 8135aeed | Isaku Yamahata | |
215 | 8135aeed | Isaku Yamahata | .is_express = 1,
|
216 | 8135aeed | Isaku Yamahata | .is_bridge = 1,
|
217 | 8135aeed | Isaku Yamahata | .config_write = ioh3420_write_config, |
218 | 8135aeed | Isaku Yamahata | .init = ioh3420_initfn, |
219 | 8135aeed | Isaku Yamahata | .exit = ioh3420_exitfn, |
220 | 8135aeed | Isaku Yamahata | |
221 | 8135aeed | Isaku Yamahata | .qdev.props = (Property[]) { |
222 | 8135aeed | Isaku Yamahata | DEFINE_PROP_UINT8("port", PCIESlot, port.port, 0), |
223 | 8135aeed | Isaku Yamahata | DEFINE_PROP_UINT8("chassis", PCIESlot, chassis, 0), |
224 | 8135aeed | Isaku Yamahata | DEFINE_PROP_UINT16("slot", PCIESlot, slot, 0), |
225 | 61620c2f | Isaku Yamahata | DEFINE_PROP_UINT16("aer_log_max", PCIESlot,
|
226 | 61620c2f | Isaku Yamahata | port.br.dev.exp.aer_log.log_max, |
227 | 61620c2f | Isaku Yamahata | PCIE_AER_LOG_MAX_DEFAULT), |
228 | 8135aeed | Isaku Yamahata | DEFINE_PROP_END_OF_LIST(), |
229 | 8135aeed | Isaku Yamahata | } |
230 | 8135aeed | Isaku Yamahata | }; |
231 | 8135aeed | Isaku Yamahata | |
232 | 8135aeed | Isaku Yamahata | static void ioh3420_register(void) |
233 | 8135aeed | Isaku Yamahata | { |
234 | 8135aeed | Isaku Yamahata | pci_qdev_register(&ioh3420_info); |
235 | 8135aeed | Isaku Yamahata | } |
236 | 8135aeed | Isaku Yamahata | |
237 | 8135aeed | Isaku Yamahata | device_init(ioh3420_register); |
238 | 8135aeed | Isaku Yamahata | |
239 | 8135aeed | Isaku Yamahata | /*
|
240 | 8135aeed | Isaku Yamahata | * Local variables:
|
241 | 8135aeed | Isaku Yamahata | * c-indent-level: 4
|
242 | 8135aeed | Isaku Yamahata | * c-basic-offset: 4
|
243 | 8135aeed | Isaku Yamahata | * tab-width: 8
|
244 | 8135aeed | Isaku Yamahata | * indent-tab-mode: nil
|
245 | 8135aeed | Isaku Yamahata | * End:
|
246 | 8135aeed | Isaku Yamahata | */ |