notro / gud

GUD USB Display
153 stars 7 forks source link

Ubuntu 22.04: USB replug doesn't work #13

Open notro opened 2 years ago

notro commented 2 years ago

Unplugging and then plugging in the adapter does not work. The display comes up as black and backlit. But when rebooting the splash comes up.

This was working on Ubuntu 20.04, but there the DRM device was not released so the DRM minor was bumped each time and not reused.

gnome-shell log:

pi@pi-ubuntu-x86:~$ journalctl -l --no-pager --boot /usr/bin/gnome-shell
april 28 13:02:31 pi-ubuntu-x86 gnome-shell[1088]: Running GNOME Shell (using mutter 42.0) as a Wayland display server
april 28 13:02:31 pi-ubuntu-x86 gnome-shell[1088]: Device '/dev/dri/card0' prefers shadow buffer
april 28 13:02:31 pi-ubuntu-x86 gnome-shell[1088]: Added device '/dev/dri/card0' (i915) using atomic mode setting.
april 28 13:02:31 pi-ubuntu-x86 gnome-shell[1088]: Created gbm renderer for '/dev/dri/card0'
april 28 13:02:31 pi-ubuntu-x86 gnome-shell[1088]: Boot VGA GPU /dev/dri/card0 selected as primary

april 28 13:02:36 pi-ubuntu-x86 gnome-shell[1088]: GNOME Shell started at Thu Apr 28 2022 13:02:34 GMT+0200 (CEST)

# plug in adapter

april 28 13:03:18 pi-ubuntu-x86 gnome-shell[1088]: Added device '/dev/dri/card1' (gud) using atomic mode setting.
april 28 13:03:18 pi-ubuntu-x86 gnome-shell[1088]: MESA-LOADER: failed to open gud: /usr/lib/dri/gud_dri.so: cannot open shared object file: No such file or directory (search paths /usr/lib/x86_64-linux-gnu/dri:\$${ORIGIN}/dri:/usr/lib/dri, suffix _dri)
april 28 13:03:18 pi-ubuntu-x86 gnome-shell[1088]: failed to load driver: gud
april 28 13:03:18 pi-ubuntu-x86 gnome-shell[1088]: Failed to initialize accelerated iGPU/dGPU framebuffer sharing: Not hardware accelerated
april 28 13:03:18 pi-ubuntu-x86 gnome-shell[1088]: Created gbm renderer for '/dev/dri/card1'

# plug out adapter

april 28 13:03:43 pi-ubuntu-x86 gnome-shell[1088]: drmModeRmFB: No such device
april 28 13:03:43 pi-ubuntu-x86 gnome-shell[1088]: Could not release device '/dev/dri/card1' (226,1): GDBus.Error:org.freedesktop.login1.DeviceNotTaken: Device not taken

# plug in adapter

april 28 13:04:20 pi-ubuntu-x86 gnome-shell[1088]: Failed to hotplug secondary gpu '/dev/dri/card1': device already present
april 28 13:04:20 pi-ubuntu-x86 gnome-shell[1088]: Failed to use suggested monitor configuration: No available CRTC for monitor 'SAM S24D590' not found
april 28 13:04:20 pi-ubuntu-x86 gnome-shell[1088]: Failed to use linear monitor configuration: No available CRTC for monitor 'SAM S24D590' not found
april 28 13:04:20 pi-ubuntu-x86 gnome-shell[1088]: Failed to use linear monitor configuration: No available CRTC for monitor 'SAM S24D590' not found

(full log)

The black display is controlled by fbdev (fbcon) as this shows:

# fills display with random pixels
$ sudo sh -c "cat /dev/random > /dev/fb1"

$ sudo cat /sys/kernel/debug/dri/1/state
plane[31]: plane-0
        crtc=crtc-0
        fb=44
                allocated by = [fbcon]
                refcount=2
                format=RG16 little-endian (0x36314752)
                modifier=0x0
                size=1920x1080
                layers:
                        size[0]=1920x1080
                        pitch[0]=3840
                        offset[0]=0
                        obj[0]:
                                name=0
                                refcount=3
                                start=00100000
                                size=4149248
                                imported=no
                                pages_use_count=0
                                vmap_use_count=0
                                vaddr=0000000000000000
        crtc-pos=1920x1080+0+0
        src-pos=1920.000000x1080.000000+0.000000+0.000000
        rotation=1
        normalized-zpos=0
        color-encoding=ITU-R BT.601 YCbCr
        color-range=YCbCr limited range
