| 
									
										
										
										
											2007-10-28 23:42:18 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * PowerMac MacIO device emulation | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright (c) 2005-2007 Fabrice Bellard | 
					
						
							|  |  |  |  * Copyright (c) 2007 Jocelyn Mayer | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Permission is hereby granted, free of charge, to any person obtaining a copy | 
					
						
							|  |  |  |  * of this software and associated documentation files (the "Software"), to deal | 
					
						
							|  |  |  |  * in the Software without restriction, including without limitation the rights | 
					
						
							|  |  |  |  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | 
					
						
							|  |  |  |  * copies of the Software, and to permit persons to whom the Software is | 
					
						
							|  |  |  |  * furnished to do so, subject to the following conditions: | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The above copyright notice and this permission notice shall be included in | 
					
						
							|  |  |  |  * all copies or substantial portions of the Software. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 
					
						
							|  |  |  |  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 
					
						
							|  |  |  |  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | 
					
						
							|  |  |  |  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 
					
						
							|  |  |  |  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 
					
						
							|  |  |  |  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | 
					
						
							|  |  |  |  * THE SOFTWARE. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2007-11-17 17:14:51 +00:00
										 |  |  | #include "hw.h"
 | 
					
						
							| 
									
										
										
										
											2007-10-28 23:42:18 +00:00
										 |  |  | #include "ppc_mac.h"
 | 
					
						
							| 
									
										
										
										
											2007-11-17 17:14:51 +00:00
										 |  |  | #include "pci.h"
 | 
					
						
							| 
									
										
										
										
											2009-01-12 17:40:23 +00:00
										 |  |  | #include "escc.h"
 | 
					
						
							| 
									
										
										
										
											2007-10-28 23:42:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-01 16:12:16 -05:00
										 |  |  | typedef struct macio_state_t macio_state_t; | 
					
						
							|  |  |  | struct macio_state_t { | 
					
						
							| 
									
										
										
										
											2007-10-28 23:42:18 +00:00
										 |  |  |     int is_oldworld; | 
					
						
							| 
									
										
										
										
											2011-08-08 16:09:17 +03:00
										 |  |  |     MemoryRegion bar; | 
					
						
							|  |  |  |     MemoryRegion *pic_mem; | 
					
						
							|  |  |  |     MemoryRegion *dbdma_mem; | 
					
						
							|  |  |  |     MemoryRegion *cuda_mem; | 
					
						
							|  |  |  |     MemoryRegion *escc_mem; | 
					
						
							| 
									
										
										
										
											2007-11-04 01:16:04 +00:00
										 |  |  |     void *nvram; | 
					
						
							| 
									
										
										
										
											2007-10-28 23:42:18 +00:00
										 |  |  |     int nb_ide; | 
					
						
							| 
									
										
										
										
											2011-08-08 16:09:17 +03:00
										 |  |  |     MemoryRegion *ide_mem[4]; | 
					
						
							| 
									
										
										
										
											2007-10-28 23:42:18 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-08 16:09:17 +03:00
										 |  |  | static void macio_bar_setup(macio_state_t *macio_state) | 
					
						
							| 
									
										
										
										
											2007-10-28 23:42:18 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     int i; | 
					
						
							| 
									
										
										
										
											2011-08-08 16:09:17 +03:00
										 |  |  |     MemoryRegion *bar = &macio_state->bar; | 
					
						
							| 
									
										
										
										
											2007-10-28 23:42:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-08 16:09:17 +03:00
										 |  |  |     memory_region_init(bar, "macio", 0x80000); | 
					
						
							|  |  |  |     if (macio_state->pic_mem) { | 
					
						
							| 
									
										
										
										
											2007-10-28 23:42:18 +00:00
										 |  |  |         if (macio_state->is_oldworld) { | 
					
						
							|  |  |  |             /* Heathrow PIC */ | 
					
						
							| 
									
										
										
										
											2011-08-08 16:09:17 +03:00
										 |  |  |             memory_region_add_subregion(bar, 0x00000, macio_state->pic_mem); | 
					
						
							| 
									
										
										
										
											2007-10-28 23:42:18 +00:00
										 |  |  |         } else { | 
					
						
							|  |  |  |             /* OpenPIC */ | 
					
						
							| 
									
										
										
										
											2011-08-08 16:09:17 +03:00
										 |  |  |             memory_region_add_subregion(bar, 0x40000, macio_state->pic_mem); | 
					
						
							| 
									
										
										
										
											2007-10-28 23:42:18 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-08-08 16:09:17 +03:00
										 |  |  |     if (macio_state->dbdma_mem) { | 
					
						
							|  |  |  |         memory_region_add_subregion(bar, 0x08000, macio_state->dbdma_mem); | 
					
						
							| 
									
										
										
										
											2007-10-28 23:42:18 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-08-08 16:09:17 +03:00
										 |  |  |     if (macio_state->escc_mem) { | 
					
						
							|  |  |  |         memory_region_add_subregion(bar, 0x13000, macio_state->escc_mem); | 
					
						
							| 
									
										
										
										
											2009-01-12 17:40:23 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-08-08 16:09:17 +03:00
										 |  |  |     if (macio_state->cuda_mem) { | 
					
						
							|  |  |  |         memory_region_add_subregion(bar, 0x16000, macio_state->cuda_mem); | 
					
						
							| 
									
										
										
										
											2007-10-28 23:42:18 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |     for (i = 0; i < macio_state->nb_ide; i++) { | 
					
						
							| 
									
										
										
										
											2011-08-08 16:09:17 +03:00
										 |  |  |         if (macio_state->ide_mem[i]) { | 
					
						
							|  |  |  |             memory_region_add_subregion(bar, 0x1f000 + (i * 0x1000), | 
					
						
							|  |  |  |                                         macio_state->ide_mem[i]); | 
					
						
							| 
									
										
										
										
											2007-10-28 23:42:18 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2007-11-04 01:16:04 +00:00
										 |  |  |     if (macio_state->nvram != NULL) | 
					
						
							| 
									
										
										
										
											2011-08-08 16:09:17 +03:00
										 |  |  |         macio_nvram_setup_bar(macio_state->nvram, bar, 0x60000); | 
					
						
							| 
									
										
										
										
											2007-10-28 23:42:18 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-08 16:09:17 +03:00
										 |  |  | void macio_init (PCIBus *bus, int device_id, int is_oldworld, | 
					
						
							|  |  |  |                  MemoryRegion *pic_mem, MemoryRegion *dbdma_mem, | 
					
						
							|  |  |  |                  MemoryRegion *cuda_mem, void *nvram, | 
					
						
							|  |  |  |                  int nb_ide, MemoryRegion **ide_mem, | 
					
						
							|  |  |  |                  MemoryRegion *escc_mem) | 
					
						
							| 
									
										
										
										
											2007-10-28 23:42:18 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     PCIDevice *d; | 
					
						
							| 
									
										
										
										
											2009-10-01 16:12:16 -05:00
										 |  |  |     macio_state_t *macio_state; | 
					
						
							| 
									
										
										
										
											2007-10-28 23:42:18 +00:00
										 |  |  |     int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     d = pci_register_device(bus, "macio", | 
					
						
							| 
									
										
										
										
											2009-10-01 16:12:16 -05:00
										 |  |  |                             sizeof(PCIDevice) + sizeof(macio_state_t), | 
					
						
							| 
									
										
										
										
											2007-10-28 23:42:18 +00:00
										 |  |  |                             -1, NULL, NULL); | 
					
						
							| 
									
										
										
										
											2009-10-01 16:12:16 -05:00
										 |  |  |     macio_state = (macio_state_t *)(d + 1); | 
					
						
							| 
									
										
										
										
											2007-10-28 23:42:18 +00:00
										 |  |  |     macio_state->is_oldworld = is_oldworld; | 
					
						
							| 
									
										
										
										
											2011-08-08 16:09:17 +03:00
										 |  |  |     macio_state->pic_mem = pic_mem; | 
					
						
							|  |  |  |     macio_state->dbdma_mem = dbdma_mem; | 
					
						
							|  |  |  |     macio_state->cuda_mem = cuda_mem; | 
					
						
							|  |  |  |     macio_state->escc_mem = escc_mem; | 
					
						
							| 
									
										
										
										
											2007-11-04 01:16:04 +00:00
										 |  |  |     macio_state->nvram = nvram; | 
					
						
							| 
									
										
										
										
											2007-10-28 23:42:18 +00:00
										 |  |  |     if (nb_ide > 4) | 
					
						
							|  |  |  |         nb_ide = 4; | 
					
						
							|  |  |  |     macio_state->nb_ide = nb_ide; | 
					
						
							|  |  |  |     for (i = 0; i < nb_ide; i++) | 
					
						
							| 
									
										
										
										
											2011-08-08 16:09:17 +03:00
										 |  |  |         macio_state->ide_mem[i] = ide_mem[i]; | 
					
						
							| 
									
										
										
										
											2007-10-28 23:42:18 +00:00
										 |  |  |     for (; i < 4; i++) | 
					
						
							| 
									
										
										
										
											2011-08-08 16:09:17 +03:00
										 |  |  |         macio_state->ide_mem[i] = NULL; | 
					
						
							| 
									
										
										
										
											2007-10-28 23:42:18 +00:00
										 |  |  |     /* Note: this code is strongly inspirated from the corresponding code
 | 
					
						
							|  |  |  |        in PearPC */ | 
					
						
							| 
									
										
										
										
											2009-01-26 15:37:35 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_APPLE); | 
					
						
							|  |  |  |     pci_config_set_device_id(d->config, device_id); | 
					
						
							| 
									
										
										
										
											2009-02-01 19:26:20 +00:00
										 |  |  |     pci_config_set_class(d->config, PCI_CLASS_OTHERS << 8); | 
					
						
							| 
									
										
										
										
											2007-10-28 23:42:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     d->config[0x3d] = 0x01; // interrupt on pin 1
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-08 16:09:17 +03:00
										 |  |  |     macio_bar_setup(macio_state); | 
					
						
							| 
									
										
										
										
											2011-08-08 16:09:31 +03:00
										 |  |  |     pci_register_bar(d, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &macio_state->bar); | 
					
						
							| 
									
										
										
										
											2007-10-28 23:42:18 +00:00
										 |  |  | } |