From patchwork Thu Feb 11 17:19:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harry Wentland X-Patchwork-Id: 8283231 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C942F9F3CD for ; Thu, 11 Feb 2016 17:21:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6FF9D2035D for ; Thu, 11 Feb 2016 17:21:56 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id A0DDF202EB for ; Thu, 11 Feb 2016 17:21:52 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D9D687A0B6; Thu, 11 Feb 2016 09:20:58 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from na01-bl2-obe.outbound.protection.outlook.com (mail-bl2on0058.outbound.protection.outlook.com [65.55.169.58]) by gabe.freedesktop.org (Postfix) with ESMTPS id DFF037A0AB for ; Thu, 11 Feb 2016 09:20:53 -0800 (PST) Received: from BN1PR12CA0033.namprd12.prod.outlook.com (10.160.77.43) by SN1PR12MB0720.namprd12.prod.outlook.com (10.163.209.22) with Microsoft SMTP Server (TLS) id 15.1.403.16; Thu, 11 Feb 2016 17:20:51 +0000 Received: from CO1NAM03FT036.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e48::208) by BN1PR12CA0033.outlook.office365.com (2a01:111:e400:49::43) with Microsoft SMTP Server (TLS) id 15.1.403.16 via Frontend Transport; Thu, 11 Feb 2016 17:20:51 +0000 Authentication-Results: spf=none (sender IP is 165.204.84.221) smtp.mailfrom=amd.com; lists.freedesktop.org; dkim=none (message not signed) header.d=none;lists.freedesktop.org; dmarc=permerror action=none header.from=amd.com; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Received: from atltwp01.amd.com (165.204.84.221) by CO1NAM03FT036.mail.protection.outlook.com (10.152.80.181) with Microsoft SMTP Server id 15.1.415.6 via Frontend Transport; Thu, 11 Feb 2016 17:20:50 +0000 X-WSS-ID: 0O2E86N-07-0WD-02 X-M-MSG: Received: from satlvexedge01.amd.com (satlvexedge01.amd.com [10.177.96.28]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by atltwp01.amd.com (Axway MailGate 5.3.1) with ESMTPS id 293AE12C130F for ; Thu, 11 Feb 2016 12:20:47 -0500 (EST) Received: from SATLEXDAG06.amd.com (10.181.40.13) by satlvexedge01.amd.com (10.177.96.28) with Microsoft SMTP Server (TLS) id 14.3.195.1; Thu, 11 Feb 2016 11:21:17 -0600 Received: from STOREXDAG03.amd.com (10.1.13.12) by satlexdag06.amd.com (10.181.40.13) with Microsoft SMTP Server (TLS) id 14.3.266.1; Thu, 11 Feb 2016 12:20:47 -0500 Received: from cnhwentlanub.amd.com (172.29.225.36) by storexdag03.amd.com (10.1.13.12) with Microsoft SMTP Server id 14.3.266.1; Thu, 11 Feb 2016 12:20:46 -0500 From: Harry Wentland To: Subject: [PATCH 18/29] drm/amd/dal: Add input pixel processing HW programming Date: Thu, 11 Feb 2016 12:19:58 -0500 Message-ID: <1455211209-26733-19-git-send-email-harry.wentland@amd.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1455211209-26733-1-git-send-email-harry.wentland@amd.com> References: <1455211209-26733-1-git-send-email-harry.wentland@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:165.204.84.221; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(2980300002)(428002)(199003)(189002)(5003600100002)(5003940100001)(19580405001)(53416004)(76176999)(2906002)(2351001)(106466001)(586003)(33646002)(229853001)(11100500001)(4326007)(1220700001)(189998001)(47776003)(77096005)(1096002)(450100001)(87936001)(105586002)(5008740100001)(19580395003)(50466002)(36756003)(50986999)(101416001)(92566002)(48376002)(2950100001)(86362001)(50226001); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB0720; H:atltwp01.amd.com; FPR:; SPF:None; MLV:sfv; A:1; MX:1; LANG:en; X-MS-Office365-Filtering-Correlation-Id: 7df775ac-4b74-4054-0c1c-08d33307b06f X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0720; 2:tV51SIa2DcxyGkcuH81ZRBFyBFVFYhOPBb/nOBcx7XfyokjnqLbrwZFOrWpUmJodiSZKb3iFfL3tzmzF8kMA2BZDuN0ZF/46k1HpUqV92c4VutkzlGo8hYZ3VC0c4612tD0ClHjk/UUX8YDA4S5fpkMFLFvxaj97lrhREwkSD8ufSTYfzVIsARmM3aLL0h3c; 3:IF3BMP85yxm43l4JCPNOSFOp7CNxE2+gExYWxmXtMXe2c4PVpr+c3D97xHmmvkpGjE+K8fDk6ogwP2kYe5ONcdtCN/VSJFKEVGpAoBj7YdqSCn+ibX68dxpUNIsLYY4C2qNDTHLUB4mrBIXNFonr4dGMTbKAEat7TFTk6ikMRx7jnmycD0AcbCTdR+9lmff5sFyTPG18A8VziSYIjD0Lf9Rppm3eRnRRsCCzlhUDuHs=; 25:1dbJQeMUHTJzt9BFKFq1RXucZyGFLpqdaenLBkKcf8fgum2siacOEZHOp17Hex5ehnCx1pgvl801gnQP3pjwiWrHHI86GK/C3kBl8wGlpIr63bNgW3+rNzUDHZYiJt1G/Z+3w0/PLS7023fVn1jbh0msH5/E7V2mYlY2b6Yk9mjheEuOoc5gBI1yllWpUX0fY9cqwnWJlBhnOPdQz6ZKwEBMy5kdYvzLPYcJEHOrSMDI+jei5PTHeaYhY2ChGTUjZGEFowNSUMuIEgb1ntEpaa99OGQpyMvREM6zabOHDvtZ1yU4oVXVqxBOYIYVB8m8 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:SN1PR12MB0720; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0720; 20:C1DEYJqjJREYvSDbm60flwoTxQSyGXklWI47krI4+JZEd6SHmfdEC3NIMYt1Vczoxt4XqTGIDkjlSFq3HOS7gB55YLUkoehKsU2pY2EBunQZNj8XdBLM8plk9lmh84dYNIVfPIOYqGrtRssL2GaBzGGLaVtbCG8IvMDmmpEjRRn75wvkjzm7AAp/pVvQg904+UaEkRtQUcYXibTIi6c7FMrAE5g2gPykV2RaPRRdg8E7qQBIiYpY7tk1EKCwsu67ta2SgcuzkceMzsI6E+PtAOKKe4Y8iOT+6Wq42Omilsez0LV6j51G7ymNnFcAXkubJIeAQoI7QUTBsDD6C5z2w1ELssQuCoIMfc2ZxItmIs5QILcBVK00Yrc0yt7fZffcFxD6imDWnu1H0SWdmQKg4gMKCkyMv4Izungwo6NSdJ4ypvkLFteImGTNsfRXhRPtO2/ndn5cGm4rxh2/hfN8DiqQKjJNzcIaGV2xy/8HTiPxjKEm/mP2sNcIUmcuIZIE X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(13017025)(13018025)(13015025)(13024025)(8121501046)(13023025)(10201501046)(3002001); SRVR:SN1PR12MB0720; BCL:0; PCL:0; RULEID:; SRVR:SN1PR12MB0720; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0720; 4:eNwuuvg7dOcxIr7j0tqmtcxi+Dilgjs5Iep+4DMn7vMvdrRbGm9lMWgCJ5wsqVHbG2y5vAW4eUshn+5LGDehmbGWisKVlzCQqOfjfVI5QwUo7Ewv83Xw3Oxu7Wj5eas+yiTgUL5rl+6Iio6pn7b6K4rq5KrrZY4hIAtl9ETkDPFAefkZ2HFoFA7U5KCU61D/xroA2ye89rlH9ai3HbWe2xFDyGRdy+hU5kuHt/vFiHe9T/bz7FTZHwwn23tyWBr7vqGJVc+tHn9nyah0D0GFv509iC/FXfWRsSRm+4+WR++DO9bAnziXZBigERNMJxCRKsZlcrWasZ9TuoiVEeabW9B04LzQRZhrplDbGwt1nORvwBXgoIDpFrPUTWcRJ3INVSiM7/pFz/Mq4zTUsuXWlJESRHsPIqdTQfi4hX4eaOovGbm9aMuh+1IWvqUh56WGr+1KCVZRoda8BtmOdXN7qfXpGuGlW2zCksPpPtylrU7rUwel0Nm9b1gN0jhKEaaP X-Forefront-PRVS: 08497C3D99 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SN1PR12MB0720; 23:7qrA/ZEzM3WZ+aMJDPGAgEfw4Ryu+LJAq4R57UOOT?= =?us-ascii?Q?47bym7kAJx6GP2HGV4r1YP2tIf3X1fT032iVTqADoM+ezDio28DBUrNjODGZ?= =?us-ascii?Q?oDEPNZ8yRtmxphiijs+8Gu0Dyd6UWCrAmSDEmFJS19i/MqnfcLBD1WegNzH4?= =?us-ascii?Q?DvIQuvNURnoBrraV8utvgofO6CLBNCRG4dPADitqCtKyymYOdgvNGBv45+qt?= =?us-ascii?Q?lAnADSphCetrHpIVLj1cIbbSzB7Wg159FFoFDQSMobvi5inPLyXJL+UYqA1U?= =?us-ascii?Q?Cg3vKBDrWaWsMFca06gPZy14VmmrR/VrBm0uB7M8JawegfDdA5JnabNXd38o?= =?us-ascii?Q?G6kcFgwIG7+ve/zSNuexQqaGRrodx0CumW0ilovqV6xh13FbGY5AQZI9OnkU?= =?us-ascii?Q?PYJNxhv8VRa0oI7tvPWU+kP0Zk8x0YOLC3UYHY7ec3+KFAnzAfyAyrxQg1+z?= =?us-ascii?Q?vAa9CDD09X/+wEji5Gtj8qs0ya+fkoVwe4WvWzKxNLMPAz65ef8dVgZh3wJG?= =?us-ascii?Q?KjiCEWRUiXLqS2lUlRR0/535pZ/nF/mJUZ72E74aiOjh/c5ftWHucwl2dTIE?= =?us-ascii?Q?soVUvde8aj/En/MsltxD0rjphFgAWWnasVG420sLNE1RGEm8dKXn/4CAM6AF?= =?us-ascii?Q?ilnnS851ZpxKzQ07u+przt1dXi0quWKkUNnl+IRHoB2ZKMoO0tlg5Jjh6VjZ?= =?us-ascii?Q?RpnEUHPyTWl9nNz0MTjOICYdjYRyvFnOqJBbBCKZss7zzXoZILbY76FqBp5H?= =?us-ascii?Q?wm3EEufpF3TzcDYOI5PWIoUGz/UmSyPBUy3YqdX3dFu+2XhtXbfhYp91KpvJ?= =?us-ascii?Q?gGOdsRcFKKStH2UObkaXNJn1jZIUOGyyzWZu5QEbL/8BcvqLf12Y3/CV9u8f?= =?us-ascii?Q?87Bkdkmoec2ir+ESEURDpbnn9OXpSSXLJOYpzw0A1TS/BtC+VnsjpHJISFhh?= =?us-ascii?Q?XPK5HiniS0ilQfs91pnr3Ukc8qO8Rgi9YEwfzuxjusZVre6n03sXYGb8/S8k?= =?us-ascii?Q?qQ=3D?= X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0720; 5:eKHCrbe5WoSZzIarbL9sCeKWZFIDzvilg9kM3woMPRcMer5Bc0/OV+xxazpknwaS0jPy36IRiaGU3G0p+WAd30ilBwt3lJBu6CLK9DwS1BKhitAUfjOmIK3t8TLED0WRxk8wb9fRUENALOsRfYrJ9g==; 24:NiKXTaiIoYdWRz4d5t52visK1JczE8bVJYFUT1RQyYkUZyGe9NVyfMnUpCw5S+OyxMJ41902KqpFjSDXECvHCYfVJl7gXLtSB4tmHSemKvc=; 20:A7BghnRSMoLu3O7/c4UQ0E1f9h1nHhglbVn3JPYmVnlTYQAokRrSB5AbaL+SoWeDl4ZHpLS8R3HLT00wHq+LofKAcMka+JiMex6iiBQT7DnJM9nOD7R0OUPlhlDtC8VFMfMJhgtPSwG+gNbNXRuKsF68GmqeW/8mPBUWopE64q0e1iiWuGG/zJZgq5DWwtZipGzmhtN08yKl9xCnO6sVQQRsFEoPkgEFFFSRWFqtILAFGT5s/EiyMWo2HRcYqb7W SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Feb 2016 17:20:50.4570 (UTC) X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.221]; Helo=[atltwp01.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB0720 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-Spam-Status: No, score=-4.4 required=5.0 tests=BAD_ENC_HEADER,BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Adds programming of cursor and input gamma. Signed-off-by: Harry Wentland Reviewed-by: Alex Deucher --- drivers/gpu/drm/amd/dal/dc/dce110/dce110_ipp.c | 65 ++ drivers/gpu/drm/amd/dal/dc/dce110/dce110_ipp.h | 100 +++ .../gpu/drm/amd/dal/dc/dce110/dce110_ipp_cursor.c | 256 ++++++ .../gpu/drm/amd/dal/dc/dce110/dce110_ipp_gamma.c | 872 +++++++++++++++++++++ 4 files changed, 1293 insertions(+) create mode 100644 drivers/gpu/drm/amd/dal/dc/dce110/dce110_ipp.c create mode 100644 drivers/gpu/drm/amd/dal/dc/dce110/dce110_ipp.h create mode 100644 drivers/gpu/drm/amd/dal/dc/dce110/dce110_ipp_cursor.c create mode 100644 drivers/gpu/drm/amd/dal/dc/dce110/dce110_ipp_gamma.c diff --git a/drivers/gpu/drm/amd/dal/dc/dce110/dce110_ipp.c b/drivers/gpu/drm/amd/dal/dc/dce110/dce110_ipp.c new file mode 100644 index 000000000000..6ab35272f979 --- /dev/null +++ b/drivers/gpu/drm/amd/dal/dc/dce110/dce110_ipp.c @@ -0,0 +1,65 @@ +/* + * Copyright 2012-15 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Authors: AMD + * + */ + +#include "dm_services.h" +#include "include/logger_interface.h" + +#include "dce/dce_11_0_d.h" +#include "dce/dce_11_0_sh_mask.h" + +#include "dce110_ipp.h" + +static struct ipp_funcs funcs = { + .ipp_cursor_set_attributes = dce110_ipp_cursor_set_attributes, + .ipp_cursor_set_position = dce110_ipp_cursor_set_position, + .ipp_program_prescale = dce110_ipp_program_prescale, + .ipp_set_degamma = dce110_ipp_set_degamma, + .ipp_set_legacy_input_gamma_mode = dce110_ipp_set_legacy_input_gamma_mode, + .ipp_set_legacy_input_gamma_ramp = dce110_ipp_set_legacy_input_gamma_ramp, + .ipp_set_palette = dce110_ipp_set_palette, +}; + +bool dce110_ipp_construct( + struct dce110_ipp* ipp, + struct dc_context *ctx, + uint32_t inst, + const struct dce110_ipp_reg_offsets *offset) +{ + ipp->base.ctx = ctx; + + ipp->base.inst = inst; + + ipp->offsets = *offset; + + ipp->base.funcs = &funcs; + + return true; +} + +void dce110_ipp_destroy(struct input_pixel_processor **ipp) +{ + dm_free((*ipp)->ctx, TO_DCE110_IPP(*ipp)); + *ipp = NULL; +} diff --git a/drivers/gpu/drm/amd/dal/dc/dce110/dce110_ipp.h b/drivers/gpu/drm/amd/dal/dc/dce110/dce110_ipp.h new file mode 100644 index 000000000000..709906face3f --- /dev/null +++ b/drivers/gpu/drm/amd/dal/dc/dce110/dce110_ipp.h @@ -0,0 +1,100 @@ +/* + * Copyright 2012-15 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Authors: AMD + * + */ + +#ifndef __DC_IPP_DCE110_H__ +#define __DC_IPP_DCE110_H__ + +#include "inc/ipp.h" + + +struct gamma_parameters; +struct dev_c_lut; + +#define TO_DCE110_IPP(input_pixel_processor)\ + container_of(input_pixel_processor, struct dce110_ipp, base) + +struct dce110_ipp_reg_offsets { + uint32_t dcp_offset; +}; + +struct dce110_ipp { + struct input_pixel_processor base; + struct dce110_ipp_reg_offsets offsets; + struct dev_c_lut saved_palette[RGB_256X3X16]; +}; + +bool dce110_ipp_construct( + struct dce110_ipp* ipp, + struct dc_context *ctx, + enum controller_id id, + const struct dce110_ipp_reg_offsets *offset); + +void dce110_ipp_destroy(struct input_pixel_processor **ipp); + +/* CURSOR RELATED */ +bool dce110_ipp_cursor_set_position( + struct input_pixel_processor *ipp, + const struct dc_cursor_position *position); + +bool dce110_ipp_cursor_set_attributes( + struct input_pixel_processor *ipp, + const struct dc_cursor_attributes *attributes); + +/* DEGAMMA RELATED */ +bool dce110_ipp_set_degamma( + struct input_pixel_processor *ipp, + const struct gamma_parameters *params, + bool force_bypass); + +void dce110_ipp_program_prescale( + struct input_pixel_processor *ipp, + enum pixel_format pixel_format); + +void dce110_ipp_set_legacy_input_gamma_mode( + struct input_pixel_processor *ipp, + bool is_legacy); + +bool dce110_ipp_set_legacy_input_gamma_ramp( + struct input_pixel_processor *ipp, + const struct gamma_ramp *gamma_ramp, + const struct gamma_parameters *params); + +bool dce110_ipp_set_palette( + struct input_pixel_processor *ipp, + const struct dev_c_lut *palette, + uint32_t start, + uint32_t length, + enum pixel_format surface_pixel_format); + +/* + * Helper functions to be resused in other ASICs + */ +void dce110_helper_select_lut(struct dce110_ipp *ipp110); + +void dce110_helper_program_black_white_offset( + struct dce110_ipp *ipp110, + enum pixel_format surface_pixel_format); + +#endif /*__DC_IPP_DCE110_H__*/ diff --git a/drivers/gpu/drm/amd/dal/dc/dce110/dce110_ipp_cursor.c b/drivers/gpu/drm/amd/dal/dc/dce110/dce110_ipp_cursor.c new file mode 100644 index 000000000000..ef91f2db24e3 --- /dev/null +++ b/drivers/gpu/drm/amd/dal/dc/dce110/dce110_ipp_cursor.c @@ -0,0 +1,256 @@ +/* + * Copyright 2012-15 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Authors: AMD + * + */ + +#include "dm_services.h" +#include "include/logger_interface.h" + +#include "dce/dce_11_0_d.h" +#include "dce/dce_11_0_sh_mask.h" + +#include "dce110_ipp.h" + +#define CURSOR_COLOR_BLACK 0x00000000 +#define CURSOR_COLOR_WHITE 0xFFFFFFFF + +#define DCP_REG(reg)\ + (reg + ipp110->offsets.dcp_offset) + +static void enable( + struct dce110_ipp *ipp110, + bool enable); + +static void lock( + struct dce110_ipp *ipp110, + bool enable); + +static void program_position( + struct dce110_ipp *ipp110, + uint32_t x, + uint32_t y); + +static bool program_control( + struct dce110_ipp *ipp110, + enum dc_cursor_color_format color_format, + bool enable_magnification, + bool inverse_transparent_clamping); + +static void program_hotspot( + struct dce110_ipp *ipp110, + uint32_t x, + uint32_t y); + +static void program_size( + struct dce110_ipp *ipp110, + uint32_t width, + uint32_t height); + +static void program_address( + struct dce110_ipp *ipp110, + PHYSICAL_ADDRESS_LOC address); + + +bool dce110_ipp_cursor_set_position( + struct input_pixel_processor *ipp, + const struct dc_cursor_position *position) +{ + struct dce110_ipp *ipp110 = TO_DCE110_IPP(ipp); + + /* lock cursor registers */ + lock(ipp110, true); + + /* Flag passed in structure differentiates cursor enable/disable. */ + /* Update if it differs from cached state. */ + enable(ipp110, position->enable); + + program_position(ipp110, position->x, position->y); + + if (position->hot_spot_enable) + program_hotspot( + ipp110, + position->x_origin, + position->y_origin); + + /* unlock cursor registers */ + lock(ipp110, false); + + return true; +} + +bool dce110_ipp_cursor_set_attributes( + struct input_pixel_processor *ipp, + const struct dc_cursor_attributes *attributes) +{ + struct dce110_ipp *ipp110 = TO_DCE110_IPP(ipp); + /* Lock cursor registers */ + lock(ipp110, true); + + /* Program cursor control */ + program_control( + ipp110, + attributes->color_format, + attributes->attribute_flags.bits.ENABLE_MAGNIFICATION, + attributes->attribute_flags.bits.INVERSE_TRANSPARENT_CLAMPING); + + /* Program hot spot coordinates */ + program_hotspot(ipp110, attributes->x_hot, attributes->y_hot); + + /* + * Program cursor size -- NOTE: HW spec specifies that HW register + * stores size as (height - 1, width - 1) + */ + program_size(ipp110, attributes->width, attributes->height); + + /* Program cursor surface address */ + program_address(ipp110, attributes->address); + + /* Unlock Cursor registers. */ + lock(ipp110, false); + + return true; +} + +static void enable( + struct dce110_ipp *ipp110, bool enable) +{ + uint32_t value = 0; + uint32_t addr = DCP_REG(mmCUR_CONTROL); + + value = dm_read_reg(ipp110->base.ctx, addr); + set_reg_field_value(value, enable, CUR_CONTROL, CURSOR_EN); + dm_write_reg(ipp110->base.ctx, addr, value); +} + +static void lock( + struct dce110_ipp *ipp110, bool lock) +{ + uint32_t value = 0; + uint32_t addr = DCP_REG(mmCUR_UPDATE); + + value = dm_read_reg(ipp110->base.ctx, addr); + set_reg_field_value(value, lock, CUR_UPDATE, CURSOR_UPDATE_LOCK); + dm_write_reg(ipp110->base.ctx, addr, value); +} + +static void program_position( + struct dce110_ipp *ipp110, + uint32_t x, + uint32_t y) +{ + uint32_t value = 0; + uint32_t addr = DCP_REG(mmCUR_POSITION); + + value = dm_read_reg(ipp110->base.ctx, addr); + set_reg_field_value(value, x, CUR_POSITION, CURSOR_X_POSITION); + set_reg_field_value(value, y, CUR_POSITION, CURSOR_Y_POSITION); + dm_write_reg(ipp110->base.ctx, addr, value); +} + +static bool program_control( + struct dce110_ipp *ipp110, + enum dc_cursor_color_format color_format, + bool enable_magnification, + bool inverse_transparent_clamping) +{ + uint32_t value = 0; + uint32_t addr = DCP_REG(mmCUR_CONTROL); + uint32_t mode = 0; + + switch (color_format) { + case CURSOR_MODE_MONO: + mode = 0; + break; + case CURSOR_MODE_COLOR_1BIT_AND: + mode = 1; + break; + case CURSOR_MODE_COLOR_PRE_MULTIPLIED_ALPHA: + mode = 2; + break; + case CURSOR_MODE_COLOR_UN_PRE_MULTIPLIED_ALPHA: + mode = 3; + break; + default: + return false; + } + + set_reg_field_value(value, mode, CUR_CONTROL, CURSOR_MODE); + set_reg_field_value(value, enable_magnification, + CUR_CONTROL, CURSOR_2X_MAGNIFY); + set_reg_field_value(value, inverse_transparent_clamping, + CUR_CONTROL, CUR_INV_TRANS_CLAMP); + dm_write_reg(ipp110->base.ctx, addr, value); + + if (color_format == CURSOR_MODE_MONO) { + addr = DCP_REG(mmCUR_COLOR1); + dm_write_reg(ipp110->base.ctx, addr, CURSOR_COLOR_BLACK); + addr = DCP_REG(mmCUR_COLOR2); + dm_write_reg(ipp110->base.ctx, addr, CURSOR_COLOR_WHITE); + } + return true; +} + +static void program_hotspot( + struct dce110_ipp *ipp110, + uint32_t x, + uint32_t y) +{ + uint32_t value = 0; + uint32_t addr = DCP_REG(mmCUR_HOT_SPOT); + + value = dm_read_reg(ipp110->base.ctx, addr); + set_reg_field_value(value, x, CUR_HOT_SPOT, CURSOR_HOT_SPOT_X); + set_reg_field_value(value, y, CUR_HOT_SPOT, CURSOR_HOT_SPOT_Y); + dm_write_reg(ipp110->base.ctx, addr, value); +} + +static void program_size( + struct dce110_ipp *ipp110, + uint32_t width, + uint32_t height) +{ + uint32_t value = 0; + uint32_t addr = DCP_REG(mmCUR_SIZE); + + value = dm_read_reg(ipp110->base.ctx, addr); + set_reg_field_value(value, width, CUR_SIZE, CURSOR_WIDTH); + set_reg_field_value(value, height, CUR_SIZE, CURSOR_HEIGHT); + dm_write_reg(ipp110->base.ctx, addr, value); +} + +static void program_address( + struct dce110_ipp *ipp110, + PHYSICAL_ADDRESS_LOC address) +{ + uint32_t addr = DCP_REG(mmCUR_SURFACE_ADDRESS_HIGH); + /* SURFACE_ADDRESS_HIGH: Higher order bits (39:32) of hardware cursor + * surface base address in byte. It is 4K byte aligned. + * The correct way to program cursor surface address is to first write + * to CUR_SURFACE_ADDRESS_HIGH, and then write to CUR_SURFACE_ADDRESS */ + + dm_write_reg(ipp110->base.ctx, addr, address.high_part); + + addr = DCP_REG(mmCUR_SURFACE_ADDRESS); + dm_write_reg(ipp110->base.ctx, addr, address.low_part); +} + diff --git a/drivers/gpu/drm/amd/dal/dc/dce110/dce110_ipp_gamma.c b/drivers/gpu/drm/amd/dal/dc/dce110/dce110_ipp_gamma.c new file mode 100644 index 000000000000..fcf65f119af4 --- /dev/null +++ b/drivers/gpu/drm/amd/dal/dc/dce110/dce110_ipp_gamma.c @@ -0,0 +1,872 @@ +/* + * Copyright 2012-15 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Authors: AMD + * + */ + +#include "dm_services.h" +#include "include/logger_interface.h" +#include "include/fixed31_32.h" +#include "basics/conversion.h" + +#include "dce/dce_11_0_d.h" +#include "dce/dce_11_0_sh_mask.h" + +#include "dce110_ipp.h" +#include "gamma_types.h" + +#define DCP_REG(reg)\ + (reg + ipp110->offsets.dcp_offset) + +enum { + MAX_INPUT_LUT_ENTRY = 256 +}; + +/* CALCULATION OPERATIONS*/ +static void convert_256_lut_entries_to_gxo_format( + const struct gamma_ramp_rgb256x3x16 *lut, + struct dev_c_lut16 *gamma) +{ + uint32_t i = 0; + + ASSERT(lut); + ASSERT(gamma); + + do { + gamma->red = lut->red[i]; + gamma->green = lut->green[i]; + gamma->blue = lut->blue[i]; + + ++gamma; + ++i; + } while (i != MAX_INPUT_LUT_ENTRY); +} + +static void convert_udx_gamma_entries_to_gxo_format( + const struct gamma_ramp_dxgi_1 *lut, + struct dev_c_lut16 *gamma) +{ + /* TODO here we deal with DXGI gamma table, + * originally, values was expressed as 'float', + * now values expressed as 'dal_fixed20_12'. */ +} + +/*PROTOTYPE DECLARATIONS*/ +static void set_lut_inc( + struct dce110_ipp *ipp110, + uint8_t inc, + bool is_float, + bool is_signed); + +static void program_black_offsets( + struct dce110_ipp *ipp110, + struct dev_c_lut16 *offset); + +static void program_white_offsets( + struct dce110_ipp *ipp110, + struct dev_c_lut16 *offset); + +static void program_lut_gamma( + struct dce110_ipp *ipp110, + const struct dev_c_lut16 *gamma, + const struct gamma_parameters *params); + +static void program_prescale( + struct dce110_ipp *ipp110, + enum pixel_format pixel_format); + +static void set_legacy_input_gamma_mode( + struct dce110_ipp *ipp110, + bool is_legacy); + +static bool set_legacy_input_gamma_ramp_rgb256x3x16( + struct dce110_ipp *ipp110, + const struct gamma_ramp *gamma_ramp, + const struct gamma_parameters *params); + +static bool set_legacy_input_gamma_ramp_dxgi1( + struct dce110_ipp *ipp110, + const struct gamma_ramp *gamma_ramp, + const struct gamma_parameters *params); + +static bool set_default_gamma( + struct dce110_ipp *ipp110, + enum pixel_format surface_pixel_format); + +static void set_degamma( + struct dce110_ipp *ipp110, + const struct gamma_parameters *params, + bool force_bypass); + +bool dce110_ipp_set_legacy_input_gamma_ramp( + struct input_pixel_processor *ipp, + const struct gamma_ramp *gamma_ramp, + const struct gamma_parameters *params) +{ + struct dce110_ipp *ipp110 = TO_DCE110_IPP(ipp); + + switch (gamma_ramp->type) { + case GAMMA_RAMP_RBG256X3X16: + return set_legacy_input_gamma_ramp_rgb256x3x16( + ipp110, gamma_ramp, params); + case GAMMA_RAMP_DXGI_1: + return set_legacy_input_gamma_ramp_dxgi1( + ipp110, gamma_ramp, params); + default: + ASSERT_CRITICAL(false); + return false; + } +} + +bool dce110_ipp_set_palette( + struct input_pixel_processor *ipp, + const struct dev_c_lut *palette, + uint32_t start, + uint32_t length, + enum pixel_format surface_pixel_format) +{ + struct dce110_ipp *ipp110 = TO_DCE110_IPP(ipp); + uint32_t i; + + if (((start + length) > MAX_INPUT_LUT_ENTRY) || (NULL == palette)) { + BREAK_TO_DEBUGGER(); + /* wrong input */ + return false; + } + + for (i = start; i < start + length; i++) { + ipp110->saved_palette[i] = palette[i]; + ipp110->saved_palette[i] = palette[i]; + ipp110->saved_palette[i] = palette[i]; + } + + return set_default_gamma(ipp110, surface_pixel_format); +} + +bool dce110_ipp_set_degamma( + struct input_pixel_processor *ipp, + const struct gamma_parameters *params, + bool force_bypass) +{ + struct dce110_ipp *ipp110 = TO_DCE110_IPP(ipp); + + set_degamma(ipp110, params, force_bypass); + + return true; +} + +void dce110_ipp_program_prescale( + struct input_pixel_processor *ipp, + enum pixel_format pixel_format) +{ + struct dce110_ipp *ipp110 = TO_DCE110_IPP(ipp); + + program_prescale(ipp110, pixel_format); +} + +void dce110_ipp_set_legacy_input_gamma_mode( + struct input_pixel_processor *ipp, + bool is_legacy) +{ + struct dce110_ipp *ipp110 = TO_DCE110_IPP(ipp); + + set_legacy_input_gamma_mode(ipp110, is_legacy); +} + +static void set_lut_inc( + struct dce110_ipp *ipp110, + uint8_t inc, + bool is_float, + bool is_signed) +{ + const uint32_t addr = DCP_REG(mmDC_LUT_CONTROL); + + uint32_t value = dm_read_reg(ipp110->base.ctx, addr); + + set_reg_field_value( + value, + inc, + DC_LUT_CONTROL, + DC_LUT_INC_R); + + set_reg_field_value( + value, + inc, + DC_LUT_CONTROL, + DC_LUT_INC_G); + + set_reg_field_value( + value, + inc, + DC_LUT_CONTROL, + DC_LUT_INC_B); + + set_reg_field_value( + value, + is_float, + DC_LUT_CONTROL, + DC_LUT_DATA_R_FLOAT_POINT_EN); + + set_reg_field_value( + value, + is_float, + DC_LUT_CONTROL, + DC_LUT_DATA_G_FLOAT_POINT_EN); + + set_reg_field_value( + value, + is_float, + DC_LUT_CONTROL, + DC_LUT_DATA_B_FLOAT_POINT_EN); + + set_reg_field_value( + value, + is_signed, + DC_LUT_CONTROL, + DC_LUT_DATA_R_SIGNED_EN); + + set_reg_field_value( + value, + is_signed, + DC_LUT_CONTROL, + DC_LUT_DATA_G_SIGNED_EN); + + set_reg_field_value( + value, + is_signed, + DC_LUT_CONTROL, + DC_LUT_DATA_B_SIGNED_EN); + + dm_write_reg(ipp110->base.ctx, addr, value); +} + +void dce110_helper_select_lut(struct dce110_ipp *ipp110) +{ + uint32_t value = 0; + + set_lut_inc(ipp110, 0, false, false); + + { + const uint32_t addr = DCP_REG(mmDC_LUT_WRITE_EN_MASK); + + value = dm_read_reg(ipp110->base.ctx, addr); + + /* enable all */ + set_reg_field_value( + value, + 0x7, + DC_LUT_WRITE_EN_MASK, + DC_LUT_WRITE_EN_MASK); + + dm_write_reg(ipp110->base.ctx, addr, value); + } + + { + const uint32_t addr = DCP_REG(mmDC_LUT_RW_MODE); + + value = dm_read_reg(ipp110->base.ctx, addr); + + set_reg_field_value( + value, + 0, + DC_LUT_RW_MODE, + DC_LUT_RW_MODE); + + dm_write_reg(ipp110->base.ctx, addr, value); + } + + { + const uint32_t addr = DCP_REG(mmDC_LUT_CONTROL); + + value = dm_read_reg(ipp110->base.ctx, addr); + + /* 00 - new u0.12 */ + set_reg_field_value( + value, + 3, + DC_LUT_CONTROL, + DC_LUT_DATA_R_FORMAT); + + set_reg_field_value( + value, + 3, + DC_LUT_CONTROL, + DC_LUT_DATA_G_FORMAT); + + set_reg_field_value( + value, + 3, + DC_LUT_CONTROL, + DC_LUT_DATA_B_FORMAT); + + dm_write_reg(ipp110->base.ctx, addr, value); + } + + { + const uint32_t addr = DCP_REG(mmDC_LUT_RW_INDEX); + + value = dm_read_reg(ipp110->base.ctx, addr); + + set_reg_field_value( + value, + 0, + DC_LUT_RW_INDEX, + DC_LUT_RW_INDEX); + + dm_write_reg(ipp110->base.ctx, addr, value); + } +} + +static void program_black_offsets( + struct dce110_ipp *ipp110, + struct dev_c_lut16 *offset) +{ + dm_write_reg(ipp110->base.ctx, + DCP_REG(mmDC_LUT_BLACK_OFFSET_RED), + offset->red); + dm_write_reg(ipp110->base.ctx, + DCP_REG(mmDC_LUT_BLACK_OFFSET_GREEN), + offset->green); + dm_write_reg(ipp110->base.ctx, + DCP_REG(mmDC_LUT_BLACK_OFFSET_BLUE), + offset->blue); +} + +static void program_white_offsets( + struct dce110_ipp *ipp110, + struct dev_c_lut16 *offset) +{ + dm_write_reg(ipp110->base.ctx, + DCP_REG(mmDC_LUT_WHITE_OFFSET_RED), + offset->red); + dm_write_reg(ipp110->base.ctx, + DCP_REG(mmDC_LUT_WHITE_OFFSET_GREEN), + offset->green); + dm_write_reg(ipp110->base.ctx, + DCP_REG(mmDC_LUT_WHITE_OFFSET_BLUE), + offset->blue); +} + +void dce110_helper_program_black_white_offset( + struct dce110_ipp *ipp110, + enum pixel_format surface_pixel_format) +{ + struct dev_c_lut16 black_offset; + struct dev_c_lut16 white_offset; + + /* get black offset */ + + switch (surface_pixel_format) { + case PIXEL_FORMAT_FP16: + /* sRGB gamut, [0.0...1.0] */ + black_offset.red = 0; + black_offset.green = 0; + black_offset.blue = 0; + break; + + case PIXEL_FORMAT_ARGB2101010_XRBIAS: + /* [-1.0...3.0] */ + black_offset.red = 0x100; + black_offset.green = 0x100; + black_offset.blue = 0x100; + break; + + default: + black_offset.red = 0; + black_offset.green = 0; + black_offset.blue = 0; + } + + /* get white offset */ + + switch (surface_pixel_format) { + case PIXEL_FORMAT_FP16: + white_offset.red = 0x3BFF; + white_offset.green = 0x3BFF; + white_offset.blue = 0x3BFF; + break; + + case PIXEL_FORMAT_ARGB2101010_XRBIAS: + white_offset.red = 0x37E; + white_offset.green = 0x37E; + white_offset.blue = 0x37E; + break; + + case PIXEL_FORMAT_ARGB8888: + white_offset.red = 0xFF; + white_offset.green = 0xFF; + white_offset.blue = 0xFF; + break; + + default: + white_offset.red = 0x3FF; + white_offset.green = 0x3FF; + white_offset.blue = 0x3FF; + } + + program_black_offsets(ipp110, &black_offset); + program_white_offsets(ipp110, &white_offset); +} + +static void program_lut_gamma( + struct dce110_ipp *ipp110, + const struct dev_c_lut16 *gamma, + const struct gamma_parameters *params) +{ + uint32_t i = 0; + uint32_t value = 0; + uint32_t addr; + + { + uint8_t max_tries = 10; + uint8_t counter = 0; + + /* Power on LUT memory */ + value = dm_read_reg( + ipp110->base.ctx, DCP_REG(mmDCFE_MEM_PWR_CTRL)); + + set_reg_field_value( + value, + 1, + DCFE_MEM_PWR_CTRL, + DCP_REGAMMA_MEM_PWR_DIS); + + dm_write_reg( + ipp110->base.ctx, DCP_REG(mmDCFE_MEM_PWR_CTRL), value); + + while (counter < max_tries) { + value = + dm_read_reg( + ipp110->base.ctx, + DCP_REG(mmDCFE_MEM_PWR_STATUS)); + + if (get_reg_field_value( + value, + DCFE_MEM_PWR_STATUS, + DCP_REGAMMA_MEM_PWR_STATE) == 0) + break; + + ++counter; + } + + if (counter == max_tries) { + dal_logger_write(ipp110->base.ctx->logger, + LOG_MAJOR_WARNING, + LOG_MINOR_COMPONENT_CONTROLLER, + "%s: regamma lut was not powered on in a timely manner, programming still proceeds\n", + __func__); + } + } + + dce110_helper_program_black_white_offset(ipp110, params->surface_pixel_format); + + dce110_helper_select_lut(ipp110); + + if (params->surface_pixel_format == PIXEL_FORMAT_INDEX8) { + addr = DCP_REG(mmDC_LUT_SEQ_COLOR); + + do { + struct dev_c_lut *index = + ipp110->saved_palette + i; + + set_reg_field_value( + value, + gamma[index->red].red, + DC_LUT_SEQ_COLOR, + DC_LUT_SEQ_COLOR); + dm_write_reg(ipp110->base.ctx, addr, value); + + + set_reg_field_value( + value, + gamma[index->green].green, + DC_LUT_SEQ_COLOR, + DC_LUT_SEQ_COLOR); + dm_write_reg(ipp110->base.ctx, addr, value); + + + set_reg_field_value( + value, + gamma[index->blue].blue, + DC_LUT_SEQ_COLOR, + DC_LUT_SEQ_COLOR); + dm_write_reg(ipp110->base.ctx, addr, value); + + ++i; + } while (i != RGB_256X3X16); + } else { + addr = DCP_REG(mmDC_LUT_SEQ_COLOR); + + do { + set_reg_field_value( + value, + gamma[i].red, + DC_LUT_SEQ_COLOR, + DC_LUT_SEQ_COLOR); + dm_write_reg(ipp110->base.ctx, addr, value); + + + set_reg_field_value( + value, + gamma[i].green, + DC_LUT_SEQ_COLOR, + DC_LUT_SEQ_COLOR); + dm_write_reg(ipp110->base.ctx, addr, value); + + + set_reg_field_value( + value, + gamma[i].blue, + DC_LUT_SEQ_COLOR, + DC_LUT_SEQ_COLOR); + dm_write_reg(ipp110->base.ctx, addr, value); + + ++i; + } while (i != RGB_256X3X16); + } + + /* we are done with DCP LUT memory; re-enable low power mode */ + value = dm_read_reg(ipp110->base.ctx, DCP_REG(mmDCFE_MEM_PWR_CTRL)); + + set_reg_field_value( + value, + 0, + DCFE_MEM_PWR_CTRL, + DCP_REGAMMA_MEM_PWR_DIS); + + dm_write_reg(ipp110->base.ctx, DCP_REG(mmDCFE_MEM_PWR_CTRL), value); +} + +static void program_prescale( + struct dce110_ipp *ipp110, + enum pixel_format pixel_format) +{ + uint32_t prescale_control; + uint32_t prescale_values_grph_r = 0; + uint32_t prescale_values_grph_g = 0; + uint32_t prescale_values_grph_b = 0; + + uint32_t prescale_num; + uint32_t prescale_denom = 1; + uint16_t prescale_hw; + uint32_t bias_num = 0; + uint32_t bias_denom = 1; + uint16_t bias_hw; + + const uint32_t addr_control = DCP_REG(mmPRESCALE_GRPH_CONTROL); + + prescale_control = dm_read_reg(ipp110->base.ctx, addr_control); + + set_reg_field_value( + prescale_control, + 0, + PRESCALE_GRPH_CONTROL, + GRPH_PRESCALE_BYPASS); + + switch (pixel_format) { + case PIXEL_FORMAT_RGB565: + prescale_num = 64; + prescale_denom = 63; + break; + + case PIXEL_FORMAT_ARGB8888: + /* This function should only be called when using regamma + * and bypassing legacy INPUT GAMMA LUT (function name is + * misleading) + */ + prescale_num = 256; + prescale_denom = 255; + break; + + case PIXEL_FORMAT_ARGB2101010: + prescale_num = 1024; + prescale_denom = 1023; + break; + + case PIXEL_FORMAT_ARGB2101010_XRBIAS: + prescale_num = 1024; + prescale_denom = 510; + bias_num = 384; + bias_denom = 1024; + break; + + case PIXEL_FORMAT_FP16: + prescale_num = 1; + break; + + default: + prescale_num = 1; + + set_reg_field_value( + prescale_control, + 1, + PRESCALE_GRPH_CONTROL, + GRPH_PRESCALE_BYPASS); + } + + prescale_hw = fixed_point_to_int_frac( + dal_fixed31_32_from_fraction(prescale_num, prescale_denom), + 2, 13); + + bias_hw = fixed_point_to_int_frac( + dal_fixed31_32_from_fraction(bias_num, bias_denom), + 2, 13); + + + set_reg_field_value( + prescale_values_grph_r, + prescale_hw, + PRESCALE_VALUES_GRPH_R, + GRPH_PRESCALE_SCALE_R); + + set_reg_field_value( + prescale_values_grph_r, + bias_hw, + PRESCALE_VALUES_GRPH_R, + GRPH_PRESCALE_BIAS_R); + + + set_reg_field_value( + prescale_values_grph_g, + prescale_hw, + PRESCALE_VALUES_GRPH_G, + GRPH_PRESCALE_SCALE_G); + + set_reg_field_value( + prescale_values_grph_g, + bias_hw, + PRESCALE_VALUES_GRPH_G, + GRPH_PRESCALE_BIAS_G); + + + set_reg_field_value( + prescale_values_grph_b, + prescale_hw, + PRESCALE_VALUES_GRPH_B, + GRPH_PRESCALE_SCALE_B); + + set_reg_field_value( + prescale_values_grph_b, + bias_hw, + PRESCALE_VALUES_GRPH_B, + GRPH_PRESCALE_BIAS_B); + + dm_write_reg(ipp110->base.ctx, + addr_control, prescale_control); + + { + dm_write_reg(ipp110->base.ctx, + DCP_REG(mmPRESCALE_VALUES_GRPH_R), + prescale_values_grph_r); + } + + { + dm_write_reg(ipp110->base.ctx, + DCP_REG(mmPRESCALE_VALUES_GRPH_G), + prescale_values_grph_g); + } + + { + dm_write_reg(ipp110->base.ctx, + DCP_REG(mmPRESCALE_VALUES_GRPH_B), + prescale_values_grph_b); + } +} + +static void set_legacy_input_gamma_mode( + struct dce110_ipp *ipp110, + bool is_legacy) +{ + const uint32_t addr = DCP_REG(mmINPUT_GAMMA_CONTROL); + uint32_t value = dm_read_reg(ipp110->base.ctx, addr); + + set_reg_field_value( + value, + !is_legacy, + INPUT_GAMMA_CONTROL, + GRPH_INPUT_GAMMA_MODE); + + dm_write_reg(ipp110->base.ctx, addr, value); +} + +static bool set_legacy_input_gamma_ramp_rgb256x3x16( + struct dce110_ipp *ipp110, + const struct gamma_ramp *gamma_ramp, + const struct gamma_parameters *params) +{ + struct dev_c_lut16 *gamma16 = + dm_alloc( + ipp110->base.ctx, + sizeof(struct dev_c_lut16) * MAX_INPUT_LUT_ENTRY); + + if (!gamma16) + return false; + + convert_256_lut_entries_to_gxo_format( + &gamma_ramp->gamma_ramp_rgb256x3x16, gamma16); + + if ((params->surface_pixel_format != PIXEL_FORMAT_ARGB2101010) && + (params->surface_pixel_format != + PIXEL_FORMAT_ARGB2101010_XRBIAS) && + (params->surface_pixel_format != PIXEL_FORMAT_FP16)) { + program_lut_gamma(ipp110, gamma16, params); + dm_free(ipp110->base.ctx, gamma16); + return true; + } + + /* TODO process DirectX-specific formats*/ + dm_free(ipp110->base.ctx, gamma16); + return false; +} + +static bool set_legacy_input_gamma_ramp_dxgi1( + struct dce110_ipp *ipp110, + const struct gamma_ramp *gamma_ramp, + const struct gamma_parameters *params) +{ + struct dev_c_lut16 *gamma16 = + dm_alloc( + ipp110->base.ctx, + sizeof(struct dev_c_lut16) * MAX_INPUT_LUT_ENTRY); + + if (!gamma16) + return false; + + convert_udx_gamma_entries_to_gxo_format( + &gamma_ramp->gamma_ramp_dxgi1, gamma16); + + if ((params->surface_pixel_format != PIXEL_FORMAT_ARGB2101010) && + (params->surface_pixel_format != + PIXEL_FORMAT_ARGB2101010_XRBIAS) && + (params->surface_pixel_format != PIXEL_FORMAT_FP16)) { + program_lut_gamma(ipp110, gamma16, params); + dm_free(ipp110->base.ctx, gamma16); + return true; + } + + /* TODO process DirectX-specific formats*/ + dm_free(ipp110->base.ctx, gamma16); + return false; +} + +static bool set_default_gamma( + struct dce110_ipp *ipp110, + enum pixel_format surface_pixel_format) +{ + uint32_t i; + + struct dev_c_lut16 *gamma16 = NULL; + struct gamma_parameters *params = NULL; + + gamma16 = dm_alloc( + ipp110->base.ctx, + sizeof(struct dev_c_lut16) * MAX_INPUT_LUT_ENTRY); + + if (!gamma16) + return false; + + params = dm_alloc(ipp110->base.ctx, sizeof(*params)); + + if (!params) { + dm_free(ipp110->base.ctx, gamma16); + return false; + } + + for (i = 0; i < MAX_INPUT_LUT_ENTRY; i++) { + gamma16[i].red = gamma16[i].green = + gamma16[i].blue = (uint16_t) (i << 8); + } + + params->surface_pixel_format = surface_pixel_format; + params->regamma_adjust_type = GRAPHICS_REGAMMA_ADJUST_HW; + params->degamma_adjust_type = GRAPHICS_DEGAMMA_ADJUST_HW; + params->selected_gamma_lut = GRAPHICS_GAMMA_LUT_REGAMMA; + params->disable_adjustments = false; + + params->regamma.features.value = 0; + + params->regamma.features.bits.GAMMA_RAMP_ARRAY = 0; + params->regamma.features.bits.GRAPHICS_DEGAMMA_SRGB = 1; + params->regamma.features.bits.OVERLAY_DEGAMMA_SRGB = 1; + + for (i = 0; i < 3; i++) { + params->regamma.gamma_coeff.a0[i] = 31308; + params->regamma.gamma_coeff.a1[i] = 12920; + params->regamma.gamma_coeff.a2[i] = 55; + params->regamma.gamma_coeff.a3[i] = 55; + params->regamma.gamma_coeff.gamma[i] = 2400; + + } + + program_lut_gamma(ipp110, gamma16, params); + + dm_free(ipp110->base.ctx, gamma16); + dm_free(ipp110->base.ctx, params); + + return true; +} + +static void set_degamma( + struct dce110_ipp *ipp110, + const struct gamma_parameters *params, + bool force_bypass) +{ + uint32_t value; + const uint32_t addr = DCP_REG(mmDEGAMMA_CONTROL); + uint32_t degamma_type = + params->regamma.features.bits.GRAPHICS_DEGAMMA_SRGB == 1 ? + 1 : 2; + + value = dm_read_reg(ipp110->base.ctx, addr); + + /* if by pass - no degamma + * when legacy and regamma LUT's we do degamma */ + if (params->degamma_adjust_type == GRAPHICS_DEGAMMA_ADJUST_BYPASS || + (params->surface_pixel_format == PIXEL_FORMAT_FP16 && + params->selected_gamma_lut == + GRAPHICS_GAMMA_LUT_REGAMMA)) + degamma_type = 0; + + if (force_bypass) + degamma_type = 0; + + set_reg_field_value( + value, + degamma_type, + DEGAMMA_CONTROL, + GRPH_DEGAMMA_MODE); + + set_reg_field_value( + value, + degamma_type, + DEGAMMA_CONTROL, + CURSOR_DEGAMMA_MODE); + + set_reg_field_value( + value, + degamma_type, + DEGAMMA_CONTROL, + CURSOR2_DEGAMMA_MODE); + + dm_write_reg(ipp110->base.ctx, addr, value); +} +