Statistics
| Branch: | Revision:

root / hw / grackle_pci.c @ 9a3a8895

History | View | Annotate | Download (5.1 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 0e655047 Andreas Färber
#include "pci_host.h"
27 3cbee15b j_mayer
#include "ppc_mac.h"
28 87ecb68b pbrook
#include "pci.h"
29 87ecb68b pbrook
30 ea026b2f blueswir1
/* debug Grackle */
31 ea026b2f blueswir1
//#define DEBUG_GRACKLE
32 ea026b2f blueswir1
33 ea026b2f blueswir1
#ifdef DEBUG_GRACKLE
34 001faf32 Blue Swirl
#define GRACKLE_DPRINTF(fmt, ...)                               \
35 001faf32 Blue Swirl
    do { printf("GRACKLE: " fmt , ## __VA_ARGS__); } while (0)
36 ea026b2f blueswir1
#else
37 001faf32 Blue Swirl
#define GRACKLE_DPRINTF(fmt, ...)
38 ea026b2f blueswir1
#endif
39 ea026b2f blueswir1
40 0e655047 Andreas Färber
#define GRACKLE_PCI_HOST_BRIDGE(obj) \
41 0e655047 Andreas Färber
    OBJECT_CHECK(GrackleState, (obj), TYPE_GRACKLE_PCI_HOST_BRIDGE)
42 0e655047 Andreas Färber
43 426f17bb Blue Swirl
typedef struct GrackleState {
44 67c332fd Andreas Färber
    PCIHostState parent_obj;
45 0e655047 Andreas Färber
46 46f3069c Blue Swirl
    MemoryRegion pci_mmio;
47 46f3069c Blue Swirl
    MemoryRegion pci_hole;
48 426f17bb Blue Swirl
} GrackleState;
49 502a5395 pbrook
50 d2b59317 pbrook
/* Don't know if this matches real hardware, but it agrees with OHW.  */
51 d2b59317 pbrook
static int pci_grackle_map_irq(PCIDevice *pci_dev, int irq_num)
52 502a5395 pbrook
{
53 d2b59317 pbrook
    return (irq_num + (pci_dev->devfn >> 3)) & 3;
54 d2b59317 pbrook
}
55 d2b59317 pbrook
56 5d4e84c8 Juan Quintela
static void pci_grackle_set_irq(void *opaque, int irq_num, int level)
57 d2b59317 pbrook
{
58 5d4e84c8 Juan Quintela
    qemu_irq *pic = opaque;
59 5d4e84c8 Juan Quintela
60 ea026b2f blueswir1
    GRACKLE_DPRINTF("set_irq num %d level %d\n", irq_num, level);
61 3cbee15b j_mayer
    qemu_set_irq(pic[irq_num + 0x15], level);
62 502a5395 pbrook
}
63 502a5395 pbrook
64 1e39101c Avi Kivity
PCIBus *pci_grackle_init(uint32_t base, qemu_irq *pic,
65 aee97b84 Avi Kivity
                         MemoryRegion *address_space_mem,
66 aee97b84 Avi Kivity
                         MemoryRegion *address_space_io)
67 502a5395 pbrook
{
68 426f17bb Blue Swirl
    DeviceState *dev;
69 426f17bb Blue Swirl
    SysBusDevice *s;
70 0e655047 Andreas Färber
    PCIHostState *phb;
71 426f17bb Blue Swirl
    GrackleState *d;
72 426f17bb Blue Swirl
73 0e655047 Andreas Färber
    dev = qdev_create(NULL, TYPE_GRACKLE_PCI_HOST_BRIDGE);
74 e23a1b33 Markus Armbruster
    qdev_init_nofail(dev);
75 0e655047 Andreas Färber
    s = SYS_BUS_DEVICE(dev);
76 8558d942 Andreas Färber
    phb = PCI_HOST_BRIDGE(dev);
77 0e655047 Andreas Färber
    d = GRACKLE_PCI_HOST_BRIDGE(dev);
78 46f3069c Blue Swirl
79 46f3069c Blue Swirl
    memory_region_init(&d->pci_mmio, "pci-mmio", 0x100000000ULL);
80 46f3069c Blue Swirl
    memory_region_init_alias(&d->pci_hole, "pci-hole", &d->pci_mmio,
81 46f3069c Blue Swirl
                             0x80000000ULL, 0x7e000000ULL);
82 46f3069c Blue Swirl
    memory_region_add_subregion(address_space_mem, 0x80000000ULL,
83 46f3069c Blue Swirl
                                &d->pci_hole);
84 46f3069c Blue Swirl
85 0e655047 Andreas Färber
    phb->bus = pci_register_bus(dev, "pci",
86 0e655047 Andreas Färber
                                pci_grackle_set_irq,
87 0e655047 Andreas Färber
                                pci_grackle_map_irq,
88 0e655047 Andreas Färber
                                pic,
89 0e655047 Andreas Färber
                                &d->pci_mmio,
90 0e655047 Andreas Färber
                                address_space_io,
91 0e655047 Andreas Färber
                                0, 4);
92 426f17bb Blue Swirl
93 0e655047 Andreas Färber
    pci_create_simple(phb->bus, 0, "grackle");
94 426f17bb Blue Swirl
95 426f17bb Blue Swirl
    sysbus_mmio_map(s, 0, base);
96 426f17bb Blue Swirl
    sysbus_mmio_map(s, 1, base + 0x00200000);
97 426f17bb Blue Swirl
98 0e655047 Andreas Färber
    return phb->bus;
99 426f17bb Blue Swirl
}
100 426f17bb Blue Swirl
101 81a322d4 Gerd Hoffmann
static int pci_grackle_init_device(SysBusDevice *dev)
102 426f17bb Blue Swirl
{
103 0e655047 Andreas Färber
    PCIHostState *phb;
104 426f17bb Blue Swirl
105 8558d942 Andreas Färber
    phb = PCI_HOST_BRIDGE(dev);
106 426f17bb Blue Swirl
107 0e655047 Andreas Färber
    memory_region_init_io(&phb->conf_mem, &pci_host_conf_le_ops,
108 0e655047 Andreas Färber
                          dev, "pci-conf-idx", 0x1000);
109 0e655047 Andreas Färber
    memory_region_init_io(&phb->data_mem, &pci_host_data_le_ops,
110 0e655047 Andreas Färber
                          dev, "pci-data-idx", 0x1000);
111 0e655047 Andreas Färber
    sysbus_init_mmio(dev, &phb->conf_mem);
112 0e655047 Andreas Färber
    sysbus_init_mmio(dev, &phb->data_mem);
113 426f17bb Blue Swirl
114 81a322d4 Gerd Hoffmann
    return 0;
115 426f17bb Blue Swirl
}
116 426f17bb Blue Swirl
117 81a322d4 Gerd Hoffmann
static int grackle_pci_host_init(PCIDevice *d)
118 426f17bb Blue Swirl
{
119 502a5395 pbrook
    d->config[0x09] = 0x01;
120 81a322d4 Gerd Hoffmann
    return 0;
121 426f17bb Blue Swirl
}
122 502a5395 pbrook
123 40021f08 Anthony Liguori
static void grackle_pci_class_init(ObjectClass *klass, void *data)
124 40021f08 Anthony Liguori
{
125 40021f08 Anthony Liguori
    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
126 39bffca2 Anthony Liguori
    DeviceClass *dc = DEVICE_CLASS(klass);
127 40021f08 Anthony Liguori
128 40021f08 Anthony Liguori
    k->init      = grackle_pci_host_init;
129 40021f08 Anthony Liguori
    k->vendor_id = PCI_VENDOR_ID_MOTOROLA;
130 40021f08 Anthony Liguori
    k->device_id = PCI_DEVICE_ID_MOTOROLA_MPC106;
131 40021f08 Anthony Liguori
    k->revision  = 0x00;
132 40021f08 Anthony Liguori
    k->class_id  = PCI_CLASS_BRIDGE_HOST;
133 39bffca2 Anthony Liguori
    dc->no_user = 1;
134 40021f08 Anthony Liguori
}
135 40021f08 Anthony Liguori
136 4240abff Andreas Färber
static const TypeInfo grackle_pci_info = {
137 39bffca2 Anthony Liguori
    .name          = "grackle",
138 39bffca2 Anthony Liguori
    .parent        = TYPE_PCI_DEVICE,
139 39bffca2 Anthony Liguori
    .instance_size = sizeof(PCIDevice),
140 40021f08 Anthony Liguori
    .class_init = grackle_pci_class_init,
141 426f17bb Blue Swirl
};
142 6e6b7363 blueswir1
143 999e12bb Anthony Liguori
static void pci_grackle_class_init(ObjectClass *klass, void *data)
144 999e12bb Anthony Liguori
{
145 999e12bb Anthony Liguori
    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
146 39bffca2 Anthony Liguori
    DeviceClass *dc = DEVICE_CLASS(klass);
147 999e12bb Anthony Liguori
148 999e12bb Anthony Liguori
    k->init = pci_grackle_init_device;
149 39bffca2 Anthony Liguori
    dc->no_user = 1;
150 999e12bb Anthony Liguori
}
151 999e12bb Anthony Liguori
152 4240abff Andreas Färber
static const TypeInfo grackle_pci_host_info = {
153 0e655047 Andreas Färber
    .name          = TYPE_GRACKLE_PCI_HOST_BRIDGE,
154 8558d942 Andreas Färber
    .parent        = TYPE_PCI_HOST_BRIDGE,
155 39bffca2 Anthony Liguori
    .instance_size = sizeof(GrackleState),
156 39bffca2 Anthony Liguori
    .class_init    = pci_grackle_class_init,
157 0ae46996 Andreas Färber
};
158 0ae46996 Andreas Färber
159 83f7d43a Andreas Färber
static void grackle_register_types(void)
160 426f17bb Blue Swirl
{
161 39bffca2 Anthony Liguori
    type_register_static(&grackle_pci_info);
162 39bffca2 Anthony Liguori
    type_register_static(&grackle_pci_host_info);
163 502a5395 pbrook
}
164 426f17bb Blue Swirl
165 83f7d43a Andreas Färber
type_init(grackle_register_types)