From patchwork Tue Nov 3 18:12:17 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 55951 Delivered-To: patches@linaro.org Received: by 10.112.61.134 with SMTP id p6csp1979592lbr; Tue, 3 Nov 2015 10:12:42 -0800 (PST) X-Received: by 10.28.137.210 with SMTP id l201mr21713471wmd.103.1446574354853; Tue, 03 Nov 2015 10:12:34 -0800 (PST) Return-Path: Received: from mail-wm0-x22f.google.com (mail-wm0-x22f.google.com. [2a00:1450:400c:c09::22f]) by mx.google.com with ESMTPS id n199si29357181wmd.87.2015.11.03.10.12.34 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Nov 2015 10:12:34 -0800 (PST) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 2a00:1450:400c:c09::22f as permitted sender) client-ip=2a00:1450:400c:c09::22f; Authentication-Results: mx.google.com; spf=pass (google.com: domain of eric.auger@linaro.org designates 2a00:1450:400c:c09::22f as permitted sender) smtp.mailfrom=eric.auger@linaro.org; dkim=pass header.i=@linaro_org.20150623.gappssmtp.com Received: by wmff134 with SMTP id f134so91297149wmf.1 for ; Tue, 03 Nov 2015 10:12:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro_org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=q0VpD1pfwo6NN/nlult6RA2kPqLM1CvwDB28DvbGAmc=; b=XTMUh7M9nBfxOOZPjKBcooAByw0ioOmqKSUot5NPcYcsl9krl5LhApd+AB//HWzVq+ CnXWm7PhghcGdLxAsY4M3k/gn/Fnu4Z+0W+GwBw2sP6s7sgz4NdvPgNqWbkCJ/WIAy2o 1GTvdjJZYl603vuUr4IjEVvu1o88pdr1cWEf/k0vvUfahMPRlJrNolniUMiO4ij/pM9j U1Ll1TtiQpWv5oGRm4cZy70G/LnbhflrXVI7J4wYepr2xK1yRT968viLTCNf8/IUAfnX ZhLpjBotc+VZC8IBwAOopfB3EiKK1xkCe3/6o4MzwYrqV7/7k0JCtvgMRoDaebBXrjh0 wwFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=q0VpD1pfwo6NN/nlult6RA2kPqLM1CvwDB28DvbGAmc=; b=cnMtaFQKlFxPhpJQ70A1l0M0GU8dBiMqZeblY4Z8BwxpoLkG+bpA6rdxBYWKLrDUnl YDZsL/kxJvJoAJwSkeGs3c9uNMq7RL/yrss7Z1dM6KSDEakLmDqO3DCzuH+f+4pEXFxD mCKpcOW7D58GcgAEJv1ODv96xQumwLUXwG/wXINl7sAppAuhLgWZ9Y0p+VTYG/gknZEL X9zHmQIgeBavS7KJnBjhFxyCMT4lj6tXdCqq63mPQd3pE/Aarkw9YSFm6i0lh+Lu/bCm 1U4NIHbPC8sU9kU5eQezZZJfRInKX/d3EnqNqIKMnzYFopAP9zB2Ujp1qjmsfU6iPDw3 dvvg== X-Gm-Message-State: ALoCoQm8sNfe/bSFVw13tmo/1PmWwBw1SwNS7+fOYaXjqvzdRBCbNCbFLNzFl24Y2RCBwyZBkz9Q X-Received: by 10.28.55.200 with SMTP id e191mr20073512wma.83.1446574354609; Tue, 03 Nov 2015 10:12:34 -0800 (PST) Return-Path: Received: from new-host-3.home (LMontsouris-657-1-37-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by smtp.gmail.com with ESMTPSA id om1sm28830527wjc.2.2015.11.03.10.12.33 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 03 Nov 2015 10:12:33 -0800 (PST) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, alex.williamson@redhat.com, b.reynal@virtualopensystems.com, arnd@arndb.de, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org Cc: christoffer.dall@linaro.org, linux-kernel@vger.kernel.org, patches@linaro.org Subject: [PATCH v6 6/8] vfio: platform: use list of registered reset function Date: Tue, 3 Nov 2015 18:12:17 +0000 Message-Id: <1446574339-1843-7-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1446574339-1843-1-git-send-email-eric.auger@linaro.org> References: <1446574339-1843-1-git-send-email-eric.auger@linaro.org> Remove the static lookup table and use the dynamic list of registered reset functions instead. Also load the reset module through its alias. The reset struct module pointer is stored in vfio_platform_device. We also remove the useless struct device pointer parameter in vfio_platform_get_reset. This patch fixes the issue related to the usage of __symbol_get, which besides from being moot, prevented compilation with CONFIG_MODULES disabled. Also usage of MODULE_ALIAS makes possible to add a new reset module without needing to update the framework. This was suggested by Arnd. Signed-off-by: Eric Auger Reported-by: Arnd Bergmann Reviewed-by: Arnd Bergmann --- v3 -> v4: - add Arnd R-b. - Remove the EXPORT_SYMBOL_GPL(vfio_platform_calxedaxgmac_reset) here v2 -> v3: - remove clear of vfio_platform_device reset_module and reset in vfio_platform_put_reset - single unlock in vfio_platform_lookup_reset - use driver_lock instead of reset_lock v1 -> v2: - use reset_lock in vfio_platform_lookup_reset - remove vfio_platform_reset_combo declaration - remove struct device *dev parameter in vfio_platform_get_reset - set reset_module and reset to NULL in put function --- .../platform/reset/vfio_platform_calxedaxgmac.c | 1 - drivers/vfio/platform/vfio_platform_common.c | 52 ++++++++++++---------- drivers/vfio/platform/vfio_platform_private.h | 7 +-- 3 files changed, 30 insertions(+), 30 deletions(-) -- 1.9.1 diff --git a/drivers/vfio/platform/reset/vfio_platform_calxedaxgmac.c b/drivers/vfio/platform/reset/vfio_platform_calxedaxgmac.c index 80718f2..640f5d8 100644 --- a/drivers/vfio/platform/reset/vfio_platform_calxedaxgmac.c +++ b/drivers/vfio/platform/reset/vfio_platform_calxedaxgmac.c @@ -76,7 +76,6 @@ int vfio_platform_calxedaxgmac_reset(struct vfio_platform_device *vdev) return 0; } -EXPORT_SYMBOL_GPL(vfio_platform_calxedaxgmac_reset); module_vfio_reset_handler("calxeda,hb-xgmac", vfio_platform_calxedaxgmac_reset); diff --git a/drivers/vfio/platform/vfio_platform_common.c b/drivers/vfio/platform/vfio_platform_common.c index f2d41a0..f74836a 100644 --- a/drivers/vfio/platform/vfio_platform_common.c +++ b/drivers/vfio/platform/vfio_platform_common.c @@ -30,37 +30,43 @@ static LIST_HEAD(reset_list); static DEFINE_MUTEX(driver_lock); -static const struct vfio_platform_reset_combo reset_lookup_table[] = { - { - .compat = "calxeda,hb-xgmac", - .reset_function_name = "vfio_platform_calxedaxgmac_reset", - .module_name = "vfio-platform-calxedaxgmac", - }, -}; - -static void vfio_platform_get_reset(struct vfio_platform_device *vdev, - struct device *dev) +static vfio_platform_reset_fn_t vfio_platform_lookup_reset(const char *compat, + struct module **module) { - int (*reset)(struct vfio_platform_device *); - int i; + struct vfio_platform_reset_node *iter; + vfio_platform_reset_fn_t reset_fn = NULL; - for (i = 0 ; i < ARRAY_SIZE(reset_lookup_table); i++) { - if (!strcmp(reset_lookup_table[i].compat, vdev->compat)) { - request_module(reset_lookup_table[i].module_name); - reset = __symbol_get( - reset_lookup_table[i].reset_function_name); - if (reset) { - vdev->reset = reset; - return; - } + mutex_lock(&driver_lock); + list_for_each_entry(iter, &reset_list, link) { + if (!strcmp(iter->compat, compat) && + try_module_get(iter->owner)) { + *module = iter->owner; + reset_fn = iter->reset; + break; } } + mutex_unlock(&driver_lock); + return reset_fn; +} + +static void vfio_platform_get_reset(struct vfio_platform_device *vdev) +{ + char modname[256]; + + vdev->reset = vfio_platform_lookup_reset(vdev->compat, + &vdev->reset_module); + if (!vdev->reset) { + snprintf(modname, 256, "vfio-reset:%s", vdev->compat); + request_module(modname); + vdev->reset = vfio_platform_lookup_reset(vdev->compat, + &vdev->reset_module); + } } static void vfio_platform_put_reset(struct vfio_platform_device *vdev) { if (vdev->reset) - symbol_put_addr(vdev->reset); + module_put(vdev->reset_module); } static int vfio_platform_regions_init(struct vfio_platform_device *vdev) @@ -557,7 +563,7 @@ int vfio_platform_probe_common(struct vfio_platform_device *vdev, return ret; } - vfio_platform_get_reset(vdev, dev); + vfio_platform_get_reset(vdev); mutex_init(&vdev->igate); diff --git a/drivers/vfio/platform/vfio_platform_private.h b/drivers/vfio/platform/vfio_platform_private.h index 415310f..d1b0668 100644 --- a/drivers/vfio/platform/vfio_platform_private.h +++ b/drivers/vfio/platform/vfio_platform_private.h @@ -58,6 +58,7 @@ struct vfio_platform_device { struct mutex igate; struct module *parent_module; const char *compat; + struct module *reset_module; /* * These fields should be filled by the bus specific binder @@ -81,12 +82,6 @@ struct vfio_platform_reset_node { vfio_platform_reset_fn_t reset; }; -struct vfio_platform_reset_combo { - const char *compat; - const char *reset_function_name; - const char *module_name; -}; - extern int vfio_platform_probe_common(struct vfio_platform_device *vdev, struct device *dev); extern struct vfio_platform_device *vfio_platform_remove_common