Statistics
| Branch: | Revision:

root / hw / prep_pci.c @ b072a3c8

History | View | Annotate | Download (5.2 kB)

1 502a5395 pbrook
/*
2 502a5395 pbrook
 * QEMU PREP PCI host
3 502a5395 pbrook
 *
4 502a5395 pbrook
 * Copyright (c) 2006 Fabrice Bellard
5 5fafdf24 ths
 *
6 502a5395 pbrook
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 502a5395 pbrook
 * of this software and associated documentation files (the "Software"), to deal
8 502a5395 pbrook
 * in the Software without restriction, including without limitation the rights
9 502a5395 pbrook
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 502a5395 pbrook
 * copies of the Software, and to permit persons to whom the Software is
11 502a5395 pbrook
 * furnished to do so, subject to the following conditions:
12 502a5395 pbrook
 *
13 502a5395 pbrook
 * The above copyright notice and this permission notice shall be included in
14 502a5395 pbrook
 * all copies or substantial portions of the Software.
15 502a5395 pbrook
 *
16 502a5395 pbrook
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 502a5395 pbrook
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 502a5395 pbrook
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 502a5395 pbrook
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 502a5395 pbrook
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 502a5395 pbrook
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 502a5395 pbrook
 * THE SOFTWARE.
23 502a5395 pbrook
 */
24 502a5395 pbrook
25 87ecb68b pbrook
#include "hw.h"
26 87ecb68b pbrook
#include "pci.h"
27 502a5395 pbrook
#include "pci_host.h"
28 8ca8c7bc Andreas Färber
#include "exec-memory.h"
29 502a5395 pbrook
30 8ca8c7bc Andreas Färber
typedef struct PRePPCIState {
31 8ca8c7bc Andreas Färber
    PCIHostState host_state;
32 8ca8c7bc Andreas Färber
    qemu_irq irq[4];
33 8ca8c7bc Andreas Färber
} PREPPCIState;
34 502a5395 pbrook
35 55526054 Andreas Färber
typedef struct RavenPCIState {
36 55526054 Andreas Färber
    PCIDevice dev;
37 55526054 Andreas Färber
} RavenPCIState;
38 55526054 Andreas Färber
39 c227f099 Anthony Liguori
static inline uint32_t PPC_PCIIO_config(target_phys_addr_t addr)
40 502a5395 pbrook
{
41 502a5395 pbrook
    int i;
42 502a5395 pbrook
43 502a5395 pbrook
    for(i = 0; i < 11; i++) {
44 502a5395 pbrook
        if ((addr & (1 << (11 + i))) != 0)
45 502a5395 pbrook
            break;
46 502a5395 pbrook
    }
47 502a5395 pbrook
    return (addr & 0x7ff) |  (i << 11);
48 502a5395 pbrook
}
49 502a5395 pbrook
50 7e5610ff Andreas Färber
static void ppc_pci_io_write(void *opaque, target_phys_addr_t addr,
51 7e5610ff Andreas Färber
                             uint64_t val, unsigned int size)
52 502a5395 pbrook
{
53 502a5395 pbrook
    PREPPCIState *s = opaque;
54 8ca8c7bc Andreas Färber
    pci_data_write(s->host_state.bus, PPC_PCIIO_config(addr), val, size);
55 502a5395 pbrook
}
56 502a5395 pbrook
57 7e5610ff Andreas Färber
static uint64_t ppc_pci_io_read(void *opaque, target_phys_addr_t addr,
58 7e5610ff Andreas Färber
                                unsigned int size)
