android_pipe: Use guest physical address for buffer read/write

For reading and writing guest user space buffers, currently the kernel
sends the guest virtual address of the buffer to the pipe device. This
virtual address has to be first converted to a guest physical address.
Doing this translation on the QEMU side is inefficient and requires
additional handling when KVM is enabled, whose implementation would
either incur intrusive changes to QEMU's KVM support code or suffer
from poor performance (see commit 08c7228 of $AOSP/external/qemu for
details), and thus should be avoided if possible.

There is a TODO comment on map_guest_buffer() (hw/misc/android_pipe.c)
which requests that the translation be done on the kernel side and that
physical addresses be passed to the device instead of virtual ones.
This patch implements the QEMU-side changes.

In order to allow the kernel to work with both the new (paddr-based)
and the old (vaddr-based) pipe devices, a read-only register is added
to the new device, which is read by the pipe driver to obtain the
version of the device. The new pipe device is assigned a non-zero
version number (currently 1), while the old device automatically gets
version 0 because it simply returns 0 on read of any unknown register.
This way, the driver can tell which version of the emulator is running
on the host, and then sends either the virtual or the physical address
for buffer read/write.

See https://android-review.googlesource.com/127963 for the kernel-side
patch.

Change-Id: Icbc0bdc58b13219e380baea2097011225380e72c
Signed-off-by: Yu Ning <yu.ning@intel.com>
2 files changed
tree: 96ed5ef0dbefa169f74dd49e0fc08bd9d5a4d502
  1. audio/
  2. backends/
  3. block/
  4. bsd-user/
  5. default-configs/
  6. disas/
  7. docs/
  8. fpu/
  9. fsdev/
  10. gdb-xml/
  11. hw/
  12. include/
  13. libcacard/
  14. libdecnumber/
  15. linux-headers/
  16. linux-user/
  17. net/
  18. pc-bios/
  19. po/
  20. qapi/
  21. qga/
  22. qobject/
  23. qom/
  24. roms/
  25. scripts/
  26. slirp/
  27. stubs/
  28. sysconfigs/
  29. target-alpha/
  30. target-arm/
  31. target-cris/
  32. target-i386/
  33. target-lm32/
  34. target-m68k/
  35. target-microblaze/
  36. target-mips/
  37. target-moxie/
  38. target-openrisc/
  39. target-ppc/
  40. target-s390x/
  41. target-sh4/
  42. target-sparc/
  43. target-tricore/
  44. target-unicore32/
  45. target-xtensa/
  46. tcg/
  47. tests/
  48. trace/
  49. ui/
  50. util/
  51. .exrc
  52. .gitignore
  53. .gitmodules
  54. .mailmap
  55. .travis.yml
  56. accel.c
  57. aio-posix.c
  58. aio-win32.c
  59. android-commands.h
  60. android-console.c
  61. android-console.h
  62. arch_init.c
  63. async.c
  64. balloon.c
  65. block-migration.c
  66. block.c
  67. blockdev-nbd.c
  68. blockdev.c
  69. blockjob.c
  70. bootdevice.c
  71. bt-host.c
  72. bt-vhci.c
  73. Changelog
  74. CODING_STYLE
  75. configure
  76. COPYING
  77. COPYING.LIB
  78. coroutine-gthread.c
  79. coroutine-sigaltstack.c
  80. coroutine-ucontext.c
  81. coroutine-win32.c
  82. cpu-exec.c
  83. cpus.c
  84. cputlb.c
  85. device-hotplug.c
  86. device_tree.c
  87. disas.c
  88. dma-helpers.c
  89. dump.c
  90. exec.c
  91. gdbstub.c
  92. HACKING
  93. hmp-commands.hx
  94. hmp.c
  95. hmp.h
  96. iohandler.c
  97. ioport.c
  98. iothread.c
  99. kvm-all.c
  100. kvm-stub.c
  101. LICENSE
  102. main-loop.c
  103. MAINTAINERS
  104. Makefile
  105. Makefile.objs
  106. Makefile.target
  107. memory.c
  108. memory_mapping.c
  109. migration-exec.c
  110. migration-fd.c
  111. migration-rdma.c
  112. migration-tcp.c
  113. migration-unix.c
  114. migration.c
  115. module-common.c
  116. monitor.c
  117. nbd.c
  118. numa.c
  119. os-posix.c
  120. os-win32.c
  121. page_cache.c
  122. qapi-schema.json
  123. qdev-monitor.c
  124. qdict-test-data.txt
  125. qemu-bridge-helper.c
  126. qemu-char.c
  127. qemu-coroutine-io.c
  128. qemu-coroutine-lock.c
  129. qemu-coroutine-sleep.c
  130. qemu-coroutine.c
  131. qemu-doc.texi
  132. qemu-file-stdio.c
  133. qemu-file-unix.c
  134. qemu-file.c
  135. qemu-img-cmds.hx
  136. qemu-img.c
  137. qemu-img.texi
  138. qemu-io-cmds.c
  139. qemu-io.c
  140. qemu-log.c
  141. qemu-nbd.c
  142. qemu-nbd.texi
  143. qemu-options-wrapper.h
  144. qemu-options.h
  145. qemu-options.hx
  146. qemu-seccomp.c
  147. qemu-tech.texi
  148. qemu-timer.c
  149. qemu.nsi
  150. qemu.sasl
  151. qmp-commands.hx
  152. qmp.c
  153. qtest.c
  154. README
  155. rules.mak
  156. savevm.c
  157. softmmu_template.h
  158. spice-qemu-char.c
  159. tcg-runtime.c
  160. tci.c
  161. thread-pool.c
  162. thunk.c
  163. tpm.c
  164. trace-events
  165. translate-all.c
  166. translate-all.h
  167. user-exec.c
  168. VERSION
  169. version.rc
  170. vl.c
  171. vmstate.c
  172. xbzrle.c
  173. xen-common-stub.c
  174. xen-common.c
  175. xen-hvm-stub.c
  176. xen-hvm.c
  177. xen-mapcache.c