From nobody Mon Oct 11 13:57:52 2021 X-Original-To: dev-commits-src-all@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 8733C17E4629; Mon, 11 Oct 2021 13:57:52 +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 4HSgNc3QNNz4mdv; Mon, 11 Oct 2021 13:57:52 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 516D121FE6; Mon, 11 Oct 2021 13:57:52 +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 19BDvq7D081992; Mon, 11 Oct 2021 13:57:52 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 19BDvqx1081991; Mon, 11 Oct 2021 13:57:52 GMT (envelope-from git) Date: Mon, 11 Oct 2021 13:57:52 GMT Message-Id: <202110111357.19BDvqx1081991@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Marcin Wojtas Subject: git: 14721190e829 - stable/12 - pci_user: call bus_translate_resource before BAR mmap List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mw X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 14721190e8298199a6cfbb6d2568ea1d17e7a107 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by mw: URL: https://cgit.FreeBSD.org/src/commit/?id=14721190e8298199a6cfbb6d2568ea1d17e7a107 commit 14721190e8298199a6cfbb6d2568ea1d17e7a107 Author: Marcin Wojtas AuthorDate: 2021-04-06 15:10:04 +0000 Commit: Marcin Wojtas CommitDate: 2021-10-11 13:40:11 +0000 pci_user: call bus_translate_resource before BAR mmap On some armv8 machines it is possible that the mapping between CPU and PCI bus BAR base addresses is not 1:1. In case a BAR is allocated in kernel using bus_alloc_resource_any this translation is handled in ofw_pci_activate_resource. Do the same in pci_user.c by calling bus_translate_resource devmethod. This fixes mmaping BARs to userspace on Marvell SoCs (Armada 7k8k/CN913x) and possibly many other platforms. Submitted by: Kornel Duleba Reviewed by: kib Obtained from: Semihalf Sponsored by: Marvell MFC after: 2 weeks Differential revision: https://reviews.freebsd.org/D29604 (cherry picked from commit f2f1ab39c04088ce53287528549e652cf68cee09) pci_user: fix build for 32-bit platforms Commit: f2f1ab39c040 ("pci_user: call bus_translate_resource before BAR mmap") broke build for 32-bit platforms due to rman_res_t and vm_paddr_t incompatible types. Fix that. (cherry picked from commit 9857e00a528bb230c8935ded5f118a7374bf808b) --- sys/dev/pci/pci_user.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sys/dev/pci/pci_user.c b/sys/dev/pci/pci_user.c index 9e3842acf889..54ddb5796cc8 100644 --- a/sys/dev/pci/pci_user.c +++ b/sys/dev/pci/pci_user.c @@ -855,7 +855,7 @@ pci_bar_mmap(device_t pcidev, struct pci_bar_mmap *pbm) struct thread *td; struct sglist *sg; struct pci_map *pm; - vm_paddr_t membase; + rman_res_t membase; vm_paddr_t pbase; vm_size_t plen; vm_offset_t addr; @@ -878,7 +878,11 @@ pci_bar_mmap(device_t pcidev, struct pci_bar_mmap *pbm) return (EBUSY); /* XXXKIB enable if _ACTIVATE */ if (!PCI_BAR_MEM(pm->pm_value)) return (EIO); - membase = pm->pm_value & PCIM_BAR_MEM_BASE; + error = BUS_TRANSLATE_RESOURCE(pcidev, SYS_RES_MEMORY, + pm->pm_value & PCIM_BAR_MEM_BASE, &membase); + if (error != 0) + return (error); + pbase = trunc_page(membase); plen = round_page(membase + ((pci_addr_t)1 << pm->pm_size)) - pbase;