From patchwork Wed Jan 23 10:45:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov X-Patchwork-Id: 10776995 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4A22114E5 for ; Wed, 23 Jan 2019 10:49:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 364D029FCD for ; Wed, 23 Jan 2019 10:49:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 29F0D2A1E7; Wed, 23 Jan 2019 10:49:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C069C29FCD for ; Wed, 23 Jan 2019 10:49:11 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 812EA6E4CE; Wed, 23 Jan 2019 10:49:09 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by gabe.freedesktop.org (Postfix) with ESMTPS id 57FB56E4CE for ; Wed, 23 Jan 2019 10:49:05 +0000 (UTC) Received: by mail-wr1-x441.google.com with SMTP id l9so1804817wrt.13 for ; Wed, 23 Jan 2019 02:49:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=gKCqtB9cCY0GAH8eD5/dzDumZug3Ko1d5SIAG0LAgK0=; b=eYrq8BDCGiLxYc72qyO4PbyLqugUPS6BIHagXCb7Bpk3vKxig7BSnGnfyH9+RNJBce VU7zpg30mnnJ0Szd2ivfl4OIXDA6TeN5lCWC7O9On+MSGarydFTg/vX08RzjMVkIgU44 cKhaOY6e0SSwQZ+43NpBghKJdcJAha2JD7XICuUgMpKbvmvhR2kipdM6pJSrfkUWYxgb sDBnzPMdUVc1rDD1p2q+vGlwOiAfZj1j15SRzGGSNCoTLeK08iDxw3VHyNpljve0dNgJ YVO8GmF0WWYNV18wWWQVv4JcTiDP4Yes0j+CSoZIYw6CZYRa2l/NvLGYwbUStArqA/AW qxqA== X-Gm-Message-State: AJcUukcIoAgDbJ0KTFd5y6wh9cDuBf6X1KAxmmrQjVcNwPzh8UxAWb8a XtfF/CRDviY4LQG0bjSzP5LZsagF X-Google-Smtp-Source: ALg8bN5Q6ZrNUbzHN8H+3mgu9rTnGpNT/w6HXPfQmo+0VJaagGDfZP5t5mJo5b6NknxRDN61NQt4Xg== X-Received: by 2002:adf:e284:: with SMTP id v4mr2083096wri.26.1548240543736; Wed, 23 Jan 2019 02:49:03 -0800 (PST) Received: from arch-x1c3.cbg.collabora.co.uk ([2a00:5f00:102:0:9665:9cff:feee:aa4d]) by smtp.gmail.com with ESMTPSA id e27sm120680872wra.67.2019.01.23.02.49.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Jan 2019 02:49:03 -0800 (PST) From: Emil Velikov To: dri-devel@lists.freedesktop.org Subject: [PATCH libdrm 1/2] xf86drm: fallback to MODALIAS for OF less platform devices Date: Wed, 23 Jan 2019 10:45:17 +0000 Message-Id: <20190123104518.7332-1-emil.l.velikov@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: emil.l.velikov@gmail.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Emil Velikov Some devices can lack OF data or it may not be available in the uevent file. Fallback to the MODALIAS data in those cases. We strip any leading "MODALIAS=.*:" thus the resulting information is compatible with existing code in Mesa. Signed-off-by: Emil Velikov --- xf86drm.c | 55 ++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 13 deletions(-) diff --git a/xf86drm.c b/xf86drm.c index 10df682b..374734eb 100644 --- a/xf86drm.c +++ b/xf86drm.c @@ -3511,15 +3511,28 @@ free_device: static int drmParsePlatformBusInfo(int maj, int min, drmPlatformBusInfoPtr info) { #ifdef __linux__ - char path[PATH_MAX + 1], *name; + char path[PATH_MAX + 1], *name, *foo; snprintf(path, sizeof(path), "/sys/dev/char/%d:%d/device", maj, min); name = sysfs_uevent_get(path, "OF_FULLNAME"); - if (!name) - return -ENOENT; + foo = name; + if (!name) { + /* If the device lacks OF data, pick the MODALIAS info */ + name = sysfs_uevent_get(path, "MODALIAS"); + if (!name) + return -ENOENT; + + /* .. and strip the MODALIAS=[platform,usb...]: part. */ + foo = strrchr(name, ':'); + if (!foo) { + free(name); + return -ENOENT; + } + foo++; + } - strncpy(info->fullname, name, DRM_PLATFORM_DEVICE_NAME_LEN); + strncpy(info->fullname, foo, DRM_PLATFORM_DEVICE_NAME_LEN); info->fullname[DRM_PLATFORM_DEVICE_NAME_LEN - 1] = '\0'; free(name); @@ -3534,18 +3547,20 @@ static int drmParsePlatformDeviceInfo(int maj, int min, drmPlatformDeviceInfoPtr info) { #ifdef __linux__ - char path[PATH_MAX + 1], *value; + char path[PATH_MAX + 1], *value, *foo; unsigned int count, i; int err; snprintf(path, sizeof(path), "/sys/dev/char/%d:%d/device", maj, min); value = sysfs_uevent_get(path, "OF_COMPATIBLE_N"); - if (!value) - return -ENOENT; - - sscanf(value, "%u", &count); - free(value); + if (value) { + sscanf(value, "%u", &count); + free(value); + } else { + /* Assume one entry if the device lack OF data */ + count = 1; + } info->compatible = calloc(count + 1, sizeof(*info->compatible)); if (!info->compatible) @@ -3553,12 +3568,26 @@ static int drmParsePlatformDeviceInfo(int maj, int min, for (i = 0; i < count; i++) { value = sysfs_uevent_get(path, "OF_COMPATIBLE_%u", i); + foo = value; if (!value) { - err = -ENOENT; - goto free; + /* If the device lacks OF data, pick the MODALIAS info */ + value = sysfs_uevent_get(path, "MODALIAS"); + if (!value) { + err = -ENOENT; + goto free; + } + + /* .. and strip the MODALIAS=[platform,usb...]: part. */ + foo = strrchr(value, ':'); + if (!foo) { + free(value); + return -ENOENT; + } + foo = strdup(foo + 1); + free(value); } - info->compatible[i] = value; + info->compatible[i] = foo; } return 0;