Statistics
| Branch: | Revision:

root / hw / grackle_pci.c @ f08b32fe

History | View | Annotate | Download (6 kB)

1 502a5395 pbrook
/*
2 3cbee15b j_mayer
 * QEMU Grackle PCI host (heathrow OldWorld PowerMac)
3 502a5395 pbrook
 *
4 3cbee15b j_mayer
 * Copyright (c) 2006-2007 Fabrice Bellard
5 3cbee15b j_mayer
 * Copyright (c) 2007 Jocelyn Mayer
6 5fafdf24 ths
 *
7 502a5395 pbrook
 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 502a5395 pbrook
 * of this software and associated documentation files (the "Software"), to deal
9 502a5395 pbrook
 * in the Software without restriction, including without limitation the rights
10 502a5395 pbrook
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 502a5395 pbrook
 * copies of the Software, and to permit persons to whom the Software is
12 502a5395 pbrook
 * furnished to do so, subject to the following conditions:
13 502a5395 pbrook
 *
14 502a5395 pbrook
 * The above copyright notice and this permission notice shall be included in
15 502a5395 pbrook
 * all copies or substantial portions of the Software.
16 502a5395 pbrook
 *
17 502a5395 pbrook
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 502a5395 pbrook
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 502a5395 pbrook
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 502a5395 pbrook
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 502a5395 pbrook
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 502a5395 pbrook
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 502a5395 pbrook
 * THE SOFTWARE.
24 502a5395 pbrook
 */
