Commit 8e05247d authored by Harish Kasiviswanathan's avatar Harish Kasiviswanathan Committed by Oded Gabbay

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: default avatarHarish Kasiviswanathan <Harish.Kasiviswanathan@amd.com>
Signed-off-by: default avatarKent Russell <kent.russell@amd.com>
Signed-off-by: default avatarFelix Kuehling <Felix.Kuehling@amd.com>
Reviewed-by: default avatarOded Gabbay <oded.gabbay@gmail.com>
Signed-off-by: default avatarOded Gabbay <oded.gabbay@gmail.com>
parent 174de876
...@@ -319,17 +319,29 @@ int kfd_parse_crat_table(void *crat_image) ...@@ -319,17 +319,29 @@ int kfd_parse_crat_table(void *crat_image)
return 0; return 0;
} }
int kfd_topology_get_crat_acpi(void *crat_image, size_t *size) /*
* kfd_create_crat_image_acpi - Allocates memory for CRAT image and
* copies CRAT from ACPI (if available).
* NOTE: Call kfd_destroy_crat_image to free CRAT image memory
*
* @crat_image: CRAT read from ACPI. If no CRAT in ACPI then
* crat_image will be NULL
* @size: [OUT] size of crat_image
*
* Return 0 if successful else return error code
*/
int kfd_create_crat_image_acpi(void **crat_image, size_t *size)
{ {
struct acpi_table_header *crat_table; struct acpi_table_header *crat_table;
acpi_status status; acpi_status status;
void *pcrat_image;
if (!size) if (!crat_image)
return -EINVAL; return -EINVAL;
/* *crat_image = NULL;
* Fetch the CRAT table from ACPI
*/ /* Fetch the CRAT table from ACPI */
status = acpi_get_table(CRAT_SIGNATURE, 0, &crat_table); status = acpi_get_table(CRAT_SIGNATURE, 0, &crat_table);
if (status == AE_NOT_FOUND) { if (status == AE_NOT_FOUND) {
pr_warn("CRAT table not found\n"); pr_warn("CRAT table not found\n");
...@@ -341,10 +353,25 @@ int kfd_topology_get_crat_acpi(void *crat_image, size_t *size) ...@@ -341,10 +353,25 @@ int kfd_topology_get_crat_acpi(void *crat_image, size_t *size)
return -EINVAL; return -EINVAL;
} }
if (*size >= crat_table->length && crat_image != NULL) pcrat_image = kmalloc(crat_table->length, GFP_KERNEL);
memcpy(crat_image, crat_table, crat_table->length); if (!pcrat_image)
return -ENOMEM;
memcpy(pcrat_image, crat_table, crat_table->length);
*crat_image = pcrat_image;
*size = crat_table->length; *size = crat_table->length;
return 0; return 0;
} }
/*
* kfd_destroy_crat_image
*
* @crat_image: [IN] - crat_image from kfd_create_crat_image_xxx(..)
*
*/
void kfd_destroy_crat_image(void *crat_image)
{
kfree(crat_image);
}
...@@ -291,7 +291,8 @@ struct cdit_header { ...@@ -291,7 +291,8 @@ struct cdit_header {
#pragma pack() #pragma pack()
int kfd_topology_get_crat_acpi(void *crat_image, size_t *size); int kfd_create_crat_image_acpi(void **crat_image, size_t *size);
void kfd_destroy_crat_image(void *crat_image);
int kfd_parse_crat_table(void *crat_image); int kfd_parse_crat_table(void *crat_image);
#endif /* KFD_CRAT_H_INCLUDED */ #endif /* KFD_CRAT_H_INCLUDED */
...@@ -699,35 +699,31 @@ int kfd_topology_init(void) ...@@ -699,35 +699,31 @@ int kfd_topology_init(void)
/* /*
* Get the CRAT image from the ACPI * Get the CRAT image from the ACPI
*/ */
ret = kfd_topology_get_crat_acpi(crat_image, &image_size); ret = kfd_create_crat_image_acpi(&crat_image, &image_size);
if (ret == 0 && image_size > 0) { if (!ret) {
pr_info("Found CRAT image with size=%zd\n", image_size); ret = kfd_parse_crat_table(crat_image);
crat_image = kmalloc(image_size, GFP_KERNEL); if (ret)
if (!crat_image) {
ret = -ENOMEM;
pr_err("No memory for allocating CRAT image\n");
goto err; goto err;
}
ret = kfd_topology_get_crat_acpi(crat_image, &image_size);
if (ret == 0) {
down_write(&topology_lock);
ret = kfd_parse_crat_table(crat_image);
if (ret == 0)
ret = kfd_topology_update_sysfs();
up_write(&topology_lock);
} else {
pr_err("Couldn't get CRAT table size from ACPI\n");
}
kfree(crat_image);
} else if (ret == -ENODATA) { } else if (ret == -ENODATA) {
/* TODO: Create fake CRAT table */
ret = 0; ret = 0;
goto err;
} else { } else {
pr_err("Couldn't get CRAT table size from ACPI\n"); pr_err("Couldn't get CRAT table size from ACPI\n");
goto err;
} }
down_write(&topology_lock);
ret = kfd_topology_update_sysfs();
up_write(&topology_lock);
if (!ret)
pr_info("Finished initializing topology\n");
else
pr_err("Failed to update topology in sysfs ret=%d\n", ret);
err: err:
pr_info("Finished initializing topology ret=%d\n", ret); kfd_destroy_crat_image(crat_image);
return ret; return ret;
} }
...@@ -747,7 +743,7 @@ static void kfd_debug_print_topology(void) ...@@ -747,7 +743,7 @@ static void kfd_debug_print_topology(void)
pr_info("Node: %d\n", i); pr_info("Node: %d\n", i);
pr_info("\tGPU assigned: %s\n", (dev->gpu ? "yes" : "no")); pr_info("\tGPU assigned: %s\n", (dev->gpu ? "yes" : "no"));
pr_info("\tCPU count: %d\n", dev->node_props.cpu_cores_count); pr_info("\tCPU count: %d\n", dev->node_props.cpu_cores_count);
pr_info("\tSIMD count: %d", dev->node_props.simd_count); pr_info("\tSIMD count: %d\n", dev->node_props.simd_count);
i++; i++;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment