From patchwork Tue May 2 13:34:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 9708051 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 E2B106021C for ; Tue, 2 May 2017 13:34:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D47902841C for ; Tue, 2 May 2017 13:34:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C91462844C; Tue, 2 May 2017 13:34:25 +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 7E6D12841C for ; Tue, 2 May 2017 13:34:25 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3D8D96E21E; Tue, 2 May 2017 13:34:17 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7DF2E6E12E; Tue, 2 May 2017 13:34:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A8B7DA1DA2; Tue, 2 May 2017 13:34:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A8B7DA1DA2 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kraxel@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A8B7DA1DA2 Received: from nilsson.home.kraxel.org (ovpn-116-113.ams2.redhat.com [10.36.116.113]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8A6D47EF76; Tue, 2 May 2017 13:34:10 +0000 (UTC) Received: by nilsson.home.kraxel.org (Postfix, from userid 500) id B4CEA807E0; Tue, 2 May 2017 15:34:09 +0200 (CEST) From: Gerd Hoffmann To: dri-devel@lists.freedesktop.org Subject: [PATCH 3/3] drm: fourcc byteorder: add drm_mode_legacy_fb_format_he Date: Tue, 2 May 2017 15:34:04 +0200 Message-Id: <20170502133404.15354-4-kraxel@redhat.com> In-Reply-To: <20170502133404.15354-1-kraxel@redhat.com> References: <20170502133404.15354-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 02 May 2017 13:34:16 +0000 (UTC) Cc: =?UTF-8?q?Michel=20D=C3=A4nzer?= , open list , amd-gfx@lists.freedesktop.org, Daniel Vetter , Gerd Hoffmann 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: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Add drm_mode_legacy_fb_format variant which returns fourcc codes for framebuffer format in host byte order. Signed-off-by: Gerd Hoffmann --- include/drm/drm_fourcc.h | 3 +++ drivers/gpu/drm/drm_fourcc.c | 54 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h index cae05153e8..729e9d1b11 100644 --- a/include/drm/drm_fourcc.h +++ b/include/drm/drm_fourcc.h @@ -73,7 +73,10 @@ const struct drm_format_info *drm_format_info(u32 format); 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_format_he(uint32_t bpp, uint32_t depth); + 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 adb3ff59a4..97ff2cdf4e 100644 --- a/drivers/gpu/drm/drm_fourcc.c +++ b/drivers/gpu/drm/drm_fourcc.c @@ -36,12 +36,24 @@ static char printable_char(int c) } /** - * drm_mode_legacy_fb_format - compute drm fourcc code from legacy description + * drm_mode_legacy_fb_format - compute drm fourcc code from legacy description, + * little endian. * @bpp: bits per pixels * @depth: bit depth per pixel * + * Deprecated, use drm_mode_legacy_fb_format_he instead. + * * Computes a drm fourcc pixel format code for the given @bpp/@depth values. * Useful in fbdev emulation code, since that deals in those values. + * + * Note that drm_mode_addfb (DRM_IOCTL_MODE_ADDFB implementation) uses this + * too. + * + * For historical reasons, this function returns fourcc codes for framebuffer + * formats in little endian byte order unconditinally, even though fbdev + * emulation expects the framebuffer in host byte order (i.e. big endian on + * big endian machines). Ideally we would simply fix this function, but that + * would break drivers expecting the broken behavior ... */ uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth) { @@ -79,6 +91,46 @@ uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth) EXPORT_SYMBOL(drm_mode_legacy_fb_format); /** + * drm_mode_legacy_fb_format_he - compute drm fourcc code from legacy + * description, host endian. + * @bpp: bits per pixels + * @depth: bit depth per pixel + * + * 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_format_he(uint32_t bpp, uint32_t depth) +{ +#ifdef __BIG_ENDIAN + uint32_t fmt; + + switch (bpp) { + case 8: + fmt = DRM_FORMAT_C8; + break; + case 24: + fmt = DRM_FORMAT_BGR888; + break; + case 32: + if (depth == 24) + fmt = DRM_FORMAT_BGRX8888; + else + fmt = DRM_FORMAT_BGRA8888; + break; + default: + DRM_ERROR("bad bpp, assuming b8g8r8x8 pixel format\n"); + fmt = DRM_FORMAT_BGRX8888; + break; + } + + return fmt; +#else + return drm_mode_legacy_fb_format(bpp, depth); +#endif +} +EXPORT_SYMBOL(drm_mode_legacy_fb_format_he); + +/** * drm_get_format_name - fill a string with a drm fourcc format's name * @format: format to compute name of * @buf: caller-supplied buffer