diff --git a/drivers/gpu/drm/agx/Kconfig b/drivers/gpu/drm/agx/Kconfig index 3a75b930b58530..51f73f219004ab 100644 --- a/drivers/gpu/drm/agx/Kconfig +++ b/drivers/gpu/drm/agx/Kconfig @@ -4,7 +4,6 @@ config DRM_AGX depends on DRM && ARCH_APPLE && APPLE_RTKIT select DRM_GEM_SHMEM_HELPER select DRM_SCHED - select CRYPTO_LIB_SHA256 help Compute-only DRM driver for the GPU in the Apple A12 (T8020). It boots the GPU firmware and runs compute jobs through the Asahi uAPI. diff --git a/drivers/gpu/drm/agx/agx_drv.c b/drivers/gpu/drm/agx/agx_drv.c index 43bfbce64be549..13f7a5718cf64b 100644 --- a/drivers/gpu/drm/agx/agx_drv.c +++ b/drivers/gpu/drm/agx/agx_drv.c @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include @@ -766,27 +765,33 @@ module_param_named(firmware, agx_firmware, charp, 0400); MODULE_PARM_DESC(firmware, "GPU firmware build iBoot loaded: 20g81 (16.6.1) or 21b91 (17.1.1); default: recognised from the firmware"); /* - * The GPU firmware builds this driver speaks, by the SHA-256 of their - * __TEXT segment (0x44000 bytes) as iBoot loads it: armfw_g11p's Mach-O, - * after its rkosftab header. Each is the same file on every A12 board that - * has the build (20G81: the iPhone XS, XS Max and XR; 21B91: the XR and - * iPad 8). + * The firmware builds this driver drives, recognised by the RTKit version + * string in the __TEXT segment (0x44000 bytes) iBoot loaded. iBoot does not + * load __TEXT byte for byte as the IPSW has it (a hash of the loaded copy + * differs from the file's), but its strings are unchanged. Each build is the + * same file on every A12 board that has it (20G81: the iPhone XS, XS Max and + * XR; 21B91: the XR and iPad 8). */ #define AGX_FW_TEXT_SIZE 0x44000 static const struct { const char *build; - u8 text[SHA256_DIGEST_SIZE]; + const char *rtkit; } agx_known_firmware[] = { - { "20g81", { 0x80, 0x47, 0x72, 0x3b, 0xc6, 0xdb, 0x37, 0x48, - 0x9d, 0xc7, 0xf7, 0x50, 0xc5, 0xdc, 0x44, 0xf3, - 0xf5, 0xef, 0xa8, 0x26, 0xb3, 0xbb, 0xd7, 0xe9, - 0x38, 0x1b, 0x77, 0x35, 0x96, 0xaa, 0x83, 0xa0 } }, - { "21b91", { 0xc6, 0x3d, 0x55, 0xb5, 0xa3, 0x11, 0x33, 0xfd, - 0x9f, 0x18, 0x19, 0x47, 0x1d, 0x97, 0x50, 0x41, - 0x9c, 0x68, 0x4c, 0x57, 0x6c, 0x9b, 0xb0, 0x93, - 0xa9, 0x1f, 0x7f, 0xa3, 0x72, 0xbe, 0xd9, 0x3d } }, + { "20g81", "RTKit-2062.142.1.release" }, + { "21b91", "RTKit-2413.42.1.release" }, }; +/* Whether the loaded __TEXT holds the string @v */ +static bool agx_text_has(const void *text, const char *v) +{ + size_t n = strlen(v), i; + + for (i = 0; i + n <= AGX_FW_TEXT_SIZE; i++) + if (!memcmp(text + i, v, n)) + return true; + return false; +} + /* One entry of apple,segment-ranges: {phys, iova, remap, size, flags}. */ struct agx_segment_range { __le64 phys; @@ -805,7 +810,6 @@ static const char *agx_firmware_build(struct device *dev) { const struct agx_segment_range *seg; const char *build; - u8 digest[SHA256_DIGEST_SIZE]; int len, i, j; if (agx_firmware[0]) @@ -821,16 +825,18 @@ static const char *agx_firmware_build(struct device *dev) text = memremap(le64_to_cpu(seg[i].phys), AGX_FW_TEXT_SIZE, MEMREMAP_WB); if (!text) continue; - sha256(text, AGX_FW_TEXT_SIZE, digest); - memunmap(text); for (j = 0; j < ARRAY_SIZE(agx_known_firmware); j++) { - if (!memcmp(digest, agx_known_firmware[j].text, sizeof(digest))) { - dev_info(dev, "GPU firmware %s\n", agx_known_firmware[j].build); + const char *v = agx_known_firmware[j].rtkit; + + if (agx_text_has(text, v)) { + memunmap(text); + dev_info(dev, "GPU firmware %s (%s)\n", + agx_known_firmware[j].build, v); return agx_known_firmware[j].build; } } - dev_warn(dev, "GPU firmware not one this driver knows (__TEXT %*phN)\n", - 8, digest); + memunmap(text); + dev_warn(dev, "GPU firmware has no RTKit version this driver knows\n"); } if (!of_property_read_string(dev->of_node, "apple,firmware-build", &build)) return build;