From nobody Tue Nov 18 18:02:34 2025 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 4d9ss715PXz6HWcf for ; Tue, 18 Nov 2025 18:02:35 +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 "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4d9ss66pdKz3HgB for ; Tue, 18 Nov 2025 18:02:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1763488955; 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=Rzd46T6+d711jun4MOU36phybPDFynEmuzSoE78zcQY=; b=cp4Fr7prqNJDcQPRvFVKNINVUQMM1z0aIVjDEGt72p1PxkKJPLIplEXtGyHEKz8vlWh1wO Ype1oRQZEUsS6c8uaaOL4eCbLyY1vTBdj89RBOnlU0YW6M8n+n8RBdg3LCrrTo1P/c7b3S wORfG1m5Wb3KxVIHSLvG5etn+53ty/J9gxxSYQyYOftd11h0B67RNjqvlD2/xlM9DKPnac +pkMc1D7DND/nzv8XcQ+zIq3LUaOVSsZoRvcQ2gDlhr3cazP8BoL26+/zVVjbjfM/mXCe2 mB8MT/nymyp10rnx3wMsjoDix/vxeQ/xoR8IanHwjlxJNs7IzV0uXCe0ABBPQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1763488955; 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=Rzd46T6+d711jun4MOU36phybPDFynEmuzSoE78zcQY=; b=OJkMkHlgycHj0qRwLEyXMDeiFYkEozNK/kyEteZW/MVJYXmQok7lNlXzvb27sgUWK4iq/G ybHRPk50OpM6MqcZDvecM90z+ClWA2ee88g/ojBTGXy1H24lgQLie46eTTquoIkQENUy8P hrfbn0npdwp5kPdLQECQNVjGzROOd3Skmcl3KNI4yPWH8keGWh5ie9weYmoKYhyZY6JNu5 0P41iadKc25B3Oxx6h8MLOmL/E3typwDfQocJ+oGseDhq61lGxIUToof1cxSXHrF8E3ik3 nUOoun2JsqUMv0XTPitE85jqdKPgYGqDdNJ1NlVJKRiPY6QGc2p45OCu0lrbZw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1763488955; a=rsa-sha256; cv=none; b=ZNqGE/psKeXzUflQ+81Dp4XSh1EHHdbf7wJndjx1wsAJMV0bDBuDq1m3hr0NrnZAtaCjDa TZJcbU5g1Y2jdKP7zjrUyVjEu0iGCC72Kr95B60q35CZ3AnNcXihc6J+kro02cgQWJVch1 rocx8cZvRJJDSYW9NyOD5z6KIN7wTzd/8SGUGbKEEjXoqI+JJZaOJz7VLHyuRTA86M4NWA xBODMD7s2l6j+EayAbNyrPuiM8q9J+PhxiCZo0qxFeDH0FtRN4dcNrFpTNfGUwYJgVZlrC eDjTVgWX2W2dOnrbALOLyhHDP1rCha7u0Z94/rNiQstyMIUR+LUf3HjKlJwSdw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4d9ss66H4pz14q0 for ; Tue, 18 Nov 2025 18:02:34 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 22f84 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 18 Nov 2025 18:02:34 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Andrew Turner Subject: git: 68e6422c6c91 - main - dev/fdt: Add support for non-PCI MSI interrupts 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: andrew X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 68e6422c6c91170a615e77028683a157e8e39d05 Auto-Submitted: auto-generated Date: Tue, 18 Nov 2025 18:02:34 +0000 Message-Id: <691cb4ba.22f84.6534df2a@gitrepo.freebsd.org> The branch main has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=68e6422c6c91170a615e77028683a157e8e39d05 commit 68e6422c6c91170a615e77028683a157e8e39d05 Author: Andrew Turner AuthorDate: 2025-11-18 18:00:30 +0000 Commit: Andrew Turner CommitDate: 2025-11-18 18:00:30 +0000 dev/fdt: Add support for non-PCI MSI interrupts Some non-PCI devices can send interrupts, e.g. the Arm SMMU or GICv5 Interrupt Wire Bridge. Add support for these by implementing pci_get_id and pci_alloc_msi and the MSI/MSI-X parts of the PCIB interface. Only the MSI parts of the PCI interface are added as that is all I am able to test. Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D53330 --- sys/dev/fdt/simplebus.c | 134 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) diff --git a/sys/dev/fdt/simplebus.c b/sys/dev/fdt/simplebus.c index a301fb0f247c..3e77f13104ff 100644 --- a/sys/dev/fdt/simplebus.c +++ b/sys/dev/fdt/simplebus.c @@ -40,6 +40,9 @@ #include +#include "pci_if.h" +#include "pcib_if.h" + /* * Bus interface. */ @@ -62,6 +65,21 @@ static ssize_t simplebus_get_property(device_t bus, device_t child, static const struct ofw_bus_devinfo *simplebus_get_devinfo(device_t bus, device_t child); +/* + * PCI interface for MSI interrupts + */ +static pci_get_id_t simplebus_get_id; +static pci_alloc_msi_t simplebus_alloc_msi; + +/* + * PCIB interface + */ +static pcib_alloc_msi_t simplebus_pcib_alloc_msi; +static pcib_release_msi_t simplebus_pcib_release_msi; +static pcib_alloc_msix_t simplebus_pcib_alloc_msix; +static pcib_release_msix_t simplebus_pcib_release_msix; +static pcib_map_msi_t simplebus_pcib_map_msi; + /* * Driver methods. */ @@ -105,6 +123,17 @@ static device_method_t simplebus_methods[] = { DEVMETHOD(ofw_bus_get_node, ofw_bus_gen_get_node), DEVMETHOD(ofw_bus_get_type, ofw_bus_gen_get_type), + /* PCI interface for MSI interrupts */ + DEVMETHOD(pci_get_id, simplebus_get_id), + DEVMETHOD(pci_alloc_msi, simplebus_alloc_msi), + + /* PCIB interface */ + DEVMETHOD(pcib_alloc_msi, simplebus_pcib_alloc_msi), + DEVMETHOD(pcib_release_msi, simplebus_pcib_release_msi), + DEVMETHOD(pcib_alloc_msix, simplebus_pcib_alloc_msix), + DEVMETHOD(pcib_release_msix, simplebus_pcib_release_msix), + DEVMETHOD(pcib_map_msi, simplebus_pcib_map_msi), + DEVMETHOD_END }; @@ -534,3 +563,108 @@ simplebus_print_child(device_t bus, device_t child) rv += bus_print_child_footer(bus, child); return (rv); } + +static int +simplebus_get_id(device_t dev, device_t child, enum pci_id_type type, + uintptr_t *id) +{ + phandle_t node, xref; + pcell_t *cells; + uintptr_t rid; + int error, ncells; + + if (type != PCI_ID_MSI) + return (EINVAL); + + node = ofw_bus_get_node(child); + error = ofw_bus_parse_xref_list_alloc(node, "msi-parent", "#msi-cells", + 0, &xref, &ncells, &cells); + if (error != 0) + return (error); + + rid = 0; + if (ncells > 0) + rid = cells[0]; + + *id = rid; + return (0); +} + +static int +simplebus_alloc_msi(device_t bus, device_t child, int *count) +{ + struct simplebus_devinfo *ndi; + struct resource_list_entry *rle; + int error, i, irq_count, *irqs; + + if (*count < 1) + return (EINVAL); + + ndi = device_get_ivars(child); + if (ndi == NULL) + return (ENXIO); + + /* Only MSI or non-MSI for now */ + rle = resource_list_find(&ndi->rl, SYS_RES_IRQ, 0); + if (rle != NULL && rle->res != NULL) + return (ENXIO); + + irq_count = *count; + irqs = mallocarray(irq_count, sizeof(int), M_DEVBUF, M_WAITOK | M_ZERO); + + error = PCIB_ALLOC_MSI(bus, child, irq_count, irq_count, irqs); + if (error != 0) + goto out; + + for (i = 0; i < irq_count; i++) { + error = bus_generic_rl_set_resource(bus, child, SYS_RES_IRQ, + i + 1, irqs[i], 1); + if (error != 0) + break; + } + + /* Clean up resources if something failed */ + if (error != 0) { + for (int j = 0; j < i; j++) { + bus_generic_rl_delete_resource(bus, child, SYS_RES_IRQ, + j + 1); + } + } +out: + free(irqs, M_DEVBUF); + return (error); +} + +static int +simplebus_pcib_alloc_msi(device_t dev, device_t child, int count, int maxcount, + int *irqs) +{ + return (PCIB_ALLOC_MSI(device_get_parent(dev), child, count, maxcount, + irqs)); +} + +static int +simplebus_pcib_release_msi(device_t dev, device_t child, int count, int *irqs) +{ + return (PCIB_RELEASE_MSI(device_get_parent(dev), child, count, irqs)); +} + +static int +simplebus_pcib_alloc_msix(device_t dev, device_t child, int *irq) +{ + return (PCIB_ALLOC_MSIX(device_get_parent(dev), child, irq)); +} + +static int +simplebus_pcib_release_msix(device_t dev, device_t child, int irq) +{ + return (PCIB_RELEASE_MSIX(device_get_parent(dev), child, irq)); +} + +static int +simplebus_pcib_map_msi(device_t dev, device_t child, int irq, uint64_t *addr, + uint32_t *data) +{ + return (PCIB_MAP_MSI(device_get_parent(dev), child, irq, addr, + data)); +}