xref: /qemu/hw/pci-bridge/xio3130_upstream.c (revision c6329a2d0976661a466e02e29f50ce7b708cb8eb)
1faf1e708SIsaku Yamahata /*
2faf1e708SIsaku Yamahata  * xio3130_upstream.c
3faf1e708SIsaku Yamahata  * TI X3130 pci express upstream port switch
4faf1e708SIsaku Yamahata  *
5faf1e708SIsaku Yamahata  * Copyright (c) 2010 Isaku Yamahata <yamahata at valinux co jp>
6faf1e708SIsaku Yamahata  *                    VA Linux Systems Japan K.K.
7faf1e708SIsaku Yamahata  *
8faf1e708SIsaku Yamahata  * This program is free software; you can redistribute it and/or modify
9faf1e708SIsaku Yamahata  * it under the terms of the GNU General Public License as published by
10faf1e708SIsaku Yamahata  * the Free Software Foundation; either version 2 of the License, or
11faf1e708SIsaku Yamahata  * (at your option) any later version.
12faf1e708SIsaku Yamahata  *
13faf1e708SIsaku Yamahata  * This program is distributed in the hope that it will be useful,
14faf1e708SIsaku Yamahata  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15faf1e708SIsaku Yamahata  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16faf1e708SIsaku Yamahata  * GNU General Public License for more details.
17faf1e708SIsaku Yamahata  *
18faf1e708SIsaku Yamahata  * You should have received a copy of the GNU General Public License along
19faf1e708SIsaku Yamahata  * with this program; if not, see <http://www.gnu.org/licenses/>.
20faf1e708SIsaku Yamahata  */
21faf1e708SIsaku Yamahata 
2297d5408fSPeter Maydell #include "qemu/osdep.h"
2383c9f4caSPaolo Bonzini #include "hw/pci/pci_ids.h"
2483c9f4caSPaolo Bonzini #include "hw/pci/msi.h"
2583c9f4caSPaolo Bonzini #include "hw/pci/pcie.h"
26*c6329a2dSPhilippe Mathieu-Daudé #include "hw/pci/pcie_port.h"
27faf1e708SIsaku Yamahata 
28faf1e708SIsaku Yamahata #define PCI_DEVICE_ID_TI_XIO3130U       0x8232  /* upstream port */
29faf1e708SIsaku Yamahata #define XIO3130_REVISION                0x2
30faf1e708SIsaku Yamahata #define XIO3130_MSI_OFFSET              0x70
31faf1e708SIsaku Yamahata #define XIO3130_MSI_SUPPORTED_FLAGS     PCI_MSI_FLAGS_64BIT
32faf1e708SIsaku Yamahata #define XIO3130_MSI_NR_VECTOR           1
33faf1e708SIsaku Yamahata #define XIO3130_SSVID_OFFSET            0x80
34faf1e708SIsaku Yamahata #define XIO3130_SSVID_SVID              0
35faf1e708SIsaku Yamahata #define XIO3130_SSVID_SSID              0
36faf1e708SIsaku Yamahata #define XIO3130_EXP_OFFSET              0x90
37faf1e708SIsaku Yamahata #define XIO3130_AER_OFFSET              0x100
38faf1e708SIsaku Yamahata 
39faf1e708SIsaku Yamahata static void xio3130_upstream_write_config(PCIDevice *d, uint32_t address,
40faf1e708SIsaku Yamahata                                           uint32_t val, int len)
41faf1e708SIsaku Yamahata {
42faf1e708SIsaku Yamahata     pci_bridge_write_config(d, address, val, len);
43faf1e708SIsaku Yamahata     pcie_cap_flr_write_config(d, address, val, len);
44a158f92fSIsaku Yamahata     pcie_aer_write_config(d, address, val, len);
45faf1e708SIsaku Yamahata }
46faf1e708SIsaku Yamahata 
47faf1e708SIsaku Yamahata static void xio3130_upstream_reset(DeviceState *qdev)
48faf1e708SIsaku Yamahata {
4940021f08SAnthony Liguori     PCIDevice *d = PCI_DEVICE(qdev);
50cbd2d434SJan Kiszka 
51faf1e708SIsaku Yamahata     pci_bridge_reset(qdev);
52faf1e708SIsaku Yamahata     pcie_cap_deverr_reset(d);
53faf1e708SIsaku Yamahata }
54faf1e708SIsaku Yamahata 
55f8cd1b02SMao Zhongyi static void xio3130_upstream_realize(PCIDevice *d, Error **errp)
56faf1e708SIsaku Yamahata {
57bcb75750SAndreas Färber     PCIEPort *p = PCIE_PORT(d);
58faf1e708SIsaku Yamahata     int rc;
59faf1e708SIsaku Yamahata 
609cfaa007SCao jin     pci_bridge_initfn(d, TYPE_PCIE_BUS);
61faf1e708SIsaku Yamahata     pcie_port_init_reg(d);
62faf1e708SIsaku Yamahata 
63faf1e708SIsaku Yamahata     rc = msi_init(d, XIO3130_MSI_OFFSET, XIO3130_MSI_NR_VECTOR,
64faf1e708SIsaku Yamahata                   XIO3130_MSI_SUPPORTED_FLAGS & PCI_MSI_FLAGS_64BIT,
65f8cd1b02SMao Zhongyi                   XIO3130_MSI_SUPPORTED_FLAGS & PCI_MSI_FLAGS_MASKBIT,
66f8cd1b02SMao Zhongyi                   errp);
67faf1e708SIsaku Yamahata     if (rc < 0) {
681108b2f8SCao jin         assert(rc == -ENOTSUP);
69a158f92fSIsaku Yamahata         goto err_bridge;
70faf1e708SIsaku Yamahata     }
7152ea63deSCao jin 
72faf1e708SIsaku Yamahata     rc = pci_bridge_ssvid_init(d, XIO3130_SSVID_OFFSET,
73f8cd1b02SMao Zhongyi                                XIO3130_SSVID_SVID, XIO3130_SSVID_SSID,
74f8cd1b02SMao Zhongyi                                errp);
75faf1e708SIsaku Yamahata     if (rc < 0) {
76a158f92fSIsaku Yamahata         goto err_bridge;
77faf1e708SIsaku Yamahata     }
7852ea63deSCao jin 
79faf1e708SIsaku Yamahata     rc = pcie_cap_init(d, XIO3130_EXP_OFFSET, PCI_EXP_TYPE_UPSTREAM,
80f8cd1b02SMao Zhongyi                        p->port, errp);
81faf1e708SIsaku Yamahata     if (rc < 0) {
82a158f92fSIsaku Yamahata         goto err_msi;
83faf1e708SIsaku Yamahata     }
84faf1e708SIsaku Yamahata     pcie_cap_flr_init(d);
85faf1e708SIsaku Yamahata     pcie_cap_deverr_init(d);
8652ea63deSCao jin 
87f18c697bSDou Liyang     rc = pcie_aer_init(d, PCI_ERR_VER, XIO3130_AER_OFFSET,
88f8cd1b02SMao Zhongyi                        PCI_ERR_SIZEOF, errp);
89a158f92fSIsaku Yamahata     if (rc < 0) {
90a158f92fSIsaku Yamahata         goto err;
91a158f92fSIsaku Yamahata     }
92faf1e708SIsaku Yamahata 
93f8cd1b02SMao Zhongyi     return;
94a158f92fSIsaku Yamahata 
95a158f92fSIsaku Yamahata err:
96a158f92fSIsaku Yamahata     pcie_cap_exit(d);
97a158f92fSIsaku Yamahata err_msi:
98a158f92fSIsaku Yamahata     msi_uninit(d);
99a158f92fSIsaku Yamahata err_bridge:
100f90c2bcdSAlex Williamson     pci_bridge_exitfn(d);
101faf1e708SIsaku Yamahata }
102faf1e708SIsaku Yamahata 
103f90c2bcdSAlex Williamson static void xio3130_upstream_exitfn(PCIDevice *d)
104faf1e708SIsaku Yamahata {
105a158f92fSIsaku Yamahata     pcie_aer_exit(d);
106faf1e708SIsaku Yamahata     pcie_cap_exit(d);
107a158f92fSIsaku Yamahata     msi_uninit(d);
108f90c2bcdSAlex Williamson     pci_bridge_exitfn(d);
109faf1e708SIsaku Yamahata }
110faf1e708SIsaku Yamahata 
111faf1e708SIsaku Yamahata static const VMStateDescription vmstate_xio3130_upstream = {
112faf1e708SIsaku Yamahata     .name = "xio3130-express-upstream-port",
1139d6b9db1SPeter Xu     .priority = MIG_PRI_PCI_BUS,
114faf1e708SIsaku Yamahata     .version_id = 1,
115faf1e708SIsaku Yamahata     .minimum_version_id = 1,
116faf1e708SIsaku Yamahata     .fields = (VMStateField[]) {
11720daa90aSDr. David Alan Gilbert         VMSTATE_PCI_DEVICE(parent_obj.parent_obj, PCIEPort),
118bcb75750SAndreas Färber         VMSTATE_STRUCT(parent_obj.parent_obj.exp.aer_log, PCIEPort, 0,
119f055e96bSAndreas Färber                        vmstate_pcie_aer_log, PCIEAERLog),
120faf1e708SIsaku Yamahata         VMSTATE_END_OF_LIST()
121faf1e708SIsaku Yamahata     }
122faf1e708SIsaku Yamahata };
123faf1e708SIsaku Yamahata 
12440021f08SAnthony Liguori static void xio3130_upstream_class_init(ObjectClass *klass, void *data)
12540021f08SAnthony Liguori {
12639bffca2SAnthony Liguori     DeviceClass *dc = DEVICE_CLASS(klass);
12740021f08SAnthony Liguori     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
12840021f08SAnthony Liguori 
12940021f08SAnthony Liguori     k->is_bridge = 1;
13040021f08SAnthony Liguori     k->config_write = xio3130_upstream_write_config;
131f8cd1b02SMao Zhongyi     k->realize = xio3130_upstream_realize;
13240021f08SAnthony Liguori     k->exit = xio3130_upstream_exitfn;
13340021f08SAnthony Liguori     k->vendor_id = PCI_VENDOR_ID_TI;
13440021f08SAnthony Liguori     k->device_id = PCI_DEVICE_ID_TI_XIO3130U;
13540021f08SAnthony Liguori     k->revision = XIO3130_REVISION;
136125ee0edSMarcel Apfelbaum     set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
13739bffca2SAnthony Liguori     dc->desc = "TI X3130 Upstream Port of PCI Express Switch";
13839bffca2SAnthony Liguori     dc->reset = xio3130_upstream_reset;
13939bffca2SAnthony Liguori     dc->vmsd = &vmstate_xio3130_upstream;
140faf1e708SIsaku Yamahata }
14140021f08SAnthony Liguori 
1428c43a6f0SAndreas Färber static const TypeInfo xio3130_upstream_info = {
14340021f08SAnthony Liguori     .name          = "x3130-upstream",
144bcb75750SAndreas Färber     .parent        = TYPE_PCIE_PORT,
14540021f08SAnthony Liguori     .class_init    = xio3130_upstream_class_init,
14671d78767SEduardo Habkost     .interfaces = (InterfaceInfo[]) {
14771d78767SEduardo Habkost         { INTERFACE_PCIE_DEVICE },
14871d78767SEduardo Habkost         { }
14971d78767SEduardo Habkost     },
150faf1e708SIsaku Yamahata };
151faf1e708SIsaku Yamahata 
15283f7d43aSAndreas Färber static void xio3130_upstream_register_types(void)
153faf1e708SIsaku Yamahata {
15439bffca2SAnthony Liguori     type_register_static(&xio3130_upstream_info);
155faf1e708SIsaku Yamahata }
156faf1e708SIsaku Yamahata 
15783f7d43aSAndreas Färber type_init(xio3130_upstream_register_types)
158