xref: /linux/drivers/gpu/drm/amd/include/amdgpu_ptl.h (revision e16d0d16728179fb8eaad93c8a12825eb6746eca)
18ce9c731SPerry Yuan /*
28ce9c731SPerry Yuan  * Copyright 2026 Advanced Micro Devices, Inc.
38ce9c731SPerry Yuan  *
48ce9c731SPerry Yuan  * Permission is hereby granted, free of charge, to any person obtaining a
58ce9c731SPerry Yuan  * copy of this software and associated documentation files (the "Software"),
68ce9c731SPerry Yuan  * to deal in the Software without restriction, including without limitation
78ce9c731SPerry Yuan  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
88ce9c731SPerry Yuan  * and/or sell copies of the Software, and to permit persons to whom the
98ce9c731SPerry Yuan  * Software is furnished to do so, subject to the following conditions:
108ce9c731SPerry Yuan  *
118ce9c731SPerry Yuan  * The above copyright notice and this permission notice shall be included in
128ce9c731SPerry Yuan  * all copies or substantial portions of the Software.
138ce9c731SPerry Yuan  *
148ce9c731SPerry Yuan  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
158ce9c731SPerry Yuan  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
168ce9c731SPerry Yuan  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
178ce9c731SPerry Yuan  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
188ce9c731SPerry Yuan  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
198ce9c731SPerry Yuan  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
208ce9c731SPerry Yuan  * OTHER DEALINGS IN THE SOFTWARE.
218ce9c731SPerry Yuan  */
228ce9c731SPerry Yuan 
238ce9c731SPerry Yuan #ifndef __AMDGPU_PTL_H__
248ce9c731SPerry Yuan #define __AMDGPU_PTL_H__
258ce9c731SPerry Yuan 
268ce9c731SPerry Yuan enum amdgpu_ptl_fmt {
278ce9c731SPerry Yuan 	AMDGPU_PTL_FMT_I8   = 0,
288ce9c731SPerry Yuan 	AMDGPU_PTL_FMT_F16  = 1,
298ce9c731SPerry Yuan 	AMDGPU_PTL_FMT_BF16 = 2,
308ce9c731SPerry Yuan 	AMDGPU_PTL_FMT_F32  = 3,
318ce9c731SPerry Yuan 	AMDGPU_PTL_FMT_F64  = 4,
328ce9c731SPerry Yuan 	AMDGPU_PTL_FMT_F8   = 5,
338ce9c731SPerry Yuan 	AMDGPU_PTL_FMT_VECTOR  = 6,
348ce9c731SPerry Yuan 	AMDGPU_PTL_FMT_INVALID = 7,
358ce9c731SPerry Yuan };
368ce9c731SPerry Yuan 
37950688d2SPerry Yuan enum amdgpu_ptl_disable_source {
38950688d2SPerry Yuan 	AMDGPU_PTL_DISABLE_SYSFS = 0,
39950688d2SPerry Yuan 	AMDGPU_PTL_DISABLE_PROFILER,
40950688d2SPerry Yuan 	AMDGPU_PTL_DISABLE_MAX,
41950688d2SPerry Yuan };
428ce9c731SPerry Yuan struct amdgpu_ptl {
438ce9c731SPerry Yuan 	enum amdgpu_ptl_fmt		fmt1;
448ce9c731SPerry Yuan 	enum amdgpu_ptl_fmt		fmt2;
458ce9c731SPerry Yuan 	bool				enabled;
468ce9c731SPerry Yuan 	bool				hw_supported;
47b6dc8f75SPerry Yuan 	bool				permanently_disabled;
48dd61e275SPerry Yuan 	/* PTL disable reference counting */
49dd61e275SPerry Yuan 	atomic_t			disable_ref;
508ce9c731SPerry Yuan 	struct mutex			mutex;
51950688d2SPerry Yuan 	DECLARE_BITMAP(disable_bitmap, AMDGPU_PTL_DISABLE_MAX);
52*e16d0d16SPerry Yuan 	bool				ptl_sysfs_created;
538ce9c731SPerry Yuan };
548ce9c731SPerry Yuan 
558ce9c731SPerry Yuan int amdgpu_ptl_perf_monitor_ctrl(struct amdgpu_device *adev, u32 req_code,
568ce9c731SPerry Yuan 		u32 *ptl_state,
578ce9c731SPerry Yuan 		enum amdgpu_ptl_fmt *fmt1,
588ce9c731SPerry Yuan 		enum amdgpu_ptl_fmt *fmt2);
598ce9c731SPerry Yuan 
60d51a0439SPerry Yuan int amdgpu_ptl_sysfs_init(struct amdgpu_device *adev);
61d51a0439SPerry Yuan void amdgpu_ptl_sysfs_fini(struct amdgpu_device *adev);
62d51a0439SPerry Yuan 
63d51a0439SPerry Yuan extern const struct attribute_group amdgpu_ptl_attr_group;
648ce9c731SPerry Yuan #endif /* __AMDGPU_PTL_H__ */
65