Statistics
| Branch: | Revision:

root / hw / dec_pci.c @ 5e22c276

History | View | Annotate | Download (4.6 kB)

1 e1c6bbab Blue Swirl
/*
2 e1c6bbab Blue Swirl
 * QEMU DEC 21154 PCI bridge
3 e1c6bbab Blue Swirl
 *
4 e1c6bbab Blue Swirl
 * Copyright (c) 2006-2007 Fabrice Bellard
5 e1c6bbab Blue Swirl
 * Copyright (c) 2007 Jocelyn Mayer
6 e1c6bbab Blue Swirl
 *
7 e1c6bbab Blue Swirl
 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 e1c6bbab Blue Swirl
 * of this software and associated documentation files (the "Software"), to deal
9 e1c6bbab Blue Swirl
 * in the Software without restriction, including without limitation the rights
10 e1c6bbab Blue Swirl
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 e1c6bbab Blue Swirl
 * copies of the Software, and to permit persons to whom the Software is
12 e1c6bbab Blue Swirl
 * furnished to do so, subject to the following conditions:
13 e1c6bbab Blue Swirl
 *
14 e1c6bbab Blue Swirl
 * The above copyright notice and this permission notice shall be included in
15 e1c6bbab Blue Swirl
 * all copies or substantial portions of the Software.
16 e1c6bbab Blue Swirl
 *
17 e1c6bbab Blue Swirl
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 e1c6bbab Blue Swirl
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 e1c6bbab Blue Swirl
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 e1c6bbab Blue Swirl
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 e1c6bbab Blue Swirl
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 e1c6bbab Blue Swirl
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 e1c6bbab Blue Swirl
 * THE SOFTWARE.
24 e1c6bbab Blue Swirl
 */
