From patchwork Thu Nov 9 19:28:13 2023 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: 742599 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:110f:b0:32d:baff:b0ca with SMTP id z15csp1017927wrw; Thu, 9 Nov 2023 11:29:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IFmfk8gBAtv/WdnPncDdYiiMctsAO8Mj34Q6oAO3TmiBnLroubOmbsbOX6qo5JX6QcQniO+ X-Received: by 2002:a05:6358:938c:b0:168:ca83:d241 with SMTP id h12-20020a056358938c00b00168ca83d241mr6224492rwb.12.1699558183252; Thu, 09 Nov 2023 11:29:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699558183; cv=none; d=google.com; s=arc-20160816; b=sBnhiJi01eYv016c5zffxGiW07zvmmWvgasB+Kgu4ukSDrRv9NIwUpcKBHCeMeFvJC Bgzg7fjnS5KGo3JmKasOu4Pf1psKsevKWTHoLB+UdR/pAfjflmYqTGY1LhlstjVAmb2J aFygiWAQEqYHcj6HSE41gZhld1Dq0Jp9Ej/LJfyHnpkVx9NtHbKJOyzchyHgr5TvOUyy 0RxckytNHiyCWmu3bCmydFIFSqIui8280dAod0k87zm/33xQei5XHTwuXjiTvFZ3M1ue KK6Wl+5ZjzswvUOmlBJpn+PBAJokl7aYY2Es4wmpLPho/7zkEJ6movWC6OdHFn5NJKuX B4eQ== 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=VbCASInnNu6Q9uFgn8bNgw0dLduM6GSUn61bZ+goPO8=; fh=DIg4VbvV6UsIVtjymVavUODq0hsDWu0+XvIrfuGsGdI=; b=B1hyvXPbDUl9xQUyVrCpBpDfpPQuKyTtCIh4viZ7yAR/Bb19GSpRIpFzvpTNkTT3vB rUv+3IWCVVvO+1JXr68s+VGLSTI9rl+407Sfyt90iInpz+0mYdaM4HlVYEcOpa2P/19L I8y5VTgaoa0IG/zMdb6FaRvEllOYTkxNggR/KCm6vvgiG2RwacWTlRggZbLpbLN/6MkY rQ3IrfHeMuwDtu/RVC4oCO8lMB6LivdlRHoztflS9YN5graOi93tCHn2cRMhJsatukmG s774fBK/PkmZfi/mM+m+x8j12wthyI89Hr+jBNs4V60ucABVZYPJbtJ/NMCusTHZmKOO u0uA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aPz1kT8t; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id j20-20020ac85f94000000b0041cb522af96si3270334qta.347.2023.11.09.11.29.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 09 Nov 2023 11:29:43 -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=aPz1kT8t; 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 Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r1AiU-0006f5-LI; Thu, 09 Nov 2023 14:29:26 -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 1r1AiJ-0005lZ-Px for qemu-devel@nongnu.org; Thu, 09 Nov 2023 14:29:17 -0500 Received: from mail-ed1-x534.google.com ([2a00:1450:4864:20::534]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r1AiH-0005OE-CT for qemu-devel@nongnu.org; Thu, 09 Nov 2023 14:29:14 -0500 Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-5437269a661so4805900a12.0 for ; Thu, 09 Nov 2023 11:29:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699558150; x=1700162950; 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=VbCASInnNu6Q9uFgn8bNgw0dLduM6GSUn61bZ+goPO8=; b=aPz1kT8tU/br4Ec1wAGjYyD4QDrp3n3D6WhvdD2rWaRtqEU5d28fgvFtYu9jCQ1sg8 sfgVeC6Jd8MYr/B+8yKOwnY9zSfUNSunRXY+SkX08lsXi1QPSBuCIxf5upybT3IjPOh3 XV00CW8P7TLqzTNElYZwPdbSX9ZytJY4P9DinM30KfZugI9+0my51V4ayq3rjkjSuwdu muqZhj0z5FrDHUB+W8Url9kGmjyrUWNYRPUhIrb0/uTrJO3zQxb5BOvXGZ/siIyuKdtQ aAf45h+y2hDxj+yAdNVdaNYZUpth9bKi66xXcDfV37dxtpWg570UF+wo6z8LcvJbcXpF KWSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699558150; x=1700162950; 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=VbCASInnNu6Q9uFgn8bNgw0dLduM6GSUn61bZ+goPO8=; b=o2/Ua4JmBxj+1WARDmWYPBaurlk8f036joflcwZlE2doQ67tGhXABaw2NgcgfpyZpH akJfyGL+T/EpdkytFR3muuyZHBTMRkMat1CNbLdvaITpzyIMU21Ihw+uZ3Eg5x/qkHkU mTugOKP5asKVWNRTWSjKLDSR6I9f3CiheEo4ssybpSYT+Gk6MHfoIn7dWjAiyw2uBKu+ ueCFkCw6YAeytwiYp/7QD3F5a/OlTLzT5j26OIatfG0MM8uQblIicleojvyjes2Q/CHy dLO+jCZZgy7Tr72EKqiZ52ujZAJrJ8Sk489W7d1NW0t7VQ74kHWtyO86nZxwy3o0JL0z d92g== X-Gm-Message-State: AOJu0YytUcBVP4UrOP3lvmq/+EujbJFz9vSQxOGLDtbXlkq6ItpuN5Nb EhYDWh+B83CeVvCYt+pikh4ox2RKkJiQfdblEQpL9A== X-Received: by 2002:a17:906:bc85:b0:9b2:bdbb:f145 with SMTP id lv5-20020a170906bc8500b009b2bdbbf145mr190299ejb.34.1699558150739; Thu, 09 Nov 2023 11:29:10 -0800 (PST) Received: from m1x-phil.lan ([176.187.199.161]) by smtp.gmail.com with ESMTPSA id dv16-20020a170906b81000b009a1c05bd672sm2902807ejb.127.2023.11.09.11.29.09 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 09 Nov 2023 11:29:10 -0800 (PST) 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?= , Gavin Shan , Paolo Bonzini , Mark Cave-Ayland , Peter Maydell , Evgeny Iakovlev , qemu-arm@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH-for-8.2 v4 09/10] hw/char/pl011: Add transmit FIFO to PL011State Date: Thu, 9 Nov 2023 20:28:13 +0100 Message-ID: <20231109192814.95977-10-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231109192814.95977-1-philmd@linaro.org> References: <20231109192814.95977-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::534; envelope-from=philmd@linaro.org; helo=mail-ed1-x534.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, T_SCC_BODY_TEXT_LINE=-0.01 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 In order to make the next commit easier to review, introduce the transmit FIFO, but do not yet use it. 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. 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 d853802132..20898f43a6 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) @@ -53,6 +54,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 727decd428..f474f56780 100644 --- a/hw/char/pl011.c +++ b/hw/char/pl011.c @@ -147,11 +147,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_write_txdata(PL011State *s, uint8_t data) @@ -436,6 +438,24 @@ static const VMStateDescription vmstate_pl011_clock = { } }; +static bool pl011_xmit_fifo_state_needed(void *opaque) +{ + PL011State* s = opaque; + + return !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; @@ -487,7 +507,11 @@ static const VMStateDescription vmstate_pl011 = { .subsections = (const VMStateDescription * []) { &vmstate_pl011_clock, NULL - } + }, + .subsections = (const VMStateDescription * []) { + &vmstate_pl011_xmit_fifo, + NULL + }, }; static Property pl011_properties[] = { @@ -502,6 +526,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++) { @@ -514,6 +539,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); @@ -557,6 +589,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, };