Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp610485imm; Wed, 19 Sep 2018 04:13:39 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYZeJweFsgLozHQDnmw9h69Up1UG1DCJt9LjrhtDTUs4GQ5vioF2XK6PbT6auYLJaRBYvuz X-Received: by 2002:a62:e08b:: with SMTP id d11-v6mr35666693pfm.214.1537355618842; Wed, 19 Sep 2018 04:13:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537355618; cv=none; d=google.com; s=arc-20160816; b=KKPi85Z8R11XBMY3m0KWLrQrqX9mPMAsoc40IcLYTeDDQnzcPcCNsQFCltKi2k28AC I6yoQ+wfFsbqNef5FwIf9qgs9BhMATyykt8SQasGXYLgm3HglFPzce6c391g3WN2hpIv sbHEfI+WwLKZmm1+1esIuTanUCpu1NqYzgUo3EgAS25hnqEhgKT1NCDBLA4op5fp4iu9 afBDhmBLcWA6W/xULAZdq7V93Et8eDJDvcE7mY+2tjXHfDM/S4T/xtfMvEIPe/fyyG4g h5wKWmHoLbpE6tf7XokkdMtoKNzid4w5mXFmtgo04O9nGj1UzLGZQi+LPsNdDU5NZbhk rzVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=KFFjnC+C3HH56WQEr9eV5DgQ3BzQkdh4TL/0lXNnbI0=; b=AL79EGXW09HUGFzbLgmuJEYuPAEZzFY8xtWDXTKVjCICqfmen99TO8/q8zmniWBhvf vNDW0rYwN/RLlqTd0qEWePzsXWuySRuwlKqM3b120atdoOHeKLNzjj/yxKfedotiyjuZ FUJRWYxrbcEQNln5nwauz4gbgKyFuUW08HFKOmdQ0rtY6BNx6Jh+esulFO7B9UuCGU1T rlngZOyiVWv9qzriXnjVWUXvVeoZr119a8U6dzHYhlQEpAmVjsB+V5pBRn7s5WlFVekM XihxcvT2eTQTudsXSFLXzN7YjRnVgbm2yPV3I1KONi+v7kJs0RKsfHbh0YieBdY/QbZb 17iA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m37-v6si21459789pla.236.2018.09.19.04.13.22; Wed, 19 Sep 2018 04:13:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731235AbeISQuX (ORCPT + 99 others); Wed, 19 Sep 2018 12:50:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52972 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727675AbeISQuW (ORCPT ); Wed, 19 Sep 2018 12:50:22 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8CEDE317C412; Wed, 19 Sep 2018 11:12:57 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-56.phx2.redhat.com [10.3.116.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0AC0227BAB; Wed, 19 Sep 2018 11:12:54 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 88D3A9C262; Wed, 19 Sep 2018 13:12:52 +0200 (CEST) From: Gerd Hoffmann To: dri-devel@lists.freedesktop.org Cc: michel@daenzer.net, imirkin@alum.mit.edu, Gerd Hoffmann , Gustavo Padovan , Maarten Lankhorst , Sean Paul , David Airlie , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v3 1/5] drm: move native byte order quirk to new drm_mode_legacy_fb_format2 function Date: Wed, 19 Sep 2018 13:12:48 +0200 Message-Id: <20180919111252.7932-2-kraxel@redhat.com> In-Reply-To: <20180919111252.7932-1-kraxel@redhat.com> References: <20180919111252.7932-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 19 Sep 2018 11:12:57 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Turns out we need the pixel format fixup not only for the addfb ioctl, but also for fbdev emulation code. Ideally we would place it in drm_mode_legacy_fb_format(). That would create alot of churn though, and most drivers don't care because they never ever run on a big endian platform. So add a new drm_mode_legacy_fb_format2() function instead. Signed-off-by: Gerd Hoffmann --- include/drm/drm_fourcc.h | 2 ++ drivers/gpu/drm/drm_fourcc.c | 28 ++++++++++++++++++++++++++++ drivers/gpu/drm/drm_framebuffer.c | 15 +++------------ 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h index fac831c401..4b82bb6576 100644 --- a/include/drm/drm_fourcc.h +++ b/include/drm/drm_fourcc.h @@ -88,6 +88,8 @@ const struct drm_format_info * drm_get_format_info(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cmd); uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth); +uint32_t drm_mode_legacy_fb_format2(uint32_t bpp, uint32_t depth, + bool native); int drm_format_num_planes(uint32_t format); int drm_format_plane_cpp(uint32_t format, int plane); int drm_format_horz_chroma_subsampling(uint32_t format); diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c index be1d6aaef6..1c1aaa8b23 100644 --- a/drivers/gpu/drm/drm_fourcc.c +++ b/drivers/gpu/drm/drm_fourcc.c @@ -96,6 +96,34 @@ uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth) EXPORT_SYMBOL(drm_mode_legacy_fb_format); /** + * drm_mode_legacy_fb_format2 - compute drm fourcc code from legacy description + * @bpp: bits per pixels + * @depth: bit depth per pixel + * @native: use host native byte order + * + * Computes a drm fourcc pixel format code for the given @bpp/@depth values. + * Useful in fbdev emulation code, since that deals in those values. + */ +uint32_t drm_mode_legacy_fb_format2(uint32_t bpp, uint32_t depth, + bool native) +{ + uint32_t fmt = drm_mode_legacy_fb_format(bpp, depth); + + if (native) { + if (fmt == DRM_FORMAT_XRGB8888) + fmt = DRM_FORMAT_HOST_XRGB8888; + if (fmt == DRM_FORMAT_ARGB8888) + fmt = DRM_FORMAT_HOST_ARGB8888; + if (fmt == DRM_FORMAT_RGB565) + fmt = DRM_FORMAT_HOST_RGB565; + if (fmt == DRM_FORMAT_XRGB1555) + fmt = DRM_FORMAT_HOST_XRGB1555; + } + return fmt; +} +EXPORT_SYMBOL(drm_mode_legacy_fb_format2); + +/** * drm_get_format_name - fill a string with a drm fourcc format's name * @format: format to compute name of * @buf: caller-supplied buffer diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c index 1ee3d6b442..f72e3dffc7 100644 --- a/drivers/gpu/drm/drm_framebuffer.c +++ b/drivers/gpu/drm/drm_framebuffer.c @@ -111,12 +111,14 @@ int drm_mode_addfb(struct drm_device *dev, struct drm_mode_fb_cmd *or, struct drm_file *file_priv) { struct drm_mode_fb_cmd2 r = {}; + bool native = dev->mode_config.quirk_addfb_prefer_host_byte_order; int ret; if (!drm_core_check_feature(dev, DRIVER_MODESET)) return -EOPNOTSUPP; - r.pixel_format = drm_mode_legacy_fb_format(or->bpp, or->depth); + r.pixel_format = drm_mode_legacy_fb_format2(or->bpp, or->depth, + native); if (r.pixel_format == DRM_FORMAT_INVALID) { DRM_DEBUG("bad {bpp:%d, depth:%d}\n", or->bpp, or->depth); return -EINVAL; @@ -133,17 +135,6 @@ int drm_mode_addfb(struct drm_device *dev, struct drm_mode_fb_cmd *or, r.pixel_format == DRM_FORMAT_XRGB2101010) r.pixel_format = DRM_FORMAT_XBGR2101010; - if (dev->mode_config.quirk_addfb_prefer_host_byte_order) { - if (r.pixel_format == DRM_FORMAT_XRGB8888) - r.pixel_format = DRM_FORMAT_HOST_XRGB8888; - if (r.pixel_format == DRM_FORMAT_ARGB8888) - r.pixel_format = DRM_FORMAT_HOST_ARGB8888; - if (r.pixel_format == DRM_FORMAT_RGB565) - r.pixel_format = DRM_FORMAT_HOST_RGB565; - if (r.pixel_format == DRM_FORMAT_XRGB1555) - r.pixel_format = DRM_FORMAT_HOST_XRGB1555; - } - ret = drm_mode_addfb2(dev, &r, file_priv); if (ret) return ret; -- 2.9.3