Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp4238046pxb; Tue, 17 Nov 2020 15:26:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJzOfpjV+VnBL4VyOisCZyexmDzuBchJ2tWoCXuFqzWaheNGLr8VrP4IAGCIgFnAPPEVAbZQ X-Received: by 2002:a17:906:c298:: with SMTP id r24mr4012904ejz.381.1605655606144; Tue, 17 Nov 2020 15:26:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605655606; cv=none; d=google.com; s=arc-20160816; b=EySqDQwXiaUb3oxJ3kx22MqqVVMvue0GTSKtCZM3idMm4lW1F4gW/h7u6l7lLlTJ5b /F9AxnsJQ1NtZFp4IJDgHkcxoyn6T8Iz4kCKrD4DSYYyI9vEcrRnJx27AO6Cb6r+rqJ+ YTPWDiewyPemb7iBFLisEsM4ZJRBNfDwZMniL5dqpX1JiC2sq4+qQVZU3qLXvmI9g5tS zmICHBeVnYfMWROnlovUq99XiyMhjiQB7hcegQe4t3/Zka98yop+m5whBku/KvNeOKUu ttZvQo2kozhJPFR0XFT7jwwC56ILYce46bDRKbTy9Jth/oOIZ8qUWvDkWgAApmzy2ADa YY1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=qdDrJWDoHM5C1t4XqMRoNQ2neP9NmJwItgmGwxLWbMo=; b=C5NCeiTsrBkLgzxCfhWeDOjS2RJrLblOtPPVGhZ0H083A5vHGtiR/B97CKNBFjmAO+ AK8VC/JE8xLQgGnHnZSsk8/WbtDkJXIEQ+DXIRoh10LXheiNQsUp6+K+lRnAOREMcxI6 0SLNSdgGUFOuLtwfQdpy2Nzk8GNxQ/6wU9cD5lwmLJ16NLvlwc1TbUThv1+0YRB/UB8H sB3brsYkURRp8LUgabpSTCO98rh9tXxspZYw1ZvjJsg1chEC934U5zu6Zrne4gn+Oys4 0nQ+OlsfF/xaLzw/M1y6g7PZwLfuytx35E5DoYTzi2prPVJPivVxMdcgYrp/o1CUe+Tg Rmcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b="H/1rcnGF"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z17si223296ejr.722.2020.11.17.15.26.23; Tue, 17 Nov 2020 15:26:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b="H/1rcnGF"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729952AbgKQXZA (ORCPT + 99 others); Tue, 17 Nov 2020 18:25:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727554AbgKQXY7 (ORCPT ); Tue, 17 Nov 2020 18:24:59 -0500 Received: from mail-ot1-x364.google.com (mail-ot1-x364.google.com [IPv6:2607:f8b0:4864:20::364]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 589D5C0613CF for ; Tue, 17 Nov 2020 15:24:59 -0800 (PST) Received: by mail-ot1-x364.google.com with SMTP id n89so21208587otn.3 for ; Tue, 17 Nov 2020 15:24:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=qdDrJWDoHM5C1t4XqMRoNQ2neP9NmJwItgmGwxLWbMo=; b=H/1rcnGFfUvdaGgRNzk8FZxK5+4fMsGc3y/9hm7g8vursSgcgWBkvYKC1Jm4jzrOtT 047O8ZRqbMRsMOojYJL5NQ9LG2dvXj6y+XVqy8sL+uohknWUpH35jVTEPwoquy4Wl264 DEx+2dM4B864ZTbZesCugkealE6+rHrofZ8dA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=qdDrJWDoHM5C1t4XqMRoNQ2neP9NmJwItgmGwxLWbMo=; b=dCKf9PHRDUaGVUeoUOkdFJ4heLJKEhOZ5OdyYoEh0mBbqu7Ck6ruCwNZO43WYUr+jR udtqiDRWrfL7yzaFn6P66YXgg3eosNOMMxZ8hWHVa2JfgOofP2fKF8MiLVuSwxBXC10F +MfFMZKIsZ1d8darp9okW9ZxXSRrVn3fv2rqv3VP9RPVjNIj247cGFZk/kYyLGiK8iOE AlGqU5clvf1WsU0mYyq21e/S0LyZPhXVo9AqNYdjChjy/851yJfplDK3nkNjwFJ5ehyF cbKMUiedpL1qiRIp87jhIQff3NN9jnVOtaWiJzj0DwFxbp4aSSIz9k3RcRfQT4xL3iw5 bCwQ== X-Gm-Message-State: AOAM531nTePrBlcTftArPvpMxmABfyuYNkXIr9cVL8eD2hJjhEwi9aA4 nY1uxNoZqFo9Yvsq0+y3rK2jQfX0+4FyI4Hg7cI3ujmqAaPh X-Received: by 2002:a9d:1f5:: with SMTP id e108mr4767468ote.309.1605655498648; Tue, 17 Nov 2020 15:24:58 -0800 (PST) Received: from lbrmn-lnxub113.broadcom.net ([192.19.228.250]) by smtp-relay.gmail.com with ESMTPS id q22sm5867076otg.13.2020.11.17.15.24.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Nov 2020 15:24:58 -0800 (PST) X-Relaying-Domain: broadcom.com From: Scott Branden To: Arnd Bergmann , Greg Kroah-Hartman , Scott Branden , Desmond Yan Cc: Kees Cook , linux-kernel@vger.kernel.org, bcm-kernel-feedback-list@broadcom.com, Olof Johansson Subject: [PATCH v7 11/13] misc: bcm-vk: add mmap function for exposing BAR2 Date: Tue, 17 Nov 2020 15:23:18 -0800 Message-Id: <20201117232320.4958-12-scott.branden@broadcom.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201117232320.4958-1-scott.branden@broadcom.com> References: <20201117232320.4958-1-scott.branden@broadcom.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add mmap function that allows host application to open up BAR2 memory for remote spooling out messages from the VK logger. Co-developed-by: Desmond Yan Signed-off-by: Desmond Yan Signed-off-by: Scott Branden --- drivers/misc/bcm-vk/bcm_vk_dev.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/misc/bcm-vk/bcm_vk_dev.c b/drivers/misc/bcm-vk/bcm_vk_dev.c index e572a7b18fab..cac07419f041 100644 --- a/drivers/misc/bcm-vk/bcm_vk_dev.c +++ b/drivers/misc/bcm-vk/bcm_vk_dev.c @@ -1199,6 +1199,29 @@ static long bcm_vk_reset(struct bcm_vk *vk, struct vk_reset __user *arg) return ret; } +static int bcm_vk_mmap(struct file *file, struct vm_area_struct *vma) +{ + struct bcm_vk_ctx *ctx = file->private_data; + struct bcm_vk *vk = container_of(ctx->miscdev, struct bcm_vk, miscdev); + unsigned long pg_size; + + /* only BAR2 is mmap possible, which is bar num 4 due to 64bit */ +#define VK_MMAPABLE_BAR 4 + + pg_size = ((pci_resource_len(vk->pdev, VK_MMAPABLE_BAR) - 1) + >> PAGE_SHIFT) + 1; + if (vma->vm_pgoff + vma_pages(vma) > pg_size) + return -EINVAL; + + vma->vm_pgoff += (pci_resource_start(vk->pdev, VK_MMAPABLE_BAR) + >> PAGE_SHIFT); + vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); + + return io_remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff, + vma->vm_end - vma->vm_start, + vma->vm_page_prot); +} + static long bcm_vk_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { long ret = -EINVAL; @@ -1237,6 +1260,7 @@ static const struct file_operations bcm_vk_fops = { .write = bcm_vk_write, .poll = bcm_vk_poll, .release = bcm_vk_release, + .mmap = bcm_vk_mmap, .unlocked_ioctl = bcm_vk_ioctl, }; -- 2.17.1