From: "Hervé Poussineau" <hpoussin@reactos.org>
To: Peter Maydell <peter.maydell@linaro.org>,
Laurent Vivier <laurent@vivier.eu>
Cc: "QEMU Developers" <qemu-devel@nongnu.org>,
"Kevin Wolf" <kwolf@redhat.com>, "Fam Zheng" <famz@redhat.com>,
Qemu-block <qemu-block@nongnu.org>,
"Jason Wang" <jasowang@redhat.com>,
"Mark Cave-Ayland" <mark.cave-ayland@ilande.co.uk>,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
"Gerd Hoffmann" <kraxel@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Max Reitz" <mreitz@redhat.com>,
"Yongbok Kim" <yongbok.kim@mips.com>,
"Andreas Färber" <afaerber@suse.de>,
"Aurelien Jarno" <aurelien@aurel32.net>
Subject: Re: [Qemu-devel] [RFC v3 09/10] dp8393x: manage big endian bus
Date: Mon, 9 Jul 2018 00:17:52 +0200 [thread overview]
Message-ID: <7225a30e-0112-8b8b-f121-d133769ad62e@reactos.org> (raw)
In-Reply-To: <CAFEAcA-T4+fc62yOL4mGd=_v_0vPLcCR94apqWf=k3DA9HkLuA@mail.gmail.com>
Le 08/07/2018 à 23:11, Peter Maydell a écrit :
> On 28 June 2018 at 00:29, Laurent Vivier <laurent@vivier.eu> wrote:
>> This is needed by Quadra 800, this card can run on little-endian
>> or big-endian bus.
>>
>> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
>> Tested-by: Hervé Poussineau <hpoussin@reactos.org>
>> ---
>> hw/net/dp8393x.c | 88 ++++++++++++++++++++++++++++++++++++--------------------
>> 1 file changed, 57 insertions(+), 31 deletions(-)
>>
>> diff --git a/hw/net/dp8393x.c b/hw/net/dp8393x.c
>> index f2d2ce344c..62adff9ba3 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;
>> @@ -220,6 +221,29 @@ 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 = be16_to_cpu(base[offset * width + width - 1]);
>> + } else {
>> + val = le16_to_cpu(base[offset * width]);
>> + }
>> + return val;
>> +}
>> +
>> +static void dp8393x_put(dp8393xState *s, int width, uint16_t *base, int offset,
>> + uint16_t val)
>> +{
>> + if (s->big_endian) {
>> + base[offset * width + width - 1] = cpu_to_be16(val);
>> + } else {
>> + base[offset * width] = cpu_to_le16(val);
>> + }
>> +}
>> +
>> static void dp8393x_update_irq(dp8393xState *s)
>> {
>> int level = (s->regs[SONIC_IMR] & s->regs[SONIC_ISR]) ? 1 : 0;
>> @@ -251,12 +275,12 @@ static void dp8393x_do_load_cam(dp8393xState *s)
>> /* Fill current entry */
>> address_space_rw(&s->as, dp8393x_cdp(s),
>> MEMTXATTRS_UNSPECIFIED, (uint8_t *)data, size, 0);
>> - s->cam[index][0] = data[1 * width] & 0xff;
>> - s->cam[index][1] = data[1 * width] >> 8;
>> - s->cam[index][2] = data[2 * width] & 0xff;
>> - s->cam[index][3] = data[2 * width] >> 8;
>> - s->cam[index][4] = data[3 * width] & 0xff;
>> - s->cam[index][5] = data[3 * width] >> 8;
>> + s->cam[index][0] = dp8393x_get(s, width, data, 1) & 0xff;
>> + s->cam[index][1] = dp8393x_get(s, width, data, 1) >> 8;
>> + s->cam[index][2] = dp8393x_get(s, width, data, 2) & 0xff;
>> + s->cam[index][3] = dp8393x_get(s, width, data, 2) >> 8;
>> + s->cam[index][4] = dp8393x_get(s, width, data, 3) & 0xff;
>> + s->cam[index][5] = dp8393x_get(s, width, data, 3) >> 8;
>
> The general pattern with the code in this device seems to be
> "load sizeof(uint16_t) * width * N bytes; then look at
> data[i * width], possibly with an endianness flip", where
> width is either 1 or 2 depending on a config register.
>
> Maybe it would be clearer if the data was loaded by doing a
> loop of N iterations of address_space_ldl_le / address_space_ldw_le /
> address_space_ldl_be / address_space_ldw_be ? Then you're doing
> something more like what the device is doing (ie a series of
> bus accesses of a particular width and endianness), and the
> handling of width and endianness is in the code doing the data
> loads rather than in the code that is manipulating the loaded
> data.
>
> Incidentally, the only other use of this device is in
> the mips 'jazz' boards. Those seem to be compiled for both
> mips64el and mips64 -- does anybody know if it actually
> works correctly in both those configurations ?
dp8393x in mips64el works well. mips64 is not testable.
Hervé
next prev parent reply other threads:[~2018-07-08 22:18 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-27 23:29 [Qemu-devel] [RFC v3 00/10] hw/m68k: add Apple Machintosh Quadra 800 machine Laurent Vivier
2018-06-27 23:29 ` [Qemu-devel] [RFC v3 01/10] hw/m68k: add via support Laurent Vivier
2018-06-27 23:29 ` [Qemu-devel] [RFC v3 02/10] ADB: VIA probes ADB bus when it is idle Laurent Vivier
2018-06-28 11:30 ` Dr. David Alan Gilbert
2018-06-29 18:28 ` Mark Cave-Ayland
2018-06-27 23:29 ` [Qemu-devel] [RFC v3 03/10] escc: introduce a selector for the register bit Laurent Vivier
2018-06-27 23:29 ` [Qemu-devel] [RFC v3 04/10] hw/m68k: add video card Laurent Vivier
2018-06-28 12:03 ` Dr. David Alan Gilbert
2018-07-09 17:03 ` Thomas Huth
2018-08-07 8:44 ` Gerd Hoffmann
2018-06-27 23:29 ` [Qemu-devel] [RFC v3 05/10] hw/m68k: Apple Sound Chip (ASC) emulation Laurent Vivier
2018-06-28 11:12 ` Dr. David Alan Gilbert
2018-06-27 23:29 ` [Qemu-devel] [RFC v3 06/10] ESP: add pseudo-DMA as used by Macintosh Laurent Vivier
2018-06-28 8:13 ` Paolo Bonzini
2018-06-28 8:27 ` Laurent Vivier
2018-06-27 23:29 ` [Qemu-devel] [RFC v3 07/10] hw/m68k: add Nubus support Laurent Vivier
2018-06-29 18:31 ` Mark Cave-Ayland
2018-06-27 23:29 ` [Qemu-devel] [RFC v3 08/10] hw/m68k: add a dummy SWIM floppy controller Laurent Vivier
2018-06-28 19:55 ` Hervé Poussineau
2018-06-27 23:29 ` [Qemu-devel] [RFC v3 09/10] dp8393x: manage big endian bus Laurent Vivier
2018-07-08 21:11 ` Peter Maydell
2018-07-08 22:17 ` Hervé Poussineau [this message]
2018-06-27 23:29 ` [Qemu-devel] [RFC v3 10/10] hw/m68k: define Macintosh Quadra 800 Laurent Vivier
2018-06-29 18:20 ` [Qemu-devel] [RFC v3 00/10] hw/m68k: add Apple Machintosh Quadra 800 machine Mark Cave-Ayland
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7225a30e-0112-8b8b-f121-d133769ad62e@reactos.org \
--to=hpoussin@reactos.org \
--cc=afaerber@suse.de \
--cc=aurelien@aurel32.net \
--cc=dgilbert@redhat.com \
--cc=famz@redhat.com \
--cc=jasowang@redhat.com \
--cc=kraxel@redhat.com \
--cc=kwolf@redhat.com \
--cc=laurent@vivier.eu \
--cc=mark.cave-ayland@ilande.co.uk \
--cc=mreitz@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=yongbok.kim@mips.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).