| 92 | } |
| 93 | |
| 94 | static ApirLoadLibraryReturnCode virtgpu_load_library(virtgpu * gpu) { |
| 95 | apir_encoder * encoder; |
| 96 | apir_decoder * decoder; |
| 97 | ApirLoadLibraryReturnCode ret; |
| 98 | |
| 99 | encoder = remote_call_prepare(gpu, APIR_COMMAND_TYPE_LOADLIBRARY, 0); |
| 100 | if (!encoder) { |
| 101 | GGML_ABORT(GGML_VIRTGPU "%s: hypercall error: failed to prepare the API Remoting command encoder", __func__); |
| 102 | return APIR_LOAD_LIBRARY_HYPERCALL_INITIALIZATION_ERROR; |
| 103 | } |
| 104 | |
| 105 | long long call_duration_ns; |
| 106 | |
| 107 | ret = (ApirLoadLibraryReturnCode) remote_call(gpu, encoder, &decoder, APIR_LOADLIBRARY_MAX_WAIT_MS, |
| 108 | &call_duration_ns); |
| 109 | log_call_duration(call_duration_ns, "API Remoting LoadLibrary"); |
| 110 | |
| 111 | if (!decoder) { |
| 112 | GGML_ABORT(GGML_VIRTGPU "%s: hypercall error: failed to trigger the API Remoting hypercall.\n", __func__); |
| 113 | return APIR_LOAD_LIBRARY_HYPERCALL_INITIALIZATION_ERROR; |
| 114 | } |
| 115 | |
| 116 | remote_call_finish(gpu, encoder, decoder); |
| 117 | |
| 118 | if (ret == APIR_LOAD_LIBRARY_SUCCESS) { |
| 119 | GGML_LOG_INFO(GGML_VIRTGPU "The API Remoting backend was successfully loaded and initialized\n"); |
| 120 | |
| 121 | return ret; |
| 122 | } |
| 123 | |
| 124 | // something wrong happened, find out what. |
| 125 | if (ret < APIR_LOAD_LIBRARY_INIT_BASE_INDEX) { |
| 126 | if (ret == APIR_LOAD_LIBRARY_ENV_VAR_MISSING) { |
| 127 | GGML_ABORT(GGML_VIRTGPU |
| 128 | "%s: virglrenderer could not open the API Remoting backend library, " |
| 129 | "some environment variables are missing. " |
| 130 | "Make sure virglrenderer is correctly configured by the hypervisor. (%s)", |
| 131 | __func__, apir_load_library_error(ret)); |
| 132 | } else if (ret == APIR_LOAD_LIBRARY_CANNOT_OPEN) { |
| 133 | GGML_ABORT(GGML_VIRTGPU |
| 134 | "%s: virglrenderer could not open the API Remoting backend library. " |
| 135 | "Make sure virglrenderer is correctly configured by the hypervisor. (%s)", |
| 136 | __func__, apir_load_library_error(ret)); |
| 137 | } else if (ret == APIR_LOAD_LIBRARY_ENV_VAR_MISSING) { |
| 138 | GGML_ABORT(GGML_VIRTGPU |
| 139 | "%s: could not load the backend library, some symbols are missing. " |
| 140 | "Make sure virglrenderer is correctly configured by the hypervisor. (%s) ", |
| 141 | __func__, apir_load_library_error(ret)); |
| 142 | } else { |
| 143 | GGML_ABORT(GGML_VIRTGPU "%s: virglrenderer could not load the API Remoting backend library. (%s - code %d)", |
| 144 | __func__, apir_load_library_error(ret), ret); |
| 145 | } |
| 146 | return ret; |
| 147 | } |
| 148 | |
| 149 | GGML_LOG_INFO(GGML_VIRTGPU "%s: virglrenderer successfully loaded the API Remoting backend library.\n", __func__); |
| 150 | |
| 151 | ApirLoadLibraryReturnCode apir_ret = (ApirLoadLibraryReturnCode) (ret - APIR_LOAD_LIBRARY_INIT_BASE_INDEX); |
no test coverage detected