From patchwork Mon Sep 11 14:31:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Noralf_Tr=C3=B8nnes?= X-Patchwork-Id: 9947461 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 F15EE602C9 for ; Mon, 11 Sep 2017 14:33:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E09CE28C3D for ; Mon, 11 Sep 2017 14:33:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C728728C85; Mon, 11 Sep 2017 14:33:09 +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=-4.2 required=2.0 tests=BAYES_00, 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 254C02887A for ; Mon, 11 Sep 2017 14:32:19 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 800196E3DF; Mon, 11 Sep 2017 14:32:16 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from smtp.domeneshop.no (smtp.domeneshop.no [IPv6:2a01:5b40:0:3005::1]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2D6066E3E0; Mon, 11 Sep 2017 14:32:15 +0000 (UTC) Received: from 211.81-166-168.customer.lyse.net ([81.166.168.211]:41326 helo=localhost.localdomain) by smtp.domeneshop.no with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_CBC_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1drPkz-0000vg-DJ; Mon, 11 Sep 2017 16:32:13 +0200 From: =?UTF-8?q?Noralf=20Tr=C3=B8nnes?= To: dri-devel@lists.freedesktop.org Date: Mon, 11 Sep 2017 16:31:56 +0200 Message-Id: <1505140322-17416-3-git-send-email-noralf@tronnes.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1505140322-17416-1-git-send-email-noralf@tronnes.org> References: <1505140322-17416-1-git-send-email-noralf@tronnes.org> MIME-Version: 1.0 Cc: daniel.vetter@ffwll.ch, intel-gfx@lists.freedesktop.org, =?UTF-8?q?Noralf=20Tr=C3=B8nnes?= , laurent.pinchart@ideasonboard.com, dh.herrmann@gmail.com Subject: [Intel-gfx] [PATCH 2/8] drm/framebuffer: Add drm_framebuffer_create_dumb() X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP drm_framebuffer_create_dumb() uses the dumb buffer API to create a buffer that is attached to a framebuffer. Useful for fbdev emulation. Signed-off-by: Noralf Trønnes --- drivers/gpu/drm/drm_framebuffer.c | 61 +++++++++++++++++++++++++++++++++++++++ include/drm/drm_framebuffer.h | 4 +++ 2 files changed, 65 insertions(+) diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c index af27984..07e5199 100644 --- a/drivers/gpu/drm/drm_framebuffer.c +++ b/drivers/gpu/drm/drm_framebuffer.c @@ -955,3 +955,64 @@ int drm_framebuffer_plane_height(int height, return fb_plane_height(height, fb->format, plane); } EXPORT_SYMBOL(drm_framebuffer_plane_height); + +/** + * drm_framebuffer_create_dumb - Create dumb framebuffer + * @file_priv: DRM file + * @width: Framebuffer width + * @height: Framebuffer height + * @format: Framebuffer FOURCC format + * + * This function creates a framebuffer backed by a dumb buffer for in-kernel + * use. fbdev emulation code can use this to create a framebuffer. + * + * Returns: + * Pointer to a drm_framebuffer on success or an error pointer on failure. + */ +struct drm_framebuffer * +drm_framebuffer_create_dumb(struct drm_file *file_priv, unsigned int width, + unsigned int height, u32 format) +{ + struct drm_device *dev = file_priv->minor->dev; + struct drm_mode_create_dumb dumb_args = { 0 }; + struct drm_mode_fb_cmd2 fb_args = { 0 }; + struct drm_framebuffer *fb; + int ret; + + dumb_args.width = width; + dumb_args.height = height; + dumb_args.bpp = drm_format_plane_cpp(format, 0) * 8; + + ret = drm_mode_create_dumb_ioctl(dev, &dumb_args, file_priv); + if (ret) + return ERR_PTR(ret); + + fb_args.width = width; + fb_args.height = height; + fb_args.pixel_format = format; + fb_args.handles[0] = dumb_args.handle; + fb_args.pitches[0] = dumb_args.pitch; + + ret = drm_mode_addfb2(dev, &fb_args, file_priv); + if (ret) + goto err_destroy_dumb; + + fb = drm_framebuffer_lookup(dev, fb_args.fb_id); + if (!fb) { + ret = -ENOENT; + goto err_rmfb; + } + + /* drop the reference we picked up in framebuffer lookup */ + drm_framebuffer_put(fb); + + return fb; + +err_rmfb: + drm_mode_rmfb(dev, &fb_args, file_priv); +err_destroy_dumb: + drm_mode_destroy_dumb_ioctl(dev, &dumb_args, file_priv); + + return ERR_PTR(ret); +} +EXPORT_SYMBOL(drm_framebuffer_create_dumb); diff --git a/include/drm/drm_framebuffer.h b/include/drm/drm_framebuffer.h index b6996dd..212c66a 100644 --- a/include/drm/drm_framebuffer.h +++ b/include/drm/drm_framebuffer.h @@ -306,4 +306,8 @@ int drm_framebuffer_plane_width(int width, int drm_framebuffer_plane_height(int height, const struct drm_framebuffer *fb, int plane); +struct drm_framebuffer * +drm_framebuffer_create_dumb(struct drm_file *file_priv, unsigned int width, + unsigned int height, u32 format); + #endif