dpcd.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * Xilinx Display Port Control Data
  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. #include "trace.h"
  34. #define DPCD_READABLE_AREA 0x600
  35. struct DPCDState {
  36. /*< private >*/
  37. AUXSlave parent_obj;
  38. /*< public >*/
  39. /*
  40. * The DCPD is 0x7FFFF length but read as 0 after offset 0x5FF.
  41. */
  42. uint8_t dpcd_info[DPCD_READABLE_AREA];
  43. MemoryRegion iomem;
  44. };
  45. static uint64_t dpcd_read(void *opaque, hwaddr offset, unsigned size)
  46. {
  47. uint8_t ret;
  48. DPCDState *e = DPCD(opaque);
  49. if (offset < DPCD_READABLE_AREA) {
  50. ret = e->dpcd_info[offset];
  51. } else {
  52. qemu_log_mask(LOG_GUEST_ERROR, "dpcd: Bad offset 0x%" HWADDR_PRIX "\n",
  53. offset);
  54. ret = 0;
  55. }
  56. trace_dpcd_read(offset, ret);
  57. return ret;
  58. }
  59. static void dpcd_write(void *opaque, hwaddr offset, uint64_t value,
  60. unsigned size)
  61. {
  62. DPCDState *e = DPCD(opaque);
  63. trace_dpcd_write(offset, value);
  64. if (offset < DPCD_READABLE_AREA) {
  65. e->dpcd_info[offset] = value;
  66. } else {
  67. qemu_log_mask(LOG_GUEST_ERROR, "dpcd: Bad offset 0x%" HWADDR_PRIX "\n",
  68. offset);
  69. }
  70. }
  71. static const MemoryRegionOps aux_ops = {
  72. .read = dpcd_read,
  73. .write = dpcd_write,
  74. .valid = {
  75. .min_access_size = 1,
  76. .max_access_size = 1,
  77. },
  78. .impl = {
  79. .min_access_size = 1,
  80. .max_access_size = 1,
  81. },
  82. };
  83. static void dpcd_reset(DeviceState *dev)
  84. {
  85. DPCDState *s = DPCD(dev);
  86. memset(&(s->dpcd_info), 0, sizeof(s->dpcd_info));
  87. s->dpcd_info[DPCD_REVISION] = DPCD_REV_1_0;
  88. s->dpcd_info[DPCD_MAX_LINK_RATE] = DPCD_5_4GBPS;
  89. s->dpcd_info[DPCD_MAX_LANE_COUNT] = DPCD_FOUR_LANES;
  90. s->dpcd_info[DPCD_RECEIVE_PORT0_CAP_0] = DPCD_EDID_PRESENT;
  91. /* buffer size */
  92. s->dpcd_info[DPCD_RECEIVE_PORT0_CAP_1] = 0xFF;
  93. s->dpcd_info[DPCD_LANE0_1_STATUS] = DPCD_LANE0_CR_DONE
  94. | DPCD_LANE0_CHANNEL_EQ_DONE
  95. | DPCD_LANE0_SYMBOL_LOCKED
  96. | DPCD_LANE1_CR_DONE
  97. | DPCD_LANE1_CHANNEL_EQ_DONE
  98. | DPCD_LANE1_SYMBOL_LOCKED;
  99. s->dpcd_info[DPCD_LANE2_3_STATUS] = DPCD_LANE2_CR_DONE
  100. | DPCD_LANE2_CHANNEL_EQ_DONE
  101. | DPCD_LANE2_SYMBOL_LOCKED
  102. | DPCD_LANE3_CR_DONE
  103. | DPCD_LANE3_CHANNEL_EQ_DONE
  104. | DPCD_LANE3_SYMBOL_LOCKED;
  105. s->dpcd_info[DPCD_LANE_ALIGN_STATUS_UPDATED] = DPCD_INTERLANE_ALIGN_DONE;
  106. s->dpcd_info[DPCD_SINK_STATUS] = DPCD_RECEIVE_PORT_0_STATUS;
  107. }
  108. static void dpcd_init(Object *obj)
  109. {
  110. DPCDState *s = DPCD(obj);
  111. memory_region_init_io(&s->iomem, obj, &aux_ops, s, TYPE_DPCD, 0x80000);
  112. aux_init_mmio(AUX_SLAVE(obj), &s->iomem);
  113. }
  114. static const VMStateDescription vmstate_dpcd = {
  115. .name = TYPE_DPCD,
  116. .version_id = 0,
  117. .minimum_version_id = 0,
  118. .fields = (VMStateField[]) {
  119. VMSTATE_UINT8_ARRAY_V(dpcd_info, DPCDState, DPCD_READABLE_AREA, 0),
  120. VMSTATE_END_OF_LIST()
  121. }
  122. };
  123. static void dpcd_class_init(ObjectClass *oc, void *data)
  124. {
  125. DeviceClass *dc = DEVICE_CLASS(oc);
  126. dc->reset = dpcd_reset;
  127. dc->vmsd = &vmstate_dpcd;
  128. }
  129. static const TypeInfo dpcd_info = {
  130. .name = TYPE_DPCD,
  131. .parent = TYPE_AUX_SLAVE,
  132. .instance_size = sizeof(DPCDState),
  133. .class_init = dpcd_class_init,
  134. .instance_init = dpcd_init,
  135. };
  136. static void dpcd_register_types(void)
  137. {
  138. type_register_static(&dpcd_info);
  139. }
  140. type_init(dpcd_register_types)