hw/arm/nseries: don't print to stdout or stderr

Remove various bits of printing to stdout or stderr from the
nseries code, replacing it with a qemu log message where there's
an appropriate log category, and just dropping the output for
some of the more debug-like printing.

In particular, this will get rid of the 'mipid_reset' message
you currently get from 'make check'.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Andreas Färber <afaerber@suse.de>
Message-id: 1363368565-24546-1-git-send-email-peter.maydell@linaro.org
pl050: Don't send always-constant is_mouse field

The is_mouse field of the pl050 state structure is constant (it tracks
whether this is a 'pl050_keyboard' or 'pl050_mouse'), so there's
no need to include it in the VMState structure.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Message-id: 1363628480-29306-1-git-send-email-peter.maydell@linaro.org
hw/arm_mptimer: Save the timer state

Add a missing VMSTATE_TIMER() entry to the arm_mptimer vmstate
description; this omission meant that we would probably hang on reload
when the timer failed to fire.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
Message-id: 1363967348-3044-1-git-send-email-peter.maydell@linaro.org
vmstate.h: introduce VMSTATE_BUFFER_POINTER_UNSAFE macro

Macro could be used to migrate a dynamically allocated buffer of known size.

Signed-off-by: Igor Mitsyanko <i.mitsyanko@gmail.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-id: 1362923278-4080-2-git-send-email-i.mitsyanko@gmail.com
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
hw/sd.c: fix migration of dynamically allocated buffer "buf"

VMSTATE_BUFFER_UNSAFE should be used for buffers inlined in device state, not
for buffers allocated dynamically. Change to VMSTATE_BUFFER_POINTER_UNSAFE macro,
which will do migration right.

Signed-off-by: Igor Mitsyanko <i.mitsyanko@gmail.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Tested-by: Michael Walle <michael@walle.cc>
Message-id: 1362923278-4080-3-git-send-email-i.mitsyanko@gmail.com
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
hw/onenand.c: fix migration of dynamically allocated buffer "otp"

VMSTATE_BUFFER_UNSAFE should be used for buffers inlined in device state, not
for buffers allocated dynamically. Change to VMSTATE_BUFFER_POINTER_UNSAFE macro,
which will do migration right.

Signed-off-by: Igor Mitsyanko <i.mitsyanko@gmail.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-id: 1362923278-4080-4-git-send-email-i.mitsyanko@gmail.com
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
vmstate: Add support for two dimensional arrays

Add support for migrating two dimensional arrays, by defining
a set of new macros VMSTATE_*_2DARRAY paralleling the existing
VMSTATE_*_ARRAY macros. 2D arrays are handled the same for actual
state serialization; the only difference is that the type check
has to change for a 2D array.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Igor Mitsyanko <i.mitsyanko@gmail.com>
Message-id: 1363975375-3166-2-git-send-email-peter.maydell@linaro.org
arm_gic: Fix sizes of state fields in preparation for vmstate support

In preparation for switching to vmstate for migration support, fix
the sizes of various GIC state fields. In particular, we replace all
the bitfields (which VMState can't deal with) with straightforward
uint8_t values which we do bit operations on. (The bitfields made
more sense when NCPU was set differently in different situations,
but we now always model at the architectural limit of 8.)

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Igor Mitsyanko <i.mitsyanko@gmail.com>
Reviewed-by: Andreas Färber <afaerber@suse.de>
Message-id: 1363975375-3166-3-git-send-email-peter.maydell@linaro.org
hw/arm_gic_common: Use vmstate struct rather than save/load functions

Update the GIC save/restore to use vmstate rather than hand-rolled
save/load functions.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Igor Mitsyanko <i.mitsyanko@gmail.com>
Message-id: 1363975375-3166-4-git-send-email-peter.maydell@linaro.org
pflash_cfi01: Drop unused 'bypass' field

For pflash_cfi01 the 'bypass' field is set to zero and never changes,
so remove it (it is a leftover from pflash_cfi02, where bypass is
implemented).

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Message-id: 1363717469-30980-2-git-send-email-peter.maydell@linaro.org
pflash_cfi01: Implement migration support

Add a vmstate to pflash_cfi01, so that it can be live migrated.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Message-id: 1363717469-30980-3-git-send-email-peter.maydell@linaro.org
pl330: Don't inhibit ES bits on INTEN

This if-else logic inhibits setting of the event status (ES) bits
when interrupts are enabled. This is incorrect. ES should be set
regardless on INTEN state. INTEN only inhibits the signalling of
events to PL330 threads, not setting of the ES register.

Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
cadence_uart: Flush queued characters on reset

Reset can be used to empty the rx-fifo. As the fifo full condition is
used to return false from can_receive, queued rx data should be flushed
on reset accordingly.

Cc: Wendy Liang <jliang@xilinx.com>
Cc: Jason Wu <huanyu@xilinx.com>

Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
Reported-by: Jason Wu <huanyu@xilinx.com>
Message-id: 494c1e005e225c915d295ddfd75d992ad2dabc3c.1364964526.git.peter.crosthwaite@xilinx.com
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
hw/nand.c: Fix nand erase operation

Usually, nand erase operation has only 2 or 3 address cycles.
We need to mask s->addr to zero unset stale high-order bytes in the nand address
before using it as the erase address.

This fixes the NAND erase operation in Linux.

[PC: Generalised to work for any number of address cycles rather than just 3]

Signed-off-by: Wendy Liang <jliang@xilinx.com>
Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
Message-id: 1364967188-26711-1-git-send-email-peter.crosthwaite@xilinx.com
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
add def_value_str in QemuOptDesc struct and rewrite qemu_opts_print

qemu_opts_print has no user now, so can re-write the function safely.

qemu_opts_print will be used while using "qemu-img create", it will
produce the same output as previous code.

The behavior of this function has changed:

1. Print every possible option, whether a value has been set or not.
2. Option descriptors may provide a default value.
3. Print to stdout instead of stderr.

Previously the behavior was to print every option that has been set.
Options that have not been set would be skipped.

v11->v12
1) make def_value_str become the real default value string in opt_set
function.

