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