2 * PowerMac MacIO device emulation
4 * Copyright (c) 2005-2007 Fabrice Bellard
5 * Copyright (c) 2007 Jocelyn Mayer
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:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
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
30 #define TYPE_MACIO "macio"
31 #define MACIO(obj) OBJECT_CHECK(MacIOState, (obj), TYPE_MACIO)
33 typedef struct MacIOState
41 MemoryRegion
*pic_mem
;
42 MemoryRegion
*dbdma_mem
;
43 MemoryRegion
*cuda_mem
;
44 MemoryRegion
*escc_mem
;
47 MemoryRegion
*ide_mem
[4];
50 static void macio_bar_setup(MacIOState
*macio_state
)
53 MemoryRegion
*bar
= &macio_state
->bar
;
55 if (macio_state
->pic_mem
) {
56 if (macio_state
->is_oldworld
) {
58 memory_region_add_subregion(bar
, 0x00000, macio_state
->pic_mem
);
61 memory_region_add_subregion(bar
, 0x40000, macio_state
->pic_mem
);
64 if (macio_state
->dbdma_mem
) {
65 memory_region_add_subregion(bar
, 0x08000, macio_state
->dbdma_mem
);
67 if (macio_state
->escc_mem
) {
68 memory_region_add_subregion(bar
, 0x13000, macio_state
->escc_mem
);
70 if (macio_state
->cuda_mem
) {
71 memory_region_add_subregion(bar
, 0x16000, macio_state
->cuda_mem
);
73 for (i
= 0; i
< macio_state
->nb_ide
; i
++) {
74 if (macio_state
->ide_mem
[i
]) {
75 memory_region_add_subregion(bar
, 0x1f000 + (i
* 0x1000),
76 macio_state
->ide_mem
[i
]);
79 if (macio_state
->nvram
!= NULL
)
80 macio_nvram_setup_bar(macio_state
->nvram
, bar
, 0x60000);
83 static int macio_initfn(PCIDevice
*d
)
85 d
->config
[0x3d] = 0x01; // interrupt on pin 1
89 static void macio_instance_init(Object
*obj
)
91 MacIOState
*s
= MACIO(obj
);
93 memory_region_init(&s
->bar
, "macio", 0x80000);
96 static void macio_class_init(ObjectClass
*klass
, void *data
)
98 PCIDeviceClass
*k
= PCI_DEVICE_CLASS(klass
);
100 k
->init
= macio_initfn
;
101 k
->vendor_id
= PCI_VENDOR_ID_APPLE
;
102 k
->class_id
= PCI_CLASS_OTHERS
<< 8;
105 static const TypeInfo macio_type_info
= {
107 .parent
= TYPE_PCI_DEVICE
,
108 .instance_size
= sizeof(MacIOState
),
109 .instance_init
= macio_instance_init
,
110 .class_init
= macio_class_init
,
113 static void macio_register_types(void)
115 type_register_static(&macio_type_info
);
118 type_init(macio_register_types
)
120 void macio_init (PCIBus
*bus
, int device_id
, int is_oldworld
,
121 MemoryRegion
*pic_mem
, MemoryRegion
*dbdma_mem
,
122 MemoryRegion
*cuda_mem
, void *nvram
,
123 int nb_ide
, MemoryRegion
**ide_mem
,
124 MemoryRegion
*escc_mem
)
127 MacIOState
*macio_state
;
130 d
= pci_create_simple(bus
, -1, TYPE_MACIO
);
132 macio_state
= MACIO(d
);
133 macio_state
->is_oldworld
= is_oldworld
;
134 macio_state
->pic_mem
= pic_mem
;
135 macio_state
->dbdma_mem
= dbdma_mem
;
136 macio_state
->cuda_mem
= cuda_mem
;
137 macio_state
->escc_mem
= escc_mem
;
138 macio_state
->nvram
= nvram
;
141 macio_state
->nb_ide
= nb_ide
;
142 for (i
= 0; i
< nb_ide
; i
++)
143 macio_state
->ide_mem
[i
] = ide_mem
[i
];
145 macio_state
->ide_mem
[i
] = NULL
;
146 /* Note: this code is strongly inspirated from the corresponding code
149 pci_config_set_device_id(d
->config
, device_id
);
151 macio_bar_setup(macio_state
);
152 pci_register_bar(d
, 0, PCI_BASE_ADDRESS_SPACE_MEMORY
, &macio_state
->bar
);