From patchwork Mon Mar 16 21:12:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Zwisler X-Patchwork-Id: 6025511 Return-Path: X-Original-To: patchwork-linux-nvdimm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 793DABF90F for ; Mon, 16 Mar 2015 21:13:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BA12320452 for ; Mon, 16 Mar 2015 21:13:37 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 942BB203E9 for ; Mon, 16 Mar 2015 21:13:35 +0000 (UTC) Received: from ml01.vlan14.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 8860480FE6; Mon, 16 Mar 2015 14:13:35 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by ml01.01.org (Postfix) with ESMTP id EAD9480FE6 for ; Mon, 16 Mar 2015 14:13:33 -0700 (PDT) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga103.fm.intel.com with ESMTP; 16 Mar 2015 14:07:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.11,411,1422950400"; d="scan'208";a="541751280" Received: from theros.lm.intel.com ([10.232.112.52]) by orsmga003.jf.intel.com with ESMTP; 16 Mar 2015 14:12:10 -0700 From: Ross Zwisler To: linux-kernel@vger.kernel.org Date: Mon, 16 Mar 2015 15:12:58 -0600 Message-Id: <1426540380-24503-5-git-send-email-ross.zwisler@linux.intel.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1426540380-24503-1-git-send-email-ross.zwisler@linux.intel.com> References: <1426540380-24503-1-git-send-email-ross.zwisler@linux.intel.com> Cc: axboe@kernel.dk, riel@redhat.com, linux-nvdimm@lists.01.org, hch@infradead.org, linux-fsdevel@vger.kernel.org Subject: [Linux-nvdimm] [PATCH 4/6] pmem: Add support for direct_access() X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Ross Zwisler Cc: linux-nvdimm@lists.01.org Cc: linux-fsdevel@vger.kernel.org Cc: axboe@kernel.dk Cc: hch@infradead.org Cc: riel@redhat.com --- drivers/block/pmem.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/block/pmem.c b/drivers/block/pmem.c index 0be3669..d63bc96 100644 --- a/drivers/block/pmem.c +++ b/drivers/block/pmem.c @@ -74,6 +74,15 @@ static void *pmem_lookup_pg_addr(struct pmem_device *pmem, sector_t sector) return pmem->virt_addr + offset; } +/* sector must be page aligned */ +static unsigned long pmem_lookup_pfn(struct pmem_device *pmem, sector_t sector) +{ + size_t page_offset = sector >> PAGE_SECTORS_SHIFT; + + BUG_ON(sector & (PAGE_SECTORS - 1)); + return (pmem->phys_addr >> PAGE_SHIFT) + page_offset; +} + /* * sector is not required to be page aligned. * n is at most a single page, but could be less. @@ -193,9 +202,24 @@ static int pmem_rw_page(struct block_device *bdev, sector_t sector, return 0; } +static long pmem_direct_access(struct block_device *bdev, sector_t sector, + void **kaddr, unsigned long *pfn, long size) +{ + struct pmem_device *pmem = bdev->bd_disk->private_data; + + if (!pmem) + return -ENODEV; + + *kaddr = pmem_lookup_pg_addr(pmem, sector); + *pfn = pmem_lookup_pfn(pmem, sector); + + return pmem->size - (sector * 512); +} + static const struct block_device_operations pmem_fops = { .owner = THIS_MODULE, .rw_page = pmem_rw_page, + .direct_access = pmem_direct_access, .getgeo = pmem_getgeo, };