From patchwork Thu Oct 22 09:42:01 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 55423 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lf0-f72.google.com (mail-lf0-f72.google.com [209.85.215.72]) by patches.linaro.org (Postfix) with ESMTPS id ED74F2304B for ; Thu, 22 Oct 2015 09:42:19 +0000 (UTC) Received: by lfaz124 with SMTP id z124sf29385652lfa.0 for ; Thu, 22 Oct 2015 02:42:19 -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=ThZlISKcTtFT/T1m1FWtYEQFQ3tTGsD9Sv0/xfLfyEs=; b=Xpr8v69GtTOSWjgSUEh1wuCdDdtrS0dXP0Ag0bnPMHBY2kRYuIGrEwIWqS0+pNh8Fy CALeZSy0svlddRbdR9MqOA3Umu/1SjarIhY388wuHQTPgJqO1CMSgwtd5XmpZgDnV1ym MybOxnJxhj4dl1WiNGotrgQZoV9F/fvRW7LjSDlg2Sc1uoTMultMkhKxLelQXGILD1a7 bog/Fed1ou8Bl70AaYvF5kztlmQ2WMZvRpxDLhcfIzGTRBQ1Xg5yeCbLNyN/0q8wbwQr Gl+rQD3V5toUfsj12+X4V+WwXbUhhTAtOPZtnO51FrXYLuwfXjGdds8JqCX/uwhRUdwV +0iw== X-Gm-Message-State: ALoCoQnaDdePePLnLpT4Cazf/JaDOEDU+KnrbgJnthhzy1+bTJOeJMCM1+8zB6vXAens8ZBRM1Od X-Received: by 10.180.9.104 with SMTP id y8mr8101376wia.7.1445506939001; Thu, 22 Oct 2015 02:42:19 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.147.194 with SMTP id v185ls311610lfd.22.gmail; Thu, 22 Oct 2015 02:42:18 -0700 (PDT) X-Received: by 10.112.36.229 with SMTP id t5mr7973997lbj.61.1445506938858; Thu, 22 Oct 2015 02:42:18 -0700 (PDT) Received: from mail-lf0-f47.google.com (mail-lf0-f47.google.com. [209.85.215.47]) by mx.google.com with ESMTPS id s199si9044471lfd.168.2015.10.22.02.42.18 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Oct 2015 02:42:18 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.47 as permitted sender) client-ip=209.85.215.47; Received: by lfaz124 with SMTP id z124so41209910lfa.1 for ; Thu, 22 Oct 2015 02:42:18 -0700 (PDT) X-Received: by 10.25.205.193 with SMTP id d184mr2931309lfg.72.1445506938703; Thu, 22 Oct 2015 02:42:18 -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 w3csp485406lbq; Thu, 22 Oct 2015 02:42:18 -0700 (PDT) X-Received: by 10.181.13.101 with SMTP id ex5mr35471338wid.2.1445506936551; Thu, 22 Oct 2015 02:42:16 -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 cq9si17314921wjb.31.2015.10.22.02.42.16 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Oct 2015 02:42:16 -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 wijp11 with SMTP id p11so23071323wij.0 for ; Thu, 22 Oct 2015 02:42:16 -0700 (PDT) X-Received: by 10.180.188.100 with SMTP id fz4mr40896671wic.28.1445506936359; Thu, 22 Oct 2015 02:42:16 -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 lr6sm9376859wic.3.2015.10.22.02.42.15 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Oct 2015 02:42:15 -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 v2 5/6] vfio: platform: use list of registered reset function Date: Thu, 22 Oct 2015 11:42:01 +0200 Message-Id: <1445506922-6005-6-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1445506922-6005-1-git-send-email-eric.auger@linaro.org> References: <1445506922-6005-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.47 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 --- 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 | 57 ++++++++++++++++----------- drivers/vfio/platform/vfio_platform_private.h | 7 +--- 2 files changed, 34 insertions(+), 30 deletions(-) diff --git a/drivers/vfio/platform/vfio_platform_common.c b/drivers/vfio/platform/vfio_platform_common.c index e7d615f..95b8294 100644 --- a/drivers/vfio/platform/vfio_platform_common.c +++ b/drivers/vfio/platform/vfio_platform_common.c @@ -34,37 +34,46 @@ static LIST_HEAD(reset_list); static DEFINE_MUTEX(reset_lock); 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; - 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(&reset_lock); + list_for_each_entry(iter, &reset_list, link) { + if (!strcmp(iter->compat, compat) && + try_module_get(iter->owner)) { + *module = iter->owner; + mutex_unlock(&reset_lock); + return iter->reset; } } + + mutex_unlock(&reset_lock); + return NULL; +} + +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); + if (vdev->reset) { + module_put(vdev->reset_module); + vdev->reset_module = NULL; + vdev->reset = NULL; + } } static int vfio_platform_regions_init(struct vfio_platform_device *vdev) @@ -561,7 +570,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 620ee40..e968454 100644 --- a/drivers/vfio/platform/vfio_platform_private.h +++ b/drivers/vfio/platform/vfio_platform_private.h @@ -57,6 +57,7 @@ struct vfio_platform_device { int refcnt; struct mutex igate; const char *compat; + struct module *reset_module; /* * These fields should be filled by the bus specific binder @@ -71,12 +72,6 @@ struct vfio_platform_device { int (*reset)(struct vfio_platform_device *vdev); }; -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