From nobody Mon Oct 17 20:41:39 2022 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4MrpnH5YLxz4fQnL; Mon, 17 Oct 2022 20:41:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4MrpnH4mqJz46QB; Mon, 17 Oct 2022 20:41:39 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1666039299; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=/UD9LcHcqDf3Lf5M6XcswOS3/LSobgan2i3RpldtCyM=; b=v7ZZQ6STQ6GczQXi+fqiM1ioHLbnhV00yhdbBnJ/Oy0b9IA8fidaSk2b9suwVHlk7s2r1H H8RR8mFK/aRs99Jlw2vCNdCMMdmPb8TExhn/JJv8PVZDO/a3ZRD3R8olZ81OJRRTsrUoJE A6Sv9+BkjvNkDHoo6uX/LDkyOJogBY48qvLwNcI9C9Jm6tiylBVmYYwJDk/OfyzEkYSwWj t4ueGHF8XDXNkxhq0Wyj7b8i5JdBuQjv0wafPA7q09zz/n9NjIhVUfmt++nuE7ytkXwkaP vl/+AuLBrZn5lB6+x4Nnk34m0Q5OqUdnniwzb9LyD4BlaFKl/AzGzW837vhjYg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4MrpnH3rNpzxTr; Mon, 17 Oct 2022 20:41:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 29HKfdX9096552; Mon, 17 Oct 2022 20:41:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 29HKfdPH096551; Mon, 17 Oct 2022 20:41:39 GMT (envelope-from git) Date: Mon, 17 Oct 2022 20:41:39 GMT Message-Id: <202210172041.29HKfdPH096551@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: "Bjoern A. Zeeb" Subject: git: 2088e5bdac39 - stable/13 - LinuxKPI: dma-mapping: add dmam_alloc_coherent() List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bz X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 2088e5bdac398e5f084739fd4f4d206530178c33 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1666039299; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=/UD9LcHcqDf3Lf5M6XcswOS3/LSobgan2i3RpldtCyM=; b=JJaupTwSjgV5oV57PQpP9Ab2Cm04CO8NxT2aXgaOjEVAc9xim1rV7rOGkAPI7dyeAt8/yL 7N9LcA1lauxrVDUS8iEGXp7pbQuqkdFDB2WLY/H4DH/9ATivKQ0xMcZU0D1a4FjqrymPWp Cv5vMKhxQCImaYMRrZ/PtR63IC4txQjkn4c2lIZm4dIaMDm+L2dMAAUeE4ADn2v7hSALEl hz/hsudCtWO6epZWyFmlpOhv1Es8RipnAVgsJyXiKAfsjdnqqHtQOJYzobCHf8toB3l+3E ORJ9CKPCCrfuY5PaiGuGvftLjZKY2nB/Wz10VwU1rnhsBhW/yVtDc0pT8LaBTg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1666039299; a=rsa-sha256; cv=none; b=wsPNW2inhE6PmOCRG45zf1fqX0VJxXl0v9kPA1QOktL1DVBuet2z8qhbX6O+Qxq183J4c6 po9yD1RTuJZdpQsRkrcHD4bvdTqzjfrVrNDvOsZuEk2ur0E6WcQuuhH5hzBFDPVpGl9U9J OfoHMpPc923b8GLN3Fw45CDBCAFkASthMMmig0IyXGJTd45dqkj8/O7bTpB0MDJw8QTOB8 Z0AJsBag2zcbuLC27pmItbE+HK40woPAJhKvWSzBMZeUBSd3IDLT+ImLlVlNqje4vXEU90 jOaGU95FqROK55Jpiht5A3QlS85JJqHQVJCkfd8dbnyukeVZVToNE+H1ghtnVQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=2088e5bdac398e5f084739fd4f4d206530178c33 commit 2088e5bdac398e5f084739fd4f4d206530178c33 Author: Bjoern A. Zeeb AuthorDate: 2022-09-21 20:58:05 +0000 Commit: Bjoern A. Zeeb CommitDate: 2022-10-17 20:37:04 +0000 LinuxKPI: dma-mapping: add dmam_alloc_coherent() Add the devres version dmam_alloc_coherent() of dma_alloc_coherent() along with the ancillary free function. Sponsored by: The FreeBSD Foundation Reviewed by: hselasky Differential Revision: https://reviews.freebsd.org/D36661 (cherry picked from commit 7105f0d967530852b907375687575a8c2ba62fd2) --- .../linuxkpi/common/include/linux/dma-mapping.h | 10 ++++++ sys/compat/linuxkpi/common/src/linux_pci.c | 39 ++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/sys/compat/linuxkpi/common/include/linux/dma-mapping.h b/sys/compat/linuxkpi/common/include/linux/dma-mapping.h index 94adb0c64431..ef3570ef7639 100644 --- a/sys/compat/linuxkpi/common/include/linux/dma-mapping.h +++ b/sys/compat/linuxkpi/common/include/linux/dma-mapping.h @@ -95,6 +95,8 @@ int linux_dma_tag_init(struct device *, u64); int linux_dma_tag_init_coherent(struct device *, u64); void *linux_dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle, gfp_t flag); +void *linuxkpi_dmam_alloc_coherent(struct device *dev, size_t size, + dma_addr_t *dma_handle, gfp_t flag); dma_addr_t linux_dma_map_phys(struct device *dev, vm_paddr_t phys, size_t len); void linux_dma_unmap(struct device *dev, dma_addr_t dma_addr, size_t size); int linux_dma_map_sg_attrs(struct device *dev, struct scatterlist *sgl, @@ -159,6 +161,14 @@ dma_zalloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle, return (dma_alloc_coherent(dev, size, dma_handle, flag | __GFP_ZERO)); } +static inline void * +dmam_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle, + gfp_t flag) +{ + + return (linuxkpi_dmam_alloc_coherent(dev, size, dma_handle, flag)); +} + static inline void dma_free_coherent(struct device *dev, size_t size, void *cpu_addr, dma_addr_t dma_addr) diff --git a/sys/compat/linuxkpi/common/src/linux_pci.c b/sys/compat/linuxkpi/common/src/linux_pci.c index f5de87947c37..b0820c9b2c3e 100644 --- a/sys/compat/linuxkpi/common/src/linux_pci.c +++ b/sys/compat/linuxkpi/common/src/linux_pci.c @@ -1140,6 +1140,45 @@ linux_dma_alloc_coherent(struct device *dev, size_t size, return (mem); } +struct lkpi_devres_dmam_coherent { + size_t size; + dma_addr_t *handle; + void *mem; +}; + +static void +lkpi_dmam_free_coherent(struct device *dev, void *p) +{ + struct lkpi_devres_dmam_coherent *dr; + + dr = p; + dma_free_coherent(dev, dr->size, dr->mem, *dr->handle); +} + +void * +linuxkpi_dmam_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle, + gfp_t flag) +{ + struct lkpi_devres_dmam_coherent *dr; + + dr = lkpi_devres_alloc(lkpi_dmam_free_coherent, + sizeof(*dr), GFP_KERNEL | __GFP_ZERO); + + if (dr == NULL) + return (NULL); + + dr->size = size; + dr->mem = linux_dma_alloc_coherent(dev, size, dma_handle, flag); + dr->handle = dma_handle; + if (dr->mem == NULL) { + lkpi_devres_free(dr); + return (NULL); + } + + lkpi_devres_add(dev, dr); + return (dr->mem); +} + void linuxkpi_dma_sync(struct device *dev, dma_addr_t dma_addr, size_t size, bus_dmasync_op_t op)