Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1286498pxb; Fri, 1 Apr 2022 09:14:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzPJeQ4MchJhwGBbzX3ViRqp6rl6/KsAw7VbbIuPwSvCZBw9KP6RIMXD9EJHKGuq07GaoYM X-Received: by 2002:a4a:9567:0:b0:324:8a04:ea2d with SMTP id n36-20020a4a9567000000b003248a04ea2dmr7042779ooi.86.1648829680486; Fri, 01 Apr 2022 09:14:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648829680; cv=none; d=google.com; s=arc-20160816; b=c3WGCKHsDxMEe2pprRGXymkV2tyGcW0ymL+gL2y7yg0p4jmWBg3HFDemcB2MOnL1g2 Rs9jihgXvMNDh73J3JXkFfbh/4j0PJrmjlQjVrpnufMJGkxcjCyItVA/Mv1eI/Wjbwhc DiuZddOfxaOakRujQl4+n/MbkI0jWbHr79jfw1Z0Me2+2T5NxuANiacACqPSNZ11YYzu BVOGNjH6G4uU/tGTafZbFYd1W+ekrWEoX/0h/t9JJyPj8mgJXbTx8SJLTv37OCHh5mza fLy5LLHCw5tWGAm9Ysm/L91+6Tzzp5lQ7l9LNwAZ6qax4VBiiFbyg49NgDWTA208W5P/ kP4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5DFXf31GKfSGudJZyBNWX7ZcGus44fo6rHAT7tAYQY8=; b=UMWSMf9vNWXPfiDF7CBIUcAE1s1mwM5oJfXC935BmMzuBrI/++abI82oV6w4nimIi8 vLr1HPqSAn+SXkFMMRtDS+b1BXBPKhE3rQEBVRL14/2f7bwhcmbwjPgfCNkX72jACoN4 XsXGbI09xUVItb6Bj2761kU2WjqHXsKEkmoPR24uQNXxRUIDtA5AMkrU6khccOMhoV8H N/PPrRnV3yO+DpXy7FoDhUE/joeElYvadAZG9Ra/le4okuuW7yG4+jsxrOAiN1umYlf5 g8peZmAYkCoKadAqnATyKUudD1Jl6hN0B1Kd9+WTOuV2z/1ybTezIsFjlDoD/AK3Z+4e MRtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Jnkg08f6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o20-20020a9d6d14000000b005cb2fc1386fsi1526569otp.235.2022.04.01.09.14.24; Fri, 01 Apr 2022 09:14:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Jnkg08f6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346090AbiDANEI (ORCPT + 99 others); Fri, 1 Apr 2022 09:04:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346017AbiDANEE (ORCPT ); Fri, 1 Apr 2022 09:04:04 -0400 Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [IPv6:2a00:1450:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C12B0220327 for ; Fri, 1 Apr 2022 06:02:14 -0700 (PDT) Received: by mail-lj1-x233.google.com with SMTP id bn33so3823246ljb.6 for ; Fri, 01 Apr 2022 06:02:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5DFXf31GKfSGudJZyBNWX7ZcGus44fo6rHAT7tAYQY8=; b=Jnkg08f69bgoGQwPpKIopTB8tcKz0IebSYALBukbDLhMBCYt0NYzDEkVFEcm2XdeaQ AXnQ3tCnpMYEheFK4GPQsPn7oxI6SvkvlnYVy8aj2T9F42UjX9Urk7gEQkMOjSbgQ414 q/5Oz6bizdwuPYfFsIZs7sVTyFFdGZ2L2JVnrNC0w8fhyv3XTJtjKZTJoTJXCeZFymlZ GiX+HRqzs9j+qijZN+cdMEf/q/u1qRiacXF9FRqMy51TJaxXs2r35G518hPSb0R/8DQ2 wmurVP7wp/HYhZOIszPKFd0d5kvqukWTfOScqjkzWt3lHQtEplWUIZVS4geVWWnFt6W3 RWlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5DFXf31GKfSGudJZyBNWX7ZcGus44fo6rHAT7tAYQY8=; b=B8niEsNrQiPyHqRFqZcrBdChDuXFh4igL/zP8SUqzlmWqz2kn4AZYvhlVd0VWKcD2Z k/fMmexSaY9HEKech884tqWg3zOepYgb4/LSubK4sj7NLcze0nSf9rl+uboy/vXu0hRf zi8XVu30qa3vb9esWVxmn33zQxgvnvwl37d5fZj1RoFQ89SVJ71hq4wBkVaSjX/cdH38 PJpZR4ln0ICKTCZCaJWnkCrvisF2g1b6hg7LoaYe4SYT/3Kp/OD3gKpxQdbfMG3XgDGI PKp/Q1R5gftJyIKS8YUjx2LHCqt+1iNFNaOqzy/esTO/uJ2AZqanvH+JHa7T49BE0eg5 RFWw== X-Gm-Message-State: AOAM531kpmV6xlSU/EGs+pRDdSMhfqUuutgiqPSW5+w8uoNFf0/mYqdx YtGqncXBxN+badF+nHHDYSU= X-Received: by 2002:a2e:b012:0:b0:249:8061:8486 with SMTP id y18-20020a2eb012000000b0024980618486mr13200997ljk.463.1648818132866; Fri, 01 Apr 2022 06:02:12 -0700 (PDT) Received: from inno-pc.lan (88-115-161-74.elisa-laajakaista.fi. [88.115.161.74]) by smtp.gmail.com with ESMTPSA id y22-20020a056512045600b0044a997dea9esm235574lfk.283.2022.04.01.06.02.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Apr 2022 06:02:12 -0700 (PDT) From: Zhi Wang X-Google-Original-From: Zhi Wang To: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org Cc: Zhi Wang , Christoph Hellwig , Jason Gunthorpe , Jani Nikula , Joonas Lahtinen , Vivi Rodrigo , Zhenyu Wang Subject: [PATCH v8 2/3] i915/gvt: Save the initial HW state snapshot in i915 Date: Fri, 1 Apr 2022 09:02:06 -0400 Message-Id: <20220401130207.33944-3-zhi.a.wang@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220401130207.33944-1-zhi.a.wang@intel.com> References: <20220401130207.33944-1-zhi.a.wang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Save the initial HW state snapshot in i915 so that the rest code of GVT-g can be moved into a dedicated module while it can still get a clean initial HW state saved at the correct time during the initialization of i915. The futhrer vGPU created by GVT-g will use this HW state as the initial HW state. --- v6: - Remove the reference of intel_gvt_device_info.(Christoph) - Refine the save_mmio() function. (Christoph) Cc: Christoph Hellwig Cc: Jason Gunthorpe Cc: Jani Nikula Cc: Joonas Lahtinen Cc: Vivi Rodrigo Cc: Zhenyu Wang Cc: Zhi Wang Signed-off-by: Zhi Wang --- drivers/gpu/drm/i915/i915_drv.h | 2 + drivers/gpu/drm/i915/intel_gvt.c | 92 +++++++++++++++++++++++++++++++- 2 files changed, 92 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index 943267393ecb..abb39444b8be 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -421,6 +421,8 @@ struct i915_virtual_gpu { struct mutex lock; /* serialises sending of g2v_notify command pkts */ bool active; u32 caps; + u32 *initial_mmio; + u8 *initial_cfg_space; }; struct i915_selftest_stash { diff --git a/drivers/gpu/drm/i915/intel_gvt.c b/drivers/gpu/drm/i915/intel_gvt.c index cf6e98962d82..65daab2c4d9e 100644 --- a/drivers/gpu/drm/i915/intel_gvt.c +++ b/drivers/gpu/drm/i915/intel_gvt.c @@ -86,6 +86,85 @@ void intel_gvt_sanitize_options(struct drm_i915_private *dev_priv) dev_priv->params.enable_gvt = 0; } +static void free_initial_hw_state(struct drm_i915_private *dev_priv) +{ + struct i915_virtual_gpu *vgpu = &dev_priv->vgpu; + + vfree(vgpu->initial_mmio); + vgpu->initial_mmio = NULL; + + kfree(vgpu->initial_cfg_space); + vgpu->initial_cfg_space = NULL; +} + +static void save_mmio(struct intel_gvt_mmio_table_iter *iter, u32 offset, + u32 size) +{ + struct drm_i915_private *dev_priv = iter->i915; + u32 *mmio, i; + + for (i = offset; i < offset + size; i += 4) { + mmio = iter->data + i; + *mmio = intel_uncore_read_notrace(to_gt(dev_priv)->uncore, + _MMIO(i)); + } +} + +static int handle_mmio(struct intel_gvt_mmio_table_iter *iter, + u32 offset, u32 size) +{ + if (WARN_ON(!IS_ALIGNED(offset, 4))) + return -EINVAL; + + save_mmio(iter, offset, size); + return 0; +} + +static int save_initial_hw_state(struct drm_i915_private *dev_priv) +{ + struct pci_dev *pdev = to_pci_dev(dev_priv->drm.dev); + struct i915_virtual_gpu *vgpu = &dev_priv->vgpu; + struct intel_gvt_mmio_table_iter iter; + void *mem; + int i, ret; + + mem = kzalloc(PCI_CFG_SPACE_EXP_SIZE, GFP_KERNEL); + if (!mem) + return -ENOMEM; + + vgpu->initial_cfg_space = mem; + + for (i = 0; i < PCI_CFG_SPACE_EXP_SIZE; i += 4) + pci_read_config_dword(pdev, i, mem + i); + + mem = vzalloc(2 * SZ_1M); + if (!mem) { + ret = -ENOMEM; + goto err_mmio; + } + + vgpu->initial_mmio = mem; + + iter.i915 = dev_priv; + iter.data = vgpu->initial_mmio; + iter.handle_mmio_cb = handle_mmio; + + ret = intel_gvt_iterate_mmio_table(&iter); + if (ret) + goto err_iterate; + + return 0; + +err_iterate: + vfree(vgpu->initial_mmio); + vgpu->initial_mmio = NULL; +err_mmio: + kfree(vgpu->initial_cfg_space); + vgpu->initial_cfg_space = NULL; + + return ret; +} + /** * intel_gvt_init - initialize GVT components * @dev_priv: drm i915 private data @@ -115,15 +194,23 @@ int intel_gvt_init(struct drm_i915_private *dev_priv) return -EIO; } + ret = save_initial_hw_state(dev_priv); + if (ret) { + drm_dbg(&dev_priv->drm, "Fail to save initial HW state\n"); + goto err_save_hw_state; + } + ret = intel_gvt_init_device(dev_priv); if (ret) { drm_dbg(&dev_priv->drm, "Fail to init GVT device\n"); - goto bail; + goto err_init_device; } return 0; -bail: +err_init_device: + free_initial_hw_state(dev_priv); +err_save_hw_state: dev_priv->params.enable_gvt = 0; return 0; } @@ -147,6 +234,7 @@ void intel_gvt_driver_remove(struct drm_i915_private *dev_priv) return; intel_gvt_clean_device(dev_priv); + free_initial_hw_state(dev_priv); } /** -- 2.25.1