Statistics
| Branch: | Revision:

root / hw / xio3130_upstream.c @ c1ded3dc

History | View | Annotate | Download (4.9 kB)

1 faf1e708 Isaku Yamahata
/*
2 faf1e708 Isaku Yamahata
 * xio3130_upstream.c
3 faf1e708 Isaku Yamahata
 * TI X3130 pci express upstream port switch
4 faf1e708 Isaku Yamahata
 *
5 faf1e708 Isaku Yamahata
 * Copyright (c) 2010 Isaku Yamahata <yamahata at valinux co jp>
6 faf1e708 Isaku Yamahata
 *                    VA Linux Systems Japan K.K.
7 faf1e708 Isaku Yamahata
 *
8 faf1e708 Isaku Yamahata
 * This program is free software; you can redistribute it and/or modify
9 faf1e708 Isaku Yamahata
 * it under the terms of the GNU General Public License as published by
10 faf1e708 Isaku Yamahata
 * the Free Software Foundation; either version 2 of the License, or
11 faf1e708 Isaku Yamahata
 * (at your option) any later version.
12 faf1e708 Isaku Yamahata
 *
13 faf1e708 Isaku Yamahata
 * This program is distributed in the hope that it will be useful,
14 faf1e708 Isaku Yamahata
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 faf1e708 Isaku Yamahata
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 faf1e708 Isaku Yamahata
 * GNU General Public License for more details.
17 faf1e708 Isaku Yamahata
 *
18 faf1e708 Isaku Yamahata
 * You should have received a copy of the GNU General Public License along
19 faf1e708 Isaku Yamahata
 * with this program; if not, see <http://www.gnu.org/licenses/>.
20 faf1e708 Isaku Yamahata
 */
21 faf1e708 Isaku Yamahata
22 faf1e708 Isaku Yamahata
#include "pci_ids.h"
23 faf1e708 Isaku Yamahata
#include "msi.h"
24 faf1e708 Isaku Yamahata
#include "pcie.h"
25 faf1e708 Isaku Yamahata
#include "xio3130_upstream.h"
26 faf1e708 Isaku Yamahata
27 faf1e708 Isaku Yamahata
#define PCI_DEVICE_ID_TI_XIO3130U       0x8232  /* upstream port */
28 faf1e708 Isaku Yamahata
#define XIO3130_REVISION                0x2
29 faf1e708 Isaku Yamahata
#define XIO3130_MSI_OFFSET              0x70
30 faf1e708 Isaku Yamahata
#define XIO3130_MSI_SUPPORTED_FLAGS     PCI_MSI_FLAGS_64BIT
31 faf1e708 Isaku Yamahata
#define XIO3130_MSI_NR_VECTOR           1
32 faf1e708 Isaku Yamahata
#define XIO3130_SSVID_OFFSET            0x80
33 faf1e708 Isaku Yamahata
#define XIO3130_SSVID_SVID              0
34 faf1e708 Isaku Yamahata
#define XIO3130_SSVID_SSID              0
35 faf1e708 Isaku Yamahata
#define XIO3130_EXP_OFFSET              0x90
36 faf1e708 Isaku Yamahata
#define XIO3130_AER_OFFSET              0x100
37 faf1e708 Isaku Yamahata
38 faf1e708 Isaku Yamahata
static void xio3130_upstream_write_config(PCIDevice *d, uint32_t address,
39 faf1e708 Isaku Yamahata
                                          uint32_t val, int len)
40 faf1e708 Isaku Yamahata
{
41 faf1e708 Isaku Yamahata
    pci_bridge_write_config(d, address, val, len);
42 faf1e708 Isaku Yamahata
    pcie_cap_flr_write_config(d, address, val, len);
43 faf1e708 Isaku Yamahata
    msi_write_config(d, address, val, len);
44 faf1e708 Isaku Yamahata
    /* TODO: AER */
45 faf1e708 Isaku Yamahata
}
46 faf1e708 Isaku Yamahata
47 faf1e708 Isaku Yamahata
static void xio3130_upstream_reset(DeviceState *qdev)
48 faf1e708 Isaku Yamahata
{
49 faf1e708 Isaku Yamahata
    PCIDevice *d = DO_UPCAST(PCIDevice, qdev, qdev);
50 faf1e708 Isaku Yamahata
    msi_reset(d);
51 faf1e708 Isaku Yamahata
    pci_bridge_reset(qdev);
52 faf1e708 Isaku Yamahata
    pcie_cap_deverr_reset(d);
53 faf1e708 Isaku Yamahata
}
54 faf1e708 Isaku Yamahata
55 faf1e708 Isaku Yamahata
static int xio3130_upstream_initfn(PCIDevice *d)
56 faf1e708 Isaku Yamahata
{
57 faf1e708 Isaku Yamahata
    PCIBridge* br = DO_UPCAST(PCIBridge, dev, d);
58 faf1e708 Isaku Yamahata
    PCIEPort *p = DO_UPCAST(PCIEPort, br, br);
59 faf1e708 Isaku Yamahata
    int rc;
60 faf1e708 Isaku Yamahata
61 faf1e708 Isaku Yamahata
    rc = pci_bridge_initfn(d);
62 faf1e708 Isaku Yamahata
    if (rc < 0) {
63 faf1e708 Isaku Yamahata
        return rc;
64 faf1e708 Isaku Yamahata
    }
65 faf1e708 Isaku Yamahata
66 faf1e708 Isaku Yamahata
    pcie_port_init_reg(d);
67 faf1e708 Isaku Yamahata
    pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_TI);
