From patchwork Wed Jan 29 15:38:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Golubev X-Patchwork-Id: 11357595 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 364D913B4 for ; Thu, 30 Jan 2020 08:33:08 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1E0B020CC7 for ; Thu, 30 Jan 2020 08:33:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1E0B020CC7 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=opensynergy.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A6CB86F90E; Thu, 30 Jan 2020 08:32:47 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from plasma4.jpberlin.de (plasma4.jpberlin.de [80.241.57.33]) by gabe.freedesktop.org (Postfix) with ESMTPS id F24B56E3E7 for ; Wed, 29 Jan 2020 15:48:15 +0000 (UTC) Received: from spamfilter05.heinlein-hosting.de (spamfilter05.heinlein-hosting.de [80.241.56.123]) by plasma.jpberlin.de (Postfix) with ESMTP id EFAF1AAD56 for ; Wed, 29 Jan 2020 16:38:24 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from plasma.jpberlin.de ([80.241.56.68]) by spamfilter05.heinlein-hosting.de (spamfilter05.heinlein-hosting.de [80.241.56.123]) (amavisd-new, port 10030) with ESMTP id lJRaVVvx3BjQ for ; Wed, 29 Jan 2020 16:38:23 +0100 (CET) Received: from webmail.opensynergy.com (unknown [217.66.60.5]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (Client CN "webmail.opensynergy.com", Issuer "GeoTrust EV RSA CA 2018" (not verified)) (Authenticated sender: opensynergy@jpberlin.de) by plasma.jpberlin.de (Postfix) with ESMTPSA id D8E14B786B for ; Wed, 29 Jan 2020 16:38:23 +0100 (CET) Received: from os-lin-mgo.open-synergy.com (10.25.255.1) by MXS01.open-synergy.com (10.25.10.17) with Microsoft SMTP Server (TLS) id 14.3.468.0; Wed, 29 Jan 2020 16:38:25 +0100 From: Mikhail Golubev To: Subject: [PATCH libdrm 1/2] xf86drm: generalize the device subsystem type parsing code Date: Wed, 29 Jan 2020 16:38:09 +0100 Message-ID: <20200129153810.26876-1-Mikhail.Golubev@opensynergy.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 X-Originating-IP: [10.25.255.1] X-Mailman-Approved-At: Thu, 30 Jan 2020 08:32:45 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vasyl Vavrychuk Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Vasyl Vavrychuk Move the code, which used to get the device subsystem type from a device path in sysfs, to a separate function to be reusable. Signed-off-by: Vasyl Vavrychuk Signed-off-by: Mikhail Golubev --- xf86drm.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/xf86drm.c b/xf86drm.c index 7ae41c37..b1479128 100644 --- a/xf86drm.c +++ b/xf86drm.c @@ -2964,10 +2964,10 @@ sysfs_uevent_get(const char *path, const char *fmt, ...) /* Little white lie to avoid major rework of the existing code */ #define DRM_BUS_VIRTIO 0x10 -static int drmParseSubsystemType(int maj, int min) -{ #ifdef __linux__ - char path[PATH_MAX + 1]; +static int get_subsystem_type(const char *device_path) +{ + char path[PATH_MAX + 1] = ""; char link[PATH_MAX + 1] = ""; char *name; struct { @@ -2982,8 +2982,8 @@ static int drmParseSubsystemType(int maj, int min) { "/virtio", DRM_BUS_VIRTIO }, }; - snprintf(path, PATH_MAX, "/sys/dev/char/%d:%d/device/subsystem", - maj, min); + strncpy(path, device_path, PATH_MAX); + strncat(path, "/subsystem", PATH_MAX); if (readlink(path, link, PATH_MAX) < 0) return -errno; @@ -2998,6 +2998,17 @@ static int drmParseSubsystemType(int maj, int min) } return -EINVAL; +} +#endif + +static int drmParseSubsystemType(int maj, int min) +{ +#ifdef __linux__ + char path[PATH_MAX + 1] = ""; + + snprintf(path, PATH_MAX, "/sys/dev/char/%d:%d/device", maj, min); + + return get_subsystem_type(path); #elif defined(__OpenBSD__) || defined(__DragonFly__) return DRM_BUS_PCI; #else From patchwork Wed Jan 29 15:38:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Golubev X-Patchwork-Id: 11357593 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5FE181398 for ; Thu, 30 Jan 2020 08:33:06 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 47B572082E for ; Thu, 30 Jan 2020 08:33:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 47B572082E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=opensynergy.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 768F56F90A; Thu, 30 Jan 2020 08:32:47 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org X-Greylist: delayed 586 seconds by postgrey-1.36 at gabe; Wed, 29 Jan 2020 15:48:15 UTC Received: from plasma4.jpberlin.de (plasma4.jpberlin.de [80.241.57.33]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9A0696E3E7 for ; Wed, 29 Jan 2020 15:48:15 +0000 (UTC) Received: from spamfilter01.heinlein-hosting.de (spamfilter01.heinlein-hosting.de [80.241.56.115]) by plasma.jpberlin.de (Postfix) with ESMTP id D8CDABB9B6 for ; Wed, 29 Jan 2020 16:38:29 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from plasma.jpberlin.de ([80.241.56.68]) by spamfilter01.heinlein-hosting.de (spamfilter01.heinlein-hosting.de [80.241.56.115]) (amavisd-new, port 10030) with ESMTP id oJ5qB9HlIKnF for ; Wed, 29 Jan 2020 16:38:25 +0100 (CET) Received: from webmail.opensynergy.com (unknown [217.66.60.5]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (Client CN "webmail.opensynergy.com", Issuer "GeoTrust EV RSA CA 2018" (not verified)) (Authenticated sender: opensynergy@jpberlin.de) by plasma.jpberlin.de (Postfix) with ESMTPSA id B3266B960F for ; Wed, 29 Jan 2020 16:38:25 +0100 (CET) Received: from os-lin-mgo.open-synergy.com (10.25.255.1) by MXS01.open-synergy.com (10.25.10.17) with Microsoft SMTP Server (TLS) id 14.3.468.0; Wed, 29 Jan 2020 16:38:26 +0100 From: Mikhail Golubev To: Subject: [PATCH libdrm 2/2] xf86drm: fix subsystem type lookup for virtio mmio-based devices Date: Wed, 29 Jan 2020 16:38:10 +0100 Message-ID: <20200129153810.26876-2-Mikhail.Golubev@opensynergy.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200129153810.26876-1-Mikhail.Golubev@opensynergy.com> References: <20200129153810.26876-1-Mikhail.Golubev@opensynergy.com> MIME-Version: 1.0 X-Originating-IP: [10.25.255.1] X-Mailman-Approved-At: Thu, 30 Jan 2020 08:32:45 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vasyl Vavrychuk Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Vasyl Vavrychuk Currently the code assumes that a virtio based device is always located on the PCI bus. Modify the parser to make it check the device's parent directory to determine on which bus it is located. Output for virtio-pci is the PCI bus. Output for virtio-mmio is the Platform bus. Signed-off-by: Vasyl Vavrychuk Signed-off-by: Mikhail Golubev --- xf86drm.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/xf86drm.c b/xf86drm.c index b1479128..1b22efe4 100644 --- a/xf86drm.c +++ b/xf86drm.c @@ -3005,10 +3005,20 @@ static int drmParseSubsystemType(int maj, int min) { #ifdef __linux__ char path[PATH_MAX + 1] = ""; + char real_path[PATH_MAX + 1] = ""; + int subsystem_type; snprintf(path, PATH_MAX, "/sys/dev/char/%d:%d/device", maj, min); + if (!realpath(path, real_path)) + return -errno; + strncpy(path, real_path, PATH_MAX); - return get_subsystem_type(path); + subsystem_type = get_subsystem_type(path); + if (subsystem_type == DRM_BUS_VIRTIO) { + strncat(path, "/..", PATH_MAX); + subsystem_type = get_subsystem_type(path); + } + return subsystem_type; #elif defined(__OpenBSD__) || defined(__DragonFly__) return DRM_BUS_PCI; #else @@ -3710,7 +3720,6 @@ process_device(drmDevicePtr *device, const char *d_name, switch (subsystem_type) { case DRM_BUS_PCI: - case DRM_BUS_VIRTIO: return drmProcessPciDevice(device, node, node_type, maj, min, fetch_deviceinfo, flags); case DRM_BUS_USB: