root / hw / macio.c @ 0dad6c35
History | View | Annotate | Download (4.4 kB)
1 | 3cbee15b | j_mayer | /*
|
---|---|---|---|
2 | 3cbee15b | j_mayer | * PowerMac MacIO device emulation
|
3 | 3cbee15b | j_mayer | *
|
4 | 3cbee15b | j_mayer | * Copyright (c) 2005-2007 Fabrice Bellard
|
5 | 3cbee15b | j_mayer | * Copyright (c) 2007 Jocelyn Mayer
|
6 | 3cbee15b | j_mayer | *
|
7 | 3cbee15b | j_mayer | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
8 | 3cbee15b | j_mayer | * of this software and associated documentation files (the "Software"), to deal
|
9 | 3cbee15b | j_mayer | * in the Software without restriction, including without limitation the rights
|
10 | 3cbee15b | j_mayer | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 | 3cbee15b | j_mayer | * copies of the Software, and to permit persons to whom the Software is
|
12 | 3cbee15b | j_mayer | * furnished to do so, subject to the following conditions:
|
13 | 3cbee15b | j_mayer | *
|
14 | 3cbee15b | j_mayer | * The above copyright notice and this permission notice shall be included in
|
15 | 3cbee15b | j_mayer | * all copies or substantial portions of the Software.
|
16 | 3cbee15b | j_mayer | *
|
17 | 3cbee15b | j_mayer | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18 | 3cbee15b | j_mayer | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19 | 3cbee15b | j_mayer | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
20 | 3cbee15b | j_mayer | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21 | 3cbee15b | j_mayer | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22 | 3cbee15b | j_mayer | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
23 | 3cbee15b | j_mayer | * THE SOFTWARE.
|
24 | 3cbee15b | j_mayer | */
|
25 | 87ecb68b | pbrook | #include "hw.h" |
26 | 3cbee15b | j_mayer | #include "ppc_mac.h" |
27 | 87ecb68b | pbrook | #include "pci.h" |
28 | 7fa9ae1a | blueswir1 | #include "escc.h" |
29 | 3cbee15b | j_mayer | |
30 | d8c51b05 | Anthony Liguori | typedef struct MacIOState |
31 | d8c51b05 | Anthony Liguori | { |
32 | d8c51b05 | Anthony Liguori | PCIDevice parent; |
33 | 3cbee15b | j_mayer | int is_oldworld;
|
34 | 23c5e4ca | Avi Kivity | MemoryRegion bar; |
35 | 23c5e4ca | Avi Kivity | MemoryRegion *pic_mem; |
36 | 23c5e4ca | Avi Kivity | MemoryRegion *dbdma_mem; |
37 | 23c5e4ca | Avi Kivity | MemoryRegion *cuda_mem; |
38 | 23c5e4ca | Avi Kivity | MemoryRegion *escc_mem; |
39 | 74e91155 | j_mayer | void *nvram;
|
40 | 3cbee15b | j_mayer | int nb_ide;
|
41 | 23c5e4ca | Avi Kivity | MemoryRegion *ide_mem[4];
|
42 | d8c51b05 | Anthony Liguori | } MacIOState; |
43 | 3cbee15b | j_mayer | |
44 | d8c51b05 | Anthony Liguori | static void macio_bar_setup(MacIOState *macio_state) |
45 | 3cbee15b | j_mayer | { |
46 | 3cbee15b | j_mayer | int i;
|
47 | 23c5e4ca | Avi Kivity | MemoryRegion *bar = &macio_state->bar; |
48 | 3cbee15b | j_mayer | |
49 | 23c5e4ca | Avi Kivity | memory_region_init(bar, "macio", 0x80000); |
50 | 23c5e4ca | Avi Kivity | if (macio_state->pic_mem) {
|
51 | 3cbee15b | j_mayer | if (macio_state->is_oldworld) {
|
52 | 3cbee15b | j_mayer | /* Heathrow PIC */
|
53 | 23c5e4ca | Avi Kivity | memory_region_add_subregion(bar, 0x00000, macio_state->pic_mem);
|
54 | 3cbee15b | j_mayer | } else {
|
55 | 3cbee15b | j_mayer | /* OpenPIC */
|
56 | 23c5e4ca | Avi Kivity | memory_region_add_subregion(bar, 0x40000, macio_state->pic_mem);
|
57 | 3cbee15b | j_mayer | } |
58 | 3cbee15b | j_mayer | } |
59 | 23c5e4ca | Avi Kivity | if (macio_state->dbdma_mem) {
|
60 | 23c5e4ca | Avi Kivity | memory_region_add_subregion(bar, 0x08000, macio_state->dbdma_mem);
|
61 | 3cbee15b | j_mayer | } |
62 | 23c5e4ca | Avi Kivity | if (macio_state->escc_mem) {
|
63 | 23c5e4ca | Avi Kivity | memory_region_add_subregion(bar, 0x13000, macio_state->escc_mem);
|
64 | 7fa9ae1a | blueswir1 | } |
65 | 23c5e4ca | Avi Kivity | if (macio_state->cuda_mem) {
|
66 | 23c5e4ca | Avi Kivity | memory_region_add_subregion(bar, 0x16000, macio_state->cuda_mem);
|
67 | 3cbee15b | j_mayer | } |
68 | 3cbee15b | j_mayer | for (i = 0; i < macio_state->nb_ide; i++) { |
69 | 23c5e4ca | Avi Kivity | if (macio_state->ide_mem[i]) {
|
70 | 23c5e4ca | Avi Kivity | memory_region_add_subregion(bar, 0x1f000 + (i * 0x1000), |
71 | 23c5e4ca | Avi Kivity | macio_state->ide_mem[i]); |
72 | 3cbee15b | j_mayer | } |
73 | 3cbee15b | j_mayer | } |
74 | 74e91155 | j_mayer | if (macio_state->nvram != NULL) |
75 | 23c5e4ca | Avi Kivity | macio_nvram_setup_bar(macio_state->nvram, bar, 0x60000);
|
76 | 3cbee15b | j_mayer | } |
77 | 3cbee15b | j_mayer | |
78 | d8c51b05 | Anthony Liguori | static int macio_initfn(PCIDevice *d) |
79 | d8c51b05 | Anthony Liguori | { |
80 | d8c51b05 | Anthony Liguori | d->config[0x3d] = 0x01; // interrupt on pin 1 |
81 | d8c51b05 | Anthony Liguori | return 0; |
82 | d8c51b05 | Anthony Liguori | } |
83 | d8c51b05 | Anthony Liguori | |
84 | 40021f08 | Anthony Liguori | static void macio_class_init(ObjectClass *klass, void *data) |
85 | 40021f08 | Anthony Liguori | { |
86 | 40021f08 | Anthony Liguori | PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); |
87 | 40021f08 | Anthony Liguori | |
88 | 40021f08 | Anthony Liguori | k->init = macio_initfn; |
89 | 40021f08 | Anthony Liguori | k->vendor_id = PCI_VENDOR_ID_APPLE; |
90 | 40021f08 | Anthony Liguori | k->class_id = PCI_CLASS_OTHERS << 8;
|
91 | 40021f08 | Anthony Liguori | } |
92 | 40021f08 | Anthony Liguori | |
93 | 39bffca2 | Anthony Liguori | static TypeInfo macio_info = {
|
94 | 39bffca2 | Anthony Liguori | .name = "macio",
|
95 | 39bffca2 | Anthony Liguori | .parent = TYPE_PCI_DEVICE, |
96 | 39bffca2 | Anthony Liguori | .instance_size = sizeof(MacIOState),
|
97 | 39bffca2 | Anthony Liguori | .class_init = macio_class_init, |
98 | d8c51b05 | Anthony Liguori | }; |
99 | d8c51b05 | Anthony Liguori | |
100 | d8c51b05 | Anthony Liguori | static void macio_register(void) |
101 | d8c51b05 | Anthony Liguori | { |
102 | 39bffca2 | Anthony Liguori | type_register_static(&macio_info); |
103 | d8c51b05 | Anthony Liguori | } |
104 | d8c51b05 | Anthony Liguori | |
105 | d8c51b05 | Anthony Liguori | device_init(macio_register); |
106 | d8c51b05 | Anthony Liguori | |
107 | 23c5e4ca | Avi Kivity | void macio_init (PCIBus *bus, int device_id, int is_oldworld, |
108 | 23c5e4ca | Avi Kivity | MemoryRegion *pic_mem, MemoryRegion *dbdma_mem, |
109 | 23c5e4ca | Avi Kivity | MemoryRegion *cuda_mem, void *nvram,
|
110 | 23c5e4ca | Avi Kivity | int nb_ide, MemoryRegion **ide_mem,
|
111 | 23c5e4ca | Avi Kivity | MemoryRegion *escc_mem) |
112 | 3cbee15b | j_mayer | { |
113 | 3cbee15b | j_mayer | PCIDevice *d; |
114 | d8c51b05 | Anthony Liguori | MacIOState *macio_state; |
115 | 3cbee15b | j_mayer | int i;
|
116 | 3cbee15b | j_mayer | |
117 | d8c51b05 | Anthony Liguori | d = pci_create_simple(bus, -1, "macio"); |
118 | d8c51b05 | Anthony Liguori | |
119 | d8c51b05 | Anthony Liguori | macio_state = DO_UPCAST(MacIOState, parent, d); |
120 | 3cbee15b | j_mayer | macio_state->is_oldworld = is_oldworld; |
121 | 23c5e4ca | Avi Kivity | macio_state->pic_mem = pic_mem; |
122 | 23c5e4ca | Avi Kivity | macio_state->dbdma_mem = dbdma_mem; |
123 | 23c5e4ca | Avi Kivity | macio_state->cuda_mem = cuda_mem; |
124 | 23c5e4ca | Avi Kivity | macio_state->escc_mem = escc_mem; |
125 | 74e91155 | j_mayer | macio_state->nvram = nvram; |
126 | 3cbee15b | j_mayer | if (nb_ide > 4) |
127 | 3cbee15b | j_mayer | nb_ide = 4;
|
128 | 3cbee15b | j_mayer | macio_state->nb_ide = nb_ide; |
129 | 3cbee15b | j_mayer | for (i = 0; i < nb_ide; i++) |
130 | 23c5e4ca | Avi Kivity | macio_state->ide_mem[i] = ide_mem[i]; |
131 | 3cbee15b | j_mayer | for (; i < 4; i++) |
132 | 23c5e4ca | Avi Kivity | macio_state->ide_mem[i] = NULL;
|
133 | 3cbee15b | j_mayer | /* Note: this code is strongly inspirated from the corresponding code
|
134 | 3cbee15b | j_mayer | in PearPC */
|
135 | deb54399 | aliguori | |
136 | deb54399 | aliguori | pci_config_set_device_id(d->config, device_id); |
137 | 3cbee15b | j_mayer | |
138 | 23c5e4ca | Avi Kivity | macio_bar_setup(macio_state); |
139 | e824b2cc | Avi Kivity | pci_register_bar(d, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &macio_state->bar);
|
140 | 3cbee15b | j_mayer | } |