25 502a5395 pbrook
26 426f17bb Blue Swirl
#include "sysbus.h"
27 3cbee15b j_mayer
#include "ppc_mac.h"
28 87ecb68b pbrook
#include "pci.h"
29 4f5e19e6 Isaku Yamahata
#include "pci_host.h"
30 87ecb68b pbrook
31 ea026b2f blueswir1
/* debug Grackle */
32 ea026b2f blueswir1
//#define DEBUG_GRACKLE
33 ea026b2f blueswir1
34 ea026b2f blueswir1
#ifdef DEBUG_GRACKLE
35 001faf32 Blue Swirl
#define GRACKLE_DPRINTF(fmt, ...)                               \
36 001faf32 Blue Swirl
    do { printf("GRACKLE: " fmt , ## __VA_ARGS__); } while (0)
37 ea026b2f blueswir1
#else
38 001faf32 Blue Swirl
#define GRACKLE_DPRINTF(fmt, ...)
39 ea026b2f blueswir1
#endif
40 ea026b2f blueswir1
41 426f17bb Blue Swirl
typedef struct GrackleState {
42 426f17bb Blue Swirl
    SysBusDevice busdev;
43 426f17bb Blue Swirl
    PCIHostState host_state;
44 426f17bb Blue Swirl
} GrackleState;
45 502a5395 pbrook
46 d2b59317 pbrook
/* Don't know if this matches real hardware, but it agrees with OHW.  */
47 d2b59317 pbrook
static int pci_grackle_map_irq(PCIDevice *pci_dev, int irq_num)
48 502a5395 pbrook
{
49 d2b59317 pbrook
    return (irq_num + (pci_dev->devfn >> 3)) & 3;
50 d2b59317 pbrook
}
51 d2b59317 pbrook
52 5d4e84c8 Juan Quintela
static void pci_grackle_set_irq(void *opaque, int irq_num, int level)
53 d2b59317 pbrook
{
54 5d4e84c8 Juan Quintela
    qemu_irq *pic = opaque;
55 5d4e84c8 Juan Quintela
56 ea026b2f blueswir1
    GRACKLE_DPRINTF("set_irq num %d level %d\n", irq_num, level);
57 3cbee15b j_mayer
    qemu_set_irq(pic[irq_num + 0x15], level);
58 502a5395 pbrook
}
59 502a5395 pbrook
60 9b64997f blueswir1
static void pci_grackle_save(QEMUFile* f, void *opaque)
61 9b64997f blueswir1
{
62 9b64997f blueswir1
    PCIDevice *d = opaque;
63 9b64997f blueswir1
64 9b64997f blueswir1
    pci_device_save(d, f);
65 9b64997f blueswir1
}
66 9b64997f blueswir1
67 9b64997f blueswir1
static int pci_grackle_load(QEMUFile* f, void *opaque, int version_id)
68 9b64997f blueswir1
{
69 9b64997f blueswir1
    PCIDevice *d = opaque;
70 9b64997f blueswir1
71 9b64997f blueswir1
    if (version_id != 1)
72 9b64997f blueswir1
        return -EINVAL;
73 9b64997f blueswir1
74 9b64997f blueswir1
    return pci_device_load(d, f);
75 9b64997f blueswir1
}
76 9b64997f blueswir1
77 6e6b7363 blueswir1
static void pci_grackle_reset(void *opaque)
78 6e6b7363 blueswir1
{
79 6e6b7363 blueswir1
}
80 6e6b7363 blueswir1
81 d537cf6c pbrook
PCIBus *pci_grackle_init(uint32_t base, qemu_irq *pic)
82 502a5395 pbrook
{
83 426f17bb Blue Swirl
    DeviceState *dev;
84 426f17bb Blue Swirl
    SysBusDevice *s;
85 426f17bb Blue Swirl
    GrackleState *d;
86 426f17bb Blue Swirl
87 426f17bb Blue Swirl
    dev = qdev_create(NULL, "grackle");
88 e23a1b33 Markus Armbruster
    qdev_init_nofail(dev);
89 426f17bb Blue Swirl
    s = sysbus_from_qdev(dev);
90 426f17bb Blue Swirl
    d = FROM_SYSBUS(GrackleState, s);
91 cdd0935c Blue Swirl
    d->host_state.bus = pci_register_bus(&d->busdev.qdev, "pci",
92 426f17bb Blue Swirl
                                         pci_grackle_set_irq,
93 426f17bb Blue Swirl
                                         pci_grackle_map_irq,
94 426f17bb Blue Swirl
                                         pic, 0, 4);
95 426f17bb Blue Swirl
96 426f17bb Blue Swirl
    pci_create_simple(d->host_state.bus, 0, "grackle");
97 426f17bb Blue Swirl
98 426f17bb Blue Swirl
    sysbus_mmio_map(s, 0, base);
99 426f17bb Blue Swirl
    sysbus_mmio_map(s, 1, base + 0x00200000);
100 426f17bb Blue Swirl
101 426f17bb Blue Swirl
    return d->host_state.bus;
102 426f17bb Blue Swirl
}
103 426f17bb Blue Swirl
104 81a322d4 Gerd Hoffmann
static int pci_grackle_init_device(SysBusDevice *dev)
105 426f17bb Blue Swirl
{
106 426f17bb Blue Swirl
    GrackleState *s;
107 426f17bb Blue Swirl
    int pci_mem_config, pci_mem_data;
108 426f17bb Blue Swirl
109 426f17bb Blue Swirl
    s = FROM_SYSBUS(GrackleState, dev);
110 426f17bb Blue Swirl
111 f08b32fe Isaku Yamahata
    pci_mem_config = pci_host_conf_register_mmio(&s->host_state);
112 f08b32fe Isaku Yamahata
    pci_mem_data = pci_host_data_register_mmio(&s->host_state);
113 426f17bb Blue Swirl
    sysbus_init_mmio(dev, 0x1000, pci_mem_config);
114 426f17bb Blue Swirl
    sysbus_init_mmio(dev, 0x1000, pci_mem_data);
115 426f17bb Blue Swirl
116 426f17bb Blue Swirl
    register_savevm("grackle", 0, 1, pci_grackle_save, pci_grackle_load,
117 426f17bb Blue Swirl
                    &s->host_state);
118 426f17bb Blue Swirl
    qemu_register_reset(pci_grackle_reset, &s->host_state);
119 81a322d4 Gerd Hoffmann
    return 0;
120 426f17bb Blue Swirl
}
121 426f17bb Blue Swirl
122 81a322d4 Gerd Hoffmann
static int pci_dec_21154_init_device(SysBusDevice *dev)
123 426f17bb Blue Swirl
{
124 502a5395 pbrook
    GrackleState *s;
125 502a5395 pbrook
    int pci_mem_config, pci_mem_data;
126 502a5395 pbrook
127 426f17bb Blue Swirl
    s = FROM_SYSBUS(GrackleState, dev);
128 502a5395 pbrook
129 f08b32fe Isaku Yamahata
    pci_mem_config = pci_host_conf_register_mmio(&s->host_state);
130 f08b32fe Isaku Yamahata
    pci_mem_data = pci_host_data_register_mmio(&s->host_state);
131 426f17bb Blue Swirl
    sysbus_init_mmio(dev, 0x1000, pci_mem_config);
132 426f17bb Blue Swirl
    sysbus_init_mmio(dev, 0x1000, pci_mem_data);
133 81a322d4 Gerd Hoffmann
    return 0;
134 426f17bb Blue Swirl
}
135 426f17bb Blue Swirl
136 81a322d4 Gerd Hoffmann
static int grackle_pci_host_init(PCIDevice *d)
137 426f17bb Blue Swirl
{
138 deb54399 aliguori
    pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_MOTOROLA);
139 deb54399 aliguori
    pci_config_set_device_id(d->config, PCI_DEVICE_ID_MOTOROLA_MPC106);
140 502a5395 pbrook
    d->config[0x08] = 0x00; // revision
141 502a5395 pbrook
    d->config[0x09] = 0x01;
142 173a543b blueswir1
    pci_config_set_class(d->config, PCI_CLASS_BRIDGE_HOST);
143 6407f373 Isaku Yamahata
    d->config[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL; // header_type
144 81a322d4 Gerd Hoffmann
    return 0;
145 426f17bb Blue Swirl
}
146 502a5395 pbrook
147 81a322d4 Gerd Hoffmann
static int dec_21154_pci_host_init(PCIDevice *d)
148 426f17bb Blue Swirl
{
149 502a5395 pbrook
    /* PCI2PCI bridge same values as PearPC - check this */
150 4ebcf884 blueswir1
    pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_DEC);
151 4ebcf884 blueswir1
    pci_config_set_device_id(d->config, PCI_DEVICE_ID_DEC_21154);
152 502a5395 pbrook
    d->config[0x08] = 0x02; // revision
153 173a543b blueswir1
    pci_config_set_class(d->config, PCI_CLASS_BRIDGE_PCI);
154 6407f373 Isaku Yamahata
    d->config[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_BRIDGE; // header_type
155 502a5395 pbrook
156 502a5395 pbrook
    d->config[0x18] = 0x0;  // primary_bus
157 502a5395 pbrook
    d->config[0x19] = 0x1;  // secondary_bus
158 502a5395 pbrook
    d->config[0x1a] = 0x1;  // subordinate_bus
159 502a5395 pbrook
    d->config[0x1c] = 0x10; // io_base
160 502a5395 pbrook
    d->config[0x1d] = 0x20; // io_limit
161 3b46e624 ths
162 502a5395 pbrook
    d->config[0x20] = 0x80; // memory_base
163 502a5395 pbrook
    d->config[0x21] = 0x80;
164 502a5395 pbrook
    d->config[0x22] = 0x90; // memory_limit
165 502a5395 pbrook
    d->config[0x23] = 0x80;
166 3b46e624 ths
167 502a5395 pbrook
    d->config[0x24] = 0x00; // prefetchable_memory_base
168 502a5395 pbrook
    d->config[0x25] = 0x84;
169 502a5395 pbrook
    d->config[0x26] = 0x00; // prefetchable_memory_limit
170 502a5395 pbrook
    d->config[0x27] = 0x85;
171 81a322d4 Gerd Hoffmann
    return 0;
172 426f17bb Blue Swirl
}
173 426f17bb Blue Swirl
174 426f17bb Blue Swirl
static PCIDeviceInfo grackle_pci_host_info = {
175 426f17bb Blue Swirl
    .qdev.name = "grackle",
176 426f17bb Blue Swirl
    .qdev.size = sizeof(PCIDevice),
177 426f17bb Blue Swirl
    .init      = grackle_pci_host_init,
178 426f17bb Blue Swirl
};
179 6e6b7363 blueswir1
180 426f17bb Blue Swirl
static PCIDeviceInfo dec_21154_pci_host_info = {
181 426f17bb Blue Swirl
    .qdev.name = "DEC 21154",
182 426f17bb Blue Swirl
    .qdev.size = sizeof(PCIDevice),
183 426f17bb Blue Swirl
    .init      = dec_21154_pci_host_init,
184 426f17bb Blue Swirl
};
185 426f17bb Blue Swirl
186 426f17bb Blue Swirl
static void grackle_register_devices(void)
187 426f17bb Blue Swirl
{
188 426f17bb Blue Swirl
    sysbus_register_dev("grackle", sizeof(GrackleState),
189 426f17bb Blue Swirl
                        pci_grackle_init_device);
190 426f17bb Blue Swirl
    pci_qdev_register(&grackle_pci_host_info);
191 426f17bb Blue Swirl
    sysbus_register_dev("DEC 21154", sizeof(GrackleState),
192 426f17bb Blue Swirl
                        pci_dec_21154_init_device);
193 426f17bb Blue Swirl
    pci_qdev_register(&dec_21154_pci_host_info);
194 502a5395 pbrook
}
195 426f17bb Blue Swirl
196 426f17bb Blue Swirl
device_init(grackle_register_devices)