prep_systemio.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /*
  2. * QEMU PReP System I/O emulation
  3. *
  4. * Copyright (c) 2017 Hervé Poussineau
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. */
  24. #include "qemu/osdep.h"
  25. #include "hw/irq.h"
  26. #include "hw/isa/isa.h"
  27. #include "hw/qdev-properties.h"
  28. #include "migration/vmstate.h"
  29. #include "exec/address-spaces.h"
  30. #include "qemu/error-report.h" /* for error_report() */
  31. #include "qemu/module.h"
  32. #include "sysemu/runstate.h"
  33. #include "cpu.h"
  34. #include "trace.h"
  35. #define TYPE_PREP_SYSTEMIO "prep-systemio"
  36. #define PREP_SYSTEMIO(obj) \
  37. OBJECT_CHECK(PrepSystemIoState, (obj), TYPE_PREP_SYSTEMIO)
  38. /* Bit as defined in PowerPC Reference Plaform v1.1, sect. 6.1.5, p. 132 */
  39. #define PREP_BIT(n) (1 << (7 - (n)))
  40. typedef struct PrepSystemIoState {
  41. ISADevice parent_obj;
  42. MemoryRegion ppc_parity_mem;
  43. qemu_irq non_contiguous_io_map_irq;
  44. uint8_t sreset; /* 0x0092 */
  45. uint8_t equipment; /* 0x080c */
  46. uint8_t system_control; /* 0x081c */
  47. uint8_t iomap_type; /* 0x0850 */
  48. uint8_t ibm_planar_id; /* 0x0852 */
  49. qemu_irq softreset_irq;
  50. PortioList portio;
  51. } PrepSystemIoState;
  52. /* PORT 0092 -- Special Port 92 (Read/Write) */
  53. enum {
  54. PORT0092_SOFTRESET = PREP_BIT(7),
  55. PORT0092_LE_MODE = PREP_BIT(6),
  56. };
  57. static void prep_port0092_write(void *opaque, uint32_t addr, uint32_t val)
  58. {
  59. PrepSystemIoState *s = opaque;
  60. trace_prep_systemio_write(addr, val);
  61. s->sreset = val & PORT0092_SOFTRESET;
  62. qemu_set_irq(s->softreset_irq, s->sreset);
  63. if ((val & PORT0092_LE_MODE) != 0) {
  64. /* XXX Not supported yet */
  65. error_report("little-endian mode not supported");
  66. vm_stop(RUN_STATE_PAUSED);
  67. } else {
  68. /* Nothing to do */
  69. }
  70. }
  71. static uint32_t prep_port0092_read(void *opaque, uint32_t addr)
  72. {
  73. PrepSystemIoState *s = opaque;
  74. trace_prep_systemio_read(addr, s->sreset);
  75. return s->sreset;
  76. }
  77. /* PORT 0808 -- Hardfile Light Register (Write Only) */
  78. enum {
  79. PORT0808_HARDFILE_LIGHT_ON = PREP_BIT(7),
  80. };
  81. static void prep_port0808_write(void *opaque, uint32_t addr, uint32_t val)
  82. {
  83. trace_prep_systemio_write(addr, val);
  84. }
  85. /* PORT 0810 -- Password Protect 1 Register (Write Only) */
  86. /* reset by port 0x4D in the SIO */
  87. static void prep_port0810_write(void *opaque, uint32_t addr, uint32_t val)
  88. {
  89. trace_prep_systemio_write(addr, val);
  90. }
  91. /* PORT 0812 -- Password Protect 2 Register (Write Only) */
  92. /* reset by port 0x4D in the SIO */
  93. static void prep_port0812_write(void *opaque, uint32_t addr, uint32_t val)
  94. {
  95. trace_prep_systemio_write(addr, val);
  96. }
  97. /* PORT 0814 -- L2 Invalidate Register (Write Only) */
  98. static void prep_port0814_write(void *opaque, uint32_t addr, uint32_t val)
  99. {
  100. trace_prep_systemio_write(addr, val);
  101. }
  102. /* PORT 0818 -- Reserved for Keylock (Read Only) */
  103. enum {
  104. PORT0818_KEYLOCK_SIGNAL_HIGH = PREP_BIT(7),
  105. };
  106. static uint32_t prep_port0818_read(void *opaque, uint32_t addr)
  107. {
  108. uint32_t val = 0;
  109. trace_prep_systemio_read(addr, val);
  110. return val;
  111. }
  112. /* PORT 080C -- Equipment */
  113. enum {
  114. PORT080C_SCSIFUSE = PREP_BIT(1),
  115. PORT080C_L2_COPYBACK = PREP_BIT(4),
  116. PORT080C_L2_256 = PREP_BIT(5),
  117. PORT080C_UPGRADE_CPU = PREP_BIT(6),
  118. PORT080C_L2 = PREP_BIT(7),
  119. };
  120. static uint32_t prep_port080c_read(void *opaque, uint32_t addr)
  121. {
  122. PrepSystemIoState *s = opaque;
  123. trace_prep_systemio_read(addr, s->equipment);
  124. return s->equipment;
  125. }
  126. /* PORT 081C -- System Control Register (Read/Write) */
  127. enum {
  128. PORT081C_FLOPPY_MOTOR_INHIBIT = PREP_BIT(3),
  129. PORT081C_MASK_TEA = PREP_BIT(2),
  130. PORT081C_L2_UPDATE_INHIBIT = PREP_BIT(1),
  131. PORT081C_L2_CACHEMISS_INHIBIT = PREP_BIT(0),
  132. };
  133. static void prep_port081c_write(void *opaque, uint32_t addr, uint32_t val)
  134. {
  135. static const uint8_t mask = PORT081C_FLOPPY_MOTOR_INHIBIT |
  136. PORT081C_MASK_TEA |
  137. PORT081C_L2_UPDATE_INHIBIT |
  138. PORT081C_L2_CACHEMISS_INHIBIT;
  139. PrepSystemIoState *s = opaque;
  140. trace_prep_systemio_write(addr, val);
  141. s->system_control = val & mask;
  142. }
  143. static uint32_t prep_port081c_read(void *opaque, uint32_t addr)
  144. {
  145. PrepSystemIoState *s = opaque;
  146. trace_prep_systemio_read(addr, s->system_control);
  147. return s->system_control;
  148. }
  149. /* System Board Identification */
  150. static uint32_t prep_port0852_read(void *opaque, uint32_t addr)
  151. {
  152. PrepSystemIoState *s = opaque;
  153. trace_prep_systemio_read(addr, s->ibm_planar_id);
  154. return s->ibm_planar_id;
  155. }
  156. /* PORT 0850 -- I/O Map Type Register (Read/Write) */
  157. enum {
  158. PORT0850_IOMAP_NONCONTIGUOUS = PREP_BIT(7),
  159. };
  160. static uint32_t prep_port0850_read(void *opaque, uint32_t addr)
  161. {
  162. PrepSystemIoState *s = opaque;
  163. trace_prep_systemio_read(addr, s->iomap_type);
  164. return s->iomap_type;
  165. }
  166. static void prep_port0850_write(void *opaque, uint32_t addr, uint32_t val)
  167. {
  168. PrepSystemIoState *s = opaque;
  169. trace_prep_systemio_write(addr, val);
  170. qemu_set_irq(s->non_contiguous_io_map_irq,
  171. val & PORT0850_IOMAP_NONCONTIGUOUS);
  172. s->iomap_type = val & PORT0850_IOMAP_NONCONTIGUOUS;
  173. }
  174. static const MemoryRegionPortio ppc_io800_port_list[] = {
  175. { 0x092, 1, 1, .read = prep_port0092_read,
  176. .write = prep_port0092_write, },
  177. { 0x808, 1, 1, .write = prep_port0808_write, },
  178. { 0x80c, 1, 1, .read = prep_port080c_read, },
  179. { 0x810, 1, 1, .write = prep_port0810_write, },
  180. { 0x812, 1, 1, .write = prep_port0812_write, },
  181. { 0x814, 1, 1, .write = prep_port0814_write, },
  182. { 0x818, 1, 1, .read = prep_port0818_read },
  183. { 0x81c, 1, 1, .read = prep_port081c_read,
  184. .write = prep_port081c_write, },
  185. { 0x850, 1, 1, .read = prep_port0850_read,
  186. .write = prep_port0850_write, },
  187. { 0x852, 1, 1, .read = prep_port0852_read, },
  188. PORTIO_END_OF_LIST()
  189. };
  190. static uint64_t ppc_parity_error_readl(void *opaque, hwaddr addr,
  191. unsigned int size)
  192. {
  193. uint32_t val = 0;
  194. trace_prep_systemio_read((unsigned int)addr, val);
  195. return val;
  196. }
  197. static const MemoryRegionOps ppc_parity_error_ops = {
  198. .read = ppc_parity_error_readl,
  199. .valid = {
  200. .min_access_size = 4,
  201. .max_access_size = 4,
  202. },
  203. };
  204. static void prep_systemio_realize(DeviceState *dev, Error **errp)
  205. {
  206. ISADevice *isa = ISA_DEVICE(dev);
  207. PrepSystemIoState *s = PREP_SYSTEMIO(dev);
  208. PowerPCCPU *cpu;
  209. qdev_init_gpio_out(dev, &s->non_contiguous_io_map_irq, 1);
  210. s->iomap_type = PORT0850_IOMAP_NONCONTIGUOUS;
  211. qemu_set_irq(s->non_contiguous_io_map_irq,
  212. s->iomap_type & PORT0850_IOMAP_NONCONTIGUOUS);
  213. cpu = POWERPC_CPU(first_cpu);
  214. s->softreset_irq = cpu->env.irq_inputs[PPC6xx_INPUT_HRESET];
  215. isa_register_portio_list(isa, &s->portio, 0x0, ppc_io800_port_list, s,
  216. "systemio800");
  217. memory_region_init_io(&s->ppc_parity_mem, OBJECT(dev),
  218. &ppc_parity_error_ops, s, "ppc-parity", 0x4);
  219. memory_region_add_subregion(get_system_memory(), 0xbfffeff0,
  220. &s->ppc_parity_mem);
  221. }
  222. static const VMStateDescription vmstate_prep_systemio = {
  223. .name = "prep_systemio",
  224. .version_id = 1,
  225. .minimum_version_id = 1,
  226. .fields = (VMStateField[]) {
  227. VMSTATE_UINT8(sreset, PrepSystemIoState),
  228. VMSTATE_UINT8(system_control, PrepSystemIoState),
  229. VMSTATE_UINT8(iomap_type, PrepSystemIoState),
  230. VMSTATE_END_OF_LIST()
  231. },
  232. };
  233. static Property prep_systemio_properties[] = {
  234. DEFINE_PROP_UINT8("ibm-planar-id", PrepSystemIoState, ibm_planar_id, 0),
  235. DEFINE_PROP_UINT8("equipment", PrepSystemIoState, equipment, 0),
  236. DEFINE_PROP_END_OF_LIST()
  237. };
  238. static void prep_systemio_class_initfn(ObjectClass *klass, void *data)
  239. {
  240. DeviceClass *dc = DEVICE_CLASS(klass);
  241. dc->realize = prep_systemio_realize;
  242. dc->vmsd = &vmstate_prep_systemio;
  243. dc->props = prep_systemio_properties;
  244. }
  245. static TypeInfo prep_systemio800_info = {
  246. .name = TYPE_PREP_SYSTEMIO,
  247. .parent = TYPE_ISA_DEVICE,
  248. .instance_size = sizeof(PrepSystemIoState),
  249. .class_init = prep_systemio_class_initfn,
  250. };
  251. static void prep_systemio_register_types(void)
  252. {
  253. type_register_static(&prep_systemio800_info);
  254. }
  255. type_init(prep_systemio_register_types)