root / hw / macio.c @ 06113719
History | View | Annotate | Download (4.5 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 | 3cbee15b | j_mayer | typedef struct macio_state_t macio_state_t; |
31 | 3cbee15b | j_mayer | struct macio_state_t {
|
32 | 3cbee15b | j_mayer | int is_oldworld;
|
33 | 3cbee15b | j_mayer | int pic_mem_index;
|
34 | 3cbee15b | j_mayer | int dbdma_mem_index;
|
35 | 3cbee15b | j_mayer | int cuda_mem_index;
|
36 | 7fa9ae1a | blueswir1 | int escc_mem_index;
|
37 | 74e91155 | j_mayer | void *nvram;
|
38 | 3cbee15b | j_mayer | int nb_ide;
|
39 | 3cbee15b | j_mayer | int ide_mem_index[4]; |
40 | 3cbee15b | j_mayer | }; |
41 | 3cbee15b | j_mayer | |
42 | 3cbee15b | j_mayer | static void macio_map (PCIDevice *pci_dev, int region_num, |
43 | 3cbee15b | j_mayer | uint32_t addr, uint32_t size, int type)
|
44 | 3cbee15b | j_mayer | { |
45 | 3cbee15b | j_mayer | macio_state_t *macio_state; |
46 | 3cbee15b | j_mayer | int i;
|
47 | 3cbee15b | j_mayer | |
48 | 3cbee15b | j_mayer | macio_state = (macio_state_t *)(pci_dev + 1);
|
49 | 3cbee15b | j_mayer | if (macio_state->pic_mem_index >= 0) { |
50 | 3cbee15b | j_mayer | if (macio_state->is_oldworld) {
|
51 | 3cbee15b | j_mayer | /* Heathrow PIC */
|
52 | 3cbee15b | j_mayer | cpu_register_physical_memory(addr + 0x00000, 0x1000, |
53 | 3cbee15b | j_mayer | macio_state->pic_mem_index); |
54 | 3cbee15b | j_mayer | } else {
|
55 | 3cbee15b | j_mayer | /* OpenPIC */
|
56 | 3cbee15b | j_mayer | cpu_register_physical_memory(addr + 0x40000, 0x40000, |
57 | 3cbee15b | j_mayer | macio_state->pic_mem_index); |
58 | 3cbee15b | j_mayer | } |
59 | 3cbee15b | j_mayer | } |
60 | 3cbee15b | j_mayer | if (macio_state->dbdma_mem_index >= 0) { |
61 | 3cbee15b | j_mayer | cpu_register_physical_memory(addr + 0x08000, 0x1000, |
62 | 3cbee15b | j_mayer | macio_state->dbdma_mem_index); |
63 | 3cbee15b | j_mayer | } |
64 | 7fa9ae1a | blueswir1 | if (macio_state->escc_mem_index >= 0) { |
65 | 7fa9ae1a | blueswir1 | cpu_register_physical_memory(addr + 0x13000, ESCC_SIZE << 4, |
66 | 7fa9ae1a | blueswir1 | macio_state->escc_mem_index); |
67 | 7fa9ae1a | blueswir1 | } |
68 | 3cbee15b | j_mayer | if (macio_state->cuda_mem_index >= 0) { |
69 | 3cbee15b | j_mayer | cpu_register_physical_memory(addr + 0x16000, 0x2000, |
70 | 3cbee15b | j_mayer | macio_state->cuda_mem_index); |
71 | 3cbee15b | j_mayer | } |
72 | 3cbee15b | j_mayer | for (i = 0; i < macio_state->nb_ide; i++) { |
73 | 3cbee15b | j_mayer | if (macio_state->ide_mem_index[i] >= 0) { |
74 | 3cbee15b | j_mayer | cpu_register_physical_memory(addr + 0x1f000 + (i * 0x1000), 0x1000, |
75 | 3cbee15b | j_mayer | macio_state->ide_mem_index[i]); |
76 | 3cbee15b | j_mayer | } |
77 | 3cbee15b | j_mayer | } |
78 | 74e91155 | j_mayer | if (macio_state->nvram != NULL) |
79 | 74e91155 | j_mayer | macio_nvram_map(macio_state->nvram, addr + 0x60000);
|
80 | 3cbee15b | j_mayer | } |
81 | 3cbee15b | j_mayer | |
82 | 3cbee15b | j_mayer | void macio_init (PCIBus *bus, int device_id, int is_oldworld, int pic_mem_index, |
83 | 74e91155 | j_mayer | int dbdma_mem_index, int cuda_mem_index, void *nvram, |
84 | 7fa9ae1a | blueswir1 | int nb_ide, int *ide_mem_index, int escc_mem_index) |
85 | 3cbee15b | j_mayer | { |
86 | 3cbee15b | j_mayer | PCIDevice *d; |
87 | 3cbee15b | j_mayer | macio_state_t *macio_state; |
88 | 3cbee15b | j_mayer | int i;
|
89 | 3cbee15b | j_mayer | |
90 | 3cbee15b | j_mayer | d = pci_register_device(bus, "macio",
|
91 | 3cbee15b | j_mayer | sizeof(PCIDevice) + sizeof(macio_state_t), |
92 | 3cbee15b | j_mayer | -1, NULL, NULL); |
93 | 3cbee15b | j_mayer | macio_state = (macio_state_t *)(d + 1);
|
94 | 3cbee15b | j_mayer | macio_state->is_oldworld = is_oldworld; |
95 | 3cbee15b | j_mayer | macio_state->pic_mem_index = pic_mem_index; |
96 | 3cbee15b | j_mayer | macio_state->dbdma_mem_index = dbdma_mem_index; |
97 | 3cbee15b | j_mayer | macio_state->cuda_mem_index = cuda_mem_index; |
98 | 7fa9ae1a | blueswir1 | macio_state->escc_mem_index = escc_mem_index; |
99 | 74e91155 | j_mayer | macio_state->nvram = nvram; |
100 | 3cbee15b | j_mayer | if (nb_ide > 4) |
101 | 3cbee15b | j_mayer | nb_ide = 4;
|
102 | 3cbee15b | j_mayer | macio_state->nb_ide = nb_ide; |
103 | 3cbee15b | j_mayer | for (i = 0; i < nb_ide; i++) |
104 | 3cbee15b | j_mayer | macio_state->ide_mem_index[i] = ide_mem_index[i]; |
105 | 3cbee15b | j_mayer | for (; i < 4; i++) |
106 | 3cbee15b | j_mayer | macio_state->ide_mem_index[i] = -1;
|
107 | 3cbee15b | j_mayer | /* Note: this code is strongly inspirated from the corresponding code
|
108 | 3cbee15b | j_mayer | in PearPC */
|
109 | deb54399 | aliguori | |
110 | deb54399 | aliguori | pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_APPLE); |
111 | deb54399 | aliguori | pci_config_set_device_id(d->config, device_id); |
112 | 173a543b | blueswir1 | pci_config_set_class(d->config, PCI_CLASS_OTHERS << 8);
|
113 | 6407f373 | Isaku Yamahata | d->config[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL; // header_type
|
114 | 3cbee15b | j_mayer | |
115 | 3cbee15b | j_mayer | d->config[0x3d] = 0x01; // interrupt on pin 1 |
116 | 3cbee15b | j_mayer | |
117 | 28c2c264 | Avi Kivity | pci_register_bar(d, 0, 0x80000, |
118 | 3cbee15b | j_mayer | PCI_ADDRESS_SPACE_MEM, macio_map); |
119 | 3cbee15b | j_mayer | } |