kms.patch (2803B)
1 drm: pick a card that drives a display, and no render node is fine 2 3 a phone often has its GPU on a render only card beside the display 4 controller. with no boot_vga to go by, the first card was taken, the GPU. 5 the card is now one with connectors in sysfs where any card has them, and a 6 display controller without a render node is used, without wl_drm. 7 8 --- a/libswc/drm.c 9 +++ b/libswc/drm.c 10 @@ -134,6 +134,27 @@ 11 return sscanf(entry->d_name, "card%u", &num) == 1; 12 } 13 14 +/* whether the card drives a display, by the connectors sysfs lists under it 15 + * (card0-DSI-1). a render only card, as many a phone's GPU is beside its 16 + * display controller, has none */ 17 +static bool 18 +has_connectors(const char *card) 19 +{ 20 + struct dirent *entry; 21 + size_t len = strlen(card); 22 + bool found = false; 23 + DIR *dir; 24 + 25 + if (!(dir = opendir("/sys/class/drm"))) { 26 + return false; 27 + } 28 + while (!found && (entry = readdir(dir))) { 29 + found = !strncmp(entry->d_name, card, len) && entry->d_name[len] == '-'; 30 + } 31 + closedir(dir); 32 + return found; 33 +} 34 + 35 static bool 36 find_primary_drm_device(char *path, size_t size) 37 { 38 @@ -142,6 +163,7 @@ 39 unsigned index; 40 FILE *file; 41 unsigned char boot_vga; 42 + bool any_connected = false; 43 44 num_cards = scandir("/dev/dri", &cards, &select_card, &alphasort); 45 46 @@ -150,6 +172,16 @@ 47 } 48 49 for (index = 0; index < num_cards; ++index) { 50 + any_connected = any_connected || has_connectors(cards[index]->d_name); 51 + } 52 + 53 + for (index = 0; index < num_cards; ++index) { 54 + /* where sysfs says which cards have outputs, only those do */ 55 + if (any_connected && !has_connectors(cards[index]->d_name)) { 56 + free(cards[index]); 57 + continue; 58 + } 59 + 60 snprintf(path, size, "/sys/class/drm/%s/device/boot_vga", 61 cards[index]->d_name); 62 63 @@ -294,11 +326,9 @@ 64 swc.backend->cursor_width = swc.drm->cursor_w; 65 swc.backend->cursor_height = swc.drm->cursor_h; 66 67 + /* a display controller on its own has no render node: clients are then 68 + * not offered wl_drm */ 69 drm.path = drmGetRenderDeviceNameFromFd(swc.drm->fd); 70 - if (!drm.path) { 71 - ERROR("Could not determine render node path\n"); 72 - goto error1; 73 - } 74 75 if (!(swc.drm->context = wld_drm_create_context(swc.drm->fd))) { 76 ERROR("Could not create WLD DRM context\n"); 77 @@ -321,11 +351,13 @@ 78 } 79 80 if (!wld_drm_is_dumb(swc.drm->context)) { 81 - drm.global = wl_global_create(swc.display, &wl_drm_interface, 2, NULL, 82 - &bind_drm); 83 - if (!drm.global) { 84 - ERROR("Could not create wl_drm global\n"); 85 - goto error4; 86 + if (drm.path) { 87 + drm.global = wl_global_create(swc.display, &wl_drm_interface, 2, 88 + NULL, &bind_drm); 89 + if (!drm.global) { 90 + ERROR("Could not create wl_drm global\n"); 91 + goto error4; 92 + } 93 } 94 95 drm.dmabuf = swc_dmabuf_create(swc.display);