mpc8544_guts.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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.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. };
  53. typedef struct GutsState GutsState;
  54. static uint32_t mpc8544_guts_read32(void *opaque, target_phys_addr_t addr)
  55. {
  56. uint32_t value = 0;
  57. CPUState *env = cpu_single_env;
  58. addr &= MPC8544_GUTS_MMIO_SIZE - 1;
  59. switch (addr) {
  60. case MPC8544_GUTS_ADDR_PVR:
  61. value = env->spr[SPR_PVR];
  62. break;
  63. case MPC8544_GUTS_ADDR_SVR:
  64. value = env->spr[SPR_E500_SVR];
  65. break;
  66. default:
  67. fprintf(stderr, "guts: Unknown register read: %x\n", (int)addr);
  68. break;
  69. }
  70. return value;
  71. }
  72. static CPUReadMemoryFunc * const mpc8544_guts_read[] = {
  73. NULL,
  74. NULL,
  75. &mpc8544_guts_read32,
  76. };
  77. static void mpc8544_guts_write32(void *opaque, target_phys_addr_t addr,
  78. uint32_t value)
  79. {
  80. addr &= MPC8544_GUTS_MMIO_SIZE - 1;
  81. switch (addr) {
  82. case MPC8544_GUTS_ADDR_RSTCR:
  83. if (value & MPC8544_GUTS_RSTCR_RESET) {
  84. qemu_system_reset_request();
  85. }
  86. break;
  87. default:
  88. fprintf(stderr, "guts: Unknown register write: %x = %x\n",
  89. (int)addr, value);
  90. break;
  91. }
  92. }
  93. static CPUWriteMemoryFunc * const mpc8544_guts_write[] = {
  94. NULL,
  95. NULL,
  96. &mpc8544_guts_write32,
  97. };
  98. static int mpc8544_guts_initfn(SysBusDevice *dev)
  99. {
  100. GutsState *s;
  101. int iomem;
  102. s = FROM_SYSBUS(GutsState, sysbus_from_qdev(dev));
  103. iomem = cpu_register_io_memory(mpc8544_guts_read, mpc8544_guts_write, s,
  104. DEVICE_BIG_ENDIAN);
  105. sysbus_init_mmio(dev, MPC8544_GUTS_MMIO_SIZE, iomem);
  106. return 0;
  107. }
  108. static SysBusDeviceInfo mpc8544_guts_info = {
  109. .init = mpc8544_guts_initfn,
  110. .qdev.name = "mpc8544-guts",
  111. .qdev.size = sizeof(GutsState),
  112. };
  113. static void mpc8544_guts_register(void)
  114. {
  115. sysbus_register_withprop(&mpc8544_guts_info);
  116. }
  117. device_init(mpc8544_guts_register);