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