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; From patchwork Wed Jan 23 10:45:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov X-Patchwork-Id: 10776997 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 CB34E13BF for ; Wed, 23 Jan 2019 10:49:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BAC3829FCD for ; Wed, 23 Jan 2019 10:49:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AF1C82A1E7; Wed, 23 Jan 2019 10:49:14 +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 49F8C29FCD for ; Wed, 23 Jan 2019 10:49:14 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BA0EB6E4CF; Wed, 23 Jan 2019 10:49:12 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5C1D36E4CE for ; Wed, 23 Jan 2019 10:49:06 +0000 (UTC) Received: by mail-wr1-x444.google.com with SMTP id s12so1848621wrt.4 for ; Wed, 23 Jan 2019 02:49:06 -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:in-reply-to :references:mime-version:content-transfer-encoding; bh=RYS9FmbLutXqNhY0ZarZhelhwCa53K5nHJc9aGpMkIE=; b=PdEZoYOxFw0uL4IbIOXYw1RksVUrEk8khKYsKfeu4eNyeBv+cg6EVU2Rhi2olj/uz4 VA/mVKxo21fG/UXsrOoMTbZhKrrFxDLdle1WVxAhw3hmOqrHhMTpK6F7pkN8oBTLen6P uVw4aihNKNJKqAwgeyjREV0E+mjfO+uI3b4Dy3I/V0vVyYOZlB/BgZG4K28tjxyP/muo HlLNexBBVjj83F+sEljP8jCMl0r4cSDGpz853vvu/x2wIBfH6nRnTgxBQtjoEhI7rjh2 e7UIgw/fDYLWYw+4y8j5sStOeieqGAfBw7MrzLewnz57GIoJUtKxZnF8geChHNlxqoQj vNcA== X-Gm-Message-State: AJcUukeu767WUV8WPMFWFE1alx0i+eTZLwU+7JuGpkwAMz27LRTVOZT9 xGZ7ii2R8Ba5pFFYXkhHJbWknafE X-Google-Smtp-Source: ALg8bN4TMrWPayXYFHUeMrVLgQ+DfLRST3JacG90dgn4s+/D8yb+zmJcrdaY5Jk443jha9dfD+XXXw== X-Received: by 2002:a5d:550f:: with SMTP id b15mr2189831wrv.330.1548240544621; Wed, 23 Jan 2019 02:49:04 -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.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Jan 2019 02:49:04 -0800 (PST) From: Emil Velikov To: dri-devel@lists.freedesktop.org Subject: [PATCH libdrm 2/2] xf85drm: de-duplicate drmParse{Platform.Host1x}{Bus, Device}Info Date: Wed, 23 Jan 2019 10:45:18 +0000 Message-Id: <20190123104518.7332-2-emil.l.velikov@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190123104518.7332-1-emil.l.velikov@gmail.com> References: <20190123104518.7332-1-emil.l.velikov@gmail.com> 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 The functions are virtually identical, fold them up. Signed-off-by: Emil Velikov Reviewed-by: Eric Engestrom --- xf86drm.c | 98 +++++++++---------------------------------------------- 1 file changed, 15 insertions(+), 83 deletions(-) diff --git a/xf86drm.c b/xf86drm.c index 374734eb..18c9693a 100644 --- a/xf86drm.c +++ b/xf86drm.c @@ -3508,7 +3508,7 @@ free_device: return ret; } -static int drmParsePlatformBusInfo(int maj, int min, drmPlatformBusInfoPtr info) +static int drmParseOFBusInfo(int maj, int min, char *fullname) { #ifdef __linux__ char path[PATH_MAX + 1], *name, *foo; @@ -3532,19 +3532,18 @@ static int drmParsePlatformBusInfo(int maj, int min, drmPlatformBusInfoPtr info) foo++; } - strncpy(info->fullname, foo, DRM_PLATFORM_DEVICE_NAME_LEN); - info->fullname[DRM_PLATFORM_DEVICE_NAME_LEN - 1] = '\0'; + strncpy(fullname, foo, DRM_PLATFORM_DEVICE_NAME_LEN); + fullname[DRM_PLATFORM_DEVICE_NAME_LEN - 1] = '\0'; free(name); return 0; #else -#warning "Missing implementation of drmParsePlatformBusInfo" +#warning "Missing implementation of drmParseOFBusInfo" return -EINVAL; #endif } -static int drmParsePlatformDeviceInfo(int maj, int min, - drmPlatformDeviceInfoPtr info) +static int drmParseOFDeviceInfo(int maj, int min, char ***compatible) { #ifdef __linux__ char path[PATH_MAX + 1], *value, *foo; @@ -3562,8 +3561,8 @@ static int drmParsePlatformDeviceInfo(int maj, int min, count = 1; } - info->compatible = calloc(count + 1, sizeof(*info->compatible)); - if (!info->compatible) + *compatible = calloc(count + 1, sizeof(char *)); + if (!*compatible) return -ENOMEM; for (i = 0; i < count; i++) { @@ -3587,19 +3586,19 @@ static int drmParsePlatformDeviceInfo(int maj, int min, free(value); } - info->compatible[i] = foo; + *compatible[i] = foo; } return 0; free: while (i--) - free(info->compatible[i]); + free(*compatible[i]); - free(info->compatible); + free(*compatible); return err; #else -#warning "Missing implementation of drmParsePlatformDeviceInfo" +#warning "Missing implementation of drmParseOFDeviceInfo" return -EINVAL; #endif } @@ -3622,7 +3621,7 @@ static int drmProcessPlatformDevice(drmDevicePtr *device, dev->businfo.platform = (drmPlatformBusInfoPtr)ptr; - ret = drmParsePlatformBusInfo(maj, min, dev->businfo.platform); + ret = drmParseOFBusInfo(maj, min, dev->businfo.platform->fullname); if (ret < 0) goto free_device; @@ -3630,7 +3629,7 @@ static int drmProcessPlatformDevice(drmDevicePtr *device, ptr += sizeof(drmPlatformBusInfo); dev->deviceinfo.platform = (drmPlatformDeviceInfoPtr)ptr; - ret = drmParsePlatformDeviceInfo(maj, min, dev->deviceinfo.platform); + ret = drmParseOFDeviceInfo(maj, min, &dev->deviceinfo.platform->compatible); if (ret < 0) goto free_device; } @@ -3644,73 +3643,6 @@ free_device: return ret; } -static int drmParseHost1xBusInfo(int maj, int min, drmHost1xBusInfoPtr info) -{ -#ifdef __linux__ - char path[PATH_MAX + 1], *name; - - snprintf(path, sizeof(path), "/sys/dev/char/%d:%d/device", maj, min); - - name = sysfs_uevent_get(path, "OF_FULLNAME"); - if (!name) - return -ENOENT; - - strncpy(info->fullname, name, DRM_HOST1X_DEVICE_NAME_LEN); - info->fullname[DRM_HOST1X_DEVICE_NAME_LEN - 1] = '\0'; - free(name); - - return 0; -#else -#warning "Missing implementation of drmParseHost1xBusInfo" - return -EINVAL; -#endif -} - -static int drmParseHost1xDeviceInfo(int maj, int min, - drmHost1xDeviceInfoPtr info) -{ -#ifdef __linux__ - char path[PATH_MAX + 1], *value; - 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); - - info->compatible = calloc(count + 1, sizeof(*info->compatible)); - if (!info->compatible) - return -ENOMEM; - - for (i = 0; i < count; i++) { - value = sysfs_uevent_get(path, "OF_COMPATIBLE_%u", i); - if (!value) { - err = -ENOENT; - goto free; - } - - info->compatible[i] = value; - } - - return 0; - -free: - while (i--) - free(info->compatible[i]); - - free(info->compatible); - return err; -#else -#warning "Missing implementation of drmParseHost1xDeviceInfo" - return -EINVAL; -#endif -} - static int drmProcessHost1xDevice(drmDevicePtr *device, const char *node, int node_type, int maj, int min, bool fetch_deviceinfo, @@ -3729,7 +3661,7 @@ static int drmProcessHost1xDevice(drmDevicePtr *device, dev->businfo.host1x = (drmHost1xBusInfoPtr)ptr; - ret = drmParseHost1xBusInfo(maj, min, dev->businfo.host1x); + ret = drmParseOFBusInfo(maj, min, dev->businfo.host1x->fullname); if (ret < 0) goto free_device; @@ -3737,7 +3669,7 @@ static int drmProcessHost1xDevice(drmDevicePtr *device, ptr += sizeof(drmHost1xBusInfo); dev->deviceinfo.host1x = (drmHost1xDeviceInfoPtr)ptr; - ret = drmParseHost1xDeviceInfo(maj, min, dev->deviceinfo.host1x); + ret = drmParseOFDeviceInfo(maj, min, &dev->deviceinfo.host1x->compatible); if (ret < 0) goto free_device; }