From patchwork Mon Jul 2 17:26:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Lucero X-Patchwork-Id: 42121 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 0E0461B56D; Mon, 2 Jul 2018 19:27:14 +0200 (CEST) Received: from netronome.com (host-79-78-33-110.static.as9105.net [79.78.33.110]) by dpdk.org (Postfix) with ESMTP id 427E11B56A; Mon, 2 Jul 2018 19:27:12 +0200 (CEST) Received: from netronome.com (localhost [127.0.0.1]) by netronome.com (8.14.4/8.14.4/Debian-4.1ubuntu1) with ESMTP id w62HR7qH032348; Mon, 2 Jul 2018 18:27:07 +0100 Received: (from alucero@localhost) by netronome.com (8.14.4/8.14.4/Submit) id w62HR7T3032347; Mon, 2 Jul 2018 18:27:07 +0100 From: Alejandro Lucero To: dev@dpdk.org Cc: stable@dpdk.org, anatoly.burakov@intel.com, maxime.coquelin@redhat.com Date: Mon, 2 Jul 2018 18:26:58 +0100 Message-Id: <1530552423-32301-2-git-send-email-alejandro.lucero@netronome.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1530552423-32301-1-git-send-email-alejandro.lucero@netronome.com> References: <1530552423-32301-1-git-send-email-alejandro.lucero@netronome.com> Subject: [dpdk-dev] [PATCH 1/6] mem: add function for checking memsegs IOVAs addresses X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" A device can suffer addressing limitations. This functions checks memsegs have iovas within the supported range based on dma mask. PMD should use this during initialization if supported devices suffer addressing limitations, returning an error if this function returns memsegs out of range. Another potential usage is for emulated IOMMU hardware with addressing limitations. Signed-off-by: Alejandro Lucero --- lib/librte_eal/common/eal_common_memory.c | 37 ++++++++++++++++++++++++++++++ lib/librte_eal/common/include/rte_memory.h | 3 +++ 2 files changed, 40 insertions(+) diff --git a/lib/librte_eal/common/eal_common_memory.c b/lib/librte_eal/common/eal_common_memory.c index fc6c44d..ca49e5c 100644 --- a/lib/librte_eal/common/eal_common_memory.c +++ b/lib/librte_eal/common/eal_common_memory.c @@ -109,6 +109,43 @@ } } +/* check memseg iovas are within the required range based on dma mask */ +int +rte_eal_check_dma_mask(uint8_t maskbits) +{ + + const struct rte_mem_config *mcfg; + uint64_t mask; + int i; + int ret = 0; + + /* create dma mask */ + mask = 1ULL << maskbits; + mask -= 1; + + /* get pointer to global configuration */ + mcfg = rte_eal_get_configuration()->mem_config; + + for (i = 0; i < RTE_MAX_MEMSEG; i++) { + if (mcfg->memseg[i].addr == NULL) + break; + + if (mcfg->memseg[i].iova & ~mask) { + ret = -1; + break; + } + } + + if (!ret) + return ret; + + RTE_LOG(INFO, EAL, "memseg[%d] iova %"PRIx64" out of range:\n", + i, mcfg->memseg[i].iova); + RTE_LOG(INFO, EAL, "\tusing dma mask %"PRIx64"\n", mask); + + return -1; +} + /* return the number of memory channels */ unsigned rte_memory_get_nchannel(void) { diff --git a/lib/librte_eal/common/include/rte_memory.h b/lib/librte_eal/common/include/rte_memory.h index 80a8fc0..b2a0168 100644 --- a/lib/librte_eal/common/include/rte_memory.h +++ b/lib/librte_eal/common/include/rte_memory.h @@ -209,6 +209,9 @@ struct rte_memseg { */ unsigned rte_memory_get_nrank(void); +/* check memsegs iovas are within a range based on dma mask */ +int rte_eal_check_dma_mask(uint8_t maskbits); + /** * Drivers based on uio will not load unless physical * addresses are obtainable. It is only possible to get