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 316DD606A32A for ; Wed, 2 Dec 2026 14:22:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=e6XdU0sf Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EF66510E56F; Wed, 2 Dec 2026 14:22:38 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) by gabe.freedesktop.org (Postfix) with ESMTPS id 319F810EA1C for ; Wed, 2 Dec 2026 14:22:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796221353; x=1827757353; h=date:from:to:cc:subject:message-id:references: in-reply-to:mime-version; bh=jwGO/09WSVQKX5Xzru1CdgS//CEPr5Qa+W+FW4EEhHo=; b=e6XdU0sfoSOX+PVmrI0MHNkJniAGKd5a3nL5R2vYkMYPUl6l1xqdo6kj MQ44YRiMQBIUFXonh8PKR5vxeGHh+3DBSpH/YyvO7Stkl48mUMWmHjqh5 tHmuV0W2NJEtwcTbNNlRaUk9H++ScjK2qLVa0kdGKKue4SqvIFg+j9UVl 4aBxS5NKAr4JUAEEJ8SbxKDSYH/O0ggxptCGhGEii+xVOeI/W2rhWyefY 6Hxw8jsKiVpR7BUe2oWmJg03kOwr7sEkA/0HDLuutzwmWxhtw/wIUtnS8 o0xv9b5DKiVbVRgnGcmJ3vl14cUlo/6U6MJeb40GDUeuOdAtgWux9T2ZV g==; X-CSE-ConnectionGUID: jjhmsYiAQqC2+ltovTXVuA== X-CSE-MsgGUID: bcjnOoe+RB6x9lM4wrwvmA== X-IronPort-AV: E=McAfee;i="6800,10657,11984"; a="5054198" X-IronPort-AV: E=Sophos;i="6.27,246,1787036400"; d="scan'208";a="5054198" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2026 06:22:33 -0800 X-CSE-ConnectionGUID: sp9IOEvPSBubH40ZV/+qPw== X-CSE-MsgGUID: gTsB7lhZTOyY1jxJuLokVA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,246,1787036400"; d="scan'208";a="13327855" Received: from fmsmsx901.amr.corp.intel.com ([10.18.126.90]) by orviesa008.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2026 06:22:32 -0800 Received: from FMSMSX903.amr.corp.intel.com (10.18.126.92) by fmsmsx901.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Wed, 2 Dec 2026 06:22:32 -0800 Received: from fmsedg901.ED.cps.intel.com (10.1.192.143) by FMSMSX903.amr.corp.intel.com (10.18.126.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57 via Frontend Transport; Wed, 2 Dec 2026 06:22:32 -0800 Received: from DM1PR04CU001.outbound.protection.outlook.com (52.101.61.23) by edgegateway.intel.com (192.55.55.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Wed, 2 Dec 2026 06:22:31 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=pxvZVkRBKuwQWY1M9mMGKXepReczpWECSm2q1qKusUq6ApWz5BG2/iC9kTok5Z5oIekJoqcCJ/wOm1C6/KrcQAlqOfy1HFzIPQ6GI0STD4MURVR2qeLaDCvzfIPCDZbv167QXjZJmmHqu2OtkOHxVFSbNP0So5C/hxf8CQkSQEqnh0J5AbyhDxGZuIMn9L1+Arx+nStvzWI68RmPaIhiyybrseXonr1FIAxYGyLNPEfAflx0rZyDFrybCsvsuScu0cNkV0U5cyHDeAU4QvXwYwf1y2/OXHzQS3i9OZl3sngzbAx54+rELripljDkUT3x0qRT8n2/EZThR2ezEsH82g== 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=jwGO/09WSVQKX5Xzru1CdgS//CEPr5Qa+W+FW4EEhHo=; b=NKYCWU0IkRFwf/RzNwTRQ9dmQw4FZYZCDv0VZVGE2gGXv0Lm9JDjvm5LJXZn8OeIt7q4l5WTbBbkODP8fzTEnRu6zJ/2M5RiBRvrNvuEmsJKocaCT0oXek58mix/FYhpDUa9UubjxBdsDa09hg+U2L5syG1lqdcLJ7SCzxzeLxUL0X4xQtZSbFSziilZNKfskq4fk4ShIOTj/yixsy9P7w7U88RfugURiePCuKGw4ZgTYHd4iLW5M1sPpj2gJCE1gXxrUT4NpuQvtU8xzSqh3YcpJhXN10P23zAHhzL1TtRNQkPctvHxk/938nwEqPuPkfRfK0Mr+M4dDLw7XpUkJw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from DS7PR11MB5990.namprd11.prod.outlook.com (2603:10b6:8:71::5) by PH7PR11MB6979.namprd11.prod.outlook.com (2603:10b6:510:207::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.7; Wed, 2 Dec 2026 14:22:28 +0000 Received: from DS7PR11MB5990.namprd11.prod.outlook.com ([fe80::133c:5eed:3aec:b899]) by DS7PR11MB5990.namprd11.prod.outlook.com ([fe80::133c:5eed:3aec:b899%3]) with mapi id 15.21.0688.009; Wed, 2 Dec 2026 14:22:28 +0000 Date: Wed, 2 Dec 2026 09:22:24 -0500 From: Rodrigo Vivi To: Karthik Poosa CC: , , , , , , , , Subject: Re: [PATCH v7 04/10] drm/xe/hwmon: Expose pwm[1-3] Message-ID: References: <20261202125637.1581881-1-karthik.poosa@intel.com> <20261202125637.1581881-5-karthik.poosa@intel.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261202125637.1581881-5-karthik.poosa@intel.com> X-ClientProxiedBy: BY1P220CA0011.NAMP220.PROD.OUTLOOK.COM (2603:10b6:a03:59d::11) To DS7PR11MB5990.namprd11.prod.outlook.com (2603:10b6:8:71::5) X-Archived-By: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR11MB5990:EE_|PH7PR11MB6979:EE_ X-MS-Office365-Filtering-Correlation-Id: faa05af4-d721-45e9-ae15-08df507fb1bb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|23010399003|376014|366016|1800799024|4143699003|18002099003|261009223027099003|6133799003|22082099003|261022105027099003|11063799006|10067099003|56012099006|261022113327099003|261022115727099003|261102123227099003|261021130227099003|261026135527099003|261021133027099003|261021121427099003|261026140227099003|261021135927099003|261021123027099003|261026130827099003|261026121527099003|261022075727099003|261028144727099003; X-Microsoft-Antispam-Message-Info: go6nr5qdXX0xb2C3FPb/XUxuO39orWEFp0CwAWXhGNUEdQoyAvZnuWXDtH86JMVvCicYxb+0U0YifG8IbxG/8qMVTp/GG1MhtsSR3B175Q4URUHZf8t0qm967wcSDGnecZ//ymU+wonKsfThKTT69T61uWEuax1fhUTjNgIhlhx/N+x3ovEsY9zzgRHn2FQE6qDakQvLUT7no4j4NBJSSpO0zROPpkPSW8//zcH02xvN4jeT3zmxfRs84bX6X/yf0OFkVgsjvQdTYwyh907Flq6r5flYgpjHJykPjGZSScp/yctgIMW6YfSTZRF5bZQzu8Dp+2pS5Je2j7uqeZGU4EJUuKgq/95W7eylSYHgBx4lPJ92/f6okLn2kvNnqeqsIBn4+EB3YG1272mhc06vGZiaUE512FfBFFB5IGKtH1EjGwZXlUdFTfrhUx5L4XGdX5al0HXAkSdgTXzNoDqr/9P5SAQZ4T7t10cTpYJWDERLLAEsOU90Of4DwRxtCMQv8FLyOJz6qf5ESvOXF/8OFwstXOeQqpmPxTwXpPEVJIs4SgeN7HEanrw4AuzcWi8QyyfvhntBRgqlvXVEBjZPrg+wMKDJ+PZ5tUMimJLVUceTF6Q2p8UA2G+yGleRW69a43Z6HXiwaf3V9oIqDdTBpzYRceQdYO/Yo2iyBL6LU/I= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DS7PR11MB5990.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(23010399003)(376014)(366016)(1800799024)(4143699003)(18002099003)(261009223027099003)(6133799003)(22082099003)(261022105027099003)(11063799006)(10067099003)(56012099006)(261022113327099003)(261022115727099003)(261102123227099003)(261021130227099003)(261026135527099003)(261021133027099003)(261021121427099003)(261026140227099003)(261021135927099003)(261021123027099003)(261026130827099003)(261026121527099003)(261022075727099003)(261028144727099003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?tkwI974vPfsLgiaxUPGNu+HDdoZOuDSzdKgV2Qa2rTcaE0ypHGtzVg0YvRLE?= =?us-ascii?Q?TD+6klAdXmVSjPhLYKwKsw17j8nfDa5bBNeT2SLQA1Eysi86ly9cl909nREX?= =?us-ascii?Q?X+VYd2Wrr1yRtzRJ7CY3ZpIY37PdznOpp7ntWbHl6D1S7IdhR1wSrX4dEZFU?= =?us-ascii?Q?0/kXQw4atV7s0gIRgpaoSEjl4gKW5AudOkXMH4EjgSehyormDyQ5uyTgnrXi?= =?us-ascii?Q?VGUKgZFgV6EELX3+oTGWbQeaoik+5E/4dg/VfuCEc8b3XJD/9fxhBcCmT9Rx?= =?us-ascii?Q?q2RjADf12Mv1Z7pe1mwkoTiZVBfMpH4hvmprgjGrmcdwEKQhwd/JG1/aAgfa?= =?us-ascii?Q?6nsNzg930Nq4vtIm5szpLhXsjoLGQBSCalQZK8fcabJ6WsHFUbgUkyIfJ0+Z?= =?us-ascii?Q?rEWPCn9v8TS5TfFkElgLZop0KjYCbCjIlduwfBtb4E2h8gOdkWquUxTKDb4d?= =?us-ascii?Q?Lbidh8XICbbzSdiZ5BDF8+oGNb15ej/WexxrJDv846CSEL/N2F7JBc2C2BgO?= =?us-ascii?Q?L7RrqPzVfB7DM+woNAWbZc+ulfTakXpjPJm7LeXgqgVvgYGocaXYEbR26CH5?= =?us-ascii?Q?vL6O9w3W1ZcEiRIe1exQ59ydQF8mGN1uyuoinWCifIj3LNL6A7hx+wtodMC0?= =?us-ascii?Q?ssXlOYt265V9QBSd+Dskf49iq6ON+U9TMbKignTNzSZpYU/n7AZLhHgEc5G0?= =?us-ascii?Q?NvIZOaEMnThRU0C17OWkxNP2qM6hLd0RrAEzbWaRsUqsceAcopsjK4CX2lQ7?= =?us-ascii?Q?CFpHdoAkLjKjzB7LRcSN3EsLAn878BUWdKIY3haZpyUcdWOjYsaBAewBlKJm?= =?us-ascii?Q?qjNdyemTvvhQuAYpry9FVot2vnPgsb0H+/tX3zYNzMU8IlD0ZFk1ApUhrHjq?= =?us-ascii?Q?ZG0k3V4AUzPZiAQn/Js5gpjolyYcABTVSpqkaWLlxWAkGgTuF76EhH50w8V1?= =?us-ascii?Q?gROPT44x3dVbZldKFzf5ojkRcIZdLqHo4Sx88NpxUB1hGdAaaf/M15+/875l?= =?us-ascii?Q?V520sdXbMbJ8OspjxHaBlbufrFgYgpa9Kdc6t7ndYsra1vVQ6DorcmlOTt6p?= =?us-ascii?Q?yFQS4gFtQ8Tm9TeRie6EoFWSGWQ/ObyuHS/KofJd7hyYZ2lBEnaOqsd533iH?= =?us-ascii?Q?2XVs62BC4qNI635MIkD0xDskMeRlGcbMfwAfGcu2ZwjOtXMYZAiX+K7yKM1h?= =?us-ascii?Q?qvM5bz86yY/EzkKDzFwLjjW6mOHwRv6Cr/grYOhFpsGg3tlXkBZIMsiXpLcE?= =?us-ascii?Q?zDJmmp9O/YUffIAyNTHtWIRA4CIeMyr9DUu/8MQZvdJCv5jhKPzwF2KfXrmr?= =?us-ascii?Q?7wyg8qpDuqIZfDVANnJILocSpdsJdby5KSTAtFTTRg8D/LK6FnRxIFqyXSS/?= =?us-ascii?Q?FBE9p+XSLInDo6DxXu6f+9wVTdyUd1RR3VXndWUpzDvTAblXtSHZzrN92fbB?= =?us-ascii?Q?mYIi+KajepV4rXzQtOvA2MWIasi4KznLnknp1vv++5CU2oUZyQclpN2o99m2?= =?us-ascii?Q?hvmJZMYulQVJeAeJSqtXnq1wi8qScbFjCTRjtwg8+yailaU5mRDVlTAJVumh?= =?us-ascii?Q?gcS+WqzZbdyGdQLxNDsga1MVWAW3rqGhEko05n9tBAtvNwWGUFf/PmHOm4kj?= =?us-ascii?Q?maGNCbjmdxAt4GGk7y52DxsZ3NQlZCLQiKzax2lanc16n97tunCUh6ILRU66?= =?us-ascii?Q?HkLT/kS8MIyjEXc+ivMPlQ46YKBFAHDRAYm/gmrwZB3vtZXgUTjGWB6bL2Sm?= =?us-ascii?Q?PQB1R7x1nA=3D=3D?= X-Exchange-RoutingPolicyChecked: otR1s1pED+hZBOl7PbR4ghJWw9uTAWm98L1o59VNx83nzxrMjffNeVpo7kQzil0y0LO4ZowcooxSZ63Q4M6GRWIlSNwQPV8FQJ37anXlmpz1eXHY/HXl3tDo+1R1dk53u8fugfHbX1NZ7lmmn2hzqWzBh3W3YinbSTiW6TF5/ikIUCK9/kkQtFtYC6Ef/cLx6zVXFypdnwE7xU39xgzHI1GM2wkKPq7Z09buWbjkRA0rk7Wqnq8xBe/dE6z+auitnOJJZ3DYUqIfL/85c9FPMa10rCsK8UJw3dr+YBO2ZJzc5rQ6FnB5QTC9wSVkk1ie7esPsOLu2KPoKYzHS97PYA== X-MS-Exchange-CrossTenant-Network-Message-Id: faa05af4-d721-45e9-ae15-08df507fb1bb X-MS-Exchange-CrossTenant-AuthSource: DS7PR11MB5990.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2026 14:22:28.5816 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: iqzLwmbcI+ZNWsVlF5qddSHekBPx6yekz1NlLWXFZ0jBs97AjZ6OLT8XbmAs0UU4w0x9SbDwG7TKFNiXJuLseg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR11MB6979 X-OriginatorOrg: intel.com X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Intel-xe" X-Spam-Status: No, score=-15.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,SPF_HELO_NONE, SPF_PASS 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 On Wed, Dec 02, 2026 at 06:26:31PM +0530, Karthik Poosa wrote: > Expose pwm[1-3] hwmon attributes for each available fan. Userspace can > read PWM values in the range 0..255 and set a manual fan speed > independently of the fan curve. Switching back to the stock curve is > added by a later patch. > > Read active PWM from PMT on BMG. On other platforms, derive PWM from the > stock curve when no user table is active. > > After writing the user table, read back its point count to verify > firmware accepted it. If verification fails, restore stock fan control. > > Document pwm[1-3] in the Xe hwmon ABI. > > Signed-off-by: Karthik Poosa Reviewed-by: Rodrigo Vivi > --- > > v2: > - Use xe helpers for dmesg logs. > - Avoid using hwmon->num_fans to get fan count in > xe_hwmon_pwm_is_visible(). > > v3: > - Set PWM directly through the user table; avoid initializing it from the > stock table. (Soham) > - Move the unused xe_hwmon_activate_user_fan_table() to the subsequent > patch. > - Fail pwmN reads when no value has been written, rather than activating > the user table from the stock table. > - Define MIN_FAN_CONTROL_POINTS as 2. > - Use MIN_FAN_CONTROL_POINTS for PWM configuration. (Soham) > - Use batched writes for configuring fan control points when setting pwmN. > - Add and rephrase couple debug logs. > - Update the hwmon documentation. > > v4: > - Use tab indentation in ABI doc and MIN_FAN_CONTROL_POINTS. (Soham) > - Drop unused linux/delay.h include. (Soham) > - Clamp min PWM to 100% since fan table speed is in percent. (Soham) > - Log both the requested pwm and the applied percentage. (Soham) > - Fail the pwm write if pcode reports a user point count other than > MIN_FAN_CONTROL_POINTS after the write. (Soham) > - Drop redundant channel range checks in pwm read/write. (Soham) > - Fix misleading comments and debug log alignment. (Soham) > - Note that the 0..255 to percent round trip is lossy. (Soham) > - Update ABI Date and KernelVersion to November 2026 and 7.5. > - Document that pwm values below the fan minimum are raised to it. > - Return -ENODATA and log at debug level when pwm has not been set. > - Invalidate the cached user table when the pwm write or verify fails. > - Clear point count on pcode read failure. > - Drop unneeded parentheses in MIN_FAN_CONTROL_POINTS and FIXED_PWM_TEMP. > - Document pcode user table write ordering. > > v5: > - Expose pwm[1-3] node only if stock table is valid. > - Read current pwm from PMT for BMG and from stock table for other > platforms when user table is not active. > - Read back the user point count after every PWM table write and fall > back to stock table when the count is not accepted. > > v6: > - Add couple of warnings. (Soham) > > v7: > - Move user fan-table batch construction and verification into > new function xe_hwmon_commit_user_fan_table(). (Badal) > - Keep xe_hwmon_set_user_fan_pwm() responsible for preparing the > fixed two-point curve and updating the cached user table. (Badal) > - Log an out-of-range PWM read at debug level, as pollers reading pwmN > after resume flood dmesg. (Rodrigo) > - Drop Soham Reviewed-by as refactor occurred. > - Make pwm node visible only if stock points > MIN_FAN_CONTROL_POINTS. > > .../ABI/testing/sysfs-driver-intel-xe-hwmon | 9 + > drivers/gpu/drm/xe/regs/xe_pmt.h | 5 + > drivers/gpu/drm/xe/xe_hwmon.c | 362 ++++++++++++++++++ > drivers/gpu/drm/xe/xe_pcode_api.h | 3 + > 4 files changed, 379 insertions(+) > > diff --git a/Documentation/ABI/testing/sysfs-driver-intel-xe-hwmon b/Documentation/ABI/testing/sysfs-driver-intel-xe-hwmon > index ac9ccfd47eab..34c50f13f0b4 100644 > --- a/Documentation/ABI/testing/sysfs-driver-intel-xe-hwmon > +++ b/Documentation/ABI/testing/sysfs-driver-intel-xe-hwmon > @@ -346,3 +346,12 @@ Description: RW. Package burst power limit interval (Tau in PL2/Tau) in > milliseconds over which sustained power is averaged. > > Only supported for particular Intel Xe graphics platforms. > + > +What: /sys/bus/pci/drivers/xe/.../hwmon/hwmon/pwm[1-3] > +Date: December 2026 > +KernelVersion: 7.5 > +Contact: intel-xe@lists.freedesktop.org > +Description: RW. Target fan PWM duty value in the range 0..255, where 255 > + is 100% fan speed. > + > + Only supported for particular Intel Xe graphics platforms. > diff --git a/drivers/gpu/drm/xe/regs/xe_pmt.h b/drivers/gpu/drm/xe/regs/xe_pmt.h > index fb5b5a8648ba..4fec057b2dd6 100644 > --- a/drivers/gpu/drm/xe/regs/xe_pmt.h > +++ b/drivers/gpu/drm/xe/regs/xe_pmt.h > @@ -15,6 +15,11 @@ > #define ENERGY_PKG REG_GENMASK64(31, 0) > #define ENERGY_CARD REG_GENMASK64(63, 32) > > +#define BMG_FAN_PWM_PMT_OFFSET (0x58) > +#define BMG_FAN1_PWM REG_GENMASK64(15, 0) > +#define BMG_FAN2_PWM REG_GENMASK64(31, 16) > +#define BMG_FAN3_PWM REG_GENMASK64(47, 32) > + > #define PUNIT_VERSION_OFFSET 0xA0 > > #define XE_PMT_BASE_OFFSET 0xE0000 > diff --git a/drivers/gpu/drm/xe/xe_hwmon.c b/drivers/gpu/drm/xe/xe_hwmon.c > index fdc846d84e3d..dd6f1f97fbf7 100644 > --- a/drivers/gpu/drm/xe/xe_hwmon.c > +++ b/drivers/gpu/drm/xe/xe_hwmon.c > @@ -157,6 +157,9 @@ enum fan_table_type { > /* Maximum number of fan control points supported by each fan. */ > #define MAX_FAN_CONTROL_POINTS 10 > > +/* Minimum number of points required for a user fan table. */ > +#define MIN_FAN_CONTROL_POINTS 2 > + > /* Fan control point index: bit31 selects fan table type; bits30:0 control point index. */ > #define FCP_INDEX(table_type, point_num) (((u32)(table_type) << 31) | \ > ((u32)(point_num) & GENMASK(30, 0))) > @@ -923,6 +926,7 @@ static const struct hwmon_channel_info * const hwmon_info[] = { > HWMON_CHANNEL_INFO(energy, HWMON_E_INPUT | HWMON_E_LABEL, HWMON_E_INPUT | HWMON_E_LABEL), > HWMON_CHANNEL_INFO(fan, HWMON_F_INPUT | HWMON_F_MAX, HWMON_F_INPUT | HWMON_F_MAX, > HWMON_F_INPUT | HWMON_F_MAX), > + HWMON_CHANNEL_INFO(pwm, HWMON_PWM_INPUT, HWMON_PWM_INPUT, HWMON_PWM_INPUT), > NULL > }; > > @@ -1166,6 +1170,162 @@ static int xe_hwmon_get_fan_enable_mask(struct xe_hwmon *hwmon) > return 0; > } > > +static int xe_hwmon_get_fan_point_count(struct xe_hwmon *hwmon, u8 fan, u32 *point_count, > + enum fan_table_type table_type) > +{ > + int ret; > + > + *point_count = 0; > + ret = xe_hwmon_pcode_read_fan_control(hwmon, > + (table_type == USER_FAN_TABLE) ? > + FSC_READ_USER_FAN_CONTROL_POINTS : > + FSC_READ_STOCK_FAN_CONTROL_POINTS, > + fan, point_count); > + if (ret) { > + *point_count = 0; > + xe_err(hwmon->xe, "failed to read fan %d %s point count, ret=%d\n", fan, > + (table_type == USER_FAN_TABLE) ? "user" : "stock", ret); > + return ret; > + } > + > + if (*point_count > MAX_FAN_CONTROL_POINTS) { > + xe_err(hwmon->xe, "fan %d %s point count %u exceeds max %u\n", fan, > + (table_type == USER_FAN_TABLE) ? "user" : "stock", *point_count, > + MAX_FAN_CONTROL_POINTS); > + return -EINVAL; > + } > + > + return 0; > +} > + > +/* > + * Set the fan to automatic mode by clearing the user fan table. > + * This will make the firmware run the stock fan table. > + */ > +static int xe_hwmon_fan_set_auto(struct xe_hwmon *hwmon, u8 fan) > +{ > + struct xe_hwmon_fan_info *fi = &hwmon->fi[fan]; > + int ret; > + > + ret = xe_pcode_write(xe_device_get_root_tile(hwmon->xe), > + PCODE_MBOX(FAN_SPEED_CONTROL, FSC_WRITE_NUM_FAN_CONTROL_POINTS, fan), > + 0); > + if (ret) > + return ret; > + > + fi->fan_table[USER_FAN_TABLE].point_count = 0; > + > + return 0; > +} > + > +static int xe_hwmon_commit_user_fan_table(struct xe_hwmon *hwmon, u8 fan, > + const struct fan_control_point *points, u32 point_count) > +{ > + /* The extra write is for the final write that sets the number of fan control points */ > + struct xe_pcode_write writes[MAX_FAN_CONTROL_POINTS + 1]; > + u32 accepted_count = 0; > + u32 point; > + int ret, write_ret, verify_ret; > + > + if (point_count < MIN_FAN_CONTROL_POINTS || > + point_count > MAX_FAN_CONTROL_POINTS) { > + xe_err(hwmon->xe, "fan %d table needs %d-%d points, got %u\n", fan, > + MIN_FAN_CONTROL_POINTS, MAX_FAN_CONTROL_POINTS, point_count); > + return -EINVAL; > + } > + > + for (point = 0; point < point_count; point++) { > + u8 temp = points[point].temp; > + u8 speed = points[point].speed; > + > + /* Firmware requires increasing temperature and non-decreasing speed. */ > + if (point > 0) { > + u8 prev_temp = points[point - 1].temp; > + u8 prev_speed = points[point - 1].speed; > + > + if (temp <= prev_temp || speed < prev_speed) { > + xe_dbg(hwmon->xe, > + "fan %d point %u not monotonic: %u/%u%% after %u/%u%%\n", > + fan, point, temp, speed, prev_temp, prev_speed); > + return -EINVAL; > + } > + } > + > + /* Prepare the write for this fan control point */ > + writes[point].mbox = PCODE_MBOX(FAN_SPEED_CONTROL, FSC_WRITE_FAN_TABLE, > + fan); > + writes[point].data = FIELD_PREP(FAN_CONTROL_POINT_TEMP_MASK, temp) | > + FIELD_PREP(FAN_CONTROL_POINT_SPEED_MASK, speed); > + } > + > + xe_dbg(hwmon->xe, "committing fan %d user table with %u points\n", fan, point_count); > + > + /* pcode fills the user table from point 0 in write order; the count write commits it. */ > + writes[point_count].mbox = PCODE_MBOX(FAN_SPEED_CONTROL, FSC_WRITE_NUM_FAN_CONTROL_POINTS, > + fan); > + writes[point_count].data = point_count; > + > + write_ret = xe_pcode_write_batch(xe_device_get_root_tile(hwmon->xe), writes, > + point_count + 1); > + if (write_ret) > + xe_err(hwmon->xe, "failed to write fan %d user table, ret=%d\n", fan, write_ret); > + > + verify_ret = xe_hwmon_get_fan_point_count(hwmon, fan, &accepted_count, USER_FAN_TABLE); > + if (write_ret || verify_ret || accepted_count != point_count) { > + int failure_ret = write_ret ?: verify_ret ?: -EIO; > + > + if (verify_ret || accepted_count != point_count) > + xe_err(hwmon->xe, > + "fan %d table count verification failed: ret=%d, expected=%u, got=%u\n", > + fan, verify_ret, point_count, accepted_count); > + /* Firmware may have accepted only part of the table; fall back to stock. */ > + ret = xe_hwmon_fan_set_auto(hwmon, fan); > + if (ret) > + xe_err(hwmon->xe, "failed to restore fan %d to stock mode, ret=%d\n", fan, > + ret); > + return failure_ret; > + } > + > + xe_dbg(hwmon->xe, "fan %d user table committed successfully with %u points\n", fan, > + point_count); > + return 0; > +} > + > +/* Temperature to set when setting the fan PWM with pwm[1-3]. */ > +#define FIXED_PWM_TEMP 1 > + > +static int xe_hwmon_set_user_fan_pwm(struct xe_hwmon *hwmon, u8 fan, u8 pwm) > +{ > + struct xe_hwmon_fan_info *fi = &hwmon->fi[fan]; > + struct fan_table *user_table = &fi->fan_table[USER_FAN_TABLE]; > + struct fan_control_point points[MIN_FAN_CONTROL_POINTS]; > + int ret, i; > + u8 speed; > + > + /* Fan table speed are in percent. */ > + speed = min_t(u32, DIV_ROUND_CLOSEST(pwm * 100, U8_MAX), 100); > + > + /* Fan control needs at least two points; program them all at the same speed. */ > + for (i = 0; i < MIN_FAN_CONTROL_POINTS; i++) { > + points[i].temp = FIXED_PWM_TEMP + i; > + points[i].speed = speed; > + } > + > + ret = xe_hwmon_commit_user_fan_table(hwmon, fan, points, MIN_FAN_CONTROL_POINTS); > + if (ret) { > + xe_err(hwmon->xe, "failed to set pwm %u (%u%%) for fan %d, ret=%d\n", > + pwm, speed, fan, ret); > + return ret; > + } > + > + /* Update the user fan table cache. */ > + memcpy(user_table->fcp, points, sizeof(points)); > + user_table->point_count = MIN_FAN_CONTROL_POINTS; > + xe_dbg(hwmon->xe, "applied pwm %u (%u%%) for fan %d\n", pwm, speed, fan); > + > + return 0; > +} > + > static int xe_hwmon_read_fan_control_info(struct xe_hwmon *hwmon) > { > bool found = false; > @@ -1795,6 +1955,22 @@ xe_hwmon_fan_is_visible(struct xe_hwmon *hwmon, u32 attr, int channel) > } > } > > +static umode_t > +xe_hwmon_pwm_is_visible(struct xe_hwmon *hwmon, u32 attr, int channel) > +{ > + /* Manual control starts from the stock table, so it needs a usable curve. */ > + if (!hwmon->xe->info.has_fan_control || !IS_FAN_ENABLED(hwmon, channel) || > + hwmon->fi[channel].fan_table[STOCK_FAN_TABLE].point_count < MIN_FAN_CONTROL_POINTS) > + return 0; > + > + switch (attr) { > + case hwmon_pwm_input: > + return 0644; > + default: > + return 0; > + } > +} > + > static int > xe_hwmon_fan_input_read(struct xe_hwmon *hwmon, int channel, long *val) > { > @@ -1848,6 +2024,185 @@ xe_hwmon_fan_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *val) > } > } > > +/** > + * xe_hwmon_get_stock_table_pwm - Calculate PWM from the stock fan curve > + * @hwmon: hwmon instance, with hwmon_lock held and runtime PM active > + * @channel: fan channel > + * @val: calculated PWM percentage > + * > + * Read package temperature and linearly interpolate the stock table. Temperatures > + * outside the table range use the speed at the nearest endpoint. > + * > + * Return: 0 on success, or a negative error code. > + */ > +static int xe_hwmon_get_stock_table_pwm(struct xe_hwmon *hwmon, int channel, long *val) > +{ > + const struct fan_table *table = &hwmon->fi[channel].fan_table[STOCK_FAN_TABLE]; > + long temperature, pwm; > + int point, ret; > + > + lockdep_assert_held(&hwmon->hwmon_lock); > + > + if (!table->point_count) > + return -ENODATA; > + > + ret = xe_hwmon_temp_read(hwmon, hwmon_temp_input, CHANNEL_PKG, &temperature); > + if (ret) > + return ret; > + > + pwm = table->fcp[0].speed; > + for (point = 1; point < table->point_count; point++) { > + const struct fan_control_point *lower = &table->fcp[point - 1]; > + const struct fan_control_point *upper = &table->fcp[point]; > + long lower_temp = lower->temp * MILLIDEGREE_PER_DEGREE; > + long upper_temp = upper->temp * MILLIDEGREE_PER_DEGREE; > + long pwm_delta = upper->speed - lower->speed; > + > + /* Find the bracketing points; temperatures outside the curve use endpoints. */ > + if (temperature <= lower_temp) > + break; > + if (temperature < upper_temp) { > + pwm += DIV_ROUND_CLOSEST(pwm_delta * (temperature - lower_temp), > + upper_temp - lower_temp); > + break; > + } > + pwm = upper->speed; > + } > + > + *val = pwm; > + xe_dbg(hwmon->xe, "fan %d stock table active PWM value: %ld\n", channel, pwm); > + return 0; > +} > + > +/** > + * xe_hwmon_get_pwm_from_pmt - Read active fan PWM from PMT telemetry > + * @hwmon: hwmon instance, with hwmon_lock held and runtime PM active > + * @channel: fan channel > + * @val: raw PWM percentage returned by PMT > + * > + * Return: 0 on success, or a negative error code. > + */ > +static int xe_hwmon_get_pwm_from_pmt(struct xe_hwmon *hwmon, int channel, long *val) > +{ > + u64 pmt_val; > + u32 guid, pwm; > + int ret; > + > + lockdep_assert_held(&hwmon->hwmon_lock); > + > + if (hwmon->xe->info.platform != XE_BATTLEMAGE) > + return -EOPNOTSUPP; > + > + ret = xe_vsec_get_guid(hwmon->xe, &guid); > + if (ret) { > + xe_warn(hwmon->xe, "failed to read pwm, PMT unavailable: %d\n", ret); > + return ret; > + } > + > + ret = xe_pmt_telem_read(hwmon->xe->drm.dev, guid, &pmt_val, > + BMG_FAN_PWM_PMT_OFFSET, sizeof(pmt_val)); > + if (ret != sizeof(pmt_val)) { > + xe_warn(hwmon->xe, "pwm read from PMT failed: %d\n", ret); > + return ret < 0 ? ret : -EIO; > + } > + > + switch (channel) { > + case FAN_1: > + pwm = REG_FIELD_GET64(BMG_FAN1_PWM, pmt_val); > + break; > + case FAN_2: > + pwm = REG_FIELD_GET64(BMG_FAN2_PWM, pmt_val); > + break; > + case FAN_3: > + pwm = REG_FIELD_GET64(BMG_FAN3_PWM, pmt_val); > + break; > + default: > + return -EOPNOTSUPP; > + } > + > + xe_dbg(hwmon->xe, "fan %d: active pwm from PMT: %u\n", channel, pwm); > + > + *val = pwm; > + return 0; > +} > + > +static int > +xe_hwmon_pwm_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *val) > +{ > + struct xe_hwmon_fan_info *fi; > + long pwm; > + int ret = 0; > + > + mutex_lock(&hwmon->hwmon_lock); > + > + fi = &hwmon->fi[channel]; > + > + switch (attr) { > + case hwmon_pwm_input: > + /* If the user fan table is not populated, get active stock pwm */ > + if (!fi->fan_table[USER_FAN_TABLE].point_count) { > + xe_dbg(hwmon->xe, "user fan table not active for fan %d\n", channel); > + switch (hwmon->xe->info.platform) { > + case XE_BATTLEMAGE: > + ret = xe_hwmon_get_pwm_from_pmt(hwmon, channel, &pwm); > + break; > + default: > + ret = xe_hwmon_get_stock_table_pwm(hwmon, channel, &pwm); > + break; > + } > + if (ret) > + goto unlock; > + } else { > + /* > + * pwmN writes set every user-table point to the same speed, > + * so the first point gives the cached manual PWM percentage. > + */ > + pwm = fi->fan_table[USER_FAN_TABLE].fcp[0].speed; > + } > + if (pwm < 0 || pwm > 100) { > + xe_dbg(hwmon->xe, "invalid PWM value %ld read for fan %d\n", pwm, channel); > + ret = -ERANGE; > + goto unlock; > + } > + /* Speed is cached in percent, so the 0..255 round trip may be off by a step. */ > + *val = DIV_ROUND_CLOSEST(pwm * U8_MAX, 100); > + xe_dbg(hwmon->xe, "pwm read for fan %d: %ld\n", channel, *val); > + break; > + default: > + ret = -EOPNOTSUPP; > + break; > + } > + > +unlock: > + mutex_unlock(&hwmon->hwmon_lock); > + return ret; > +} > + > +static int > +xe_hwmon_pwm_write(struct xe_hwmon *hwmon, u32 attr, int channel, long val) > +{ > + int ret = 0; > + > + mutex_lock(&hwmon->hwmon_lock); > + > + switch (attr) { > + case hwmon_pwm_input: > + if (val < 0 || val > U8_MAX) { > + xe_dbg(hwmon->xe, "pwm %ld out of range for fan %d\n", val, channel); > + ret = -EINVAL; > + break; > + } > + ret = xe_hwmon_set_user_fan_pwm(hwmon, channel, (u8)val); > + break; > + default: > + ret = -EOPNOTSUPP; > + break; > + } > + mutex_unlock(&hwmon->hwmon_lock); > + > + return ret; > +} > + > static umode_t > xe_hwmon_is_visible(const void *drvdata, enum hwmon_sensor_types type, > u32 attr, int channel) > @@ -1874,6 +2229,9 @@ xe_hwmon_is_visible(const void *drvdata, enum hwmon_sensor_types type, > case hwmon_fan: > ret = xe_hwmon_fan_is_visible(hwmon, attr, channel); > break; > + case hwmon_pwm: > + ret = xe_hwmon_pwm_is_visible(hwmon, attr, channel); > + break; > default: > ret = 0; > break; > @@ -1903,6 +2261,8 @@ xe_hwmon_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, > return xe_hwmon_energy_read(hwmon, attr, channel, val); > case hwmon_fan: > return xe_hwmon_fan_read(hwmon, attr, channel, val); > + case hwmon_pwm: > + return xe_hwmon_pwm_read(hwmon, attr, channel, val); > default: > return -EOPNOTSUPP; > } > @@ -1921,6 +2281,8 @@ xe_hwmon_write(struct device *dev, enum hwmon_sensor_types type, u32 attr, > return xe_hwmon_power_write(hwmon, attr, channel, val); > case hwmon_curr: > return xe_hwmon_curr_write(hwmon, attr, channel, val); > + case hwmon_pwm: > + return xe_hwmon_pwm_write(hwmon, attr, channel, val); > default: > return -EOPNOTSUPP; > } > diff --git a/drivers/gpu/drm/xe/xe_pcode_api.h b/drivers/gpu/drm/xe/xe_pcode_api.h > index 2308e5464082..bf321ed19251 100644 > --- a/drivers/gpu/drm/xe/xe_pcode_api.h > +++ b/drivers/gpu/drm/xe/xe_pcode_api.h > @@ -86,9 +86,12 @@ > #define MEMORY_CONFIG_SUBCOMMAND_READ_MAX_FREQUENCY 0x1 > > #define FAN_SPEED_CONTROL 0x7D > +#define FSC_WRITE_NUM_FAN_CONTROL_POINTS 0x0 > +#define FSC_WRITE_FAN_TABLE 0x1 > #define FSC_READ_MAX_FAN_RPS 0x3 > #define FSC_READ_NUM_FANS 0x4 > #define FSC_READ_STOCK_FAN_CONTROL_POINTS 0x5 > +#define FSC_READ_USER_FAN_CONTROL_POINTS 0x6 > #define FSC_READ_FAN_TABLE 0x7 > #define FAN_CONTROL_POINT_TEMP_MASK REG_GENMASK(7, 0) > #define FAN_CONTROL_POINT_SPEED_MASK REG_GENMASK(15, 8) > -- > 2.34.1 >