Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2223146pxb; Fri, 25 Mar 2022 13:21:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQ7ugO9cM0EbpaBAKXBbtUzuivOgphQ1MsTOgz/X9zDDT2u8bN1ht2mDZGzXHj8HOvcPl3 X-Received: by 2002:a17:902:f787:b0:152:157:eb7 with SMTP id q7-20020a170902f78700b0015201570eb7mr13069555pln.109.1648239683258; Fri, 25 Mar 2022 13:21:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648239683; cv=none; d=google.com; s=arc-20160816; b=X2uyOznWCdaoRy6F0wWi3M7cMrc0A0ylfTP5BhlBAeYzDVAbhQVFdpkYt0VHZ1/sXL s29ArftO2cJfxESioM2VsYiNVUdzYaXbyN5am2QJgTAS17Eo7RKxAUxGUkYz+/1Iiin2 SpWakJLC5a0aBS1U+KnnJZQfGqf+C011wb8BH/EHZP6Yh2C5gH6p1NJo6Xd1kXSmsknK gCK0S7ho5BsH06jHaFCntryvrhFM2hI+mnnn2l/cjqZqV25XpqppXrsw/YVMrhLNw6b8 HXcS/Ik4F9LwGlxKcf6iVv9yg/XFpV3arjlziJV5ZwT1AiIPS1u/Goejl824oqmgLMLK UdmA== 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=TLgjjMSuFWQdL+dKuSVaDlRlfsfwjYB9yjRacbyvBAg=; b=RI0UyMWJovVTk8S5FnSriHZA1pgPtYxLYKPdAPpv7rT9mTTKMS3RurmAXV6opQxw0b jHuAiicReDtJ8R3qVSVJyFNQ3jWkihgcGzi0qIlb7kkGui36MRfxO/EHob3GoVpsY+fC DWX4T2r3IBnV4baUpvfE88HnGTp/WK2WepiHtenLPO7YQ0m+vs174+56G6s2dvetExZw 3XEcYpXf5ICXKTVSHVnr3FZFwrjNkVxzUBTKGBc6hRFuaBG5FYBhMThvVRey5QZG8uTD ClRAezUYCzDGSwtH97UkBGjUzVxm03R6kUMBkbmZf2M/AuIVG8AgnrmIinj+Mpt0Il1Q exOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=idb7lzMC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id s14-20020a63b40e000000b003816043eeecsi3352169pgf.225.2022.03.25.13.21.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 13:21:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=idb7lzMC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CE4ED3FE8A4; Fri, 25 Mar 2022 12:29:18 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229833AbiCYT3z (ORCPT + 99 others); Fri, 25 Mar 2022 15:29:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229696AbiCYT3g (ORCPT ); Fri, 25 Mar 2022 15:29:36 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7D6719322E for ; Fri, 25 Mar 2022 12:04:08 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id a1so12064465wrh.10 for ; Fri, 25 Mar 2022 12:04:08 -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=TLgjjMSuFWQdL+dKuSVaDlRlfsfwjYB9yjRacbyvBAg=; b=idb7lzMCnWEbezjpXE9rxAJr/VOHsHBfnwgr5E/fRG+h77t7cN/X9fjKUCZD5H9E5u GSjmUMQAllN2jv/kXhTN+9q6wtKqVaD6t6xgOBrCUTw9fhvioebdL9y78UvB6XtjcM2w 8RvZsh5MXdXNXKAk3kSklaDHB9RGgeDOUzdiziXBBwKbNVvXRF8eg9JIe94wq551QvbW hm7fhNHKwyjmwx5PWtTP0fKKSWA0Yqq4DMyRxkwhxmz+Tq4AE+LRduLSdo058F2dltuS f/vUglgcITMP9i9pBCHpir3iPpRxbaNnWAjzin1YA1yqjyOrWGBTeMCCe2H7KsBxNBCG XzBw== 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=TLgjjMSuFWQdL+dKuSVaDlRlfsfwjYB9yjRacbyvBAg=; b=7cPXdzp2xQtTswfHTcZh9W4oiEbQgnht6ZEFqILezKkk2lUOmKfIseCkjWt2aMEjrf bWnaThnrHjK23vXRoGkJOXWyknSPAR4UMU2oshBVDl2072NSqCwxdG8SsFaBcreYfQFJ AMr62qHnLv3VnedwvWAX0ePcQVVtSTpBL2zqp0WMb+9ki79Dycg11myIumx/ns9nVnKH ACjf178E++BRkE6V+XcDktftSQFtvW5drxt6of5zA8q+CvxFLDRrccx3pjYIPlV5eBDM lRtmxjGfW6kW8gyjtbeKHwMJpfML/z/e9XTxAsqMFCiErME5fPznH8HL6SOJcwompaqG ytrg== X-Gm-Message-State: AOAM531YJN++MjD/bs3morcukkAhvFK+68ICCSMtqYfXkYFfUD6yhtYc u5s7BH8BkhGsvjyVrGjahJIRGKSHwYE= X-Received: by 2002:a05:6512:3b21:b0:44a:20fc:3e15 with SMTP id f33-20020a0565123b2100b0044a20fc3e15mr8650907lfv.266.1648230789531; Fri, 25 Mar 2022 10:53:09 -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 z17-20020ac24191000000b004483a4d9a3esm775738lfh.152.2022.03.25.10.53.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 10:53:09 -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 v7 2/3] i915/gvt: Save the initial HW state snapshot in i915 Date: Fri, 25 Mar 2022 13:52:50 -0400 Message-Id: <20220325175251.167164-2-zhi.a.wang@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220325175251.167164-1-zhi.a.wang@intel.com> References: <20220325175251.167164-1-zhi.a.wang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 418091484e02..0edc9ecbd403 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -429,6 +429,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