From patchwork Fri Jan 5 02:05:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hyun Kwon X-Patchwork-Id: 10145969 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 6048D60329 for ; Fri, 5 Jan 2018 02:21:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7833428922 for ; Fri, 5 Jan 2018 02:21:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6C97728925; Fri, 5 Jan 2018 02:21:18 +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.1 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID 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 6A2F428922 for ; Fri, 5 Jan 2018 02:21:17 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B1CF06E29D; Fri, 5 Jan 2018 02:21:16 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org X-Greylist: delayed 897 seconds by postgrey-1.35 at gabe; Fri, 05 Jan 2018 02:21:14 UTC Received: from NAM01-BY2-obe.outbound.protection.outlook.com (mail-by2nam01on0075.outbound.protection.outlook.com [104.47.34.75]) by gabe.freedesktop.org (Postfix) with ESMTPS id ADCDA6E29C for ; Fri, 5 Jan 2018 02:21:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector1-xilinx-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=xrFc5n6S20NzsQznM5S+35I/lYGiEBHTNvn/qa/f0Qc=; b=TQE9CXT37yiFnNJZrXRNP8wtJyWcL3Ol1AcBSoQAu5kDtFybWZUdoWlww7ChKU/lhzq5bv6jWlDTOVoXPpAYYTX+4LDg94noNxajd+d84zym9CD1J2ErMF6a28vqDvTdRRep5aYmKXAxe7Q7zHi764oMeGrh+NikCneuE1qCSg4= Received: from MWHPR02CA0035.namprd02.prod.outlook.com (10.164.133.24) by DM5PR02MB3386.namprd02.prod.outlook.com (10.164.152.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.386.5; Fri, 5 Jan 2018 02:06:16 +0000 Received: from CY1NAM02FT015.eop-nam02.prod.protection.outlook.com (2a01:111:f400:7e45::201) by MWHPR02CA0035.outlook.office365.com (2603:10b6:301:60::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.386.5 via Frontend Transport; Fri, 5 Jan 2018 02:06:13 +0000 Authentication-Results: spf=pass (sender IP is 149.199.60.83) smtp.mailfrom=xilinx.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=bestguesspass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.60.83 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.60.83; helo=xsj-pvapsmtpgw01; Received: from xsj-pvapsmtpgw01 (149.199.60.83) by CY1NAM02FT015.mail.protection.outlook.com (10.152.75.146) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.345.12 via Frontend Transport; Fri, 5 Jan 2018 02:06:12 +0000 Received: from unknown-38-66.xilinx.com ([149.199.38.66] helo=xsj-pvapsmtp01) by xsj-pvapsmtpgw01 with esmtp (Exim 4.63) (envelope-from ) id 1eXHOe-0005ue-Ar; Thu, 04 Jan 2018 18:06:12 -0800 Received: from [127.0.0.1] (helo=xsj-smtp-dlp1.xlnx.xilinx.com) by xsj-pvapsmtp01 with esmtp (Exim 4.63) (envelope-from ) id 1eXHOe-0003P3-7Y; Thu, 04 Jan 2018 18:06:12 -0800 Received: from xsj-pvapsmtp01 (maildrop.xilinx.com [149.199.38.66]) by xsj-smtp-dlp1.xlnx.xilinx.com (8.13.8/8.13.1) with ESMTP id w0526BXZ003021; Thu, 4 Jan 2018 18:06:11 -0800 Received: from [172.19.2.244] (helo=xsjhyunkubuntu) by xsj-pvapsmtp01 with esmtp (Exim 4.63) (envelope-from ) id 1eXHOd-0003OY-7W; Thu, 04 Jan 2018 18:06:11 -0800 Received: by xsjhyunkubuntu (Postfix, from userid 13638) id 379992C68EA; Thu, 4 Jan 2018 18:06:11 -0800 (PST) From: Hyun Kwon To: , Subject: [PATCH 03/10] drm: xlnx: Add xlnx fb of Xilinx DRM KMS Date: Thu, 4 Jan 2018 18:05:52 -0800 Message-ID: <1515117959-18068-4-git-send-email-hyun.kwon@xilinx.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1515117959-18068-1-git-send-email-hyun.kwon@xilinx.com> References: <1515117959-18068-1-git-send-email-hyun.kwon@xilinx.com> X-RCIS-Action: ALLOW X-TM-AS-Product-Ver: IMSS-7.1.0.1224-8.2.0.1013-23572.006 X-TM-AS-User-Approved-Sender: Yes;Yes X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:149.199.60.83; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(396003)(39860400002)(376002)(346002)(39380400002)(2980300002)(438002)(199004)(189003)(106466001)(5660300001)(63266004)(8936002)(50226002)(305945005)(6266002)(356003)(59450400001)(47776003)(4326008)(48376002)(50466002)(90966002)(478600001)(36756003)(103686004)(316002)(6666003)(2950100002)(107886003)(76176011)(51416003)(2906002)(106002)(81156014)(54906003)(110136005)(52956003)(16586007)(81166006)(42186006)(8676002)(107986001)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR02MB3386; H:xsj-pvapsmtpgw01; FPR:; SPF:Pass; PTR:unknown-60-83.xilinx.com; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; CY1NAM02FT015; 1:v+wjExCDvi6r1+BWZiYr7GnprLXBkDSBNzWFv77dKSc6JPQ4NVZg8pYFY+WOTriLXvTuFMX5rS4l6Qehuwa7F2SJYjvqbx8RGlkgtduPvNqPgq5QiVLAUgtgW3WAnWsB MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c1182a36-febf-4b46-c53d-08d553e0e59a X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(5600026)(4604075)(4608076)(2017052603307)(7153060); SRVR:DM5PR02MB3386; X-Microsoft-Exchange-Diagnostics: 1; DM5PR02MB3386; 3:esVaiUHtRvdxCSfFXI/wM0LQripc4E5x3pNF0YpN2sUQUD8y7oE8CuId26FLsRiR/zn3kHitaV/iMCsgH5aTo/vQfKDcXYy4byca4M/GqXbLxZv/E8p5qJBt9FAUN1oc1LRsQpcLCs8bV08q73gVExuDIfIee92QB9wYQT5yIlXIZUaOTAMIldfbcjaHA0oUscXTYXBMLnlr/6vrR5bGo8NR8E0AcQtjZ7sP8nO29JEV54/3XOoqRIDp3IN7htTfOFptzI2sfod/HJBqD9nJ9DL5mWUT+ZuLUd4ABEGWjGgyXz+Ue6goL5jbKL2qn+VagVjVayw8x73SyefnfSnhG54Pfd2P6kHCO+leudFjoD4=; 25:quWvlbJ3z0pVl3zZCzUqAY4OHTq9oy1NTYq6tSxkCKYTiDoyU56U5cUGrlcqpGmb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nHDKlcAg+vdNU/URlnfM1W3X X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(192813158149592); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040470)(2401047)(8121501046)(5005006)(93006095)(93004095)(10201501046)(3002001)(3231023)(944501075)(6055026)(6041268)(20161123564045)(20161123562045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(6072148)(201708071742011); SRVR:DM5PR02MB3386; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:DM5PR02MB3386; X-Microsoft-Exchange-Diagnostics: 1; DM5PR02MB3386; 4:uZqV0vtqeXRvqCzcrbGSkdF7kdQ+YDWYYL1wczJOBHR3b/FfFoDP1LjyzGtgfeEJmJFXIs36Eq6tN6WxfULMOQOyqfO2Cu+78U5oTHhu0W5lug+HyyqKaREWB0iodfyNJ0gTPSNvq/ba5/77DUQKMoEE4hsr6o99KRJKfE7JKkA7L+nUukL7qSGWqiH7jatGWuranEeOtV5xYZTOcalXYZdlI9UKggKl3tmfAlA/kEY4oCIEFeabYHOIZt50t4PO/bgxK268mBjztX/AKMnUoD+f9GF6nXyUc0k0nPZnoNsqSNdVUzdeRtluAixSyvQu X-Forefront-PRVS: 05437568AA X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM5PR02MB3386; 23:V3X4cuqKt8Oz6PcA04wasvOTKXJk7NWNLGL6od02k?= =?us-ascii?Q?3KoM/XglyTcNm7Omz+wJa0GJPhjwygaSVJolm7/3YleQ/B+h3dfgs9xK9dbo?= =?us-ascii?Q?iQv6groOXlMeA7aYAXnRxL/cVzHkn2Xsr09jX0Vu66b1/PaTai+3UU6KP6Cz?= =?us-ascii?Q?M9CvB+9Q0gTnvDaVrFbcBUdE+YHmCxQoPruKV2Dut6a0VkcEypESB8B/JyAZ?= =?us-ascii?Q?Fq2zCmyzPH5eQEvB4nEnxcUDprVOYj7lvReoIDQoNRh9i9tOk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jKorPYBeujxunmRmpyb7+wglH1h5ZgCJjvIUM6V01YJOZHeZzHxhNryJxsVFNtB5g+dEZEYspWUi68TTsQs7mlZ2mnu8QKAC3MVVgc8P30EN70FOwgrjT/KjTCLl73szGXDAthnbUlXXYFS9Jjxt5FphfdVw0jOuc/EYGTO72I3/IG3OUk+6Q1I42Ja/5BnJ7Fh33QpRkEm6Vjrl+u49YfbeKIYmxm1rHNsf+IXg8EoGCBWYJSq+jtUdjOECV9QV3P73qBYI3a08p2FhipW2ruqVSAL9lIGXhwLmicKjp5eaOyOCXbA7v61w8dKgFiM7r0mgw=; 5:UjoJVM7NBc2Dt4S3D1wMGOkY0igQ2YrKGFIR6vEzlTkSobR+EVrMVS4uZBU2Gkrqzk0MCxUNm0zqZcHiGimq5gMyyD8tPHRRPa+n9q/bCAiyE1K9yW9YLGp8ZWls2c+cRINZvFii/jH0tVFdgdKma78kQVpCgsOYvWiGlc4jsoo=; 24:EZJX2hRR2U+acimXo1TYQR1PGowgZeF6NEOo2hpXvd8Uuo/HjyMsqHmWkVHQcg4kNDZtV9x1h3aSBzLq5z5Zvtz2VYDtVBjS+Nvrql6Gw0k=; 7:jKRJYCbcr33IyMpwkeoy0RpEntYOeoeITLhRhYj58lB2Hh1fI5h7v8xW0BKrsLAoTvbroof4WpWYZrTvGyWzHOswaktUKHptQSQb2UnD0HvMsENCaVx9jQQN37AdOK7NucKM3M0HpuByjYviO0+N49ckrG4ck4OqStBKzckoMWpb8+6ojYdV2m3F4I4+kbctj7Kl0qPZnZ86XLSoa17h+NymB/WLWFKj/iUmlzO5IQRqsDXsHAHrGl15/ogrvVui SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Jan 2018 02:06:12.9885 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c1182a36-febf-4b46-c53d-08d553e0e59a X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c; Ip=[149.199.60.83]; Helo=[xsj-pvapsmtpgw01] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR02MB3386 Cc: Michal Simek , Hyun Kwon X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Helpers for framebuffers backed by cma allocator. Signed-off-by: Hyun Kwon --- drivers/gpu/drm/xlnx/xlnx_fb.c | 467 +++++++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/xlnx/xlnx_fb.h | 30 +++ 2 files changed, 497 insertions(+) create mode 100644 drivers/gpu/drm/xlnx/xlnx_fb.c create mode 100644 drivers/gpu/drm/xlnx/xlnx_fb.h diff --git a/drivers/gpu/drm/xlnx/xlnx_fb.c b/drivers/gpu/drm/xlnx/xlnx_fb.c new file mode 100644 index 0000000..dbe9fbf --- /dev/null +++ b/drivers/gpu/drm/xlnx/xlnx_fb.c @@ -0,0 +1,467 @@ +/* + * Xilinx DRM KMS Framebuffer helper + * + * Copyright (C) 2015 - 2018 Xilinx, Inc. + * + * Author: Hyun Woo Kwon + * + * Based on drm_fb_cma_helper.c + * + * Copyright (C) 2012 Analog Device Inc. + * + * SPDX-License-Identifier: GPL-2.0 + */ + +#include +#include +#include +#include +#include + +#include "xlnx_fb.h" + +#define XLNX_MAX_PLANES 4 + +struct xlnx_fb { + struct drm_framebuffer base; + struct drm_gem_cma_object *obj[XLNX_MAX_PLANES]; +}; + +struct xlnx_fbdev { + struct drm_fb_helper fb_helper; + struct xlnx_fb *fb; + unsigned int align; + unsigned int vres_mult; +}; + +static inline struct xlnx_fbdev *to_fbdev(struct drm_fb_helper *fb_helper) +{ + return container_of(fb_helper, struct xlnx_fbdev, fb_helper); +} + +static inline struct xlnx_fb *to_fb(struct drm_framebuffer *base_fb) +{ + return container_of(base_fb, struct xlnx_fb, base); +} + +static void xlnx_fb_destroy(struct drm_framebuffer *base_fb) +{ + struct xlnx_fb *fb = to_fb(base_fb); + int i; + + for (i = 0; i < XLNX_MAX_PLANES; i++) + if (fb->obj[i]) + drm_gem_object_unreference_unlocked(&fb->obj[i]->base); + + drm_framebuffer_cleanup(base_fb); + kfree(fb); +} + +static int xlnx_fb_create_handle(struct drm_framebuffer *base_fb, + struct drm_file *file_priv, + unsigned int *handle) +{ + struct xlnx_fb *fb = to_fb(base_fb); + + return drm_gem_handle_create(file_priv, &fb->obj[0]->base, handle); +} + +static struct drm_framebuffer_funcs xlnx_fb_funcs = { + .destroy = xlnx_fb_destroy, + .create_handle = xlnx_fb_create_handle, +}; + +/** + * xlnx_fb_alloc - Allocate a xlnx_fb + * @drm: DRM object + * @mode_cmd: drm_mode_fb_cmd2 struct + * @obj: pointers for returned drm_gem_cma_objects + * @num_planes: number of planes to be allocated + * + * This function is based on drm_fb_cma_alloc(). + * + * Return: a xlnx_fb object, or ERR_PTR. + */ +static struct xlnx_fb * +xlnx_fb_alloc(struct drm_device *drm, + const struct drm_mode_fb_cmd2 *mode_cmd, + struct drm_gem_cma_object **obj, unsigned int num_planes) +{ + struct xlnx_fb *fb; + int ret; + int i; + + fb = kzalloc(sizeof(*fb), GFP_KERNEL); + if (!fb) + return ERR_PTR(-ENOMEM); + + drm_helper_mode_fill_fb_struct(drm, &fb->base, mode_cmd); + + for (i = 0; i < num_planes; i++) + fb->obj[i] = obj[i]; + + ret = drm_framebuffer_init(drm, &fb->base, &xlnx_fb_funcs); + if (ret) { + dev_err(drm->dev, "Failed to initialize fb: %d\n", ret); + kfree(fb); + return ERR_PTR(ret); + } + + return fb; +} + +/** + * xlnx_fb_get_paddr - Get physycal address of framebuffer + * @base_fb: the framebuffer + * @plane: which plane + * + * This function is based on drm_fb_cma_get_gem_obj(). + * + * Return: a physical address of the plane, or 0 + */ +dma_addr_t +xlnx_fb_get_paddr(struct drm_framebuffer *base_fb, unsigned int plane) +{ + struct xlnx_fb *fb = to_fb(base_fb); + + if (plane >= XLNX_MAX_PLANES) + return 0; + + return fb->obj[plane]->paddr; +} +EXPORT_SYMBOL_GPL(xlnx_fb_get_paddr); + +static int +xlnx_fb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg) +{ + struct drm_fb_helper *fb_helper = info->par; + unsigned int i; + int ret = 0; + + switch (cmd) { + case FBIO_WAITFORVSYNC: + for (i = 0; i < fb_helper->crtc_count; i++) { + struct drm_mode_set *mode_set; + struct drm_crtc *crtc; + + mode_set = &fb_helper->crtc_info[i].mode_set; + crtc = mode_set->crtc; + ret = drm_crtc_vblank_get(crtc); + if (!ret) { + drm_crtc_wait_one_vblank(crtc); + drm_crtc_vblank_put(crtc); + } + } + return ret; + default: + return -ENOTTY; + } + + return 0; +} + +static struct fb_ops xlnx_fbdev_ops = { + .owner = THIS_MODULE, + .fb_fillrect = sys_fillrect, + .fb_copyarea = sys_copyarea, + .fb_imageblit = sys_imageblit, + .fb_check_var = drm_fb_helper_check_var, + .fb_set_par = drm_fb_helper_set_par, + .fb_blank = drm_fb_helper_blank, + .fb_pan_display = drm_fb_helper_pan_display, + .fb_setcmap = drm_fb_helper_setcmap, + .fb_ioctl = xlnx_fb_ioctl, +}; + +/** + * xlnx_fbdev_create - Create the fbdev with a framebuffer + * @fb_helper: fb helper structure + * @size: framebuffer size info + * + * This function is based on drm_fbdev_cma_create(). + * + * Return: 0 if successful, or the error code. + */ +static int xlnx_fbdev_create(struct drm_fb_helper *fb_helper, + struct drm_fb_helper_surface_size *size) +{ + struct xlnx_fbdev *fbdev = to_fbdev(fb_helper); + struct drm_mode_fb_cmd2 mode_cmd = { 0 }; + struct drm_device *drm = fb_helper->dev; + struct drm_gem_cma_object *obj; + struct drm_framebuffer *base_fb; + unsigned int bytes_per_pixel; + unsigned long offset; + struct fb_info *fbi; + size_t bytes; + int ret; + + dev_dbg(drm->dev, "surface width(%d), height(%d) and bpp(%d)\n", + size->surface_width, size->surface_height, size->surface_bpp); + + bytes_per_pixel = DIV_ROUND_UP(size->surface_bpp, 8); + + mode_cmd.width = size->surface_width; + mode_cmd.height = size->surface_height; + mode_cmd.pitches[0] = ALIGN(size->surface_width * bytes_per_pixel, + fbdev->align); + mode_cmd.pixel_format = xlnx_get_format(drm); + + mode_cmd.height *= fbdev->vres_mult; + bytes = mode_cmd.pitches[0] * mode_cmd.height; + obj = drm_gem_cma_create(drm, bytes); + if (IS_ERR(obj)) + return PTR_ERR(obj); + + fbi = framebuffer_alloc(0, drm->dev); + if (!fbi) { + dev_err(drm->dev, "Failed to allocate framebuffer info.\n"); + ret = -ENOMEM; + goto err_drm_gem_cma_free_object; + } + + fbdev->fb = xlnx_fb_alloc(drm, &mode_cmd, &obj, 1); + if (IS_ERR(fbdev->fb)) { + dev_err(drm->dev, "Failed to allocate DRM framebuffer.\n"); + ret = PTR_ERR(fbdev->fb); + goto err_framebuffer_release; + } + + base_fb = &fbdev->fb->base; + fb_helper->fb = base_fb; + fb_helper->fbdev = fbi; + fbi->par = fb_helper; + fbi->flags = FBINFO_FLAG_DEFAULT; + fbi->fbops = &xlnx_fbdev_ops; + + ret = fb_alloc_cmap(&fbi->cmap, 256, 0); + if (ret) { + dev_err(drm->dev, "Failed to allocate color map.\n"); + goto err_xlnx_fb_destroy; + } + + drm_fb_helper_fill_fix(fbi, base_fb->pitches[0], + base_fb->format->depth); + drm_fb_helper_fill_var(fbi, fb_helper, base_fb->width, base_fb->height); + fbi->var.yres = base_fb->height / fbdev->vres_mult; + + offset = fbi->var.xoffset * bytes_per_pixel; + offset += fbi->var.yoffset * base_fb->pitches[0]; + + drm->mode_config.fb_base = (resource_size_t)obj->paddr; + fbi->screen_base = (char __iomem *)(obj->vaddr + offset); + fbi->fix.smem_start = (unsigned long)(obj->paddr + offset); + fbi->screen_size = bytes; + fbi->fix.smem_len = bytes; + + return 0; + +err_xlnx_fb_destroy: + drm_framebuffer_unregister_private(base_fb); + xlnx_fb_destroy(base_fb); +err_framebuffer_release: + framebuffer_release(fbi); +err_drm_gem_cma_free_object: + drm_gem_cma_free_object(&obj->base); + return ret; +} + +static struct drm_fb_helper_funcs xlnx_fb_helper_funcs = { + .fb_probe = xlnx_fbdev_create, +}; + +/** + * xlnx_fb_init - Allocate and initializes the Xilinx framebuffer + * @drm: DRM device + * @preferred_bpp: preferred bits per pixel for the device + * @max_conn_count: maximum number of connectors + * @align: alignment value for pitch + * @vres_mult: multiplier for virtual resolution + * + * This function is based on drm_fbdev_cma_init(). + * + * Return: a newly allocated drm_fb_helper struct or a ERR_PTR. + */ +struct drm_fb_helper * +xlnx_fb_init(struct drm_device *drm, int preferred_bpp, + unsigned int max_conn_count, unsigned int align, + unsigned int vres_mult) +{ + struct xlnx_fbdev *fbdev; + struct drm_fb_helper *fb_helper; + int ret; + + fbdev = kzalloc(sizeof(*fbdev), GFP_KERNEL); + if (!fbdev) + return ERR_PTR(-ENOMEM); + + fbdev->vres_mult = vres_mult; + fbdev->align = align; + fb_helper = &fbdev->fb_helper; + drm_fb_helper_prepare(drm, fb_helper, &xlnx_fb_helper_funcs); + + ret = drm_fb_helper_init(drm, fb_helper, max_conn_count); + if (ret < 0) { + dev_err(drm->dev, "Failed to initialize drm fb helper.\n"); + goto err_free; + } + + ret = drm_fb_helper_single_add_all_connectors(fb_helper); + if (ret < 0) { + dev_err(drm->dev, "Failed to add connectors.\n"); + goto err_drm_fb_helper_fini; + } + + ret = drm_fb_helper_initial_config(fb_helper, preferred_bpp); + if (ret < 0) { + dev_err(drm->dev, "Failed to set initial hw configuration.\n"); + goto err_drm_fb_helper_fini; + } + + return fb_helper; + +err_drm_fb_helper_fini: + drm_fb_helper_fini(fb_helper); +err_free: + kfree(fbdev); + return ERR_PTR(ret); +} + +/** + * xlnx_fbdev_defio_fini - Free the defio fb + * @fbi: fb_info struct + * + * This function is based on drm_fbdev_cma_defio_fini(). + */ +static void xlnx_fbdev_defio_fini(struct fb_info *fbi) +{ + if (!fbi->fbdefio) + return; + + fb_deferred_io_cleanup(fbi); + kfree(fbi->fbdefio); + kfree(fbi->fbops); +} + +/** + * xlnx_fbdev_fini - Free the Xilinx framebuffer + * @fb_helper: drm_fb_helper struct + * + * This function is based on drm_fbdev_cma_fini(). + */ +void xlnx_fb_fini(struct drm_fb_helper *fb_helper) +{ + struct xlnx_fbdev *fbdev = to_fbdev(fb_helper); + + drm_fb_helper_unregister_fbi(&fbdev->fb_helper); + if (fbdev->fb_helper.fbdev) + xlnx_fbdev_defio_fini(fbdev->fb_helper.fbdev); + + if (fbdev->fb_helper.fb) + drm_framebuffer_remove(fbdev->fb_helper.fb); + + drm_fb_helper_fini(&fbdev->fb_helper); + kfree(fbdev); +} + +/** + * xlnx_fb_restore_mode - Restores initial framebuffer mode + * @fb_helper: drm_fb_helper struct, may be NULL + * + * This function is based on drm_fbdev_cma_restore_mode() and usually called + * from the Xilinx DRM drivers lastclose callback. + */ +void xlnx_fb_restore_mode(struct drm_fb_helper *fb_helper) +{ + if (!fb_helper) + return; + drm_fb_helper_restore_fbdev_mode_unlocked(fb_helper); +} + +/** + * xlnx_fb_create - (struct drm_mode_config_funcs *)->fb_create callback + * @drm: DRM device + * @file_priv: drm file private data + * @mode_cmd: mode command for fb creation + * + * This functions creates a drm_framebuffer for given mode @mode_cmd. This + * functions is intended to be used for the fb_create callback function of + * drm_mode_config_funcs. + * + * Return: a drm_framebuffer object if successful, or ERR_PTR. + */ +struct drm_framebuffer * +xlnx_fb_create(struct drm_device *drm, struct drm_file *file_priv, + const struct drm_mode_fb_cmd2 *mode_cmd) +{ + struct xlnx_fb *fb; + struct drm_gem_cma_object *objs[XLNX_MAX_PLANES]; + struct drm_gem_object *obj; + const struct drm_format_info *info; + struct drm_format_name_buf format_name; + int ret; + int i; + + info = drm_format_info(mode_cmd->pixel_format); + if (!info) { + dev_err(drm->dev, "unsupported framebuffer format %s\n", + drm_get_format_name(mode_cmd->pixel_format, + &format_name)); + ret = -EINVAL; + goto err_out; + } + + for (i = 0; i < info->num_planes; i++) { + unsigned int width = mode_cmd->width / (i ? info->hsub : 1); + unsigned int height = mode_cmd->height / (i ? info->vsub : 1); + unsigned int min_size; + + obj = drm_gem_object_lookup(file_priv, + mode_cmd->handles[i]); + if (!obj) { + dev_err(drm->dev, "Failed to lookup GEM object\n"); + ret = -ENXIO; + goto err_gem_object_unreference; + } + + min_size = (height - 1) * mode_cmd->pitches[i] + width * + info->cpp[i] + mode_cmd->offsets[i]; + + if (obj->size < min_size) { + drm_gem_object_unreference_unlocked(obj); + ret = -EINVAL; + goto err_gem_object_unreference; + } + objs[i] = to_drm_gem_cma_obj(obj); + } + + fb = xlnx_fb_alloc(drm, mode_cmd, objs, i); + if (IS_ERR(fb)) { + ret = PTR_ERR(fb); + goto err_gem_object_unreference; + } + + fb->base.format = info; + + return &fb->base; + +err_gem_object_unreference: + for (i--; i >= 0; i--) + drm_gem_object_unreference_unlocked(&objs[i]->base); +err_out: + return ERR_PTR(ret); +} + +/** + * xlnx_fb_hotplug_event - Poll for hotpulug events + * @fb_helper: drm_fb_helper struct, may be NULL + * + * This function is based on drm_fbdev_cma_hotplug_event() and usually called + * from the Xilinx DRM drivers output_poll_changed callback. + */ +void xlnx_fb_hotplug_event(struct drm_fb_helper *fb_helper) +{ + if (!fb_helper) + return; + drm_fb_helper_hotplug_event(fb_helper); +} diff --git a/drivers/gpu/drm/xlnx/xlnx_fb.h b/drivers/gpu/drm/xlnx/xlnx_fb.h new file mode 100644 index 0000000..3f7e962 --- /dev/null +++ b/drivers/gpu/drm/xlnx/xlnx_fb.h @@ -0,0 +1,30 @@ +/* + * Xilinx DRM KMS Framebuffer helper header + * + * Copyright (C) 2015 - 2018 Xilinx, Inc. + * + * Author: Hyun Woo Kwon + * + * SPDX-License-Identifier: GPL-2.0 + */ + +#ifndef _XLNX_FB_H_ +#define _XLNX_FB_H_ + +struct drm_fb_helper; + +dma_addr_t +xlnx_fb_get_paddr(struct drm_framebuffer *base_fb, unsigned int plane); + +void xlnx_fb_restore_mode(struct drm_fb_helper *fb_helper); +struct drm_framebuffer * +xlnx_fb_create(struct drm_device *drm, struct drm_file *file_priv, + const struct drm_mode_fb_cmd2 *mode_cmd); +void xlnx_fb_hotplug_event(struct drm_fb_helper *fb_helper); +struct drm_fb_helper * +xlnx_fb_init(struct drm_device *drm, int preferred_bpp, + unsigned int max_conn_count, unsigned int align, + unsigned int vres_mult); +void xlnx_fb_fini(struct drm_fb_helper *fb_helper); + +#endif /* _XLNX_FB_H_ */