j_mayer | 3cbee15 | 2007-10-28 23:42:18 +0000 | [diff] [blame] | 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 | */ |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 25 | #include "hw.h" |
j_mayer | 3cbee15 | 2007-10-28 23:42:18 +0000 | [diff] [blame] | 26 | #include "ppc_mac.h" |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 27 | #include "pci.h" |
blueswir1 | 7fa9ae1 | 2009-01-12 17:40:23 +0000 | [diff] [blame] | 28 | #include "escc.h" |
j_mayer | 3cbee15 | 2007-10-28 23:42:18 +0000 | [diff] [blame] | 29 | |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 30 | typedef struct macio_state_t macio_state_t; |
| 31 | struct macio_state_t { |
j_mayer | 3cbee15 | 2007-10-28 23:42:18 +0000 | [diff] [blame] | 32 | int is_oldworld; |
Avi Kivity | 23c5e4c | 2011-08-08 16:09:17 +0300 | [diff] [blame^] | 33 | MemoryRegion bar; |
| 34 | MemoryRegion *pic_mem; |
| 35 | MemoryRegion *dbdma_mem; |
| 36 | MemoryRegion *cuda_mem; |
| 37 | MemoryRegion *escc_mem; |
j_mayer | 74e9115 | 2007-11-04 01:16:04 +0000 | [diff] [blame] | 38 | void *nvram; |
j_mayer | 3cbee15 | 2007-10-28 23:42:18 +0000 | [diff] [blame] | 39 | int nb_ide; |
Avi Kivity | 23c5e4c | 2011-08-08 16:09:17 +0300 | [diff] [blame^] | 40 | MemoryRegion *ide_mem[4]; |
j_mayer | 3cbee15 | 2007-10-28 23:42:18 +0000 | [diff] [blame] | 41 | }; |
| 42 | |
Avi Kivity | 23c5e4c | 2011-08-08 16:09:17 +0300 | [diff] [blame^] | 43 | static void macio_bar_setup(macio_state_t *macio_state) |
j_mayer | 3cbee15 | 2007-10-28 23:42:18 +0000 | [diff] [blame] | 44 | { |
j_mayer | 3cbee15 | 2007-10-28 23:42:18 +0000 | [diff] [blame] | 45 | int i; |
Avi Kivity | 23c5e4c | 2011-08-08 16:09:17 +0300 | [diff] [blame^] | 46 | MemoryRegion *bar = &macio_state->bar; |
j_mayer | 3cbee15 | 2007-10-28 23:42:18 +0000 | [diff] [blame] | 47 | |
Avi Kivity | 23c5e4c | 2011-08-08 16:09:17 +0300 | [diff] [blame^] | 48 | memory_region_init(bar, "macio", 0x80000); |
| 49 | if (macio_state->pic_mem) { |
j_mayer | 3cbee15 | 2007-10-28 23:42:18 +0000 | [diff] [blame] | 50 | if (macio_state->is_oldworld) { |
| 51 | /* Heathrow PIC */ |
Avi Kivity | 23c5e4c | 2011-08-08 16:09:17 +0300 | [diff] [blame^] | 52 | memory_region_add_subregion(bar, 0x00000, macio_state->pic_mem); |
j_mayer | 3cbee15 | 2007-10-28 23:42:18 +0000 | [diff] [blame] | 53 | } else { |
| 54 | /* OpenPIC */ |
Avi Kivity | 23c5e4c | 2011-08-08 16:09:17 +0300 | [diff] [blame^] | 55 | memory_region_add_subregion(bar, 0x40000, macio_state->pic_mem); |
j_mayer | 3cbee15 | 2007-10-28 23:42:18 +0000 | [diff] [blame] | 56 | } |
| 57 | } |
Avi Kivity | 23c5e4c | 2011-08-08 16:09:17 +0300 | [diff] [blame^] | 58 | if (macio_state->dbdma_mem) { |
| 59 | memory_region_add_subregion(bar, 0x08000, macio_state->dbdma_mem); |
j_mayer | 3cbee15 | 2007-10-28 23:42:18 +0000 | [diff] [blame] | 60 | } |
Avi Kivity | 23c5e4c | 2011-08-08 16:09:17 +0300 | [diff] [blame^] | 61 | if (macio_state->escc_mem) { |
| 62 | memory_region_add_subregion(bar, 0x13000, macio_state->escc_mem); |
blueswir1 | 7fa9ae1 | 2009-01-12 17:40:23 +0000 | [diff] [blame] | 63 | } |
Avi Kivity | 23c5e4c | 2011-08-08 16:09:17 +0300 | [diff] [blame^] | 64 | if (macio_state->cuda_mem) { |
| 65 | memory_region_add_subregion(bar, 0x16000, macio_state->cuda_mem); |
j_mayer | 3cbee15 | 2007-10-28 23:42:18 +0000 | [diff] [blame] | 66 | } |
| 67 | for (i = 0; i < macio_state->nb_ide; i++) { |
Avi Kivity | 23c5e4c | 2011-08-08 16:09:17 +0300 | [diff] [blame^] | 68 | if (macio_state->ide_mem[i]) { |
| 69 | memory_region_add_subregion(bar, 0x1f000 + (i * 0x1000), |
| 70 | macio_state->ide_mem[i]); |
j_mayer | 3cbee15 | 2007-10-28 23:42:18 +0000 | [diff] [blame] | 71 | } |
| 72 | } |
j_mayer | 74e9115 | 2007-11-04 01:16:04 +0000 | [diff] [blame] | 73 | if (macio_state->nvram != NULL) |
Avi Kivity | 23c5e4c | 2011-08-08 16:09:17 +0300 | [diff] [blame^] | 74 | macio_nvram_setup_bar(macio_state->nvram, bar, 0x60000); |
j_mayer | 3cbee15 | 2007-10-28 23:42:18 +0000 | [diff] [blame] | 75 | } |
| 76 | |
Avi Kivity | 23c5e4c | 2011-08-08 16:09:17 +0300 | [diff] [blame^] | 77 | void macio_init (PCIBus *bus, int device_id, int is_oldworld, |
| 78 | MemoryRegion *pic_mem, MemoryRegion *dbdma_mem, |
| 79 | MemoryRegion *cuda_mem, void *nvram, |
| 80 | int nb_ide, MemoryRegion **ide_mem, |
| 81 | MemoryRegion *escc_mem) |
j_mayer | 3cbee15 | 2007-10-28 23:42:18 +0000 | [diff] [blame] | 82 | { |
| 83 | PCIDevice *d; |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 84 | macio_state_t *macio_state; |
j_mayer | 3cbee15 | 2007-10-28 23:42:18 +0000 | [diff] [blame] | 85 | int i; |
| 86 | |
| 87 | d = pci_register_device(bus, "macio", |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 88 | sizeof(PCIDevice) + sizeof(macio_state_t), |
j_mayer | 3cbee15 | 2007-10-28 23:42:18 +0000 | [diff] [blame] | 89 | -1, NULL, NULL); |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 90 | macio_state = (macio_state_t *)(d + 1); |
j_mayer | 3cbee15 | 2007-10-28 23:42:18 +0000 | [diff] [blame] | 91 | macio_state->is_oldworld = is_oldworld; |
Avi Kivity | 23c5e4c | 2011-08-08 16:09:17 +0300 | [diff] [blame^] | 92 | macio_state->pic_mem = pic_mem; |
| 93 | macio_state->dbdma_mem = dbdma_mem; |
| 94 | macio_state->cuda_mem = cuda_mem; |
| 95 | macio_state->escc_mem = escc_mem; |
j_mayer | 74e9115 | 2007-11-04 01:16:04 +0000 | [diff] [blame] | 96 | macio_state->nvram = nvram; |
j_mayer | 3cbee15 | 2007-10-28 23:42:18 +0000 | [diff] [blame] | 97 | if (nb_ide > 4) |
| 98 | nb_ide = 4; |
| 99 | macio_state->nb_ide = nb_ide; |
| 100 | for (i = 0; i < nb_ide; i++) |
Avi Kivity | 23c5e4c | 2011-08-08 16:09:17 +0300 | [diff] [blame^] | 101 | macio_state->ide_mem[i] = ide_mem[i]; |
j_mayer | 3cbee15 | 2007-10-28 23:42:18 +0000 | [diff] [blame] | 102 | for (; i < 4; i++) |
Avi Kivity | 23c5e4c | 2011-08-08 16:09:17 +0300 | [diff] [blame^] | 103 | macio_state->ide_mem[i] = NULL; |
j_mayer | 3cbee15 | 2007-10-28 23:42:18 +0000 | [diff] [blame] | 104 | /* Note: this code is strongly inspirated from the corresponding code |
| 105 | in PearPC */ |
aliguori | deb5439 | 2009-01-26 15:37:35 +0000 | [diff] [blame] | 106 | |
| 107 | pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_APPLE); |
| 108 | pci_config_set_device_id(d->config, device_id); |
blueswir1 | 173a543 | 2009-02-01 19:26:20 +0000 | [diff] [blame] | 109 | pci_config_set_class(d->config, PCI_CLASS_OTHERS << 8); |
j_mayer | 3cbee15 | 2007-10-28 23:42:18 +0000 | [diff] [blame] | 110 | |
| 111 | d->config[0x3d] = 0x01; // interrupt on pin 1 |
| 112 | |
Avi Kivity | 23c5e4c | 2011-08-08 16:09:17 +0300 | [diff] [blame^] | 113 | macio_bar_setup(macio_state); |
| 114 | pci_register_bar_region(d, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, |
| 115 | &macio_state->bar); |
j_mayer | 3cbee15 | 2007-10-28 23:42:18 +0000 | [diff] [blame] | 116 | } |