From patchwork Sun Feb 16 21:00:57 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: 865557 Delivered-To: patch@linaro.org Received: by 2002:a5d:64e6:0:b0:38f:210b:807b with SMTP id g6csp829491wri; Sun, 16 Feb 2025 13:03:37 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUvxYw6SWLi800xiecHBJObyrEDE7D4aIhaLq7UBjLgvizkW665eD0LzDWxcV9eSzIqYFsmOg==@linaro.org X-Google-Smtp-Source: AGHT+IEnxEt5q5wHmTHo4SLDdcbE6RxFHYHt5q5bnaPCrrn6nLb9m1kqMrCBPO+ahdmRftmkEAIH X-Received: by 2002:ac8:7e8f:0:b0:471:9bf6:a941 with SMTP id d75a77b69052e-471dbd07eb7mr107433021cf.14.1739739817217; Sun, 16 Feb 2025 13:03:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1739739817; cv=none; d=google.com; s=arc-20240605; b=N8yd3P4XcxIbnkIjTs+XX9VVXqbK3YylskfWbziKaK8i9TtbitPoi8/W0LX5yMpzAf 6i+5kKSw/SaZdAAq3IQu05E4dO9/gkiCMstfeuF2gDQwV8N1iApisoj0JwJBfJNsxDuR cJ2aw8lWWeXAGv9KqWWq14exYVvq//bsJP9YDjgTWlrTPzCz74rClXquGXao4RYWxjdW SVwerG9urFhYCVaJ+JnFQlKvY3FXlixmKySWsCI5ELdU2NQVA8kMlS6uOg0IGtpc5Hv/ UeG66FpZJ1Y1fq4xuuudV608aYM2uwi+7zqbqrbsTA/ioAyhkVdBSDstxwZHc5AXPg9O xlQw== 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=vcyVI0kPFXhH981sg+d29nPiWvZ9LL1zDe7HaHRgPOQ=; fh=PGfEOx04XnvL/8Nun0MfKnWqAt99bm+Sh5MxcMxSB00=; b=Mwnu0Bji+J1ZI78GIsc66fb8ucf5yVGFjrzwGm1NAJ4TRfryderulj9oef//Qri8UY wZl9CqdV6xm1zwM4OhkVvhstswCxhcdrV3zhmeTmake2uSpalW33J5f3hoLA0UqzzF27 4R55/14Zn4ZW+J8UCYkn1Y4S79XpUZNLER5cc5Eueltr2yDabYakC5PtNq7NRRXnztKy sQyCkn1iQK8l8HXAx2qY8wxGGx1VSWCICmZM1jd868w7+8LDoQCo0GKRtdDRH/yNgyGL 8VBcCnM0TYM6orCU9eTNqysQ9+TnTMmeOGNMxbdgF5DZlqCPqqLLIsL0ge8opFo9+HsQ 6cng==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wmXjjD6I; 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-471ef29c821si10365341cf.269.2025.02.16.13.03.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 16 Feb 2025 13:03:37 -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=wmXjjD6I; 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 1tjllp-000307-Uu; Sun, 16 Feb 2025 16:01:45 -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 1tjllg-0002yW-F4 for qemu-devel@nongnu.org; Sun, 16 Feb 2025 16:01:39 -0500 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tjllc-0007vB-CR for qemu-devel@nongnu.org; Sun, 16 Feb 2025 16:01:35 -0500 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-4396a4d5e3bso21810905e9.3 for ; Sun, 16 Feb 2025 13:01:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1739739690; x=1740344490; 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=vcyVI0kPFXhH981sg+d29nPiWvZ9LL1zDe7HaHRgPOQ=; b=wmXjjD6I3wCUhgRib1v1ewxQrQMxh9AOtG4m+ZoQOqOrATKTBXdIDYVdWTwhIQlYNa ylLT+5luSRxd+XKDPljujUNoK2YJ9hv6LmixozpJbuWKzbPyltxZ1Zzzt3ZiOzr6B9rX ybiC9T3h7eAP6i511//mzyZMcyuJx2joKN8mVMO6rqVWYqa4iw5YOpAud7h6uhxNQNyZ XnjahJLeMouIiLA4Phnu+oLSKeDLM27MvexDa2z+skV39isRrMG3hXq4b1bxiNW4QU3A n6Y7qscwGeO3QeNKwjS1ZAulIF9IjBZNigIcIYAYg+xkMmt5b9os9yq2KX3jAL/HpxnD 9PsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739739690; x=1740344490; 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=vcyVI0kPFXhH981sg+d29nPiWvZ9LL1zDe7HaHRgPOQ=; b=V/WA8GztHRFe9BlZgMSP42cy87qDchkHB5YY1vVG3q+ImOBAAXBU8fxbqZM88thTjV CUEOwCPDt5oo+llP2+TpkukbGcStLCeYRYnJ4Aitpn6f1F2FbqB+zpypM/aPSJMHQl3d H7S2ck7VVnx+gxvXnbDFmOIHHlkTaYthlYM1qgFjuSal9E9fl/BwIM1SCFpCSlNMoFeA EMlpVqkXi/pYXXgYWLzpyF15cMe4MxfDY3XDFTwxBqZdKl9iOs/DskWabH4ygqjXM2jt rkaPT9RElcTnxEoz9NomHTvmeSItMak9eiYuLCtor1onp+SzyctVjYOrOOnZGbS9GdbX sJrg== X-Gm-Message-State: AOJu0YyAAjpr7DJA+s41t12A1Nh1oHu2QquJNTi3PUvTvwbXBpkxnM6a OpYdE1PjXloiNeWGLJPkUOov3bMXqBR35njbmhraMMJgt7fLZEBHOlvf9rsDks+UiWJA046v5qj 23A0= X-Gm-Gg: ASbGncua1lQTWZGs3UctBE5hI+ULQVdYLmcYWYRJ74UcJwz7z7qZW/t7iNfb7IvX0YZ 1kU+7DzmS9vwnFIhBAOGSw2BvrMVEC1SBd/TF+G0rOq/DW6f6jyo9D7rJFWxYw1qXimBePxiUVN I6spVrzbWWWefgpPHGwyoSFBIB6gZ6c1ymjeaAak483eWJhX0rPKYpk8Xv3y1AfvjJvaBKVGt4G suzbCrB9BPerL2Jq0+MLzmtcfPR4d44CBFLBaNN4Ck2z2hvmfy3X2w+g9EJeY7IPFNlRHmKfU8b p6AKIPxxlJn2z+cRXUZrriOuEieyIHyMLHU5R1Az6UqEx2pkag179klKMRtnxf7GyvzyrFw= X-Received: by 2002:a05:600c:310e:b0:439:57bb:2aa with SMTP id 5b1f17b1804b1-4396e6aa7d3mr84051405e9.11.1739739690378; Sun, 16 Feb 2025 13:01:30 -0800 (PST) Received: from localhost.localdomain (88-187-86-199.subs.proxad.net. [88.187.86.199]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43961884e88sm101602185e9.26.2025.02.16.13.01.29 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 16 Feb 2025 13:01:29 -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 33/39] hw/char/xilinx_uartlite: Make device endianness configurable Date: Sun, 16 Feb 2025 22:00:57 +0100 Message-ID: <20250216210103.70235-6-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::32e; envelope-from=philmd@linaro.org; helo=mail-wm1-x32e.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. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Thomas Huth Reviewed-by: Richard Henderson Message-Id: <20250213122217.62654-6-philmd@linaro.org> --- hw/char/xilinx_uartlite.c | 34 ++++++++++++++++-------- hw/microblaze/petalogix_s3adsp1800_mmu.c | 1 + hw/riscv/microblaze-v-generic.c | 1 + 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/hw/char/xilinx_uartlite.c b/hw/char/xilinx_uartlite.c index 56955e0d74a..4037c937eeb 100644 --- a/hw/char/xilinx_uartlite.c +++ b/hw/char/xilinx_uartlite.c @@ -24,6 +24,7 @@ #include "qemu/osdep.h" #include "qemu/log.h" +#include "qapi/error.h" #include "hw/char/xilinx_uartlite.h" #include "hw/irq.h" #include "hw/qdev-properties.h" @@ -57,6 +58,7 @@ struct XilinxUARTLite { SysBusDevice parent_obj; + EndianMode model_endianness; MemoryRegion mmio; CharBackend chr; qemu_irq irq; @@ -166,17 +168,21 @@ uart_write(void *opaque, hwaddr addr, uart_update_irq(s); } -static const MemoryRegionOps uart_ops = { - .read = uart_read, - .write = uart_write, - .endianness = DEVICE_NATIVE_ENDIAN, - .valid = { - .min_access_size = 1, - .max_access_size = 4 - } +static const MemoryRegionOps uart_ops[2] = { + [0 ... 1] = { + .read = uart_read, + .write = uart_write, + .valid = { + .min_access_size = 1, + .max_access_size = 4, + }, + }, + [0].endianness = DEVICE_LITTLE_ENDIAN, + [1].endianness = DEVICE_BIG_ENDIAN, }; static const Property xilinx_uartlite_properties[] = { + DEFINE_PROP_ENDIAN_NODEFAULT("endianness", XilinxUARTLite, model_endianness), DEFINE_PROP_CHR("chardev", XilinxUARTLite, chr), }; @@ -214,6 +220,15 @@ static void xilinx_uartlite_realize(DeviceState *dev, Error **errp) { XilinxUARTLite *s = XILINX_UARTLITE(dev); + if (s->model_endianness == ENDIAN_MODE_UNSPECIFIED) { + error_setg(errp, TYPE_XILINX_UARTLITE " property 'endianness'" + " must be set to 'big' or 'little'"); + return; + } + + memory_region_init_io(&s->mmio, OBJECT(dev), + &uart_ops[s->model_endianness == ENDIAN_MODE_BIG], + s, "xlnx.xps-uartlite", R_MAX * 4); qemu_chr_fe_set_handlers(&s->chr, uart_can_rx, uart_rx, uart_event, NULL, s, NULL, true); } @@ -223,9 +238,6 @@ static void xilinx_uartlite_init(Object *obj) XilinxUARTLite *s = XILINX_UARTLITE(obj); sysbus_init_irq(SYS_BUS_DEVICE(obj), &s->irq); - - memory_region_init_io(&s->mmio, obj, &uart_ops, s, - "xlnx.xps-uartlite", R_MAX * 4); sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->mmio); } diff --git a/hw/microblaze/petalogix_s3adsp1800_mmu.c b/hw/microblaze/petalogix_s3adsp1800_mmu.c index caaea222a8c..bdba2006b72 100644 --- a/hw/microblaze/petalogix_s3adsp1800_mmu.c +++ b/hw/microblaze/petalogix_s3adsp1800_mmu.c @@ -109,6 +109,7 @@ petalogix_s3adsp1800_init(MachineState *machine) } dev = qdev_new(TYPE_XILINX_UARTLITE); + qdev_prop_set_enum(dev, "endianness", endianness); qdev_prop_set_chr(dev, "chardev", serial_hd(0)); sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, UARTLITE_BASEADDR); diff --git a/hw/riscv/microblaze-v-generic.c b/hw/riscv/microblaze-v-generic.c index 3c79f5733b2..d8e67906d26 100644 --- a/hw/riscv/microblaze-v-generic.c +++ b/hw/riscv/microblaze-v-generic.c @@ -92,6 +92,7 @@ static void mb_v_generic_init(MachineState *machine) /* Uartlite */ dev = qdev_new(TYPE_XILINX_UARTLITE); + qdev_prop_set_enum(dev, "endianness", ENDIAN_MODE_LITTLE); qdev_prop_set_chr(dev, "chardev", serial_hd(0)); sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, UARTLITE_BASEADDR);