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>
[cdall: special casing "qemud:<name>"]
Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
android_pipe: Factor out example/test pipes from android_pipe

The Android Pipe main implementation file should only contain the actual
implementation.  Keeping all that test backend implementation code in
there just makes it confusing to grep in the file and figure out what is
going on.

This could be made dependent on some sort of debug flag to avoid
compiling test code as part of shipped binaries in the future.

Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
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

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>
[AJB: Bunch of clean-up/re-factoring to GIOChannel code]
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
ranchu: Create console and ADB ports automatically

On startup, start listening on the console and ADB ports automatically,
using the same "start at 5554 and work up until we find a pair of
ports which we can listen on" algorithm as the classic emulator.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>