25 e1c6bbab Blue Swirl
26 d55380bb Blue Swirl
#include "dec_pci.h"
27 e1c6bbab Blue Swirl
#include "sysbus.h"
28 a2cb15b0 Michael S. Tsirkin
#include "pci/pci.h"
29 a2cb15b0 Michael S. Tsirkin
#include "pci/pci_host.h"
30 a2cb15b0 Michael S. Tsirkin
#include "pci/pci_bridge.h"
31 06aac7bd Michael S. Tsirkin
#include "pci/pci_bus.h"
32 e1c6bbab Blue Swirl
33 e1c6bbab Blue Swirl
/* debug DEC */
34 e1c6bbab Blue Swirl
//#define DEBUG_DEC
35 e1c6bbab Blue Swirl
36 e1c6bbab Blue Swirl
#ifdef DEBUG_DEC
37 e1c6bbab Blue Swirl
#define DEC_DPRINTF(fmt, ...)                               \
38 e1c6bbab Blue Swirl
    do { printf("DEC: " fmt , ## __VA_ARGS__); } while (0)
39 e1c6bbab Blue Swirl
#else
40 e1c6bbab Blue Swirl
#define DEC_DPRINTF(fmt, ...)
41 e1c6bbab Blue Swirl
#endif
42 e1c6bbab Blue Swirl
43 ab615367 Andreas Färber
#define DEC_21154(obj) OBJECT_CHECK(DECState, (obj), TYPE_DEC_21154)
44 ab615367 Andreas Färber
45 e1c6bbab Blue Swirl
typedef struct DECState {
46 67c332fd Andreas Färber
    PCIHostState parent_obj;
47 e1c6bbab Blue Swirl
} DECState;
48 e1c6bbab Blue Swirl
49 d55380bb Blue Swirl
static int dec_map_irq(PCIDevice *pci_dev, int irq_num)
50 d55380bb Blue Swirl
{
51 d55380bb Blue Swirl
    return irq_num;
52 d55380bb Blue Swirl
}
53 d55380bb Blue Swirl
54 40021f08 Anthony Liguori
static void dec_21154_pci_bridge_class_init(ObjectClass *klass, void *data)
55 40021f08 Anthony Liguori
{
56 39bffca2 Anthony Liguori
    DeviceClass *dc = DEVICE_CLASS(klass);
57 40021f08 Anthony Liguori
    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
58 40021f08 Anthony Liguori
59 40021f08 Anthony Liguori
    k->init = pci_bridge_initfn;
60 40021f08 Anthony Liguori
    k->exit = pci_bridge_exitfn;
61 40021f08 Anthony Liguori
    k->vendor_id = PCI_VENDOR_ID_DEC;
62 40021f08 Anthony Liguori
    k->device_id = PCI_DEVICE_ID_DEC_21154;
63 40021f08 Anthony Liguori
    k->config_write = pci_bridge_write_config;
64 40021f08 Anthony Liguori
    k->is_bridge = 1;
65 39bffca2 Anthony Liguori
    dc->desc = "DEC 21154 PCI-PCI bridge";
66 39bffca2 Anthony Liguori
    dc->reset = pci_bridge_reset;
67 39bffca2 Anthony Liguori
    dc->vmsd = &vmstate_pci_device;
68 40021f08 Anthony Liguori
}
69 40021f08 Anthony Liguori
70 4240abff Andreas Färber
static const TypeInfo dec_21154_pci_bridge_info = {
71 39bffca2 Anthony Liguori
    .name          = "dec-21154-p2p-bridge",
72 39bffca2 Anthony Liguori
    .parent        = TYPE_PCI_DEVICE,
73 39bffca2 Anthony Liguori
    .instance_size = sizeof(PCIBridge),
74 39bffca2 Anthony Liguori
    .class_init    = dec_21154_pci_bridge_class_init,
75 68f79994 Isaku Yamahata
};
76 68f79994 Isaku Yamahata
77 68f79994 Isaku Yamahata
PCIBus *pci_dec_21154_init(PCIBus *parent_bus, int devfn)
78 68f79994 Isaku Yamahata
{
79 68f79994 Isaku Yamahata
    PCIDevice *dev;
80 68f79994 Isaku Yamahata
    PCIBridge *br;
81 d55380bb Blue Swirl
82 68f79994 Isaku Yamahata
    dev = pci_create_multifunction(parent_bus, devfn, false,
83 68f79994 Isaku Yamahata
                                   "dec-21154-p2p-bridge");
84 68f79994 Isaku Yamahata
    br = DO_UPCAST(PCIBridge, dev, dev);
85 68f79994 Isaku Yamahata
    pci_bridge_map_irq(br, "DEC 21154 PCI-PCI bridge", dec_map_irq);
86 68f79994 Isaku Yamahata
    qdev_init_nofail(&dev->qdev);
87 68f79994 Isaku Yamahata
    return pci_bridge_get_sec_bus(br);
88 d55380bb Blue Swirl
}
89 d55380bb Blue Swirl
90 999e12bb Anthony Liguori
static int pci_dec_21154_device_init(SysBusDevice *dev)
91 e1c6bbab Blue Swirl
{
92 ab615367 Andreas Färber
    PCIHostState *phb;
93 e1c6bbab Blue Swirl
94 8558d942 Andreas Färber
    phb = PCI_HOST_BRIDGE(dev);
95 e1c6bbab Blue Swirl
96 ab615367 Andreas Färber
    memory_region_init_io(&phb->conf_mem, &pci_host_conf_le_ops,
97 ab615367 Andreas Färber
                          dev, "pci-conf-idx", 0x1000);
98 ab615367 Andreas Färber
    memory_region_init_io(&phb->data_mem, &pci_host_data_le_ops,
99 ab615367 Andreas Färber
                          dev, "pci-data-idx", 0x1000);
100 ab615367 Andreas Färber
    sysbus_init_mmio(dev, &phb->conf_mem);
101 ab615367 Andreas Färber
    sysbus_init_mmio(dev, &phb->data_mem);
102 e1c6bbab Blue Swirl
    return 0;
103 e1c6bbab Blue Swirl
}
104 e1c6bbab Blue Swirl
105 e1c6bbab Blue Swirl
static int dec_21154_pci_host_init(PCIDevice *d)
106 e1c6bbab Blue Swirl
{
107 e1c6bbab Blue Swirl
    /* PCI2PCI bridge same values as PearPC - check this */
108 e1c6bbab Blue Swirl
    return 0;
109 e1c6bbab Blue Swirl
}
110 e1c6bbab Blue Swirl
111 40021f08 Anthony Liguori
static void dec_21154_pci_host_class_init(ObjectClass *klass, void *data)
112 40021f08 Anthony Liguori
{
113 40021f08 Anthony Liguori
    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
114 40021f08 Anthony Liguori
115 40021f08 Anthony Liguori
    k->init = dec_21154_pci_host_init;
116 40021f08 Anthony Liguori
    k->vendor_id = PCI_VENDOR_ID_DEC;
117 40021f08 Anthony Liguori
    k->device_id = PCI_DEVICE_ID_DEC_21154;
118 40021f08 Anthony Liguori
    k->revision = 0x02;
119 40021f08 Anthony Liguori
    k->class_id = PCI_CLASS_BRIDGE_PCI;
120 40021f08 Anthony Liguori
    k->is_bridge = 1;
121 40021f08 Anthony Liguori
}
122 40021f08 Anthony Liguori
123 4240abff Andreas Färber
static const TypeInfo dec_21154_pci_host_info = {
124 39bffca2 Anthony Liguori
    .name          = "dec-21154",
125 39bffca2 Anthony Liguori
    .parent        = TYPE_PCI_DEVICE,
126 39bffca2 Anthony Liguori
    .instance_size = sizeof(PCIDevice),
127 39bffca2 Anthony Liguori
    .class_init    = dec_21154_pci_host_class_init,
128 e1c6bbab Blue Swirl
};
129 e1c6bbab Blue Swirl
130 999e12bb Anthony Liguori
static void pci_dec_21154_device_class_init(ObjectClass *klass, void *data)
131 e1c6bbab Blue Swirl
{
132 999e12bb Anthony Liguori
    SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
133 999e12bb Anthony Liguori
134 999e12bb Anthony Liguori
    sdc->init = pci_dec_21154_device_init;
135 999e12bb Anthony Liguori
}
136 999e12bb Anthony Liguori
137 4240abff Andreas Färber
static const TypeInfo pci_dec_21154_device_info = {
138 ab615367 Andreas Färber
    .name          = TYPE_DEC_21154,
139 8558d942 Andreas Färber
    .parent        = TYPE_PCI_HOST_BRIDGE,
140 39bffca2 Anthony Liguori
    .instance_size = sizeof(DECState),
141 39bffca2 Anthony Liguori
    .class_init    = pci_dec_21154_device_class_init,
142 999e12bb Anthony Liguori
};
143 40021f08 Anthony Liguori
144 83f7d43a Andreas Färber
static void dec_register_types(void)
145 999e12bb Anthony Liguori
{
146 39bffca2 Anthony Liguori
    type_register_static(&pci_dec_21154_device_info);
147 39bffca2 Anthony Liguori
    type_register_static(&dec_21154_pci_host_info);
148 39bffca2 Anthony Liguori
    type_register_static(&dec_21154_pci_bridge_info);
149 e1c6bbab Blue Swirl
}
150 e1c6bbab Blue Swirl
151 83f7d43a Andreas Färber
type_init(dec_register_types)