1 /* SPDX-License-Identifier: GPL-2.0 OR MIT */
2 /*
3  * Copyright 2014-2022 Advanced Micro Devices, Inc.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
19  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21  * OTHER DEALINGS IN THE SOFTWARE.
22  */
23 
24 #ifndef __KFD_TOPOLOGY_H__
25 #define __KFD_TOPOLOGY_H__
26 
27 #include <linux/types.h>
28 #include <linux/list.h>
29 #include <linux/kfd_sysfs.h>
30 #include "kfd_crat.h"
31 
32 #define KFD_TOPOLOGY_PUBLIC_NAME_SIZE 32
33 
34 struct kfd_node_properties {
35 	uint64_t hive_id;
36 	uint32_t cpu_cores_count;
37 	uint32_t simd_count;
38 	uint32_t mem_banks_count;
39 	uint32_t caches_count;
40 	uint32_t io_links_count;
41 	uint32_t cpu_core_id_base;
42 	uint32_t simd_id_base;
43 	uint32_t capability;
44 	uint32_t max_waves_per_simd;
45 	uint32_t lds_size_in_kb;
46 	uint32_t gds_size_in_kb;
47 	uint32_t num_gws;
48 	uint32_t wave_front_size;
49 	uint32_t array_count;
50 	uint32_t simd_arrays_per_engine;
51 	uint32_t cu_per_simd_array;
52 	uint32_t simd_per_cu;
53 	uint32_t max_slots_scratch_cu;
54 	uint32_t engine_id;
55 	uint32_t gfx_target_version;
56 	uint32_t vendor_id;
57 	uint32_t device_id;
58 	uint32_t location_id;
59 	uint32_t domain;
60 	uint32_t max_engine_clk_fcompute;
61 	uint32_t max_engine_clk_ccompute;
62 	int32_t  drm_render_minor;
63 	uint32_t num_sdma_engines;
64 	uint32_t num_sdma_xgmi_engines;
65 	uint32_t num_sdma_queues_per_engine;
66 	uint32_t num_cp_queues;
67 	char name[KFD_TOPOLOGY_PUBLIC_NAME_SIZE];
68 };
69 
70 struct kfd_mem_properties {
71 	struct list_head	list;
72 	uint32_t		heap_type;
73 	uint64_t		size_in_bytes;
74 	uint32_t		flags;
75 	uint32_t		width;
76 	uint32_t		mem_clk_max;
77 	struct kfd_dev		*gpu;
78 	struct kobject		*kobj;
79 	struct attribute	attr;
80 };
81 
82 struct kfd_cache_properties {
83 	struct list_head	list;
84 	uint32_t		processor_id_low;
85 	uint32_t		cache_level;
86 	uint32_t		cache_size;
87 	uint32_t		cacheline_size;
88 	uint32_t		cachelines_per_tag;
89 	uint32_t		cache_assoc;
90 	uint32_t		cache_latency;
91 	uint32_t		cache_type;
92 	uint8_t			sibling_map[CRAT_SIBLINGMAP_SIZE];
93 	struct kfd_dev		*gpu;
94 	struct kobject		*kobj;
95 	struct attribute	attr;
96 };
97 
98 struct kfd_iolink_properties {
99 	struct list_head	list;
100 	uint32_t		iolink_type;
101 	uint32_t		ver_maj;
102 	uint32_t		ver_min;
103 	uint32_t		node_from;
104 	uint32_t		node_to;
105 	uint32_t		weight;
106 	uint32_t		min_latency;
107 	uint32_t		max_latency;
108 	uint32_t		min_bandwidth;
109 	uint32_t		max_bandwidth;
110 	uint32_t		rec_transfer_size;
111 	uint32_t		flags;
112 	struct kfd_dev		*gpu;
113 	struct kobject		*kobj;
114 	struct attribute	attr;
115 };
116 
117 struct kfd_perf_properties {
118 	struct list_head	list;
119 	char			block_name[16];
120 	uint32_t		max_concurrent;
121 	struct attribute_group	*attr_group;
122 };
123 
124 struct kfd_topology_device {
125 	struct list_head		list;
126 	uint32_t			gpu_id;
127 	uint32_t			proximity_domain;
128 	struct kfd_node_properties	node_props;
129 	struct list_head		mem_props;
130 	uint32_t			cache_count;
131 	struct list_head		cache_props;
132 	uint32_t			io_link_count;
133 	struct list_head		io_link_props;
134 	struct list_head		perf_props;
135 	struct kfd_dev			*gpu;
136 	struct kobject			*kobj_node;
137 	struct kobject			*kobj_mem;
138 	struct kobject			*kobj_cache;
139 	struct kobject			*kobj_iolink;
140 	struct kobject			*kobj_perf;
141 	struct attribute		attr_gpuid;
142 	struct attribute		attr_name;
143 	struct attribute		attr_props;
144 	uint8_t				oem_id[CRAT_OEMID_LENGTH];
145 	uint8_t				oem_table_id[CRAT_OEMTABLEID_LENGTH];
146 	uint32_t			oem_revision;
147 };
148 
149 struct kfd_system_properties {
150 	uint32_t		num_devices;     /* Number of H-NUMA nodes */
151 	uint32_t		generation_count;
152 	uint64_t		platform_oem;
153 	uint64_t		platform_id;
154 	uint64_t		platform_rev;
155 	struct kobject		*kobj_topology;
156 	struct kobject		*kobj_nodes;
157 	struct attribute	attr_genid;
158 	struct attribute	attr_props;
159 };
160 
161 struct kfd_topology_device *kfd_create_topology_device(
162 		struct list_head *device_list);
163 void kfd_release_topology_device_list(struct list_head *device_list);
164 
165 #endif /* __KFD_TOPOLOGY_H__ */
166