macio.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 "hw.h"
  26. #include "ppc_mac.h"
  27. #include "pci.h"
  28. #include "escc.h"
  29. typedef struct macio_state_t macio_state_t;
  30. struct macio_state_t {
  31. int is_oldworld;
  32. int pic_mem_index;
  33. int dbdma_mem_index;
  34. int cuda_mem_index;
  35. int escc_mem_index;
  36. void *nvram;
  37. int nb_ide;
  38. int ide_mem_index[4];
  39. };
  40. static void macio_map (PCIDevice *pci_dev, int region_num,
  41. uint32_t addr, uint32_t size, int type)
  42. {
  43. macio_state_t *macio_state;
  44. int i;
  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->escc_mem_index >= 0) {
  62. cpu_register_physical_memory(addr + 0x13000, ESCC_SIZE << 4,
  63. macio_state->escc_mem_index);
  64. }
  65. if (macio_state->cuda_mem_index >= 0) {
  66. cpu_register_physical_memory(addr + 0x16000, 0x2000,
  67. macio_state->cuda_mem_index);
  68. }
  69. for (i = 0; i < macio_state->nb_ide; i++) {
  70. if (macio_state->ide_mem_index[i] >= 0) {
  71. cpu_register_physical_memory(addr + 0x1f000 + (i * 0x1000), 0x1000,
  72. macio_state->ide_mem_index[i]);
  73. }
  74. }
  75. if (macio_state->nvram != NULL)
  76. macio_nvram_map(macio_state->nvram, addr + 0x60000);
  77. }
  78. void macio_init (PCIBus *bus, int device_id, int is_oldworld, int pic_mem_index,
  79. int dbdma_mem_index, int cuda_mem_index, void *nvram,
  80. int nb_ide, int *ide_mem_index, int escc_mem_index)
  81. {
  82. PCIDevice *d;
  83. macio_state_t *macio_state;
  84. int i;
  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->escc_mem_index = escc_mem_index;
  94. macio_state->nvram = nvram;
  95. if (nb_ide > 4)
  96. nb_ide = 4;
  97. macio_state->nb_ide = nb_ide;
  98. for (i = 0; i < nb_ide; i++)
  99. macio_state->ide_mem_index[i] = ide_mem_index[i];
  100. for (; i < 4; i++)
  101. macio_state->ide_mem_index[i] = -1;
  102. /* Note: this code is strongly inspirated from the corresponding code
  103. in PearPC */
  104. pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_APPLE);
  105. pci_config_set_device_id(d->config, device_id);
  106. pci_config_set_class(d->config, PCI_CLASS_OTHERS << 8);
  107. d->config[0x0e] = 0x00; // header_type
  108. d->config[0x3d] = 0x01; // interrupt on pin 1
  109. pci_register_io_region(d, 0, 0x80000,
  110. PCI_ADDRESS_SPACE_MEM, macio_map);
  111. }