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: 10870695 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 3D03517E6 for ; Tue, 26 Mar 2019 09:17:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2A0822902D for ; Tue, 26 Mar 2019 09:17:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1E2762903E; Tue, 26 Mar 2019 09:17:57 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A16E72902E for ; Tue, 26 Mar 2019 09:17:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728991AbfCZJR4 (ORCPT ); Tue, 26 Mar 2019 05:17:56 -0400 Received: from mx2.suse.de ([195.135.220.15]:39724 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726258AbfCZJR4 (ORCPT ); Tue, 26 Mar 2019 05:17:56 -0400 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 Cc: dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, Thomas Zimmermann 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 Sender: linux-fbdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org 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 };