|
23 | 23 | * |
24 | 24 | */ |
25 | 25 |
|
| 26 | +#include <linux/firmware.h> |
26 | 27 | #include "amdgpu.h" |
27 | 28 | #include "amdgpu_gfx.h" |
28 | 29 | #include "amdgpu_rlc.h" |
@@ -865,3 +866,142 @@ int amdgpu_gfx_get_num_kcq(struct amdgpu_device *adev) |
865 | 866 | } |
866 | 867 | return amdgpu_num_kcq; |
867 | 868 | } |
| 869 | + |
| 870 | +void amdgpu_gfx_cp_init_microcode(struct amdgpu_device *adev, |
| 871 | + uint32_t ucode_id) |
| 872 | +{ |
| 873 | + const struct gfx_firmware_header_v1_0 *cp_hdr; |
| 874 | + const struct gfx_firmware_header_v2_0 *cp_hdr_v2_0; |
| 875 | + struct amdgpu_firmware_info *info = NULL; |
| 876 | + const struct firmware *ucode_fw; |
| 877 | + unsigned int fw_size; |
| 878 | + |
| 879 | + switch (ucode_id) { |
| 880 | + case AMDGPU_UCODE_ID_CP_PFP: |
| 881 | + cp_hdr = (const struct gfx_firmware_header_v1_0 *) |
| 882 | + adev->gfx.pfp_fw->data; |
| 883 | + adev->gfx.pfp_fw_version = |
| 884 | + le32_to_cpu(cp_hdr->header.ucode_version); |
| 885 | + adev->gfx.pfp_feature_version = |
| 886 | + le32_to_cpu(cp_hdr->ucode_feature_version); |
| 887 | + ucode_fw = adev->gfx.pfp_fw; |
| 888 | + fw_size = le32_to_cpu(cp_hdr->header.ucode_size_bytes); |
| 889 | + break; |
| 890 | + case AMDGPU_UCODE_ID_CP_RS64_PFP: |
| 891 | + cp_hdr_v2_0 = (const struct gfx_firmware_header_v2_0 *) |
| 892 | + adev->gfx.pfp_fw->data; |
| 893 | + adev->gfx.pfp_fw_version = |
| 894 | + le32_to_cpu(cp_hdr_v2_0->header.ucode_version); |
| 895 | + adev->gfx.pfp_feature_version = |
| 896 | + le32_to_cpu(cp_hdr_v2_0->ucode_feature_version); |
| 897 | + ucode_fw = adev->gfx.pfp_fw; |
| 898 | + fw_size = le32_to_cpu(cp_hdr_v2_0->ucode_size_bytes); |
| 899 | + break; |
| 900 | + case AMDGPU_UCODE_ID_CP_RS64_PFP_P0_STACK: |
| 901 | + case AMDGPU_UCODE_ID_CP_RS64_PFP_P1_STACK: |
| 902 | + cp_hdr_v2_0 = (const struct gfx_firmware_header_v2_0 *) |
| 903 | + adev->gfx.pfp_fw->data; |
| 904 | + ucode_fw = adev->gfx.pfp_fw; |
| 905 | + fw_size = le32_to_cpu(cp_hdr_v2_0->data_size_bytes); |
| 906 | + break; |
| 907 | + case AMDGPU_UCODE_ID_CP_ME: |
| 908 | + cp_hdr = (const struct gfx_firmware_header_v1_0 *) |
| 909 | + adev->gfx.me_fw->data; |
| 910 | + adev->gfx.me_fw_version = |
| 911 | + le32_to_cpu(cp_hdr->header.ucode_version); |
| 912 | + adev->gfx.me_feature_version = |
| 913 | + le32_to_cpu(cp_hdr->ucode_feature_version); |
| 914 | + ucode_fw = adev->gfx.me_fw; |
| 915 | + fw_size = le32_to_cpu(cp_hdr->header.ucode_size_bytes); |
| 916 | + break; |
| 917 | + case AMDGPU_UCODE_ID_CP_RS64_ME: |
| 918 | + cp_hdr_v2_0 = (const struct gfx_firmware_header_v2_0 *) |
| 919 | + adev->gfx.me_fw->data; |
| 920 | + adev->gfx.me_fw_version = |
| 921 | + le32_to_cpu(cp_hdr_v2_0->header.ucode_version); |
| 922 | + adev->gfx.me_feature_version = |
| 923 | + le32_to_cpu(cp_hdr_v2_0->ucode_feature_version); |
| 924 | + ucode_fw = adev->gfx.me_fw; |
| 925 | + fw_size = le32_to_cpu(cp_hdr_v2_0->ucode_size_bytes); |
| 926 | + break; |
| 927 | + case AMDGPU_UCODE_ID_CP_RS64_ME_P0_STACK: |
| 928 | + case AMDGPU_UCODE_ID_CP_RS64_ME_P1_STACK: |
| 929 | + cp_hdr_v2_0 = (const struct gfx_firmware_header_v2_0 *) |
| 930 | + adev->gfx.me_fw->data; |
| 931 | + ucode_fw = adev->gfx.me_fw; |
| 932 | + fw_size = le32_to_cpu(cp_hdr_v2_0->data_size_bytes); |
| 933 | + break; |
| 934 | + case AMDGPU_UCODE_ID_CP_CE: |
| 935 | + cp_hdr = (const struct gfx_firmware_header_v1_0 *) |
| 936 | + adev->gfx.ce_fw->data; |
| 937 | + adev->gfx.ce_fw_version = |
| 938 | + le32_to_cpu(cp_hdr->header.ucode_version); |
| 939 | + adev->gfx.ce_feature_version = |
| 940 | + le32_to_cpu(cp_hdr->ucode_feature_version); |
| 941 | + ucode_fw = adev->gfx.ce_fw; |
| 942 | + fw_size = le32_to_cpu(cp_hdr->header.ucode_size_bytes); |
| 943 | + break; |
| 944 | + case AMDGPU_UCODE_ID_CP_MEC1: |
| 945 | + cp_hdr = (const struct gfx_firmware_header_v1_0 *) |
| 946 | + adev->gfx.mec_fw->data; |
| 947 | + adev->gfx.mec_fw_version = |
| 948 | + le32_to_cpu(cp_hdr->header.ucode_version); |
| 949 | + adev->gfx.mec_feature_version = |
| 950 | + le32_to_cpu(cp_hdr->ucode_feature_version); |
| 951 | + ucode_fw = adev->gfx.mec_fw; |
| 952 | + fw_size = le32_to_cpu(cp_hdr->header.ucode_size_bytes) - |
| 953 | + le32_to_cpu(cp_hdr->jt_size) * 4; |
| 954 | + break; |
| 955 | + case AMDGPU_UCODE_ID_CP_MEC1_JT: |
| 956 | + cp_hdr = (const struct gfx_firmware_header_v1_0 *) |
| 957 | + adev->gfx.mec_fw->data; |
| 958 | + ucode_fw = adev->gfx.mec_fw; |
| 959 | + fw_size = le32_to_cpu(cp_hdr->jt_size) * 4; |
| 960 | + break; |
| 961 | + case AMDGPU_UCODE_ID_CP_MEC2: |
| 962 | + cp_hdr = (const struct gfx_firmware_header_v1_0 *) |
| 963 | + adev->gfx.mec2_fw->data; |
| 964 | + adev->gfx.mec2_fw_version = |
| 965 | + le32_to_cpu(cp_hdr->header.ucode_version); |
| 966 | + adev->gfx.mec2_feature_version = |
| 967 | + le32_to_cpu(cp_hdr->ucode_feature_version); |
| 968 | + ucode_fw = adev->gfx.mec2_fw; |
| 969 | + fw_size = le32_to_cpu(cp_hdr->header.ucode_size_bytes) - |
| 970 | + le32_to_cpu(cp_hdr->jt_size) * 4; |
| 971 | + break; |
| 972 | + case AMDGPU_UCODE_ID_CP_MEC2_JT: |
| 973 | + cp_hdr = (const struct gfx_firmware_header_v1_0 *) |
| 974 | + adev->gfx.mec2_fw->data; |
| 975 | + ucode_fw = adev->gfx.mec2_fw; |
| 976 | + fw_size = le32_to_cpu(cp_hdr->jt_size) * 4; |
| 977 | + break; |
| 978 | + case AMDGPU_UCODE_ID_CP_RS64_MEC: |
| 979 | + cp_hdr_v2_0 = (const struct gfx_firmware_header_v2_0 *) |
| 980 | + adev->gfx.mec_fw->data; |
| 981 | + adev->gfx.mec_fw_version = |
| 982 | + le32_to_cpu(cp_hdr_v2_0->header.ucode_version); |
| 983 | + adev->gfx.mec_feature_version = |
| 984 | + le32_to_cpu(cp_hdr_v2_0->ucode_feature_version); |
| 985 | + ucode_fw = adev->gfx.mec_fw; |
| 986 | + fw_size = le32_to_cpu(cp_hdr_v2_0->ucode_size_bytes); |
| 987 | + break; |
| 988 | + case AMDGPU_UCODE_ID_CP_RS64_MEC_P0_STACK: |
| 989 | + case AMDGPU_UCODE_ID_CP_RS64_MEC_P1_STACK: |
| 990 | + case AMDGPU_UCODE_ID_CP_RS64_MEC_P2_STACK: |
| 991 | + case AMDGPU_UCODE_ID_CP_RS64_MEC_P3_STACK: |
| 992 | + cp_hdr_v2_0 = (const struct gfx_firmware_header_v2_0 *) |
| 993 | + adev->gfx.mec_fw->data; |
| 994 | + ucode_fw = adev->gfx.mec_fw; |
| 995 | + fw_size = le32_to_cpu(cp_hdr_v2_0->data_size_bytes); |
| 996 | + break; |
| 997 | + default: |
| 998 | + break; |
| 999 | + } |
| 1000 | + |
| 1001 | + if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP) { |
| 1002 | + info = &adev->firmware.ucode[ucode_id]; |
| 1003 | + info->ucode_id = ucode_id; |
| 1004 | + info->fw = ucode_fw; |
| 1005 | + adev->firmware.fw_size += ALIGN(fw_size, PAGE_SIZE); |
| 1006 | + } |
| 1007 | +} |
0 commit comments