59 502a5395 pbrook
{
60 502a5395 pbrook
    PREPPCIState *s = opaque;
61 8ca8c7bc Andreas Färber
    return pci_data_read(s->host_state.bus, PPC_PCIIO_config(addr), size);
62 502a5395 pbrook
}
63 502a5395 pbrook
64 f81138ce Avi Kivity
static const MemoryRegionOps PPC_PCIIO_ops = {
65 7e5610ff Andreas Färber
    .read = ppc_pci_io_read,
66 7e5610ff Andreas Färber
    .write = ppc_pci_io_write,
67 9c95f183 Andreas Färber
    .endianness = DEVICE_LITTLE_ENDIAN,
68 502a5395 pbrook
};
69 502a5395 pbrook
70 d2b59317 pbrook
static int prep_map_irq(PCIDevice *pci_dev, int irq_num)
71 502a5395 pbrook
{
72 80b3ada7 pbrook
    return (irq_num + (pci_dev->devfn >> 3)) & 1;
73 d2b59317 pbrook
}
74 d2b59317 pbrook
75 5d4e84c8 Juan Quintela
static void prep_set_irq(void *opaque, int irq_num, int level)
76 d2b59317 pbrook
{
77 5d4e84c8 Juan Quintela
    qemu_irq *pic = opaque;
78 5d4e84c8 Juan Quintela
79 8ca8c7bc Andreas Färber
    qemu_set_irq(pic[irq_num] , level);
80 502a5395 pbrook
}
81 502a5395 pbrook
82 8ca8c7bc Andreas Färber
static int raven_pcihost_init(SysBusDevice *dev)
83 502a5395 pbrook
{
84 8ca8c7bc Andreas Färber
    PCIHostState *h = FROM_SYSBUS(PCIHostState, dev);
85 8ca8c7bc Andreas Färber
    PREPPCIState *s = DO_UPCAST(PREPPCIState, host_state, h);
86 8ca8c7bc Andreas Färber
    MemoryRegion *address_space_mem = get_system_memory();
87 8ca8c7bc Andreas Färber
    MemoryRegion *address_space_io = get_system_io();
88 8ca8c7bc Andreas Färber
    PCIBus *bus;
89 8ca8c7bc Andreas Färber
    int i;
90 8ca8c7bc Andreas Färber
91 8ca8c7bc Andreas Färber
    for (i = 0; i < 4; i++) {
92 8ca8c7bc Andreas Färber
        sysbus_init_irq(dev, &s->irq[i]);
93 8ca8c7bc Andreas Färber
    }
94 502a5395 pbrook
95 8ca8c7bc Andreas Färber
    bus = pci_register_bus(&h->busdev.qdev, NULL,
96 8ca8c7bc Andreas Färber
                           prep_set_irq, prep_map_irq, s->irq,
97 8ca8c7bc Andreas Färber
                           address_space_mem, address_space_io, 0, 4);
98 8ca8c7bc Andreas Färber
    h->bus = bus;
99 502a5395 pbrook
100 8ca8c7bc Andreas Färber
    memory_region_init_io(&h->conf_mem, &pci_host_conf_be_ops, s,
101 d0ed8076 Avi Kivity
                          "pci-conf-idx", 1);
102 8ca8c7bc Andreas Färber
    sysbus_add_io(dev, 0xcf8, &h->conf_mem);
103 8ca8c7bc Andreas Färber
    sysbus_init_ioports(&h->busdev, 0xcf8, 1);
104 d0ed8076 Avi Kivity
105 8ca8c7bc Andreas Färber
    memory_region_init_io(&h->data_mem, &pci_host_data_be_ops, s,
106 d0ed8076 Avi Kivity
                          "pci-conf-data", 1);
107 8ca8c7bc Andreas Färber
    sysbus_add_io(dev, 0xcfc, &h->data_mem);
108 8ca8c7bc Andreas Färber
    sysbus_init_ioports(&h->busdev, 0xcfc, 1);
109 502a5395 pbrook
110 8ca8c7bc Andreas Färber
    memory_region_init_io(&h->mmcfg, &PPC_PCIIO_ops, s, "pciio", 0x00400000);
111 8ca8c7bc Andreas Färber
    memory_region_add_subregion(address_space_mem, 0x80800000, &h->mmcfg);
112 502a5395 pbrook
113 8ca8c7bc Andreas Färber
    pci_create_simple(bus, 0, "raven");
114 55526054 Andreas Färber
115 8ca8c7bc Andreas Färber
    return 0;
116 55526054 Andreas Färber
}
117 55526054 Andreas Färber
118 55526054 Andreas Färber
static int raven_init(PCIDevice *d)
119 55526054 Andreas Färber
{
120 502a5395 pbrook
    d->config[0x0C] = 0x08; // cache_line_size
121 502a5395 pbrook
    d->config[0x0D] = 0x10; // latency_timer
122 502a5395 pbrook
    d->config[0x34] = 0x00; // capabilities_pointer
123 502a5395 pbrook
124 55526054 Andreas Färber
    return 0;
125 502a5395 pbrook
}
126 55526054 Andreas Färber
127 55526054 Andreas Färber
static const VMStateDescription vmstate_raven = {
128 55526054 Andreas Färber
    .name = "raven",
129 55526054 Andreas Färber
    .version_id = 0,
130 55526054 Andreas Färber
    .minimum_version_id = 0,
131 55526054 Andreas Färber
    .fields = (VMStateField[]) {
132 55526054 Andreas Färber
        VMSTATE_PCI_DEVICE(dev, RavenPCIState),
133 55526054 Andreas Färber
        VMSTATE_END_OF_LIST()
134 55526054 Andreas Färber
    },
135 55526054 Andreas Färber
};
136 55526054 Andreas Färber
137 40021f08 Anthony Liguori
static void raven_class_init(ObjectClass *klass, void *data)
138 40021f08 Anthony Liguori
{
139 40021f08 Anthony Liguori
    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
140 39bffca2 Anthony Liguori
    DeviceClass *dc = DEVICE_CLASS(klass);
141 40021f08 Anthony Liguori
142 40021f08 Anthony Liguori
    k->init = raven_init;
143 40021f08 Anthony Liguori
    k->vendor_id = PCI_VENDOR_ID_MOTOROLA;
144 40021f08 Anthony Liguori
    k->device_id = PCI_DEVICE_ID_MOTOROLA_RAVEN;
145 40021f08 Anthony Liguori
    k->revision = 0x00;
146 40021f08 Anthony Liguori
    k->class_id = PCI_CLASS_BRIDGE_HOST;
147 39bffca2 Anthony Liguori
    dc->desc = "PReP Host Bridge - Motorola Raven";
148 39bffca2 Anthony Liguori
    dc->vmsd = &vmstate_raven;
149 39bffca2 Anthony Liguori
    dc->no_user = 1;
150 40021f08 Anthony Liguori
}
151 40021f08 Anthony Liguori
152 39bffca2 Anthony Liguori
static TypeInfo raven_info = {
153 40021f08 Anthony Liguori
    .name = "raven",
154 39bffca2 Anthony Liguori
    .parent = TYPE_PCI_DEVICE,
155 39bffca2 Anthony Liguori
    .instance_size = sizeof(RavenPCIState),
156 40021f08 Anthony Liguori
    .class_init = raven_class_init,
157 55526054 Andreas Färber
};
158 55526054 Andreas Färber
159 999e12bb Anthony Liguori
static void raven_pcihost_class_init(ObjectClass *klass, void *data)
160 999e12bb Anthony Liguori
{
161 999e12bb Anthony Liguori
    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
162 39bffca2 Anthony Liguori
    DeviceClass *dc = DEVICE_CLASS(klass);
163 999e12bb Anthony Liguori
164 999e12bb Anthony Liguori
    k->init = raven_pcihost_init;
165 39bffca2 Anthony Liguori
    dc->fw_name = "pci";
166 39bffca2 Anthony Liguori
    dc->no_user = 1;
167 999e12bb Anthony Liguori
}
168 999e12bb Anthony Liguori
169 39bffca2 Anthony Liguori
static TypeInfo raven_pcihost_info = {
170 999e12bb Anthony Liguori
    .name = "raven-pcihost",
171 39bffca2 Anthony Liguori
    .parent = TYPE_SYS_BUS_DEVICE,
172 39bffca2 Anthony Liguori
    .instance_size = sizeof(PREPPCIState),
173 999e12bb Anthony Liguori
    .class_init = raven_pcihost_class_init,
174 8ca8c7bc Andreas Färber
};
175 8ca8c7bc Andreas Färber
176 83f7d43a Andreas Färber
static void raven_register_types(void)
177 55526054 Andreas Färber
{
178 39bffca2 Anthony Liguori
    type_register_static(&raven_pcihost_info);
179 39bffca2 Anthony Liguori
    type_register_static(&raven_info);
180 55526054 Andreas Färber
}
181 55526054 Andreas Färber
182 83f7d43a Andreas Färber
type_init(raven_register_types)