blob: c30ade38bde3295effb8431c4fd59d925d6fa120 [file] [log] [blame]
Blue Swirle1c6bba2010-02-05 18:48:36 +00001/*
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
Blue Swirld55380b2010-02-07 19:28:32 +000026#include "dec_pci.h"
Blue Swirle1c6bba2010-02-05 18:48:36 +000027#include "sysbus.h"
28#include "pci.h"
29#include "pci_host.h"
Isaku Yamahata783753f2010-07-13 13:01:39 +090030#include "pci_bridge.h"
Isaku Yamahata68f79992010-07-13 13:01:42 +090031#include "pci_internals.h"
Blue Swirle1c6bba2010-02-05 18:48:36 +000032
33/* debug DEC */
34//#define DEBUG_DEC
35
36#ifdef DEBUG_DEC
37#define DEC_DPRINTF(fmt, ...) \
38 do { printf("DEC: " fmt , ## __VA_ARGS__); } while (0)
39#else
40#define DEC_DPRINTF(fmt, ...)
41#endif
42
Andreas Färberab615362012-08-20 19:07:59 +020043#define DEC_21154(obj) OBJECT_CHECK(DECState, (obj), TYPE_DEC_21154)
44
Blue Swirle1c6bba2010-02-05 18:48:36 +000045typedef struct DECState {
Andreas Färber67c332f2012-08-20 19:08:09 +020046 PCIHostState parent_obj;
Blue Swirle1c6bba2010-02-05 18:48:36 +000047} DECState;
48
Blue Swirld55380b2010-02-07 19:28:32 +000049static int dec_map_irq(PCIDevice *pci_dev, int irq_num)
50{
51 return irq_num;
52}
53
Anthony Liguori40021f02011-12-04 12:22:06 -060054static void dec_21154_pci_bridge_class_init(ObjectClass *klass, void *data)
55{
Anthony Liguori39bffca2011-12-07 21:34:16 -060056 DeviceClass *dc = DEVICE_CLASS(klass);
Anthony Liguori40021f02011-12-04 12:22:06 -060057 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
58
59 k->init = pci_bridge_initfn;
60 k->exit = pci_bridge_exitfn;
61 k->vendor_id = PCI_VENDOR_ID_DEC;
62 k->device_id = PCI_DEVICE_ID_DEC_21154;
63 k->config_write = pci_bridge_write_config;
64 k->is_bridge = 1;
Anthony Liguori39bffca2011-12-07 21:34:16 -060065 dc->desc = "DEC 21154 PCI-PCI bridge";
66 dc->reset = pci_bridge_reset;
67 dc->vmsd = &vmstate_pci_device;
Anthony Liguori40021f02011-12-04 12:22:06 -060068}
69
Andreas Färber4240abf2012-08-20 19:07:56 +020070static const TypeInfo dec_21154_pci_bridge_info = {
Anthony Liguori39bffca2011-12-07 21:34:16 -060071 .name = "dec-21154-p2p-bridge",
72 .parent = TYPE_PCI_DEVICE,
73 .instance_size = sizeof(PCIBridge),
74 .class_init = dec_21154_pci_bridge_class_init,
Isaku Yamahata68f79992010-07-13 13:01:42 +090075};
76
Blue Swirld55380b2010-02-07 19:28:32 +000077PCIBus *pci_dec_21154_init(PCIBus *parent_bus, int devfn)
78{
Isaku Yamahata68f79992010-07-13 13:01:42 +090079 PCIDevice *dev;
80 PCIBridge *br;
Blue Swirld55380b2010-02-07 19:28:32 +000081
Isaku Yamahata68f79992010-07-13 13:01:42 +090082 dev = pci_create_multifunction(parent_bus, devfn, false,
83 "dec-21154-p2p-bridge");
84 br = DO_UPCAST(PCIBridge, dev, dev);
85 pci_bridge_map_irq(br, "DEC 21154 PCI-PCI bridge", dec_map_irq);
86 qdev_init_nofail(&dev->qdev);
87 return pci_bridge_get_sec_bus(br);
Blue Swirld55380b2010-02-07 19:28:32 +000088}
89
Anthony Liguori999e12b2012-01-24 13:12:29 -060090static int pci_dec_21154_device_init(SysBusDevice *dev)
Blue Swirle1c6bba2010-02-05 18:48:36 +000091{
Andreas Färberab615362012-08-20 19:07:59 +020092 PCIHostState *phb;
Blue Swirle1c6bba2010-02-05 18:48:36 +000093
Andreas Färber8558d942012-08-20 19:08:08 +020094 phb = PCI_HOST_BRIDGE(dev);
Blue Swirle1c6bba2010-02-05 18:48:36 +000095
Andreas Färberab615362012-08-20 19:07:59 +020096 memory_region_init_io(&phb->conf_mem, &pci_host_conf_le_ops,
97 dev, "pci-conf-idx", 0x1000);
98 memory_region_init_io(&phb->data_mem, &pci_host_data_le_ops,
99 dev, "pci-data-idx", 0x1000);
100 sysbus_init_mmio(dev, &phb->conf_mem);
101 sysbus_init_mmio(dev, &phb->data_mem);
Blue Swirle1c6bba2010-02-05 18:48:36 +0000102 return 0;
103}
104
105static int dec_21154_pci_host_init(PCIDevice *d)
106{
107 /* PCI2PCI bridge same values as PearPC - check this */
Blue Swirle1c6bba2010-02-05 18:48:36 +0000108 return 0;
109}
110
Anthony Liguori40021f02011-12-04 12:22:06 -0600111static void dec_21154_pci_host_class_init(ObjectClass *klass, void *data)
112{
113 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
114
115 k->init = dec_21154_pci_host_init;
116 k->vendor_id = PCI_VENDOR_ID_DEC;
117 k->device_id = PCI_DEVICE_ID_DEC_21154;
118 k->revision = 0x02;
119 k->class_id = PCI_CLASS_BRIDGE_PCI;
120 k->is_bridge = 1;
121}
122
Andreas Färber4240abf2012-08-20 19:07:56 +0200123static const TypeInfo dec_21154_pci_host_info = {
Anthony Liguori39bffca2011-12-07 21:34:16 -0600124 .name = "dec-21154",
125 .parent = TYPE_PCI_DEVICE,
126 .instance_size = sizeof(PCIDevice),
127 .class_init = dec_21154_pci_host_class_init,
Blue Swirle1c6bba2010-02-05 18:48:36 +0000128};
129
Anthony Liguori999e12b2012-01-24 13:12:29 -0600130static void pci_dec_21154_device_class_init(ObjectClass *klass, void *data)
131{
132 SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
133
134 sdc->init = pci_dec_21154_device_init;
135}
136
Andreas Färber4240abf2012-08-20 19:07:56 +0200137static const TypeInfo pci_dec_21154_device_info = {
Andreas Färberab615362012-08-20 19:07:59 +0200138 .name = TYPE_DEC_21154,
Andreas Färber8558d942012-08-20 19:08:08 +0200139 .parent = TYPE_PCI_HOST_BRIDGE,
Anthony Liguori39bffca2011-12-07 21:34:16 -0600140 .instance_size = sizeof(DECState),
141 .class_init = pci_dec_21154_device_class_init,
Anthony Liguori999e12b2012-01-24 13:12:29 -0600142};
143
Andreas Färber83f7d432012-02-09 15:20:55 +0100144static void dec_register_types(void)
Blue Swirle1c6bba2010-02-05 18:48:36 +0000145{
Anthony Liguori39bffca2011-12-07 21:34:16 -0600146 type_register_static(&pci_dec_21154_device_info);
147 type_register_static(&dec_21154_pci_host_info);
148 type_register_static(&dec_21154_pci_bridge_info);
Blue Swirle1c6bba2010-02-05 18:48:36 +0000149}
150
Andreas Färber83f7d432012-02-09 15:20:55 +0100151type_init(dec_register_types)