crtc[33]: crtc-0
        enable=1
        active=1
        self_refresh_active=0
        planes_changed=1
        mode_changed=1
        active_changed=1
        connectors_changed=1
        color_mgmt_changed=0
        plane_mask=1
        connector_mask=1
        encoder_mask=1
        mode: "1920x1080": 60 148500 1920 2008 2052 2200 1080 1084 1089 1125 0x48 0x5
connector[36]: HDMI-A-3
        crtc=crtc-0
        self_refresh_aware=0
connector[41]: HDMI-A-4
        crtc=(null)
        self_refresh_aware=0

gnome-shell has an fd open:

$ lsof /dev/dri/card1
COMMAND    PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
gnome-she 1088   pi   90u   CHR  226,1      0t0  893 /dev/dri/card1

kernel log:

$ sudo dmesg
[   57.954833] usb 2-3.1: new high-speed USB device number 7 using xhci_hcd
[   58.055802] usb 2-3.1: New USB device found, idVendor=1d50, idProduct=614d, bcdDevice= 1.00
[   58.055815] usb 2-3.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[   58.055821] usb 2-3.1: Product: Raspberry Pi 4 Display Gadget
[   58.055825] usb 2-3.1: Manufacturer: Raspberry Pi
[   58.055829] usb 2-3.1: SerialNumber: 100000003b40d6c6
[   58.081205] [drm] Initialized gud 1.0.0 20200422 for 2-3.1:1.0 on minor 1
[   58.111827] gud 2-3.1:1.0: [drm] fb1: guddrmfb frame buffer device
[   58.111900] usbcore: registered new interface driver gud
[   83.565261] usb 2-3.1: USB disconnect, device number 7
[  120.574149] usb 2-3.1: new high-speed USB device number 8 using xhci_hcd
[  120.675008] usb 2-3.1: New USB device found, idVendor=1d50, idProduct=614d, bcdDevice= 1.00
[  120.675023] usb 2-3.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[  120.675029] usb 2-3.1: Product: Raspberry Pi 4 Display Gadget
[  120.675033] usb 2-3.1: Manufacturer: Raspberry Pi
[  120.675037] usb 2-3.1: SerialNumber: 100000003b40d6c6
[  120.682448] [drm] Initialized gud 1.0.0 20200422 for 2-3.1:1.0 on minor 1
[  120.712974] gud 2-3.1:1.0: [drm] fb1: guddrmfb frame buffer device

This shows the reboot splash

$ sudo reboot

Do the same with debug enabled: /etc/environment

MUTTER_VERBOSE=1
MUTTER_DEBUG=1
MUTTER_USE_LOGFILE=1

log: https://gist.github.com/notro/a11be18408e9daddbf84b318f949e8e1

notro commented 2 years ago

I tried disabling fbdev for the USB adapter, to see if the 'No available CRTC for monitor' message went away. It didn't.

$ echo 0 | sudo tee /sys/module/drm_kms_helper/parameters/fbdev_emulation

# plug in, plug out, plug in

$ journalctl -l --no-pager --boot /usr/bin/gnome-shell -g "No available CRTC"
april 28 14:27:26 pi-ubuntu-x86 gnome-shell[1092]: Failed to use suggested monitor configuration: No available CRTC for monitor 'SAM S24D590' not found
april 28 14:27:26 pi-ubuntu-x86 gnome-shell[1092]: Failed to use linear monitor configuration: No available CRTC for monitor 'SAM S24D590' not found
april 28 14:27:27 pi-ubuntu-x86 gnome-shell[1092]: Failed to use linear monitor configuration: No available CRTC for monitor 'SAM S24D590' not found

$ sudo cat /sys/kernel/debug/dri/1/state
plane[31]: plane-0
        crtc=(null)
        fb=0
        crtc-pos=0x0+0+0
        src-pos=0.000000x0.000000+0.000000+0.000000
        rotation=1
        normalized-zpos=0
        color-encoding=ITU-R BT.601 YCbCr
        color-range=YCbCr limited range
