]> git.proxmox.com Git - qemu.git/blame - hw/macio.c
* sort the PowerPC target object files
[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 */
25#include "vl.h"
26#include "ppc_mac.h"
27
28typedef struct macio_state_t macio_state_t;
29struct macio_state_t {
30 int is_oldworld;
31 int pic_mem_index;
32 int dbdma_mem_index;
33 int cuda_mem_index;
34 int nvram_mem_index;
35 int nb_ide;
36 int ide_mem_index[4];
37};
38
39static void macio_map (PCIDevice *pci_dev, int region_num,
40 uint32_t addr, uint32_t size, int type)
41{
42 macio_state_t *macio_state;
43 int i;
44
45 macio_state = (macio_state_t *)(pci_dev + 1);
46 if (macio_state->pic_mem_index >= 0) {
47 if (macio_state->is_oldworld) {
48 /* Heathrow PIC */
49 cpu_register_physical_memory(addr + 0x00000, 0x1000,
50 macio_state->pic_mem_index);
51 } else {
52 /* OpenPIC */
53 cpu_register_physical_memory(addr + 0x40000, 0x40000,
54 macio_state->pic_mem_index);
55 }
56 }
57 if (macio_state->dbdma_mem_index >= 0) {
58 cpu_register_physical_memory(addr + 0x08000, 0x1000,
59 macio_state->dbdma_mem_index);
60 }
61 if (macio_state->cuda_mem_index >= 0) {
62 cpu_register_physical_memory(addr + 0x16000, 0x2000,
63 macio_state->cuda_mem_index);
64 }
65 for (i = 0; i < macio_state->nb_ide; i++) {
66 if (macio_state->ide_mem_index[i] >= 0) {
67 cpu_register_physical_memory(addr + 0x1f000 + (i * 0x1000), 0x1000,
68 macio_state->ide_mem_index[i]);
69 }
70 }
71 if (macio_state->nvram_mem_index >= 0) {
72 cpu_register_physical_memory(addr + 0x60000, 0x20000,
73 macio_state->nvram_mem_index);
74 }
75}
76
77void macio_init (PCIBus *bus, int device_id, int is_oldworld, int pic_mem_index,
78 int dbdma_mem_index, int cuda_mem_index, int nvram_mem_index,
79 int nb_ide, int *ide_mem_index)
80{
81 PCIDevice *d;
82 macio_state_t *macio_state;
83 int i;
84
85 d = pci_register_device(bus, "macio",
86 sizeof(PCIDevice) + sizeof(macio_state_t),
87 -1, NULL, NULL);
88 macio_state = (macio_state_t *)(d + 1);
89 macio_state->is_oldworld = is_oldworld;
90 macio_state->pic_mem_index = pic_mem_index;
91 macio_state->dbdma_mem_index = dbdma_mem_index;
92 macio_state->cuda_mem_index = cuda_mem_index;
93 macio_state->nvram_mem_index = nvram_mem_index;
94 if (nb_ide > 4)
95 nb_ide = 4;
96 macio_state->nb_ide = nb_ide;
97 for (i = 0; i < nb_ide; i++)
98 macio_state->ide_mem_index[i] = ide_mem_index[i];
99 for (; i < 4; i++)
100 macio_state->ide_mem_index[i] = -1;
101 /* Note: this code is strongly inspirated from the corresponding code
102 in PearPC */
103 d->config[0x00] = 0x6b; // vendor_id
104 d->config[0x01] = 0x10;
105 d->config[0x02] = device_id;
106 d->config[0x03] = device_id >> 8;
107
108 d->config[0x0a] = 0x00; // class_sub = pci2pci
109 d->config[0x0b] = 0xff; // class_base = bridge
110 d->config[0x0e] = 0x00; // header_type
111
112 d->config[0x3d] = 0x01; // interrupt on pin 1
113
114 pci_register_io_region(d, 0, 0x80000,
115 PCI_ADDRESS_SPACE_MEM, macio_map);
116}