From nobody Sat Nov 23 10:42:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1731080754687363.82129427500934; Fri, 8 Nov 2024 07:45:54 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 961741843; Fri, 8 Nov 2024 10:45:53 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id B16D11743; Fri, 8 Nov 2024 10:44:01 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 3F0421754; Fri, 8 Nov 2024 10:43:56 -0500 (EST) Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 240461626 for ; Fri, 8 Nov 2024 10:43:41 -0500 (EST) Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-43168d9c6c9so19266655e9.3 for ; Fri, 08 Nov 2024 07:43:41 -0800 (PST) Received: from localhost.localdomain ([154.14.63.34]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-381eda0411csm5171097f8f.95.2024.11.08.07.43.38 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 08 Nov 2024 07:43:39 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.5 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1731080620; x=1731685420; darn=lists.libvirt.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jztEo/+GQMsNL+O6RII0AfRvEqFktG+ZuY9PKLU7Y+w=; b=liOgMB5DNExO6+H3Qu756vIWZfBEoj+zOVjtMVjc731IBa0Qy6IYlsAcTBGCvf9W8y Lw9TrdckfnjLORhwnf/HhIwBd4SW9zbFgZgA5sdBz9fbpYPyH+CGsscfCTWZ6I+2+gA5 wHoAvWw5R514gyXnQOvydJ2MSTI6S0la6Xc5YpIHlacXscey9+dFIjSZo1kqu2oSyIil fS2kMYjVY3gsghnuuyiMWb5rl5u+I8eYxzTnT7hrCgK1wFHnogYgrBlSN/BmkvL0a/Ux Tqjm1gWmVila5U/ewAkjFNorqcmlwwpvKi7aoH7zlmjBkS5P+KYNxXsuTMxMxawL0aIC CnDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731080620; x=1731685420; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jztEo/+GQMsNL+O6RII0AfRvEqFktG+ZuY9PKLU7Y+w=; b=IqKoYBsQFTfJAEoY8EEmt4E3khDuErOKXEbUAY/qFqbTo3MomxTFlJDZQVyf1y8kSo gzB9Uz9nEl4RWr0/Z56ZfPtkVk8OguiIFVSwbp0Sww2u7lbdE8bj5pUDuna/AFossA5F 2zX45T2oUAYtRyUIL/7nPMc3Rjh1u0qYYMCdIH0AsubT8rHFcHsjdbdybk0N/iFPGYyH wCNpFI9huHbfi1napLM7cX+h63Rd7d+J73HD3xH/s0rDSxcVVlW0cA80h9Fc3Dj7Zpnn MFG16Z1TJvZkXmaVVk5IrNTYam+qnp9RPWrhVzWiNa4UXIpY4VsMq+FYqPMe/vA0CSZ5 fqwA== X-Forwarded-Encrypted: i=1; AJvYcCVZMe3bPrMobfAr3oJqr63XHa2zFyj++naIOhNPjMZLxyon+DpeYsDjaBZmd2Xoy7GUzv9Jtg==@lists.libvirt.org X-Gm-Message-State: AOJu0YzPG99iVVwJbd52rx4dc2bpVVWITmCC+U8+LJXbSdsqk1jWFpa8 VcNBeRO3sJ8VsonUPiHsR4aejgN+zCyltjiAnokffCpaDEFIfFkk+gYvF6uXTGY= X-Google-Smtp-Source: AGHT+IF4Ugi9i4ohYJ6/e/reb5mP7ZkKvdFRLOQDtGNOw2OnU1DRbDqdGn8AVX3iYc0JeXIcm9zFdA== X-Received: by 2002:a05:600c:8715:b0:426:602d:a246 with SMTP id 5b1f17b1804b1-432b75199famr24760155e9.32.1731080619895; Fri, 08 Nov 2024 07:43:39 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Anton Johansson Subject: [RFC PATCH v3 04/17] hw/net/xilinx_ethlite: Simplify by having configurable endianness Date: Fri, 8 Nov 2024 15:43:04 +0000 Message-ID: <20241108154317.12129-5-philmd@linaro.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241108154317.12129-1-philmd@linaro.org> References: <20241108154317.12129-1-philmd@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: OHO5QVLIJFHLN3BJ3BAIDLUZL3BMPLS3 X-Message-ID-Hash: OHO5QVLIJFHLN3BJ3BAIDLUZL3BMPLS3 X-MailFrom: philmd@linaro.org X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0 CC: Jason Wang , Paolo Bonzini , Richard Henderson , devel@lists.libvirt.org, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "Edgar E. Iglesias" , Thomas Huth , qemu-arm@nongnu.org, qemu-ppc@nongnu.org, Peter Maydell , Alistair Francis , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1731080755073116600 Content-Type: text/plain; charset="utf-8" The Xilinx 'ethlite' device was added in commit b43848a100 ("xilinx: Add ethlite emulation"), being only built back then for a big-endian MicroBlaze target (see commit 72b675caac "microblaze: Hook into the build-system"). I/O endianness access was then clarified in commit d48751ed4f ("xilinx-ethlite: Simplify byteswapping to/from brams"). Here the 'fix' was to use tswap32(). Since the machine was built as big-endian target, tswap32() use means the fix was for a little endian host. While the datasheet (reference added in file header) is not precise about it, we interpret such change as the device expects accesses in big-endian order. Instead of having a double swapping, one in the core memory layer due to DEVICE_NATIVE_ENDIAN and a second one with the tswap calls, allow the machine code to select the proper endianness desired, removing the need of tswap(). Replace the DEVICE_NATIVE_ENDIAN MemoryRegionOps by a pair of DEVICE_LITTLE_ENDIAN / DEVICE_BIG_ENDIAN. Add the "little-endian" property to select the device endianness, defaulting to little endian. Set the proper endianness on the single machine using the device. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- RFC until I digest Paolo's review from v1: https://lore.kernel.org/qemu-devel/34f6fe2f-06e0-4e2a-a361-2d662f6814b5@red= hat.com/ --- hw/microblaze/petalogix_s3adsp1800_mmu.c | 1 + hw/net/xilinx_ethlite.c | 44 +++++++++++++++--------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/hw/microblaze/petalogix_s3adsp1800_mmu.c b/hw/microblaze/petal= ogix_s3adsp1800_mmu.c index af949196d3..f02d343e29 100644 --- a/hw/microblaze/petalogix_s3adsp1800_mmu.c +++ b/hw/microblaze/petalogix_s3adsp1800_mmu.c @@ -121,6 +121,7 @@ petalogix_s3adsp1800_init(MachineState *machine) sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, irq[TIMER_IRQ]); =20 dev =3D qdev_new("xlnx.xps-ethernetlite"); + qdev_prop_set_bit(dev, "little-endian", !TARGET_BIG_ENDIAN); qemu_configure_nic_device(dev, true, NULL); qdev_prop_set_uint32(dev, "tx-ping-pong", 0); qdev_prop_set_uint32(dev, "rx-ping-pong", 0); diff --git a/hw/net/xilinx_ethlite.c b/hw/net/xilinx_ethlite.c index e84b4cdd35..5c27f1250d 100644 --- a/hw/net/xilinx_ethlite.c +++ b/hw/net/xilinx_ethlite.c @@ -3,6 +3,9 @@ * * Copyright (c) 2009 Edgar E. Iglesias. * + * DS580: https://docs.amd.com/v/u/en-US/xps_ethernetlite + * LogiCORE IP XPS Ethernet Lite Media Access Controller + * * Permission is hereby granted, free of charge, to any person obtaining a= copy * of this software and associated documentation files (the "Software"), t= o deal * in the Software without restriction, including without limitation the r= ights @@ -25,7 +28,6 @@ #include "qemu/osdep.h" #include "qemu/module.h" #include "qom/object.h" -#include "exec/tswap.h" #include "hw/sysbus.h" #include "hw/irq.h" #include "hw/qdev-properties.h" @@ -60,6 +62,7 @@ struct xlx_ethlite { SysBusDevice parent_obj; =20 + bool little_endian_model; MemoryRegion mmio; qemu_irq irq; NICState *nic; @@ -103,9 +106,10 @@ eth_read(void *opaque, hwaddr addr, unsigned int size) break; =20 default: - r =3D tswap32(s->regs[addr]); + r =3D s->regs[addr]; break; } + return r; } =20 @@ -161,23 +165,26 @@ eth_write(void *opaque, hwaddr addr, break; =20 default: - s->regs[addr] =3D tswap32(value); + s->regs[addr] =3D value; break; } } =20 -static const MemoryRegionOps eth_ops =3D { - .read =3D eth_read, - .write =3D eth_write, - .endianness =3D DEVICE_NATIVE_ENDIAN, - .impl =3D { - .min_access_size =3D 4, - .max_access_size =3D 4, +static const MemoryRegionOps eth_ops[2] =3D { + [0 ... 1] =3D { + .read =3D eth_read, + .write =3D eth_write, + .impl =3D { + .min_access_size =3D 4, + .max_access_size =3D 4, + }, + .valid =3D { + .min_access_size =3D 4, + .max_access_size =3D 4, + }, }, - .valid =3D { - .min_access_size =3D 4, - .max_access_size =3D 4 - } + [0].endianness =3D DEVICE_BIG_ENDIAN, + [1].endianness =3D DEVICE_LITTLE_ENDIAN, }; =20 static bool eth_can_rx(NetClientState *nc) @@ -237,6 +244,10 @@ static void xilinx_ethlite_realize(DeviceState *dev, E= rror **errp) { struct xlx_ethlite *s =3D XILINX_ETHLITE(dev); =20 + memory_region_init_io(&s->mmio, OBJECT(dev), + ð_ops[s->little_endian_model], s, + "xlnx.xps-ethernetlite", R_MAX * 4); + qemu_macaddr_default_if_unset(&s->conf.macaddr); s->nic =3D qemu_new_nic(&net_xilinx_ethlite_info, &s->conf, object_get_typename(OBJECT(dev)), dev->id, @@ -249,13 +260,12 @@ static void xilinx_ethlite_init(Object *obj) struct xlx_ethlite *s =3D XILINX_ETHLITE(obj); =20 sysbus_init_irq(SYS_BUS_DEVICE(obj), &s->irq); - - memory_region_init_io(&s->mmio, obj, ð_ops, s, - "xlnx.xps-ethernetlite", R_MAX * 4); sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->mmio); } =20 static Property xilinx_ethlite_properties[] =3D { + DEFINE_PROP_BOOL("little-endian", struct xlx_ethlite, + little_endian_model, true), DEFINE_PROP_UINT32("tx-ping-pong", struct xlx_ethlite, c_tx_pingpong, = 1), DEFINE_PROP_UINT32("rx-ping-pong", struct xlx_ethlite, c_rx_pingpong, = 1), DEFINE_NIC_PROPERTIES(struct xlx_ethlite, conf), --=20 2.45.2