From patchwork Thu Feb 6 13:10:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13963010 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C049EC02196 for ; Thu, 6 Feb 2025 13:13:27 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tg1f7-00052p-9R; Thu, 06 Feb 2025 08:11:21 -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 1tg1ez-00050h-Ms for qemu-devel@nongnu.org; Thu, 06 Feb 2025 08:11:13 -0500 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tg1ex-00082Q-Cv for qemu-devel@nongnu.org; Thu, 06 Feb 2025 08:11:13 -0500 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-436345cc17bso6243505e9.0 for ; Thu, 06 Feb 2025 05:11:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1738847469; x=1739452269; 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=4hjV9qje+F9WM+1u7JaIIDgc7g6v/WUaxTXGCOTYvnI=; b=vDFtTl9cLjF3W12hmvrpTXgy6i1fKQSUh5Ac69JywwRisbOPuaGp9A2EL6BiQq1lJL 3Ciz8mU/14SBo53ZEgSEkBTHs0A8wv4S6x6TE1bA7NiEK+UMXmkQDma2QcAFj9qKYjP+ YzxoEmgwksulXEws4tfnvz+ZpCjiSiQWX3xWK2SfRRW/eqiKSHHoQntEW1fCydR+cNqi BJwS8ErSEd3PVhFC6BmK/4PuGUI/Wy+DVl2ZdpKOA2QZFAHln85/V0+yVSF6u99QtYta oZiGbiJXK74UX3IqPd3qXJKKUB5so3OjVphMOozfjCYatHqq3fjFREP/eywabVW3tXQ4 kuew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738847469; x=1739452269; 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=4hjV9qje+F9WM+1u7JaIIDgc7g6v/WUaxTXGCOTYvnI=; b=NjsPgwfnC3x8sK3VjAqssvc6X4Re2q2XUh8m5gCN6frO1oCceOwtt03Er7nqfH1iBj qphmD/LWA0uj9jXWyrRiEJOM3NwpPR4Uw9sDJROWaGiDRssx8eoVgmN66w9HPXR+MXgy /rDAUAuKc3J8itj4qMQmbAIHOixwwiZ8Xd/SJYaLG/Knq30QpytAdU/OM/wdVqEj59vP 28NJS8e5w+gnDoJitDnishJYiObuojDmmVWpZ3gGikzoffunh/kvz50ImmqMk5u+QWEI bHjF5bKAB2KoETY6e0BlLNP80BNAzaxxNt+IBkKkuNscFYW2+PuM/5Uo50hzYpmjG8QS wWyQ== X-Gm-Message-State: AOJu0Yyizam/yWE2NLHnmjArlIw2eBks64o+5SXOsyUOGWjJpGaVx0LN FQTHHMTMk2V0jjZVfYkBp8zV3ccpMblGMK34ZemEzXhaIFIism4Oe5UJY+qkpumfUO24j4u8qm/ snRY= X-Gm-Gg: ASbGnctWd/MjQBdGQOadUyV6iChirXN+d4S5Dt9rq+sinIchameYjARcO/6a650nNI6 fyTfL3FO0QhKVJ5SlXlohPI3P3oYLbIvwG9r00NQcCKppSZNi8rprB+HBXYW/NtihCvLlnj4bL0 kfG305uUXnJML+CxeywyDxYBHmX28Viw8J3L0R68ft/V0r4mq3JlXm7ogsaHR5LgEg9e0TenCbb slgKUC2AVsQbw9KhU4fGc1ujWx/gsiSs89aa+72iMvDF15Ml0i2h/2JWmJ8YLgVRw9VE5cPRRDQ 8jc/Af/EW/v9DJgkyuJPbfKCqlwYA6fEDzO2qk1+ayfQiG3JGn/SGRi5GU8Q5QMANg== X-Google-Smtp-Source: AGHT+IG5KuMThKcuLm7hcVGyYyQeWEVmIbCY6VWXFvAfGUxfab70FuaUwn7dHCHbtG0ugxXJQ+e+8g== X-Received: by 2002:a05:600c:512a:b0:434:f3a1:b214 with SMTP id 5b1f17b1804b1-4390d56cd58mr50851855e9.28.1738847469434; Thu, 06 Feb 2025 05:11:09 -0800 (PST) Received: from localhost.localdomain (88-187-86-199.subs.proxad.net. [88.187.86.199]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38dc5839877sm254030f8f.3.2025.02.06.05.11.08 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 06 Feb 2025 05:11:08 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Anton Johansson , Jason Wang , Paolo Bonzini , Alistair Francis , Thomas Huth , Richard Henderson , Peter Maydell , "Edgar E. Iglesias" , =?utf-8?q?Philippe_Mathieu-?= =?utf-8?q?Daud=C3=A9?= Subject: [PATCH v5 03/16] hw/timer/xilinx_timer: Make device endianness configurable Date: Thu, 6 Feb 2025 14:10:39 +0100 Message-ID: <20250206131052.30207-4-philmd@linaro.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250206131052.30207-1-philmd@linaro.org> References: <20250206131052.30207-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32d; envelope-from=philmd@linaro.org; helo=mail-wm1-x32d.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=unavailable 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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 for each machine using the device. Reviewed-by: Richard Henderson Signed-off-by: Philippe Mathieu-Daudé --- hw/microblaze/petalogix_ml605_mmu.c | 1 + hw/microblaze/petalogix_s3adsp1800_mmu.c | 1 + hw/ppc/virtex_ml507.c | 1 + hw/timer/xilinx_timer.c | 35 +++++++++++++++--------- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/hw/microblaze/petalogix_ml605_mmu.c b/hw/microblaze/petalogix_ml605_mmu.c index cf3b9574db3..bbda70aa93b 100644 --- a/hw/microblaze/petalogix_ml605_mmu.c +++ b/hw/microblaze/petalogix_ml605_mmu.c @@ -127,6 +127,7 @@ petalogix_ml605_init(MachineState *machine) /* 2 timers at irq 2 @ 100 Mhz. */ dev = qdev_new("xlnx.xps-timer"); + qdev_prop_set_bit(dev, "little-endian", true); qdev_prop_set_uint32(dev, "one-timer-only", 0); qdev_prop_set_uint32(dev, "clock-frequency", 100 * 1000000); sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); diff --git a/hw/microblaze/petalogix_s3adsp1800_mmu.c b/hw/microblaze/petalogix_s3adsp1800_mmu.c index fbf52ba8f2f..9d4316b4036 100644 --- a/hw/microblaze/petalogix_s3adsp1800_mmu.c +++ b/hw/microblaze/petalogix_s3adsp1800_mmu.c @@ -114,6 +114,7 @@ petalogix_s3adsp1800_init(MachineState *machine) /* 2 timers at irq 2 @ 62 Mhz. */ dev = qdev_new("xlnx.xps-timer"); + qdev_prop_set_bit(dev, "little-endian", !TARGET_BIG_ENDIAN); qdev_prop_set_uint32(dev, "one-timer-only", 0); qdev_prop_set_uint32(dev, "clock-frequency", 62 * 1000000); sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); diff --git a/hw/ppc/virtex_ml507.c b/hw/ppc/virtex_ml507.c index 23238119273..f87c221d076 100644 --- a/hw/ppc/virtex_ml507.c +++ b/hw/ppc/virtex_ml507.c @@ -230,6 +230,7 @@ static void virtex_init(MachineState *machine) /* 2 timers at irq 2 @ 62 Mhz. */ dev = qdev_new("xlnx.xps-timer"); + qdev_prop_set_bit(dev, "little-endian", false); qdev_prop_set_uint32(dev, "one-timer-only", 0); qdev_prop_set_uint32(dev, "clock-frequency", 62 * 1000000); sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); diff --git a/hw/timer/xilinx_timer.c b/hw/timer/xilinx_timer.c index 6595cf5f517..d942ac226e6 100644 --- a/hw/timer/xilinx_timer.c +++ b/hw/timer/xilinx_timer.c @@ -3,6 +3,9 @@ * * Copyright (c) 2009 Edgar E. Iglesias. * + * DS573: https://docs.amd.com/v/u/en-US/xps_timer + * LogiCORE IP XPS Timer/Counter (v1.02a) + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights @@ -69,6 +72,7 @@ struct XpsTimerState { SysBusDevice parent_obj; + bool little_endian_model; MemoryRegion mmio; qemu_irq irq; uint8_t one_timer_only; @@ -189,18 +193,21 @@ timer_write(void *opaque, hwaddr addr, timer_update_irq(t); } -static const MemoryRegionOps timer_ops = { - .read = timer_read, - .write = timer_write, - .endianness = DEVICE_NATIVE_ENDIAN, - .impl = { - .min_access_size = 4, - .max_access_size = 4, +static const MemoryRegionOps timer_ops[2] = { + [0 ... 1] = { + .read = timer_read, + .write = timer_write, + .impl = { + .min_access_size = 4, + .max_access_size = 4, + }, + .valid = { + .min_access_size = 4, + .max_access_size = 4, + }, }, - .valid = { - .min_access_size = 4, - .max_access_size = 4 - } + [0].endianness = DEVICE_BIG_ENDIAN, + [1].endianness = DEVICE_LITTLE_ENDIAN, }; static void timer_hit(void *opaque) @@ -233,8 +240,9 @@ static void xilinx_timer_realize(DeviceState *dev, Error **errp) ptimer_transaction_commit(xt->ptimer); } - memory_region_init_io(&t->mmio, OBJECT(t), &timer_ops, t, "xlnx.xps-timer", - R_MAX * 4 * num_timers(t)); + memory_region_init_io(&t->mmio, OBJECT(t), + &timer_ops[t->little_endian_model], t, + "xlnx.xps-timer", R_MAX * 4 * num_timers(t)); sysbus_init_mmio(SYS_BUS_DEVICE(dev), &t->mmio); } @@ -247,6 +255,7 @@ static void xilinx_timer_init(Object *obj) } static const Property xilinx_timer_properties[] = { + DEFINE_PROP_BOOL("little-endian", XpsTimerState, little_endian_model, true), DEFINE_PROP_UINT32("clock-frequency", XpsTimerState, freq_hz, 62 * 1000000), DEFINE_PROP_UINT8("one-timer-only", XpsTimerState, one_timer_only, 0), };