2 * Copyright 2014 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
23 #include <linux/types.h>
24 #include <linux/kernel.h>
25 #include <linux/pci.h>
26 #include <linux/errno.h>
27 #include <linux/acpi.h>
28 #include <linux/hash.h>
29 #include <linux/cpufreq.h>
30 #include <linux/log2.h>
31 #include <linux/dmi.h>
32 #include <linux/atomic.h>
36 #include "kfd_topology.h"
37 #include "kfd_device_queue_manager.h"
38 #include "kfd_iommu.h"
39 #include "amdgpu_amdkfd.h"
40 #include "amdgpu_ras.h"
42 /* topology_device_list - Master list of all topology devices */
43 static struct list_head topology_device_list;
44 static struct kfd_system_properties sys_props;
46 static DECLARE_RWSEM(topology_lock);
47 static atomic_t topology_crat_proximity_domain;
49 struct kfd_topology_device *kfd_topology_device_by_proximity_domain(
50 uint32_t proximity_domain)
52 struct kfd_topology_device *top_dev;
53 struct kfd_topology_device *device = NULL;
55 down_read(&topology_lock);
57 list_for_each_entry(top_dev, &topology_device_list, list)
58 if (top_dev->proximity_domain == proximity_domain) {
63 up_read(&topology_lock);
68 struct kfd_topology_device *kfd_topology_device_by_id(uint32_t gpu_id)
70 struct kfd_topology_device *top_dev = NULL;
71 struct kfd_topology_device *ret = NULL;
73 down_read(&topology_lock);
75 list_for_each_entry(top_dev, &topology_device_list, list)
76 if (top_dev->gpu_id == gpu_id) {
81 up_read(&topology_lock);
86 struct kfd_dev *kfd_device_by_id(uint32_t gpu_id)
88 struct kfd_topology_device *top_dev;
90 top_dev = kfd_topology_device_by_id(gpu_id);
97 struct kfd_dev *kfd_device_by_pci_dev(const struct pci_dev *pdev)
99 struct kfd_topology_device *top_dev;
100 struct kfd_dev *device = NULL;
102 down_read(&topology_lock);
104 list_for_each_entry(top_dev, &topology_device_list, list)
105 if (top_dev->gpu && top_dev->gpu->pdev == pdev) {
106 device = top_dev->gpu;
110 up_read(&topology_lock);
115 struct kfd_dev *kfd_device_by_kgd(const struct kgd_dev *kgd)
117 struct kfd_topology_device *top_dev;
118 struct kfd_dev *device = NULL;
120 down_read(&topology_lock);
122 list_for_each_entry(top_dev, &topology_device_list, list)
123 if (top_dev->gpu && top_dev->gpu->kgd == kgd) {
124 device = top_dev->gpu;
128 up_read(&topology_lock);
133 /* Called with write topology_lock acquired */
134 static void kfd_release_topology_device(struct kfd_topology_device *dev)
136 struct kfd_mem_properties *mem;
137 struct kfd_cache_properties *cache;
138 struct kfd_iolink_properties *iolink;
139 struct kfd_perf_properties *perf;
141 list_del(&dev->list);
143 while (dev->mem_props.next != &dev->mem_props) {
144 mem = container_of(dev->mem_props.next,
145 struct kfd_mem_properties, list);
146 list_del(&mem->list);
150 while (dev->cache_props.next != &dev->cache_props) {
151 cache = container_of(dev->cache_props.next,
152 struct kfd_cache_properties, list);
153 list_del(&cache->list);
157 while (dev->io_link_props.next != &dev->io_link_props) {
158 iolink = container_of(dev->io_link_props.next,
159 struct kfd_iolink_properties, list);
160 list_del(&iolink->list);
164 while (dev->perf_props.next != &dev->perf_props) {
165 perf = container_of(dev->perf_props.next,
166 struct kfd_perf_properties, list);
167 list_del(&perf->list);
174 void kfd_release_topology_device_list(struct list_head *device_list)
176 struct kfd_topology_device *dev;
178 while (!list_empty(device_list)) {
179 dev = list_first_entry(device_list,
180 struct kfd_topology_device, list);
181 kfd_release_topology_device(dev);
185 static void kfd_release_live_view(void)
187 kfd_release_topology_device_list(&topology_device_list);
188 memset(&sys_props, 0, sizeof(sys_props));
191 struct kfd_topology_device *kfd_create_topology_device(
192 struct list_head *device_list)
194 struct kfd_topology_device *dev;
196 dev = kfd_alloc_struct(dev);
198 pr_err("No memory to allocate a topology device");
202 INIT_LIST_HEAD(&dev->mem_props);
203 INIT_LIST_HEAD(&dev->cache_props);
204 INIT_LIST_HEAD(&dev->io_link_props);
205 INIT_LIST_HEAD(&dev->perf_props);
207 list_add_tail(&dev->list, device_list);
213 #define sysfs_show_gen_prop(buffer, offs, fmt, ...) \
214 (offs += snprintf(buffer+offs, PAGE_SIZE-offs, \
216 #define sysfs_show_32bit_prop(buffer, offs, name, value) \
217 sysfs_show_gen_prop(buffer, offs, "%s %u\n", name, value)
218 #define sysfs_show_64bit_prop(buffer, offs, name, value) \
219 sysfs_show_gen_prop(buffer, offs, "%s %llu\n", name, value)
220 #define sysfs_show_32bit_val(buffer, offs, value) \
221 sysfs_show_gen_prop(buffer, offs, "%u\n", value)
222 #define sysfs_show_str_val(buffer, offs, value) \
223 sysfs_show_gen_prop(buffer, offs, "%s\n", value)
225 static ssize_t sysprops_show(struct kobject *kobj, struct attribute *attr,
230 /* Making sure that the buffer is an empty string */
233 if (attr == &sys_props.attr_genid) {
234 sysfs_show_32bit_val(buffer, offs,
235 sys_props.generation_count);
236 } else if (attr == &sys_props.attr_props) {
237 sysfs_show_64bit_prop(buffer, offs, "platform_oem",
238 sys_props.platform_oem);
239 sysfs_show_64bit_prop(buffer, offs, "platform_id",
240 sys_props.platform_id);
241 sysfs_show_64bit_prop(buffer, offs, "platform_rev",
242 sys_props.platform_rev);
250 static void kfd_topology_kobj_release(struct kobject *kobj)
255 static const struct sysfs_ops sysprops_ops = {
256 .show = sysprops_show,
259 static struct kobj_type sysprops_type = {
260 .release = kfd_topology_kobj_release,
261 .sysfs_ops = &sysprops_ops,
264 static ssize_t iolink_show(struct kobject *kobj, struct attribute *attr,
268 struct kfd_iolink_properties *iolink;
270 /* Making sure that the buffer is an empty string */
273 iolink = container_of(attr, struct kfd_iolink_properties, attr);
274 if (iolink->gpu && kfd_devcgroup_check_permission(iolink->gpu))
276 sysfs_show_32bit_prop(buffer, offs, "type", iolink->iolink_type);
277 sysfs_show_32bit_prop(buffer, offs, "version_major", iolink->ver_maj);
278 sysfs_show_32bit_prop(buffer, offs, "version_minor", iolink->ver_min);
279 sysfs_show_32bit_prop(buffer, offs, "node_from", iolink->node_from);
280 sysfs_show_32bit_prop(buffer, offs, "node_to", iolink->node_to);
281 sysfs_show_32bit_prop(buffer, offs, "weight", iolink->weight);
282 sysfs_show_32bit_prop(buffer, offs, "min_latency", iolink->min_latency);
283 sysfs_show_32bit_prop(buffer, offs, "max_latency", iolink->max_latency);
284 sysfs_show_32bit_prop(buffer, offs, "min_bandwidth",
285 iolink->min_bandwidth);
286 sysfs_show_32bit_prop(buffer, offs, "max_bandwidth",
287 iolink->max_bandwidth);
288 sysfs_show_32bit_prop(buffer, offs, "recommended_transfer_size",
289 iolink->rec_transfer_size);
290 sysfs_show_32bit_prop(buffer, offs, "flags", iolink->flags);
295 static const struct sysfs_ops iolink_ops = {
299 static struct kobj_type iolink_type = {
300 .release = kfd_topology_kobj_release,
301 .sysfs_ops = &iolink_ops,
304 static ssize_t mem_show(struct kobject *kobj, struct attribute *attr,
308 struct kfd_mem_properties *mem;
310 /* Making sure that the buffer is an empty string */
313 mem = container_of(attr, struct kfd_mem_properties, attr);
314 if (mem->gpu && kfd_devcgroup_check_permission(mem->gpu))
316 sysfs_show_32bit_prop(buffer, offs, "heap_type", mem->heap_type);
317 sysfs_show_64bit_prop(buffer, offs, "size_in_bytes",
319 sysfs_show_32bit_prop(buffer, offs, "flags", mem->flags);
320 sysfs_show_32bit_prop(buffer, offs, "width", mem->width);
321 sysfs_show_32bit_prop(buffer, offs, "mem_clk_max",
327 static const struct sysfs_ops mem_ops = {
331 static struct kobj_type mem_type = {
332 .release = kfd_topology_kobj_release,
333 .sysfs_ops = &mem_ops,
336 static ssize_t kfd_cache_show(struct kobject *kobj, struct attribute *attr,
341 struct kfd_cache_properties *cache;
343 /* Making sure that the buffer is an empty string */
346 cache = container_of(attr, struct kfd_cache_properties, attr);
347 if (cache->gpu && kfd_devcgroup_check_permission(cache->gpu))
349 sysfs_show_32bit_prop(buffer, offs, "processor_id_low",
350 cache->processor_id_low);
351 sysfs_show_32bit_prop(buffer, offs, "level", cache->cache_level);
352 sysfs_show_32bit_prop(buffer, offs, "size", cache->cache_size);
353 sysfs_show_32bit_prop(buffer, offs, "cache_line_size",
354 cache->cacheline_size);
355 sysfs_show_32bit_prop(buffer, offs, "cache_lines_per_tag",
356 cache->cachelines_per_tag);
357 sysfs_show_32bit_prop(buffer, offs, "association", cache->cache_assoc);
358 sysfs_show_32bit_prop(buffer, offs, "latency", cache->cache_latency);
359 sysfs_show_32bit_prop(buffer, offs, "type", cache->cache_type);
360 offs += snprintf(buffer+offs, PAGE_SIZE-offs, "sibling_map ");
361 for (i = 0; i < CRAT_SIBLINGMAP_SIZE; i++)
362 for (j = 0; j < sizeof(cache->sibling_map[0])*8; j++)
364 offs += snprintf(buffer+offs, PAGE_SIZE-offs, "%d,",
365 (cache->sibling_map[i] >> j) & 1);
367 /* Replace the last "," with end of line */
368 buffer[offs-1] = '\n';
372 static const struct sysfs_ops cache_ops = {
373 .show = kfd_cache_show,
376 static struct kobj_type cache_type = {
377 .release = kfd_topology_kobj_release,
378 .sysfs_ops = &cache_ops,
381 /****** Sysfs of Performance Counters ******/
383 struct kfd_perf_attr {
384 struct kobj_attribute attr;
388 static ssize_t perf_show(struct kobject *kobj, struct kobj_attribute *attrs,
392 struct kfd_perf_attr *attr;
395 attr = container_of(attrs, struct kfd_perf_attr, attr);
396 if (!attr->data) /* invalid data for PMC */
399 return sysfs_show_32bit_val(buf, offs, attr->data);
402 #define KFD_PERF_DESC(_name, _data) \
404 .attr = __ATTR(_name, 0444, perf_show, NULL), \
408 static struct kfd_perf_attr perf_attr_iommu[] = {
409 KFD_PERF_DESC(max_concurrent, 0),
410 KFD_PERF_DESC(num_counters, 0),
411 KFD_PERF_DESC(counter_ids, 0),
413 /****************************************/
415 static ssize_t node_show(struct kobject *kobj, struct attribute *attr,
419 struct kfd_topology_device *dev;
420 uint32_t log_max_watch_addr;
422 /* Making sure that the buffer is an empty string */
425 if (strcmp(attr->name, "gpu_id") == 0) {
426 dev = container_of(attr, struct kfd_topology_device,
428 if (dev->gpu && kfd_devcgroup_check_permission(dev->gpu))
430 return sysfs_show_32bit_val(buffer, offs, dev->gpu_id);
433 if (strcmp(attr->name, "name") == 0) {
434 dev = container_of(attr, struct kfd_topology_device,
437 if (dev->gpu && kfd_devcgroup_check_permission(dev->gpu))
439 return sysfs_show_str_val(buffer, offs, dev->node_props.name);
442 dev = container_of(attr, struct kfd_topology_device,
444 if (dev->gpu && kfd_devcgroup_check_permission(dev->gpu))
446 sysfs_show_32bit_prop(buffer, offs, "cpu_cores_count",
447 dev->node_props.cpu_cores_count);
448 sysfs_show_32bit_prop(buffer, offs, "simd_count",
449 dev->gpu ? dev->node_props.simd_count : 0);
450 sysfs_show_32bit_prop(buffer, offs, "mem_banks_count",
451 dev->node_props.mem_banks_count);
452 sysfs_show_32bit_prop(buffer, offs, "caches_count",
453 dev->node_props.caches_count);
454 sysfs_show_32bit_prop(buffer, offs, "io_links_count",
455 dev->node_props.io_links_count);
456 sysfs_show_32bit_prop(buffer, offs, "cpu_core_id_base",
457 dev->node_props.cpu_core_id_base);
458 sysfs_show_32bit_prop(buffer, offs, "simd_id_base",
459 dev->node_props.simd_id_base);
460 sysfs_show_32bit_prop(buffer, offs, "max_waves_per_simd",
461 dev->node_props.max_waves_per_simd);
462 sysfs_show_32bit_prop(buffer, offs, "lds_size_in_kb",
463 dev->node_props.lds_size_in_kb);
464 sysfs_show_32bit_prop(buffer, offs, "gds_size_in_kb",
465 dev->node_props.gds_size_in_kb);
466 sysfs_show_32bit_prop(buffer, offs, "num_gws",
467 dev->node_props.num_gws);
468 sysfs_show_32bit_prop(buffer, offs, "wave_front_size",
469 dev->node_props.wave_front_size);
470 sysfs_show_32bit_prop(buffer, offs, "array_count",
471 dev->node_props.array_count);
472 sysfs_show_32bit_prop(buffer, offs, "simd_arrays_per_engine",
473 dev->node_props.simd_arrays_per_engine);
474 sysfs_show_32bit_prop(buffer, offs, "cu_per_simd_array",
475 dev->node_props.cu_per_simd_array);
476 sysfs_show_32bit_prop(buffer, offs, "simd_per_cu",
477 dev->node_props.simd_per_cu);
478 sysfs_show_32bit_prop(buffer, offs, "max_slots_scratch_cu",
479 dev->node_props.max_slots_scratch_cu);
480 sysfs_show_32bit_prop(buffer, offs, "vendor_id",
481 dev->node_props.vendor_id);
482 sysfs_show_32bit_prop(buffer, offs, "device_id",
483 dev->node_props.device_id);
484 sysfs_show_32bit_prop(buffer, offs, "location_id",
485 dev->node_props.location_id);
486 sysfs_show_32bit_prop(buffer, offs, "domain",
487 dev->node_props.domain);
488 sysfs_show_32bit_prop(buffer, offs, "drm_render_minor",
489 dev->node_props.drm_render_minor);
490 sysfs_show_64bit_prop(buffer, offs, "hive_id",
491 dev->node_props.hive_id);
492 sysfs_show_32bit_prop(buffer, offs, "num_sdma_engines",
493 dev->node_props.num_sdma_engines);
494 sysfs_show_32bit_prop(buffer, offs, "num_sdma_xgmi_engines",
495 dev->node_props.num_sdma_xgmi_engines);
496 sysfs_show_32bit_prop(buffer, offs, "num_sdma_queues_per_engine",
497 dev->node_props.num_sdma_queues_per_engine);
498 sysfs_show_32bit_prop(buffer, offs, "num_cp_queues",
499 dev->node_props.num_cp_queues);
503 __ilog2_u32(dev->gpu->device_info->num_of_watch_points);
505 if (log_max_watch_addr) {
506 dev->node_props.capability |=
507 HSA_CAP_WATCH_POINTS_SUPPORTED;
509 dev->node_props.capability |=
510 ((log_max_watch_addr <<
511 HSA_CAP_WATCH_POINTS_TOTALBITS_SHIFT) &
512 HSA_CAP_WATCH_POINTS_TOTALBITS_MASK);
515 if (dev->gpu->device_info->asic_family == CHIP_TONGA)
516 dev->node_props.capability |=
517 HSA_CAP_AQL_QUEUE_DOUBLE_MAP;
519 sysfs_show_32bit_prop(buffer, offs, "max_engine_clk_fcompute",
520 dev->node_props.max_engine_clk_fcompute);
522 sysfs_show_64bit_prop(buffer, offs, "local_mem_size", 0ULL);
524 sysfs_show_32bit_prop(buffer, offs, "fw_version",
525 dev->gpu->mec_fw_version);
526 sysfs_show_32bit_prop(buffer, offs, "capability",
527 dev->node_props.capability);
528 sysfs_show_32bit_prop(buffer, offs, "sdma_fw_version",
529 dev->gpu->sdma_fw_version);
530 sysfs_show_64bit_prop(buffer, offs, "unique_id",
531 amdgpu_amdkfd_get_unique_id(dev->gpu->kgd));
535 return sysfs_show_32bit_prop(buffer, offs, "max_engine_clk_ccompute",
536 cpufreq_quick_get_max(0)/1000);
539 static const struct sysfs_ops node_ops = {
543 static struct kobj_type node_type = {
544 .release = kfd_topology_kobj_release,
545 .sysfs_ops = &node_ops,
548 static void kfd_remove_sysfs_file(struct kobject *kobj, struct attribute *attr)
550 sysfs_remove_file(kobj, attr);
555 static void kfd_remove_sysfs_node_entry(struct kfd_topology_device *dev)
557 struct kfd_iolink_properties *iolink;
558 struct kfd_cache_properties *cache;
559 struct kfd_mem_properties *mem;
560 struct kfd_perf_properties *perf;
562 if (dev->kobj_iolink) {
563 list_for_each_entry(iolink, &dev->io_link_props, list)
565 kfd_remove_sysfs_file(iolink->kobj,
569 kobject_del(dev->kobj_iolink);
570 kobject_put(dev->kobj_iolink);
571 dev->kobj_iolink = NULL;
574 if (dev->kobj_cache) {
575 list_for_each_entry(cache, &dev->cache_props, list)
577 kfd_remove_sysfs_file(cache->kobj,
581 kobject_del(dev->kobj_cache);
582 kobject_put(dev->kobj_cache);
583 dev->kobj_cache = NULL;
587 list_for_each_entry(mem, &dev->mem_props, list)
589 kfd_remove_sysfs_file(mem->kobj, &mem->attr);
592 kobject_del(dev->kobj_mem);
593 kobject_put(dev->kobj_mem);
594 dev->kobj_mem = NULL;
597 if (dev->kobj_perf) {
598 list_for_each_entry(perf, &dev->perf_props, list) {
599 kfree(perf->attr_group);
600 perf->attr_group = NULL;
602 kobject_del(dev->kobj_perf);
603 kobject_put(dev->kobj_perf);
604 dev->kobj_perf = NULL;
607 if (dev->kobj_node) {
608 sysfs_remove_file(dev->kobj_node, &dev->attr_gpuid);
609 sysfs_remove_file(dev->kobj_node, &dev->attr_name);
610 sysfs_remove_file(dev->kobj_node, &dev->attr_props);
611 kobject_del(dev->kobj_node);
612 kobject_put(dev->kobj_node);
613 dev->kobj_node = NULL;
617 static int kfd_build_sysfs_node_entry(struct kfd_topology_device *dev,
620 struct kfd_iolink_properties *iolink;
621 struct kfd_cache_properties *cache;
622 struct kfd_mem_properties *mem;
623 struct kfd_perf_properties *perf;
625 uint32_t i, num_attrs;
626 struct attribute **attrs;
628 if (WARN_ON(dev->kobj_node))
632 * Creating the sysfs folders
634 dev->kobj_node = kfd_alloc_struct(dev->kobj_node);
638 ret = kobject_init_and_add(dev->kobj_node, &node_type,
639 sys_props.kobj_nodes, "%d", id);
641 kobject_put(dev->kobj_node);
645 dev->kobj_mem = kobject_create_and_add("mem_banks", dev->kobj_node);
649 dev->kobj_cache = kobject_create_and_add("caches", dev->kobj_node);
650 if (!dev->kobj_cache)
653 dev->kobj_iolink = kobject_create_and_add("io_links", dev->kobj_node);
654 if (!dev->kobj_iolink)
657 dev->kobj_perf = kobject_create_and_add("perf", dev->kobj_node);
662 * Creating sysfs files for node properties
664 dev->attr_gpuid.name = "gpu_id";
665 dev->attr_gpuid.mode = KFD_SYSFS_FILE_MODE;
666 sysfs_attr_init(&dev->attr_gpuid);
667 dev->attr_name.name = "name";
668 dev->attr_name.mode = KFD_SYSFS_FILE_MODE;
669 sysfs_attr_init(&dev->attr_name);
670 dev->attr_props.name = "properties";
671 dev->attr_props.mode = KFD_SYSFS_FILE_MODE;
672 sysfs_attr_init(&dev->attr_props);
673 ret = sysfs_create_file(dev->kobj_node, &dev->attr_gpuid);
676 ret = sysfs_create_file(dev->kobj_node, &dev->attr_name);
679 ret = sysfs_create_file(dev->kobj_node, &dev->attr_props);
684 list_for_each_entry(mem, &dev->mem_props, list) {
685 mem->kobj = kzalloc(sizeof(struct kobject), GFP_KERNEL);
688 ret = kobject_init_and_add(mem->kobj, &mem_type,
689 dev->kobj_mem, "%d", i);
691 kobject_put(mem->kobj);
695 mem->attr.name = "properties";
696 mem->attr.mode = KFD_SYSFS_FILE_MODE;
697 sysfs_attr_init(&mem->attr);
698 ret = sysfs_create_file(mem->kobj, &mem->attr);
705 list_for_each_entry(cache, &dev->cache_props, list) {
706 cache->kobj = kzalloc(sizeof(struct kobject), GFP_KERNEL);
709 ret = kobject_init_and_add(cache->kobj, &cache_type,
710 dev->kobj_cache, "%d", i);
712 kobject_put(cache->kobj);
716 cache->attr.name = "properties";
717 cache->attr.mode = KFD_SYSFS_FILE_MODE;
718 sysfs_attr_init(&cache->attr);
719 ret = sysfs_create_file(cache->kobj, &cache->attr);
726 list_for_each_entry(iolink, &dev->io_link_props, list) {
727 iolink->kobj = kzalloc(sizeof(struct kobject), GFP_KERNEL);
730 ret = kobject_init_and_add(iolink->kobj, &iolink_type,
731 dev->kobj_iolink, "%d", i);
733 kobject_put(iolink->kobj);
737 iolink->attr.name = "properties";
738 iolink->attr.mode = KFD_SYSFS_FILE_MODE;
739 sysfs_attr_init(&iolink->attr);
740 ret = sysfs_create_file(iolink->kobj, &iolink->attr);
746 /* All hardware blocks have the same number of attributes. */
747 num_attrs = ARRAY_SIZE(perf_attr_iommu);
748 list_for_each_entry(perf, &dev->perf_props, list) {
749 perf->attr_group = kzalloc(sizeof(struct kfd_perf_attr)
750 * num_attrs + sizeof(struct attribute_group),
752 if (!perf->attr_group)
755 attrs = (struct attribute **)(perf->attr_group + 1);
756 if (!strcmp(perf->block_name, "iommu")) {
757 /* Information of IOMMU's num_counters and counter_ids is shown
758 * under /sys/bus/event_source/devices/amd_iommu. We don't
761 perf_attr_iommu[0].data = perf->max_concurrent;
762 for (i = 0; i < num_attrs; i++)
763 attrs[i] = &perf_attr_iommu[i].attr.attr;
765 perf->attr_group->name = perf->block_name;
766 perf->attr_group->attrs = attrs;
767 ret = sysfs_create_group(dev->kobj_perf, perf->attr_group);
775 /* Called with write topology lock acquired */
776 static int kfd_build_sysfs_node_tree(void)
778 struct kfd_topology_device *dev;
782 list_for_each_entry(dev, &topology_device_list, list) {
783 ret = kfd_build_sysfs_node_entry(dev, i);
792 /* Called with write topology lock acquired */
793 static void kfd_remove_sysfs_node_tree(void)
795 struct kfd_topology_device *dev;
797 list_for_each_entry(dev, &topology_device_list, list)
798 kfd_remove_sysfs_node_entry(dev);
801 static int kfd_topology_update_sysfs(void)
805 if (!sys_props.kobj_topology) {
806 sys_props.kobj_topology =
807 kfd_alloc_struct(sys_props.kobj_topology);
808 if (!sys_props.kobj_topology)
811 ret = kobject_init_and_add(sys_props.kobj_topology,
812 &sysprops_type, &kfd_device->kobj,
815 kobject_put(sys_props.kobj_topology);
819 sys_props.kobj_nodes = kobject_create_and_add("nodes",
820 sys_props.kobj_topology);
821 if (!sys_props.kobj_nodes)
824 sys_props.attr_genid.name = "generation_id";
825 sys_props.attr_genid.mode = KFD_SYSFS_FILE_MODE;
826 sysfs_attr_init(&sys_props.attr_genid);
827 ret = sysfs_create_file(sys_props.kobj_topology,
828 &sys_props.attr_genid);
832 sys_props.attr_props.name = "system_properties";
833 sys_props.attr_props.mode = KFD_SYSFS_FILE_MODE;
834 sysfs_attr_init(&sys_props.attr_props);
835 ret = sysfs_create_file(sys_props.kobj_topology,
836 &sys_props.attr_props);
841 kfd_remove_sysfs_node_tree();
843 return kfd_build_sysfs_node_tree();
846 static void kfd_topology_release_sysfs(void)
848 kfd_remove_sysfs_node_tree();
849 if (sys_props.kobj_topology) {
850 sysfs_remove_file(sys_props.kobj_topology,
851 &sys_props.attr_genid);
852 sysfs_remove_file(sys_props.kobj_topology,
853 &sys_props.attr_props);
854 if (sys_props.kobj_nodes) {
855 kobject_del(sys_props.kobj_nodes);
856 kobject_put(sys_props.kobj_nodes);
857 sys_props.kobj_nodes = NULL;
859 kobject_del(sys_props.kobj_topology);
860 kobject_put(sys_props.kobj_topology);
861 sys_props.kobj_topology = NULL;
865 /* Called with write topology_lock acquired */
866 static void kfd_topology_update_device_list(struct list_head *temp_list,
867 struct list_head *master_list)
869 while (!list_empty(temp_list)) {
870 list_move_tail(temp_list->next, master_list);
871 sys_props.num_devices++;
875 static void kfd_debug_print_topology(void)
877 struct kfd_topology_device *dev;
879 down_read(&topology_lock);
881 dev = list_last_entry(&topology_device_list,
882 struct kfd_topology_device, list);
884 if (dev->node_props.cpu_cores_count &&
885 dev->node_props.simd_count) {
886 pr_info("Topology: Add APU node [0x%0x:0x%0x]\n",
887 dev->node_props.device_id,
888 dev->node_props.vendor_id);
889 } else if (dev->node_props.cpu_cores_count)
890 pr_info("Topology: Add CPU node\n");
891 else if (dev->node_props.simd_count)
892 pr_info("Topology: Add dGPU node [0x%0x:0x%0x]\n",
893 dev->node_props.device_id,
894 dev->node_props.vendor_id);
896 up_read(&topology_lock);
899 /* Helper function for intializing platform_xx members of
900 * kfd_system_properties. Uses OEM info from the last CPU/APU node.
902 static void kfd_update_system_properties(void)
904 struct kfd_topology_device *dev;
906 down_read(&topology_lock);
907 dev = list_last_entry(&topology_device_list,
908 struct kfd_topology_device, list);
910 sys_props.platform_id =
911 (*((uint64_t *)dev->oem_id)) & CRAT_OEMID_64BIT_MASK;
912 sys_props.platform_oem = *((uint64_t *)dev->oem_table_id);
913 sys_props.platform_rev = dev->oem_revision;
915 up_read(&topology_lock);
918 static void find_system_memory(const struct dmi_header *dm,
921 struct kfd_mem_properties *mem;
922 u16 mem_width, mem_clock;
923 struct kfd_topology_device *kdev =
924 (struct kfd_topology_device *)private;
925 const u8 *dmi_data = (const u8 *)(dm + 1);
927 if (dm->type == DMI_ENTRY_MEM_DEVICE && dm->length >= 0x15) {
928 mem_width = (u16)(*(const u16 *)(dmi_data + 0x6));
929 mem_clock = (u16)(*(const u16 *)(dmi_data + 0x11));
930 list_for_each_entry(mem, &kdev->mem_props, list) {
931 if (mem_width != 0xFFFF && mem_width != 0)
932 mem->width = mem_width;
934 mem->mem_clk_max = mem_clock;
940 * Performance counters information is not part of CRAT but we would like to
941 * put them in the sysfs under topology directory for Thunk to get the data.
942 * This function is called before updating the sysfs.
944 static int kfd_add_perf_to_topology(struct kfd_topology_device *kdev)
946 /* These are the only counters supported so far */
947 return kfd_iommu_add_perf_counters(kdev);
950 /* kfd_add_non_crat_information - Add information that is not currently
951 * defined in CRAT but is necessary for KFD topology
952 * @dev - topology device to which addition info is added
954 static void kfd_add_non_crat_information(struct kfd_topology_device *kdev)
956 /* Check if CPU only node. */
958 /* Add system memory information */
959 dmi_walk(find_system_memory, kdev);
961 /* TODO: For GPU node, rearrange code from kfd_topology_add_device */
964 /* kfd_is_acpi_crat_invalid - CRAT from ACPI is valid only for AMD APU devices.
965 * Ignore CRAT for all other devices. AMD APU is identified if both CPU
966 * and GPU cores are present.
967 * @device_list - topology device list created by parsing ACPI CRAT table.
968 * @return - TRUE if invalid, FALSE is valid.
970 static bool kfd_is_acpi_crat_invalid(struct list_head *device_list)
972 struct kfd_topology_device *dev;
974 list_for_each_entry(dev, device_list, list) {
975 if (dev->node_props.cpu_cores_count &&
976 dev->node_props.simd_count)
979 pr_info("Ignoring ACPI CRAT on non-APU system\n");
983 int kfd_topology_init(void)
985 void *crat_image = NULL;
986 size_t image_size = 0;
988 struct list_head temp_topology_device_list;
989 int cpu_only_node = 0;
990 struct kfd_topology_device *kdev;
991 int proximity_domain;
993 /* topology_device_list - Master list of all topology devices
994 * temp_topology_device_list - temporary list created while parsing CRAT
995 * or VCRAT. Once parsing is complete the contents of list is moved to
996 * topology_device_list
999 /* Initialize the head for the both the lists */
1000 INIT_LIST_HEAD(&topology_device_list);
1001 INIT_LIST_HEAD(&temp_topology_device_list);
1002 init_rwsem(&topology_lock);
1004 memset(&sys_props, 0, sizeof(sys_props));
1006 /* Proximity domains in ACPI CRAT tables start counting at
1007 * 0. The same should be true for virtual CRAT tables created
1008 * at this stage. GPUs added later in kfd_topology_add_device
1011 proximity_domain = 0;
1014 * Get the CRAT image from the ACPI. If ACPI doesn't have one
1015 * or if ACPI CRAT is invalid create a virtual CRAT.
1016 * NOTE: The current implementation expects all AMD APUs to have
1017 * CRAT. If no CRAT is available, it is assumed to be a CPU
1019 ret = kfd_create_crat_image_acpi(&crat_image, &image_size);
1021 ret = kfd_parse_crat_table(crat_image,
1022 &temp_topology_device_list,
1025 kfd_is_acpi_crat_invalid(&temp_topology_device_list)) {
1026 kfd_release_topology_device_list(
1027 &temp_topology_device_list);
1028 kfd_destroy_crat_image(crat_image);
1034 ret = kfd_create_crat_image_virtual(&crat_image, &image_size,
1035 COMPUTE_UNIT_CPU, NULL,
1039 pr_err("Error creating VCRAT table for CPU\n");
1043 ret = kfd_parse_crat_table(crat_image,
1044 &temp_topology_device_list,
1047 pr_err("Error parsing VCRAT table for CPU\n");
1052 kdev = list_first_entry(&temp_topology_device_list,
1053 struct kfd_topology_device, list);
1054 kfd_add_perf_to_topology(kdev);
1056 down_write(&topology_lock);
1057 kfd_topology_update_device_list(&temp_topology_device_list,
1058 &topology_device_list);
1059 atomic_set(&topology_crat_proximity_domain, sys_props.num_devices-1);
1060 ret = kfd_topology_update_sysfs();
1061 up_write(&topology_lock);
1064 sys_props.generation_count++;
1065 kfd_update_system_properties();
1066 kfd_debug_print_topology();
1068 pr_err("Failed to update topology in sysfs ret=%d\n", ret);
1070 /* For nodes with GPU, this information gets added
1071 * when GPU is detected (kfd_topology_add_device).
1073 if (cpu_only_node) {
1074 /* Add additional information to CPU only node created above */
1075 down_write(&topology_lock);
1076 kdev = list_first_entry(&topology_device_list,
1077 struct kfd_topology_device, list);
1078 up_write(&topology_lock);
1079 kfd_add_non_crat_information(kdev);
1083 kfd_destroy_crat_image(crat_image);
1087 void kfd_topology_shutdown(void)
1089 down_write(&topology_lock);
1090 kfd_topology_release_sysfs();
1091 kfd_release_live_view();
1092 up_write(&topology_lock);
1095 static uint32_t kfd_generate_gpu_id(struct kfd_dev *gpu)
1099 uint64_t local_mem_size;
1101 struct kfd_local_mem_info local_mem_info;
1106 amdgpu_amdkfd_get_local_mem_info(gpu->kgd, &local_mem_info);
1108 local_mem_size = local_mem_info.local_mem_size_private +
1109 local_mem_info.local_mem_size_public;
1111 buf[0] = gpu->pdev->devfn;
1112 buf[1] = gpu->pdev->subsystem_vendor |
1113 (gpu->pdev->subsystem_device << 16);
1114 buf[2] = pci_domain_nr(gpu->pdev->bus);
1115 buf[3] = gpu->pdev->device;
1116 buf[4] = gpu->pdev->bus->number;
1117 buf[5] = lower_32_bits(local_mem_size);
1118 buf[6] = upper_32_bits(local_mem_size);
1120 for (i = 0, hashout = 0; i < 7; i++)
1121 hashout ^= hash_32(buf[i], KFD_GPU_ID_HASH_WIDTH);
1125 /* kfd_assign_gpu - Attach @gpu to the correct kfd topology device. If
1126 * the GPU device is not already present in the topology device
1127 * list then return NULL. This means a new topology device has to
1128 * be created for this GPU.
1130 static struct kfd_topology_device *kfd_assign_gpu(struct kfd_dev *gpu)
1132 struct kfd_topology_device *dev;
1133 struct kfd_topology_device *out_dev = NULL;
1134 struct kfd_mem_properties *mem;
1135 struct kfd_cache_properties *cache;
1136 struct kfd_iolink_properties *iolink;
1138 down_write(&topology_lock);
1139 list_for_each_entry(dev, &topology_device_list, list) {
1140 /* Discrete GPUs need their own topology device list
1141 * entries. Don't assign them to CPU/APU nodes.
1143 if (!gpu->use_iommu_v2 &&
1144 dev->node_props.cpu_cores_count)
1147 if (!dev->gpu && (dev->node_props.simd_count > 0)) {
1151 list_for_each_entry(mem, &dev->mem_props, list)
1152 mem->gpu = dev->gpu;
1153 list_for_each_entry(cache, &dev->cache_props, list)
1154 cache->gpu = dev->gpu;
1155 list_for_each_entry(iolink, &dev->io_link_props, list)
1156 iolink->gpu = dev->gpu;
1160 up_write(&topology_lock);
1164 static void kfd_notify_gpu_change(uint32_t gpu_id, int arrival)
1167 * TODO: Generate an event for thunk about the arrival/removal
1172 /* kfd_fill_mem_clk_max_info - Since CRAT doesn't have memory clock info,
1173 * patch this after CRAT parsing.
1175 static void kfd_fill_mem_clk_max_info(struct kfd_topology_device *dev)
1177 struct kfd_mem_properties *mem;
1178 struct kfd_local_mem_info local_mem_info;
1183 /* Currently, amdgpu driver (amdgpu_mc) deals only with GPUs with
1184 * single bank of VRAM local memory.
1185 * for dGPUs - VCRAT reports only one bank of Local Memory
1186 * for APUs - If CRAT from ACPI reports more than one bank, then
1187 * all the banks will report the same mem_clk_max information
1189 amdgpu_amdkfd_get_local_mem_info(dev->gpu->kgd, &local_mem_info);
1191 list_for_each_entry(mem, &dev->mem_props, list)
1192 mem->mem_clk_max = local_mem_info.mem_clk_max;
1195 static void kfd_fill_iolink_non_crat_info(struct kfd_topology_device *dev)
1197 struct kfd_iolink_properties *link, *cpu_link;
1198 struct kfd_topology_device *cpu_dev;
1200 uint32_t cpu_flag = CRAT_IOLINK_FLAGS_ENABLED;
1201 uint32_t flag = CRAT_IOLINK_FLAGS_ENABLED;
1203 if (!dev || !dev->gpu)
1206 pcie_capability_read_dword(dev->gpu->pdev,
1207 PCI_EXP_DEVCAP2, &cap);
1209 if (!(cap & (PCI_EXP_DEVCAP2_ATOMIC_COMP32 |
1210 PCI_EXP_DEVCAP2_ATOMIC_COMP64)))
1211 cpu_flag |= CRAT_IOLINK_FLAGS_NO_ATOMICS_32_BIT |
1212 CRAT_IOLINK_FLAGS_NO_ATOMICS_64_BIT;
1214 if (!dev->gpu->pci_atomic_requested ||
1215 dev->gpu->device_info->asic_family == CHIP_HAWAII)
1216 flag |= CRAT_IOLINK_FLAGS_NO_ATOMICS_32_BIT |
1217 CRAT_IOLINK_FLAGS_NO_ATOMICS_64_BIT;
1219 /* GPU only creates direct links so apply flags setting to all */
1220 list_for_each_entry(link, &dev->io_link_props, list) {
1222 cpu_dev = kfd_topology_device_by_proximity_domain(
1225 list_for_each_entry(cpu_link,
1226 &cpu_dev->io_link_props, list)
1227 if (cpu_link->node_to == link->node_from)
1228 cpu_link->flags = cpu_flag;
1233 int kfd_topology_add_device(struct kfd_dev *gpu)
1236 struct kfd_topology_device *dev;
1237 struct kfd_cu_info cu_info;
1239 struct list_head temp_topology_device_list;
1240 void *crat_image = NULL;
1241 size_t image_size = 0;
1242 int proximity_domain;
1243 struct amdgpu_device *adev;
1245 INIT_LIST_HEAD(&temp_topology_device_list);
1247 gpu_id = kfd_generate_gpu_id(gpu);
1249 pr_debug("Adding new GPU (ID: 0x%x) to topology\n", gpu_id);
1251 proximity_domain = atomic_inc_return(&topology_crat_proximity_domain);
1253 /* Check to see if this gpu device exists in the topology_device_list.
1254 * If so, assign the gpu to that device,
1255 * else create a Virtual CRAT for this gpu device and then parse that
1256 * CRAT to create a new topology device. Once created assign the gpu to
1257 * that topology device
1259 dev = kfd_assign_gpu(gpu);
1261 res = kfd_create_crat_image_virtual(&crat_image, &image_size,
1262 COMPUTE_UNIT_GPU, gpu,
1265 pr_err("Error creating VCRAT for GPU (ID: 0x%x)\n",
1269 res = kfd_parse_crat_table(crat_image,
1270 &temp_topology_device_list,
1273 pr_err("Error parsing VCRAT for GPU (ID: 0x%x)\n",
1278 down_write(&topology_lock);
1279 kfd_topology_update_device_list(&temp_topology_device_list,
1280 &topology_device_list);
1282 /* Update the SYSFS tree, since we added another topology
1285 res = kfd_topology_update_sysfs();
1286 up_write(&topology_lock);
1289 sys_props.generation_count++;
1291 pr_err("Failed to update GPU (ID: 0x%x) to sysfs topology. res=%d\n",
1293 dev = kfd_assign_gpu(gpu);
1294 if (WARN_ON(!dev)) {
1300 dev->gpu_id = gpu_id;
1303 /* TODO: Move the following lines to function
1304 * kfd_add_non_crat_information
1307 /* Fill-in additional information that is not available in CRAT but
1308 * needed for the topology
1311 amdgpu_amdkfd_get_cu_info(dev->gpu->kgd, &cu_info);
1313 strncpy(dev->node_props.name, gpu->device_info->asic_name,
1314 KFD_TOPOLOGY_PUBLIC_NAME_SIZE);
1316 dev->node_props.simd_arrays_per_engine =
1317 cu_info.num_shader_arrays_per_engine;
1319 dev->node_props.vendor_id = gpu->pdev->vendor;
1320 dev->node_props.device_id = gpu->pdev->device;
1321 dev->node_props.capability |=
1322 ((amdgpu_amdkfd_get_asic_rev_id(dev->gpu->kgd) <<
1323 HSA_CAP_ASIC_REVISION_SHIFT) &
1324 HSA_CAP_ASIC_REVISION_MASK);
1325 dev->node_props.location_id = pci_dev_id(gpu->pdev);
1326 dev->node_props.domain = pci_domain_nr(gpu->pdev->bus);
1327 dev->node_props.max_engine_clk_fcompute =
1328 amdgpu_amdkfd_get_max_engine_clock_in_mhz(dev->gpu->kgd);
1329 dev->node_props.max_engine_clk_ccompute =
1330 cpufreq_quick_get_max(0) / 1000;
1331 dev->node_props.drm_render_minor =
1332 gpu->shared_resources.drm_render_minor;
1334 dev->node_props.hive_id = gpu->hive_id;
1335 dev->node_props.num_sdma_engines = gpu->device_info->num_sdma_engines;
1336 dev->node_props.num_sdma_xgmi_engines =
1337 gpu->device_info->num_xgmi_sdma_engines;
1338 dev->node_props.num_sdma_queues_per_engine =
1339 gpu->device_info->num_sdma_queues_per_engine;
1340 dev->node_props.num_gws = (dev->gpu->gws &&
1341 dev->gpu->dqm->sched_policy != KFD_SCHED_POLICY_NO_HWS) ?
1342 amdgpu_amdkfd_get_num_gws(dev->gpu->kgd) : 0;
1343 dev->node_props.num_cp_queues = get_cp_queues_num(dev->gpu->dqm);
1345 kfd_fill_mem_clk_max_info(dev);
1346 kfd_fill_iolink_non_crat_info(dev);
1348 switch (dev->gpu->device_info->asic_family) {
1352 dev->node_props.capability |= ((HSA_CAP_DOORBELL_TYPE_PRE_1_0 <<
1353 HSA_CAP_DOORBELL_TYPE_TOTALBITS_SHIFT) &
1354 HSA_CAP_DOORBELL_TYPE_TOTALBITS_MASK);
1358 case CHIP_POLARIS10:
1359 case CHIP_POLARIS11:
1360 case CHIP_POLARIS12:
1362 pr_debug("Adding doorbell packet type capability\n");
1363 dev->node_props.capability |= ((HSA_CAP_DOORBELL_TYPE_1_0 <<
1364 HSA_CAP_DOORBELL_TYPE_TOTALBITS_SHIFT) &
1365 HSA_CAP_DOORBELL_TYPE_TOTALBITS_MASK);
1376 case CHIP_SIENNA_CICHLID:
1377 case CHIP_NAVY_FLOUNDER:
1379 case CHIP_DIMGREY_CAVEFISH:
1380 dev->node_props.capability |= ((HSA_CAP_DOORBELL_TYPE_2_0 <<
1381 HSA_CAP_DOORBELL_TYPE_TOTALBITS_SHIFT) &
1382 HSA_CAP_DOORBELL_TYPE_TOTALBITS_MASK);
1385 WARN(1, "Unexpected ASIC family %u",
1386 dev->gpu->device_info->asic_family);
1390 * Overwrite ATS capability according to needs_iommu_device to fix
1391 * potential missing corresponding bit in CRAT of BIOS.
1393 if (dev->gpu->use_iommu_v2)
1394 dev->node_props.capability |= HSA_CAP_ATS_PRESENT;
1396 dev->node_props.capability &= ~HSA_CAP_ATS_PRESENT;
1398 /* Fix errors in CZ CRAT.
1399 * simd_count: Carrizo CRAT reports wrong simd_count, probably
1400 * because it doesn't consider masked out CUs
1401 * max_waves_per_simd: Carrizo reports wrong max_waves_per_simd
1403 if (dev->gpu->device_info->asic_family == CHIP_CARRIZO) {
1404 dev->node_props.simd_count =
1405 cu_info.simd_per_cu * cu_info.cu_active_number;
1406 dev->node_props.max_waves_per_simd = 10;
1409 adev = (struct amdgpu_device *)(dev->gpu->kgd);
1410 /* kfd only concerns sram ecc on GFX and HBM ecc on UMC */
1411 dev->node_props.capability |=
1412 ((adev->ras_features & BIT(AMDGPU_RAS_BLOCK__GFX)) != 0) ?
1413 HSA_CAP_SRAM_EDCSUPPORTED : 0;
1414 dev->node_props.capability |= ((adev->ras_features & BIT(AMDGPU_RAS_BLOCK__UMC)) != 0) ?
1415 HSA_CAP_MEM_EDCSUPPORTED : 0;
1417 if (adev->asic_type != CHIP_VEGA10)
1418 dev->node_props.capability |= (adev->ras_features != 0) ?
1419 HSA_CAP_RASEVENTNOTIFY : 0;
1421 kfd_debug_print_topology();
1424 kfd_notify_gpu_change(gpu_id, 1);
1426 kfd_destroy_crat_image(crat_image);
1430 int kfd_topology_remove_device(struct kfd_dev *gpu)
1432 struct kfd_topology_device *dev, *tmp;
1436 down_write(&topology_lock);
1438 list_for_each_entry_safe(dev, tmp, &topology_device_list, list)
1439 if (dev->gpu == gpu) {
1440 gpu_id = dev->gpu_id;
1441 kfd_remove_sysfs_node_entry(dev);
1442 kfd_release_topology_device(dev);
1443 sys_props.num_devices--;
1445 if (kfd_topology_update_sysfs() < 0)
1446 kfd_topology_release_sysfs();
1450 up_write(&topology_lock);
1453 kfd_notify_gpu_change(gpu_id, 0);
1458 /* kfd_topology_enum_kfd_devices - Enumerate through all devices in KFD
1459 * topology. If GPU device is found @idx, then valid kfd_dev pointer is
1460 * returned through @kdev
1461 * Return - 0: On success (@kdev will be NULL for non GPU nodes)
1462 * -1: If end of list
1464 int kfd_topology_enum_kfd_devices(uint8_t idx, struct kfd_dev **kdev)
1467 struct kfd_topology_device *top_dev;
1468 uint8_t device_idx = 0;
1471 down_read(&topology_lock);
1473 list_for_each_entry(top_dev, &topology_device_list, list) {
1474 if (device_idx == idx) {
1475 *kdev = top_dev->gpu;
1476 up_read(&topology_lock);
1483 up_read(&topology_lock);
1489 static int kfd_cpumask_to_apic_id(const struct cpumask *cpumask)
1491 int first_cpu_of_numa_node;
1493 if (!cpumask || cpumask == cpu_none_mask)
1495 first_cpu_of_numa_node = cpumask_first(cpumask);
1496 if (first_cpu_of_numa_node >= nr_cpu_ids)
1498 #ifdef CONFIG_X86_64
1499 return cpu_data(first_cpu_of_numa_node).apicid;
1501 return first_cpu_of_numa_node;
1505 /* kfd_numa_node_to_apic_id - Returns the APIC ID of the first logical processor
1506 * of the given NUMA node (numa_node_id)
1507 * Return -1 on failure
1509 int kfd_numa_node_to_apic_id(int numa_node_id)
1511 if (numa_node_id == -1) {
1512 pr_warn("Invalid NUMA Node. Use online CPU mask\n");
1513 return kfd_cpumask_to_apic_id(cpu_online_mask);
1515 return kfd_cpumask_to_apic_id(cpumask_of_node(numa_node_id));
1518 void kfd_double_confirm_iommu_support(struct kfd_dev *gpu)
1520 struct kfd_topology_device *dev;
1522 gpu->use_iommu_v2 = false;
1524 if (!gpu->device_info->needs_iommu_device)
1527 down_read(&topology_lock);
1529 /* Only use IOMMUv2 if there is an APU topology node with no GPU
1530 * assigned yet. This GPU will be assigned to it.
1532 list_for_each_entry(dev, &topology_device_list, list)
1533 if (dev->node_props.cpu_cores_count &&
1534 dev->node_props.simd_count &&
1536 gpu->use_iommu_v2 = true;
1538 up_read(&topology_lock);
1541 #if defined(CONFIG_DEBUG_FS)
1543 int kfd_debugfs_hqds_by_device(struct seq_file *m, void *data)
1545 struct kfd_topology_device *dev;
1549 down_read(&topology_lock);
1551 list_for_each_entry(dev, &topology_device_list, list) {
1557 seq_printf(m, "Node %u, gpu_id %x:\n", i++, dev->gpu->id);
1558 r = dqm_debugfs_hqds(m, dev->gpu->dqm);
1563 up_read(&topology_lock);
1568 int kfd_debugfs_rls_by_device(struct seq_file *m, void *data)
1570 struct kfd_topology_device *dev;
1574 down_read(&topology_lock);
1576 list_for_each_entry(dev, &topology_device_list, list) {
1582 seq_printf(m, "Node %u, gpu_id %x:\n", i++, dev->gpu->id);
1583 r = pm_debugfs_runlist(m, &dev->gpu->dqm->packets);
1588 up_read(&topology_lock);