From patchwork Wed Jun 27 21:22:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haneen Mohammed X-Patchwork-Id: 10493301 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2CCB460325 for ; Thu, 28 Jun 2018 08:23:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 13D7029EEB for ; Thu, 28 Jun 2018 08:23:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 05F8D29EFC; Thu, 28 Jun 2018 08:23:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AD5EC29EEB for ; Thu, 28 Jun 2018 08:23:24 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 566B76EC81; Thu, 28 Jun 2018 08:22:56 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x241.google.com (mail-wm0-x241.google.com [IPv6:2a00:1450:400c:c09::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id D23746EB9A for ; Wed, 27 Jun 2018 21:22:48 +0000 (UTC) Received: by mail-wm0-x241.google.com with SMTP id z137-v6so6922711wmc.0 for ; Wed, 27 Jun 2018 14:22:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=a00TjWmkdjavZbmvyFyUK1B6rNvr0gbA6citbSoHgfQ=; b=ekb4emSDH+M9k4A7Z6FF8uPd8l7Vx7r6M35EvN/DKLFr16VyPs2xrOEjvTfdt0ms9B 1WomQk/9jZoTes73KJKV5fEC+nCxjBNuZNMzs3ljzLtbFl0DWZiltkF+Ja32qCK7fzGj nj37yTG8aTGMyItfs70+vthC+DhicHK8lXTVfnKBBgWiO5kJ6GF+y/IzSQ5pinS5ohOF IJ2cd5LOGYT1tlO2wVfbBDEEdGiqEA57M1QILoM+MLTmzeyNoVpT2kbzGrr6f94EJprr gZSa/xUbMCILZ36mt0gO3CnL+tJjjcaey/YFXL1+7MeKTlcGd1Wzjd+E8tceQlHlBn5n fvpQ== X-Gm-Message-State: APt69E0VdYzKiHQ+0cv1DvtFhyOI9S6dMK5CyVkgAUqA4RM2DPetqQqB vEA9W0G4M61oLUCMftGpteyvBxu2 X-Google-Smtp-Source: AAOMgpdvrmLmexVFYdRupA8D9tsTlj3bHK3CefR0C+/v0DXTL60HECVTX21l14aytzukMdNywm8Obw== X-Received: by 2002:a1c:568a:: with SMTP id k132-v6mr3368379wmb.89.1530134567133; Wed, 27 Jun 2018 14:22:47 -0700 (PDT) Received: from haneen-vb ([78.180.222.80]) by smtp.gmail.com with ESMTPSA id u16-v6sm4229510wrp.44.2018.06.27.14.22.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 27 Jun 2018 14:22:46 -0700 (PDT) Date: Thu, 28 Jun 2018 00:22:43 +0300 From: Haneen Mohammed To: dri-devel@lists.freedesktop.org Subject: [RFC 1/3] drm/vkms: Add functions to map GEM backing storage Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) X-Mailman-Approved-At: Thu, 28 Jun 2018 08:22:06 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: hamohammed.sa@gmail.com, rodrigosiqueiramelo@gmail.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP This patch add the necessary functions to map GEM backing memory into the kernel's virtual address space. Signed-off-by: Haneen Mohammed --- drivers/gpu/drm/vkms/vkms_drv.c | 1 + drivers/gpu/drm/vkms/vkms_drv.h | 5 ++++ drivers/gpu/drm/vkms/vkms_gem.c | 50 +++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c index c56d66d9ec56..8ab53958e4b9 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.c +++ b/drivers/gpu/drm/vkms/vkms_drv.c @@ -55,6 +55,7 @@ static struct drm_driver vkms_driver = { .dumb_create = vkms_dumb_create, .dumb_map_offset = vkms_dumb_map, .gem_vm_ops = &vkms_gem_vm_ops, + .gem_free_object_unlocked = vkms_gem_free_object, .name = DRIVER_NAME, .desc = DRIVER_DESC, diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h index f115e7d1ae03..d6cb8824cee2 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.h +++ b/drivers/gpu/drm/vkms/vkms_drv.h @@ -41,6 +41,7 @@ struct vkms_gem_object { struct drm_gem_object gem; struct mutex pages_lock; /* Page lock used in page fault handler */ struct page **pages; + void *vaddr; }; #define drm_crtc_to_vkms_output(target) \ @@ -67,4 +68,8 @@ int vkms_dumb_create(struct drm_file *file, struct drm_device *dev, int vkms_dumb_map(struct drm_file *file, struct drm_device *dev, u32 handle, u64 *offset); +void vkms_gem_free_object(struct drm_gem_object *obj); + +void *vkms_gem_vmap(struct drm_gem_object *obj); + #endif /* _VKMS_DRV_H_ */ diff --git a/drivers/gpu/drm/vkms/vkms_gem.c b/drivers/gpu/drm/vkms/vkms_gem.c index 9f820f56b9e0..249855dded63 100644 --- a/drivers/gpu/drm/vkms/vkms_gem.c +++ b/drivers/gpu/drm/vkms/vkms_gem.c @@ -166,3 +166,53 @@ int vkms_dumb_map(struct drm_file *file, struct drm_device *dev, return ret; } + +void vkms_gem_free_object(struct drm_gem_object *obj) +{ + struct vkms_gem_object *vkms_obj = container_of(obj, + struct vkms_gem_object, + gem); + kvfree(vkms_obj->pages); + mutex_destroy(&vkms_obj->pages_lock); + drm_gem_object_release(obj); + kfree(vkms_obj); +} + +struct page **get_pages(struct vkms_gem_object *vkms_obj) +{ + struct drm_gem_object *gem_obj = &vkms_obj->gem; + struct page **pages = vkms_obj->pages; + + if (!pages) { + mutex_lock(&vkms_obj->pages_lock); + pages = drm_gem_get_pages(gem_obj); + if (IS_ERR(pages)) { + mutex_unlock(&vkms_obj->pages_lock); + return pages; + } + + vkms_obj->pages = pages; + mutex_unlock(&vkms_obj->pages_lock); + } + + return pages; +} + +void *vkms_gem_vmap(struct drm_gem_object *obj) +{ + void *vaddr = NULL; + struct vkms_gem_object *vkms_obj = container_of(obj, + struct vkms_gem_object, + gem); + unsigned int n_pages = obj->size >> PAGE_SHIFT; + struct page **pages = get_pages(vkms_obj); + + if (IS_ERR(pages)) { + DRM_INFO("pages allocation failed %ld\n", PTR_ERR(pages)); + return vaddr; + } + + vaddr = vmap(pages, n_pages, VM_MAP, PAGE_KERNEL); + + return vaddr; +}