From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 60C9AA034E; Thu, 17 Feb 2022 17:11:20 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 37CB34115B; Thu, 17 Feb 2022 17:10:56 +0100 (CET) Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by mails.dpdk.org (Postfix) with ESMTP id A2B7D40395 for ; Thu, 17 Feb 2022 17:06:39 +0100 (CET) Received: by mail-pf1-f170.google.com with SMTP id u16so43308pfg.12 for ; Thu, 17 Feb 2022 08:06:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oneconvergence.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uHdnym5iLF3hcfGOk4eFkvx+osDZQyrMuwSTtMyfJ1A=; b=HL8kUDuNkJNB796a6zaoVp0YziL0hpV+rBcJ1IbP1v0n6Ol4B38eSQTlB638m6InA1 OoZDzTVtwQ4YjMlWglB46YqJpgA8FP8vicfOPqHQGeYyXQMYtceoJSrxyU8j0ExrLvAn FclqyTp3GO7b116mfpEnAHva/LCeu74GzD9e0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uHdnym5iLF3hcfGOk4eFkvx+osDZQyrMuwSTtMyfJ1A=; b=DTvizTzGIifU7uoAxuwxtkrP5pPsEyNtVn49C7SKmwYbtBKrXp5zKw/7fDTcJXggba IPX0Zx1aAecGR0WHNjloX3U7THCIaze/nLugJOmMnsTfs5hc9DrDy5TsuqbVTE0lt+Zu ila4Kq1RqrOgrMZXxPZxTX3HmWiTiOk1Od+WikjNvxhPH69Zf0Ae5Tm5PdUGwF6YibyN 6AJT17YsgOpbYsW/gWKiF7ha/MLSrNMujcUqoIEiCrLshLkA7wSxgPr/HBpx1UJyndzu p8jbBwMy2CseCFvKb/WCjM+J7Yjfb3fgi4S4CAGJljkbAD0R0PXtODfoApZ2HZ/9Kzh2 +2/w== X-Gm-Message-State: AOAM53101oYLm89WfLW4t3cwlxHI5K01UnKIdm3FudCDfaZ6kdqao1O/ Cn7npuuRB6AWFqEssU3tjQJ+dw== X-Google-Smtp-Source: ABdhPJy+/Zlut8kSJ4WuqddhyiAroBFOTj0dsqByMkfMdqF0uyTnLnKGmdixG2nrJOnehc6cWPTCcQ== X-Received: by 2002:a63:105c:0:b0:36c:33aa:cb24 with SMTP id 28-20020a63105c000000b0036c33aacb24mr2923028pgq.221.1645113998845; Thu, 17 Feb 2022 08:06:38 -0800 (PST) Received: from srikanth-ThinkPad-T450.. ([49.37.144.122]) by smtp.gmail.com with ESMTPSA id z14sm47807pfh.173.2022.02.17.08.06.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Feb 2022 08:06:38 -0800 (PST) From: Srikanth Kaka To: sthemmin@microsoft.com, longli@microsoft.com Cc: dev@dpdk.org, vag.singh@oneconvergence.com, avelu@juniper.net, Srikanth Kaka Subject: [PATCH v3 04/15] bus/vmbus: add resource by index Date: Thu, 17 Feb 2022 21:36:02 +0530 Message-Id: <20220217160613.70161-5-srikanth.k@oneconvergence.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220217160613.70161-1-srikanth.k@oneconvergence.com> References: <20210927134231.11177-1-srikanth.k@oneconvergence.com> <20220217160613.70161-1-srikanth.k@oneconvergence.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Thu, 17 Feb 2022 17:10:51 +0100 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Map the memory region created by hv_uio driver by passing their index number Signed-off-by: Srikanth Kaka Signed-off-by: Vag Singh Signed-off-by: Anand Thulasiram --- drivers/bus/vmbus/freebsd/vmbus_uio.c | 70 +++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/drivers/bus/vmbus/freebsd/vmbus_uio.c b/drivers/bus/vmbus/freebsd/vmbus_uio.c index 2059ab192b..41522ba2b5 100644 --- a/drivers/bus/vmbus/freebsd/vmbus_uio.c +++ b/drivers/bus/vmbus/freebsd/vmbus_uio.c @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -17,6 +18,7 @@ #include "private.h" const char *driver_name = "hv_uio"; +static void *vmbus_map_addr; /* Check map names with kernel names */ static const char *map_names[VMBUS_MAX_RESOURCE] = { @@ -140,3 +142,71 @@ vmbus_uio_alloc_resource(struct rte_vmbus_device *dev, vmbus_uio_free_resource(dev, *uio_res); return -1; } + +static int +find_max_end_va(const struct rte_memseg_list *msl, void *arg) +{ + size_t sz = msl->memseg_arr.len * msl->page_sz; + void *end_va = RTE_PTR_ADD(msl->base_va, sz); + void **max_va = arg; + + if (*max_va < end_va) + *max_va = end_va; + return 0; +} + +/* + * TODO: this should be part of memseg api. + * code is duplicated from PCI. + */ +static void * +vmbus_find_max_end_va(void) +{ + void *va = NULL; + + rte_memseg_list_walk(find_max_end_va, &va); + return va; +} + +int +vmbus_uio_map_resource_by_index(struct rte_vmbus_device *dev, int idx, + struct mapped_vmbus_resource *uio_res, + int flags) +{ + size_t size = dev->resource[idx].len; + struct vmbus_map *maps = uio_res->maps; + void *mapaddr; + off_t offset; + int fd; + + /* devname for mmap */ + fd = open(uio_res->path, O_RDWR); + if (fd < 0) { + VMBUS_LOG(ERR, "Cannot open %s: %s", + uio_res->path, strerror(errno)); + return -1; + } + + /* try mapping somewhere close to the end of hugepages */ + if (vmbus_map_addr == NULL) + vmbus_map_addr = vmbus_find_max_end_va(); + + /* offset is special in uio it indicates which resource */ + offset = idx * rte_mem_page_size(); + + mapaddr = vmbus_map_resource(vmbus_map_addr, fd, offset, size, flags); + close(fd); + + if (mapaddr == MAP_FAILED) + return -1; + + dev->resource[idx].addr = mapaddr; + vmbus_map_addr = RTE_PTR_ADD(mapaddr, size); + + /* Record result of successful mapping for use by secondary */ + maps[idx].addr = mapaddr; + maps[idx].size = size; + + return 0; +} + -- 2.30.2