From nobody Tue Apr 23 15:01:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) client-ip=78.46.105.101; envelope-from=seabios-bounces@seabios.org; helo=coreboot.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=fail(p=none dis=none) header.from=koconnor.net Return-Path: Received: from coreboot.org (coreboot.org [78.46.105.101]) by mx.zohomail.com with SMTPS id 1642617962875167.74273774473977; Wed, 19 Jan 2022 10:46:02 -0800 (PST) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id E020916E3F89; Wed, 19 Jan 2022 18:45:58 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTP id CB54516E36D3 for ; Wed, 19 Jan 2022 18:45:22 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) for ; Wed, 19 Jan 2022 10:45:22 -0800 (PST) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by smtp.gmail.com with ESMTPSA id j11sm124388qtj.90.2022.01.19.10.45.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jan 2022 10:45:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=koconnor.net; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=iRXZAeeE8Xrmw2/97NMqAk9/OYKXF/Cb1IwPmQn9IcU=; b=LbtKH7Ky8OtINuXCCEj9bVkRDhWduphWqqeAKJJnY96vQR2G6iU7j/BGP2YZJF4H3G ocHBvRhggfZx8Ryp4n2D5/SjPeEoyNB0GuU9lMi/2+2nNhlemoH0LKS+WDDNTLKDSEA1 tvPnR6NXGP7G598El2hBQdGKmn21VVh58zk2E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=iRXZAeeE8Xrmw2/97NMqAk9/OYKXF/Cb1IwPmQn9IcU=; b=DaytfxsFZ1kaplvpyn/Ku/sbFoiyifWRmA+zVrIocSgxeWe7X+GA3y3vjhlKL7hCrc 46FhQgGpZglMbHWwrh7uviyoThqXCZndDSNSkxaDSy63dW8sa0oXLjNEdKGt/2arvd4Y cS11hvA0ze82zRfOjjw3g+v8g5BXvWQDFpyavEudTdJvr7YxQigRRi1Y8fUnIaQsGZPF Z1OmdOeGm0jU4gYtV0O9/+jAyQhYxN4bZGDkbywXUYBEgDBcFiTasv1X6SfydaQSZmS6 fCwcyZfte6wiyMhuY+wBNPE08TPyVWZarfRb4WnF1KV/19R86ln0/aRVjXMb0uGJv5o2 ghvQ== X-Gm-Message-State: AOAM532VtyZnk7Iv8PVYNpmoJLCtFRFXQ2V65WPDjgd5Qzd7ZhFjp/wS bM1OcNK19Ashg806heN0S1P8nvLbrSKgzQ== X-Google-Smtp-Source: ABdhPJx8prP+qpwwDvonMZoZX9zVuDyeRWY0OEdZmb4cjG0HKk4WUnjIXWaGdC9PFubwl88SL1kOOw== X-Received: by 2002:ac8:4e50:: with SMTP id e16mr16894799qtw.211.1642617921655; Wed, 19 Jan 2022 10:45:21 -0800 (PST) From: Kevin O'Connor To: seabios@seabios.org Date: Wed, 19 Jan 2022 13:45:10 -0500 Message-Id: <20220119184513.1828156-3-kevin@koconnor.net> In-Reply-To: <20220119184513.1828156-1-kevin@koconnor.net> References: <20220119184513.1828156-1-kevin@koconnor.net> MIME-Version: 1.0 X-Spam-Level: * Message-ID-Hash: CNEKUHAUNGIYVEARMYSJ7CJAXQZ4U6IR X-Message-ID-Hash: CNEKUHAUNGIYVEARMYSJ7CJAXQZ4U6IR X-MailFrom: kevin@koconnor.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-seabios.seabios.org-0; header-match-seabios.seabios.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.5rc1 Precedence: list Subject: [SeaBIOS] [PATCH 2/5] nvme: Add nvme_bounce_xfer() helper function List-Id: SeaBIOS mailing list Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable Authentication-Results: coreboot.org; auth=pass smtp.auth=mailman@coreboot.org smtp.mailfrom=seabios-bounces@seabios.org X-Spamd-Bar: --- X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1642617964791100001 Content-Type: text/plain; charset="utf-8" Move bounce buffer processing to a new helper function. Signed-off-by: Kevin O'Connor Reviewed-by: Alexander Graf --- src/hw/nvme.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/hw/nvme.c b/src/hw/nvme.c index a97501b..fd7c1d0 100644 --- a/src/hw/nvme.c +++ b/src/hw/nvme.c @@ -465,6 +465,25 @@ nvme_io_xfer(struct nvme_namespace *ns, u64 lba, void = *buf, u16 count, return count; } =20 +// Transfer up to one page of data using the internal dma bounce buffer +static int +nvme_bounce_xfer(struct nvme_namespace *ns, u64 lba, void *buf, u16 count, + int write) +{ + u16 const max_blocks =3D NVME_PAGE_SIZE / ns->block_size; + u16 blocks =3D count < max_blocks ? count : max_blocks; + + if (write) + memcpy(ns->dma_buffer, buf, blocks * ns->block_size); + + int res =3D nvme_io_xfer(ns, lba, ns->dma_buffer, blocks, write); + + if (!write && res >=3D 0) + memcpy(buf, ns->dma_buffer, res * ns->block_size); + + return res; +} + static void nvme_reset_prpl(struct nvme_namespace *ns) { ns->prpl_len =3D 0; @@ -718,7 +737,6 @@ nvme_scan(void) static int nvme_cmd_readwrite(struct nvme_namespace *ns, struct disk_op_s *op, int wr= ite) { - u16 const max_blocks =3D NVME_PAGE_SIZE / ns->block_size; u16 i, blocks; =20 for (i =3D 0; i < op->count;) { @@ -731,21 +749,10 @@ nvme_cmd_readwrite(struct nvme_namespace *ns, struct = disk_op_s *op, int write) if (res < 0) return DISK_RET_EBADTRACK; } else { - blocks =3D blocks_remaining < max_blocks ? blocks_remaining - : max_blocks; - - if (write) { - memcpy(ns->dma_buffer, op_buf, blocks * ns->block_size); - } - - int res =3D nvme_io_xfer(ns, op->lba + i, ns->dma_buffer, - blocks, write); + int res =3D nvme_bounce_xfer(ns, op->lba + i, op_buf, blocks, = write); if (res < 0) return DISK_RET_EBADTRACK; - - if (!write) { - memcpy(op_buf, ns->dma_buffer, blocks * ns->block_size); - } + blocks =3D res; } =20 i +=3D blocks; --=20 2.31.1 _______________________________________________ SeaBIOS mailing list -- seabios@seabios.org To unsubscribe send an email to seabios-leave@seabios.org