Statistics
| Branch: | Revision:

root / hw / grackle_pci.c @ 098d314a

History | View | Annotate | Download (4.2 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 6e6b7363 blueswir1
static void pci_grackle_reset(void *opaque)
61 6e6b7363 blueswir1
{
62 6e6b7363 blueswir1
}
63 6e6b7363 blueswir1
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 426f17bb Blue Swirl
    GrackleState *d;
71 426f17bb Blue Swirl
72 426f17bb Blue Swirl
    dev = qdev_create(NULL, "grackle");
73 e23a1b33 Markus Armbruster
    qdev_init_nofail(dev);
74 426f17bb Blue Swirl
    s = sysbus_from_qdev(dev);
75 426f17bb Blue Swirl
    d = FROM_SYSBUS(GrackleState, s);
76 cdd0935c Blue Swirl
    d->host_state.bus = pci_register_bus(&d->busdev.qdev, "pci",
77 426f17bb Blue Swirl
                                         pci_grackle_set_irq,
78 426f17bb Blue Swirl
                                         pci_grackle_map_irq,
79 aee97b84 Avi Kivity
                                         pic,
80 aee97b84 Avi Kivity
                                         address_space_mem,
81 aee97b84 Avi Kivity
                                         address_space_io,
82 aee97b84 Avi Kivity
                                         0, 4);
83 426f17bb Blue Swirl
84 426f17bb Blue Swirl
    pci_create_simple(d->host_state.bus, 0, "grackle");
85 426f17bb Blue Swirl
86 426f17bb Blue Swirl
    sysbus_mmio_map(s, 0, base);
87 426f17bb Blue Swirl
    sysbus_mmio_map(s, 1, base + 0x00200000);
88 426f17bb Blue Swirl
89 426f17bb Blue Swirl
    return d->host_state.bus;
90 426f17bb Blue Swirl
}
91 426f17bb Blue Swirl
92 81a322d4 Gerd Hoffmann
static int pci_grackle_init_device(SysBusDevice *dev)
93 426f17bb Blue Swirl
{
94 426f17bb Blue Swirl
    GrackleState *s;
95 426f17bb Blue Swirl
96 426f17bb Blue Swirl
    s = FROM_SYSBUS(GrackleState, dev);
97 426f17bb Blue Swirl
98 d0ed8076 Avi Kivity
    memory_region_init_io(&s->host_state.conf_mem, &pci_host_conf_le_ops,
99 d0ed8076 Avi Kivity
                          &s->host_state, "pci-conf-idx", 0x1000);
100 d0ed8076 Avi Kivity
    memory_region_init_io(&s->host_state.data_mem, &pci_host_data_le_ops,
101 d0ed8076 Avi Kivity
                          &s->host_state, "pci-data-idx", 0x1000);
102 d0ed8076 Avi Kivity
    sysbus_init_mmio_region(dev, &s->host_state.conf_mem);
103 d0ed8076 Avi Kivity
    sysbus_init_mmio_region(dev, &s->host_state.data_mem);
104 426f17bb Blue Swirl
105 426f17bb Blue Swirl
    qemu_register_reset(pci_grackle_reset, &s->host_state);
106 81a322d4 Gerd Hoffmann
    return 0;
107 426f17bb Blue Swirl
}
108 426f17bb Blue Swirl
109 81a322d4 Gerd Hoffmann
static int grackle_pci_host_init(PCIDevice *d)
110 426f17bb Blue Swirl
{
111 502a5395 pbrook
    d->config[0x09] = 0x01;
112 81a322d4 Gerd Hoffmann
    return 0;
113 426f17bb Blue Swirl
}
114 502a5395 pbrook
115 426f17bb Blue Swirl
static PCIDeviceInfo grackle_pci_host_info = {
116 426f17bb Blue Swirl
    .qdev.name = "grackle",
117 426f17bb Blue Swirl
    .qdev.size = sizeof(PCIDevice),
118 426f17bb Blue Swirl
    .init      = grackle_pci_host_init,
119 a614f52d Isaku Yamahata
    .vendor_id = PCI_VENDOR_ID_MOTOROLA,
120 a614f52d Isaku Yamahata
    .device_id = PCI_DEVICE_ID_MOTOROLA_MPC106,
121 a614f52d Isaku Yamahata
    .revision  = 0x00,
122 a614f52d Isaku Yamahata
    .class_id  = PCI_CLASS_BRIDGE_HOST,
123 426f17bb Blue Swirl
};
124 6e6b7363 blueswir1
125 426f17bb Blue Swirl
static void grackle_register_devices(void)
126 426f17bb Blue Swirl
{
127 426f17bb Blue Swirl
    sysbus_register_dev("grackle", sizeof(GrackleState),
128 426f17bb Blue Swirl
                        pci_grackle_init_device);
129 426f17bb Blue Swirl
    pci_qdev_register(&grackle_pci_host_info);
130 502a5395 pbrook
}
131 426f17bb Blue Swirl
132 426f17bb Blue Swirl
device_init(grackle_register_devices)