68 faf1e708 Isaku Yamahata
    pci_config_set_device_id(d->config, PCI_DEVICE_ID_TI_XIO3130U);
69 faf1e708 Isaku Yamahata
    d->config[PCI_REVISION_ID] = XIO3130_REVISION;
70 faf1e708 Isaku Yamahata
71 faf1e708 Isaku Yamahata
    rc = msi_init(d, XIO3130_MSI_OFFSET, XIO3130_MSI_NR_VECTOR,
72 faf1e708 Isaku Yamahata
                  XIO3130_MSI_SUPPORTED_FLAGS & PCI_MSI_FLAGS_64BIT,
73 faf1e708 Isaku Yamahata
                  XIO3130_MSI_SUPPORTED_FLAGS & PCI_MSI_FLAGS_MASKBIT);
74 faf1e708 Isaku Yamahata
    if (rc < 0) {
75 faf1e708 Isaku Yamahata
        return rc;
76 faf1e708 Isaku Yamahata
    }
77 faf1e708 Isaku Yamahata
    rc = pci_bridge_ssvid_init(d, XIO3130_SSVID_OFFSET,
78 faf1e708 Isaku Yamahata
                               XIO3130_SSVID_SVID, XIO3130_SSVID_SSID);
79 faf1e708 Isaku Yamahata
    if (rc < 0) {
80 faf1e708 Isaku Yamahata
        return rc;
81 faf1e708 Isaku Yamahata
    }
82 faf1e708 Isaku Yamahata
    rc = pcie_cap_init(d, XIO3130_EXP_OFFSET, PCI_EXP_TYPE_UPSTREAM,
83 faf1e708 Isaku Yamahata
                       p->port);
84 faf1e708 Isaku Yamahata
    if (rc < 0) {
85 faf1e708 Isaku Yamahata
        return rc;
86 faf1e708 Isaku Yamahata
    }
87 faf1e708 Isaku Yamahata
88 faf1e708 Isaku Yamahata
    /* TODO: implement FLR */
89 faf1e708 Isaku Yamahata
    pcie_cap_flr_init(d);
90 faf1e708 Isaku Yamahata
91 faf1e708 Isaku Yamahata
    pcie_cap_deverr_init(d);
92 faf1e708 Isaku Yamahata
    /* TODO: AER */
93 faf1e708 Isaku Yamahata
94 faf1e708 Isaku Yamahata
    return 0;
95 faf1e708 Isaku Yamahata
}
96 faf1e708 Isaku Yamahata
97 faf1e708 Isaku Yamahata
static int xio3130_upstream_exitfn(PCIDevice *d)
98 faf1e708 Isaku Yamahata
{
99 faf1e708 Isaku Yamahata
    /* TODO: AER */
100 faf1e708 Isaku Yamahata
    msi_uninit(d);
101 faf1e708 Isaku Yamahata
    pcie_cap_exit(d);
102 faf1e708 Isaku Yamahata
    return pci_bridge_exitfn(d);
103 faf1e708 Isaku Yamahata
}
104 faf1e708 Isaku Yamahata
105 faf1e708 Isaku Yamahata
PCIEPort *xio3130_upstream_init(PCIBus *bus, int devfn, bool multifunction,
106 faf1e708 Isaku Yamahata
                             const char *bus_name, pci_map_irq_fn map_irq,
107 faf1e708 Isaku Yamahata
                             uint8_t port)
