From patchwork Wed Sep 9 17:21:23 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov X-Patchwork-Id: 7147611 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 30173BF036 for ; Wed, 9 Sep 2015 17:17:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 55ED420A09 for ; Wed, 9 Sep 2015 17:17:29 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 56EFA20A06 for ; Wed, 9 Sep 2015 17:17:28 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2EB1D6EC08; Wed, 9 Sep 2015 10:17:26 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com [209.85.212.181]) by gabe.freedesktop.org (Postfix) with ESMTPS id 79BDD6EC02 for ; Wed, 9 Sep 2015 10:17:24 -0700 (PDT) Received: by wiclk2 with SMTP id lk2so29781670wic.1 for ; Wed, 09 Sep 2015 10:17:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=RR4dZS6HFn7qENSfN6H5/WRUdAHuVZvt3xhwRlvCp70=; b=lXeiaybs4TohpCgqrQ8v6c1NFXkde+Oe0z9Q08KfO5qTjec241T7hvOw5bkgbREIsT gpAtr9l8EstasW01XLwUnfuQNkzNwXEmxp3gs1MSBnmLHXfwpQO1hto8ZwtytnVQBXbp UgnYYUzLp4dlFF0++DRV5stLGOBJoJE+M7Z4poX7IPyM7kHFRyvlqlTCFBi7bBpN6vah g+RII3xAEWj19XnupevGWmpmQzBtsMMOrTvadlc5bHv7wFtZNzZU+TdyHVk4zpHYQMIv 3XldpbzrDvKWHSqtI4CbWmkYQIcqs2/hvT4fUKXSmZAImo+W+1Fkn3E1Dc/tPGTMxj90 l3mQ== X-Received: by 10.194.134.98 with SMTP id pj2mr62855104wjb.30.1441819042900; Wed, 09 Sep 2015 10:17:22 -0700 (PDT) Received: from arch-x220.localdomain (cpc12-croy20-2-0-cust52.croy.cable.virginm.net. [82.44.54.53]) by smtp.gmail.com with ESMTPSA id j7sm11257042wjz.11.2015.09.09.10.17.21 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 09 Sep 2015 10:17:22 -0700 (PDT) From: Emil Velikov To: dri-devel@lists.freedesktop.org Subject: [PATCH libdrm 02/12] xf86drm: flex platform specifics into drmParsePciBusInfo Date: Wed, 9 Sep 2015 18:21:23 +0100 Message-Id: <1441819293-25567-3-git-send-email-emil.l.velikov@gmail.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1441819293-25567-1-git-send-email-emil.l.velikov@gmail.com> References: <1441819293-25567-1-git-send-email-emil.l.velikov@gmail.com> Cc: emil.l.velikov@gmail.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This will allow one to reuse the core drmGetDevices implementation on other platforms. Keeping all the platform specifics in ParseFoo. On the plus side this saves a bit of code :) Signed-off-by: Emil Velikov --- xf86drm.c | 46 ++++++++++++++++++++-------------------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/xf86drm.c b/xf86drm.c index a5a7b41..b4c5aa0 100644 --- a/xf86drm.c +++ b/xf86drm.c @@ -2855,23 +2855,33 @@ static int drmParseSubsystemType(const char *str) return -EINVAL; } -static int drmParsePciBusInfo(const char *str, drmPciBusInfoPtr info) +static int drmParsePciBusInfo(int maj, int min, drmPciBusInfoPtr info) { + char path[PATH_MAX + 1]; + char data[128]; + char *str; int domain, bus, dev, func; - char *value; + int fd, ret; - if (str == NULL) - return -EINVAL; + snprintf(path, PATH_MAX, "/sys/dev/char/%d:%d/device/uevent", maj, min); + fd = open(path, O_RDONLY); + if (fd < 0) + return -errno; - value = strstr(str, "PCI_SLOT_NAME="); - if (value == NULL) - return -EINVAL; + ret = read(fd, data, sizeof(data)); + close(fd); + if (ret < 0) + return -errno; - value += strlen("PCI_SLOT_NAME="); +#define TAG "PCI_SLOT_NAME=" + str = strstr(data, TAG); + if (str == NULL) + return -EINVAL; - if (sscanf(value, "%04x:%02x:%02x.%1u", + if (sscanf(str, TAG "%04x:%02x:%02x.%1u", &domain, &bus, &dev, &func) != 4) return -EINVAL; +#undef TAG info->domain = domain; info->bus = bus; @@ -2981,7 +2991,6 @@ int drmGetDevices(drmDevicePtr devices[], int max_devices) struct stat sbuf = {0}; char node[PATH_MAX + 1] = ""; char path[PATH_MAX + 1] = ""; - char data[128] = ""; unsigned char config[64] = ""; int node_type, subsystem_type; int maj, min; @@ -3030,22 +3039,7 @@ int drmGetDevices(drmDevicePtr devices[], int max_devices) goto free_locals; } - snprintf(path, PATH_MAX, "/sys/dev/char/%d:%d/device/uevent", - maj, min); - fd = open(path, O_RDONLY); - if (fd < 0) { - ret = -errno; - goto free_locals; - } - ret = read(fd, data, sizeof(data)); - if (ret < 0) { - ret = -errno; - close(fd); - goto free_locals; - } - - ret = drmParsePciBusInfo(data, pcibus); - close(fd); + ret = drmParsePciBusInfo(maj, min, pcibus); if (ret) goto free_locals;