From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 13A10606A32D for ; Thu, 3 Dec 2026 14:54:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=Xyut0rhU Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A20F710E751; Thu, 3 Dec 2026 14:53:59 +0000 (UTC) Received: from BN1PR04CU002.outbound.protection.outlook.com (mail-eastus2azon11010039.outbound.protection.outlook.com [52.101.56.39]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7A58A10E751 for ; Thu, 3 Dec 2026 14:53:53 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ScitRCFhfC2i8RofYTIrU6kwgTD0tqJ74yPWAO7gkb/4hpQsvNXilLNV3aStSi/1Vd4kUEBjXZdZmZkWq6aqiHbnyN8vQHtmZ8EgrtKXGJef+l5GIKPehBsyrNPqVWyKDbdicBSv1T2gs72zLWi5DfvHPbNuDqkb0AfN1ypFFI6rAmUbwYLXcsHu/FZnYBBjGkAHlu1ZTK8lXheJIzNZSQtbxgYgoLQWAuiGzBAITChn/n95jmNMg9jIkUKyNlmhhJta7QOU0wMdbuf8PZILFyswxsJZw+RasactZ1XJ2lIm4976udliZdsjW1wrdeJXJWzUQzmxNYEdIEPNYhPtgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=U8DFTg8a+4P04vq/9rK+hmRr18MWi4bFGz9J8dVxQmY=; b=x0vjAJnEzsoAKABd7EZ0wfsYcDdadKVUM+WN/bFcesWynQnaemH3uMLRCOjmrO97NR3tB6xvZz00rDYkW+Q+f8wYGYO8ETtqSGrQ/uMAOJ112t+37KxlXP6p2KMCD6/1FS0SJCb//3a9lKXEyZm2ceB/oAUhj1d5Q61+nokqOQrmv92XoBngRar7Grb8KPV9pKUgBua4MkUhamcaDLhYp+fiGivvXxLDh6b6hOGfeVllmckLFqTs9Edub8j0dIt78Hx3gWTuS5c0y4MWTleht3wsjsbL+Wq9GmlH8PWT7OeyeD6daMvJOL9ttiNAjdcGl6lQaX7UBhDsiL3L98uG1A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.freedesktop.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=U8DFTg8a+4P04vq/9rK+hmRr18MWi4bFGz9J8dVxQmY=; b=Xyut0rhUMpaVuBy4cBDK1zt+oDqmp4OY0p8nVdkvpr0zuB3RHXSquEIN4AqSGf6KPoD11vJ7SriGut7wszv8XkA+xEBpla90y8iV4roXl+3mhDcBEDy6RoxcTqstqps2DA70p4XPNH/vgBlPa4JeINagDGjJgPjgmpWFiQZiPRU= Received: from DS7PR05CA0058.namprd05.prod.outlook.com (2603:10b6:8:2f::11) by MN0PR12MB5859.namprd12.prod.outlook.com (2603:10b6:208:37a::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.6; Thu, 3 Dec 2026 14:53:47 +0000 Received: from DS8PEPF000000E2.namprd05.prod.outlook.com (2603:10b6:8:2f:cafe::10) by DS7PR05CA0058.outlook.office365.com (2603:10b6:8:2f::11) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.709.5 via Frontend Transport; Thu, 3 Dec 2026 14:53:46 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by DS8PEPF000000E2.mail.protection.outlook.com (10.167.23.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.709.6 via Frontend Transport; Thu, 3 Dec 2026 14:53:46 +0000 Received: from siweihe2-Desktop.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Thu, 3 Dec 2026 08:53:45 -0600 From: Siwei He To: CC: , Subject: [PATCH] drm/amdgpu: add AMDGPU_INFO_CU_BITMAP query for per-XCC CU masks Date: Thu, 3 Dec 2026 09:53:32 -0500 Message-ID: <20261203145332.802558-1-siwei.he@amd.com> X-Mailer: git-send-email 2.43.0 X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS8PEPF000000E2:EE_|MN0PR12MB5859:EE_ X-MS-Office365-Filtering-Correlation-Id: b51ddaf7-5e98-4c29-9a5d-08df514d3ba5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|36860700016|23010399003|1800799024|82310400026|261026121527099003|261022105027099003|10067099003|11063799006|261009223027099003|261021121427099003|56012099006|261026140227099003|261028144727099003|261102123227099003|18002099003|13003099007; X-Microsoft-Antispam-Message-Info: 23JSdz2X5YpNIdJMVZC/JbgR0J/AmdqFOEKNbO5AeIh9RqZy86Ttiydfet7quFWjbC0Pxj+WDtON/jQ/jVzZWmhEIS1A8lIxk+ox+dtFm9MSfglk8tp8kaNmgJSoapBAl6hL8IHwA2K0QDcjwta5saVYELNnGcBmrXewRO1N4AFXbehLDprArYEXIl16uIoCbT6yBH41p+DEaSzyojSBkqj4mPqEP74GVDDwtmwJxwtLcxQ+HTio7+QUm9QI+pfG/mv+uxKYIPNfDH20nVSjNV+QoXAOEkm3u89nIZMCCtkLY+8ADPYae3cbtD72GlrmkzBXUOT3QRphDxnQfN2ZB0MnFzhnjvrrygswNX/ki+394R5rlwMkOYzw70Zprcyd8+wJO8qxY4jJN9APBV82bBbG3dACuIKWCBylXO0du56lHQYlHrpC6ylBh8jlgCp+j9ZK578ucN5vyEYraeYnG4pO4i0Qfnde1slUtAF8AW+u9Cxa3abDGDokwUJ+BqLVioG8GALj5xN+7vBt1uAppyvdi6g7WVxft3DQpdgeoUlGV3v69uWVDx640YDTMrkm1cjoXV7hlX3VcSQKFyYWwbWOjHCh73vpy6W2CBhzfVS8NDnTyQPlXedSvileByU3nBiK/p5HVs+qkdOrvByefqd/seFelHen9QHknHcwThCL7n4LcNKSTQNJfZQOeUNLWsi5hQ1Z1O+9mV0S6Ml8YA== X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:satlexmb07.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(376014)(36860700016)(23010399003)(1800799024)(82310400026)(261026121527099003)(261022105027099003)(10067099003)(11063799006)(261009223027099003)(261021121427099003)(56012099006)(261026140227099003)(261028144727099003)(261102123227099003)(18002099003)(13003099007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: FBgrxnXrBpDu3DkVJYcUFUNd/AaZImLS+KKUnmVY3K8RsdFtjwiY92IWQmZAu4XPTp46VVTnSdITnyRH/1Lxu6k8ISup/EIw8mwafcOknr3u9E7ocBjarauNDjxZ4VuBMkHd3XJoqzyS9Ghgw/ypmIvlEqnF0F7EDuJc9jMLwjrpM4E+rkHK/eZscGUg8tdRy1oHC4U1FVarcO8XpnOKhE0wKqSy7tBI92t7sa6gu0W3afmOCyeCnXhvtCuOLCdcdQarxYcFbrJWcL2yLl9i1/cQqgWRtEQTyJ80y3BmFoOD0t1DB0UcurBN7puzOZKLR6a/X6mJf91JhYrynDUjeiUAeTLYVu/EPCEP3A4H6cyf8lBNYGxZuRQ9Bbk6FuPTi0KuxsZfUd5lzT6rFY6dV1fZ1vvmslY5YOFa2w2GSyojjiCxk+7DJkhQ0+j+3LER X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Dec 2026 14:53:46.4357 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b51ddaf7-5e98-4c29-9a5d-08df514d3ba5 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS8PEPF000000E2.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB5859 X-BeenThere: amd-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for AMD gfx List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "amd-gfx" X-Spam-Status: No, score=-23.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Add AMDGPU_INFO_CU_BITMAP, returning struct drm_amdgpu_info_cu_bitmap: a header carrying num_xcc, num_se, num_sa and xcc_mask, followed by a flexible array of num_xcc * num_se * num_sa active CU masks in un-folded [xcc][se][sa] order, indexed bitmap[(xcc * num_se + se) * num_sa + sa]. Userspace for this can be found at: https://github.com/ROCm/rocm-systems/pull/14570 Signed-off-by: Siwei He --- drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 75 +++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h | 2 + drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 51 +++++++++++++++++ include/uapi/drm/amdgpu_drm.h | 32 +++++++++++ 4 files changed, 160 insertions(+) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c index 0ae6e990c310..850de3be1659 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c @@ -2050,6 +2050,81 @@ static ssize_t amdgpu_gfx_get_gfx_reset_mask(struct device *dev, return amdgpu_show_reset_mask(buf, adev->gfx.gfx_supported_reset); } +/** + * amdgpu_gfx_get_cu_bitmap - un-fold the active CU bitmap for a set of XCCs + * + * @adev: amdgpu_device pointer + * @inst_mask: mask of logical GC (XCC) instances to report + * @out: destination, filled in [xcc][se][sa] row-major order + * @max_entries: capacity of @out, in u32 entries + * + * XCCs are written in ascending set-bit order of @inst_mask, densely packed, + * so entry (xcc * num_se + se) * num_sa + sa holds shader array @sa of + * shader engine @se on the @xcc'th set bit of @inst_mask. + * + * Returns the number of XCCs written, or a negative error code. + */ +int amdgpu_gfx_get_cu_bitmap(struct amdgpu_device *adev, u32 inst_mask, + u32 *out, u32 max_entries) +{ + struct amdgpu_gfx_config *config = &adev->gfx.config; + u32 gc_version = amdgpu_ip_version(adev, GC_HWIP, 0); + u32 num_se, num_sa, sh_mul, se, sa, n = 0; + int xcc; + + if (!inst_mask) + return -ENODEV; + + /* cu_info.bitmap[] only has AMDGPU_MAX_GC_INSTANCES slots */ + if (inst_mask & ~GENMASK(AMDGPU_MAX_GC_INSTANCES - 1, 0)) { + dev_warn_once(adev->dev, + "CU bitmap: %u XCCs exceeds %u slots\n", + hweight32(inst_mask), AMDGPU_MAX_GC_INSTANCES); + return -EOPNOTSUPP; + } + + num_se = config->max_shader_engines; + num_sa = config->max_sh_per_se; + if (!num_se || !num_sa) + return -ENODEV; + + if (hweight32(inst_mask) * num_se * num_sa > max_entries) + return -EINVAL; + + /* gfx11/gfx12_0 fold SE4-7 into shader array columns 2 and 3 */ + sh_mul = (gc_version >= IP_VERSION(11, 0, 0) && + gc_version < IP_VERSION(13, 0, 0)) ? 2 : 1; + + /* + * cu_info.bitmap[] stores a [4][4] tile per XCC, and the IP backend + * packed (se, sa) into it with the fold above. The row index se % 4 is + * in range by construction; the column must both stay inside the tile + * and not alias another shader engine's slot. Shader engines 4 apart + * share a row and are separated by sh_mul columns, so num_sa > sh_mul + * overlaps them. A topology failing either test lost data when the + * backend wrote the tile, and un-folding cannot recover it -- fail + * rather than report some other slot's mask as this shader array's. + */ + if ((num_se > 4 && num_sa > sh_mul) || + (num_sa - 1) + ((num_se - 1) / 4) * sh_mul > 3) { + dev_warn_once(adev->dev, + "unsupported CU bitmap topology %u SE x %u SA\n", + num_se, num_sa); + return -EOPNOTSUPP; + } + + for_each_inst(xcc, inst_mask) { + for (se = 0; se < num_se; se++) + for (sa = 0; sa < num_sa; sa++) + out[(n * num_se + se) * num_sa + sa] = + adev->gfx.cu_info.bitmap[xcc] + [se % 4][sa + (se / 4) * sh_mul]; + n++; + } + + return n; +} + static ssize_t amdgpu_gfx_get_compute_reset_mask(struct device *dev, struct device_attribute *attr, char *buf) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h index 5939e1fb3b24..bd2617dd4c56 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h @@ -663,6 +663,8 @@ int amdgpu_gfx_poison_consumption_handler(struct amdgpu_device *adev, bool amdgpu_gfx_is_master_xcc(struct amdgpu_device *adev, int xcc_id); int amdgpu_gfx_sysfs_init(struct amdgpu_device *adev); void amdgpu_gfx_sysfs_fini(struct amdgpu_device *adev); +int amdgpu_gfx_get_cu_bitmap(struct amdgpu_device *adev, u32 inst_mask, + u32 *out, u32 max_entries); int amdgpu_gfx_reset_mes_compute(struct amdgpu_device *adev, struct amdgpu_ring *ring, struct amdgpu_fence *guilty_fence, diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c index 14a72a406d37..50943ec18b27 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c @@ -1453,6 +1453,57 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) return -EINVAL; } } + case AMDGPU_INFO_CU_BITMAP: { + struct drm_amdgpu_info_cu_bitmap *cu_bitmap; + u32 num_xcc, num_se, num_sa, nent; + size_t sz; + + fpriv = (struct amdgpu_fpriv *)filp->driver_priv; + + /* scope the reply to the partition this fd was opened against */ + if (adev->xcp_mgr && adev->xcp_mgr->num_xcps > 0 && + fpriv->xcp_id < adev->xcp_mgr->num_xcps) { + xcp = &adev->xcp_mgr->xcp[fpriv->xcp_id]; + ret = amdgpu_xcp_get_inst_details(xcp, AMDGPU_XCP_GFX, + &inst_mask); + if (ret) + return ret; + } else { + /* inst_mask is a logical mask */ + inst_mask = adev->gfx.xcc_mask ? + GENMASK(NUM_XCC(adev->gfx.xcc_mask) - 1, 0) : 1; + } + + num_xcc = hweight32(inst_mask); + num_se = adev->gfx.config.max_shader_engines; + num_sa = adev->gfx.config.max_sh_per_se; + if (!num_xcc || !num_se || !num_sa) + return -ENODEV; + + nent = num_xcc * num_se * num_sa; + sz = struct_size(cu_bitmap, bitmap, nent); + + cu_bitmap = kzalloc(sz, GFP_KERNEL); + if (!cu_bitmap) + return -ENOMEM; + + ret = amdgpu_gfx_get_cu_bitmap(adev, inst_mask, + cu_bitmap->bitmap, nent); + if (ret < 0) { + kfree(cu_bitmap); + return ret; + } + + cu_bitmap->num_xcc = ret; + cu_bitmap->num_se = num_se; + cu_bitmap->num_sa = num_sa; + cu_bitmap->xcc_mask = inst_mask; + + ret = copy_to_user(out, cu_bitmap, min_t(size_t, size, sz)) ? + -EFAULT : 0; + kfree(cu_bitmap); + return ret; + } default: DRM_DEBUG_KMS("Invalid request %d\n", info->query); return -EINVAL; diff --git a/include/uapi/drm/amdgpu_drm.h b/include/uapi/drm/amdgpu_drm.h index 29009f6aabde..b726dc511491 100644 --- a/include/uapi/drm/amdgpu_drm.h +++ b/include/uapi/drm/amdgpu_drm.h @@ -1289,6 +1289,8 @@ struct drm_amdgpu_cs_chunk_cp_gfx_shadow { #define AMDGPU_INFO_GPUVM_FAULT 0x23 /* query FW object size and alignment */ #define AMDGPU_INFO_UQ_FW_AREAS 0x24 +/* query the full per-XCC active CU bitmap */ +#define AMDGPU_INFO_CU_BITMAP 0x25 #define AMDGPU_INFO_MMR_SE_INDEX_SHIFT 0 #define AMDGPU_INFO_MMR_SE_INDEX_MASK 0xff @@ -1363,6 +1365,36 @@ struct drm_amdgpu_info { }; }; +/* + * Reply to AMDGPU_INFO_CU_BITMAP. + * + * Reports every XCC visible to the file descriptor in + * un-folded [xcc][se][sa] order. + * + * On a partitioned device the reply covers only the XCCs belonging to the + * partition the file descriptor was opened against. + * + * The reply is variable length and carries no fixed topology limits. Query it + * twice: first with return_size = sizeof(struct drm_amdgpu_info_cu_bitmap) to + * read the counts, then with return_size large enough for the trailing array. + */ +struct drm_amdgpu_info_cu_bitmap { + /** number of XCC slices described by bitmap[] */ + __u32 num_xcc; + /** number of shader engines per XCC */ + __u32 num_se; + /** number of shader arrays per shader engine */ + __u32 num_sa; + /** mask of logical XCC instances this reply describes */ + __u32 xcc_mask; + /** + * active CU mask per shader array, num_xcc * num_se * num_sa entries + * in [xcc][se][sa] row-major order. Index as + * bitmap[(xcc * num_se + se) * num_sa + sa]. + */ + __u32 bitmap[]; +}; + struct drm_amdgpu_info_gds { /** GDS GFX partition size */ __u32 gds_gfx_partition_size; -- 2.43.0