# Enable graphics acceleration on Raspberry Pi 4B ###### tags: `Raspberry Pi` `Linux Kernel` `DRM` `GPU` **Note:** This is a test report, not an official solution yet. Thanks to the ecosystem's effort. The pure Linux mainline kernel (not RPi OS kernel) works well on Raspberry Pi 4B 4GB, which I have on hands. System boots up, gets into GNOME desktop environment, has the VC4 DRM driver, connects to the HDMI (including HDMI audio). The ethernet & WiFi work as well. It is **"almost"** good to be a normal computer for daily usage now. Why it is **"almost"**??? Because, it lacks the driver to support the V3D GPU on BCM2711, which will make the UI acting more smoothly. Stefan has listed the supporting status at "[Upstream Raspberry Pi 4 B support](https://github.com/lategoodbye/rpi-zero/issues/43)". In Febuaraury of this year, Nicolas sent out the patch series "[RFC/PATCH,00/11] [Raspberry PI 4 V3D enablement](https://patchwork.kernel.org/project/linux-arm-kernel/cover/20210205135249.2924-1-nsaenzjulienne@suse.de/)". Following that, a few days later, there is the new patch series "[v3,00/15] [Raspberry PI 4 V3D enablement](https://patchwork.kernel.org/project/linux-arm-kernel/cover/20210217114811.22069-1-nsaenzjulienne@suse.de/)". Earlier this month, I participated in #EndlessOrangeWeek, a program where the entire Endless team engages in projects designed to grow our collective learning related to our skills, work and mission. I chose this topic to test the GPU on Raspberry Pi 4B. ## Build the kernel I applied the v3 patch series based on [mainline Linux kernel at tags/v5.15](https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/log/?h=v5.15). Then tested the modified kernel with [Ubuntu 21.10 RPi 4B image](https://ubuntu.com/download/raspberry-pi) by replacing the kernel, device tree blob and initrd. #### Applied cleanly: * [v3,01/15] [dt-bindings: soc: bcm: bcm2835-pm: Convert bindings to DT schema](https://patchwork.kernel.org/project/linux-arm-kernel/patch/20210217114811.22069-2-nsaenzjulienne@suse.de/) * [v3,02/15] [dt-bindings: soc: bcm: bcm2835-pm: Introduce reg-names](https://patchwork.kernel.org/project/linux-arm-kernel/patch/20210217114811.22069-3-nsaenzjulienne@suse.de/) * [v3,03/15] [dt-bindings: soc: bcm: bcm2835-pm: Add support for bcm2711](https://patchwork.kernel.org/project/linux-arm-kernel/patch/20210217114811.22069-4-nsaenzjulienne@suse.de/) * [v3,04/15] [ARM: dts: bcm2835/bcm2711: Introduce reg-names in watchdog node](https://patchwork.kernel.org/project/linux-arm-kernel/patch/20210217114811.22069-5-nsaenzjulienne@suse.de/) * [v3,05/15] [ARM: dts: bcm2711: Use proper compatible in PM/Watchdog node](https://patchwork.kernel.org/project/linux-arm-kernel/patch/20210217114811.22069-6-nsaenzjulienne@suse.de/) * [v3,06/15] [mfd: bcm2835-pm: Use 'reg-names' to get resources](https://patchwork.kernel.org/project/linux-arm-kernel/patch/20210217114811.22069-7-nsaenzjulienne@suse.de/) * [v3,07/15] [mfd: bcm2835-pm: Add support for BCM2711](https://patchwork.kernel.org/project/linux-arm-kernel/patch/20210217114811.22069-8-nsaenzjulienne@suse.de/) * [v3,08/15] [soc: bcm: bcm2835-power: Add support for BCM2711's RPiVid ASB](https://patchwork.kernel.org/project/linux-arm-kernel/patch/20210217114811.22069-9-nsaenzjulienne@suse.de/) * [v3,09/15] [soc: bcm: bcm2835-power: Bypass power_on/off() calls](https://patchwork.kernel.org/project/linux-arm-kernel/patch/20210217114811.22069-10-nsaenzjulienne@suse.de/) * [v3,10/15] [dt-bindings: gpu: v3d: Add BCM2711's compatible](https://patchwork.kernel.org/project/linux-arm-kernel/patch/20210217114811.22069-11-nsaenzjulienne@suse.de/) * [v3,13/15] [ARM: dts: bcm2711: Enable V3D](https://patchwork.kernel.org/project/linux-arm-kernel/patch/20210217114811.22069-14-nsaenzjulienne@suse.de/) #### Fixed conflict and applied: * [v3,11/15] [drm/v3d: Get rid of pm code](https://patchwork.kernel.org/project/linux-arm-kernel/patch/20210217114811.22069-12-nsaenzjulienne@suse.de/) * [v3,12/15] [drm/v3d: Add support for bcm2711](https://patchwork.kernel.org/project/linux-arm-kernel/patch/20210217114811.22069-13-nsaenzjulienne@suse.de/) #### Just the build config: * [v3,14/15] [ARM: configs: Enable DRM_V3D](https://patchwork.kernel.org/project/linux-arm-kernel/patch/20210217114811.22069-15-nsaenzjulienne@suse.de/) * [v3,15/15] [arm64: config: Enable DRM_V3D](https://patchwork.kernel.org/project/linux-arm-kernel/patch/20210217114811.22069-16-nsaenzjulienne@suse.de/) Here is my test repository: https://github.com/starnight/linux/tree/v3d-5.15 The kernel is built as aarch64 architecture with enabled `CONFIG_DRM_V3D` and `CONFIG_DRM_VC4`. Then, install the kernel, initrd and device tree blob into the boot partion. ## Prepare the system boot path Edit the **config.txt** to use the modified kernel and initrd. ``` kernel=vmlinux-5.15.0+ initramfs initrd.imag-5.15.0+ followkernel ``` Comment all of the `dtoverlay` in **config.txt** as well. I use the device tree blob from the patched kernel for this test. Insert the SD card to Rasperry Pi 4B and power on! ## Check the V3D Seems the kernel initialized the V3D GPU. ```shell= $ dmesg | grep v3d [ 2.274145] [drm] Initialized v3d 1.0.0 20180419 for fec00000.gpu on minor 0 ``` The device tree has the GPU node. ```shell= $ cat /proc/device-tree/scb/gpu@7ec00000/compatible brcm,bcm2711-v3d ``` Mesa shows "`GL_RENDERER: V3D 4.2`"! ```shell= $ es2_info EGL_VERSION: 1.4 EGL_VENDOR: Mesa Project EGL_EXTENSIONS: EGL_ANDROID_blob_cache, EGL_CHROMIUM_sync_control, EGL_EXT_buffer_age, EGL_EXT_image_dma_buf_import, EGL_EXT_image_dma_buf_import_modifiers, EGL_EXT_swap_buffers_with_damage, EGL_KHR_cl_event2, EGL_KHR_config_attribs, EGL_KHR_create_context, EGL_KHR_create_context_no_error, EGL_KHR_fence_sync, EGL_KHR_get_all_proc_addresses, EGL_KHR_gl_colorspace, EGL_KHR_gl_renderbuffer_image, EGL_KHR_gl_texture_2D_image, EGL_KHR_gl_texture_3D_image, EGL_KHR_gl_texture_cubemap_image, EGL_KHR_image, EGL_KHR_image_base, EGL_KHR_image_pixmap, EGL_KHR_no_config_context, EGL_KHR_reusable_sync, EGL_KHR_surfaceless_context, EGL_KHR_swap_buffers_with_damage, EGL_EXT_pixel_format_float, EGL_KHR_wait_sync, EGL_MESA_configless_context, EGL_MESA_drm_image, EGL_MESA_image_dma_buf_export, EGL_MESA_query_driver, EGL_NOK_texture_from_pixmap EGL_CLIENT_APIS: OpenGL OpenGL_ES GL_VERSION: OpenGL ES 3.1 Mesa 21.2.2 GL_RENDERER: V3D 4.2 GL_EXTENSIONS: GL_EXT_blend_minmax, GL_EXT_multi_draw_arrays, GL_EXT_texture_compression_s3tc, GL_EXT_texture_compression_dxt1, GL_EXT_texture_format_BGRA8888, GL_OES_compressed_ETC1_RGB8_texture, GL_OES_depth24, GL_OES_element_index_uint, GL_OES_fbo_render_mipmap, GL_OES_mapbuffer, GL_OES_rgb8_rgba8, GL_OES_standard_derivatives, GL_OES_stencil8, GL_OES_texture_3D, GL_OES_texture_float, GL_OES_texture_half_float, GL_OES_texture_half_float_linear, GL_OES_texture_npot, GL_OES_vertex_half_float, GL_EXT_draw_instanced, GL_EXT_texture_sRGB_decode, GL_OES_EGL_image, GL_OES_depth_texture, GL_OES_packed_depth_stencil, GL_EXT_texture_type_2_10_10_10_REV, GL_OES_get_program_binary, GL_APPLE_texture_max_level, GL_EXT_discard_framebuffer, GL_EXT_read_format_bgra, GL_EXT_frag_depth, GL_NV_fbo_color_attachments, GL_OES_EGL_image_external, GL_OES_EGL_sync, GL_OES_vertex_array_object, GL_ANGLE_pack_reverse_row_order, GL_ANGLE_texture_compression_dxt3, GL_ANGLE_texture_compression_dxt5, GL_EXT_occlusion_query_boolean, GL_EXT_texture_rg, GL_EXT_unpack_subimage, GL_NV_draw_buffers, GL_NV_read_buffer, GL_NV_read_depth, GL_NV_read_depth_stencil, GL_NV_read_stencil, GL_EXT_draw_buffers, GL_EXT_map_buffer_range, GL_KHR_debug, GL_KHR_texture_compression_astc_ldr, GL_NV_pixel_buffer_object, GL_OES_depth_texture_cube_map, GL_OES_required_internalformat, GL_OES_surfaceless_context, GL_EXT_color_buffer_float, GL_EXT_sRGB_write_control, GL_EXT_separate_shader_objects, GL_EXT_shader_implicit_conversions, GL_EXT_shader_integer_mix, GL_EXT_base_instance, GL_EXT_compressed_ETC1_RGB8_sub_texture, GL_EXT_draw_elements_base_vertex, GL_EXT_primitive_bounding_box, GL_EXT_shader_io_blocks, GL_EXT_texture_border_clamp, GL_KHR_context_flush_control, GL_NV_image_formats, GL_OES_draw_elements_base_vertex, GL_OES_primitive_bounding_box, GL_OES_shader_io_blocks, GL_OES_texture_border_clamp, GL_OES_texture_stencil8, GL_OES_texture_storage_multisample_2d_array, GL_EXT_buffer_storage, GL_EXT_float_blend, GL_EXT_geometry_point_size, GL_EXT_geometry_shader, GL_KHR_no_error, GL_KHR_texture_compression_astc_sliced_3d, GL_OES_EGL_image_external_essl3, GL_OES_geometry_point_size, GL_OES_geometry_shader, GL_OES_shader_image_atomic, GL_EXT_texture_compression_s3tc_srgb, GL_MESA_shader_integer_functions, GL_KHR_parallel_shader_compile, GL_EXT_EGL_image_storage, GL_MESA_framebuffer_flip_y, GL_EXT_texture_query_lod, GL_MESA_bgra ``` Then, test it with `es2gears`. But, the UI becomes frozen some times and the kernel shows the error "`flip_done timed out`": ``` [drm:drm_crtc_commit_wait] *ERROR* flip_done timed out [drm:drm_atomic_helper_wait_for_flip_done] *ERROR* [CRTC:68:crtc-3] flip_done timed out [drm:drm_atomic_helper_wait_for_dependencies] *ERROR* [CRTC:68:crtc-3] commit wait timed out [drm:drm_crtc_commit_wait] *ERROR* flip_done timed out vc4-drm gpu: [drm] *ERROR* Timed out waiting for commit ``` I notice that this error happens when ever applications touch GL related things with ont only patched kernel, but also the pure mainline kernel. So, I filed this bug to upstream as "[VC4 DRM waiting for flip down makes UI freeze a while with kernel 5.15](https://bugzilla.kernel.org/show_bug.cgi?id=214991)". I found this error is related to the commits: * [f3c420fe19f8 ("drm/vc4: kms: Convert to atomic helpers")](https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=f3c420fe19f8cc39adf379365decf63167596dc3) * [82faa3276012 ("drm/vc4: kms: Remove async modeset semaphore")](https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=82faa3276012d272d930026e7666d978ef2c6fef) So, I reverted these two commits as a workaround. After this, the "flip_done timed out" error does not appear again. ![](https://hackmd.io/_uploads/BkouTudL3.png) Okay! Let's play the 3D game [OpenArena](http://openarena.ws/smfnews.php) for test!!! ![](https://hackmd.io/_uploads/ByHwp__82.png) It works better than without GPU! However, the resolution has to be downgraded to 1024x576 for example. Otherwise, the UI response will be so lag. ![](https://hackmd.io/_uploads/Hy6Ha_OIn.jpg) ![](https://hackmd.io/_uploads/r17L6ddI2.jpg) ## Recap * The v5.15 and latest mainline kernel with fixed conflict patches and fixed "flip_done timed out" bug can play the v3d gpu on Ubuntu 21.10. So, the device tree part & binding in the patch series are okay. * However, the patch [v3,11/15] [drm/v3d: Get rid of pm code](https://patchwork.kernel.org/project/linux-arm-kernel/patch/20210217114811.22069-12-nsaenzjulienne@suse.de/) makes me thinking: Is there any better way to do that. And, this might be why upstream did not merge the patch series. * Have to find out why the v3d gpu of modified kernel works with Ubuntu, but does not work with other distros, like Endless OS. Problems in mesa, libdrm, Xorg/Wayland or any other packages? ![](https://hackmd.io/_uploads/HyCX6u_82.png) * Mesa: Installed the same Mesa 21.2.2-1ubuntu1 * libdrm: Installed the same libdrm 2.4.107-8ubuntu1 * Xorg/Wayland (both run with Wayland): * Ubuntu Impish has xwayland 2:1.20.13-1ubuntu1 * Endless OS has xwayland 2:1.20.11-1endless1bem1