From nobody Sat Nov 23 22:48:07 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1730812033; cv=none; d=zohomail.com; s=zohoarc; b=CJuvGADLT4avxAfZuPCXNHPoE2fO3AqhDr86iGHytUoHem1O/5hdpKgh1/RmApDH6QfXp/UmIfe5m6fu7u3RtQQsnyqzuFI8J+45+AhJikWw+82F0i0jF+iCQyUlnhLmtPR+50+YMSosU/hNkOut7LFHciE6cofhiC5BVy4cGNo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730812033; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=8o7w6mm+R/wQGpGGVYXrXktqPkxmlHPhQB9iwAgMFYc=; b=Gw7Cwvp/2cAccaoLWs5J4vrliJ3PQbclwF5siMgq2yZ2ogqNSdGsE2CKSHeWq6P0xV7u1jpr6+QGI+yrghKJFjgIkbFdBrj3yXzgyM44rdhgCCa2r4WtyRj64ZBxUkl1VTL5DZq204qw3I80tAue1i+lSj+SqrZC/dTEmPwAvRw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730812033327174.73038435421415; Tue, 5 Nov 2024 05:07:13 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8JGl-00065y-M3; Tue, 05 Nov 2024 08:06:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8JGa-0005fE-A6 for qemu-devel@nongnu.org; Tue, 05 Nov 2024 08:06:42 -0500 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t8JGY-0002d2-A9 for qemu-devel@nongnu.org; Tue, 05 Nov 2024 08:06:40 -0500 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-4316a44d1bbso46496155e9.3 for ; Tue, 05 Nov 2024 05:06:37 -0800 (PST) Received: from localhost.localdomain (86.red-88-29-160.dynamicip.rima-tde.net. [88.29.160.86]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4327d5c65absm185489175e9.16.2024.11.05.05.06.32 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 05 Nov 2024 05:06:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730811996; x=1731416796; darn=nongnu.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=8o7w6mm+R/wQGpGGVYXrXktqPkxmlHPhQB9iwAgMFYc=; b=MxAp+1ehdfasvlGIbeGzzUdYsHvm29DUahviUlIv/AL3BUtqUlsUmQkGAAf/V9fbuV 2F/qKMIQ4qT692ob6zlwFdhBcc/9UwiBRbaThXMnmCQVZg9SFctb+ypUwdtpGKnn4/Bi CMajKhcPq8XV0PMZejRvmybMiyp0OH25G0449MeMaDzJPCiQzOBCBtGMTHwZ6D6j/2Nk wQiFMkS5JzFaLJDgQudsryJRV8iL/71BqLFAZtZlRVQLK+JV+CvKRiERpnDSrgNsl6JO HWKqUi3g1upvQj39rVv+Y4eB7NwsvjOD8zFREY1Mq9TdN4btNHQmWiO9Zv883IUJuV45 2J2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730811996; x=1731416796; 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=8o7w6mm+R/wQGpGGVYXrXktqPkxmlHPhQB9iwAgMFYc=; b=krzmkqeHqOz3f6l/eD6xYFVjwqDPervCoYHdePLkkBr5N77zrdoWpAiaKfy68nXH58 eiig2WtyzV8V/ZAn1GAw0dRzvYKTgkWHgm9TpT5otesNHCXM70CQZkIXNLT+a9Vu7f4k 77vzRsCE5NortigHrAkT1DmsFSA2dlzdDPkokHN812sX1OSqDMnd2Bsr76+QKavOzTIG VRgRChOpug2Pdj+xZ1+K/PWqUyRbskIlqSWR5LXl1eksxXGny4OmzO9Rs+ncenOiyb0h cKDPyUJDkEoxVCIZQLmAf4igkhxytvvkZuPncEyEYWz0mAllAIoVSwLX3lcV0mfi9V1J CQ9g== X-Gm-Message-State: AOJu0YyFFKVHPqAugrGm0HyMclj9tUeBoMz0F2jBoUEnkD66nltJcKVA pKqIyVYuVTh3Q4TiruPENO+6YZPyJqs20BgC/lRCmQJLumXHDcuOqkJT2E8jYPbn6oJuXnZNXJ5 mtDk= X-Google-Smtp-Source: AGHT+IGJfMAsKECXVoK0zYacWad+CWee04MBRfDuL0IXDekiXipIffi1uncuWI4/YK351Ggybd4Lqg== X-Received: by 2002:a05:600c:3507:b0:431:4e3f:9dee with SMTP id 5b1f17b1804b1-4327b6f46d3mr165594015e9.4.1730811995992; Tue, 05 Nov 2024 05:06:35 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Anton Johansson Cc: "Edgar E. Iglesias" , Peter Maydell , Alistair Francis , Thomas Huth , qemu-arm@nongnu.org, devel@lists.libvirt.org, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Jason Wang , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH 12/19] hw/net/xilinx_ethlite: Only expect big-endian accesses Date: Tue, 5 Nov 2024 14:04:24 +0100 Message-ID: <20241105130431.22564-13-philmd@linaro.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241105130431.22564-1-philmd@linaro.org> References: <20241105130431.22564-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::332; envelope-from=philmd@linaro.org; helo=mail-wm1-x332.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1730812034288116600 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. Besides, this is what other Xilinx/MicroBlaze devices use (see the 3 previous commits). Correct the MemoryRegionOps endianness. Add a 'access-little-endian' property, so if the bus access expect little-endian order we swap the values. Replace the tswap32() calls accordingly. Set the property on the single machine using this device. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/microblaze/petalogix_s3adsp1800_mmu.c | 1 + hw/net/xilinx_ethlite.c | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/hw/microblaze/petalogix_s3adsp1800_mmu.c b/hw/microblaze/petal= ogix_s3adsp1800_mmu.c index 8110be83715..8407dbee12a 100644 --- a/hw/microblaze/petalogix_s3adsp1800_mmu.c +++ b/hw/microblaze/petalogix_s3adsp1800_mmu.c @@ -123,6 +123,7 @@ petalogix_s3adsp1800_init(MachineState *machine) 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); + qdev_prop_set_bit(dev, "access-little-endian", !TARGET_BIG_ENDIAN); sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, ETHLITE_BASEADDR); sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, irq[ETHLITE_IRQ]); diff --git a/hw/net/xilinx_ethlite.c b/hw/net/xilinx_ethlite.c index ede7c172748..44ef11ebf89 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" @@ -65,6 +67,7 @@ struct xlx_ethlite NICState *nic; NICConf conf; =20 + bool access_little_endian; uint32_t c_tx_pingpong; uint32_t c_rx_pingpong; unsigned int txbuf; @@ -103,9 +106,12 @@ eth_read(void *opaque, hwaddr addr, unsigned int size) break; =20 default: - r =3D tswap32(s->regs[addr]); + r =3D s->regs[addr]; break; } + if (s->access_little_endian) { + bswap32s(&r); + } return r; } =20 @@ -117,6 +123,10 @@ eth_write(void *opaque, hwaddr addr, unsigned int base =3D 0; uint32_t value =3D val64; =20 + if (s->access_little_endian) { + bswap32s(&value); + } + addr >>=3D 2; switch (addr)=20 { @@ -161,7 +171,7 @@ eth_write(void *opaque, hwaddr addr, break; =20 default: - s->regs[addr] =3D tswap32(value); + s->regs[addr] =3D value; break; } } @@ -169,7 +179,7 @@ eth_write(void *opaque, hwaddr addr, static const MemoryRegionOps eth_ops =3D { .read =3D eth_read, .write =3D eth_write, - .endianness =3D DEVICE_NATIVE_ENDIAN, + .endianness =3D DEVICE_BIG_ENDIAN, .impl =3D { .min_access_size =3D 4, .max_access_size =3D 4, @@ -256,6 +266,8 @@ static void xilinx_ethlite_init(Object *obj) } =20 static Property xilinx_ethlite_properties[] =3D { + DEFINE_PROP_BOOL("access-little-endian", struct xlx_ethlite, + access_little_endian, false), 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