From patchwork Thu Nov 9 19:28:05 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: 742600 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:110f:b0:32d:baff:b0ca with SMTP id z15csp1017998wrw; Thu, 9 Nov 2023 11:29:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IFYYC/kfh2xtRAZU8iGdPyx0vNQJnP6161HXldG5WPUZp8mc8zCLbIGF8nVQE6MY1C5e913 X-Received: by 2002:ad4:5cee:0:b0:66d:253c:9a80 with SMTP id iv14-20020ad45cee000000b0066d253c9a80mr7144072qvb.54.1699558195677; Thu, 09 Nov 2023 11:29:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699558195; cv=none; d=google.com; s=arc-20160816; b=nP3SWTLMXsgMibHD3RA0RmK/0eHeOyXx7s9oS7GM0m5+ekhHVGBF1dt5kvMq0PvyDB sxtIoM0mHQgDlpXQxZwu1lCC8n8XKagEbKQ7tufHTBwN0CdvkMnteRhJl1d4nrAjvUi3 RI0iBHoCouzNqil/nypo0dS+0Ii7fLy5bq2XQMNc7T2sTVsK4S5TLTKOD2qBSyngfxfp khmLUnAdanFAaPAenOhQFnVZzFAfkbua6Fsy6pyq5UvBxpfGvrV1GqbK2OWrgEWtYt/2 yav9i0map4bEDemK3UkvTKkIszj9G8r0vg4n0LcbynE6TQUa05D7kFnwSHan9FISAHd2 C6yA== 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=tAZvf0/lxzzRafQirPbdSKogeoxVhHxgjxTZIWfzoxQ=; fh=GQxR5x0bbpeaxpQRj0Ss2iF9lxOTaG+uCQYEI2XZ3x0=; b=dtTCH3jxzi2t2a8+EgZhYtalB5a2NQY82oex6OsDJNx2/bbJs7ug43F7MmJpZz4imq l1sM+Lah+6jGq172rkElSX4Feg0h07i24cypA05ZXN4B4xp6OWEa3skQ6B9zN2pwohPi jnSk2U26e1ik7xwQBxQfMvDDa3AvIX/SwT1sWKEzmqZMd62OkLsrfB/FXZCze6QarfFo Sm/TdKaLUN1cS19JEByNXY7HILLCoMLR1J17f9LUMy2wcf0zaaf7meINtNr7+1m1Qc00 jp3t9zq+VpXPT7m5Hv/GIDbrCrM9AhGLlCLCNkaoB8Q4AbVEvbq2y8uWFwkNqy/QCtOA 00jA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NqaF7rDg; 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 b9-20020a0cfb49000000b0065b081ea06bsi3254395qvq.22.2023.11.09.11.29.55 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 09 Nov 2023 11:29:55 -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=NqaF7rDg; 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 1r1AhY-000515-5q; Thu, 09 Nov 2023 14:28:28 -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 1r1AhW-0004uf-L1 for qemu-devel@nongnu.org; Thu, 09 Nov 2023 14:28:26 -0500 Received: from mail-ed1-x52f.google.com ([2a00:1450:4864:20::52f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r1AhU-0005G0-W3 for qemu-devel@nongnu.org; Thu, 09 Nov 2023 14:28:26 -0500 Received: by mail-ed1-x52f.google.com with SMTP id 4fb4d7f45d1cf-5440f25dcc7so2027472a12.0 for ; Thu, 09 Nov 2023 11:28:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699558103; x=1700162903; 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=tAZvf0/lxzzRafQirPbdSKogeoxVhHxgjxTZIWfzoxQ=; b=NqaF7rDg+cNy598mq7WXsKuET9YrMQV/LJ+ncqMhJIQKLSGfQzymsTq6CqTB4SX5bb CmmVJzVDaU4PP3Tmi8Qwq/HzoLLLxk5pomwuswp5KFanblWn6M2F/6rrAh00MzcwKvGj I6DQU4lti/xy7ZGYLoWxT30dx+2a7PmIqLdphYaNut2XAJFNqGikyMoxbKAmvj7MS4az tVSBX+IcUMQffeqF6pBXOACheGA5dY/2XJAoHiegylbyFdufs76UT9kO1yQCPBYjFFwx yMCct2a2xvaadTvFzFOncHlMys5MzmBFvJn8pvA38CHtjYvGIIDxmtKjdmXeeaLcxNAP 8eLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699558103; x=1700162903; 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=tAZvf0/lxzzRafQirPbdSKogeoxVhHxgjxTZIWfzoxQ=; b=BblOfxbZr9cyPnFaZfUszuczkLf/ZFNQXPscuNyPJ8jkDwD9VbEJR+yo2i1ZNm6Jri Bw3oJjQlIEy3dqNUamjjr0iel7Y9q1dYNaoefeCYhvVm3XR4u2/ELqLv2yrdjH+2z56I XOZ9lw7NBKnRJRuc4EBqM+AwlJOYFu/IpUt7Kv41dL5IYrvSuS6DNOSuIR85bXBwYWBX zOmNU70kZJbo9iGUqIIb41sxkB25KFNePaS0yRVTycOTuOOIdGOKBzVcxvTjnVe9a8qc 2oGT6efpP8Ns28MT542AY7dXBo9uUQR3Vk6OKSHf4kIy7ySVk9MpPYfUpo2LaD7Z4RMh H7Fg== X-Gm-Message-State: AOJu0YwpA+xLs5656TCrwVOqr0YzekgNZkzZtmzpToMNEGYoFearlF1j eyI06pg7OVoAoKj8YrapUF5+sXq/ZdFr1Us31kXssQ== X-Received: by 2002:a50:8d0b:0:b0:53e:37d1:a31f with SMTP id s11-20020a508d0b000000b0053e37d1a31fmr5226900eds.28.1699558103375; Thu, 09 Nov 2023 11:28:23 -0800 (PST) Received: from m1x-phil.lan ([176.187.199.161]) by smtp.gmail.com with ESMTPSA id z3-20020a5096c3000000b00544f8271b5fsm189937eda.8.2023.11.09.11.28.22 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 09 Nov 2023 11:28:23 -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?= , Francisco Iglesias Subject: [PATCH-for-8.2 v4 01/10] util/fifo8: Allow fifo8_pop_buf() to not populate popped length Date: Thu, 9 Nov 2023 20:28:05 +0100 Message-ID: <20231109192814.95977-2-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::52f; envelope-from=philmd@linaro.org; helo=mail-ed1-x52f.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=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 There might be cases where we know the number of bytes we can pop from the FIFO, or we simply don't care how many bytes is returned. Allow fifo8_pop_buf() to take a NULL numptr. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Francisco Iglesias Reviewed-by: Alex Bennée Reviewed-by: Richard Henderson --- include/qemu/fifo8.h | 10 +++++----- util/fifo8.c | 12 ++++++++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/include/qemu/fifo8.h b/include/qemu/fifo8.h index 16be02f361..d0d02bc73d 100644 --- a/include/qemu/fifo8.h +++ b/include/qemu/fifo8.h @@ -71,7 +71,7 @@ uint8_t fifo8_pop(Fifo8 *fifo); * fifo8_pop_buf: * @fifo: FIFO to pop from * @max: maximum number of bytes to pop - * @num: actual number of returned bytes + * @numptr: pointer filled with number of bytes returned (can be NULL) * * Pop a number of elements from the FIFO up to a maximum of max. The buffer * containing the popped data is returned. This buffer points directly into @@ -82,16 +82,16 @@ uint8_t fifo8_pop(Fifo8 *fifo); * around in the ring buffer; in this case only a contiguous part of the data * is returned. * - * The number of valid bytes returned is populated in *num; will always return - * at least 1 byte. max must not be 0 or greater than the number of bytes in - * the FIFO. + * The number of valid bytes returned is populated in *numptr; will always + * return at least 1 byte. max must not be 0 or greater than the number of + * bytes in the FIFO. * * Clients are responsible for checking the availability of requested data * using fifo8_num_used(). * * Returns: A pointer to popped data. */ -const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *num); +const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *numptr); /** * fifo8_reset: diff --git a/util/fifo8.c b/util/fifo8.c index d4d1c135e0..032e985440 100644 --- a/util/fifo8.c +++ b/util/fifo8.c @@ -66,16 +66,20 @@ uint8_t fifo8_pop(Fifo8 *fifo) return ret; } -const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *num) +const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *numptr) { uint8_t *ret; + uint32_t num; assert(max > 0 && max <= fifo->num); - *num = MIN(fifo->capacity - fifo->head, max); + num = MIN(fifo->capacity - fifo->head, max); ret = &fifo->data[fifo->head]; - fifo->head += *num; + fifo->head += num; fifo->head %= fifo->capacity; - fifo->num -= *num; + fifo->num -= num; + if (numptr) { + *numptr = num; + } return ret; } From patchwork Thu Nov 9 19:28:06 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: 742596 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:110f:b0:32d:baff:b0ca with SMTP id z15csp1017904wrw; Thu, 9 Nov 2023 11:29:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IFX5pg4+DQwgfA9U2kf6rknKvfK7tW9btU8aG/lSxqh6nloMCBLBXXfaoQhDjbX9ZqW1yVf X-Received: by 2002:a05:620a:2952:b0:77a:1d5b:2cc4 with SMTP id n18-20020a05620a295200b0077a1d5b2cc4mr6491966qkp.9.1699558180701; Thu, 09 Nov 2023 11:29:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699558180; cv=none; d=google.com; s=arc-20160816; b=r25tiqYpI9k/sxeSzOv4E1szh/sqvR1T8kXDNeRX16Ef876W5lgO26tr9GcIpkepRq qYExuGl8ulBrar/SaIZDrN1IvpNhyw8nnfi/Me3ZSorTavMYlMk58rdCXWy4lCOjqns7 +gOh4VIR9ZvRl3y/YE92yi8SowIjPbnM5PLA5f7E2DxJkOlaIc43O2+ylQT2WGRMtuDy 5qtntiPqkOO28ITTtednYZefG5aWilsBL/v4vF2d873KMwuK9jpITh7oASf8sxGN8E5y R6t7hDOGNz3IlCK4RO7AiAmSJ/Px3A3rhdYMK9oYr2ABez5n7c/tSa0fhpcDGdEej9lg QuVA== 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=BO0D2WVoS2EP+jLak3Jz2oTxKuP2p7K6nXjgv8ItBfQ=; fh=GQxR5x0bbpeaxpQRj0Ss2iF9lxOTaG+uCQYEI2XZ3x0=; b=STZG+0I7n0Hqy+xw/tWKd0k522+aCqCOwAR4ekIcs7Zav3CGtrH6YacAyYG1ioCN8A yf+XNwiFaAN++uFTQx3nr2Ibb8Yf4kx2qnXSCRuaMlyzV++ENeyKrygFFYj8kOFfk4je ATSlvvU7BFZEhmBsOl8G/+Yufb6fHjxqF2sZRTuF1eVHH2gkoqV1f9q/UQuVD4i78V/R x1cXn9NNG5tv0UwnkcgcwFDOWCgWT9ls8cTCd0XXACoINbJDDsi9IkKEdgObYbj69gZL QzWNPawnOwJg0nL5k+oytXyRa/IGThB47C1QBpya2WNHx8Zukf16XWc2IRk5I6ql6AJa tvcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tfNv+2mj; 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 z10-20020ae9c10a000000b0076daa449cb8si3227568qki.224.2023.11.09.11.29.40 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 09 Nov 2023 11:29:40 -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=tfNv+2mj; 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 1r1Ahf-00054S-Dq; Thu, 09 Nov 2023 14:28:35 -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 1r1Ahd-00053k-Tj for qemu-devel@nongnu.org; Thu, 09 Nov 2023 14:28:33 -0500 Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r1Ahc-0005GV-8r for qemu-devel@nongnu.org; Thu, 09 Nov 2023 14:28:33 -0500 Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-9d267605ceeso209734566b.2 for ; Thu, 09 Nov 2023 11:28:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699558109; x=1700162909; 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=BO0D2WVoS2EP+jLak3Jz2oTxKuP2p7K6nXjgv8ItBfQ=; b=tfNv+2mjSdiHuj6izxKvhPqyNSpT00DzsUACdTaTi/LgitchUy9nGEVrqdU4KvHnfH sSPVwyGRVULCB+c24BZbwimRyY+8tXKAoKpMfgSer/d2J/EAQvn+KsN8bXvXtQcN4GoB eYS3mkDHFQpN/DDcRwmXlBZa5UmYZ9wr7PUlTj6wDcL/F9tu5mVhiTV6SYOG49IK57VI OaV3KjisNz+TJqoFK86fdRP1J6NfRsMHPlBZmrge+nV5oJKn+Sz6mrSD7B8dInVevfgf Uzrymg0h9Ep5lr+MW3qzQLE4UP+GLr4SDvki8yuB+0i63AvJRrr4VUh1T7WS0aiqYD3I tpIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699558109; x=1700162909; 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=BO0D2WVoS2EP+jLak3Jz2oTxKuP2p7K6nXjgv8ItBfQ=; b=RrsrkKzlNUQgA4wqOKK5hXR3429bu1j5U0lUGv15Vpg6HamjF0WF2nYfTKfFUpUo+O ZlRrb+sZK50QUlfzsmGDgd1cp4YlrS61NyQazQcCDcjW+DH3k4vNGgNAikhi24KpiFLu sb44tDcLUGXELNlfg/yssqZ2KxX9t9LD1rvix98W0WE0qqcmBkFn0SpqhDKG335Dp/5n JD2D9vjKE430QWYdCVP5ub+hOoBivvJ5V2dqOuoV5evW1FExBvEs0CIDe2R2ExflfPxk XsFhJ+5qFD7RbNqpcY4LSyopoW6xjvWMmupTzX8co1/WIa0vX3Ulld2URNlQCDh9SThe 1KMw== X-Gm-Message-State: AOJu0Yx7VGTO4s1YapLH3plkNKuxZeRkMwZeGnYdk7QtA6kh4YqmCJz4 2MPb3f2KQSLHxSr/D6ko+k7JLd7kU3WtCU7ycOL+hQ== X-Received: by 2002:a17:907:7faa:b0:9e0:5f68:143c with SMTP id qk42-20020a1709077faa00b009e05f68143cmr5572161ejc.35.1699558109337; Thu, 09 Nov 2023 11:28:29 -0800 (PST) Received: from m1x-phil.lan ([176.187.199.161]) by smtp.gmail.com with ESMTPSA id qh23-20020a170906ecb700b009a19701e7b5sm2954549ejb.96.2023.11.09.11.28.27 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 09 Nov 2023 11:28:28 -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?= , Francisco Iglesias Subject: [PATCH-for-8.2 v4 02/10] util/fifo8: Introduce fifo8_peek_buf() Date: Thu, 9 Nov 2023 20:28:06 +0100 Message-ID: <20231109192814.95977-3-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::62b; envelope-from=philmd@linaro.org; helo=mail-ej1-x62b.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 To be able to peek at FIFO content without popping it, introduce the fifo8_peek_buf() method by factoring common content from fifo8_pop_buf(). Reviewed-by: Francisco Iglesias Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Alex Bennée Reviewed-by: Richard Henderson --- include/qemu/fifo8.h | 27 +++++++++++++++++++++++++++ util/fifo8.c | 22 ++++++++++++++++++---- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/include/qemu/fifo8.h b/include/qemu/fifo8.h index d0d02bc73d..c6295c6ff0 100644 --- a/include/qemu/fifo8.h +++ b/include/qemu/fifo8.h @@ -93,6 +93,33 @@ uint8_t fifo8_pop(Fifo8 *fifo); */ const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *numptr); +/** + * fifo8_peek_buf: read upto max bytes from the fifo + * @fifo: FIFO to read from + * @max: maximum number of bytes to peek + * @numptr: pointer filled with number of bytes returned (can be NULL) + * + * Peek into a number of elements from the FIFO up to a maximum of max. + * The buffer containing the data peeked into is returned. This buffer points + * directly into the FIFO backing store. Since data is invalidated once any + * of the fifo8_* APIs are called on the FIFO, it is the caller responsibility + * to access it before doing further API calls. + * + * The function may return fewer bytes than requested when the data wraps + * around in the ring buffer; in this case only a contiguous part of the data + * is returned. + * + * The number of valid bytes returned is populated in *numptr; will always + * return at least 1 byte. max must not be 0 or greater than the number of + * bytes in the FIFO. + * + * Clients are responsible for checking the availability of requested data + * using fifo8_num_used(). + * + * Returns: A pointer to peekable data. + */ +const uint8_t *fifo8_peek_buf(Fifo8 *fifo, uint32_t max, uint32_t *numptr); + /** * fifo8_reset: * @fifo: FIFO to reset diff --git a/util/fifo8.c b/util/fifo8.c index 032e985440..e12477843e 100644 --- a/util/fifo8.c +++ b/util/fifo8.c @@ -66,7 +66,8 @@ uint8_t fifo8_pop(Fifo8 *fifo) return ret; } -const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *numptr) +static const uint8_t *fifo8_peekpop_buf(Fifo8 *fifo, uint32_t max, + uint32_t *numptr, bool do_pop) { uint8_t *ret; uint32_t num; @@ -74,15 +75,28 @@ const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *numptr) assert(max > 0 && max <= fifo->num); num = MIN(fifo->capacity - fifo->head, max); ret = &fifo->data[fifo->head]; - fifo->head += num; - fifo->head %= fifo->capacity; - fifo->num -= num; + + if (do_pop) { + fifo->head += num; + fifo->head %= fifo->capacity; + fifo->num -= num; + } if (numptr) { *numptr = num; } return ret; } +const uint8_t *fifo8_peek_buf(Fifo8 *fifo, uint32_t max, uint32_t *numptr) +{ + return fifo8_peekpop_buf(fifo, max, numptr, false); +} + +const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *numptr) +{ + return fifo8_peekpop_buf(fifo, max, numptr, true); +} + void fifo8_reset(Fifo8 *fifo) { fifo->num = 0; From patchwork Thu Nov 9 19:28:07 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: 742598 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:110f:b0:32d:baff:b0ca with SMTP id z15csp1017925wrw; Thu, 9 Nov 2023 11:29:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IEhOJc5dUaSneka40kXWCKaCcugiLxmaw+zsQE1B6xn/w8BnuoD4zbjF5Lp54Zmpu5ZxiFb X-Received: by 2002:a0c:d791:0:b0:675:b83f:6db3 with SMTP id z17-20020a0cd791000000b00675b83f6db3mr303740qvi.22.1699558182997; Thu, 09 Nov 2023 11:29:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699558182; cv=none; d=google.com; s=arc-20160816; b=i5kRPjxVqRr7nkjr+wOdSV4H+jAwUcoYK55owMAS2UoqnbENCkKk0FfZuYT/kBeFEw wOxKqVIglKywNYHCMD+gXx6uJCraMImv/I9Do6HjoXmNZtw2xUDwGUnGbUMTNRK3BzPw 7qLkW2ARyiuNscHhVCQ/Gu5luk5wMXngtQ1QazSbd+/SCXVgKz9+6y6WzWk4jGQRlrSV Fvq77x6tN4FnTfzrGTgVvXKqRlDDPGQVDogDDshb679yzPzmdAbpMcu9fkOldLEG5Zru AlPCOvQcaB2BKn8gPN2rnKxiUoaA4R+BrNhXoygu6d6kQ8Oln09Rh1uEBY5RPDYxeGt3 qbug== 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=mP8e7F+MNf59pa1iU6FTfmv7Sb18zKeyajADdz6BZOc=; fh=Zi/lk1CoRxouROvt4Eod7oP2jg68ZE5jz0tOr4SBE9g=; b=iqCM50Wc7CNtetVRslsaZ/Le3Cwn/vytkSZPMuGQ+2lVXc8RB8BGHLe6sIYkxDm5wb PMGC3du/cHJGVGA/eZnU2whjEJmxaSTbAJ3E+8NA1CPnj0XluqHigyM90zTalZyTswNZ UAyg3i0JMaQRJcBzjufoHCgGBzlt1C00EmciCrdZVKcncyScTR0DwASgWYTkuMprq/oG SQEyjiY9T3SX1YSA2Ei3REJxOFkxEReZY4ZlFjYncqqh0FtLzsC8bOYEgPu058zyBDwb sZ7TBuf1nu1oK1qaDrBhg4Ee2tgbdc79dtcIs/kb68PtpVthC+54qgp9SW2SGwXvPf8X Z7fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yUA8Lh9v; 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 s8-20020a0cf648000000b0066db35504e0si3274722qvm.502.2023.11.09.11.29.42 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 09 Nov 2023 11:29:42 -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=yUA8Lh9v; 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 1r1Ahk-00055w-Hc; Thu, 09 Nov 2023 14:28:40 -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 1r1Ahi-00055K-PC for qemu-devel@nongnu.org; Thu, 09 Nov 2023 14:28:38 -0500 Received: from mail-ed1-x530.google.com ([2a00:1450:4864:20::530]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r1Ahh-0005Gv-7J for qemu-devel@nongnu.org; Thu, 09 Nov 2023 14:28:38 -0500 Received: by mail-ed1-x530.google.com with SMTP id 4fb4d7f45d1cf-53e2308198eso2022864a12.1 for ; Thu, 09 Nov 2023 11:28:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699558115; x=1700162915; 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=mP8e7F+MNf59pa1iU6FTfmv7Sb18zKeyajADdz6BZOc=; b=yUA8Lh9vnAqKuqVclqo4i3ETE3k3VEdY79vtFZFifhM6esPzTL+Sc1vbf6GCBFyaTt Y62vlH/CLoCuJaA7twdJw3h36m+WNZ2DmiKq2R3l4N1CC4WCpYBSx8pwPLbTrM/nKttr SQflwdGaeuFjcdqJW7kXLF5p5PTfX9qGgYS2pZUcckqSETQQR64s0h2avoLPApes/e1n 7S2mjFt5kmJBnhYbhsXkAksFPBLAXlAhMSb9Msj0uSmI/A/qcegHa7xD2dRgDtDeyqmD /zFoId7TjiraCPJmILdUVa4QpONPtym7ZCmNLQ7PVxO9RWIRaIJ2p+c0EaSIBbbP74NF VOZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699558115; x=1700162915; 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=mP8e7F+MNf59pa1iU6FTfmv7Sb18zKeyajADdz6BZOc=; b=nV8gVbj3FKIJoJ8gtBap4VIG+lvstfdbWtS8XmA792aYG/QbDbDIS0HGXEhFpkwOaN zs+gzGWwIwhNwcvvnbpgKPBB9kcgsQiL4wnrmmBwL9NBLECShh5OEEU4FGbwXUbNatX+ fHZD/DUAx8BOoOUTzS03PvzGL6nY6TO4eCZZ5uuidkKzJk6z10cWoGjzdPSROfJT/1TT qYVw4fH+z8GzmCKtL8ZwrdLkPOxGghzPyHmIhsob+yPjHt26KWsQO0UaclpmRSYcDns/ HlUtzBPZ1UwmsqkGaDsykJxTmu+MFkhU6u8Xt3EdiS2Z7ABap2/qiDOb0u6/Ihbi3SIQ Ze7g== X-Gm-Message-State: AOJu0YxYMeo1X0kAiDtYaauqBBrF935RMUsiKzRV5PlQULi/l3ZQ75ay FFLxbpl37nrVQwXg0Ae4SfcBqmdMZCWGDfRiTu71Mw== X-Received: by 2002:a17:906:d9dd:b0:9e5:21d9:3ba6 with SMTP id qk29-20020a170906d9dd00b009e521d93ba6mr712372ejb.9.1699558115130; Thu, 09 Nov 2023 11:28:35 -0800 (PST) Received: from m1x-phil.lan ([176.187.199.161]) by smtp.gmail.com with ESMTPSA id bw25-20020a170906c1d900b009bd9ac83a9fsm2946023ejb.152.2023.11.09.11.28.33 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 09 Nov 2023 11:28:34 -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?= , Richard Henderson Subject: [PATCH-for-8.2 v4 03/10] hw/char/pl011: Split RX/TX path of pl011_reset_fifo() Date: Thu, 9 Nov 2023 20:28:07 +0100 Message-ID: <20231109192814.95977-4-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::530; envelope-from=philmd@linaro.org; helo=mail-ed1-x530.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=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 To be able to reset the RX or TX FIFO separately, split pl011_reset_fifo() in two. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Alex Bennée Reviewed-by: Richard Henderson --- hw/char/pl011.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/hw/char/pl011.c b/hw/char/pl011.c index 58edeb9ddb..1f07c7b021 100644 --- a/hw/char/pl011.c +++ b/hw/char/pl011.c @@ -132,14 +132,21 @@ static inline unsigned pl011_get_fifo_depth(PL011State *s) return pl011_is_fifo_enabled(s) ? PL011_FIFO_DEPTH : 1; } -static inline void pl011_reset_fifo(PL011State *s) +static inline void pl011_reset_rx_fifo(PL011State *s) { s->read_count = 0; s->read_pos = 0; /* Reset FIFO flags */ - s->flags &= ~(PL011_FLAG_RXFF | PL011_FLAG_TXFF); - s->flags |= PL011_FLAG_RXFE | PL011_FLAG_TXFE; + s->flags &= ~PL011_FLAG_RXFF; + s->flags |= PL011_FLAG_RXFE; +} + +static inline void pl011_reset_tx_fifo(PL011State *s) +{ + /* Reset FIFO flags */ + s->flags &= ~PL011_FLAG_TXFF; + s->flags |= PL011_FLAG_TXFE; } static uint64_t pl011_read(void *opaque, hwaddr offset, @@ -289,7 +296,8 @@ static void pl011_write(void *opaque, hwaddr offset, case 11: /* UARTLCR_H */ /* Reset the FIFO state on FIFO enable or disable */ if ((s->lcr ^ value) & LCR_FEN) { - pl011_reset_fifo(s); + pl011_reset_rx_fifo(s); + pl011_reset_tx_fifo(s); } if ((s->lcr ^ value) & LCR_BRK) { int break_enable = value & LCR_BRK; @@ -506,7 +514,8 @@ static void pl011_reset(DeviceState *dev) s->ifl = 0x12; s->cr = 0x300; s->flags = 0; - pl011_reset_fifo(s); + pl011_reset_rx_fifo(s); + pl011_reset_tx_fifo(s); } static void pl011_class_init(ObjectClass *oc, void *data) From patchwork Thu Nov 9 19:28:08 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: 742601 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:110f:b0:32d:baff:b0ca with SMTP id z15csp1018286wrw; Thu, 9 Nov 2023 11:30:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IGGbiBkUPTefka9SIjh0O3ZF7M+2ebRydOTko2j3GY8W7ZtPCBjBl1G2zmvzqmUZfywdoRL X-Received: by 2002:a05:6122:2027:b0:49e:1eca:f84d with SMTP id l39-20020a056122202700b0049e1ecaf84dmr2561380vkd.14.1699558235863; Thu, 09 Nov 2023 11:30:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699558235; cv=none; d=google.com; s=arc-20160816; b=HEa3rd//Rnj1j9JyTqeQgHRECLeqRK5X2yYQ0iw7Vi3dzQskpYo/JsGt6/HSst2pd+ i7u8Fsbwk3M1SSTQNfPuII3oYBRbCI/s1J3HeupFUjTj703hM1gVnjo20T5JojoJi4Bt z7GFJEpbTIejCl21OICf0F2ZK+H6goplf7vzC6ku8k07IqC7XkR+WfzVFRTvwFBp14Jl EwWuWhRj7qCAiAg4hGgK5/jp9LPr+K7inP1j8O2YUAZUMfHgEnfK1j2CfnLqHdksDWbp 7VxN+EP8Fou7DH2JmiQMh8tzApH05g0ERsIAyL8lkNx3v5LVxMojEQJPPMCi1lpCB7Q1 oBOw== 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=4RcEaeq0Z+56TpsJGBFP08HsnS3amqPkJQB4mf707C8=; fh=DIg4VbvV6UsIVtjymVavUODq0hsDWu0+XvIrfuGsGdI=; b=N1DZknOg+h0nuPDt1vXO64lhLHx0PPfsLo5ZyWWUVrtbWJDwWR9zXcHghvS02SkDGm 1gk2L8vNocw+VQ2+qhcI7+DAfBcd3OygCbLOO9QdHRD1uU+ZID3545YtM1OL/7C9CE7a UcYPKztEhNng4HHlIgiNeNJAmQFryv7WXTkNL6WJewD/39YxlAHA/+D9wI6O0Tfh043n tn4UZcVhLKDGFqHR7OUJubALL0HxTHPehI9V9KKZXu7fbxxOPdiiLFbRNiapVOmGVUD9 25CEO8T7l1SYu9akMO0LSGnMmko/+CyBstgI+fYjMdOIdVTtc1wARLVKul07kmynZ3js Ho3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aZ1o6QiN; 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 m12-20020ad44a0c000000b0064f72cc4bdasi3372247qvz.575.2023.11.09.11.30.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 09 Nov 2023 11:30:35 -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=aZ1o6QiN; 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 1r1Ahs-0005FY-4u; Thu, 09 Nov 2023 14:28:48 -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 1r1Ahp-0005Ez-Ae for qemu-devel@nongnu.org; Thu, 09 Nov 2023 14:28:45 -0500 Received: from mail-ed1-x536.google.com ([2a00:1450:4864:20::536]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r1Ahm-0005HS-H9 for qemu-devel@nongnu.org; Thu, 09 Nov 2023 14:28:43 -0500 Received: by mail-ed1-x536.google.com with SMTP id 4fb4d7f45d1cf-54553e4888bso1752534a12.2 for ; Thu, 09 Nov 2023 11:28:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699558121; x=1700162921; 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=4RcEaeq0Z+56TpsJGBFP08HsnS3amqPkJQB4mf707C8=; b=aZ1o6QiNBdtXS2EHkgqglPT6KqQ7ZPqlUY/+jTJP8kvgZJ0PMZwuTzBQE8OCxZNPHr gVuuN/MXif6I+a2X49syDP+LOidM3rUMkNX8rbh+QcjWgx2kOLk8z4Uj5m0tnu2ylQCw vIpTn6c1StNYCnWhJJfo/vjrw2ldBFuQejOoHtmTT5U6GK74NrjMzE0QcwzFzQ1kkjiK N4x7qbjw0n3dkwvdYOdMtaTh77EH1uptHdrfPIVtNlXuMgN205sev3acaF+BFVaIWVR5 cLqfWsOlnu/Nmp12d5plTIDI0q6JwoYJE6I5FKU0EKbr++WUkG9cBoe8FRM6jQ2VwytJ 5X3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699558121; x=1700162921; 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=4RcEaeq0Z+56TpsJGBFP08HsnS3amqPkJQB4mf707C8=; b=lk+shYdnytl7WjuhcxiIOCwKn4YyV+z9/TSacSmOuWVGbEsxBANGlVM/e7XhghHbWf t2aAZolqeBOyirNhukzWHSIsOAxJOSVDnt91lsQzouVWlz+uiTYP732nfzeMk97Jqu34 4EWu+cSvkeH4jy11UcXBkq/R0kZErQRNvE+s1+Bgb0E7WYqEtjEUDaDwPJSA+td2P9Jl wAB3JPWsCaLDRc9D508bnZSG/JiDKmZ0vkmR3t35M9wJHhF5SqVSEbrxmN1qnEP4EikE oKqRmhOR75HtJu/5HiD59udkSTnvIRiH4hO1uX5KxzR7YsN8S3J323DhapJPZ+c/VwFk X65A== X-Gm-Message-State: AOJu0YwJJHx1lBRnKfhgQL5Wy5rXz4cRV551VuDXpwy9b41WIep7qAOx 18+0H1H0Phi+ln4taGCunHjBSwAQZieWCaQgdI7r/w== X-Received: by 2002:a05:6402:358c:b0:545:5601:4148 with SMTP id y12-20020a056402358c00b0054556014148mr3310692edc.7.1699558120928; Thu, 09 Nov 2023 11:28:40 -0800 (PST) Received: from m1x-phil.lan ([176.187.199.161]) by smtp.gmail.com with ESMTPSA id n18-20020a05640204d200b0054554a7bbedsm181784edw.24.2023.11.09.11.28.39 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 09 Nov 2023 11:28:40 -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 04/10] hw/char/pl011: Extract pl011_write_txdata() from pl011_write() Date: Thu, 9 Nov 2023 20:28:08 +0100 Message-ID: <20231109192814.95977-5-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::536; envelope-from=philmd@linaro.org; helo=mail-ed1-x536.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=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 When implementing FIFO, this code will become more complex. Start by factoring it out to a new pl011_write_txdata() function. No functional change intended. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Alex Bennée --- hw/char/pl011.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/hw/char/pl011.c b/hw/char/pl011.c index 1f07c7b021..1cb9015ea2 100644 --- a/hw/char/pl011.c +++ b/hw/char/pl011.c @@ -149,6 +149,17 @@ static inline void pl011_reset_tx_fifo(PL011State *s) s->flags |= PL011_FLAG_TXFE; } +static void pl011_write_txdata(PL011State *s, uint8_t data) +{ + /* ??? Check if transmitter is enabled. */ + + /* XXX this blocks entire thread. Rewrite to use + * qemu_chr_fe_write and background I/O callbacks */ + qemu_chr_fe_write_all(&s->chr, &data, 1); + s->int_level |= INT_TX; + pl011_update(s); +} + static uint64_t pl011_read(void *opaque, hwaddr offset, unsigned size) { @@ -262,19 +273,13 @@ static void pl011_write(void *opaque, hwaddr offset, uint64_t value, unsigned size) { PL011State *s = (PL011State *)opaque; - unsigned char ch; trace_pl011_write(offset, value, pl011_regname(offset)); switch (offset >> 2) { case 0: /* UARTDR */ - /* ??? Check if transmitter is enabled. */ - ch = value; - /* XXX this blocks entire thread. Rewrite to use - * qemu_chr_fe_write and background I/O callbacks */ - qemu_chr_fe_write_all(&s->chr, &ch, 1); - s->int_level |= INT_TX; - pl011_update(s); + s->readbuff = value; + pl011_write_txdata(s, value); break; case 1: /* UARTRSR/UARTECR */ s->rsr = 0; From patchwork Thu Nov 9 19:28:09 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: 742597 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:110f:b0:32d:baff:b0ca with SMTP id z15csp1017920wrw; Thu, 9 Nov 2023 11:29:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IEij721cFDPqjuzH82own1bvh+nVysxgeIPpPl94NxaV6rGDF9vJ1NmgUn050t8SUxeBZCX X-Received: by 2002:a05:620a:4720:b0:773:ca5c:4556 with SMTP id bs32-20020a05620a472000b00773ca5c4556mr425210qkb.10.1699558182961; Thu, 09 Nov 2023 11:29:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699558182; cv=none; d=google.com; s=arc-20160816; b=Vu5uQyo+SJABv8R22yi9gfD1Ps2pZpxfKZf8TKUj2ueFn/bYM57xwjpCWN0YA8RNKP N+9I4eiOvWXGj0EmwEO0byg2DNtunwk/uygYqKiAXQFmi//FkCQwdJ+jtLM0d5PQthMO AoiwCwHeFuPStIQQbD0NpgMmWw2ltsQ+iorftbTfrIas+0QM04RzGs8L9RGJSPlQDqPh QVYC34CJz3Hai2YJ8B313Nc6d4uizHf+Tt7J0rZEbtJngyBIa3fv62cR/IiAcNQL4ak8 mW2yvwsvpa/l0Ux/siG2mr65zScMA8P77yneGlWT6B537UIDoB4nAn56MQCdI1VLTD+F eDyA== 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=5g0UHLmrzpBXUAHJbDdjYHH8dsW06tpS080WDx/2FO0=; fh=Zi/lk1CoRxouROvt4Eod7oP2jg68ZE5jz0tOr4SBE9g=; b=FHREiDTE8KATQqs4eSndkSxNABLab+bQhaMzSb+Id5sUCIZN3S2H/0lG7Ml+QZmyU5 a4Yis9mpH1v3lic4KqMnPFzvoLvEugL7MD19iQJFFA8+SwhDRId8VFlj+sgIrWZXScuX Aq+LU6KnObtq20sL0cbrOF/2ffXEPRdJIZPq5WRHc7RppnyT2YpforhKTK7O8O1QI+7Q ChrwWt6NRrp7joiAHfYJRjo/cAhcnoN0mqzX3+YqEgVE6ykcykSA+f7HfAHP6h3FX7Bq f2BfJZ1cY3ttt7Di4E7NEX1BtyCVWuCKWbAwcH0RleWi7hSp8A03HkIRJUe0AqTVXlPQ vJsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IF0YNX5h; 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 e1-20020a05620a014100b0077771ab761bsi1055115qkn.35.2023.11.09.11.29.42 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 09 Nov 2023 11:29:42 -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=IF0YNX5h; 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 1r1AiL-0005l9-Uo; Thu, 09 Nov 2023 14:29:18 -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 1r1Ahw-0005Hf-7R for qemu-devel@nongnu.org; Thu, 09 Nov 2023 14:28:57 -0500 Received: from mail-ej1-x629.google.com ([2a00:1450:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r1Ahs-0005Hs-N0 for qemu-devel@nongnu.org; Thu, 09 Nov 2023 14:28:51 -0500 Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-9c53e8b7cf4so211265866b.1 for ; Thu, 09 Nov 2023 11:28:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699558127; x=1700162927; 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=5g0UHLmrzpBXUAHJbDdjYHH8dsW06tpS080WDx/2FO0=; b=IF0YNX5h+jeFnwz/GDjs7O7/0TnAwwqWMVtRuFm+oxr74QPr2tw1DvFQoNPk7IikKD +GtO0/yFn9XZLMnak2KqH84pgIs28uCQTIydjRvVoKw18luZoqqcx+FLeDyAAhVxLTJ2 7kmE4BHG6/y/AM89G/PnzA9nWIw6X983rzRvknc8VyLssgUDe5iP6Lj9IZCu8x2qIihp B82uKDAPqNhRypiKJesmFuqLIdxQhlPNK6iEB6XZBVeq3dWLzMKuXWulbYIxZ9M/69vN Ufgp6fslRTQzZNy/yHz4AMMf7H04UuiAeXbboebDsOUFCBUa6q+6PziHK1VXIVYTG/Eo s4aQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699558127; x=1700162927; 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=5g0UHLmrzpBXUAHJbDdjYHH8dsW06tpS080WDx/2FO0=; b=rD7GhHDMmD4cGnAZxhrPHYtcsBLieYtVSLAIZunYwTc9wDQVLmNU1f/8UQnX9aj1Gw YKf9HRW5vSD94koj5+wwfWpyL7pU43ABhY07LATG91CAoUbn2z+WfVQ+kzP0uK/EqVEV jNxAIMtHhoWd86B0HrC08ez+yXduIW/eixMqyGYA+/FIo6jJvslxCm/aeKgPUkftJ1x6 TLH4jtqk5bkoTbwM3z34ftiHa7699l7C3K8h58FKp0LNS6nFV+YUWl/C0Dipe5hJkEDg N1SKijk5atun2HBcGwP94Yd2k2Tw2vZ7zwC2uyliir9PrjQvlgspfxaICXMWWCdIdKpC EAgw== X-Gm-Message-State: AOJu0YyVJRyIpU074O/MGdOPqASkEndDe2ObuzTsLcTr93zcp/I61Wf6 UEsKVJYIQpfrUR3E6T2GP93gPw4N9uv4mUrppkeGgg== X-Received: by 2002:a17:907:26c9:b0:9d2:ab03:a22d with SMTP id bp9-20020a17090726c900b009d2ab03a22dmr4450766ejc.73.1699558126739; Thu, 09 Nov 2023 11:28:46 -0800 (PST) Received: from m1x-phil.lan ([176.187.199.161]) by smtp.gmail.com with ESMTPSA id qx11-20020a170906fccb00b009b2f2451381sm2930998ejb.182.2023.11.09.11.28.45 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 09 Nov 2023 11:28:46 -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?= , Richard Henderson Subject: [PATCH-for-8.2 v4 05/10] hw/char/pl011: Extract pl011_read_rxdata() from pl011_read() Date: Thu, 9 Nov 2023 20:28:09 +0100 Message-ID: <20231109192814.95977-6-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::629; envelope-from=philmd@linaro.org; helo=mail-ej1-x629.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=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 To keep MemoryRegionOps read/write handlers with similar logic, factor pl011_read_txdata() out of pl011_read(), similar to what the previous commit did to pl011_write(). No functional change intended. Reviewed-by: Richard Henderson Signed-off-by: Philippe Mathieu-Daudé --- hw/char/pl011.c | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/hw/char/pl011.c b/hw/char/pl011.c index 1cb9015ea2..30309337b1 100644 --- a/hw/char/pl011.c +++ b/hw/char/pl011.c @@ -160,31 +160,38 @@ static void pl011_write_txdata(PL011State *s, uint8_t data) pl011_update(s); } +static uint32_t pl011_read_rxdata(PL011State *s) +{ + uint32_t c; + + s->flags &= ~PL011_FLAG_RXFF; + c = s->read_fifo[s->read_pos]; + if (s->read_count > 0) { + s->read_count--; + s->read_pos = (s->read_pos + 1) & (pl011_get_fifo_depth(s) - 1); + } + if (s->read_count == 0) { + s->flags |= PL011_FLAG_RXFE; + } + if (s->read_count == s->read_trigger - 1) { + s->int_level &= ~ INT_RX; + } + trace_pl011_read_fifo(s->read_count); + s->rsr = c >> 8; + pl011_update(s); + qemu_chr_fe_accept_input(&s->chr); + return c; +} + static uint64_t pl011_read(void *opaque, hwaddr offset, unsigned size) { PL011State *s = (PL011State *)opaque; - uint32_t c; uint64_t r; switch (offset >> 2) { case 0: /* UARTDR */ - s->flags &= ~PL011_FLAG_RXFF; - c = s->read_fifo[s->read_pos]; - if (s->read_count > 0) { - s->read_count--; - s->read_pos = (s->read_pos + 1) & (pl011_get_fifo_depth(s) - 1); - } - if (s->read_count == 0) { - s->flags |= PL011_FLAG_RXFE; - } - if (s->read_count == s->read_trigger - 1) - s->int_level &= ~ INT_RX; - trace_pl011_read_fifo(s->read_count); - s->rsr = c >> 8; - pl011_update(s); - qemu_chr_fe_accept_input(&s->chr); - r = c; + r = pl011_read_rxdata(s); break; case 1: /* UARTRSR */ r = s->rsr; From patchwork Thu Nov 9 19:28:10 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: 742603 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:110f:b0:32d:baff:b0ca with SMTP id z15csp1019103wrw; Thu, 9 Nov 2023 11:32:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IE9An7h/7PMjjO1wdkkvO1QaJ0359Kmr4WCfN1+gxJzztKa0bffzwkeDW0rL4b/wG3YPbBW X-Received: by 2002:ad4:4423:0:b0:66d:5cfe:82a6 with SMTP id e3-20020ad44423000000b0066d5cfe82a6mr353105qvt.27.1699558342208; Thu, 09 Nov 2023 11:32:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699558342; cv=none; d=google.com; s=arc-20160816; b=K/EDiaZGs1sV0KWX6cAWZJTwDtoI5u+5rFD6uVlBxPWoK/GOC+hqQJ/n8L/orBXEec vQRpg2Scm18sWUSCldHSIfLkw8ApxPmzDbNMCoF0qEMStbwh+1UH0BqDZHskrxNMhGxv lz7CFdxHMZcyn3otiS5ZaXWbNLw1LsghY9t14FM8qixx9qYs6b5oMTnOmf3P5pS6md0k dzFr705gqxBPVjvmeZQoojM+YDlF5sGvwvz4QrCAAyf8rqu/O2MtZlcU6u/BduY0R12L nJM1FtVqIKMow3kwqmWP2yf65A9lU/GHmFxmmc+boou+2caECKh99UVAweHTbM4Z+YCZ HACQ== 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=TEZCH3t9203jXT8Ca8hiOxWdvxGRGRt32KSzy33l+nU=; fh=Zi/lk1CoRxouROvt4Eod7oP2jg68ZE5jz0tOr4SBE9g=; b=nuZa0pNpb+1grxw6MQdj8nayFEC07K702dmqlpUJHFH/GCMJddJqGGja4EX8VWxzqS D6RfrR+t6+89Oubia+IisvhddiM3zf7P0t9F2ZZ8HmbLecVANJXIO1ZnGmvqfxZA+LLx sjD3APDVECQJesJtd6/4Un6qkh6Qe/Ja+Vb3jepH1ysxEZhHazOREUipHhQ4nC8W2eex A09NuMgpyKpLdKGXnbVqrRym1l8jDbSPE7MDWrqEInhT4bQszWN77L5JUnneSK+Go35f PKTIwMSPl0kyNAAut/3wEAWmPLQcwEM1Z83Xb4LbBSg2/SzU24OaFllXF1Orl4l3GphC QpRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="bmUkq/Qi"; 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 s17-20020ad45251000000b00658963f9a46si3338509qvq.277.2023.11.09.11.32.22 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 09 Nov 2023 11:32:22 -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="bmUkq/Qi"; 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 1r1AiQ-0005yE-AO; Thu, 09 Nov 2023 14:29:22 -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 1r1Ai2-0005RW-B4 for qemu-devel@nongnu.org; Thu, 09 Nov 2023 14:29:02 -0500 Received: from mail-ej1-x62d.google.com ([2a00:1450:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r1Ahy-0005IO-JJ for qemu-devel@nongnu.org; Thu, 09 Nov 2023 14:28:57 -0500 Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-9dd6dc9c00cso216021466b.3 for ; Thu, 09 Nov 2023 11:28:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699558133; x=1700162933; 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=TEZCH3t9203jXT8Ca8hiOxWdvxGRGRt32KSzy33l+nU=; b=bmUkq/QiqQsVxBIPg6upwJ3HanE2T6z3MuOJU7EAhURTKDz+A8kASIlZvFgIf/2orm 99JsS8K6Jt14ckG8Po+nRQSlCqGQtNXk7srx/mVspcrJwbHEOMj0Hzryb7Q3R4WuWRXR md5OGIAGP1z8vcl5j6ZtS9ntO7EmbeClB9+z1CEEHhQBiW1kwtYoSgafe9ujlwCSi9Rm Dq+SgUuICnsQbeo/s+JX7W8ZjtlahgqwzXfIDVX8j1r7cwiQT/VkN8F65huo06+SqBBK F08nR4RGH24P7bYnbgUYsrytZkqxKMI7ISquOsIJEXpfsneQiOVOAdTl9lEpnVlJ6Yab dgGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699558133; x=1700162933; 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=TEZCH3t9203jXT8Ca8hiOxWdvxGRGRt32KSzy33l+nU=; b=SZ/CLP+53GUX4awM4Gnm6SUGkvKNqKGMn3czyzCEvINF6t6Szhf9R5DCaPSgcfaI7F 2t59B3PblHTXz4+p49DUj0rpQ+hzXBx3VpRyZEf+zruHXJolnEU4V9BKdh6m9NRPPlm8 0KCHgISkaW4dwjj+WS7VzCuPEmIlK//7/puRLFj+ot+Lsbi9tlVGvPi31/9WiRTynLYf WIxijmhGq1RkfZoeEmKU7OsQAqTe5SYpbi5xe5np9Nny+yIRflbzGnrr9rH9b+CCWBPf R/8Pjo3Y1h04UPhMQiBodpMZeOUdCxaDNl8GneWf0EIHzkGU5YFwlgq4nOr0nsx+1Zre qiGw== X-Gm-Message-State: AOJu0YwgPdPHcfdwJ9kIF2qGs8kqprtgnWpbTK/vee6FXMlPj2BGTvBU AoSzrzbU3szKYmwUp4xhyD5oiw/cWB7uWu5KFbeRmg== X-Received: by 2002:a17:907:a0b:b0:9bf:9c58:e91e with SMTP id bb11-20020a1709070a0b00b009bf9c58e91emr4392989ejc.56.1699558132912; Thu, 09 Nov 2023 11:28:52 -0800 (PST) Received: from m1x-phil.lan ([176.187.199.161]) by smtp.gmail.com with ESMTPSA id g2-20020a1709064e4200b009b2c9476726sm2904753ejw.21.2023.11.09.11.28.51 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 09 Nov 2023 11:28:52 -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?= , Richard Henderson Subject: [PATCH-for-8.2 v4 06/10] hw/char/pl011: Warn when using disabled transmitter Date: Thu, 9 Nov 2023 20:28:10 +0100 Message-ID: <20231109192814.95977-7-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::62d; envelope-from=philmd@linaro.org; helo=mail-ej1-x62d.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=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 We shouldn't transmit characters when the full UART or its transmitter is disabled. However we don't want to break the possibly incomplete "my first bare metal assembly program"s, so we choose to simply display a warning when this occurs. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Alex Bennée Reviewed-by: Richard Henderson --- hw/char/pl011.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/hw/char/pl011.c b/hw/char/pl011.c index 30309337b1..9c43cb47bf 100644 --- a/hw/char/pl011.c +++ b/hw/char/pl011.c @@ -76,6 +76,10 @@ DeviceState *pl011_create(hwaddr addr, qemu_irq irq, Chardev *chr) #define LCR_FEN (1 << 4) #define LCR_BRK (1 << 0) +/* Control Register, UARTCR */ +#define CR_TXE (1 << 8) +#define CR_UARTEN (1 << 0) + static const unsigned char pl011_id_arm[8] = { 0x11, 0x10, 0x14, 0x00, 0x0d, 0xf0, 0x05, 0xb1 }; static const unsigned char pl011_id_luminary[8] = @@ -151,7 +155,12 @@ static inline void pl011_reset_tx_fifo(PL011State *s) static void pl011_write_txdata(PL011State *s, uint8_t data) { - /* ??? Check if transmitter is enabled. */ + if (!(s->cr & CR_UARTEN)) { + qemu_log_mask(LOG_GUEST_ERROR, "PL011 data written to disabled UART\n"); + } + if (!(s->cr & CR_TXE)) { + qemu_log_mask(LOG_GUEST_ERROR, "PL011 data written to disabled TX UART\n"); + } /* XXX this blocks entire thread. Rewrite to use * qemu_chr_fe_write and background I/O callbacks */ From patchwork Thu Nov 9 19:28:11 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: 742602 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:110f:b0:32d:baff:b0ca with SMTP id z15csp1019060wrw; Thu, 9 Nov 2023 11:32:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IEqoKzgWe6hzbwfPRfoMJkS7r9e/dn6IocFKaHcZ2rZoMeSBn61ybQjynmd4jifebxzMjw8 X-Received: by 2002:a05:620a:3712:b0:773:af69:e614 with SMTP id de18-20020a05620a371200b00773af69e614mr6669951qkb.58.1699558336542; Thu, 09 Nov 2023 11:32:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699558336; cv=none; d=google.com; s=arc-20160816; b=yzqPk0NymGQqkRcYlJExFr9lUaDAIWnA6b032XVxE46mEnES8gwMtTQhdDUJJrAyVk 5jYuBAUwn/hHCAB+9iekb/NGru+rp1GcsyAKtU9mOAvRRWp/XK/0M9IEKyWv6Y9Ox5kS 9f4yGZDH0Me1iAhZe9Ngy8s0Z5akXV1b4dWr8X8GK0do47mkh5zF/OB8+ObJ1SaxJwsR rHmdpW5w82zS7bsjf+MICSNMkhHw+u8Sl28aucW/tbZOYDW/2/B1+p3hTow3q1AIN2M+ faga+J49ayJ3QPIaJtKAxzslPO7fFCMfSkBn8EnYT3LeYxPpzIp3+4NSt4eUTxYdvTP6 0bJA== 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=SyyFM5rojPE+uJBRWUA1uUis15hpR5uGCcF147lyuU8=; fh=Zi/lk1CoRxouROvt4Eod7oP2jg68ZE5jz0tOr4SBE9g=; b=ScvCUYiJhy/ZozGWBSgSQjxE5OKHyb74azb8eA89KDFXANUG86RuYv18uglO6wj5F6 dQ0nxfQHlxF1+LT0BujSHv+HK2sHFBbZUN76Eav5ab3lH31A/1Hgey2cbO7Eohi0koVz EgXlDReA9a0fa+lPHa6IgT0JazgIFJSP1GjG4pmbcTvFeCapJVMdhNw50CTeFE4cXrwE CIwxwkwDtaF7enNeU5WTogyymQRoAa90i8WxmqIT5baqxdzqidDmsVKhyvP+pvSaj9jq JdoqkyUwkc2fDVT1a3vrHE3XT7Oc5NETPwd4Qsqum+rPdSBg0QPOQy5lhuWrjtI6HdsZ 5O5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ceWJJSVT; 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 w9-20020a05620a424900b00775a6554b41si3243461qko.285.2023.11.09.11.32.16 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 09 Nov 2023 11:32:16 -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=ceWJJSVT; 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 1r1AiQ-0005wf-5E; Thu, 09 Nov 2023 14:29:22 -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 1r1Ai6-0005Ru-MA for qemu-devel@nongnu.org; Thu, 09 Nov 2023 14:29:04 -0500 Received: from mail-ej1-x629.google.com ([2a00:1450:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r1Ai5-0005J3-58 for qemu-devel@nongnu.org; Thu, 09 Nov 2023 14:29:02 -0500 Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-9c2a0725825so216555366b.2 for ; Thu, 09 Nov 2023 11:29:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699558138; x=1700162938; 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=SyyFM5rojPE+uJBRWUA1uUis15hpR5uGCcF147lyuU8=; b=ceWJJSVTDqh3rVWtpr6FLID8/EGtwSPZfOCpxla5lqrYQx5o8LuqgVLsuI+x9kWjfm tDUiNPz1AsI0xqahGzAeKR7UoUT22pE1lh2Lzs+mHwgcJ20qRWtHHAZggxQoUcF9mN6N f/Ay6ySseUgVFULW6LSOeWLkNRdXFW9Zs/7UvVgtZIgJqO+msBUoE5xirzO+TSbAuIdT T89g69M3uNaLF7g9JMYKBQmwYWvi2VwDGkDXCseUgIdxqjIZgmPzBFawoNED1+jh7+Vl Y4BOZnq6dGKytEU/CHJxwGdD5cyrYpWjOaSoFdoCDSditHlKy/yMd1BaHv5+UbsqEgVG DjLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699558138; x=1700162938; 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=SyyFM5rojPE+uJBRWUA1uUis15hpR5uGCcF147lyuU8=; b=pOYEqV/7pvC15swAJObP1fwqYMJR4bD99PBknWT0keOhYg+83NEfoL2vRkyofImcKv DILEilAFtH8WtoIVhBiQ80XyXTG6QTg8JIfWkyt9eCFEQmmUKsemIEE5QB6oezub9FyO qWFK4cnBVesx8krdjcI1ZNQojJQCw376mLtQyHiROTfGQ34/KLICBimLDfAYrTjuf8Wm Gi4c4wHOvNvEARUwtplSzwAQFXU0DwokGfYv84Fn70WtrBIRa/BoNuBKGR8b8cnPhICc Zu5bwhmJE/eTVi86O1JBh2PIZX1wYgHlmmI9ZjR9FO5wZxlQ+BJMqP/HIG2LYfXARx22 z4kg== X-Gm-Message-State: AOJu0Ywhc/RYpkpZ7kjlvavtGK6LIx14nda+F8XwqW1Bm4PXX388966v AoEXXw6C1qWjzsVQfhslE0tUqY3tVFMF6kwY6EiQFg== X-Received: by 2002:a17:907:96a5:b0:9c5:7f8b:bafc with SMTP id hd37-20020a17090796a500b009c57f8bbafcmr5691609ejc.22.1699558138606; Thu, 09 Nov 2023 11:28:58 -0800 (PST) Received: from m1x-phil.lan ([176.187.199.161]) by smtp.gmail.com with ESMTPSA id s3-20020a1709067b8300b009adc77fe164sm2938523ejo.66.2023.11.09.11.28.57 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 09 Nov 2023 11:28:58 -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?= , Richard Henderson Subject: [PATCH-for-8.2 v4 07/10] hw/char/pl011: Check if receiver is enabled Date: Thu, 9 Nov 2023 20:28:11 +0100 Message-ID: <20231109192814.95977-8-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::629; envelope-from=philmd@linaro.org; helo=mail-ej1-x629.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 Do not receive characters when UART or receiver are disabled. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson --- hw/char/pl011.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/hw/char/pl011.c b/hw/char/pl011.c index 9c43cb47bf..ca931be139 100644 --- a/hw/char/pl011.c +++ b/hw/char/pl011.c @@ -77,6 +77,7 @@ DeviceState *pl011_create(hwaddr addr, qemu_irq irq, Chardev *chr) #define LCR_BRK (1 << 0) /* Control Register, UARTCR */ +#define CR_RXE (1 << 9) #define CR_TXE (1 << 8) #define CR_UARTEN (1 << 0) @@ -359,9 +360,11 @@ static void pl011_write(void *opaque, hwaddr offset, static int pl011_can_receive(void *opaque) { PL011State *s = (PL011State *)opaque; - int r; + int r = 0; - r = s->read_count < pl011_get_fifo_depth(s); + if ((s->cr & CR_UARTEN) && (s->cr & CR_RXE)) { + r = s->read_count < pl011_get_fifo_depth(s); + } trace_pl011_can_receive(s->lcr, s->read_count, r); return r; } From patchwork Thu Nov 9 19:28:12 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: 742604 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:110f:b0:32d:baff:b0ca with SMTP id z15csp1019109wrw; Thu, 9 Nov 2023 11:32:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IFinOqwdqz1xuO1KBPGn8iKn/R9y7RSOxMU9SoIJAw22bZzdMsmBOZDikWwesMka9si/PNu X-Received: by 2002:a05:6102:2006:b0:45d:a27a:7e8c with SMTP id p6-20020a056102200600b0045da27a7e8cmr6027097vsr.23.1699558343249; Thu, 09 Nov 2023 11:32:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699558343; cv=none; d=google.com; s=arc-20160816; b=yF3zVajE1AjziPwQMTYB/4e0Tz1tluTgZoyKNitKGSejRS95gbGmtROlBiEw26hCA2 gMQgvtVunylOUp4ybPe29G5kJl159mF9Xhc/RH+hZVrIksziE9kCMsKS7cOsghTgFbxX R9nAETgeIdUbuTRUJbym4ntlkoTOf8+kk19pIpW4MDnqIggqdxAmi3VnsXbI97kAifJi iYF45VhVCwYh5knzHIQhuayFMhOYmPur3ZMMYF5grJE/v/B1mAKKTJ19aReTK+NsDzl0 O2qKClgOxGsk7A2uONMYVFr4wS74PYn2q2XZDsNrF+YtbGBKGTaiScQqez67SFP15Cib 2aBw== 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=RHS4Z4THTDrdonuMomFxK3JmiClhr4y8badmiGx38uU=; fh=Zi/lk1CoRxouROvt4Eod7oP2jg68ZE5jz0tOr4SBE9g=; b=ub52ej1Fom6EnAg/1Z2u8GSf7VjrNyJfaeDj71G1qEsdmICLOw41rNKQXjG3wW/LTE kC3KhfHVE5/4Gz7J2Vv9+0owaegM5obzgvJzhzRsJBjNBpSTPuBdjnvpCJpev038xpyO DJgATyiMuhsnbfiKZ83MC2RUr1DzmzOv41zYRgnhSbeRJq5qKcUu9r/YhiOYCMWK0D/r lhQwXLDGIQNCDvfxlpMdFVwto76NtqMpzcHk979gmn1u/1fKi6ZfpBuYXKzl57gxAwt0 fD9+fcUWB1Y+lZygXbvP1d7bWd8bbLqfWbc9dCTlgAiL8FcmsJPjdfDTtcRFtRyZOXLH MUtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=srhFSKYF; 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 h3-20020ad45443000000b00647290d544bsi3360374qvt.296.2023.11.09.11.32.22 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 09 Nov 2023 11:32:23 -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=srhFSKYF; 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 1r1AiQ-0005yb-CJ; Thu, 09 Nov 2023 14:29:22 -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 1r1AiC-0005Zw-HD for qemu-devel@nongnu.org; Thu, 09 Nov 2023 14:29:13 -0500 Received: from mail-ej1-x62d.google.com ([2a00:1450:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r1AiA-0005Nk-BZ for qemu-devel@nongnu.org; Thu, 09 Nov 2023 14:29:08 -0500 Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-9e213f198dfso217183666b.2 for ; Thu, 09 Nov 2023 11:29:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699558145; x=1700162945; 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=RHS4Z4THTDrdonuMomFxK3JmiClhr4y8badmiGx38uU=; b=srhFSKYFdWB0BPPj3McGWeBEDt1J5YjW8dFWpWiphF45b8D2hC4I20hFhnQGv+hEs0 YlF38S6XfE9Oz5A2LtyLZI19U6UiTDQI0C+NCOr1ZOOckmx5NhZtTWq+JOqIWTFDHIs4 q5iBSYHtn0RhTuJHMHwMRdni3fJkJTKe69jys+vPAel/y5Ujv7ZFaT2jKBM8d67ORb+S b4gNnvvxAhdMBk2rouzly41OFeLvbZSW8KkWHwUxmmn9PKcBAZ1PbL5/dXeqV7GBP9vm 5JC9UwsIrvVjIpfPp6WvzBMm3sXm5ld27DwxSTCavLccXIydT+57sPpqwkDqoTYlX2ah eqSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699558145; x=1700162945; 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=RHS4Z4THTDrdonuMomFxK3JmiClhr4y8badmiGx38uU=; b=D57OKciEPsUuZqK9I9Uqdeq5WtUur+EE/EYIRfx46Z0fbbg+xvHGf2OrjdhxVSVAbH CZjQp1lVfhzlsW5+j3tcyEzb+Ucn0P3CH/84cP+TxGHsOJtsiwIS2aMMqnAggZzAHg0t 3S7JTvGVdoqqHCfU15HWgvFT0tMAKamrnfeFQdaA9IXWwCc7u2u7fy7vg+L8QiweCK1G JfNn3NATKW6+rFEBenYmgG7zdL8/pSQW5RMW7uA8IHFvv/60O5l11qBwEEOnUdlh/FHt cyAnqzNbIcaxxwQy6R9tbhQOWp0gxg9Br0gC+PFaLIDdiDFpxFiGsHX161yBCX+81tYE 17LQ== X-Gm-Message-State: AOJu0YzrRCwKyLQiE5pB7Wiip/J2nxCysGqcm4f3WDUL9y0G3GWSjVqC ZLvWdSfJ2nUFcJuE1QjYirJiRnvaWIHTOtJRutVyJg== X-Received: by 2002:a17:907:9304:b0:9c7:5186:de1a with SMTP id bu4-20020a170907930400b009c75186de1amr5108548ejc.8.1699558144629; Thu, 09 Nov 2023 11:29:04 -0800 (PST) Received: from m1x-phil.lan ([176.187.199.161]) by smtp.gmail.com with ESMTPSA id l22-20020a17090612d600b009c3828fec06sm2914829ejb.81.2023.11.09.11.29.03 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 09 Nov 2023 11:29:04 -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?= , Richard Henderson Subject: [PATCH-for-8.2 v4 08/10] hw/char/pl011: Rename RX FIFO methods Date: Thu, 9 Nov 2023 20:28:12 +0100 Message-ID: <20231109192814.95977-9-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::62d; envelope-from=philmd@linaro.org; helo=mail-ej1-x62d.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=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 preparation of having a TX FIFO, rename the RX FIFO methods. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Alex Bennée Reviewed-by: Richard Henderson --- hw/char/pl011.c | 10 +++++----- hw/char/trace-events | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/hw/char/pl011.c b/hw/char/pl011.c index ca931be139..727decd428 100644 --- a/hw/char/pl011.c +++ b/hw/char/pl011.c @@ -369,7 +369,7 @@ static int pl011_can_receive(void *opaque) return r; } -static void pl011_put_fifo(void *opaque, uint32_t value) +static void pl011_fifo_rx_put(void *opaque, uint32_t value) { PL011State *s = (PL011State *)opaque; int slot; @@ -380,9 +380,9 @@ static void pl011_put_fifo(void *opaque, uint32_t value) s->read_fifo[slot] = value; s->read_count++; s->flags &= ~PL011_FLAG_RXFE; - trace_pl011_put_fifo(value, s->read_count); + trace_pl011_fifo_rx_put(value, s->read_count); if (s->read_count == pipe_depth) { - trace_pl011_put_fifo_full(); + trace_pl011_fifo_rx_full(); s->flags |= PL011_FLAG_RXFF; } if (s->read_count == s->read_trigger) { @@ -393,13 +393,13 @@ static void pl011_put_fifo(void *opaque, uint32_t value) static void pl011_receive(void *opaque, const uint8_t *buf, int size) { - pl011_put_fifo(opaque, *buf); + pl011_fifo_rx_put(opaque, *buf); } static void pl011_event(void *opaque, QEMUChrEvent event) { if (event == CHR_EVENT_BREAK) { - pl011_put_fifo(opaque, DR_BE); + pl011_fifo_rx_put(opaque, DR_BE); } } diff --git a/hw/char/trace-events b/hw/char/trace-events index 7a398c82a5..bc9e84261f 100644 --- a/hw/char/trace-events +++ b/hw/char/trace-events @@ -58,8 +58,8 @@ pl011_read(uint32_t addr, uint32_t value, const char *regname) "addr 0x%03x valu pl011_read_fifo(int read_count) "FIFO read, read_count now %d" pl011_write(uint32_t addr, uint32_t value, const char *regname) "addr 0x%03x value 0x%08x reg %s" pl011_can_receive(uint32_t lcr, int read_count, int r) "LCR 0x%08x read_count %d returning %d" -pl011_put_fifo(uint32_t c, int read_count) "new char 0x%x read_count now %d" -pl011_put_fifo_full(void) "FIFO now full, RXFF set" +pl011_fifo_rx_put(uint32_t c, int read_count) "new char 0x%02x read_count now %d" +pl011_fifo_rx_full(void) "RX FIFO now full, RXFF set" pl011_baudrate_change(unsigned int baudrate, uint64_t clock, uint32_t ibrd, uint32_t fbrd) "new baudrate %u (clk: %" PRIu64 "hz, ibrd: %" PRIu32 ", fbrd: %" PRIu32 ")" # cmsdk-apb-uart.c 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, }; From patchwork Thu Nov 9 19:28:14 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: 742595 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:110f:b0:32d:baff:b0ca with SMTP id z15csp1017883wrw; Thu, 9 Nov 2023 11:29:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IFPLceJoJa1XrD//pZCRc3PvArQhBN4i2+AZwTurynZUPyddWHHOmz5gEVtBGxMJWk/Ph+c X-Received: by 2002:a05:6214:501c:b0:658:9565:9736 with SMTP id jo28-20020a056214501c00b0065895659736mr7877626qvb.56.1699558177132; Thu, 09 Nov 2023 11:29:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699558177; cv=none; d=google.com; s=arc-20160816; b=vuNbOHbmSsxHiVtBqt3sF6eYJQU/AsXhOxw44nIE9m5EKKNLXTOUpPgiEinIf2QAE3 8eHruSsk+LO5NHu+ukIkEHP6IZFRbr2546yq6aoJvCcMbzyv16RUN0gvHicB3r9Fg5kS pvCqHcqAZfTLGlUL1h5ahAvwpgHYQbs7Dr3UcuUXASgBY3X7MN+3YAY4gdAq1qLOOhB9 aDC3Gu89qxCix9dldxGXzOL7KxlSysNna/ZUBsz5V9gu4wcijpwg1ljHPcVWrFXcK13D 6fEThrFgadt2MKy43vzeJIyBy73LoYguWqp9bp+cCPFHbOPMbGna/5leeZ+YBrBRcA+9 P9ug== 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=L0ZgfFAgA7ypETy4OWUsXUiUb+FjTb/S73XLff6YN2Y=; fh=n7joC1En9kOODo5cknOnlSvmXvqw4rwZKjGMK8wqNNM=; b=iETp+I49a2+F2/7QtiQ2eUvjM9cA7RhWVWqe28I8ZnNhR1XUSqJboFDTUNAjIwx69B YMhnK8XwzzjPeIE/TD3MzNeaErbbuSP6P0hQfO2VP1HZ8FJEyA8Ml3uVG8VfHDiTV3Pl 89N8/ctQzCHLtv4HSNzp2pDV2UUCMIAsR9jASlqyBGWNgcyAxESqd59+lz9YOzWsOdcR buB5LhwlIx0xVIRYjLpD8QmsHtLx3X2hoolLjnrONq1wbR7gDZRxOvC1lKuFGnIsQNCd L9S9gCREy3u5QSexRpxwCulV/OXlQTZ1svwX6EYrBTFDP4exyWC28vazjOnDQqZjwoHd zztA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=v3mqpWyB; 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 pv19-20020ad45493000000b0066d08ac0ba0si3311968qvb.230.2023.11.09.11.29.36 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 09 Nov 2023 11:29: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=v3mqpWyB; 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 1r1AiS-0006LR-Hi; Thu, 09 Nov 2023 14:29:24 -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 1r1AiP-0005rH-Ej for qemu-devel@nongnu.org; Thu, 09 Nov 2023 14:29:21 -0500 Received: from mail-ej1-x629.google.com ([2a00:1450:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r1AiM-0005Os-P0 for qemu-devel@nongnu.org; Thu, 09 Nov 2023 14:29:20 -0500 Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-9dd6dc9c00cso216087366b.3 for ; Thu, 09 Nov 2023 11:29:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699558157; x=1700162957; 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=L0ZgfFAgA7ypETy4OWUsXUiUb+FjTb/S73XLff6YN2Y=; b=v3mqpWyBsXXej/2han14VNwj7ZGHEFIRdaiWj0FRkbUWrH6SlEDfkky/bVDJZor1EV dlivelR41Btds7kJLU3GtWq/OLC9PWOR0Ij7tHBuk5lmN1gs1vJv0q9d8C87hVlJc6+r 44OdAIFhDVfRiUmPcRxb1BpGnnmqpgbUMIqBQkjBYW7tiAADH2Z3M2Cq8RlFh0ri7953 z4H92+iJSydoxA93hHvVPalTu+cP/iHgznBLl99C9CpJ18+95fO76CwHybKBLh7RIcSG dqTZZ0PVr82sSF5B7dG+wKOPcPUEZ3Sd8GRLMs6BQKLxU91kR106rMqgT3qFjjAL5BfH Ymig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699558157; x=1700162957; 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=L0ZgfFAgA7ypETy4OWUsXUiUb+FjTb/S73XLff6YN2Y=; b=AYTMAVb8aHOWfH5FRC9KNI1jFjG8Jke5D4D11fqoxAhf0T4B4laUiZ2nEhthL2nbHy bfa49Eye5XWFsTs0VDiOOWpcZOhGSxKaSUt0pRE5NZ6Zm2WvQb4sxvO+SHc89GIYaEjy dGVBnQtO4gkECjerRnTrBhUclHKRHaXpQ3KuAL9sDzP4FgmknUUHPhMI1ilxEbFz4vDI f0BgSD1IquGdXTD6C6epEJTngd9TBFJDbK9UfO/rsY17I+kWik0OhK/kC3V/4fiKCCFZ rBkT3PG+QH7lATUfPtQNGNut3e3aEUbJkmfBbGrJXXqi4N4QKfSLESvGD1CbBluc7JhL FD3w== X-Gm-Message-State: AOJu0YwhUlF0SHag5UFGu/YUtf90gE6l+YcHb+SmybXdmVkDi4xA3qBy jBapiV9r+KAxg4IbH4uMpZ2KAozKQOAEVr4JA8M5CQ== X-Received: by 2002:a17:907:3e1c:b0:9b2:d554:da0e with SMTP id hp28-20020a1709073e1c00b009b2d554da0emr5818301ejc.69.1699558157027; Thu, 09 Nov 2023 11:29:17 -0800 (PST) Received: from m1x-phil.lan ([176.187.199.161]) by smtp.gmail.com with ESMTPSA id f4-20020a170906048400b00988e953a586sm2933836eja.61.2023.11.09.11.29.15 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 09 Nov 2023 11:29:16 -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?= , Mikko Rapeli Subject: [PATCH-for-8.2 v4 10/10] hw/char/pl011: Implement TX FIFO Date: Thu, 9 Nov 2023 20:28:14 +0100 Message-ID: <20231109192814.95977-11-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::629; envelope-from=philmd@linaro.org; helo=mail-ej1-x629.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 If the UART back-end chardev doesn't drain data as fast as stdout does or blocks, buffer in the TX FIFO to try again later. This avoids having the IO-thread busy waiting on chardev back-ends, reported recently when testing the Trusted Reference Stack and using the socket backend: https://linaro.atlassian.net/browse/TRS-149?focusedCommentId=149574 Implement registering a front-end 'watch' callback on back-end events, so we can resume transmitting when the back-end is writable again, not blocking the main loop. Similarly to the RX FIFO path, FIFO level selection is not implemented (interrupt is triggered when a single byte is available in the FIFO). We only migrate the TX FIFO if it is in use. Reported-by: Mikko Rapeli Suggested-by: Alex Bennée Signed-off-by: Philippe Mathieu-Daudé --- hw/char/pl011.c | 107 ++++++++++++++++++++++++++++++++++++++++--- hw/char/trace-events | 4 ++ 2 files changed, 105 insertions(+), 6 deletions(-) diff --git a/hw/char/pl011.c b/hw/char/pl011.c index f474f56780..a14ece4f07 100644 --- a/hw/char/pl011.c +++ b/hw/char/pl011.c @@ -57,6 +57,9 @@ DeviceState *pl011_create(hwaddr addr, qemu_irq irq, Chardev *chr) /* Data Register, UARTDR */ #define DR_BE (1 << 10) +/* Receive Status Register/Error Clear Register, UARTRSR/UARTECR */ +#define RSR_OE (1 << 3) + /* Interrupt status bits in UARTRIS, UARTMIS, UARTIMSC */ #define INT_OE (1 << 10) #define INT_BE (1 << 9) @@ -156,6 +159,68 @@ static void pl011_reset_tx_fifo(PL011State *s) fifo8_reset(&s->xmit_fifo); } +static gboolean pl011_drain_tx(PL011State *s) +{ + trace_pl011_fifo_tx_drain(fifo8_num_used(&s->xmit_fifo)); + pl011_reset_tx_fifo(s); + s->rsr &= ~RSR_OE; + return G_SOURCE_REMOVE; +} + +static gboolean pl011_xmit(void *do_not_use, GIOCondition cond, void *opaque) +{ + PL011State *s = opaque; + int ret; + const uint8_t *buf; + uint32_t buflen; + uint32_t count; + bool tx_enabled; + + tx_enabled = (s->cr & CR_UARTEN) && (s->cr & CR_TXE); + if (!tx_enabled) { + /* + * If TX is disabled, nothing to do. + * Keep the potentially used FIFO as is. + */ + return G_SOURCE_REMOVE; + } + + if (!qemu_chr_fe_backend_connected(&s->chr)) { + /* Instant drain the fifo when there's no back-end */ + return pl011_drain_tx(s); + } + + count = fifo8_num_used(&s->xmit_fifo); + if (count < 1) { + /* FIFO empty */ + return G_SOURCE_REMOVE; + } + + /* Transmit as much data as we can */ + buf = fifo8_peek_buf(&s->xmit_fifo, count, &buflen); + ret = qemu_chr_fe_write(&s->chr, buf, buflen); + if (ret >= 0) { + /* Pop the data we could transmit */ + trace_pl011_fifo_tx_xmit(ret); + fifo8_pop_buf(&s->xmit_fifo, ret, NULL); + s->int_level |= INT_TX; + } + + if (!fifo8_is_empty(&s->xmit_fifo)) { + /* Reschedule another transmission if we couldn't transmit all */ + guint r = qemu_chr_fe_add_watch(&s->chr, G_IO_OUT | G_IO_HUP, + pl011_xmit, s); + if (!r) { + /* Error in back-end? */ + return pl011_drain_tx(s); + } + } + + pl011_update(s); + + return G_SOURCE_REMOVE; +} + static void pl011_write_txdata(PL011State *s, uint8_t data) { if (!(s->cr & CR_UARTEN)) { @@ -165,11 +230,25 @@ static void pl011_write_txdata(PL011State *s, uint8_t data) qemu_log_mask(LOG_GUEST_ERROR, "PL011 data written to disabled TX UART\n"); } - /* XXX this blocks entire thread. Rewrite to use - * qemu_chr_fe_write and background I/O callbacks */ - qemu_chr_fe_write_all(&s->chr, &data, 1); - s->int_level |= INT_TX; - pl011_update(s); + if (fifo8_is_full(&s->xmit_fifo)) { + /* + * The FIFO contents remain valid because no more data is + * written when the FIFO is full, only the contents of the + * shift register are overwritten. The CPU must now read + * the data, to empty the FIFO. + */ + trace_pl011_fifo_tx_overrun(); + s->rsr |= RSR_OE; + return; + } + + trace_pl011_fifo_tx_put(data); + fifo8_push(&s->xmit_fifo, data); + if (fifo8_is_full(&s->xmit_fifo)) { + s->flags |= PL011_FLAG_TXFF; + } + + pl011_xmit(NULL, G_IO_OUT, s); } static uint32_t pl011_read_rxdata(PL011State *s) @@ -331,10 +410,21 @@ static void pl011_write(void *opaque, hwaddr offset, s->lcr = value; pl011_set_read_trigger(s); break; - case 12: /* UARTCR */ + case 12: /* UARTCR */ { + uint16_t en_bits = s->cr & (CR_UARTEN | CR_TXE | CR_RXE); + uint16_t dis_bits = value & (CR_UARTEN | CR_TXE | CR_RXE); + if (en_bits ^ dis_bits && !fifo8_is_empty(&s->xmit_fifo)) { + /* + * If the UART is disabled in the middle of transmission + * or reception, it completes the current character before + * stopping. + */ + pl011_xmit(NULL, G_IO_OUT, s); + } /* ??? Need to implement the enable and loopback bits. */ s->cr = value; break; + } case 13: /* UARTIFS */ s->ifl = value; pl011_set_read_trigger(s); @@ -477,6 +567,11 @@ static int pl011_post_load(void *opaque, int version_id) s->read_pos = 0; } + if (!fifo8_is_empty(&s->xmit_fifo)) { + /* Reschedule another transmission */ + qemu_chr_fe_add_watch(&s->chr, G_IO_OUT | G_IO_HUP, pl011_xmit, s); + } + return 0; } diff --git a/hw/char/trace-events b/hw/char/trace-events index bc9e84261f..ee00af0c66 100644 --- a/hw/char/trace-events +++ b/hw/char/trace-events @@ -60,6 +60,10 @@ pl011_write(uint32_t addr, uint32_t value, const char *regname) "addr 0x%03x val pl011_can_receive(uint32_t lcr, int read_count, int r) "LCR 0x%08x read_count %d returning %d" pl011_fifo_rx_put(uint32_t c, int read_count) "new char 0x%02x read_count now %d" pl011_fifo_rx_full(void) "RX FIFO now full, RXFF set" +pl011_fifo_tx_put(uint8_t byte) "TX FIFO push [0x%02x]" +pl011_fifo_tx_xmit(int count) "TX FIFO pop %d" +pl011_fifo_tx_overrun(void) "TX FIFO overrun" +pl011_fifo_tx_drain(unsigned drained) "TX FIFO draining %u" pl011_baudrate_change(unsigned int baudrate, uint64_t clock, uint32_t ibrd, uint32_t fbrd) "new baudrate %u (clk: %" PRIu64 "hz, ibrd: %" PRIu32 ", fbrd: %" PRIu32 ")" # cmsdk-apb-uart.c