diff options
author | Harish Kasiviswanathan <harish.kasiviswanathan@amd.com> | 2017-12-08 23:08:51 -0500 |
---|---|---|
committer | Oded Gabbay <oded.gabbay@gmail.com> | 2017-12-08 23:08:51 -0500 |
commit | 8e05247d4c23ff1c91682cf28d2ddb4210808e7d (patch) | |
tree | 7a2cf809c3e4660e62a499939e7e40bfa5691da5 | |
parent | 174de876d6d02f7159363495a3f34461ba91d3ee (diff) |
drm/amdkfd: Reorganize CRAT fetching from ACPI
Reorganize and rename kfd_topology_get_crat_acpi function. In this way
acpi_get_table(..) needs to be called only once. This will also aid in
dGPU topology implementation.
Signed-off-by: Harish Kasiviswanathan <Harish.Kasiviswanathan@amd.com>
Signed-off-by: Kent Russell <kent.russell@amd.com>
Signed-off-by: Felix Kuehling <Felix.Kuehling@amd.com>
Reviewed-by: Oded Gabbay <oded.gabbay@gmail.com>
Signed-off-by: Oded Gabbay <oded.gabbay@gmail.com>
-rw-r--r-- | drivers/gpu/drm/amd/amdkfd/kfd_crat.c | 41 | ||||
-rw-r--r-- | drivers/gpu/drm/amd/amdkfd/kfd_crat.h | 3 | ||||
-rw-r--r-- | drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 40 |
3 files changed, 54 insertions, 30 deletions
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_crat.c b/drivers/gpu/drm/amd/amdkfd/kfd_crat.c index f2dda6012b77..aa754c1ff682 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_crat.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_crat.c | |||
@@ -319,17 +319,29 @@ int kfd_parse_crat_table(void *crat_image) | |||
319 | return 0; | 319 | return 0; |
320 | } | 320 | } |
321 | 321 | ||
322 | int kfd_topology_get_crat_acpi(void *crat_image, size_t *size) | 322 | /* |
323 | * kfd_create_crat_image_acpi - Allocates memory for CRAT image and | ||
324 | * copies CRAT from ACPI (if available). | ||
325 | * NOTE: Call kfd_destroy_crat_image to free CRAT image memory | ||
326 | * | ||
327 | * @crat_image: CRAT read from ACPI. If no CRAT in ACPI then | ||
328 | * crat_image will be NULL | ||
329 | * @size: [OUT] size of crat_image | ||
330 | * | ||
331 | * Return 0 if successful else return error code | ||
332 | */ | ||
333 | int kfd_create_crat_image_acpi(void **crat_image, size_t *size) | ||
323 | { | 334 | { |
324 | struct acpi_table_header *crat_table; | 335 | struct acpi_table_header *crat_table; |
325 | acpi_status status; | 336 | acpi_status status; |
337 | void *pcrat_image; | ||
326 | 338 | ||
327 | if (!size) | 339 | if (!crat_image) |
328 | return -EINVAL; | 340 | return -EINVAL; |
329 | 341 | ||
330 | /* | 342 | *crat_image = NULL; |
331 | * Fetch the CRAT table from ACPI | 343 | |
332 | */ | 344 | /* Fetch the CRAT table from ACPI */ |
333 | status = acpi_get_table(CRAT_SIGNATURE, 0, &crat_table); | 345 | status = acpi_get_table(CRAT_SIGNATURE, 0, &crat_table); |
334 | if (status == AE_NOT_FOUND) { | 346 | if (status == AE_NOT_FOUND) { |
335 | pr_warn("CRAT table not found\n"); | 347 | pr_warn("CRAT table not found\n"); |
@@ -341,10 +353,25 @@ int kfd_topology_get_crat_acpi(void *crat_image, size_t *size) | |||
341 | return -EINVAL; | 353 | return -EINVAL; |
342 | } | 354 | } |
343 | 355 | ||
344 | if (*size >= crat_table->length && crat_image != NULL) | 356 | pcrat_image = kmalloc(crat_table->length, GFP_KERNEL); |
345 | memcpy(crat_image, crat_table, crat_table->length); | 357 | if (!pcrat_image) |
358 | return -ENOMEM; | ||
359 | |||
360 | memcpy(pcrat_image, crat_table, crat_table->length); | ||
346 | 361 | ||
362 | *crat_image = pcrat_image; | ||
347 | *size = crat_table->length; | 363 | *size = crat_table->length; |
348 | 364 | ||
349 | return 0; | 365 | return 0; |
350 | } | 366 | } |
367 | |||
368 | /* | ||
369 | * kfd_destroy_crat_image | ||
370 | * | ||
371 | * @crat_image: [IN] - crat_image from kfd_create_crat_image_xxx(..) | ||
372 | * | ||
373 | */ | ||
374 | void kfd_destroy_crat_image(void *crat_image) | ||
375 | { | ||
376 | kfree(crat_image); | ||
377 | } | ||
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_crat.h b/drivers/gpu/drm/amd/amdkfd/kfd_crat.h index 920697b4469b..da83105d127d 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_crat.h +++ b/drivers/gpu/drm/amd/amdkfd/kfd_crat.h | |||
@@ -291,7 +291,8 @@ struct cdit_header { | |||
291 | 291 | ||
292 | #pragma pack() | 292 | #pragma pack() |
293 | 293 | ||
294 | int kfd_topology_get_crat_acpi(void *crat_image, size_t *size); | 294 | int kfd_create_crat_image_acpi(void **crat_image, size_t *size); |
295 | void kfd_destroy_crat_image(void *crat_image); | ||
295 | int kfd_parse_crat_table(void *crat_image); | 296 | int kfd_parse_crat_table(void *crat_image); |
296 | 297 | ||
297 | #endif /* KFD_CRAT_H_INCLUDED */ | 298 | #endif /* KFD_CRAT_H_INCLUDED */ |
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_topology.c b/drivers/gpu/drm/amd/amdkfd/kfd_topology.c index b6cf785d0138..35da4af28c87 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_topology.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_topology.c | |||
@@ -699,35 +699,31 @@ int kfd_topology_init(void) | |||
699 | /* | 699 | /* |
700 | * Get the CRAT image from the ACPI | 700 | * Get the CRAT image from the ACPI |
701 | */ | 701 | */ |
702 | ret = kfd_topology_get_crat_acpi(crat_image, &image_size); | 702 | ret = kfd_create_crat_image_acpi(&crat_image, &image_size); |
703 | if (ret == 0 && image_size > 0) { | 703 | if (!ret) { |
704 | pr_info("Found CRAT image with size=%zd\n", image_size); | 704 | ret = kfd_parse_crat_table(crat_image); |
705 | crat_image = kmalloc(image_size, GFP_KERNEL); | 705 | if (ret) |
706 | if (!crat_image) { | ||
707 | ret = -ENOMEM; | ||
708 | pr_err("No memory for allocating CRAT image\n"); | ||
709 | goto err; | 706 | goto err; |
710 | } | ||
711 | ret = kfd_topology_get_crat_acpi(crat_image, &image_size); | ||
712 | |||
713 | if (ret == 0) { | ||
714 | down_write(&topology_lock); | ||
715 | ret = kfd_parse_crat_table(crat_image); | ||
716 | if (ret == 0) | ||
717 | ret = kfd_topology_update_sysfs(); | ||
718 | up_write(&topology_lock); | ||
719 | } else { | ||
720 | pr_err("Couldn't get CRAT table size from ACPI\n"); | ||
721 | } | ||
722 | kfree(crat_image); | ||
723 | } else if (ret == -ENODATA) { | 707 | } else if (ret == -ENODATA) { |
708 | /* TODO: Create fake CRAT table */ | ||
724 | ret = 0; | 709 | ret = 0; |
710 | goto err; | ||
725 | } else { | 711 | } else { |
726 | pr_err("Couldn't get CRAT table size from ACPI\n"); | 712 | pr_err("Couldn't get CRAT table size from ACPI\n"); |
713 | goto err; | ||
727 | } | 714 | } |
728 | 715 | ||
716 | down_write(&topology_lock); | ||
717 | ret = kfd_topology_update_sysfs(); | ||
718 | up_write(&topology_lock); | ||
719 | |||
720 | if (!ret) | ||
721 | pr_info("Finished initializing topology\n"); | ||
722 | else | ||
723 | pr_err("Failed to update topology in sysfs ret=%d\n", ret); | ||
724 | |||
729 | err: | 725 | err: |
730 | pr_info("Finished initializing topology ret=%d\n", ret); | 726 | kfd_destroy_crat_image(crat_image); |
731 | return ret; | 727 | return ret; |
732 | } | 728 | } |
733 | 729 | ||
@@ -747,7 +743,7 @@ static void kfd_debug_print_topology(void) | |||
747 | pr_info("Node: %d\n", i); | 743 | pr_info("Node: %d\n", i); |
748 | pr_info("\tGPU assigned: %s\n", (dev->gpu ? "yes" : "no")); | 744 | pr_info("\tGPU assigned: %s\n", (dev->gpu ? "yes" : "no")); |
749 | pr_info("\tCPU count: %d\n", dev->node_props.cpu_cores_count); | 745 | pr_info("\tCPU count: %d\n", dev->node_props.cpu_cores_count); |
750 | pr_info("\tSIMD count: %d", dev->node_props.simd_count); | 746 | pr_info("\tSIMD count: %d\n", dev->node_props.simd_count); |
751 | i++; | 747 | i++; |
752 | } | 748 | } |
753 | } | 749 | } |