mpc8544_guts.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * QEMU PowerPC MPC8544 global util pseudo-device
  3. *
  4. * Copyright (C) 2011 Freescale Semiconductor, Inc. All rights reserved.
  5. *
  6. * Author: Alexander Graf, <alex@csgraf.de>
  7. *
  8. * This is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * *****************************************************************
  14. *
  15. * The documentation for this device is noted in the MPC8544 documentation,
  16. * file name "MPC8544ERM.pdf". You can easily find it on the web.
  17. *
  18. */
  19. #include "hw.h"
  20. #include "sysemu/sysemu.h"
  21. #include "sysbus.h"
  22. #define MPC8544_GUTS_MMIO_SIZE 0x1000
  23. #define MPC8544_GUTS_RSTCR_RESET 0x02
  24. #define MPC8544_GUTS_ADDR_PORPLLSR 0x00
  25. #define MPC8544_GUTS_ADDR_PORBMSR 0x04
  26. #define MPC8544_GUTS_ADDR_PORIMPSCR 0x08
  27. #define MPC8544_GUTS_ADDR_PORDEVSR 0x0C
  28. #define MPC8544_GUTS_ADDR_PORDBGMSR 0x10
  29. #define MPC8544_GUTS_ADDR_PORDEVSR2 0x14
  30. #define MPC8544_GUTS_ADDR_GPPORCR 0x20
  31. #define MPC8544_GUTS_ADDR_GPIOCR 0x30
  32. #define MPC8544_GUTS_ADDR_GPOUTDR 0x40
  33. #define MPC8544_GUTS_ADDR_GPINDR 0x50
  34. #define MPC8544_GUTS_ADDR_PMUXCR 0x60
  35. #define MPC8544_GUTS_ADDR_DEVDISR 0x70
  36. #define MPC8544_GUTS_ADDR_POWMGTCSR 0x80
  37. #define MPC8544_GUTS_ADDR_MCPSUMR 0x90
  38. #define MPC8544_GUTS_ADDR_RSTRSCR 0x94
  39. #define MPC8544_GUTS_ADDR_PVR 0xA0
  40. #define MPC8544_GUTS_ADDR_SVR 0xA4
  41. #define MPC8544_GUTS_ADDR_RSTCR 0xB0
  42. #define MPC8544_GUTS_ADDR_IOVSELSR 0xC0
  43. #define MPC8544_GUTS_ADDR_DDRCSR 0xB20
  44. #define MPC8544_GUTS_ADDR_DDRCDR 0xB24
  45. #define MPC8544_GUTS_ADDR_DDRCLKDR 0xB28
  46. #define MPC8544_GUTS_ADDR_CLKOCR 0xE00
  47. #define MPC8544_GUTS_ADDR_SRDS1CR1 0xF04
  48. #define MPC8544_GUTS_ADDR_SRDS2CR1 0xF10
  49. #define MPC8544_GUTS_ADDR_SRDS2CR3 0xF18
  50. struct GutsState {
  51. SysBusDevice busdev;
  52. MemoryRegion iomem;
  53. };
  54. typedef struct GutsState GutsState;
  55. static uint64_t mpc8544_guts_read(void *opaque, hwaddr addr,
  56. unsigned size)
  57. {
  58. uint32_t value = 0;
  59. CPUPPCState *env = cpu_single_env;
  60. addr &= MPC8544_GUTS_MMIO_SIZE - 1;
  61. switch (addr) {
  62. case MPC8544_GUTS_ADDR_PVR:
  63. value = env->spr[SPR_PVR];
  64. break;
  65. case MPC8544_GUTS_ADDR_SVR:
  66. value = env->spr[SPR_E500_SVR];
  67. break;
  68. default:
  69. fprintf(stderr, "guts: Unknown register read: %x\n", (int)addr);
  70. break;
  71. }
  72. return value;
  73. }
  74. static void mpc8544_guts_write(void *opaque, hwaddr addr,
  75. uint64_t value, unsigned size)
  76. {
  77. addr &= MPC8544_GUTS_MMIO_SIZE - 1;
  78. switch (addr) {
  79. case MPC8544_GUTS_ADDR_RSTCR:
  80. if (value & MPC8544_GUTS_RSTCR_RESET) {
  81. qemu_system_reset_request();
  82. }
  83. break;
  84. default:
  85. fprintf(stderr, "guts: Unknown register write: %x = %x\n",
  86. (int)addr, (unsigned)value);
  87. break;
  88. }
  89. }
  90. static const MemoryRegionOps mpc8544_guts_ops = {
  91. .read = mpc8544_guts_read,
  92. .write = mpc8544_guts_write,
  93. .endianness = DEVICE_BIG_ENDIAN,
  94. .valid = {
  95. .min_access_size = 4,
  96. .max_access_size = 4,
  97. },
  98. };
  99. static int mpc8544_guts_initfn(SysBusDevice *dev)
  100. {
  101. GutsState *s;
  102. s = FROM_SYSBUS(GutsState, SYS_BUS_DEVICE(dev));
  103. memory_region_init_io(&s->iomem, &mpc8544_guts_ops, s,
  104. "mpc6544.guts", MPC8544_GUTS_MMIO_SIZE);
  105. sysbus_init_mmio(dev, &s->iomem);
  106. return 0;
  107. }
  108. static void mpc8544_guts_class_init(ObjectClass *klass, void *data)
  109. {
  110. SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
  111. k->init = mpc8544_guts_initfn;
  112. }
  113. static const TypeInfo mpc8544_guts_info = {
  114. .name = "mpc8544-guts",
  115. .parent = TYPE_SYS_BUS_DEVICE,
  116. .instance_size = sizeof(GutsState),
  117. .class_init = mpc8544_guts_class_init,
  118. };
  119. static void mpc8544_guts_register_types(void)
  120. {
  121. type_register_static(&mpc8544_guts_info);
  122. }
  123. type_init(mpc8544_guts_register_types)