From nobody Mon Sep 16 19:49:23 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 16427837777166.761083707746025; Fri, 21 Jan 2022 08:49:37 -0800 (PST) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id E046616E4191; Fri, 21 Jan 2022 16:49:33 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTP id 35D3816E3D81 for ; Fri, 21 Jan 2022 16:48:53 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) for ; Fri, 21 Jan 2022 08:48:53 -0800 (PST) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by smtp.gmail.com with ESMTPSA id d8sm3480466qtd.70.2022.01.21.08.48.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jan 2022 08:48:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=koconnor.net; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LOKd+qQzuaC1bfJvJ4wRj7PQ2Gg8BD4v/mdBvCmQ4uA=; b=eJhuqPIODKKRhkEyguWuvqzjPXevuyXuL6V2DIpONKy3uLvqeF9naZYN4DuD26TEFk 1bsyNacUlN1LOQSmlvo2K7p54KK2WxnA2hGK9hXlq5LDXE8XF3pOZZaIxtZzVXhllRIN fM/KQYv5GVk+ZglFYOJkCzc9p4XL7iNSY+Glc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LOKd+qQzuaC1bfJvJ4wRj7PQ2Gg8BD4v/mdBvCmQ4uA=; b=S+OPdPGS2UgtIZRCbg/PZjS87JZKFpUR9mYKelqGU57GFh1UP6SajDScldTG/uzVtn 5cgKYwHCGs+uyt0nMmPBghV81MTT5MU6YQGHyBP6GVtJEea4XDi9/3wukMpgEzSKJhVk aPSPK5XLDTt5Nk5m5aMGkJKxi7HgeYCT7BubIFytHS+X5gN1E2RDfjHC5wFLlVOi2616 +ytSJ0Dw6XjCYx8YzbyTanXJmtDE6K76pcFYq68leyRJU6W38DLvcpmuO/2s5TEc0sJN XHEaiH+o1V8yzkVjbc+unedxgieYZKxw2A5eX0ieSB+0iVATKEOGbn4p2PILb4s7gfy3 KCGA== X-Gm-Message-State: AOAM531uCinNCdxnMiODiorDKsCggIDUBCZilyW4mr2xnHcYUQ/qTiBM zOvt72xWC0sibf88O3A3qLNP2WHWvvm9oA== X-Google-Smtp-Source: ABdhPJyDZDf/LQxNpOQJ/hdnO1vYzH5RhEJctGVAh49ZbyjPm4RPhUNbuQdsOPwuomTJDGcSEAbp5g== X-Received: by 2002:ad4:4589:: with SMTP id x9mr4556814qvu.27.1642783732013; Fri, 21 Jan 2022 08:48:52 -0800 (PST) From: Kevin O'Connor To: seabios@seabios.org Date: Fri, 21 Jan 2022 11:48:44 -0500 Message-Id: <20220121164848.2000294-3-kevin@koconnor.net> In-Reply-To: <20220121164848.2000294-1-kevin@koconnor.net> References: <20220121164848.2000294-1-kevin@koconnor.net> MIME-Version: 1.0 X-Spam-Level: ** Message-ID-Hash: AJCGQ5V47LPTOZDUTCV24QM7QDNXWA4V X-Message-ID-Hash: AJCGQ5V47LPTOZDUTCV24QM7QDNXWA4V 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 CC: Alexander Graf X-Mailman-Version: 3.3.5rc1 Precedence: list Subject: [SeaBIOS] [PATCHv2 2/6] 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: 1642783779432100001 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 608651a..d656e9b 100644 --- a/src/hw/nvme.c +++ b/src/hw/nvme.c @@ -464,6 +464,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; @@ -717,7 +736,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;) { @@ -730,21 +748,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