2
0

macio.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. MemoryRegion bar;
  33. MemoryRegion *pic_mem;
  34. MemoryRegion *dbdma_mem;
  35. MemoryRegion *cuda_mem;
  36. MemoryRegion *escc_mem;
  37. void *nvram;
  38. int nb_ide;
  39. MemoryRegion *ide_mem[4];
  40. };
  41. static void macio_bar_setup(macio_state_t *macio_state)
  42. {
  43. int i;
  44. MemoryRegion *bar = &macio_state->bar;
  45. memory_region_init(bar, "macio", 0x80000);
  46. if (macio_state->pic_mem) {
  47. if (macio_state->is_oldworld) {
  48. /* Heathrow PIC */
  49. memory_region_add_subregion(bar, 0x00000, macio_state->pic_mem);
  50. } else {
  51. /* OpenPIC */
  52. memory_region_add_subregion(bar, 0x40000, macio_state->pic_mem);
  53. }
  54. }
  55. if (macio_state->dbdma_mem) {
  56. memory_region_add_subregion(bar, 0x08000, macio_state->dbdma_mem);
  57. }
  58. if (macio_state->escc_mem) {
  59. memory_region_add_subregion(bar, 0x13000, macio_state->escc_mem);
  60. }
  61. if (macio_state->cuda_mem) {
  62. memory_region_add_subregion(bar, 0x16000, macio_state->cuda_mem);
  63. }
  64. for (i = 0; i < macio_state->nb_ide; i++) {
  65. if (macio_state->ide_mem[i]) {
  66. memory_region_add_subregion(bar, 0x1f000 + (i * 0x1000),
  67. macio_state->ide_mem[i]);
  68. }
  69. }
  70. if (macio_state->nvram != NULL)
  71. macio_nvram_setup_bar(macio_state->nvram, bar, 0x60000);
  72. }
  73. void macio_init (PCIBus *bus, int device_id, int is_oldworld,
  74. MemoryRegion *pic_mem, MemoryRegion *dbdma_mem,
  75. MemoryRegion *cuda_mem, void *nvram,
  76. int nb_ide, MemoryRegion **ide_mem,
  77. MemoryRegion *escc_mem)
  78. {
  79. PCIDevice *d;
  80. macio_state_t *macio_state;
  81. int i;
  82. d = pci_register_device(bus, "macio",
  83. sizeof(PCIDevice) + sizeof(macio_state_t),
  84. -1, NULL, NULL);
  85. macio_state = (macio_state_t *)(d + 1);
  86. macio_state->is_oldworld = is_oldworld;
  87. macio_state->pic_mem = pic_mem;
  88. macio_state->dbdma_mem = dbdma_mem;
  89. macio_state->cuda_mem = cuda_mem;
  90. macio_state->escc_mem = escc_mem;
  91. macio_state->nvram = nvram;
  92. if (nb_ide > 4)
  93. nb_ide = 4;
  94. macio_state->nb_ide = nb_ide;
  95. for (i = 0; i < nb_ide; i++)
  96. macio_state->ide_mem[i] = ide_mem[i];
  97. for (; i < 4; i++)
  98. macio_state->ide_mem[i] = NULL;
  99. /* Note: this code is strongly inspirated from the corresponding code
  100. in PearPC */
  101. pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_APPLE);
  102. pci_config_set_device_id(d->config, device_id);
  103. pci_config_set_class(d->config, PCI_CLASS_OTHERS << 8);
  104. d->config[0x3d] = 0x01; // interrupt on pin 1
  105. macio_bar_setup(macio_state);
  106. pci_register_bar(d, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &macio_state->bar);
  107. }