framebuffer.c: cosmetic clean-ups
monitor: add support for dynamic command tables

This adds the scaffolding for creating dynamic command tables. Once a
monitor is initialised with dynamic command tables we can then add
additional commands to the monitor on demand.

This has the additional benefit of not having to build architecture
specific console commands into all builds of QEMU.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
target-arm: A64: fix use 12 bit page tables for AArch64 [!UPSTREAM]

The AArch64 architecture only support 4k+ pages so using a smaller value
for QEMU's internal page table handling only makes us less efficient. I
ran some simple benchmarks and measured a 25-30% speed improvement for
CPU bound tasks like booting the kernel or compressing a section of a
file-system.

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

---
Upstream status:
  The patch as is in not suitable for upstream as booting a sufficiently
  old aarch32 image against the aarch64-system emulator would break with
  such a static fixing of the table.

  The work to update the size of the page table on start-up needs to be done.
Initial goldfish_fb display device

import goldfish_fb from android

HACK: goldfish_fb: remove FB_GET_FORMAT register

FB_GET_FORMAT and associated code poke at a bunch of display internals,
but are never referenced by the kernel.  Revisit on top of the new qemu
display API if/when it's needed by the kernel.

HACK: goldfish_fb: disable UI rotation events

It's not clear how this worked or how to port it to the new display API,
so disable it for now

goldfish_fb: port to modern qemu apis

The device/object APIs and display APIs have been significantly
refactored.  qemu also has a tracing API which can replace the debugging
printfs.

Signed-off-by: Greg Hackmann <ghackmann@google.com>

Although the milkymist display device is indeed RGB565, it is
bigendian, so we can't actually borrow its drawfn helpers.
Implement our own instead.

After an FB_SET_BASE write, the guest is waiting for us to complete an
update cycle and notify it (via the FB_INT_BASE_UPDATE_DONE interrupt
status bit). Force the graphics backend to actually do a redraw
immediately; this avoids the guest timing out and producing periodic
"goldfish_fb_pan_display: timeout waiting for base update" warnings
on displays like VNC which make an effort to avoid redraw.

goldfish_fb: Don't use uninitialized ymin if screen is blank

Initialize ymin in the code path taken if the screen is blank,
to avoid use of an uninitialized variable.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
import goldfish_audio from android

goldfish_audio: remove code to read audio input from disk

Even on the android qemu, there are syntax errors when USE_QEMU_AUDIO_IN
is defined to 0 or left undefined.  No point in trying to port something
that doesn't work.

goldfish_audio: port to modern qemu apis

Signed-off-by: Greg Hackmann <ghackmann@google.com>
import goldfish_battery from android

Signed-off-by: Greg Hackmann <ghackmann@google.com>
goldfish_battery: port to modern qemu apis

Signed-off-by: Greg Hackmann <ghackmann@google.com>
hw/arm/ranchu: New machine model for 64-bit ARM Android emulator

Add a new machine model for the 64-bit ARM Android emulator.
This is based heavily on the 'virt' machine model, and like
that we also create a device tree to pass to the guest kernel.
The major difference is that this board will have all the
Android-specific devices in it.

We leave space for putting in the goldfish_audio device but do
not actually enable it for now, since audio is not an initial
requirement and has not been tested.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
PMM:
 * updated to use MachineState
 * updated to handle PSCI 0.2
hw/input/goldfish_events.c: Implement goldfish events device

Implement the goldfish 'events' device which provides a variety
of input events including simulated touchscreen and hard buttons.

This is a forward port and revamp of the goldfish/events_device
from the classic Android emulator. Some features from the
classic emulator are not supported:
 * multitouch
 * full keyboard

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
hw/arm/ranchu: Add goldfish events device

Add the goldfish events device to the ranchu board.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
slirp: Make slirp_lookup() a public function net_slirp_lookup()

Make slirp_lookup() a public function so other files can look up the
Slirp stack too. We improve the interface a bit so this is practical:
 * use Error arguments to report failures rather than calling
   monitor_printf() directly
 * return a Slirp* rather than a SlirpStack*, since the latter is a type
   local to this source file
 * rename to net_slirp_lookup() to match the other public functions
   in net/slirp.h

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
qemu-char: Add a chr_del_client method to char backends

Add a chr_del_client method to char backends. This makes sense
mostly for TCP, where it means "close the current connection and
then go back to listening for a new one"; the semantics are
as if the remote end had closed the connection.

This could for completeness be supported for other backends
(eg pipe, fd, tty), but this patch only supports it in TCP.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
monitor.c: Add support for Android console

Implement the Android console by hijacking the stock QEMU
monitor and implementing a different command set.

This commit provides the initial minimal framework and
changes to the core monitor code; it implements only the
two commands 'help' and 'kill'.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
android-console: Add support for redir commands

Add support for the redir commands which allow addition, removal
and listing of TCP and UDP port rediroctions.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
android-console: Implement quit

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
android-console: Add KO: prefix to parser syntax error messages

Indirect all the syntax error messages from the command parser
through a function pointer, so the Android console can override
it to put the KO: prefix on them.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
android-console: Make 'help' output match the classic emulator

Implement the 'help' command ourselves rather than using the
monitor's usual version, so we can make the output text match the
format of the classic emulator. This might not be necessary but
perhaps external tools are parsing the output to see what commands
are supported.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
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>
[PMM: Listen for ADB connections on 127.0.0.1, not localhost]
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>