From nobody Fri Feb 17 23:45:01 2023 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 4PJT252vyzz3rxSb; Fri, 17 Feb 2023 23:45:01 +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 4PJT2524vkz3HQY; Fri, 17 Feb 2023 23:45:01 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676677501; 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=cOsOgu3CQRKq3FEn6NqOS+VXIt+H3i5lqlPzd7OLOCU=; b=PTxn6T0ukzCEJ/Ie/vJPm2lA80Pxx2+SfHMm6PBanZmqEIepN5rUPegK3dMn+sgnKLSMTv TDiqn07CJNBq2Di55XiCbiUEeSw0qMLuZyiS5rR6htqH/PN3eBrOQ/CGzaCexASNRtBNr0 qWzB/ZF5vJO5FExctXQGlu9nK8Or2EhOlz1/r3OrO33/6g3J72DWW8CkuZ0PjDPlH8eQLe +PRi9fdH4eBpqqlvlnymkVBws6q0Gp8M9rwFaVus6jRoFt8HnjA2yAllP2rQzcopEUYkku ZxwVM+4/LmvjWuE8uz6mOBRMVnPC+ApC1mAjRjW5Tf6/CsxIU6DD7inD+R6U0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676677501; 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=cOsOgu3CQRKq3FEn6NqOS+VXIt+H3i5lqlPzd7OLOCU=; b=t64ixnJCI1QMsrvMauDReIHxeNXAAAeC0HbLM+J+tNrRxlwMyhbkQUkTXAezr5h2g03Jff IM39oRXN4uTsM2fF+gZ6L3Z77Zs+bed6FgC6WYU4z/KJlbQzz/9j2JNFnfZdgXCiVUI2YA A5QlJkXXK7hJDyKnqImiWef/9ftNJfzUJXU7Rlpvy0D9/8nuIA0ax9DA+bKoJKqsIau/IG ruvSAMbjO7ep7XF4z04+GQss8MFQ8He5svEikm8vHprmwM+Wtw9DSS8D0Dj6AO9dC+e+0O 2hZUflADnqubKhpPKWER89sZRn8XdnPWq+d1/BrIHxdWFNZjkb2hQb3GQHtW9A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1676677501; a=rsa-sha256; cv=none; b=kpcHGR9cn9TbBadTW9qfccNVgKf6uVwTwXuMexBKN60yzfD3kTyRa8D8fBdR1QdqhB2WWe eR5U4/rBmZ6PGTflNKyvCf8zDJ7RWJ37JzrjnkGU7Y/zjwyupIKXsqCSXo1SPuEW4+tFIV wrt2ruu/B8w00g3FlcpZq5oM2JT59OyWPlXpKQiq557ZSStfQhpkxtQrVRkxxWJgmSujIc bLF59NmlnhYma/zO8BnwTncwHJg/8RZrfXRWv9m/zp8wnV79qKs4YtSNn571YpBjW1FJHb 8O6RrosGd+ABHl3kFIZyGgywOfpboFM02TU7oCazQ3KOhQb2gUpN+p6wPz1rWw== 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 4PJT2519TMz11rF; Fri, 17 Feb 2023 23:45:01 +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 31HNj1MZ025318; Fri, 17 Feb 2023 23:45:01 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 31HNj1Sc025317; Fri, 17 Feb 2023 23:45:01 GMT (envelope-from git) Date: Fri, 17 Feb 2023 23:45:01 GMT Message-Id: <202302172345.31HNj1Sc025317@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: 7d23664b35a2 - stable/13 - LinuxKPI: implement irq_get_msi_desc() 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: bz X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 7d23664b35a2611dc4fea56f7cfd2b99f91626a0 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=7d23664b35a2611dc4fea56f7cfd2b99f91626a0 commit 7d23664b35a2611dc4fea56f7cfd2b99f91626a0 Author: Bjoern A. Zeeb AuthorDate: 2022-11-28 18:27:03 +0000 Commit: Bjoern A. Zeeb CommitDate: 2023-02-17 23:42:16 +0000 LinuxKPI: implement irq_get_msi_desc() Add irq_get_msi_desc() as a wrapper around a PCI function which will allocate a single cached value (see comment on struct) for the msi_desc requested if it doesn't exist yet and handle freeing it when the PCI device goes away. We take the values from the ivars of the native (FreeBSD) device. While changing struct pci_dev also add the msi_cap field requested by a wireless driver. MFC after: 3 days Reviewed by: hselasky (earlier version) Differential Revision: https://reviews.freebsd.org/D37523 (cherry picked from commit 4b56afaf7bf4fa37bae5b26fd93ee1ff5969c1bb) --- sys/compat/linuxkpi/common/include/linux/pci.h | 14 ++++++++++++ sys/compat/linuxkpi/common/src/linux_pci.c | 31 ++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/sys/compat/linuxkpi/common/include/linux/pci.h b/sys/compat/linuxkpi/common/include/linux/pci.h index ba4ee8a9b70a..6a7dd1eaaa83 100644 --- a/sys/compat/linuxkpi/common/include/linux/pci.h +++ b/sys/compat/linuxkpi/common/include/linux/pci.h @@ -306,6 +306,17 @@ _pci_exit(void) \ module_init(_pci_init); \ module_exit(_pci_exit) +struct msi_msg { + uint32_t data; +}; + +struct msi_desc { + struct msi_msg msg; + struct { + bool is_64; + } msi_attrib; +}; + /* * If we find drivers accessing this from multiple KPIs we may have to * refcount objects of this structure. @@ -342,6 +353,8 @@ struct pci_dev { bool managed; /* devres "pcim_*(). */ bool want_iomap_res; bool msix_enabled; + uint8_t msi_cap; + struct msi_desc *msi_desc; }; /* XXX add kassert here on the mmio offset */ @@ -371,6 +384,7 @@ struct resource *_lkpi_pci_iomap(struct pci_dev *pdev, int bar, int mmio_size); struct pcim_iomap_devres *lkpi_pcim_iomap_devres_find(struct pci_dev *pdev); void lkpi_pcim_iomap_table_release(struct device *, void *); struct pci_dev *lkpi_pci_get_device(uint16_t, uint16_t, struct pci_dev *); +struct msi_desc *lkpi_pci_msi_desc_alloc(int); static inline bool dev_is_pci(struct device *dev) diff --git a/sys/compat/linuxkpi/common/src/linux_pci.c b/sys/compat/linuxkpi/common/src/linux_pci.c index 2db542284332..ba40ded9cddf 100644 --- a/sys/compat/linuxkpi/common/src/linux_pci.c +++ b/sys/compat/linuxkpi/common/src/linux_pci.c @@ -341,6 +341,8 @@ lkpinew_pci_dev_release(struct device *dev) if (pdev->bus->self != pdev) pci_dev_put(pdev->bus->self); free(pdev->bus, M_DEVBUF); + if (pdev->msi_desc != NULL) + free(pdev->msi_desc, M_DEVBUF); free(pdev, M_DEVBUF); } @@ -972,6 +974,35 @@ pci_device_is_present(struct pci_dev *pdev) return (bus_child_present(dev)); } +struct msi_desc * +lkpi_pci_msi_desc_alloc(int irq) +{ + struct device *dev; + struct pci_dev *pdev; + struct msi_desc *desc; + struct pci_devinfo *dinfo; + struct pcicfg_msi *msi; + + dev = linux_pci_find_irq_dev(irq); + if (dev == NULL) + return (NULL); + + pdev = to_pci_dev(dev); + if (pdev->msi_desc != NULL) + return (pdev->msi_desc); + + dinfo = device_get_ivars(dev->bsddev); + msi = &dinfo->cfg.msi; + + desc = malloc(sizeof(*desc), M_DEVBUF, M_WAITOK | M_ZERO); + + desc->msi_attrib.is_64 = + (msi->msi_ctrl & PCIM_MSICTRL_64BIT) ? true : false; + desc->msg.data = msi->msi_data; + + return (desc); +} + CTASSERT(sizeof(dma_addr_t) <= sizeof(uint64_t)); struct linux_dma_obj {