android_pipe: import the qemu_pipe/goldfish_pipe code

This brings in the android emulator pipe code from the current aosp-qemu
master branch. It works with and has been tested with the pingpong
pipe device. Currently the device cannot save and restore.

  - remove dependency on android utils (ANEW/ASTRDUP/AFREE)
  - detach from the goldfish_device bus bits (inc irq raising)
  - import a few helper functions (uint64_set_high/low, goldfish_guest_is_64bit)
  - disable the VM save/restore code
  - use current_cpu for memory translation ops instead of cpu_single_env
  - fix debugging prints using portable formats
  - common code path for translating vaddr->qemu addr*
  - make some debug statments user-visible (unimp and guest errors)

There is a hacking backlink between AndroidPipeState and the PipeDevice
stuff (which should be merged cleanly later) just so we can get back to
->irq when we need to.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>

---

v2
 - Fix get_qemu_addr_of_guest_buffer() to use cpu_physical_memory_map(),
 - remove remaining dead code (#if 0/commented)
 - rename remaining Goldfish/goldfish_ to Android/android_
 - add a little commentary to the top of the file
 - completely remove state save/restore code
 - add some FIXME statements where known

v3
 - handle failure to get physical page

v4
 - special case the "qemud:<name>" as an indication of a channel name.
 - reverse ping-pong pipe PIPE_WAKE_WRITE/READ wake-ups
 - rm some commented out code
 - merge in adding pipe device to ranchu model

v5
 - revert the reverse
android_adb_dbg: Add Android adb-debug backend

Add the adb-debug backend (identified by "qemud:adb-debug") which simply
prints all chars send accross the pipe buffers from the guest to stderr.

Reads are handled like the zero pipe.

Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
android_adb: add Android ADB backend [WIP]

The Android adbd daemon running inside Android VMs on the emulator
expect to be able to talk to a backend named "qemud:adb" (for historical
reasons).

The backend will carry out a handshake:
 1. Listen for connections from the host adb server on
    adb_port = <5555 + (2 * emulator instance id)>.
 2. Connect to the local adb server on port 5037 if it's available.
 3. Listen for and accept the beginning of the handshake with the adbd
    daemon (adbd sends 'accept' over the write).
 4. After the adb backend detects a connection on <adb_port>, it sends
    back an "ok" string to adbd.
 5. The adb backend will not send any more data over the pipe until it
    recognizes a 'start' request, which means the adbd is ready to
    receive data from the host ADB server.

Once the above process is complete, the adb backend will consume
everything it receives on the socket connected on <adb_port> and send it
over the adb pipe and will consume everything it receives over the adb
pipe and send it on the socket connected on <adb_port>.

Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

---

v2
 - re-write to be more GIOChannel like
 - unify adb_backend_tcp_state into adb_backend_state
 - remove connected, fd and tag fields, just use ->chan and ->listen_chan
 - don't manually clear Source, use return during connect sequence
 - sprinkling of commentary at the salient points
 - added a bunch of asserts to ensure things stay consistent
 - try and pass around &adb_state as *bs where possible
 - squash all fprintf's into DPRINTF
 - link current active chan to adb_pipe->chan

v3
 - rm pointless wakeup and debug state

v4
 - cast to (int) and use %x format for windows