]> git.proxmox.com Git - mirror_qemu.git/blame - hw/macio.c
mac_nvram: Mark as Big Endian
[mirror_qemu.git] / hw / macio.c
CommitLineData
3cbee15b
JM
1/*
2 * PowerMac MacIO device emulation
3 *
4 * Copyright (c) 2005-2007 Fabrice Bellard
5 * Copyright (c) 2007 Jocelyn Mayer
6 *
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 */
87ecb68b 25#include "hw.h"
baec1910 26#include "ppc/mac.h"
a2cb15b0 27#include "pci/pci.h"
7fa9ae1a 28#include "escc.h"
3cbee15b 29
fcf1bbab
AF
30#define TYPE_MACIO "macio"
31#define MACIO(obj) OBJECT_CHECK(MacIOState, (obj), TYPE_MACIO)
32
d8c51b05
AL
33typedef struct MacIOState
34{
fcf1bbab 35 /*< private >*/
d8c51b05 36 PCIDevice parent;
fcf1bbab
AF
37 /*< public >*/
38
23c5e4ca
AK
39 MemoryRegion bar;
40 MemoryRegion *pic_mem;
41 MemoryRegion *dbdma_mem;
42 MemoryRegion *cuda_mem;
43 MemoryRegion *escc_mem;
74e91155 44 void *nvram;
3cbee15b 45 int nb_ide;
23c5e4ca 46 MemoryRegion *ide_mem[4];
d8c51b05 47} MacIOState;
3cbee15b 48
d8c51b05 49static void macio_bar_setup(MacIOState *macio_state)
3cbee15b 50{
3cbee15b 51 int i;
23c5e4ca 52 MemoryRegion *bar = &macio_state->bar;
3cbee15b 53
23c5e4ca
AK
54 if (macio_state->dbdma_mem) {
55 memory_region_add_subregion(bar, 0x08000, macio_state->dbdma_mem);
3cbee15b 56 }
23c5e4ca
AK
57 if (macio_state->escc_mem) {
58 memory_region_add_subregion(bar, 0x13000, macio_state->escc_mem);
7fa9ae1a 59 }
23c5e4ca
AK
60 if (macio_state->cuda_mem) {
61 memory_region_add_subregion(bar, 0x16000, macio_state->cuda_mem);
3cbee15b
JM
62 }
63 for (i = 0; i < macio_state->nb_ide; i++) {
23c5e4ca
AK
64 if (macio_state->ide_mem[i]) {
65 memory_region_add_subregion(bar, 0x1f000 + (i * 0x1000),
66 macio_state->ide_mem[i]);
3cbee15b
JM
67 }
68 }
74e91155 69 if (macio_state->nvram != NULL)
23c5e4ca 70 macio_nvram_setup_bar(macio_state->nvram, bar, 0x60000);
3cbee15b
JM
71}
72
d037834a 73static int macio_common_initfn(PCIDevice *d)
d8c51b05 74{
7b925079
AF
75 MacIOState *s = MACIO(d);
76
d8c51b05 77 d->config[0x3d] = 0x01; // interrupt on pin 1
7b925079
AF
78
79 macio_bar_setup(s);
80 pci_register_bar(d, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->bar);
81
d8c51b05
AL
82 return 0;
83}
84
d037834a
AF
85static int macio_oldworld_initfn(PCIDevice *d)
86{
87 MacIOState *s = MACIO(d);
88 int ret = macio_common_initfn(d);
89 if (ret < 0) {
90 return ret;
91 }
92
93 if (s->pic_mem) {
94 /* Heathrow PIC */
95 memory_region_add_subregion(&s->bar, 0x00000, s->pic_mem);
96 }
97
98 return 0;
99}
100
101static int macio_newworld_initfn(PCIDevice *d)
102{
103 MacIOState *s = MACIO(d);
104 int ret = macio_common_initfn(d);
105 if (ret < 0) {
106 return ret;
107 }
108
109 if (s->pic_mem) {
110 /* OpenPIC */
111 memory_region_add_subregion(&s->bar, 0x40000, s->pic_mem);
112 }
113
114 return 0;
115}
116
fcf1bbab
AF
117static void macio_instance_init(Object *obj)
118{
119 MacIOState *s = MACIO(obj);
120
121 memory_region_init(&s->bar, "macio", 0x80000);
122}
123
d037834a
AF
124static void macio_oldworld_class_init(ObjectClass *oc, void *data)
125{
126 PCIDeviceClass *pdc = PCI_DEVICE_CLASS(oc);
127
128 pdc->init = macio_oldworld_initfn;
129 pdc->device_id = PCI_DEVICE_ID_APPLE_343S1201;
130}
131
132static void macio_newworld_class_init(ObjectClass *oc, void *data)
133{
134 PCIDeviceClass *pdc = PCI_DEVICE_CLASS(oc);
135
136 pdc->init = macio_newworld_initfn;
137 pdc->device_id = PCI_DEVICE_ID_APPLE_UNI_N_KEYL;
138}
139
40021f08
AL
140static void macio_class_init(ObjectClass *klass, void *data)
141{
142 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
143
40021f08
AL
144 k->vendor_id = PCI_VENDOR_ID_APPLE;
145 k->class_id = PCI_CLASS_OTHERS << 8;
146}
147
d037834a
AF
148static const TypeInfo macio_oldworld_type_info = {
149 .name = TYPE_OLDWORLD_MACIO,
150 .parent = TYPE_MACIO,
151 .class_init = macio_oldworld_class_init,
152};
153
154static const TypeInfo macio_newworld_type_info = {
155 .name = TYPE_NEWWORLD_MACIO,
156 .parent = TYPE_MACIO,
157 .class_init = macio_newworld_class_init,
158};
159
fcf1bbab
AF
160static const TypeInfo macio_type_info = {
161 .name = TYPE_MACIO,
39bffca2
AL
162 .parent = TYPE_PCI_DEVICE,
163 .instance_size = sizeof(MacIOState),
fcf1bbab 164 .instance_init = macio_instance_init,
d037834a 165 .abstract = true,
39bffca2 166 .class_init = macio_class_init,
d8c51b05
AL
167};
168
83f7d43a 169static void macio_register_types(void)
d8c51b05 170{
fcf1bbab 171 type_register_static(&macio_type_info);
d037834a
AF
172 type_register_static(&macio_oldworld_type_info);
173 type_register_static(&macio_newworld_type_info);
d8c51b05
AL
174}
175
83f7d43a 176type_init(macio_register_types)
d8c51b05 177
d037834a
AF
178void macio_init(PCIDevice *d,
179 MemoryRegion *pic_mem, MemoryRegion *dbdma_mem,
180 MemoryRegion *cuda_mem, void *nvram,
181 int nb_ide, MemoryRegion **ide_mem,
182 MemoryRegion *escc_mem)
3cbee15b 183{
d037834a 184 MacIOState *macio_state = MACIO(d);
3cbee15b
JM
185 int i;
186
23c5e4ca
AK
187 macio_state->pic_mem = pic_mem;
188 macio_state->dbdma_mem = dbdma_mem;
189 macio_state->cuda_mem = cuda_mem;
190 macio_state->escc_mem = escc_mem;
74e91155 191 macio_state->nvram = nvram;
3cbee15b
JM
192 if (nb_ide > 4)
193 nb_ide = 4;
194 macio_state->nb_ide = nb_ide;
195 for (i = 0; i < nb_ide; i++)
23c5e4ca 196 macio_state->ide_mem[i] = ide_mem[i];
3cbee15b
JM
197 /* Note: this code is strongly inspirated from the corresponding code
198 in PearPC */
deb54399 199
7b925079 200 qdev_init_nofail(DEVICE(d));
3cbee15b 201}