2
0

dpcd.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * dpcd.c
  3. *
  4. * Copyright (C) 2015 : GreenSocs Ltd
  5. * http://www.greensocs.com/ , email: info@greensocs.com
  6. *
  7. * Developed by :
  8. * Frederic Konrad <fred.konrad@greensocs.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation, either version 2 of the License, or
  13. * (at your option)any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License along
  21. * with this program; if not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. /*
  25. * This is a simple AUX slave which emulates a connected screen.
  26. */
  27. #include "qemu/osdep.h"
  28. #include "qemu/log.h"
  29. #include "qemu/module.h"
  30. #include "hw/misc/auxbus.h"
  31. #include "migration/vmstate.h"
  32. #include "hw/display/dpcd.h"
  33. #ifndef DEBUG_DPCD
  34. #define DEBUG_DPCD 0
  35. #endif
  36. #define DPRINTF(fmt, ...) do { \
  37. if (DEBUG_DPCD) { \
  38. qemu_log("dpcd: " fmt, ## __VA_ARGS__); \
  39. } \
  40. } while (0)
  41. #define DPCD_READABLE_AREA 0x600
  42. struct DPCDState {
  43. /*< private >*/
  44. AUXSlave parent_obj;
  45. /*< public >*/
  46. /*
  47. * The DCPD is 0x7FFFF length but read as 0 after offset 0x5FF.
  48. */
  49. uint8_t dpcd_info[DPCD_READABLE_AREA];
  50. MemoryRegion iomem;
  51. };
  52. static uint64_t dpcd_read(void *opaque, hwaddr offset, unsigned size)
  53. {
  54. uint8_t ret;
  55. DPCDState *e = DPCD(opaque);
  56. if (offset < DPCD_READABLE_AREA) {
  57. ret = e->dpcd_info[offset];
  58. } else {
  59. qemu_log_mask(LOG_GUEST_ERROR, "dpcd: Bad offset 0x%" HWADDR_PRIX "\n",
  60. offset);
  61. ret = 0;
  62. }
  63. DPRINTF("read 0x%" PRIX8 " @0x%" HWADDR_PRIX "\n", ret, offset);
  64. return ret;
  65. }
  66. static void dpcd_write(void *opaque, hwaddr offset, uint64_t value,
  67. unsigned size)
  68. {
  69. DPCDState *e = DPCD(opaque);
  70. DPRINTF("write 0x%" PRIX8 " @0x%" HWADDR_PRIX "\n", (uint8_t)value, offset);
  71. if (offset < DPCD_READABLE_AREA) {
  72. e->dpcd_info[offset] = value;
  73. } else {
  74. qemu_log_mask(LOG_GUEST_ERROR, "dpcd: Bad offset 0x%" HWADDR_PRIX "\n",
  75. offset);
  76. }
  77. }
  78. static const MemoryRegionOps aux_ops = {
  79. .read = dpcd_read,
  80. .write = dpcd_write,
  81. .valid = {
  82. .min_access_size = 1,
  83. .max_access_size = 1,
  84. },
  85. .impl = {
  86. .min_access_size = 1,
  87. .max_access_size = 1,
  88. },
  89. };
  90. static void dpcd_reset(DeviceState *dev)
  91. {
  92. DPCDState *s = DPCD(dev);
  93. memset(&(s->dpcd_info), 0, sizeof(s->dpcd_info));
  94. s->dpcd_info[DPCD_REVISION] = DPCD_REV_1_0;
  95. s->dpcd_info[DPCD_MAX_LINK_RATE] = DPCD_5_4GBPS;
  96. s->dpcd_info[DPCD_MAX_LANE_COUNT] = DPCD_FOUR_LANES;
  97. s->dpcd_info[DPCD_RECEIVE_PORT0_CAP_0] = DPCD_EDID_PRESENT;
  98. /* buffer size */
  99. s->dpcd_info[DPCD_RECEIVE_PORT0_CAP_1] = 0xFF;
  100. s->dpcd_info[DPCD_LANE0_1_STATUS] = DPCD_LANE0_CR_DONE
  101. | DPCD_LANE0_CHANNEL_EQ_DONE
  102. | DPCD_LANE0_SYMBOL_LOCKED
  103. | DPCD_LANE1_CR_DONE
  104. | DPCD_LANE1_CHANNEL_EQ_DONE
  105. | DPCD_LANE1_SYMBOL_LOCKED;
  106. s->dpcd_info[DPCD_LANE2_3_STATUS] = DPCD_LANE2_CR_DONE
  107. | DPCD_LANE2_CHANNEL_EQ_DONE
  108. | DPCD_LANE2_SYMBOL_LOCKED
  109. | DPCD_LANE3_CR_DONE
  110. | DPCD_LANE3_CHANNEL_EQ_DONE
  111. | DPCD_LANE3_SYMBOL_LOCKED;
  112. s->dpcd_info[DPCD_LANE_ALIGN_STATUS_UPDATED] = DPCD_INTERLANE_ALIGN_DONE;
  113. s->dpcd_info[DPCD_SINK_STATUS] = DPCD_RECEIVE_PORT_0_STATUS;
  114. }
  115. static void dpcd_init(Object *obj)
  116. {
  117. DPCDState *s = DPCD(obj);
  118. memory_region_init_io(&s->iomem, obj, &aux_ops, s, TYPE_DPCD, 0x7FFFF);
  119. aux_init_mmio(AUX_SLAVE(obj), &s->iomem);
  120. }
  121. static const VMStateDescription vmstate_dpcd = {
  122. .name = TYPE_DPCD,
  123. .version_id = 0,
  124. .minimum_version_id = 0,
  125. .fields = (VMStateField[]) {
  126. VMSTATE_UINT8_ARRAY_V(dpcd_info, DPCDState, DPCD_READABLE_AREA, 0),
  127. VMSTATE_END_OF_LIST()
  128. }
  129. };
  130. static void dpcd_class_init(ObjectClass *oc, void *data)
  131. {
  132. DeviceClass *dc = DEVICE_CLASS(oc);
  133. dc->reset = dpcd_reset;
  134. dc->vmsd = &vmstate_dpcd;
  135. }
  136. static const TypeInfo dpcd_info = {
  137. .name = TYPE_DPCD,
  138. .parent = TYPE_AUX_SLAVE,
  139. .instance_size = sizeof(DPCDState),
  140. .class_init = dpcd_class_init,
  141. .instance_init = dpcd_init,
  142. };
  143. static void dpcd_register_types(void)
  144. {
  145. type_register_static(&dpcd_info);
  146. }
  147. type_init(dpcd_register_types)