dec.c 4.7 KB
Newer Older
B
Blue Swirl 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/*
 * QEMU DEC 21154 PCI bridge
 *
 * Copyright (c) 2006-2007 Fabrice Bellard
 * Copyright (c) 2007 Jocelyn Mayer
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

26
#include "dec.h"
27 28 29 30 31
#include "hw/sysbus.h"
#include "hw/pci/pci.h"
#include "hw/pci/pci_host.h"
#include "hw/pci/pci_bridge.h"
#include "hw/pci/pci_bus.h"
B
Blue Swirl 已提交
32 33 34 35 36 37 38 39 40 41 42

/* debug DEC */
//#define DEBUG_DEC

#ifdef DEBUG_DEC
#define DEC_DPRINTF(fmt, ...)                               \
    do { printf("DEC: " fmt , ## __VA_ARGS__); } while (0)
#else
#define DEC_DPRINTF(fmt, ...)
#endif

43 44
#define DEC_21154(obj) OBJECT_CHECK(DECState, (obj), TYPE_DEC_21154)

B
Blue Swirl 已提交
45
typedef struct DECState {
A
Andreas Färber 已提交
46
    PCIHostState parent_obj;
B
Blue Swirl 已提交
47 48
} DECState;

49 50 51 52 53
static int dec_map_irq(PCIDevice *pci_dev, int irq_num)
{
    return irq_num;
}

54 55 56 57 58
static int dec_pci_bridge_initfn(PCIDevice *pci_dev)
{
    return pci_bridge_initfn(pci_dev, TYPE_PCI_BUS);
}

59 60
static void dec_21154_pci_bridge_class_init(ObjectClass *klass, void *data)
{
61
    DeviceClass *dc = DEVICE_CLASS(klass);
62 63
    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);

64
    k->init = dec_pci_bridge_initfn;
65 66 67 68 69
    k->exit = pci_bridge_exitfn;
    k->vendor_id = PCI_VENDOR_ID_DEC;
    k->device_id = PCI_DEVICE_ID_DEC_21154;
    k->config_write = pci_bridge_write_config;
    k->is_bridge = 1;
70 71 72
    dc->desc = "DEC 21154 PCI-PCI bridge";
    dc->reset = pci_bridge_reset;
    dc->vmsd = &vmstate_pci_device;
73 74
}

75
static const TypeInfo dec_21154_pci_bridge_info = {
76
    .name          = "dec-21154-p2p-bridge",
77
    .parent        = TYPE_PCI_BRIDGE,
78 79
    .instance_size = sizeof(PCIBridge),
    .class_init    = dec_21154_pci_bridge_class_init,
80 81 82 83 84 85
};

PCIBus *pci_dec_21154_init(PCIBus *parent_bus, int devfn)
{
    PCIDevice *dev;
    PCIBridge *br;
86

87 88
    dev = pci_create_multifunction(parent_bus, devfn, false,
                                   "dec-21154-p2p-bridge");
89
    br = PCI_BRIDGE(dev);
90 91 92
    pci_bridge_map_irq(br, "DEC 21154 PCI-PCI bridge", dec_map_irq);
    qdev_init_nofail(&dev->qdev);
    return pci_bridge_get_sec_bus(br);
93 94
}

95
static int pci_dec_21154_device_init(SysBusDevice *dev)
B
Blue Swirl 已提交
96
{
97
    PCIHostState *phb;
B
Blue Swirl 已提交
98

99
    phb = PCI_HOST_BRIDGE(dev);
B
Blue Swirl 已提交
100

101
    memory_region_init_io(&phb->conf_mem, OBJECT(dev), &pci_host_conf_le_ops,
102
                          dev, "pci-conf-idx", 0x1000);
103
    memory_region_init_io(&phb->data_mem, OBJECT(dev), &pci_host_data_le_ops,
104 105 106
                          dev, "pci-data-idx", 0x1000);
    sysbus_init_mmio(dev, &phb->conf_mem);
    sysbus_init_mmio(dev, &phb->data_mem);
B
Blue Swirl 已提交
107 108 109 110 111 112 113 114 115
    return 0;
}

static int dec_21154_pci_host_init(PCIDevice *d)
{
    /* PCI2PCI bridge same values as PearPC - check this */
    return 0;
}

116 117 118 119 120 121 122 123 124 125 126 127
static void dec_21154_pci_host_class_init(ObjectClass *klass, void *data)
{
    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);

    k->init = dec_21154_pci_host_init;
    k->vendor_id = PCI_VENDOR_ID_DEC;
    k->device_id = PCI_DEVICE_ID_DEC_21154;
    k->revision = 0x02;
    k->class_id = PCI_CLASS_BRIDGE_PCI;
    k->is_bridge = 1;
}

128
static const TypeInfo dec_21154_pci_host_info = {
129 130 131 132
    .name          = "dec-21154",
    .parent        = TYPE_PCI_DEVICE,
    .instance_size = sizeof(PCIDevice),
    .class_init    = dec_21154_pci_host_class_init,
B
Blue Swirl 已提交
133 134
};

135
static void pci_dec_21154_device_class_init(ObjectClass *klass, void *data)
B
Blue Swirl 已提交
136
{
137 138 139 140 141
    SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);

    sdc->init = pci_dec_21154_device_init;
}

142
static const TypeInfo pci_dec_21154_device_info = {
143
    .name          = TYPE_DEC_21154,
144
    .parent        = TYPE_PCI_HOST_BRIDGE,
145 146
    .instance_size = sizeof(DECState),
    .class_init    = pci_dec_21154_device_class_init,
147
};
148

A
Andreas Färber 已提交
149
static void dec_register_types(void)
150
{
151 152 153
    type_register_static(&pci_dec_21154_device_info);
    type_register_static(&dec_21154_pci_host_info);
    type_register_static(&dec_21154_pci_bridge_info);
B
Blue Swirl 已提交
154 155
}

A
Andreas Färber 已提交
156
type_init(dec_register_types)