2
0

mpc8544_guts.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 "qemu/osdep.h"
  20. #include "qemu/module.h"
  21. #include "sysemu/runstate.h"
  22. #include "cpu.h"
  23. #include "hw/sysbus.h"
  24. #define MPC8544_GUTS_MMIO_SIZE 0x1000
  25. #define MPC8544_GUTS_RSTCR_RESET 0x02
  26. #define MPC8544_GUTS_ADDR_PORPLLSR 0x00
  27. #define MPC8544_GUTS_ADDR_PORBMSR 0x04
  28. #define MPC8544_GUTS_ADDR_PORIMPSCR 0x08
  29. #define MPC8544_GUTS_ADDR_PORDEVSR 0x0C
  30. #define MPC8544_GUTS_ADDR_PORDBGMSR 0x10
  31. #define MPC8544_GUTS_ADDR_PORDEVSR2 0x14
  32. #define MPC8544_GUTS_ADDR_GPPORCR 0x20
  33. #define MPC8544_GUTS_ADDR_GPIOCR 0x30
  34. #define MPC8544_GUTS_ADDR_GPOUTDR 0x40
  35. #define MPC8544_GUTS_ADDR_GPINDR 0x50
  36. #define MPC8544_GUTS_ADDR_PMUXCR 0x60
  37. #define MPC8544_GUTS_ADDR_DEVDISR 0x70
  38. #define MPC8544_GUTS_ADDR_POWMGTCSR 0x80
  39. #define MPC8544_GUTS_ADDR_MCPSUMR 0x90
  40. #define MPC8544_GUTS_ADDR_RSTRSCR 0x94
  41. #define MPC8544_GUTS_ADDR_PVR 0xA0
  42. #define MPC8544_GUTS_ADDR_SVR 0xA4
  43. #define MPC8544_GUTS_ADDR_RSTCR 0xB0
  44. #define MPC8544_GUTS_ADDR_IOVSELSR 0xC0
  45. #define MPC8544_GUTS_ADDR_DDRCSR 0xB20
  46. #define MPC8544_GUTS_ADDR_DDRCDR 0xB24
  47. #define MPC8544_GUTS_ADDR_DDRCLKDR 0xB28
  48. #define MPC8544_GUTS_ADDR_CLKOCR 0xE00
  49. #define MPC8544_GUTS_ADDR_SRDS1CR1 0xF04
  50. #define MPC8544_GUTS_ADDR_SRDS2CR1 0xF10
  51. #define MPC8544_GUTS_ADDR_SRDS2CR3 0xF18
  52. #define TYPE_MPC8544_GUTS "mpc8544-guts"
  53. #define MPC8544_GUTS(obj) OBJECT_CHECK(GutsState, (obj), TYPE_MPC8544_GUTS)
  54. struct GutsState {
  55. /*< private >*/
  56. SysBusDevice parent_obj;
  57. /*< public >*/
  58. MemoryRegion iomem;
  59. };
  60. typedef struct GutsState GutsState;
  61. static uint64_t mpc8544_guts_read(void *opaque, hwaddr addr,
  62. unsigned size)
  63. {
  64. uint32_t value = 0;
  65. PowerPCCPU *cpu = POWERPC_CPU(current_cpu);
  66. CPUPPCState *env = &cpu->env;
  67. addr &= MPC8544_GUTS_MMIO_SIZE - 1;
  68. switch (addr) {
  69. case MPC8544_GUTS_ADDR_PVR:
  70. value = env->spr[SPR_PVR];
  71. break;
  72. case MPC8544_GUTS_ADDR_SVR:
  73. value = env->spr[SPR_E500_SVR];
  74. break;
  75. default:
  76. fprintf(stderr, "guts: Unknown register read: %x\n", (int)addr);
  77. break;
  78. }
  79. return value;
  80. }
  81. static void mpc8544_guts_write(void *opaque, hwaddr addr,
  82. uint64_t value, unsigned size)
  83. {
  84. addr &= MPC8544_GUTS_MMIO_SIZE - 1;
  85. switch (addr) {
  86. case MPC8544_GUTS_ADDR_RSTCR:
  87. if (value & MPC8544_GUTS_RSTCR_RESET) {
  88. qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
  89. }
  90. break;
  91. default:
  92. fprintf(stderr, "guts: Unknown register write: %x = %x\n",
  93. (int)addr, (unsigned)value);
  94. break;
  95. }
  96. }
  97. static const MemoryRegionOps mpc8544_guts_ops = {
  98. .read = mpc8544_guts_read,
  99. .write = mpc8544_guts_write,
  100. .endianness = DEVICE_BIG_ENDIAN,
  101. .valid = {
  102. .min_access_size = 4,
  103. .max_access_size = 4,
  104. },
  105. };
  106. static void mpc8544_guts_initfn(Object *obj)
  107. {
  108. SysBusDevice *d = SYS_BUS_DEVICE(obj);
  109. GutsState *s = MPC8544_GUTS(obj);
  110. memory_region_init_io(&s->iomem, OBJECT(s), &mpc8544_guts_ops, s,
  111. "mpc8544.guts", MPC8544_GUTS_MMIO_SIZE);
  112. sysbus_init_mmio(d, &s->iomem);
  113. }
  114. static const TypeInfo mpc8544_guts_info = {
  115. .name = TYPE_MPC8544_GUTS,
  116. .parent = TYPE_SYS_BUS_DEVICE,
  117. .instance_size = sizeof(GutsState),
  118. .instance_init = mpc8544_guts_initfn,
  119. };
  120. static void mpc8544_guts_register_types(void)
  121. {
  122. type_register_static(&mpc8544_guts_info);
  123. }
  124. type_init(mpc8544_guts_register_types)