From patchwork Fri Mar 23 12:34:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Micha=C5=82_Winiarski?= X-Patchwork-Id: 10304517 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 733B960385 for ; Fri, 23 Mar 2018 12:34:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 61BDB28E2F for ; Fri, 23 Mar 2018 12:34:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 54DF328E31; Fri, 23 Mar 2018 12:34:44 +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 B82DE28E2F for ; Fri, 23 Mar 2018 12:34:43 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1E2E36E352; Fri, 23 Mar 2018 12:34:43 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by gabe.freedesktop.org (Postfix) with ESMTPS id 80F2B6E352 for ; Fri, 23 Mar 2018 12:34:42 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Mar 2018 05:34:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,350,1517904000"; d="scan'208";a="39984484" Received: from irsmsx102.ger.corp.intel.com ([163.33.3.155]) by fmsmga004.fm.intel.com with ESMTP; 23 Mar 2018 05:34:40 -0700 Received: from localhost (172.28.172.64) by IRSMSX102.ger.corp.intel.com (163.33.3.155) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 23 Mar 2018 12:34:40 +0000 From: =?UTF-8?q?Micha=C5=82=20Winiarski?= To: Date: Fri, 23 Mar 2018 13:34:07 +0100 Message-ID: <20180323123411.3214-4-michal.winiarski@intel.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180323123411.3214-1-michal.winiarski@intel.com> References: <20180323123411.3214-1-michal.winiarski@intel.com> MIME-Version: 1.0 X-Originating-IP: [172.28.172.64] Subject: [Intel-gfx] [PATCH 4/8] drm/i915/guc: Separate WOPCM partitioning from constraints check X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP In the following patches we're going to support constraints checking on an already locked partitioning. Let's structure the code now to allow for code reuse and reduce the churn later on. Signed-off-by: MichaƂ Winiarski Cc: Chris Wilson Cc: Jackie Li Cc: Joonas Lahtinen Cc: Michal Wajdeczko --- drivers/gpu/drm/i915/intel_wopcm.c | 141 +++++++++++++++++++++++++++---------- 1 file changed, 102 insertions(+), 39 deletions(-) diff --git a/drivers/gpu/drm/i915/intel_wopcm.c b/drivers/gpu/drm/i915/intel_wopcm.c index 50854a6b9493..52841d340002 100644 --- a/drivers/gpu/drm/i915/intel_wopcm.c +++ b/drivers/gpu/drm/i915/intel_wopcm.c @@ -84,6 +84,17 @@ static inline u32 context_reserved_size(struct drm_i915_private *i915) return 0; } +static inline u32 guc_fw_size_in_wopcm(u32 guc_fw_size) +{ + return ALIGN(guc_fw_size + GUC_WOPCM_RESERVED + + GUC_WOPCM_STACK_RESERVED, PAGE_SIZE); +} + +static inline u32 huc_fw_size_in_wopcm(u32 huc_fw_size) +{ + return huc_fw_size + WOPCM_RESERVED_SIZE; +} + static u32 gen9_size_for_dword_gap_restriction(u32 guc_wopcm_base, u32 guc_wopcm_size) { @@ -121,19 +132,54 @@ gen9_size_for_huc_restriction(u32 guc_wopcm_size, u32 huc_fw_size) return additional_size; } -static inline int check_hw_restriction(struct drm_i915_private *i915, - u32 guc_wopcm_base, u32 guc_wopcm_size, - u32 huc_fw_size) +static int check_huc_fw_fits(struct intel_wopcm *wopcm, u32 huc_fw_size) +{ + if (huc_fw_size_in_wopcm(huc_fw_size) > wopcm->guc.base) { + DRM_ERROR("Need %uKiB WOPCM for HuC, %uKiB available.\n", + huc_fw_size_in_wopcm(huc_fw_size) / 1024, + wopcm->guc.base / 1024); + return -E2BIG; + } + + return 0; +} + +static int check_guc_fw_fits(struct intel_wopcm *wopcm, u32 guc_fw_size) +{ + if (guc_fw_size_in_wopcm(guc_fw_size) > wopcm->guc.size) { + DRM_ERROR("Need %uKiB WOPCM for GuC, %uKiB available.\n", + huc_fw_size_in_wopcm(guc_fw_size) / 1024, + wopcm->guc.size / 1024); + return -E2BIG; + } + + return 0; +} + +static int check_ctx_rsvd_fits(struct intel_wopcm *wopcm, u32 ctx_rsvd) +{ + if ((wopcm->guc.base + wopcm->guc.size + ctx_rsvd) > wopcm->size) { + DRM_ERROR("GuC WOPCM base (%uKiB) is too big.\n", + wopcm->guc.base / 1024); + return -E2BIG; + } + + return 0; +} + +static int wopcm_check_hw_restrictions(struct intel_wopcm *wopcm) { + struct drm_i915_private *i915 = wopcm_to_i915(wopcm); + u32 huc_fw_size = intel_uc_fw_get_upload_size(&i915->huc.fw); u32 size; if (IS_GEN9(i915) || IS_CNL_REVID(i915, CNL_REVID_A0, CNL_REVID_A0)) { - size = gen9_size_for_dword_gap_restriction(guc_wopcm_base, - guc_wopcm_size); + size = gen9_size_for_dword_gap_restriction(wopcm->guc.base, + wopcm->guc.size); if (size) goto err; - size = gen9_size_for_huc_restriction(guc_wopcm_size, + size = gen9_size_for_huc_restriction(wopcm->guc.size, huc_fw_size); if (size) goto err; @@ -143,12 +189,54 @@ static inline int check_hw_restriction(struct drm_i915_private *i915, err: DRM_ERROR("GuC WOPCM size %uKiB is too small. %uKiB more needed.\n", - guc_wopcm_size / 1024, + wopcm->guc.size / 1024, size / 1024); return -E2BIG; } +static bool wopcm_check_components_fit(struct intel_wopcm *wopcm) +{ + struct drm_i915_private *i915 = wopcm_to_i915(wopcm); + u32 huc_fw_size = intel_uc_fw_get_upload_size(&i915->huc.fw); + u32 guc_fw_size = intel_uc_fw_get_upload_size(&i915->guc.fw); + u32 ctx_rsvd = context_reserved_size(i915); + int err; + + err = check_huc_fw_fits(wopcm, huc_fw_size); + if (err) + return err; + + err = check_guc_fw_fits(wopcm, guc_fw_size); + if (err) + return err; + + err = check_ctx_rsvd_fits(wopcm, ctx_rsvd); + if (err) + return err; + + return 0; +} + +static int wopcm_guc_init(struct intel_wopcm *wopcm) +{ + struct drm_i915_private *dev_priv = wopcm_to_i915(wopcm); + u32 huc_fw_size = intel_uc_fw_get_upload_size(&dev_priv->huc.fw); + u32 ctx_rsvd = context_reserved_size(dev_priv); + + wopcm->guc.base = ALIGN_DOWN(huc_fw_size_in_wopcm(huc_fw_size), + GUC_WOPCM_OFFSET_ALIGNMENT); + + wopcm->guc.size = ALIGN(wopcm->size - wopcm->guc.base - ctx_rsvd, + PAGE_SIZE); + + DRM_DEBUG_DRIVER("GuC WOPCM Region: [%uKiB, %uKiB)\n", + wopcm->guc.base / 1024, + (wopcm->guc.base + wopcm->guc.size) / 1024); + + return 0; +} + /** * intel_wopcm_init() - Initialize the WOPCM structure. * @wopcm: pointer to intel_wopcm. @@ -163,46 +251,21 @@ static inline int check_hw_restriction(struct drm_i915_private *i915, */ int intel_wopcm_init(struct intel_wopcm *wopcm) { - struct drm_i915_private *i915 = wopcm_to_i915(wopcm); - u32 guc_fw_size = intel_uc_fw_get_upload_size(&i915->guc.fw); - u32 huc_fw_size = intel_uc_fw_get_upload_size(&i915->huc.fw); - u32 ctx_rsvd = context_reserved_size(i915); - u32 guc_wopcm_base; - u32 guc_wopcm_size; - u32 guc_wopcm_rsvd; int err; GEM_BUG_ON(!wopcm->size); - guc_wopcm_base = ALIGN(huc_fw_size + WOPCM_RESERVED_SIZE, - GUC_WOPCM_OFFSET_ALIGNMENT); - if ((guc_wopcm_base + ctx_rsvd) >= wopcm->size) { - DRM_ERROR("GuC WOPCM base (%uKiB) is too big.\n", - guc_wopcm_base / 1024); - return -E2BIG; - } - - guc_wopcm_size = wopcm->size - guc_wopcm_base - ctx_rsvd; - guc_wopcm_size &= GUC_WOPCM_SIZE_MASK; - - DRM_DEBUG_DRIVER("Calculated GuC WOPCM Region: [%uKiB, %uKiB)\n", - guc_wopcm_base / 1024, guc_wopcm_size / 1024); - - guc_wopcm_rsvd = GUC_WOPCM_RESERVED + GUC_WOPCM_STACK_RESERVED; - if ((guc_fw_size + guc_wopcm_rsvd) > guc_wopcm_size) { - DRM_ERROR("Need %uKiB WOPCM for GuC, %uKiB available.\n", - (guc_fw_size + guc_wopcm_rsvd) / 1024, - guc_wopcm_size / 1024); - return -E2BIG; - } + err = wopcm_guc_init(wopcm); + if (err) + return err; - err = check_hw_restriction(i915, guc_wopcm_base, guc_wopcm_size, - huc_fw_size); + err = wopcm_check_hw_restrictions(wopcm); if (err) return err; - wopcm->guc.base = guc_wopcm_base; - wopcm->guc.size = guc_wopcm_size; + err = wopcm_check_components_fit(wopcm); + if (err) + return err; return 0; }