2
0

vmware_utils.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * QEMU VMWARE paravirtual devices - auxiliary code
  3. *
  4. * Copyright (c) 2012 Ravello Systems LTD (http://ravellosystems.com)
  5. *
  6. * Developed by Daynix Computing LTD (http://www.daynix.com)
  7. *
  8. * Authors:
  9. * Dmitry Fleytman <dmitry@daynix.com>
  10. * Yan Vugenfirer <yan@daynix.com>
  11. *
  12. * This work is licensed under the terms of the GNU GPL, version 2 or later.
  13. * See the COPYING file in the top-level directory.
  14. *
  15. */
  16. #ifndef VMWARE_UTILS_H
  17. #define VMWARE_UTILS_H
  18. #include "qemu/range.h"
  19. #include "vmxnet_debug.h"
  20. /*
  21. * Shared memory access functions with byte swap support
  22. * Each function contains printout for reverse-engineering needs
  23. *
  24. */
  25. static inline void
  26. vmw_shmem_read(PCIDevice *d, hwaddr addr, void *buf, int len)
  27. {
  28. VMW_SHPRN("SHMEM r: %" PRIx64 ", len: %d to %p", addr, len, buf);
  29. pci_dma_read(d, addr, buf, len);
  30. }
  31. static inline void
  32. vmw_shmem_write(PCIDevice *d, hwaddr addr, void *buf, int len)
  33. {
  34. VMW_SHPRN("SHMEM w: %" PRIx64 ", len: %d to %p", addr, len, buf);
  35. pci_dma_write(d, addr, buf, len);
  36. }
  37. static inline void
  38. vmw_shmem_rw(PCIDevice *d, hwaddr addr, void *buf, int len, int is_write)
  39. {
  40. VMW_SHPRN("SHMEM r/w: %" PRIx64 ", len: %d (to %p), is write: %d",
  41. addr, len, buf, is_write);
  42. if (is_write)
  43. pci_dma_write(d, addr, buf, len);
  44. else
  45. pci_dma_read(d, addr, buf, len);
  46. }
  47. static inline void
  48. vmw_shmem_set(PCIDevice *d, hwaddr addr, uint8_t val, int len)
  49. {
  50. int i;
  51. VMW_SHPRN("SHMEM set: %" PRIx64 ", len: %d (value 0x%X)", addr, len, val);
  52. for (i = 0; i < len; i++) {
  53. pci_dma_write(d, addr + i, &val, 1);
  54. }
  55. }
  56. static inline uint32_t
  57. vmw_shmem_ld8(PCIDevice *d, hwaddr addr)
  58. {
  59. uint8_t res;
  60. pci_dma_read(d, addr, &res, 1);
  61. VMW_SHPRN("SHMEM load8: %" PRIx64 " (value 0x%X)", addr, res);
  62. return res;
  63. }
  64. static inline void
  65. vmw_shmem_st8(PCIDevice *d, hwaddr addr, uint8_t value)
  66. {
  67. VMW_SHPRN("SHMEM store8: %" PRIx64 " (value 0x%X)", addr, value);
  68. pci_dma_write(d, addr, &value, 1);
  69. }
  70. static inline uint32_t
  71. vmw_shmem_ld16(PCIDevice *d, hwaddr addr)
  72. {
  73. uint16_t res;
  74. pci_dma_read(d, addr, &res, 2);
  75. res = le16_to_cpu(res);
  76. VMW_SHPRN("SHMEM load16: %" PRIx64 " (value 0x%X)", addr, res);
  77. return res;
  78. }
  79. static inline void
  80. vmw_shmem_st16(PCIDevice *d, hwaddr addr, uint16_t value)
  81. {
  82. VMW_SHPRN("SHMEM store16: %" PRIx64 " (value 0x%X)", addr, value);
  83. value = cpu_to_le16(value);
  84. pci_dma_write(d, addr, &value, 2);
  85. }
  86. static inline uint32_t
  87. vmw_shmem_ld32(PCIDevice *d, hwaddr addr)
  88. {
  89. uint32_t res;
  90. pci_dma_read(d, addr, &res, 4);
  91. res = le32_to_cpu(res);
  92. VMW_SHPRN("SHMEM load32: %" PRIx64 " (value 0x%X)", addr, res);
  93. return res;
  94. }
  95. static inline void
  96. vmw_shmem_st32(PCIDevice *d, hwaddr addr, uint32_t value)
  97. {
  98. VMW_SHPRN("SHMEM store32: %" PRIx64 " (value 0x%X)", addr, value);
  99. value = cpu_to_le32(value);
  100. pci_dma_write(d, addr, &value, 4);
  101. }
  102. static inline uint64_t
  103. vmw_shmem_ld64(PCIDevice *d, hwaddr addr)
  104. {
  105. uint64_t res;
  106. pci_dma_read(d, addr, &res, 8);
  107. res = le64_to_cpu(res);
  108. VMW_SHPRN("SHMEM load64: %" PRIx64 " (value %" PRIx64 ")", addr, res);
  109. return res;
  110. }
  111. static inline void
  112. vmw_shmem_st64(PCIDevice *d, hwaddr addr, uint64_t value)
  113. {
  114. VMW_SHPRN("SHMEM store64: %" PRIx64 " (value %" PRIx64 ")", addr, value);
  115. value = cpu_to_le64(value);
  116. pci_dma_write(d, addr, &value, 8);
  117. }
  118. /* Macros for simplification of operations on array-style registers */
  119. /*
  120. * Whether <addr> lies inside of array-style register defined by <base>,
  121. * number of elements (<cnt>) and element size (<regsize>)
  122. *
  123. */
  124. #define VMW_IS_MULTIREG_ADDR(addr, base, cnt, regsize) \
  125. range_covers_byte(base, cnt * regsize, addr)
  126. /*
  127. * Returns index of given register (<addr>) in array-style register defined by
  128. * <base> and element size (<regsize>)
  129. *
  130. */
  131. #define VMW_MULTIREG_IDX_BY_ADDR(addr, base, regsize) \
  132. (((addr) - (base)) / (regsize))
  133. #endif