crtc[33]: crtc-0
        enable=0
        active=0
        self_refresh_active=0
        planes_changed=0
        mode_changed=0
        active_changed=0
        connectors_changed=0
        color_mgmt_changed=0
        plane_mask=0
        connector_mask=0
        encoder_mask=0
        mode: "": 0 0 0 0 0 0 0 0 0 0 0x0 0x0
connector[36]: HDMI-A-3
        crtc=(null)
        self_refresh_aware=0
connector[41]: HDMI-A-4
        crtc=(null)
        self_refresh_aware=0
notro commented 9 months ago

Replug works on Fedora 38 but the DRM device is still not closed.

Nov 23 00:49:11 fedora-1 gnome-shell[1279]: Running GNOME Shell (using mutter 44.6) as a Wayland display server

# plug in

Dec 07 21:28:15 fedora-1 gnome-shell[2194]: MESA-LOADER: failed to open gud: /usr/lib64/dri/gud_dri.so: cannot open shared object file: No such file or directory (search paths /usr/lib64/dri, suffix _dri)
Dec 07 21:28:15 fedora-1 gnome-shell[2194]: kmsro: driver missing
Dec 07 21:28:15 fedora-1 gnome-shell[2194]: Added device '/dev/dri/card0' (gud) using atomic mode setting.
Dec 07 21:28:15 fedora-1 gnome-shell[2194]: g_hash_table_insert_internal: assertion 'hash_table != NULL' failed
Dec 07 21:28:15 fedora-1 gnome-shell[2194]: g_hash_table_steal_extended: assertion 'hash_table != NULL' failed
Dec 07 21:28:15 fedora-1 gnome-shell[2194]: MESA-LOADER: failed to open gud: /usr/lib64/dri/gud_dri.so: cannot open shared object file: No such file or directory (search paths /usr/lib64/dri, suffix _dri)
Dec 07 21:28:15 fedora-1 gnome-shell[2194]: kmsro: driver missing
Dec 07 21:28:15 fedora-1 gnome-shell[2194]: Failed to initialize accelerated iGPU/dGPU framebuffer sharing: Not hardware accelerated
Dec 07 21:28:15 fedora-1 gnome-shell[2194]: Created gbm renderer for '/dev/dri/card0'
Dec 07 21:28:16 fedora-1 gnome-shell[2194]: Error looking up permission: GDBus.Error:org.freedesktop.portal.Error.NotFound: No entry for geolocation

# plug out

Dec 07 21:36:07 fedora-1 gnome-shell[2194]: drmModeRmFB: No such device

# plug in

Dec 07 21:39:55 fedora-1 gnome-shell[2194]: MESA-LOADER: failed to open gud: /usr/lib64/dri/gud_dri.so: cannot open shared object file: No such file or directory (search paths /usr/lib64/dri, suffix _dri)
Dec 07 21:39:55 fedora-1 gnome-shell[2194]: kmsro: driver missing
Dec 07 21:39:55 fedora-1 gnome-shell[2194]: Added device '/dev/dri/card2' (gud) using atomic mode setting.
Dec 07 21:39:55 fedora-1 gnome-shell[2194]: g_hash_table_insert_internal: assertion 'hash_table != NULL' failed
Dec 07 21:39:55 fedora-1 gnome-shell[2194]: g_hash_table_steal_extended: assertion 'hash_table != NULL' failed
Dec 07 21:39:55 fedora-1 gnome-shell[2194]: MESA-LOADER: failed to open gud: /usr/lib64/dri/gud_dri.so: cannot open shared object file: No such file or directory (search paths /usr/lib64/dri, suffix _dri)
Dec 07 21:39:55 fedora-1 gnome-shell[2194]: kmsro: driver missing
Dec 07 21:39:55 fedora-1 gnome-shell[2194]: Failed to initialize accelerated iGPU/dGPU framebuffer sharing: Not hardware accelerated
Dec 07 21:39:55 fedora-1 gnome-shell[2194]: Created gbm renderer for '/dev/dri/card2'