root / hw / macio.c @ 43b26fc8
History | View | Annotate | Download (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 | c227f099 | Anthony Liguori | typedef struct macio_state_t macio_state_t; |
31 | c227f099 | Anthony Liguori | struct macio_state_t {
|
32 | 3cbee15b | j_mayer | int is_oldworld;
|
33 | 23c5e4ca | Avi Kivity | MemoryRegion bar; |
34 | 23c5e4ca | Avi Kivity | MemoryRegion *pic_mem; |
35 | 23c5e4ca | Avi Kivity | MemoryRegion *dbdma_mem; |
36 | 23c5e4ca | Avi Kivity | MemoryRegion *cuda_mem; |
37 | 23c5e4ca | Avi Kivity | MemoryRegion *escc_mem; |
38 | 74e91155 | j_mayer | void *nvram;
|
39 | 3cbee15b | j_mayer | int nb_ide;
|
40 | 23c5e4ca | Avi Kivity | MemoryRegion *ide_mem[4];
|
41 | 3cbee15b | j_mayer | }; |
42 | 3cbee15b | j_mayer | |
43 | 23c5e4ca | Avi Kivity | static void macio_bar_setup(macio_state_t *macio_state) |
44 | 3cbee15b | j_mayer | { |
45 | 3cbee15b | j_mayer | int i;
|
46 | 23c5e4ca | Avi Kivity | MemoryRegion *bar = &macio_state->bar; |
47 | 3cbee15b | j_mayer | |
48 | 23c5e4ca | Avi Kivity | memory_region_init(bar, "macio", 0x80000); |
49 | 23c5e4ca | Avi Kivity | if (macio_state->pic_mem) {
|
50 | 3cbee15b | j_mayer | if (macio_state->is_oldworld) {
|
51 | 3cbee15b | j_mayer | /* Heathrow PIC */
|
52 | 23c5e4ca | Avi Kivity | memory_region_add_subregion(bar, 0x00000, macio_state->pic_mem);
|
53 | 3cbee15b | j_mayer | } else {
|
54 | 3cbee15b | j_mayer | /* OpenPIC */
|
55 | 23c5e4ca | Avi Kivity | memory_region_add_subregion(bar, 0x40000, macio_state->pic_mem);
|
56 | 3cbee15b | j_mayer | } |
57 | 3cbee15b | j_mayer | } |
58 | 23c5e4ca | Avi Kivity | if (macio_state->dbdma_mem) {
|
59 | 23c5e4ca | Avi Kivity | memory_region_add_subregion(bar, 0x08000, macio_state->dbdma_mem);
|
60 | 3cbee15b | j_mayer | } |
61 | 23c5e4ca | Avi Kivity | if (macio_state->escc_mem) {
|
62 | 23c5e4ca | Avi Kivity | memory_region_add_subregion(bar, 0x13000, macio_state->escc_mem);
|
63 | 7fa9ae1a | blueswir1 | } |
64 | 23c5e4ca | Avi Kivity | if (macio_state->cuda_mem) {
|
65 | 23c5e4ca | Avi Kivity | memory_region_add_subregion(bar, 0x16000, macio_state->cuda_mem);
|
66 | 3cbee15b | j_mayer | } |
67 | 3cbee15b | j_mayer | for (i = 0; i < macio_state->nb_ide; i++) { |
68 | 23c5e4ca | Avi Kivity | if (macio_state->ide_mem[i]) {
|
69 | 23c5e4ca | Avi Kivity | memory_region_add_subregion(bar, 0x1f000 + (i * 0x1000), |
70 | 23c5e4ca | Avi Kivity | macio_state->ide_mem[i]); |
71 | 3cbee15b | j_mayer | } |
72 | 3cbee15b | j_mayer | } |
73 | 74e91155 | j_mayer | if (macio_state->nvram != NULL) |
74 | 23c5e4ca | Avi Kivity | macio_nvram_setup_bar(macio_state->nvram, bar, 0x60000);
|
75 | 3cbee15b | j_mayer | } |
76 | 3cbee15b | j_mayer | |
77 | 23c5e4ca | Avi Kivity | void macio_init (PCIBus *bus, int device_id, int is_oldworld, |
78 | 23c5e4ca | Avi Kivity | MemoryRegion *pic_mem, MemoryRegion *dbdma_mem, |
79 | 23c5e4ca | Avi Kivity | MemoryRegion *cuda_mem, void *nvram,
|
80 | 23c5e4ca | Avi Kivity | int nb_ide, MemoryRegion **ide_mem,
|
81 | 23c5e4ca | Avi Kivity | MemoryRegion *escc_mem) |
82 | 3cbee15b | j_mayer | { |
83 | 3cbee15b | j_mayer | PCIDevice *d; |
84 | c227f099 | Anthony Liguori | macio_state_t *macio_state; |
85 | 3cbee15b | j_mayer | int i;
|
86 | 3cbee15b | j_mayer | |
87 | 3cbee15b | j_mayer | d = pci_register_device(bus, "macio",
|
88 | c227f099 | Anthony Liguori | sizeof(PCIDevice) + sizeof(macio_state_t), |
89 | 3cbee15b | j_mayer | -1, NULL, NULL); |
90 | c227f099 | Anthony Liguori | macio_state = (macio_state_t *)(d + 1);
|
91 | 3cbee15b | j_mayer | macio_state->is_oldworld = is_oldworld; |
92 | 23c5e4ca | Avi Kivity | macio_state->pic_mem = pic_mem; |
93 | 23c5e4ca | Avi Kivity | macio_state->dbdma_mem = dbdma_mem; |
94 | 23c5e4ca | Avi Kivity | macio_state->cuda_mem = cuda_mem; |
95 | 23c5e4ca | Avi Kivity | macio_state->escc_mem = escc_mem; |
96 | 74e91155 | j_mayer | macio_state->nvram = nvram; |
97 | 3cbee15b | j_mayer | if (nb_ide > 4) |
98 | 3cbee15b | j_mayer | nb_ide = 4;
|
99 | 3cbee15b | j_mayer | macio_state->nb_ide = nb_ide; |
100 | 3cbee15b | j_mayer | for (i = 0; i < nb_ide; i++) |
101 | 23c5e4ca | Avi Kivity | macio_state->ide_mem[i] = ide_mem[i]; |
102 | 3cbee15b | j_mayer | for (; i < 4; i++) |
103 | 23c5e4ca | Avi Kivity | macio_state->ide_mem[i] = NULL;
|
104 | 3cbee15b | j_mayer | /* Note: this code is strongly inspirated from the corresponding code
|
105 | 3cbee15b | j_mayer | in PearPC */
|
106 | deb54399 | aliguori | |
107 | deb54399 | aliguori | pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_APPLE); |
108 | deb54399 | aliguori | pci_config_set_device_id(d->config, device_id); |
109 | 173a543b | blueswir1 | pci_config_set_class(d->config, PCI_CLASS_OTHERS << 8);
|
110 | 3cbee15b | j_mayer | |
111 | 3cbee15b | j_mayer | d->config[0x3d] = 0x01; // interrupt on pin 1 |
112 | 3cbee15b | j_mayer | |
113 | 23c5e4ca | Avi Kivity | macio_bar_setup(macio_state); |
114 | e824b2cc | Avi Kivity | pci_register_bar(d, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &macio_state->bar);
|
115 | 3cbee15b | j_mayer | } |