v10->v11:
1)  print all values that have actually been assigned while accept-any
cases.

v7->v8:
1) print "elements => accept any params" while opts_accepts_any() ==
true.
2) since def_print_str is the default value if an option isn't set,
so rename it to def_value_str.

Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
rewirte

Conflicts:
	block.c
avoid duplication of default value in QemuOpts

This patch will move the default value entirely to QemuOptDesc.

When getting the value of an option that hasn't been set, and
QemuOptDesc has a default value, return that.  Else, behave as
before.

Example: qemu_opt_get_number(opts, "foo", 42)

   If "foo" has been set in opts, return its value.

   Else, if opt's QemuOptDesc has a default value for "foo", return
   that.

   Else, return 42.

   Note that the last argument is useless when QemuOptDesc has a
   default value.  Ugly.  If it bothers us, assert that the argument
   equals the default from QemuOptDesc.

Example: qemu_opt_get(opts, "bar")

   If "bar" has been set in opts, return its value.

   Else, if opt's QemuOptDesc has a default value for "bar", return
   that.

   Else, return NULL.

Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Create four QemuOptsList related functions

This patch will create 4 functions, count_opts_list, qemu_opts_append,
qemu_opts_free and qemu_opts_print_help, they will be used in following
commits.

v11->v12:
1) renmae functions.
2) fix loop styles and code styles.
3) qemu_opts_apend will not return NULL now.
4) merge_lists value is from arguments in qemu_opts_append.

v6->v7:
1) Fix typo.

v5->v6:
1) allocate enough space in append_opts_list function.

Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
set merge_lists and accept NULL in qemu_opts_append

Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Use QemuOpts support in block layer

This patch will use QemuOpts related functions in block layer, add
a member bdrv_create_opts to BlockDriver struct, it will return
a QemuOptsList pointer, which includes the image format's create
options.

And create options's primary consumer is block creating related
functions, so modify them together.

v11->v12:
1) create functions, such as qemu_opt_get_del  and qemu_opt_replace_set.
These functions works like origin code.
2) use QEMU_OPT_SIZE, not QEMU_OPT_NUMBER.
3) in bdrv_create, if opts is NULL, will create an empty one, so can
discard if(opts) code safely.

v10->v11:
1) qed.h move QED_DEFAULT_CLUSTER_SIZE from enum to macro, or
qemu_opts_print produce un-expanded cluster_size.
2) In qcow2.c and qcow.c, bdrv_create_file(filename, NULL), NULL ->
opts,
or while using protocol, there will be an error.

v8->v9:
1) add qemu_ prefix to gluster_create_opts.
2) fix bug: bdrv_gluster_unix and bdrv_gluster_rdma should also be
   converted.

v7->v8:
1) rebase to upstream source tree.
2) add gluster.c, raw-win32.c, and rbd.c.

v6->v7:
1) use osdep.h:stringify(), not redefining new macro.
2) preserve TODO comment.
3) fix typo. BLOCK_OPT_ENCRYPT->BLOCK_OPT_STATIC.
4) initialize disk_type even when opts is NULL.

v5->v6:
1) judge if opts == NULL in block layer create functions.
2) use bdrv_create_file(filename, NULL) in qcow_create and cow_create
funtion.
3) made more readable while using qemu_opt_get_number.

Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>

Conflicts:
	block.c