108 faf1e708 Isaku Yamahata
{
109 faf1e708 Isaku Yamahata
    PCIDevice *d;
110 faf1e708 Isaku Yamahata
    PCIBridge *br;
111 faf1e708 Isaku Yamahata
    DeviceState *qdev;
112 faf1e708 Isaku Yamahata
113 faf1e708 Isaku Yamahata
    d = pci_create_multifunction(bus, devfn, multifunction, "x3130-upstream");
114 faf1e708 Isaku Yamahata
    if (!d) {
115 faf1e708 Isaku Yamahata
        return NULL;
116 faf1e708 Isaku Yamahata
    }
117 faf1e708 Isaku Yamahata
    br = DO_UPCAST(PCIBridge, dev, d);
118 faf1e708 Isaku Yamahata
119 faf1e708 Isaku Yamahata
    qdev = &br->dev.qdev;
120 faf1e708 Isaku Yamahata
    pci_bridge_map_irq(br, bus_name, map_irq);
121 faf1e708 Isaku Yamahata
    qdev_prop_set_uint8(qdev, "port", port);
122 faf1e708 Isaku Yamahata
    qdev_init_nofail(qdev);
123 faf1e708 Isaku Yamahata
124 faf1e708 Isaku Yamahata
    return DO_UPCAST(PCIEPort, br, br);
125 faf1e708 Isaku Yamahata
}
126 faf1e708 Isaku Yamahata
127 faf1e708 Isaku Yamahata
static const VMStateDescription vmstate_xio3130_upstream = {
128 faf1e708 Isaku Yamahata
    .name = "xio3130-express-upstream-port",
129 faf1e708 Isaku Yamahata
    .version_id = 1,
130 faf1e708 Isaku Yamahata
    .minimum_version_id = 1,
131 faf1e708 Isaku Yamahata
    .minimum_version_id_old = 1,
132 faf1e708 Isaku Yamahata
    .fields = (VMStateField[]) {
133 faf1e708 Isaku Yamahata
        VMSTATE_PCIE_DEVICE(br.dev, PCIEPort),
134 faf1e708 Isaku Yamahata
        /* TODO: AER */
135 faf1e708 Isaku Yamahata
        VMSTATE_END_OF_LIST()
136 faf1e708 Isaku Yamahata
    }
137 faf1e708 Isaku Yamahata
};
138 faf1e708 Isaku Yamahata
139 faf1e708 Isaku Yamahata
static PCIDeviceInfo xio3130_upstream_info = {
140 faf1e708 Isaku Yamahata
    .qdev.name = "x3130-upstream",
141 faf1e708 Isaku Yamahata
    .qdev.desc = "TI X3130 Upstream Port of PCI Express Switch",
142 faf1e708 Isaku Yamahata
    .qdev.size = sizeof(PCIEPort),
143 faf1e708 Isaku Yamahata
    .qdev.reset = xio3130_upstream_reset,
144 faf1e708 Isaku Yamahata
    .qdev.vmsd = &vmstate_xio3130_upstream,
145 faf1e708 Isaku Yamahata
146 faf1e708 Isaku Yamahata
    .is_express = 1,
147 faf1e708 Isaku Yamahata
    .is_bridge = 1,
148 faf1e708 Isaku Yamahata
    .config_write = xio3130_upstream_write_config,
149 faf1e708 Isaku Yamahata
    .init = xio3130_upstream_initfn,
150 faf1e708 Isaku Yamahata
    .exit = xio3130_upstream_exitfn,
151 faf1e708 Isaku Yamahata
152 faf1e708 Isaku Yamahata
    .qdev.props = (Property[]) {
153 faf1e708 Isaku Yamahata
        DEFINE_PROP_UINT8("port", PCIEPort, port, 0),
154 faf1e708 Isaku Yamahata
        /* TODO: AER */
155 faf1e708 Isaku Yamahata
        DEFINE_PROP_END_OF_LIST(),
156 faf1e708 Isaku Yamahata
    }
157 faf1e708 Isaku Yamahata
};
158 faf1e708 Isaku Yamahata
159 faf1e708 Isaku Yamahata
static void xio3130_upstream_register(void)
160 faf1e708 Isaku Yamahata
{
161 faf1e708 Isaku Yamahata
    pci_qdev_register(&xio3130_upstream_info);
162 faf1e708 Isaku Yamahata
}
163 faf1e708 Isaku Yamahata
164 faf1e708 Isaku Yamahata
device_init(xio3130_upstream_register);
165 faf1e708 Isaku Yamahata
166 faf1e708 Isaku Yamahata
167 faf1e708 Isaku Yamahata
/*
168 faf1e708 Isaku Yamahata
 * Local variables:
169 faf1e708 Isaku Yamahata
 *  c-indent-level: 4
170 faf1e708 Isaku Yamahata
 *  c-basic-offset: 4
171 faf1e708 Isaku Yamahata
 *  tab-width: 8
172 faf1e708 Isaku Yamahata
 *  indent-tab-mode: nil
173 faf1e708 Isaku Yamahata
 * End:
174 faf1e708 Isaku Yamahata
 */