From patchwork Fri Jul 19 18:10:37 2024 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: 813419 Delivered-To: patch@linaro.org Received: by 2002:adf:f288:0:b0:367:895a:4699 with SMTP id k8csp878258wro; Fri, 19 Jul 2024 11:14:45 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCU+yj4NB2GuJ1rIndQiLHWea8gM83u4Z9iQ6C3kOcPnxH++AE9bQmLqekhd60gE1o0hTV6Hw8gI7Q2E6C5n41Mz X-Google-Smtp-Source: AGHT+IFBVPu+GLQe8ZNwyIs0B355+K4KzBk8wWU90Q1bICXGNyqYIm6/tDGHe1xeZqOjq7Jd34QB X-Received: by 2002:a05:622a:189d:b0:447:f323:28be with SMTP id d75a77b69052e-44fa5383becmr8200801cf.60.1721412885077; Fri, 19 Jul 2024 11:14:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721412885; cv=none; d=google.com; s=arc-20160816; b=L0BQvqCQPl3jx7QfY8WYu5leo+osGzRizdJaWp9KZPGWBEd2bui38bwzqvxJtkqn90 ndP0fICCIx5enN9CqKY8a87ryozcMwxoIvqYJmarmiX5cnmcemWcL7YLyiXNaTu8SrRa VFD4yH+9Dp4/vOiwfGEr/cly1ijxOwvPqve5KYgBE9P9i4ABvU4kbAqRTAD8rcvgy7l9 JfbLpCRwCL9URH4r6sl+H0ocbGtagpLae2IUo81EwN6AHprToqCSslpzn0jpGOM7cEER 37W7aZVKWPV2ut8VHr1Cub5sVhbTSiCfAyiOcIc9TBxz7qk6xYvybDJNJ7B4k6AqK6Dr xK5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; 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=Sc6hQLwehuuiEKoTJDdG/35Ecq31WpA7x5boBSd7PGs=; fh=a4LTsj9O+qaKvI8P1KF8P/8hcdvsQ8EHyfSuvL3yAcM=; b=srYA4ZxYXW+Ep4NHA6ynncRXfRX49CbjoS6WDW6bHzMxCnyiS/G1ps6xtMODui0biM N0mNm36ox7eLGBfLT824TyvEJaVy6EG1ZAYlDcasjbpxyNjmmDo8+wvempZutJLdJZow xBbOgsJAx9GmO4AoKYAnSB/8H2oUgv+ShASQpA9OpDGDUPX2xzMFQusQ2qu2qMPQoQQI Bo+IW5SE8EgLR5wK7YwRA+f/Is6/iTnn46j20sz3FFVcNxEVF2vIIWBKcwDiTJgCqsQy wm6/9Mr/JXPqEGKJzJ431oOJReNoPOKtm6YLIiXfeeBFRltV0RciJkgG3Zbld2vdn5Vv LNAw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="rhlE/7xW"; 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-44f9cdff389si20647761cf.579.2024.07.19.11.14.44 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 19 Jul 2024 11:14:45 -0700 (PDT) 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="rhlE/7xW"; 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 1sUs5u-0008Mk-3r; Fri, 19 Jul 2024 14:12:38 -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 1sUs5N-0005V1-9Y for qemu-devel@nongnu.org; Fri, 19 Jul 2024 14:12:06 -0400 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sUs5L-0003zG-C9 for qemu-devel@nongnu.org; Fri, 19 Jul 2024 14:12:04 -0400 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-427db004e36so251075e9.3 for ; Fri, 19 Jul 2024 11:12:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721412721; x=1722017521; 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=Sc6hQLwehuuiEKoTJDdG/35Ecq31WpA7x5boBSd7PGs=; b=rhlE/7xWSjDrR2tviEFUxz6yrqRC5LzHu+NNlP6cmptjtK8jvqEa5aQyehTzAWFmIr iLEpTaPEjC1iaf+OcTBO52I0mh4tAU6MUhWvGc0Jqer5thPLOnMrA6tDLyklraAAj8qD iGYVBa52tinFQwoHdL0cwW1+ro9Ojm0CeNWKbViN3cCHZSo2aNZUplfbXOYNXvAoi/RG LyZuJYEgV4CzJf2RZMTfLHSWmXl602/e2BYiFj5/CAn8+FPkO9vOhF4/P/qGnznB6MV6 7FozfmDPVB68b3+ywIqCza85bXK3gsSbuLxiqX522nA4n6mr/xa+bLIkCvSGzXRVmHXa gILg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721412721; x=1722017521; 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=Sc6hQLwehuuiEKoTJDdG/35Ecq31WpA7x5boBSd7PGs=; b=HZFkXk7ZAJ1SH4iiOE1LHhsWTkuNA/4YjMvCawYlM/e7B2ULY1BDx9K+4v6aCzifXy hdf5lXiWOllDpZUGvYZR1GxI3JCbC3iUAMlmjZO6tF3WluNqdQ3qMeK/4yTWzVjRAcm2 VgbGisJyRSuTIIlpApr8GmOczlSIl6lKyGSCvfV3Lr4XgFFkg0lUkgQW1eQdul51nQ8d /tRUnEXnOnDYrlYxKs9orYj7cGXiO6frm+rRIw0NPB/JMRwM1chmzUk3BcyXumfEWSsb BE0MYs/FUHzIYaAWplgHNq0movfqFwzszqAl1KbbCi4Z9obnwRxepeiZWMgui8btsRq1 /+6w== X-Gm-Message-State: AOJu0Yzw38kqTZD6VmcXJidi+lZ8sqjvgo8HXG2Nb9NQZOqbq3bdD45u 04JtalNSHDbr2XgZ0KL6jK2/3EsQKCD9nu4D6VkR3Q8ajkTXu0yvRME3VZYT6/9GMiNs4n8n3xZ 6 X-Received: by 2002:adf:e6c2:0:b0:367:97e7:879a with SMTP id ffacd0b85a97d-368317c0425mr6182998f8f.65.1721412721673; Fri, 19 Jul 2024 11:12:01 -0700 (PDT) Received: from localhost.localdomain (52.170.88.92.rev.sfr.net. [92.88.170.52]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36878684230sm2257427f8f.17.2024.07.19.11.11.59 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 19 Jul 2024 11:12:01 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-arm@nongnu.org, Mark Cave-Ayland , Tong Ho , Manos Pitsidianakis , Peter Maydell , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= Subject: [PATCH v5 12/16] hw/char/pl011: Add transmit FIFO to PL011State Date: Fri, 19 Jul 2024 20:10:37 +0200 Message-ID: <20240719181041.49545-13-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240719181041.49545-1-philmd@linaro.org> References: <20240719181041.49545-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=philmd@linaro.org; helo=mail-wm1-x329.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org In order to make the next commit easier to review, introduce the transmit FIFO, but do not yet use it. We only migrate the TX FIFO if it is in use. When migrating from new to old VM: - if the fifo is empty, migration will still work because of the subsection. - if the fifo is not empty, the subsection will be ignored, with the only consequence being that some characters will be dropped. Since the FIFO is created empty, we don't need a migration pre_load() handler. Uninline pl011_reset_tx_fifo(). Reviewed-by: Alex Bennée Signed-off-by: Philippe Mathieu-Daudé --- include/hw/char/pl011.h | 2 ++ hw/char/pl011.c | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/include/hw/char/pl011.h b/include/hw/char/pl011.h index 4fcaf3d7d3..e8d95961f6 100644 --- a/include/hw/char/pl011.h +++ b/include/hw/char/pl011.h @@ -18,6 +18,7 @@ #include "hw/sysbus.h" #include "chardev/char-fe.h" #include "qom/object.h" +#include "qemu/fifo8.h" #define TYPE_PL011 "pl011" OBJECT_DECLARE_SIMPLE_TYPE(PL011State, PL011) @@ -52,6 +53,7 @@ struct PL011State { Clock *clk; bool migrate_clk; const unsigned char *id; + Fifo8 xmit_fifo; }; DeviceState *pl011_create(hwaddr addr, qemu_irq irq, Chardev *chr); diff --git a/hw/char/pl011.c b/hw/char/pl011.c index c42c6d1ac2..6519340b50 100644 --- a/hw/char/pl011.c +++ b/hw/char/pl011.c @@ -167,11 +167,13 @@ static inline void pl011_reset_rx_fifo(PL011State *s) s->flags |= PL011_FLAG_RXFE; } -static inline void pl011_reset_tx_fifo(PL011State *s) +static void pl011_reset_tx_fifo(PL011State *s) { /* Reset FIFO flags */ s->flags &= ~PL011_FLAG_TXFF; s->flags |= PL011_FLAG_TXFE; + + fifo8_reset(&s->xmit_fifo); } static void pl011_fifo_rx_put(void *opaque, uint32_t value) @@ -545,6 +547,24 @@ static const VMStateDescription vmstate_pl011_clock = { } }; +static bool pl011_xmit_fifo_state_needed(void *opaque) +{ + PL011State* s = opaque; + + return (s->lcr & LCR_FEN) && !fifo8_is_empty(&s->xmit_fifo); +} + +static const VMStateDescription vmstate_pl011_xmit_fifo = { + .name = "pl011/xmit_fifo", + .version_id = 1, + .minimum_version_id = 1, + .needed = pl011_xmit_fifo_state_needed, + .fields = (VMStateField[]) { + VMSTATE_FIFO8(xmit_fifo, PL011State), + VMSTATE_END_OF_LIST() + } +}; + static int pl011_post_load(void *opaque, int version_id) { PL011State* s = opaque; @@ -599,7 +619,11 @@ static const VMStateDescription vmstate_pl011 = { .subsections = (const VMStateDescription * const []) { &vmstate_pl011_clock, NULL - } + }, + .subsections = (const VMStateDescription * []) { + &vmstate_pl011_xmit_fifo, + NULL + }, }; static Property pl011_properties[] = { @@ -614,6 +638,7 @@ static void pl011_init(Object *obj) PL011State *s = PL011(obj); int i; + fifo8_create(&s->xmit_fifo, PL011_FIFO_DEPTH); memory_region_init_io(&s->iomem, OBJECT(s), &pl011_ops, s, "pl011", 0x1000); sysbus_init_mmio(sbd, &s->iomem); for (i = 0; i < ARRAY_SIZE(s->irq); i++) { @@ -626,6 +651,13 @@ static void pl011_init(Object *obj) s->id = pl011_id_arm; } +static void pl011_finalize(Object *obj) +{ + PL011State *s = PL011(obj); + + fifo8_destroy(&s->xmit_fifo); +} + static void pl011_realize(DeviceState *dev, Error **errp) { PL011State *s = PL011(dev); @@ -669,6 +701,7 @@ static const TypeInfo pl011_arm_info = { .parent = TYPE_SYS_BUS_DEVICE, .instance_size = sizeof(PL011State), .instance_init = pl011_init, + .instance_finalize = pl011_finalize, .class_init = pl011_class_init, };