From patchwork Fri May 17 10:05:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Qian Wang X-Patchwork-Id: 10947629 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BC31B1395 for ; Fri, 17 May 2019 10:05:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A8AE026BE9 for ; Fri, 17 May 2019 10:05:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 90A9C26861; Fri, 17 May 2019 10:05:12 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 B87412675C for ; Fri, 17 May 2019 10:05:11 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AD1B78987A; Fri, 17 May 2019 10:05:10 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-eopbgr150053.outbound.protection.outlook.com [40.107.15.53]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6F9878987A for ; Fri, 17 May 2019 10:05:09 +0000 (UTC) Received: from VE1PR08MB5006.eurprd08.prod.outlook.com (10.255.159.31) by VE1PR08MB5055.eurprd08.prod.outlook.com (10.255.159.220) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1900.17; Fri, 17 May 2019 10:05:07 +0000 Received: from VE1PR08MB5006.eurprd08.prod.outlook.com ([fe80::206b:5cf6:97e:1358]) by VE1PR08MB5006.eurprd08.prod.outlook.com ([fe80::206b:5cf6:97e:1358%7]) with mapi id 15.20.1900.010; Fri, 17 May 2019 10:05:07 +0000 From: "james qian wang (Arm Technology China)" To: Liviu Dudau , "airlied@linux.ie" , Brian Starkey , "maarten.lankhorst@linux.intel.com" , "sean@poorly.run" Subject: [PATCH 1/2] drm/komeda: Add komeda_fb_check_src_coords Thread-Topic: [PATCH 1/2] drm/komeda: Add komeda_fb_check_src_coords Thread-Index: AQHVDJgA8O3lpoQKg0O8UJ9n/d0vvA== Date: Fri, 17 May 2019 10:05:06 +0000 Message-ID: <20190517100425.18716-2-james.qian.wang@arm.com> References: <20190517100425.18716-1-james.qian.wang@arm.com> In-Reply-To: <20190517100425.18716-1-james.qian.wang@arm.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [113.29.88.7] x-clientproxiedby: HK2PR02CA0222.apcprd02.prod.outlook.com (2603:1096:201:20::34) To VE1PR08MB5006.eurprd08.prod.outlook.com (2603:10a6:803:113::31) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.17.1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 0e41575e-262e-4447-b7de-08d6daaf2340 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(7168020)(4627221)(201703031133081)(201702281549075)(8990200)(5600141)(711020)(4605104)(4618075)(2017052603328)(7193020); SRVR:VE1PR08MB5055; x-ms-traffictypediagnostic: VE1PR08MB5055: nodisclaimer: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:4941; x-forefront-prvs: 0040126723 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(136003)(39860400002)(376002)(346002)(366004)(396003)(199004)(189003)(4326008)(446003)(66556008)(81156014)(8676002)(66476007)(71190400001)(25786009)(81166006)(66446008)(316002)(486006)(2501003)(8936002)(50226002)(73956011)(66946007)(11346002)(68736007)(66066001)(64756008)(2616005)(14444005)(256004)(53936002)(2201001)(86362001)(386003)(6506007)(76176011)(52116002)(6116002)(1076003)(3846002)(99286004)(54906003)(2906002)(110136005)(36756003)(55236004)(6486002)(6512007)(476003)(5660300002)(478600001)(186003)(103116003)(14454004)(71200400001)(26005)(305945005)(6436002)(7736002)(102836004); DIR:OUT; SFP:1101; SCL:1; SRVR:VE1PR08MB5055; H:VE1PR08MB5006.eurprd08.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: 5FzYg6XV/xzkss9pv8niGp+BgChlUp1OoFDmX3SNSdgCxnpcRD+wE/dJFpQwELznypYlTCv0VxkYsrf/dEBbkPArfWJCmQz9s+4K3fEkDQzdBCEingLGDUH/e4aRbBzwSrj1+723/xDoRdvm1MtVAcioJgAxfMHrqP5BPqxRlHg5CCfgxdfHFrS/tn+DmAmGF2MkvJ/lZ/mILwKrbUNsQgW2dDiFabH6bqaavco4nxZZ2yn3FxvHjg+7tn4Uha5a+yUA00ss+r4sL3+aDKhPmNJRJgen3dNId6InvsxDHvmJy4OdWf0jDeQHU1KSMIGSbo1wtJ5Ha/xMKVdye5I6vKedekfqJKekfW/Y3wC0H4zmipaunSxnLVDcx3oKyRbOMIeJqAD44bM5uP/5NI0bgCk6k8efE6qcsfog4bIGZKA= MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0e41575e-262e-4447-b7de-08d6daaf2340 X-MS-Exchange-CrossTenant-originalarrivaltime: 17 May 2019 10:05:06.8457 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR08MB5055 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=SXLECuAkNOwo4lKexmTeXwEgUEEKyyPRpvXbgIRBFeE=; b=iKRsMGBkyxG2iGRc0zCJXnC2DoU2i6cw3mfLrR1y+2/oCOI+haTxzcxmmc2lypGN0/Swu9YbR5/lwsJBxnSgsLRK5pIJKa31eEOMBhflEG2C51Jr3pZV/KYeAa0jGHV3g1Hy+Y2U4zZI2I2vK8/mzJk2HDSaSOCK082nfDsTctk= X-Mailman-Original-Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=james.qian.wang@arm.com; X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: nd , Ayan Halder , "Oscar Zhang \(Arm Technology China\)" , "Tiannan Zhu \(Arm Technology China\)" , "Jonathan Chai \(Arm Technology China\)" , "linux-kernel@vger.kernel.org" , "dri-devel@lists.freedesktop.org" , "Julien Yin \(Arm Technology China\)" , "Channing Chen \(Arm Technology China\)" , "james qian wang \(Arm Technology China\)" , "Yiqi Kang \(Arm Technology China\)" , "thomas Sun \(Arm Technology China\)" , "Lowry Li \(Arm Technology China\)" , Ben Davis Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Add komeda_fb_check_src_coords and check if the layer configured src rect can meet the requirement of fb and fb format. Signed-off-by: James Qian Wang (Arm Technology China) --- .../arm/display/komeda/komeda_framebuffer.c | 21 ++++++++++++ .../arm/display/komeda/komeda_framebuffer.h | 2 ++ .../display/komeda/komeda_pipeline_state.c | 34 +++++++++++++------ 3 files changed, 46 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c index 360ab701a88b..dd4232d13b27 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -213,6 +213,27 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, return ERR_PTR(ret); } +int komeda_fb_check_src_coords(const struct komeda_fb *kfb, + u32 src_x, u32 src_y, u32 src_w, u32 src_h) +{ + const struct drm_framebuffer *fb = &kfb->base; + const struct drm_format_info *info = fb->format; + + if ((src_x + src_w > fb->width) || (src_y + src_h > fb->height)) { + DRM_DEBUG_ATOMIC("Invalid source coordinate.\n"); + return -EINVAL; + } + + if ((src_x % info->hsub) || (src_w % info->hsub) || + (src_y % info->vsub) || (src_h % info->vsub)) { + DRM_DEBUG_ATOMIC("Wrong subsampling dimension x:%d, y:%d, w:%d, h:%d for format: %x.\n", + src_x, src_y, src_w, src_h, info->format); + return -EINVAL; + } + + return 0; +} + dma_addr_t komeda_fb_get_pixel_addr(struct komeda_fb *kfb, int x, int y, int plane) { diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.h b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.h index f4046e2e6f74..c61ca98a3a63 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.h +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.h @@ -38,6 +38,8 @@ struct komeda_fb { struct drm_framebuffer * komeda_fb_create(struct drm_device *dev, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd); +int komeda_fb_check_src_coords(const struct komeda_fb *kfb, + u32 src_x, u32 src_y, u32 src_w, u32 src_h); dma_addr_t komeda_fb_get_pixel_addr(struct komeda_fb *kfb, int x, int y, int plane); bool komeda_fb_is_layer_supported(struct komeda_fb *kfb, u32 layer_type, diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_pipeline_state.c b/drivers/gpu/drm/arm/display/komeda/komeda_pipeline_state.c index d3f414fc3956..fcd34164b3c2 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_pipeline_state.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_pipeline_state.c @@ -269,21 +269,33 @@ komeda_component_get_avail_scaler(struct komeda_component *c, static int komeda_layer_check_cfg(struct komeda_layer *layer, - struct komeda_plane_state *kplane_st, + struct komeda_fb *kfb, struct komeda_data_flow_cfg *dflow) { - struct komeda_fb *kfb = to_kfb(kplane_st->base.fb); + u32 hsize_in, vsize_in; if (!komeda_fb_is_layer_supported(kfb, layer->layer_type, dflow->rot)) return -EINVAL; - if (!in_range(&layer->hsize_in, dflow->in_w)) { - DRM_DEBUG_ATOMIC("src_w: %d is out of range.\n", dflow->in_w); + if (komeda_fb_check_src_coords(kfb, dflow->in_x, dflow->in_y, + dflow->in_w, dflow->in_h)) + return -EINVAL; + + if (layer->base.id == KOMEDA_COMPONENT_WB_LAYER) { + hsize_in = dflow->out_w; + vsize_in = dflow->out_h; + } else { + hsize_in = dflow->in_w; + vsize_in = dflow->in_h; + } + + if (!in_range(&layer->hsize_in, hsize_in)) { + DRM_DEBUG_ATOMIC("invalidate src_w %d.\n", hsize_in); return -EINVAL; } - if (!in_range(&layer->vsize_in, dflow->in_h)) { - DRM_DEBUG_ATOMIC("src_h: %d is out of range.\n", dflow->in_h); + if (!in_range(&layer->vsize_in, vsize_in)) { + DRM_DEBUG_ATOMIC("invalidate src_h %d.\n", vsize_in); return -EINVAL; } @@ -302,7 +314,7 @@ komeda_layer_validate(struct komeda_layer *layer, struct komeda_layer_state *st; int i, err; - err = komeda_layer_check_cfg(layer, kplane_st, dflow); + err = komeda_layer_check_cfg(layer, kfb, dflow); if (err) return err; @@ -360,11 +372,11 @@ komeda_wb_layer_validate(struct komeda_layer *wb_layer, struct komeda_fb *kfb = to_kfb(conn_st->writeback_job->fb); struct komeda_component_state *c_st; struct komeda_layer_state *st; - int i; + int i, err; - if (!komeda_fb_is_layer_supported(kfb, wb_layer->layer_type, - dflow->rot)) - return -EINVAL; + err = komeda_layer_check_cfg(wb_layer, kfb, dflow); + if (err) + return err; c_st = komeda_component_get_state_and_set_user(&wb_layer->base, conn_st->state, conn_st->connector, conn_st->crtc);