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>
pop
pop
push
push
Refresh of virtio_is_big_endian-cpu-method
refresh (create temporary patch)
refresh (create temporary patch)
refresh
refresh
Refresh of virtio_is_big_endian-cpu-method
refresh (create temporary patch)
refresh (create temporary patch)
refresh
refresh
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>
push
push
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>