From nobody Mon Dec 8 00:25:50 2025 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 1642783831890984.7702897801429; Fri, 21 Jan 2022 08:50:31 -0800 (PST) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id 162EF16E419D; Fri, 21 Jan 2022 16:50:27 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTP id 7BC9116E3D81 for ; Fri, 21 Jan 2022 16:48:56 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) for ; Fri, 21 Jan 2022 08:48:56 -0800 (PST) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by smtp.gmail.com with ESMTPSA id p6sm3627180qtx.18.2022.01.21.08.48.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jan 2022 08:48:55 -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=Q9OeCqGWbJcrFbFvXcyGUxfOzdbCz53k1ku2h+yjmIQ=; b=OflhOjl3t52UQcNDuaW30h2D1HoktvXba6zFXoCKpaRkykLVFvt6taodHBFc+lOfYT 3pK0lcFYO940666Ud8KN8WbrrnhVV6jOKXBcmyXuKN5ScSxccZXG0G2B0p4FXq4l12Ch YQVggmhhf12cTzFmkJXQr1cW0Sac6u/Lyr7dI= 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=Q9OeCqGWbJcrFbFvXcyGUxfOzdbCz53k1ku2h+yjmIQ=; b=SL+u7GVeTRc6gW9n1hLrL8pM/3cDWbYvgaO4wReYKZZiPpjM9KF0Yl6Tg7XQcAsfzC RiASeRJS1OZQpAccms2gQuK5SW4iCE9KVu+a4wcCBvbPzzhbYuoxBQYmAeWyhBMtB5IB yFN7kqaHK611xEyjrNaQi7hWOCAmF4PX+l/H2AW3aiTJuGK/89FAc0/xsvuaTvXkmcIC nbeYRxuHVo+Wc7D88TN7veN2PKfOGPEtM5caWLHszPiAK6s+ajPtBIaU1FmgzfSm4Zlo oB7o/mkipSwjml74PCCtre++hjGVAVvhDjt3kGQrVRNcH4RoWpnqmW0bQs5uVvvcggwQ sVig== X-Gm-Message-State: AOAM531Lpabn3VHbsRD3O7A6dYLyRK8fIqiqXw0rbBz9VbsB/iSC4Ged YxKe8ttP3bToRn93Cb6oArcvW1xsOkNzAQ== X-Google-Smtp-Source: ABdhPJzwFEtz9DAyxbnoYUL48D1cvvrg6uH25g6g2wnAd7fm/5CnI8dWWBpwsymFn3UkqsHjVt6cpQ== X-Received: by 2002:a05:622a:4d1:: with SMTP id q17mr3855853qtx.593.1642783735409; Fri, 21 Jan 2022 08:48:55 -0800 (PST) From: Kevin O'Connor To: seabios@seabios.org Date: Fri, 21 Jan 2022 11:48:48 -0500 Message-Id: <20220121164848.2000294-7-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: KR4XCBQEZ5UMSC7I4M5AAKTXBZHYYKH5 X-Message-ID-Hash: KR4XCBQEZ5UMSC7I4M5AAKTXBZHYYKH5 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 6/6] nvme: Only allocate one dma bounce buffer for all nvme drives 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: 1642783833679100001 Content-Type: text/plain; charset="utf-8" There is no need to create multiple dma bounce buffers as the BIOS disk code isn't reentrant capable. Also, verify that the allocation succeeds. Signed-off-by: Kevin O'Connor Reviewed-by: Alexander Graf --- src/hw/nvme-int.h | 3 --- src/hw/nvme.c | 21 +++++++++++++++------ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/hw/nvme-int.h b/src/hw/nvme-int.h index f0d717d..f9c807e 100644 --- a/src/hw/nvme-int.h +++ b/src/hw/nvme-int.h @@ -117,9 +117,6 @@ struct nvme_namespace { u32 block_size; u32 metadata_size; u32 max_req_size; - - /* Page aligned buffer of size NVME_PAGE_SIZE. */ - char *dma_buffer; }; =20 /* Data structures for NVMe admin identify commands */ diff --git a/src/hw/nvme.c b/src/hw/nvme.c index e9c449d..3dfa0ce 100644 --- a/src/hw/nvme.c +++ b/src/hw/nvme.c @@ -20,6 +20,9 @@ #include "nvme.h" #include "nvme-int.h" =20 +// Page aligned "dma bounce buffer" of size NVME_PAGE_SIZE in high memory +static void *nvme_dma_buffer; + static void * zalloc_page_aligned(struct zone_s *zone, u32 size) { @@ -257,6 +260,14 @@ nvme_probe_ns(struct nvme_ctrl *ctrl, u32 ns_idx, u8 m= dts) goto free_buffer; } =20 + if (!nvme_dma_buffer) { + nvme_dma_buffer =3D zalloc_page_aligned(&ZoneHigh, NVME_PAGE_SIZE); + if (!nvme_dma_buffer) { + warn_noalloc(); + goto free_buffer; + } + } + struct nvme_namespace *ns =3D malloc_fseg(sizeof(*ns)); if (!ns) { warn_noalloc(); @@ -294,8 +305,6 @@ nvme_probe_ns(struct nvme_ctrl *ctrl, u32 ns_idx, u8 md= ts) ns->max_req_size =3D -1U; } =20 - ns->dma_buffer =3D zalloc_page_aligned(&ZoneHigh, NVME_PAGE_SIZE); - char *desc =3D znprintf(MAXDESCSIZE, "NVMe NS %u: %llu MiB (%llu %u-by= te " "blocks + %u-byte metadata)", ns_id, (ns->lba_count * ns->block_size) >> 20, @@ -459,12 +468,12 @@ nvme_bounce_xfer(struct nvme_namespace *ns, u64 lba, = void *buf, u16 count, u16 blocks =3D count < max_blocks ? count : max_blocks; =20 if (write) - memcpy(ns->dma_buffer, buf, blocks * ns->block_size); + memcpy(nvme_dma_buffer, buf, blocks * ns->block_size); =20 - int res =3D nvme_io_xfer(ns, lba, ns->dma_buffer, NULL, blocks, write); + int res =3D nvme_io_xfer(ns, lba, nvme_dma_buffer, NULL, blocks, write= ); =20 if (!write && res >=3D 0) - memcpy(buf, ns->dma_buffer, res * ns->block_size); + memcpy(buf, nvme_dma_buffer, res * ns->block_size); =20 return res; } @@ -498,7 +507,7 @@ nvme_prpl_xfer(struct nvme_namespace *ns, u64 lba, void= *buf, u16 count, /* Build PRP list if we need to describe more than 2 pages */ if ((ns->block_size * count) > (NVME_PAGE_SIZE * 2)) { u32 prpl_len =3D 0; - u64 *prpl =3D (void*)ns->dma_buffer; + u64 *prpl =3D nvme_dma_buffer; int first_page =3D 1; for (; size > 0; base +=3D NVME_PAGE_SIZE, size -=3D NVME_PAGE_SIZ= E) { if (first_page) { --=20 2.31.1 _______________________________________________ SeaBIOS mailing list -- seabios@seabios.org To unsubscribe send an email to seabios-leave@seabios.org