root / hw / grackle_pci.c @ 8a637d44
History | View | Annotate | Download (5.7 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 | 87ecb68b | pbrook | #include "hw.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 | 502a5395 | pbrook | typedef target_phys_addr_t pci_addr_t;
|
41 | 502a5395 | pbrook | #include "pci_host.h" |
42 | 502a5395 | pbrook | |
43 | 502a5395 | pbrook | typedef PCIHostState GrackleState;
|
44 | 502a5395 | pbrook | |
45 | 502a5395 | pbrook | static void pci_grackle_config_writel (void *opaque, target_phys_addr_t addr, |
46 | 502a5395 | pbrook | uint32_t val) |
47 | 502a5395 | pbrook | { |
48 | 502a5395 | pbrook | GrackleState *s = opaque; |
49 | ea026b2f | blueswir1 | |
50 | ea026b2f | blueswir1 | GRACKLE_DPRINTF("config_writel addr " TARGET_FMT_plx " val %x\n", addr, |
51 | ea026b2f | blueswir1 | val); |
52 | 502a5395 | pbrook | #ifdef TARGET_WORDS_BIGENDIAN
|
53 | 502a5395 | pbrook | val = bswap32(val); |
54 | 502a5395 | pbrook | #endif
|
55 | 502a5395 | pbrook | s->config_reg = val; |
56 | 502a5395 | pbrook | } |
57 | 502a5395 | pbrook | |
58 | 502a5395 | pbrook | static uint32_t pci_grackle_config_readl (void *opaque, target_phys_addr_t addr) |
59 | 502a5395 | pbrook | { |
60 | 502a5395 | pbrook | GrackleState *s = opaque; |
61 | 502a5395 | pbrook | uint32_t val; |
62 | 502a5395 | pbrook | |
63 | 502a5395 | pbrook | val = s->config_reg; |
64 | 502a5395 | pbrook | #ifdef TARGET_WORDS_BIGENDIAN
|
65 | 502a5395 | pbrook | val = bswap32(val); |
66 | 502a5395 | pbrook | #endif
|
67 | ea026b2f | blueswir1 | GRACKLE_DPRINTF("config_readl addr " TARGET_FMT_plx " val %x\n", addr, |
68 | ea026b2f | blueswir1 | val); |
69 | 502a5395 | pbrook | return val;
|
70 | 502a5395 | pbrook | } |
71 | 502a5395 | pbrook | |
72 | 502a5395 | pbrook | static CPUWriteMemoryFunc *pci_grackle_config_write[] = {
|
73 | 502a5395 | pbrook | &pci_grackle_config_writel, |
74 | 502a5395 | pbrook | &pci_grackle_config_writel, |
75 | 502a5395 | pbrook | &pci_grackle_config_writel, |
76 | 502a5395 | pbrook | }; |
77 | 502a5395 | pbrook | |
78 | 502a5395 | pbrook | static CPUReadMemoryFunc *pci_grackle_config_read[] = {
|
79 | 502a5395 | pbrook | &pci_grackle_config_readl, |
80 | 502a5395 | pbrook | &pci_grackle_config_readl, |
81 | 502a5395 | pbrook | &pci_grackle_config_readl, |
82 | 502a5395 | pbrook | }; |
83 | 502a5395 | pbrook | |
84 | 502a5395 | pbrook | static CPUWriteMemoryFunc *pci_grackle_write[] = {
|
85 | 502a5395 | pbrook | &pci_host_data_writeb, |
86 | 502a5395 | pbrook | &pci_host_data_writew, |
87 | 502a5395 | pbrook | &pci_host_data_writel, |
88 | 502a5395 | pbrook | }; |
89 | 502a5395 | pbrook | |
90 | 502a5395 | pbrook | static CPUReadMemoryFunc *pci_grackle_read[] = {
|
91 | 502a5395 | pbrook | &pci_host_data_readb, |
92 | 502a5395 | pbrook | &pci_host_data_readw, |
93 | 502a5395 | pbrook | &pci_host_data_readl, |
94 | 502a5395 | pbrook | }; |
95 | 502a5395 | pbrook | |
96 | d2b59317 | pbrook | /* Don't know if this matches real hardware, but it agrees with OHW. */
|
97 | d2b59317 | pbrook | static int pci_grackle_map_irq(PCIDevice *pci_dev, int irq_num) |
98 | 502a5395 | pbrook | { |
99 | d2b59317 | pbrook | return (irq_num + (pci_dev->devfn >> 3)) & 3; |
100 | d2b59317 | pbrook | } |
101 | d2b59317 | pbrook | |
102 | d537cf6c | pbrook | static void pci_grackle_set_irq(qemu_irq *pic, int irq_num, int level) |
103 | d2b59317 | pbrook | { |
104 | ea026b2f | blueswir1 | GRACKLE_DPRINTF("set_irq num %d level %d\n", irq_num, level);
|
105 | 3cbee15b | j_mayer | qemu_set_irq(pic[irq_num + 0x15], level);
|
106 | 502a5395 | pbrook | } |
107 | 502a5395 | pbrook | |
108 | 9b64997f | blueswir1 | static void pci_grackle_save(QEMUFile* f, void *opaque) |
109 | 9b64997f | blueswir1 | { |
110 | 9b64997f | blueswir1 | PCIDevice *d = opaque; |
111 | 9b64997f | blueswir1 | |
112 | 9b64997f | blueswir1 | pci_device_save(d, f); |
113 | 9b64997f | blueswir1 | } |
114 | 9b64997f | blueswir1 | |
115 | 9b64997f | blueswir1 | static int pci_grackle_load(QEMUFile* f, void *opaque, int version_id) |
116 | 9b64997f | blueswir1 | { |
117 | 9b64997f | blueswir1 | PCIDevice *d = opaque; |
118 | 9b64997f | blueswir1 | |
119 | 9b64997f | blueswir1 | if (version_id != 1) |
120 | 9b64997f | blueswir1 | return -EINVAL;
|
121 | 9b64997f | blueswir1 | |
122 | 9b64997f | blueswir1 | return pci_device_load(d, f);
|
123 | 9b64997f | blueswir1 | } |
124 | 9b64997f | blueswir1 | |
125 | 6e6b7363 | blueswir1 | static void pci_grackle_reset(void *opaque) |
126 | 6e6b7363 | blueswir1 | { |
127 | 6e6b7363 | blueswir1 | } |
128 | 6e6b7363 | blueswir1 | |
129 | d537cf6c | pbrook | PCIBus *pci_grackle_init(uint32_t base, qemu_irq *pic) |
130 | 502a5395 | pbrook | { |
131 | 502a5395 | pbrook | GrackleState *s; |
132 | 502a5395 | pbrook | PCIDevice *d; |
133 | 502a5395 | pbrook | int pci_mem_config, pci_mem_data;
|
134 | 502a5395 | pbrook | |
135 | 502a5395 | pbrook | s = qemu_mallocz(sizeof(GrackleState));
|
136 | 80b3ada7 | pbrook | s->bus = pci_register_bus(pci_grackle_set_irq, pci_grackle_map_irq, |
137 | 3cbee15b | j_mayer | pic, 0, 4); |
138 | 502a5395 | pbrook | |
139 | 5fafdf24 | ths | pci_mem_config = cpu_register_io_memory(0, pci_grackle_config_read,
|
140 | 502a5395 | pbrook | pci_grackle_config_write, s); |
141 | 502a5395 | pbrook | pci_mem_data = cpu_register_io_memory(0, pci_grackle_read,
|
142 | 502a5395 | pbrook | pci_grackle_write, s); |
143 | 502a5395 | pbrook | cpu_register_physical_memory(base, 0x1000, pci_mem_config);
|
144 | 502a5395 | pbrook | cpu_register_physical_memory(base + 0x00200000, 0x1000, pci_mem_data); |
145 | 5fafdf24 | ths | d = pci_register_device(s->bus, "Grackle host bridge", sizeof(PCIDevice), |
146 | 502a5395 | pbrook | 0, NULL, NULL); |
147 | deb54399 | aliguori | pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_MOTOROLA); |
148 | deb54399 | aliguori | pci_config_set_device_id(d->config, PCI_DEVICE_ID_MOTOROLA_MPC106); |
149 | 502a5395 | pbrook | d->config[0x08] = 0x00; // revision |
150 | 502a5395 | pbrook | d->config[0x09] = 0x01; |
151 | 173a543b | blueswir1 | pci_config_set_class(d->config, PCI_CLASS_BRIDGE_HOST); |
152 | 6407f373 | Isaku Yamahata | d->config[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL; // header_type
|
153 | 502a5395 | pbrook | |
154 | 502a5395 | pbrook | #if 0
|
155 | 502a5395 | pbrook | /* PCI2PCI bridge same values as PearPC - check this */
|
156 | 4ebcf884 | blueswir1 | pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_DEC);
|
157 | 4ebcf884 | blueswir1 | pci_config_set_device_id(d->config, PCI_DEVICE_ID_DEC_21154);
|
158 | 502a5395 | pbrook | d->config[0x08] = 0x02; // revision
|
159 | 173a543b | blueswir1 | pci_config_set_class(d->config, PCI_CLASS_BRIDGE_PCI);
|
160 | 6407f373 | Isaku Yamahata | d->config[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_BRIDGE; // header_type
|
161 | 502a5395 | pbrook | |
162 | 502a5395 | pbrook | d->config[0x18] = 0x0; // primary_bus
|
163 | 502a5395 | pbrook | d->config[0x19] = 0x1; // secondary_bus
|
164 | 502a5395 | pbrook | d->config[0x1a] = 0x1; // subordinate_bus
|
165 | 502a5395 | pbrook | d->config[0x1c] = 0x10; // io_base
|
166 | 502a5395 | pbrook | d->config[0x1d] = 0x20; // io_limit
|
167 | 3b46e624 | ths | |
168 | 502a5395 | pbrook | d->config[0x20] = 0x80; // memory_base
|
169 | 502a5395 | pbrook | d->config[0x21] = 0x80;
|
170 | 502a5395 | pbrook | d->config[0x22] = 0x90; // memory_limit
|
171 | 502a5395 | pbrook | d->config[0x23] = 0x80;
|
172 | 3b46e624 | ths | |
173 | 502a5395 | pbrook | d->config[0x24] = 0x00; // prefetchable_memory_base
|
174 | 502a5395 | pbrook | d->config[0x25] = 0x84;
|
175 | 502a5395 | pbrook | d->config[0x26] = 0x00; // prefetchable_memory_limit
|
176 | 502a5395 | pbrook | d->config[0x27] = 0x85;
|
177 | 502a5395 | pbrook | #endif
|
178 | 9b64997f | blueswir1 | register_savevm("grackle", 0, 1, pci_grackle_save, pci_grackle_load, d); |
179 | 6e6b7363 | blueswir1 | qemu_register_reset(pci_grackle_reset, d); |
180 | 6e6b7363 | blueswir1 | pci_grackle_reset(d); |
181 | 6e6b7363 | blueswir1 | |
182 | 502a5395 | pbrook | return s->bus;
|
183 | 502a5395 | pbrook | } |