qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-block] [Qemu-devel] [RFC 11/13] dp8393x: manage big endian bus


From: Thomas Huth
Subject: Re: [Qemu-block] [Qemu-devel] [RFC 11/13] dp8393x: manage big endian bus
Date: Sat, 9 Jun 2018 20:25:18 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0

On 08.06.2018 22:05, Laurent Vivier wrote:
> This is needed by Quadra 800, this card can run on little-endian
> or big-endian bus.
> 
> Signed-off-by: Laurent Vivier <address@hidden>
> ---
>  hw/net/dp8393x.c | 101 
> ++++++++++++++++++++++++++++++++++++++-----------------
>  1 file changed, 70 insertions(+), 31 deletions(-)
> 
> diff --git a/hw/net/dp8393x.c b/hw/net/dp8393x.c
> index ef5f1eb94f..5061474e6b 100644
> --- a/hw/net/dp8393x.c
> +++ b/hw/net/dp8393x.c
> @@ -150,6 +150,7 @@ typedef struct dp8393xState {
>  
>      /* Hardware */
>      uint8_t it_shift;
> +    bool big_endian;
>      qemu_irq irq;
>  #ifdef DEBUG_SONIC
>      int irq_level;
> @@ -174,6 +175,12 @@ typedef struct dp8393xState {
>      AddressSpace as;
>  } dp8393xState;
>  
> +#ifdef HOST_WORDS_BIGENDIAN
> +static const bool host_big_endian = true;
> +#else
> +static const bool host_big_endian = false;
> +#endif
> +
>  /* Accessor functions for values which are formed by
>   * concatenating two 16 bit device registers. By putting these
>   * in their own functions with a uint32_t return type we avoid the
> @@ -220,6 +227,36 @@ static uint32_t dp8393x_wt(dp8393xState *s)
>      return s->regs[SONIC_WT1] << 16 | s->regs[SONIC_WT0];
>  }
>  
> +static uint16_t dp8393x_get(dp8393xState *s, int width, uint16_t *base,
> +                            int offset)
> +{
> +    uint16_t val;
> +
> +    if (s->big_endian) {
> +        val = base[offset * width + width - 1];
> +    } else {
> +        val = base[offset * width];
> +    }
> +    if (s->big_endian != host_big_endian) {
> +        val = bswap16(val);
> +    }
> +    return val;
> +}

Could you maybe write that like this instead:

{
    uint16_t val;

    if (s->big_endian) {
        val = base[offset * width + width - 1];
        val = be16_to_cpu(val);
    } else {
        val = base[offset * width];
        val = le16_to_cpu(val);
    }
    return val;
}

?
... then you don't need that ugly host_big_endian variable anymore.

 Thomas



reply via email to

[Prev in Thread] Current Thread [Next in Thread]