cpu/virtio: turn virtio_is_big_endian() into a CPU object method

Legacy virtio devices are target endian, which means it depends on the CPU.
If we want to support targets that can change endianness (modern PPC and ARM
for the moment), we need to add a per-CPU class method to be called from
the virtio code: .has_big_endian_virtio. The name looks like a software
boundary violation, but please consider it as a hint for people to
avoid using it anywhere but in the virtio code... and FWIW, the violation
comes from the virtio specification^Wmess itself ! :)

We may safely use current_cpu as the affected paths come from cpu_exec().

The base class implementation returns what we have today: it is based
on TARGET_WORDS_BIGENDIAN.

Suggested-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
cpu/virtio: turn virtio_is_big_endian() into a CPU object method

Legacy virtio devices are target endian, which means it depends on the CPU.
If we want to support targets that can change endianness (modern PPC and ARM
for the moment), we need to add a per-CPU class method to be called from
the virtio code: .has_big_endian_virtio. The name looks like a software
boundary violation, but please consider it as a hint for people to
avoid using it anywhere but in the virtio code... and FWIW, the violation
comes from the virtio specification^Wmess itself ! :)

We may safely use current_cpu as the affected paths come from cpu_exec().

The base class implementation returns what we have today: it is based
on TARGET_WORDS_BIGENDIAN.

Suggested-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
cpu/virtio: turn virtio_is_big_endian() into a CPU object method

Legacy virtio devices are target endian, which means it depends on the CPU.
If we want to support targets that can change endianness (modern PPC and ARM
for the moment), we need to add a per-CPU class method to be called from
the virtio code: .has_big_endian_virtio. The name looks like a software
boundary violation, but please consider it as a hint for people to
avoid using it anywhere but in the virtio code... and FWIW, the violation
comes from the virtio specification^Wmess itself ! :)

We may safely use current_cpu as the affected paths come from cpu_exec().

The base class implementation returns what we have today: it is based
on TARGET_WORDS_BIGENDIAN.

Suggested-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
target-ppc: ppc64 can be either endian

POWER7, POWER7+ and POWER8 families use the ILE bit of the LPCR
special purpose register to decide the endianness to use when
entering interrupt handlers. When running a linux guest, this
provides a hint on the endianness used by the kernel. From a
qemu point of view, the information is needed for legacy virtio
support and possibly crash dump support as well.

Suggested-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
target-ppc: enable virtio endian ambivalent support

Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
edit
edit
virtio: add endian-ambivalent support to VirtIODevice

Some CPU families can dynamically change their endianness. This means we can
have little endian ppc or big endian arm guests for example. This has an
impact on legacy virtio data structures since they are target endian.
We hence introduce a new property to track the endianness of each virtio
device. The lifecycle is has follow:

	virtio_init()	set endianness to default (TARGET_WORDS_BIGENDIAN)
	     |
	virtio_reset()	set endiannes according to current_cpu
	     :
	     :
	virtio_reset()	set endiannes according to current_cpu (may change)
	     :
	     :
	virtio_save()   save endianness

	virtio_init()	set endianness to default (TARGET_WORDS_BIGENDIAN)
	     |
	virtio_load()	set endianness according to saved state
	     :
	     :

It is reasonnably assumed that endianness won't change while the device
is in use.

<disclaimer>
We should save the endianness property in the migration stream. Since it
only affects PPC and ARM targets, we should put it in a subsection. That
implies porting the whole virtio migration code to VMState... :-\

In the meantime, we try to guess endianness at load time with an ugly
heuristic involving available ring indexes.

An alternative hack for PPC is to assume that all CPUs have the same
endianness, and so have all virtio devices. Since CPU state is restored
first, we can randomly choose to rely on first_cpu to get the endianness.
</disclaimer>

Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
virtio: memory accessors for endian-ambivalent targets

This is the virtio-access.h header file taken from Rusty's "endian-ambivalent
targets using legacy virtio" patch. It introduces helpers that should be used
when accessing vring data or by drivers for data that contains headers.
The virtio config space is also target endian, but the current code already
handles that with the virtio_is_big_endian() helper. There is no obvious
benefit at using the virtio accessors in this case.

Now we have two distinct paths: a fast inline one for fixed endian targets,
and a slow out-of-line one for targets that define the new TARGET_IS_BIENDIAN
macro.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
[ relicensed virtio-access.h to GPLv2+ on Rusty's request,
  pass &address_space_memory to physical memory accessors,
  per-device endianness,
  virtio tswap16 and tswap64 helpers,
  Greg Kurz <gkurz@linux.vnet.ibm.com> ]
Cc: Cédric Le Goater <clg@fr.ibm.com>
Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
virtio: allow byte swapping for vring

Quoting original text from Rusty: "This is based on a simpler patch by Anthony
Liguouri".

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
[ add VirtIODevice * argument to most helpers,
  Greg Kurz <gkurz@linux.vnet.ibm.com> ]
Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
Reviewed-by: Thomas Huth <thuth@linux.vnet.ibm.com>
virtio-net: use virtio wrappers to access headers

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
[ pass VirtIODevice * to memory accessors,
  TCP checksums fix by Cédric Le Goater,
  Greg Kurz <gkurz@linux.vnet.ibm.com> ]
Cc: Cédric Le Goater <clg@fr.ibm.com>
Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
virtio-balloon: use virtio wrappers to access page frame numbers

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
[ pass VirtIODevice * to memory accessors,
  Greg Kurz <gkurz@linux.vnet.ibm.com> ]
Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
virtio-blk: use virtio wrappers to access headers

Note that st*_raw and ld*_raw are effectively replaced by st*_p and ld*_p.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
[ pass VirtIODevice * to memory accessors,
  Greg Kurz <gkurz@linux.vnet.ibm.com> ]
Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
virtio-scsi: use virtio wrappers to access headers

Note that st*_raw and ld*_raw are effectively replaced by st*_p and ld*_p.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
[ pass VirtIODevice * to memory accessors,
  fix missing tswap32 in virtio_scsi_push_event() by Cédric Le Goater,
  Greg Kurz <gkurz@linux.vnet.ibm.com> ]
Cc: Cédric Le Goater <clg@fr.ibm.com>
Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
virtio-serial-bus: use virtio wrappers to access headers

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
[ pass VirtIODevice * to memory accessors,
  Greg Kurz <gkurz@linux.vnet.ibm.com> ]
Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
virtio-9p: use virtio wrappers to access headers

Note that st*_raw and ld*_raw are effectively replaced by st*_p and ld*_p.

Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
target-ppc: ppc64 can be either endian

POWER7, POWER7+ and POWER8 families use the ILE bit of the LPCR
special purpose register to decide the endianness to use when
entering interrupt handlers. When running a linux guest, this
provides a hint on the endianness used by the kernel. From a
qemu point of view, the information is needed for legacy virtio
support and possibly crash dump support as well.

Suggested-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
target-ppc: enable virtio endian ambivalent support

Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
edit
edit