From nobody Sun Nov 24 01:57:05 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=1727700601; cv=none; d=zohomail.com; s=zohoarc; b=ZgSX7pcOu8Eyrhjnzkw1lE/lnNlN1WD0+YVfNjS0P3EtiFD2udUL7V1pnt9trRCWISpPMuV+A5ZO/dA9mBCH3fgaqhdneMwLK/6OiawRg51XxmV09Sq2SGWVFNAo1fUA3AjOmpmtpU5w4cFpImWmFiA+TE3sC6CnQYu9XG38JTA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727700601; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=uzm24+ZWrwMOuzZZfqf6biduFwcmS7XxAWWZizuNc3E=; b=WLC7S9sQticYxI3FkAg9B1uZJpCQvbtnlXPVyz6QvwNEHOeoH07H7oQ2D82i9ZNLy73nnUo8fsK470Dqk77lzLZuE5Y3YD11oqOAFES+JjytGUyvnIGbLHsb7X3MJKyXwixlkTPQdyCR/LdZwSoWF7nRqpG0FEUv/OJZ9ihspsw= 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 1727700601635800.9248856901213; Mon, 30 Sep 2024 05:50:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1svFpS-00083I-87; Mon, 30 Sep 2024 08:48:42 -0400 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 1svFpO-00080J-5L for qemu-devel@nongnu.org; Mon, 30 Sep 2024 08:48:38 -0400 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1svFpL-00067z-Sw for qemu-devel@nongnu.org; Mon, 30 Sep 2024 08:48:37 -0400 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-37ce14ab7eeso1593045f8f.2 for ; Mon, 30 Sep 2024 05:48:35 -0700 (PDT) Received: from localhost.localdomain ([78.196.4.158]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37cd56e6408sm8975801f8f.48.2024.09.30.05.48.32 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 30 Sep 2024 05:48:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1727700514; x=1728305314; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=uzm24+ZWrwMOuzZZfqf6biduFwcmS7XxAWWZizuNc3E=; b=kcaRKTLWVdxSp1v+2AuVQcUs2z2lVsjzt9aXB2dk5UhXcrWa8YThKD57qG0teJlZQU vikNhyN/jDUjreo8rPPUBSh5Nj/BpZWgL9K5mAreWGd87jAJ8oVq0EMiyFJia9dehKZj IH4LdSDunIqEOrJHKSfywXg0mie9YjEswGxsd52uW5z8lTnku1axNOVQY7xACBWe1Qxa E3+46HRGOi2Jgs89uo2c1n5/pQvySCqAL9HZpQ5P7oYdiaDN+JB6RKqJvLHCctBLHo3K RPQrGfl0caDoPEyt1JRmo4HYWd3PnEjOlRcnOvpA4Qz1DDaoD+c1A5F1HGg0Y9gxmqDW m/dA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727700514; x=1728305314; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=uzm24+ZWrwMOuzZZfqf6biduFwcmS7XxAWWZizuNc3E=; b=l06mVPExR3rA8x5CxfE5+cIa9VtbHS4En8TGLv6g7tjczfxPSLoEL0udUIMF4J1TDP 5JY4D3dW2fTS06bqH5aP9P9dFNVVjmRcqJ9gQvLv5MNcxhHbQtBkeQH4pifEmBjXHYyD BupnaHHtzun57zpVhRI2Ljc6rdr0sF5JvxbPoextOjCLCy/4nUCDDPMh3ZSXLGHQbKRM UPzZ+cnev6KN7pITTC034xq8AEsrAhchJuV7hdDRgPpsHb0EtbtWb9V/n/bRIl6Xnjq1 eF7e/cdRp7e6iFkGpEw7jVTuIGtJP4FYIXCu5j2Cj0eI1f5cxyfEmgTq5py7Bo3JJErk X6pw== X-Gm-Message-State: AOJu0Yx6zYGxod/v0/9I5pTx4GewVMAKqctQNT/Du2qDgKirduuW0dug DzYzHlT6hzi9g+0JUCBlvG0ZjRpoa+obM8ybo5vTPADWttzG/uhKpokBQoA+NZO+d2KW+QWJiym B X-Google-Smtp-Source: AGHT+IG+WpDxktDwhDeAB7ZoaSFd8qPxhHZHMtpY9pSMS0NDmTy9YHm3YWJCoEIAfidwgw3P3C9cOg== X-Received: by 2002:adf:fa88:0:b0:37c:cce6:997d with SMTP id ffacd0b85a97d-37cd5a8c952mr11781297f8f.20.1727700513641; Mon, 30 Sep 2024 05:48:33 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Thomas Huth , Paolo Bonzini , qemu-riscv@nongnu.org, Liu Zhiwei , Alistair Francis , Daniel Henrique Barboza , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Anton Johansson , Palmer Dabbelt , Bin Meng , Weiwei Li , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH] hw/riscv/spike: Replace tswap64() by ldq_endian_p() Date: Mon, 30 Sep 2024 14:48:31 +0200 Message-ID: <20240930124831.54232-1-philmd@linaro.org> X-Mailer: git-send-email 2.45.2 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::42d; envelope-from=philmd@linaro.org; helo=mail-wr1-x42d.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: 1727700603847116600 Hold the target endianness in HTIFState::target_is_bigendian. Pass the target endianness as argument to htif_mm_init(). Replace tswap64() calls by ldq_endian_p() ones. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- Based-on: <20240930073450.33195-2-philmd@linaro.org> "qemu/bswap: Introduce ld/st_endian_p() API" Note: this is a non-QOM device! --- include/hw/char/riscv_htif.h | 4 +++- hw/char/riscv_htif.c | 17 +++++++++++------ hw/riscv/spike.c | 2 +- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/include/hw/char/riscv_htif.h b/include/hw/char/riscv_htif.h index df493fdf6b..24868ddfe1 100644 --- a/include/hw/char/riscv_htif.h +++ b/include/hw/char/riscv_htif.h @@ -35,6 +35,7 @@ typedef struct HTIFState { hwaddr tohost_offset; hwaddr fromhost_offset; MemoryRegion mmio; + bool target_is_bigendian; =20 CharBackend chr; uint64_t pending_read; @@ -49,6 +50,7 @@ void htif_symbol_callback(const char *st_name, int st_inf= o, uint64_t st_value, =20 /* legacy pre qom */ HTIFState *htif_mm_init(MemoryRegion *address_space, Chardev *chr, - uint64_t nonelf_base, bool custom_base); + uint64_t nonelf_base, bool custom_base, + bool target_is_bigendian); =20 #endif diff --git a/hw/char/riscv_htif.c b/hw/char/riscv_htif.c index 9bef60def1..77951f3c76 100644 --- a/hw/char/riscv_htif.c +++ b/hw/char/riscv_htif.c @@ -30,7 +30,6 @@ #include "qemu/timer.h" #include "qemu/error-report.h" #include "exec/address-spaces.h" -#include "exec/tswap.h" #include "sysemu/dma.h" #include "sysemu/runstate.h" =20 @@ -211,13 +210,17 @@ static void htif_handle_tohost_write(HTIFState *s, ui= nt64_t val_written) SHUTDOWN_CAUSE_GUEST_SHUTDOWN, exit_code); return; } else { + bool be =3D s->target_is_bigendian; uint64_t syscall[8]; + cpu_physical_memory_read(payload, syscall, sizeof(syscall)= ); - if (tswap64(syscall[0]) =3D=3D PK_SYS_WRITE && - tswap64(syscall[1]) =3D=3D HTIF_DEV_CONSOLE && - tswap64(syscall[3]) =3D=3D HTIF_CONSOLE_CMD_PUTC) { + if (ldq_endian_p(be, &syscall[0]) =3D=3D PK_SYS_WRITE && + ldq_endian_p(be, &syscall[1]) =3D=3D HTIF_DEV_CONSOLE = && + ldq_endian_p(be, &syscall[3]) =3D=3D HTIF_CONSOLE_CMD_= PUTC) { uint8_t ch; - cpu_physical_memory_read(tswap64(syscall[2]), &ch, 1); + + cpu_physical_memory_read(ldl_endian_p(be, &syscall[2]), + &ch, 1); qemu_chr_fe_write(&s->chr, &ch, 1); resp =3D 0x100 | (uint8_t)payload; } else { @@ -320,7 +323,8 @@ static const MemoryRegionOps htif_mm_ops =3D { }; =20 HTIFState *htif_mm_init(MemoryRegion *address_space, Chardev *chr, - uint64_t nonelf_base, bool custom_base) + uint64_t nonelf_base, bool custom_base, + bool target_is_bigendian) { uint64_t base, size, tohost_offset, fromhost_offset; =20 @@ -345,6 +349,7 @@ HTIFState *htif_mm_init(MemoryRegion *address_space, Ch= ardev *chr, s->pending_read =3D 0; s->allow_tohost =3D 0; s->fromhost_inprogress =3D 0; + s->target_is_bigendian =3D target_is_bigendian; qemu_chr_fe_init(&s->chr, chr, &error_abort); qemu_chr_fe_set_handlers(&s->chr, htif_can_recv, htif_recv, htif_event, htif_be_change, s, NULL, true); diff --git a/hw/riscv/spike.c b/hw/riscv/spike.c index 64074395bc..0989cd4a41 100644 --- a/hw/riscv/spike.c +++ b/hw/riscv/spike.c @@ -327,7 +327,7 @@ static void spike_board_init(MachineState *machine) =20 /* initialize HTIF using symbols found in load_kernel */ htif_mm_init(system_memory, serial_hd(0), memmap[SPIKE_HTIF].base, - htif_custom_base); + htif_custom_base, TARGET_BIG_ENDIAN); } =20 static void spike_set_signature(Object *obj, const char *val, Error **errp) --=20 2.45.2