From patchwork Sun Feb 16 21:00:56 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: 865554 Delivered-To: patch@linaro.org Received: by 2002:a5d:64e6:0:b0:38f:210b:807b with SMTP id g6csp829400wri; Sun, 16 Feb 2025 13:03:22 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWN1VQxoz6BNwN+Q/9ZNA44qBuejUbtfSScMTiZsbx7qPBI/YAt1nTuT6bkjLM/Elb7PVUtew==@linaro.org X-Google-Smtp-Source: AGHT+IEQXqNISyxj5oI6F79VKn6PJegmzovG2FGPAfmROE96xBLhsflIUhfbcU1zCGd+TDmY/Y79 X-Received: by 2002:a05:622a:c6:b0:46f:d928:2db6 with SMTP id d75a77b69052e-471c011264amr207919971cf.7.1739739801986; Sun, 16 Feb 2025 13:03:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1739739801; cv=none; d=google.com; s=arc-20240605; b=bqPeLbcwqQUPrU9L7hTqlFI3/L/mkRjiQhhmXIw4l7y9QW4uLqOo2ZoPiIjX56r/RE Wi6ZI9t0DcMzphQWsm1b6wOJrg1QQrSLbYAXOgvPLY62vmYHLvhXcncHuyG+Pb4Ey0e0 e/LmlBlur+ResWimTYOl3U7WJZS4ZDU1DbX/+Xdibqbgpy+OlSlpoHscrrCFKQDSQm7r TgK59PHQMuWIGjGMkZxRAPeRJCBsMty7eGPBMiIbeEyc0ESDBBZuCB/vQjeg90V4Jj+z pd3EhOj1kvPCbuNPygFIm+sl759f/EX+VpyH3BSa+KHSeoUjH78gJ4B/3Y+D/cRo9KEb gCXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=e4BWG0UyJBMGuNS/Yd69+AKuKZVB4ktl8qLDFtIcsAU=; fh=PGfEOx04XnvL/8Nun0MfKnWqAt99bm+Sh5MxcMxSB00=; b=RePtoz178rYXixzGzuvacOHXj/vC0nyDUrzsGY/1blLMK8XwN81KcHZVu5UekmzmB2 oQcnRk8m9vr3Vmg/h4D2izGLovZaNKdMe/uTI3pPtKYQYNqpm4pdnrQlVPAg3vYb0i5/ IKXs0YoJySaqbYmRLKBDOHWXoGGZU7srY5wnq5akGMGt/TLoPzJqkXIoNEX78k4lxJZ6 ucMTdd2KxAZdeKnOTHC8dojQimCsur4vFrQBcWaomZf14v481+iMKOTvYFIo+i8/lCsK OMGVI5z4pPWjOTIT5cZYG1wWUMJpjERtHIk69W3+qSbNL2wkeqf8UHwwtZkuie17nEu9 MlJQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=r6md0mql; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-471f20851b9si5576891cf.268.2025.02.16.13.03.21 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 16 Feb 2025 13:03:21 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=r6md0mql; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tjlln-0002zq-KU; Sun, 16 Feb 2025 16:01:43 -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 1tjlla-0002yB-Ft for qemu-devel@nongnu.org; Sun, 16 Feb 2025 16:01:39 -0500 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tjllX-0007uw-Mk for qemu-devel@nongnu.org; Sun, 16 Feb 2025 16:01:29 -0500 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-43963935585so36581005e9.0 for ; Sun, 16 Feb 2025 13:01:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1739739685; x=1740344485; 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=e4BWG0UyJBMGuNS/Yd69+AKuKZVB4ktl8qLDFtIcsAU=; b=r6md0mqlP3aLLP9jSi6zD3jaj7rlcWdFWNcdI7mvP+RVyzBldhsNxVTkWJOkE1zj/7 pl8F6n4x0n1avFOr+QILBgj56mtsE4qDfbvSlUrmFurdxfEufLgU2JdhqL8VgWJANjOy 7Zzzqn8IYJLk1ss9a8gmPFnTc4OkFOuSuTKcxwjR21EGx4d2KHaitsHuaJkl6kcuqq9y X3s7seri0w98UlA81IsRXrSE0Bmt+8u/HLmjwUV/RAEegCA2CdXxqphieGEUfZayzyZZ PWcZQDYHC82WXNVV6EGAZ/Gl5UTM85sDuIl8iWmfBoZlyl8EumFBAcus3HANw71diMcv fdTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739739685; x=1740344485; 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=e4BWG0UyJBMGuNS/Yd69+AKuKZVB4ktl8qLDFtIcsAU=; b=ivGzhcd1YtVjBgnu8q1K7pWPYXNqqwXDRSKn6zoULmN7kHxVUTaolEtIuMjNry0b5/ S4AsknqxHTHFr5pRSaOYk6Mj6YIzlsRk0orDSORYWS0sO6D/zJgkH4ILRz+nOOTC3kO8 QoLN0dwxg6zSLwZK7bsFYmHovfig9j2ygh58TyNeSB2Tlp56rCPGTL7YIlQJ6aBb30uM pHK/q9oJKj2axW+COgVhmzcIu1kwjhGAMyEz8zZ2QnQpgnWX7c9cqitPlszN18hVcEex 9+IMTOYhOBKaWySckKjLDO3JRUrKKxtpTr3M9aGP6Som2P+QwArwyHok6eKiitOnm757 SWLg== X-Gm-Message-State: AOJu0Yw2On7KWBXkceJwWGKtxnS1I3bXCQ3SfKcpmJR3kuN0tz8NjRSK Ux7GGs6VwlyCIh1GVFlcj0BjkMc57xus5P6+C8bYUv7LROEUcK2mWlWausMtwRGvWYgChJ8I2BR xAy4= X-Gm-Gg: ASbGncs6y5h6yGAaIPrkpJE2ECsWQPV56uG6en94pH2eN950tSAuUnOyFm5zdPK9hwA K9bn+vMzg0KukrylLfti+GZtLpMu9ty5mc55pk+WCoHtiKDS8JLg2lEtFqR2M+yhHPe4az3EcFE 4nJ0VmfSTIxjj/c5l68BaTLWcQpG3kcrVH+AcV0s8ynMFGFf7ioTdr300b+RbU2lFtyFzAvcW9u 3UyO9AQoT70fBQTiwulNYFFHpBwoAljMFgHE9CeG/QeTx1TJJykLnGSlNvT0R44BOlSqTFRWUkv hEUPCPGvxSEErMcRNi71FHNTYNFApmFgtzWSilB0D1Rev/DLn2bBv4/15h9EMTJABqTY3oU= X-Received: by 2002:a05:6000:188c:b0:38d:c557:1147 with SMTP id ffacd0b85a97d-38f33f4e5bbmr7555699f8f.51.1739739685581; Sun, 16 Feb 2025 13:01:25 -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-38f25915688sm10599309f8f.57.2025.02.16.13.01.23 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 16 Feb 2025 13:01:24 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Thomas Huth , Richard Henderson Subject: [PULL 32/39] hw/timer/xilinx_timer: Make device endianness configurable Date: Sun, 16 Feb 2025 22:00:56 +0100 Message-ID: <20250216210103.70235-5-philmd@linaro.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250216210103.70235-1-philmd@linaro.org> References: <20250216210103.70235-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::330; envelope-from=philmd@linaro.org; helo=mail-wm1-x330.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Replace the DEVICE_NATIVE_ENDIAN MemoryRegionOps by a pair of DEVICE_LITTLE_ENDIAN / DEVICE_BIG_ENDIAN. Add the "endianness" property to select the device endianness. This property is unspecified by default, and machines need to set it explicitly. Set the proper endianness for each machine using the device. Reviewed-by: Thomas Huth Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson Message-Id: <20250213122217.62654-5-philmd@linaro.org> --- hw/microblaze/petalogix_ml605_mmu.c | 1 + hw/microblaze/petalogix_s3adsp1800_mmu.c | 1 + hw/ppc/virtex_ml507.c | 1 + hw/riscv/microblaze-v-generic.c | 2 ++ hw/timer/xilinx_timer.c | 43 +++++++++++++++++------- 5 files changed, 35 insertions(+), 13 deletions(-) diff --git a/hw/microblaze/petalogix_ml605_mmu.c b/hw/microblaze/petalogix_ml605_mmu.c index a876aeb0bba..984287fdc53 100644 --- a/hw/microblaze/petalogix_ml605_mmu.c +++ b/hw/microblaze/petalogix_ml605_mmu.c @@ -129,6 +129,7 @@ petalogix_ml605_init(MachineState *machine) /* 2 timers at irq 2 @ 100 Mhz. */ dev = qdev_new("xlnx.xps-timer"); + qdev_prop_set_enum(dev, "endianness", endianness); 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 d419dc49a25..caaea222a8c 100644 --- a/hw/microblaze/petalogix_s3adsp1800_mmu.c +++ b/hw/microblaze/petalogix_s3adsp1800_mmu.c @@ -116,6 +116,7 @@ petalogix_s3adsp1800_init(MachineState *machine) /* 2 timers at irq 2 @ 62 Mhz. */ dev = qdev_new("xlnx.xps-timer"); + qdev_prop_set_enum(dev, "endianness", endianness); 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 df8f9644829..a01354d991d 100644 --- a/hw/ppc/virtex_ml507.c +++ b/hw/ppc/virtex_ml507.c @@ -231,6 +231,7 @@ static void virtex_init(MachineState *machine) /* 2 timers at irq 2 @ 62 Mhz. */ dev = qdev_new("xlnx.xps-timer"); + qdev_prop_set_enum(dev, "endianness", ENDIAN_MODE_BIG); 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/riscv/microblaze-v-generic.c b/hw/riscv/microblaze-v-generic.c index a21fdfbe6db..3c79f5733b2 100644 --- a/hw/riscv/microblaze-v-generic.c +++ b/hw/riscv/microblaze-v-generic.c @@ -104,6 +104,7 @@ static void mb_v_generic_init(MachineState *machine) /* 2 timers at irq 0 @ 100 Mhz. */ dev = qdev_new("xlnx.xps-timer"); + qdev_prop_set_enum(dev, "endianness", ENDIAN_MODE_LITTLE); qdev_prop_set_uint32(dev, "one-timer-only", 0); qdev_prop_set_uint32(dev, "clock-frequency", 100000000); sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); @@ -112,6 +113,7 @@ static void mb_v_generic_init(MachineState *machine) /* 2 timers at irq 3 @ 100 Mhz. */ dev = qdev_new("xlnx.xps-timer"); + qdev_prop_set_enum(dev, "endianness", ENDIAN_MODE_LITTLE); qdev_prop_set_uint32(dev, "one-timer-only", 0); qdev_prop_set_uint32(dev, "clock-frequency", 100000000); 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..4620528f985 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 @@ -23,10 +26,12 @@ */ #include "qemu/osdep.h" +#include "qapi/error.h" #include "hw/sysbus.h" #include "hw/irq.h" #include "hw/ptimer.h" #include "hw/qdev-properties.h" +#include "hw/qdev-properties-system.h" #include "qemu/log.h" #include "qemu/module.h" #include "qom/object.h" @@ -69,6 +74,7 @@ struct XpsTimerState { SysBusDevice parent_obj; + EndianMode model_endianness; MemoryRegion mmio; qemu_irq irq; uint8_t one_timer_only; @@ -189,18 +195,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_LITTLE_ENDIAN, + [1].endianness = DEVICE_BIG_ENDIAN, }; static void timer_hit(void *opaque) @@ -220,6 +229,12 @@ static void xilinx_timer_realize(DeviceState *dev, Error **errp) XpsTimerState *t = XILINX_TIMER(dev); unsigned int i; + if (t->model_endianness == ENDIAN_MODE_UNSPECIFIED) { + error_setg(errp, TYPE_XILINX_TIMER " property 'endianness'" + " must be set to 'big' or 'little'"); + return; + } + /* Init all the ptimers. */ t->timers = g_malloc0(sizeof t->timers[0] * num_timers(t)); for (i = 0; i < num_timers(t); i++) { @@ -233,8 +248,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->model_endianness == ENDIAN_MODE_BIG], + t, "xlnx.xps-timer", R_MAX * 4 * num_timers(t)); sysbus_init_mmio(SYS_BUS_DEVICE(dev), &t->mmio); } @@ -247,6 +263,7 @@ static void xilinx_timer_init(Object *obj) } static const Property xilinx_timer_properties[] = { + DEFINE_PROP_ENDIAN_NODEFAULT("endianness", XpsTimerState, model_endianness), DEFINE_PROP_UINT32("clock-frequency", XpsTimerState, freq_hz, 62 * 1000000), DEFINE_PROP_UINT8("one-timer-only", XpsTimerState, one_timer_only, 0), };