From patchwork Tue Mar 26 09:17:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Zimmermann X-Patchwork-Id: 10870729 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 27C821669 for ; Tue, 26 Mar 2019 09:18:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 150302873C for ; Tue, 26 Mar 2019 09:18:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0964B29035; Tue, 26 Mar 2019 09:18:26 +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,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 AA7CB2873C for ; Tue, 26 Mar 2019 09:18:25 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 94C196E7BF; Tue, 26 Mar 2019 09:18:24 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) by gabe.freedesktop.org (Postfix) with ESMTPS id DC6F66E7B2 for ; Tue, 26 Mar 2019 09:17:56 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 6F89AACD0; Tue, 26 Mar 2019 09:17:55 +0000 (UTC) From: Thomas Zimmermann To: airlied@linux.ie, daniel@ffwll.ch, b.zolnierkie@samsung.com Subject: [PATCH 05/11] drm/fbdevdrm: Add GEM and dumb interfaces Date: Tue, 26 Mar 2019 10:17:38 +0100 Message-Id: <20190326091744.11542-6-tzimmermann@suse.de> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190326091744.11542-1-tzimmermann@suse.de> References: <20190326091744.11542-1-tzimmermann@suse.de> MIME-Version: 1.0 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: linux-fbdev@vger.kernel.org, Thomas Zimmermann , dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Thomas Zimmermann --- drivers/gpu/drm/fbdevdrm/fbdevdrm_drv.c | 77 +++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/drivers/gpu/drm/fbdevdrm/fbdevdrm_drv.c b/drivers/gpu/drm/fbdevdrm/fbdevdrm_drv.c index 4a6ba6c85c5c..4724e3df6ace 100644 --- a/drivers/gpu/drm/fbdevdrm/fbdevdrm_drv.c +++ b/drivers/gpu/drm/fbdevdrm/fbdevdrm_drv.c @@ -18,6 +18,7 @@ #include #include #include +#include "fbdevdrm_bo.h" #include "fbdevdrm_device.h" /* DRM porting note: Here are some general information about the driver, @@ -64,7 +65,82 @@ static const struct file_operations driver_fops = { .read = drm_read }; +static void driver_gem_free_object(struct drm_gem_object *gobj) +{ + struct fbdevdrm_bo *fbo = fbdevdrm_bo_of_gem(gobj); + fbdevdrm_bo_put(fbo); +} + +static int driver_dumb_create(struct drm_file *file_priv, + struct drm_device *dev, + struct drm_mode_create_dumb *args) +{ + int ret; + struct fbdevdrm_bo *fbo; + u32 size, handle; + + args->pitch = args->width * ((args->bpp + 7) / 8); + args->size = args->pitch * args->height; + + size = roundup(args->size, PAGE_SIZE); + if (!size) + return -EINVAL; + + /* DRM porting note: FBdev aligns scanout buffers to multiples + * of the scanline size in bytes. TTM aligns buffers to page + * boundaries. To maintain FBdev buffers with TTM, we align BOs + * at both, the scanline offsets and the page offsets. Depending + * on resolution and color depth, this may result in some memory + * overhead. After porting an FBdev driver to DRM, you can remove + * this constrain and simply align to page boundaries. + */ + fbo = fbdevdrm_bo_create_with_pitch(dev, size, args->pitch, 0); + if (IS_ERR(fbo)) { + ret = PTR_ERR(fbo); + if (ret != -ERESTARTSYS) + DRM_ERROR("fbdevdrm: fbdevdrm_bo_create_with_pitch() " + "failed, error %d\n", -ret); + return ret; + } + + ret = drm_gem_handle_create(file_priv, &fbo->gem, &handle); + drm_gem_object_put_unlocked(&fbo->gem); /* TODO: verify ref-count */ + if (ret < 0) + goto err_fbdevdrm_bo_put; + + args->handle = handle; + + return 0; + +err_fbdevdrm_bo_put: + fbdevdrm_bo_put(fbo); + return ret; +} + +static int driver_dumb_mmap_offset(struct drm_file *file_priv, + struct drm_device *dev, uint32_t handle, + uint64_t *offset) +{ + struct drm_gem_object *obj; + struct fbdevdrm_bo *fbo; + + obj = drm_gem_object_lookup(file_priv, handle); + if (obj == NULL) + return -ENOENT; + + fbo = fbdevdrm_bo_of_gem(obj); + *offset = fbdevdrm_bo_mmap_offset(fbo); + + drm_gem_object_put_unlocked(obj); + return 0; +} + static struct drm_driver fbdevdrm_drv = { + /* GEM interfaces */ + .gem_free_object = driver_gem_free_object, + /* Dumb interfaces */ + .dumb_create = driver_dumb_create, + .dumb_map_offset = driver_dumb_mmap_offset, /* data fields */ .major = DRIVER_MAJOR, .minor = DRIVER_MINOR, @@ -72,6 +148,7 @@ static struct drm_driver fbdevdrm_drv = { .name = DRIVER_NAME, .desc = DRIVER_DESCRIPTION, .date = DRIVER_DATE, + .driver_features = DRIVER_GEM, .fops = &driver_fops };