Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp1895884ybn; Thu, 26 Sep 2019 03:58:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqxwDhloYc3RKUbW/4ZpIEead3H8JOH2VJ03+uYUs3n2BfLrQjOFpvHGqO5cK4Nrr+5qB2dg X-Received: by 2002:a50:8961:: with SMTP id f30mr2766646edf.144.1569495523409; Thu, 26 Sep 2019 03:58:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569495523; cv=none; d=google.com; s=arc-20160816; b=kiP7ihMTkmXgKQ4KmtXueLty6jWE8z0EV/CWsyjTqo0NDqvmh0Xrneqft6SvtAmfz+ 078UKhmXZ/E1fUJN1Jx1JejGbYKKorN7J0mJ0DeZHEXuQJGs6Dah3wGBqFYkr2+Qf0va WP4Bjxo24JxmaR8A/d90F5j1BFq2I542uMpgtdaaRUwF3JM6lES+S8ls8g3GvwtxBs+p 6Y/L0jB21mujU8cGKMatmqehGI+5nSF6bi+IBzS6mUKBhNOPeDf+ekhheRbLk75bb68I jkFQ4JgKnzWlPjvQCcBE917R5Ibt84PPh1jjqBMUVV2YVgyM6dsDkFQjaW9lWDgxi7tR EJyg== 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=QogNXEmJeS1CZrxJvMy3wtRPOsdlQSznMcG+nU1s9fI=; b=lwvaN2k+KsMnr3auC+cZztienaeHLwZQEWSy2uC9a2rrFJGNG6niXcCeyU11y8sa22 Nsv5lfV4CFh3ptPHEHc03KdfRZwga7nGed0X2FcYFpolmlxe1LGJRWB9EHzkyxDtvg2T 06+Ibth/lqeDHpu4efNmfBm/k/X1gAOelhN9yHDp/744qsljfU0ykuO9/oCWvgP+m+ZE NJWhZNeYYO0jz8rGddETTseIv8KgdFwpFGYgfO8jbPLioCe69bZ7p/CtmM5x7kkk5zjs adUgTV6RewiAtD9VN9cbQM8Q9QlpzpafehRhCSpL6zTahIzlHp91YYdxRdiFjYh4wjdb cYaA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x25si1079049edd.350.2019.09.26.03.58.20; Thu, 26 Sep 2019 03:58:43 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728570AbfIZIZL (ORCPT + 99 others); Thu, 26 Sep 2019 04:25:11 -0400 Received: from lucky1.263xmail.com ([211.157.147.131]:43254 "EHLO lucky1.263xmail.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726088AbfIZIZK (ORCPT ); Thu, 26 Sep 2019 04:25:10 -0400 Received: from localhost (unknown [192.168.167.193]) by lucky1.263xmail.com (Postfix) with ESMTP id 8A99668135; Thu, 26 Sep 2019 16:25:07 +0800 (CST) X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-ADDR-CHECKED4: 1 X-ANTISPAM-LEVEL: 2 X-ABS-CHECKED: 0 Received: from localhost.localdomain (unknown [58.22.7.114]) by smtp.263.net (postfix) whith ESMTP id P24701T140118476191488S1569486296531843_; Thu, 26 Sep 2019 16:25:07 +0800 (CST) X-IP-DOMAINF: 1 X-UNIQUE-TAG: <1af4b4c1788e9f87dccb81098897a452> X-RL-SENDER: hjc@rock-chips.com X-SENDER: hjc@rock-chips.com X-LOGIN-NAME: hjc@rock-chips.com X-FST-TO: dri-devel@lists.freedesktop.org X-SENDER-IP: 58.22.7.114 X-ATTACHMENT-NUM: 0 X-DNS-TYPE: 0 From: Sandy Huang To: dri-devel@lists.freedesktop.org, Sandy Huang , =?UTF-8?q?Heiko=20St=C3=BCbner?= , David Airlie , Daniel Vetter Cc: maarten.lankhorst@linux.intel.com, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/3] drm/rockchip: Add rockchip_vop_get_offset to get offset Date: Thu, 26 Sep 2019 16:24:48 +0800 Message-Id: <1569486289-152061-3-git-send-email-hjc@rock-chips.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1569486289-152061-1-git-send-email-hjc@rock-chips.com> References: <1569486289-152061-1-git-send-email-hjc@rock-chips.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add rockchip_vop_get_offset to get offset, this can compatible legacy and block_h/w format describe. Signed-off-by: Sandy Huang --- drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 61 ++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c index 2f821c5..ce74218 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c @@ -249,6 +249,56 @@ static bool has_rb_swapped(uint32_t format) } } +static u32 rockchip_vop_get_offset(struct drm_plane_state *state, u8 plane) +{ + const struct drm_format_info *info; + struct drm_rect *src = &state->src; + struct drm_framebuffer *fb = state->fb; + u32 format = fb->format->format; + u8 h_div = 1, v_div = 1; + u32 block_w, block_h, block_size, block_start_y, num_hblocks; + u32 sample_x, sample_y; + u32 offset; + + info = drm_format_info(format); + if (!info || plane >= info->num_planes) + return 0; + + if (plane > 0) { + h_div = fb->format->hsub; + v_div = fb->format->vsub; + } + + switch (format) { + case DRM_FORMAT_NV12_10: + case DRM_FORMAT_NV21_10: + case DRM_FORMAT_NV16_10: + case DRM_FORMAT_NV61_10: + case DRM_FORMAT_NV24_10: + case DRM_FORMAT_NV42_10: + block_w = drm_format_info_block_width(fb->format, plane); + block_h = drm_format_info_block_height(fb->format, plane); + block_size = fb->format->char_per_block[plane]; + + sample_x = (src->x1 >> 16) / h_div; + sample_y = (src->y1 >> 16) / v_div; + block_start_y = (sample_y / block_h) * block_h; + num_hblocks = sample_x / block_w; + + offset = fb->pitches[plane] * block_start_y; + offset += block_size * num_hblocks; + + break; + default: + offset = (src->x1 >> 16) * fb->format->cpp[plane] / h_div; + offset += (src->y1 >> 16) * fb->pitches[plane] / v_div; + + break; + } + + return offset; +} + static enum vop_data_format vop_convert_format(uint32_t format) { switch (format) { @@ -832,8 +882,7 @@ static void vop_plane_atomic_update(struct drm_plane *plane, dsp_sty = dest->y1 + crtc->mode.vtotal - crtc->mode.vsync_start; dsp_st = dsp_sty << 16 | (dsp_stx & 0xffff); - offset = (src->x1 >> 16) * fb->format->cpp[0]; - offset += (src->y1 >> 16) * fb->pitches[0]; + offset = rockchip_vop_get_offset(state, 0); dma_addr = rk_obj->dma_addr + offset + fb->offsets[0]; /* @@ -857,16 +906,10 @@ static void vop_plane_atomic_update(struct drm_plane *plane, (state->rotation & DRM_MODE_REFLECT_X) ? 1 : 0); if (is_yuv) { - int hsub = fb->format->hsub; - int vsub = fb->format->vsub; - int bpp = fb->format->cpp[1]; - uv_obj = fb->obj[1]; rk_uv_obj = to_rockchip_obj(uv_obj); - offset = (src->x1 >> 16) * bpp / hsub; - offset += (src->y1 >> 16) * fb->pitches[1] / vsub; - + offset = rockchip_vop_get_offset(state, 1); dma_addr = rk_uv_obj->dma_addr + offset + fb->offsets[1]; VOP_WIN_SET(vop, win, uv_vir, DIV_ROUND_UP(fb->pitches[1], 4)); VOP_WIN_SET(vop, win, uv_mst, dma_addr); -- 2.7.4