From patchwork Fri Oct 23 12:37:14 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 55489 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by patches.linaro.org (Postfix) with ESMTPS id 8F26420581 for ; Fri, 23 Oct 2015 12:37:40 +0000 (UTC) Received: by wiclg3 with SMTP id lg3sf10670404wic.3 for ; Fri, 23 Oct 2015 05:37:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=7A2ogCeHEMOGAL/B93HOV5Jy+w5EnuVLsTFPKveTrQs=; b=Bd3jD8lY0Yy2Z8wggQb0IBhRNTM/ZtezZMBeM0KLKoBVK/+oPES03mnJ8fmHGmZcB7 /BkRwO3/3bGZHJf+T19JGZXuvvpizli8Yh3ggaKS3MXLOtbXwowPBjyjhexy/PGQZOq1 e7KIavxBfEN8dzOwcKvxCRfsIIpKbhl33Fn+AoZ2KF5ngCPR+/7pBDrRHFooHqX4fbXe HfVp3B22+GRgaxobY+tQPASjuwurwdquuW+x672wKUeb+cXxuJyf8kXO/SDM3R7+1DWh mkkt+aJ3obuqLE06dtbujsGeN5i2N2DFPosNAGxwkygLO8cvbn/0ovhPzgyhX6j39Zn0 9q2A== X-Gm-Message-State: ALoCoQnAe+77dCQ2HzUgy3NmGAf/lhTWw5dRjRqc8imNuGnESSUGw8MEqwZ9m5iNnqjr3ALIMB+p X-Received: by 10.180.88.36 with SMTP id bd4mr820454wib.2.1445603859924; Fri, 23 Oct 2015 05:37:39 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.86.9 with SMTP id k9ls124415lfb.43.gmail; Fri, 23 Oct 2015 05:37:39 -0700 (PDT) X-Received: by 10.112.172.165 with SMTP id bd5mr10923850lbc.51.1445603859773; Fri, 23 Oct 2015 05:37:39 -0700 (PDT) Received: from mail-lf0-f52.google.com (mail-lf0-f52.google.com. [209.85.215.52]) by mx.google.com with ESMTPS id k80si12548407lfg.19.2015.10.23.05.37.39 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Oct 2015 05:37:39 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.52 as permitted sender) client-ip=209.85.215.52; Received: by lfbn126 with SMTP id n126so47429725lfb.2 for ; Fri, 23 Oct 2015 05:37:39 -0700 (PDT) X-Received: by 10.25.86.213 with SMTP id k204mr7243290lfb.36.1445603859530; Fri, 23 Oct 2015 05:37:39 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.59.35 with SMTP id w3csp1204427lbq; Fri, 23 Oct 2015 05:37:38 -0700 (PDT) X-Received: by 10.180.184.138 with SMTP id eu10mr4502476wic.25.1445603851410; Fri, 23 Oct 2015 05:37:31 -0700 (PDT) Received: from mail-wi0-f171.google.com (mail-wi0-f171.google.com. [209.85.212.171]) by mx.google.com with ESMTPS id a20si4761446wik.26.2015.10.23.05.37.31 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Oct 2015 05:37:31 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 209.85.212.171 as permitted sender) client-ip=209.85.212.171; Received: by wicfv8 with SMTP id fv8so30057921wic.0 for ; Fri, 23 Oct 2015 05:37:31 -0700 (PDT) X-Received: by 10.194.61.70 with SMTP id n6mr23149354wjr.81.1445603851207; Fri, 23 Oct 2015 05:37:31 -0700 (PDT) Received: from gnx2579.home (LMontsouris-657-1-37-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by smtp.gmail.com with ESMTPSA id s16sm2837652wik.16.2015.10.23.05.37.29 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Oct 2015 05:37:30 -0700 (PDT) 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 v3 6/7] vfio: platform: use list of registered reset function Date: Fri, 23 Oct 2015 14:37:14 +0200 Message-Id: <1445603835-14506-7-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1445603835-14506-1-git-send-email-eric.auger@linaro.org> References: <1445603835-14506-1-git-send-email-eric.auger@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: eric.auger@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.52 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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 --- 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 --- drivers/vfio/platform/vfio_platform_common.c | 52 +++++++++++++++------------ drivers/vfio/platform/vfio_platform_private.h | 7 +--- 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/drivers/vfio/platform/vfio_platform_common.c b/drivers/vfio/platform/vfio_platform_common.c index 50a388b..de3fb33 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 f8072d8..e505c15 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