From patchwork Tue Jun 25 12:45:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael J. Ruhl" X-Patchwork-Id: 13711089 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 167C8156899 for ; Tue, 25 Jun 2024 12:46:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719319586; cv=none; b=A97CxnTpkHuuy1UsGH9bQ4wWo3/f7P/+hH9gfbkcf+d17UjayyJtCoo0AH+GmLQYK2NggnsYBpchTcTOImrHdFVcJOvnPN6klEBxAoI/QmFR1gvoA5WsCwYApsVYEBiHHNTgspomRlckuNX0+gwCmESSJ6kBFg0/87zy1mzmtac= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719319586; c=relaxed/simple; bh=Tyud/nBVEqmQrX88IJ8N/r/4y3Fg1AyAvFxq0ys9M7o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DSWErOM0g6W0QfA8vrCJuZfSJqpIoow78JEHrfred3vhoAMjO4S5lUUvIrtgqWoYlX9MjPLYYursE7oaycXcHHsDicjbzLW805aURk/n6DKMSRYm4E3f57bDI4UQcgB7mHLiqOHmuPJ/Vu9HFPq+IC8lVvUPFzJeBp9jMlV5XFE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=L7WBcO/4; arc=none smtp.client-ip=192.198.163.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="L7WBcO/4" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719319585; x=1750855585; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Tyud/nBVEqmQrX88IJ8N/r/4y3Fg1AyAvFxq0ys9M7o=; b=L7WBcO/4EA7rdw48G5H9CijTSCXaWZOx2Yc//WaQljVBrge+9OIGHJTP nj92HN+hONZgW2IqXArSQ+wi03U3n5akgqvoBEKCf7llhlea4vkuc/Kp6 oh//5lUcJkaM9zc+JFzlleE0r0A+0Y2uaNF1N0x1o9WOq02mmzdgEBdBu NHDOGsm0VdmEib/83EDJBaLGCgHJ+xNr4b9CrmjKElAoAk8phOCvwtQfx 7w2LB4CerMkgtoSQ7Y5y/I0mVs/9NYJ6skq/6IJooMo5MMw23XIL7NV/G yXhRPhNnUM9YVarxbPh/vxl+F1CGMdP2JG2pGvmBNUfWLHo9wm4Jz6fcD Q==; X-CSE-ConnectionGUID: AYkh9118RYyqD68ows0Lew== X-CSE-MsgGUID: 7rqVNe/UTbKK8lIBY9FMEQ== X-IronPort-AV: E=McAfee;i="6700,10204,11113"; a="26955343" X-IronPort-AV: E=Sophos;i="6.08,264,1712646000"; d="scan'208";a="26955343" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jun 2024 05:46:21 -0700 X-CSE-ConnectionGUID: oSd/GR/CRzK/irdRE7ywYg== X-CSE-MsgGUID: ej7vnsaDRaOOVo2Yj4WmvA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,264,1712646000"; d="scan'208";a="48547085" Received: from awvttdev-05.aw.intel.com ([10.228.212.156]) by ORVIESA003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jun 2024 05:46:20 -0700 From: "Michael J. Ruhl" To: intel-xe@lists.freedesktop.org, platform-driver-x86@vger.kernel.org, david.e.box@linux.intel.com Cc: michael.j.ruhl@intel.com Subject: [PATCH v3 4/6] drm/xe/vsec: Support BMG devices Date: Tue, 25 Jun 2024 08:45:50 -0400 Message-ID: <20240625124554.3358460-5-michael.j.ruhl@intel.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240625124554.3358460-1-michael.j.ruhl@intel.com> References: <20240625124554.3358460-1-michael.j.ruhl@intel.com> Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Utilize the PMT callback API to add support for the BMG devices. Signed-off-by: Michael J. Ruhl --- drivers/gpu/drm/xe/Makefile | 1 + drivers/gpu/drm/xe/xe_device.c | 5 + drivers/gpu/drm/xe/xe_device_types.h | 6 + drivers/gpu/drm/xe/xe_vsec.c | 214 +++++++++++++++++++++++++++ drivers/gpu/drm/xe/xe_vsec.h | 13 ++ 5 files changed, 239 insertions(+) create mode 100644 drivers/gpu/drm/xe/xe_vsec.c create mode 100644 drivers/gpu/drm/xe/xe_vsec.h diff --git a/drivers/gpu/drm/xe/Makefile b/drivers/gpu/drm/xe/Makefile index b1e03bfe4a68..5860d6db1598 100644 --- a/drivers/gpu/drm/xe/Makefile +++ b/drivers/gpu/drm/xe/Makefile @@ -129,6 +129,7 @@ xe-y += xe_bb.o \ xe_vm.o \ xe_vram.o \ xe_vram_freq.o \ + xe_vsec.o \ xe_wait_user_fence.o \ xe_wa.o \ xe_wopcm.o diff --git a/drivers/gpu/drm/xe/xe_device.c b/drivers/gpu/drm/xe/xe_device.c index ca5e8435485a..35698ece59d6 100644 --- a/drivers/gpu/drm/xe/xe_device.c +++ b/drivers/gpu/drm/xe/xe_device.c @@ -53,6 +53,7 @@ #include "xe_ttm_sys_mgr.h" #include "xe_vm.h" #include "xe_vram.h" +#include "xe_vsec.h" #include "xe_wait_user_fence.h" static int xe_file_open(struct drm_device *dev, struct drm_file *file) @@ -317,6 +318,8 @@ struct xe_device *xe_device_create(struct pci_dev *pdev, goto err; } + drmm_mutex_init(&xe->drm, &xe->pmt.lock); + err = xe_display_create(xe); if (WARN_ON(err)) goto err; @@ -692,6 +695,8 @@ int xe_device_probe(struct xe_device *xe) for_each_gt(gt, xe, id) xe_gt_sanitize_freq(gt); + xe_vsec_init(xe); + return devm_add_action_or_reset(xe->drm.dev, xe_device_sanitize, xe); err_fini_display: diff --git a/drivers/gpu/drm/xe/xe_device_types.h b/drivers/gpu/drm/xe/xe_device_types.h index c37be471d11c..11513d8f3a8b 100644 --- a/drivers/gpu/drm/xe/xe_device_types.h +++ b/drivers/gpu/drm/xe/xe_device_types.h @@ -451,6 +451,12 @@ struct xe_device { struct mutex lock; } d3cold; + /** @pmt: Support the PMT driver callback interface */ + struct { + /** @pmt.lock: protect access for telemetry data */ + struct mutex lock; + } pmt; + /** * @pm_callback_task: Track the active task that is running in either * the runtime_suspend or runtime_resume callbacks. diff --git a/drivers/gpu/drm/xe/xe_vsec.c b/drivers/gpu/drm/xe/xe_vsec.c new file mode 100644 index 000000000000..a8afef731379 --- /dev/null +++ b/drivers/gpu/drm/xe/xe_vsec.c @@ -0,0 +1,214 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright © 2022 - 2024 Intel Corporation + */ +#include +#include + +#include "xe_device.h" +#include "xe_device_types.h" +#include "xe_drv.h" +#include "xe_mmio.h" +#include "xe_platform_types.h" +#include "xe_pm.h" +#include "xe_vsec.h" + +#define SOC_BASE 0x280000 + +#define BMG_PMT_BASE 0xDB000 +#define BMG_DISCOVERY_OFFSET (SOC_BASE + BMG_PMT_BASE) + +#define BMG_TELEMETRY_BASE 0xE0000 +#define BMG_TELEMETRY_OFFSET (SOC_BASE + BMG_TELEMETRY_BASE) + +#define GFX_BAR 0 + +#define SG_REMAP_INDEX1 XE_REG(SOC_BASE + 0x08) +#define SG_REMAP_ACCESS(_mem) ((_mem) << 24) +#define SG_REMAP_BITS GENMASK(31, 24) + +static struct intel_vsec_header bmg_telemetry = { + .length = 0x10, + .id = VSEC_ID_TELEMETRY, + .num_entries = 2, + .entry_size = 4, + .tbir = GFX_BAR, + .offset = BMG_DISCOVERY_OFFSET, +}; + +static struct intel_vsec_header *bmg_capabilities[] = { + &bmg_telemetry, + NULL +}; + +enum xe_vsec { + XE_VSEC_UNKNOWN = 0, + XE_VSEC_BMG, +}; + +static struct intel_vsec_platform_info xe_vsec_info[] = { + [XE_VSEC_BMG] = { + .caps = VSEC_CAP_TELEMETRY, + .headers = bmg_capabilities, + }, + { } +}; + +/* GUID Decode information */ +#define GUID_TELEM_ITERATION GENMASK(3, 0) +#define GUID_SEGMENT GENMASK(7, 4) +#define GUID_SOC_SKU GENMASK(11, 8) +#define GUID_DEVICE_ID GENMASK(27, 12) +#define GUID_CAP_TYPE GENMASK(29, 28) +#define GUID_RECORD_ID GENMASK(31, 30) + +enum record_id { + PUNIT, + OOBMSM_0, + OOBMSM_1 +}; + +enum capability { + CRASHLOG, + TELEMETRY, + WATCHER +}; + +/* + * The GUID will have the following bits to decode (high bits first): + * + * X(2bits) - Record-ID (0-PUNIT, 1-OOBMSM_0, 2-OOBMSM_1) + * X(2bits) - Capability Type (Crashlog-0, Telemetry Aggregator-1, Watcher-2) + * XXXX(16bits)– Device ID – changes for each down bin SKU’s (0xE2F8 for BMG) + * X(4bits) - SOC_SKU (SKU_INDEPENDENT-0, X3-1, X2-2, G31-3), + * X(4bits) - Segment (SEGMENT_INDEPENDENT-0, Client-1, Server-2) + * X(4bits) - {Telemetry space iteration number (0,1,..)} + * + */ +static int guid_decode(u32 guid, int *index, u32 *offset) +{ + u32 record_id = (guid & GUID_RECORD_ID) >> 30; + u32 cap_type = (guid & GUID_CAP_TYPE) >> 28; + u32 device_id = (guid & GUID_DEVICE_ID) >> 12; + + if (device_id != 0xE2F8) + return -ENODEV; + + if (record_id > OOBMSM_1 || cap_type > WATCHER) + return -EINVAL; + + *offset = 0; + + if (cap_type == CRASHLOG) { + *index = record_id == PUNIT ? 2 : 4; + return 0; + } + + switch (record_id) { + case PUNIT: + *index = 0; + if (cap_type == TELEMETRY) + *offset = 0x0200; + else /* if (cap_type == WATCHER) */ + *offset = 0x14A0; + break; + + case OOBMSM_0: + *index = 1; + if (cap_type == WATCHER) + *offset = 0x18D8; + break; + + case OOBMSM_1: + *index = 1; + if (cap_type == TELEMETRY) + *offset = 0x1000; + break; + } + + return 0; +} + +static int xe_pmt_telem_read(void *args, u32 guid, u64 *data, u32 count) +{ + struct xe_device *xe = pdev_to_xe_device((struct pci_dev *)args); + void __iomem *telem_addr = xe->tiles[0].mmio.regs + BMG_TELEMETRY_OFFSET; + u32 mem_region; + u32 offset; + int ret; + + ret = guid_decode(guid, &mem_region, &offset); + if (ret) + return ret; + + telem_addr += offset; + + mutex_lock(&xe->pmt.lock); + + /* indicate that we are not at an appropriate power level */ + ret = -ENODATA; + if (xe_pm_runtime_get_if_active(xe) > 0) { + /* set SoC re-mapper index register based on guid memory region */ + xe_mmio_rmw32(xe->tiles[0].primary_gt, SG_REMAP_INDEX1, SG_REMAP_BITS, + SG_REMAP_ACCESS(mem_region)); + + memcpy_fromio(data, telem_addr, count); + ret = count; + xe_pm_runtime_put(xe); + } + mutex_unlock(&xe->pmt.lock); + + return ret; +} + +struct pmt_callbacks xe_pmt_cb = { + .read_telem = xe_pmt_telem_read, +}; + +static const int vsec_platforms[] = { + [XE_BATTLEMAGE] = XE_VSEC_BMG, +}; + +static enum xe_vsec get_platform_info(struct xe_device *xe) +{ + if (xe->info.platform > XE_BATTLEMAGE) + return XE_VSEC_UNKNOWN; + + return vsec_platforms[xe->info.platform]; +} + +/** + * intel_vsec_init - Initialize resources and add intel_vsec auxiliary + * interface + * @xe: valid xe instance + */ +void xe_vsec_init(struct xe_device *xe) +{ + struct intel_vsec_platform_info *info; + struct device *dev = xe->drm.dev; + struct pci_dev *pdev = to_pci_dev(dev); + enum xe_vsec platform; + + platform = get_platform_info(xe); + if (platform == XE_VSEC_UNKNOWN) + return; + + info = &xe_vsec_info[platform]; + if (!info->headers) + return; + + switch (platform) { + case XE_VSEC_BMG: + info->priv_data = &xe_pmt_cb; + break; + default: + break; + } + + /* + * Register a VSEC. Cleanup is handled using device managed + * resources. + */ + intel_vsec_register(pdev, info); +} +MODULE_IMPORT_NS(INTEL_VSEC); diff --git a/drivers/gpu/drm/xe/xe_vsec.h b/drivers/gpu/drm/xe/xe_vsec.h new file mode 100644 index 000000000000..3fd29a21cad6 --- /dev/null +++ b/drivers/gpu/drm/xe/xe_vsec.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright © 2022 - 2024 Intel Corporation + */ + +#ifndef _XE_VSEC_H_ +#define _XE_VSEC_H_ + +struct xe_device; + +void xe_vsec_init(struct xe_device *xe); + +#endif