[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] virtio_tswaps() vs virtio_ld/st_p()
From: |
Stefan Hajnoczi |
Subject: |
Re: [Qemu-devel] virtio_tswaps() vs virtio_ld/st_p() |
Date: |
Mon, 19 Jan 2015 13:10:30 +0000 |
On Mon, Jan 19, 2015 at 12:49 PM, Greg Kurz <address@hidden> wrote:
> On Mon, 19 Jan 2015 11:45:39 +0000
> Peter Maydell <address@hidden> wrote:
>
>> On 19 January 2015 at 11:35, Stefan Hajnoczi <address@hidden> wrote:
>> > What is the difference between the virtio_tswaps() and
>> > virtio_ld/st_p() families of functions?
>>
>> virtio_ld/st*_p() perform a load or store from memory pointed
>> to by the (host) pointer argument.
>>
>> virtio_tswap16 &c take a value, swap it as appropriate and
>> return a value.
>>
>> virtio_tswap16s &c do an in-place byteswap on the value pointed
>> to by the host pointer argument.
>>
>> (The tswap*/tswap*s pairs are a mirror of the equivalent families
>> of functions bswap16/bswap16s provided by bswap.h.)
>>
>> The most important distinction here is that the ld/st functions
>> will handle possibly unaligned accesses, whereas the tswap
>> functions will not. The former are intended for "fish this value
>> out from some guest RAM" and the latter for "we have a structure
>> we've copied from guest RAM already via memcpy and want to swizzle
>> the entries in it".
>>
>> -- PMM
>>
>
> Heh, not sure I would have provided such a comprehensive answer. :)
>
> Stefan,
>
> Feeling curious, what was the intent behind your question ?
I'm converting hw/virtio/dataplane/vring.c to use virtio_ld/st()
accessors so that KVM on Power supports bi-endian mode.
I noticed that devices use both virtio_tswap() and virtio_ld/st() in
different places. My main worry was that they are implemented
slightly different (how they combine #ifdefs and
virtio_access_is_big_endian()) and that I was missing something.
But it seems in my case there is no difference between the two.
Stefan