Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1617920pxk; Fri, 2 Oct 2020 14:29:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzUbEHuKxiW/EV+pwdqYHSI8CR5Bw0TD0IvSACLPUPuA1khG8VxLb7bFDQCM+p6o5llS4oA X-Received: by 2002:a17:906:1d11:: with SMTP id n17mr4095532ejh.280.1601674168057; Fri, 02 Oct 2020 14:29:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601674168; cv=none; d=google.com; s=arc-20160816; b=tM0siSJAE5l421gtJAGLQc4TpJULq2zrxtwLtshjIPx0jLRUrrAyfVGLgF+fEOhGwR Ew0Pf1g5KwEakKBXH7ZiliLgQhvI7QJiYb0e6ihTi2E98AA6pVbjcE/mBVLUv78VYEji ZU4sfGGtIxm/XysIl4K+JpnzC1jUQuNNPpystkfLTwMmqe0qFZs7mABxfrriaAs1H0AS Aiuf654BzvqG+IkQolholA8jgwgZ0xCEuDpaDJAd3qTXV53iS/tcbeMILjVTUV9y29cZ 52AcmQILRJFea8A+DK/Vrgqu6+4ccPRrp8Pdmpyb2kDvMRydNvktHWtKkwSOOWebDdvr X77Q== 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=7A/AobzH+FRJXYh7LD0AjUWQzN2kh06wV+p0DOwNKws=; b=TeN3IBPoYJi8KkdPUgf+IS0zwgemFE0v9fylYPm7jHq1ApDmKdOudFS7hJThhuCyKm MR29ymI9SnYIR8GvEXkQY+ySBmpY3bZ40RLxk8xtBbhpb1elXcTjoLqjXZUUHUtdGcEG sBStp/wbZ886fH2/qCCtAlYPMXlJ+2oVtXeDlOy485UtR+YOLe66jlmTwJvuMNZCS/ZC hsR5OQ3SeYoh8IPxGwsidmwvy16YOPA/Vf4T0q2+RzXDVLXfVBrba641R27ar87QdyUb lrvuLFw+6Mut5miFzlJAESQB8zZPDhGsPV1kNhK9JdfIV55/GdtK/JZAS+LZFKkVMG5N 0Olw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=drpw6QHK; 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 p89si1946211edd.109.2020.10.02.14.29.05; Fri, 02 Oct 2020 14:29:28 -0700 (PDT) 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=drpw6QHK; 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 S1725879AbgJBVZJ (ORCPT + 99 others); Fri, 2 Oct 2020 17:25:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725780AbgJBVZH (ORCPT ); Fri, 2 Oct 2020 17:25:07 -0400 Received: from mail-ua1-x964.google.com (mail-ua1-x964.google.com [IPv6:2607:f8b0:4864:20::964]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BC52C0613D0 for ; Fri, 2 Oct 2020 14:25:07 -0700 (PDT) Received: by mail-ua1-x964.google.com with SMTP id z46so750005uac.13 for ; Fri, 02 Oct 2020 14:25:07 -0700 (PDT) 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=7A/AobzH+FRJXYh7LD0AjUWQzN2kh06wV+p0DOwNKws=; b=drpw6QHKbky4UXyUEHvJglX3H0w8zfg3d1Hn0Vbt2I9CNQemUeKz/ZuiI0YT66valP dXD+Lbzw+7WD0W6xrqq9gq+Yrv1edn6BcDaQ8MJ/O2M7mXuZI1O0KiaH2vFnfnYP3Ul3 iKKd1DwCkyn7++GGEAkcDq4x0JkJISeA1Mq2M= 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=7A/AobzH+FRJXYh7LD0AjUWQzN2kh06wV+p0DOwNKws=; b=cxgJRY4U5KSfLLkA6dnSajxMZPrbdtZe4DHI59o1yBr2tBSK8Q3L1zuLgIjNg6bCS+ ZJyfhYzOedFXWV9hzTCaWVuympcKw9QpYqv70nQtTuFpPYm80jURWK+CN6zDrVVNjG++ IwEtXfs4eRayzVvN0see2EiEIHLiOWnK2F12Ep+JdmDZNtQcUKHTLyuVsTzFjmfOvGJZ DmqiPjCZusXgxOqCibqhAZkhnpVhF6ct1DOMGZD0Fb5oIM8t6TGWOzaPyZomtJhQgKIR a4ZlbIJtG3Bf98GpaDdY0t+L2xJ+S/vEA0xN0/+C9C3KIKdRqYJtUS+d4/ZUbkqOI6Wc axzQ== X-Gm-Message-State: AOAM532MqVfmH8ICYefhsTuGh3FU7ukLLnQl4/Dm3+9PSIRWciZ5hSOx seQ0HPojqsp0xj3QUPYqZ8YeQuEb7hqsnEuXxIxhyfd3p2PK X-Received: by 2002:ab0:702a:: with SMTP id u10mr2451089ual.59.1601673906816; Fri, 02 Oct 2020 14:25:06 -0700 (PDT) Received: from lbrmn-lnxub113.broadcom.net ([192.19.228.250]) by smtp-relay.gmail.com with ESMTPS id x2sm327292vsn.4.2020.10.02.14.25.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Oct 2020 14:25:06 -0700 (PDT) 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 v6 12/14] misc: bcm-vk: add mmap function for exposing BAR2 Date: Fri, 2 Oct 2020 14:23:25 -0700 Message-Id: <20201002212327.18393-13-scott.branden@broadcom.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201002212327.18393-1-scott.branden@broadcom.com> References: <20201002212327.18393-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 6c2370723e0a..8b869d7f7b93 100644 --- a/drivers/misc/bcm-vk/bcm_vk_dev.c +++ b/drivers/misc/bcm-vk/bcm_vk_dev.c @@ -1177,6 +1177,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; @@ -1215,6 +1238,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