From nobody Fri May 06 16:25:40 2022 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 5B94C1AD174B; Fri, 6 May 2022 16:25:45 +0000 (UTC) (envelope-from rpokala@freebsd.org) Received: from smtp.freebsd.org (smtp.freebsd.org [96.47.72.83]) (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 "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Kvwsj288Yz3sjq; Fri, 6 May 2022 16:25:45 +0000 (UTC) (envelope-from rpokala@freebsd.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1651854345; 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: in-reply-to:in-reply-to:references:references; bh=OwVMubOTL9Uw7iNQ+hAaiVgypzsneJEtB0liYD4JyFw=; b=N8Mzsl++hymw5mOetHcjyxEIyt3LX8nwVtBj5doMetHCTV6RJ9LRNIntLQ/CIlNDmqcU4i zdvzGJ1b2CkOfFtsoxntpncCOnUkUfFsZWz95fL/kwAi/wCd8t7vYIpVvG1IQfZ5rZGosG xp2AORT0MyySUwbpJvEPO9ePV7l9AgjgxI782zVeEHHrb7Y3uCDCfNrljpOXmh4amPG7rt UEhMDdHsulPND0TUJaHRLNVZhXSvlCPUv7jvEEopjv+ps2Bih2RBYFEj45+iW4B9UCt4UM BgR1YJtbMV6r1u0nZKVwvZ0c1M3qpFE/syd9hrKgrObd9hT7b9TMz0S57/OGrA== Received: from [192.168.1.10] (unknown [98.42.164.217]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) (Authenticated sender: rpokala) by smtp.freebsd.org (Postfix) with ESMTPSA id 9D1F62F29E; Fri, 6 May 2022 16:25:44 +0000 (UTC) (envelope-from rpokala@freebsd.org) User-Agent: Microsoft-MacOutlook/16.60.22041000 Date: Fri, 06 May 2022 09:25:40 -0700 Subject: Re: 0b6bacc7874f - main - Add ofw_bus_iommu_map() that maps PCI requester ID to an IOMMU specifier based on "iommu-map" DTS property. From: Ravi Pokala To: Ruslan Bukin , , , Message-ID: <450C9313-CB5A-4DCA-97FB-40FC87886F00@panasas.com> Thread-Topic: 0b6bacc7874f - main - Add ofw_bus_iommu_map() that maps PCI requester ID to an IOMMU specifier based on "iommu-map" DTS property. References: <202205061551.246FpO6o060060@gitrepo.freebsd.org> In-Reply-To: <202205061551.246FpO6o060060@gitrepo.freebsd.org> 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: 7bit ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1651854345; 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: in-reply-to:in-reply-to:references:references; bh=OwVMubOTL9Uw7iNQ+hAaiVgypzsneJEtB0liYD4JyFw=; b=q4qSxGOGOEOcpKhTI1V+RMFIUkloAIOJotXI3GWiGK7hr2VUc8iGck4ZI/mzWcJZG21Lwq uKRf/jYeXs7sjrRu/b5GVAg+2g0Mtq4Gx14d6I2tNfO/inezC2b2H/fAz2VPqiXrDq2onE GMUzuTudDv++yMfcJCJpODsohOng2kgdLcTbJ09gybdmT5DVFlxbYwvelX2sZS1/nQ2BJa QuwfPMn/iXnkSn1OjqnsGfkDvIoe44r+AZjjMIk5fy2C8DL0njGJmbm5JuZ+DVEoxqLM5Z YDuMLKMSZZMp/RLr4Ik7fjdiaBgLXWGzx156RCdM4OQrku/RF+GauC3TvTloBw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1651854345; a=rsa-sha256; cv=none; b=Xy/eXaZOcqCtxOC01wGrZ1UvI/jOHCPhBl0njqGiJxVrQJn+kMmuVoLOqIB9b6WVAIFgr2 MXctozNZPRei+DFHUpf088NkuQXPc0hr9Z6QKYk3PDup+jXJNNJJdmGgz1r+OloBtJCSyo ERYGvLOswzTUXpQjdHKSkXCnUCzCIpRTmIqt0NVx7rqASqBLH7sQtLIPinTH2ln9072nON 53YktEgkLj9dE2vpFwUSMxFErPWXfmLOwMlQuX0FJF1QBygswY489IPg/cNPixFwPq9wxI ClqJyK0iY/ZkX4KDh1Hp1caETfHy3UyovKRg001gZK/2V3CGxMb8Mn5gFOUzwA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N -----Original Message----- From: on behalf of Ruslan Bukin Date: 2022-05-06, Friday at 08:51 To: , , Subject: git: 0b6bacc7874f - main - Add ofw_bus_iommu_map() that maps PCI requester ID to an IOMMU specifier based on "iommu-map" DTS property. The branch main has been updated by br: URL: https://cgit.FreeBSD.org/src/commit/?id=0b6bacc7874f9c68ad35b06f1a7614171eb9ab10 commit 0b6bacc7874f9c68ad35b06f1a7614171eb9ab10 Author: Ruslan Bukin AuthorDate: 2022-05-06 15:41:11 +0000 Commit: Ruslan Bukin CommitDate: 2022-05-06 15:48:04 +0000 Add ofw_bus_iommu_map() that maps PCI requester ID to an IOMMU specifier based on "iommu-map" DTS property. Sponsored by: UKRI --- sys/dev/ofw/ofw_bus_subr.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ sys/dev/ofw/ofw_bus_subr.h | 3 ++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/sys/dev/ofw/ofw_bus_subr.c b/sys/dev/ofw/ofw_bus_subr.c index ea57d1086779..408d554b3c7f 100644 --- a/sys/dev/ofw/ofw_bus_subr.c +++ b/sys/dev/ofw/ofw_bus_subr.c @@ -491,6 +491,50 @@ ofw_bus_msimap(phandle_t node, uint16_t pci_rid, phandle_t *msi_parent, return (err); } +int +ofw_bus_iommu_map(phandle_t node, uint16_t pci_rid, phandle_t *iommu_parent, + uint32_t *iommu_rid) +{ + pcell_t mask, iommu_base, rid_base, rid_length; + uint32_t masked_rid; + pcell_t map[4]; + ssize_t len; + int err, i; + + len = OF_getproplen(node, "iommu-map"); + if (len <= 0) + return (ENOENT); + if (len > sizeof(map)) + return (ENOMEM); + + len = OF_getencprop(node, "iommu-map", map, 16); + + err = ENOENT; + mask = 0xffffffff; + OF_getencprop(node, "iommu-map-mask", &mask, sizeof(mask)); + + masked_rid = pci_rid & mask; + for (i = 0; i < len; i += 4) { + rid_base = map[i + 0]; + rid_length = map[i + 3]; Hi Ruslan, I'm confused by this. 'map' is declared as a 4-element array, which means 'map[i + 0]' and 'map[i + 3]' are both only valid when 'i' is 0. But 'i' is the loop iterator; doesn't that mean you're accessing outside the array after the 0th time through the loop? Thanks, Ravi (rpokala@) + if (masked_rid < rid_base || + masked_rid >= (rid_base + rid_length)) + continue; + + iommu_base = map[i + 2]; + + if (iommu_parent != NULL) + *iommu_parent = map[i + 1]; + if (iommu_rid != NULL) + *iommu_rid = masked_rid - rid_base + iommu_base; + err = 0; + break; + } + + return (err); +} + static int ofw_bus_reg_to_rl_helper(device_t dev, phandle_t node, pcell_t acells, pcell_t scells, struct resource_list *rl, const char *reg_source) diff --git a/sys/dev/ofw/ofw_bus_subr.h b/sys/dev/ofw/ofw_bus_subr.h index 45709c92c1f7..89f291f92373 100644 --- a/sys/dev/ofw/ofw_bus_subr.h +++ b/sys/dev/ofw/ofw_bus_subr.h @@ -92,8 +92,9 @@ int ofw_bus_lookup_imap(phandle_t, struct ofw_bus_iinfo *, void *, int, int ofw_bus_search_intrmap(void *, int, void *, int, void *, int, void *, void *, void *, int, phandle_t *); -/* Routines for processing msi maps */ +/* Routines for processing msi and iommu maps. */ int ofw_bus_msimap(phandle_t, uint16_t, phandle_t *, uint32_t *); +int ofw_bus_iommu_map(phandle_t, uint16_t, phandle_t *, uint32_t *); /* Routines for parsing device-tree data into resource lists. */ int ofw_bus_reg_to_rl(device_t, phandle_t, pcell_t, pcell_t,