From patchwork Sun Oct 18 16:00:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 55179 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 BD71B2309B for ; Sun, 18 Oct 2015 16:00:48 +0000 (UTC) Received: by wiyb4 with SMTP id b4sf16314999wiy.2 for ; Sun, 18 Oct 2015 09:00:48 -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=wHNW14uTwRYTvH92luf/UGnWMCqoffp6hAeFB2fEsow=; b=BkC4lws30oCf6pKaXiY+crEg724dh1FTA04WYf0+jqJuOuSg4SEhTQVyN54UUNQG6A CgDx/W9xMIYtXX3WCfCRWA1Ljm3Qy/phwjCvaa7QKTYLja+RipVu2ZwM/pWDCJJBp7Zs tgkAX9wslAXt11In5LFwrv8mTLpoKA6TSG/MfPfTA6gAY56boAMCpHuRm4ggxgpR2y8F uyRLe3msBknA3YFI+0B69lBfLwdrfNUH7jP6hOJu0zJvgsd6d/BCSaC+S83vnzmP+9Ik E2UUk4eWpq4UmD41BhXSZro4VrAbLP2wkpE7PZSgf+Ie8yoLABd2r1IzbkNRcXTUpOIZ RMaw== X-Gm-Message-State: ALoCoQm8ZIAgg4+lj+yU19cgaywmdm84gR2Na/d7FpBNnYsFaKVSPby6z06WLip1Z1zfiTnk+Byv X-Received: by 10.112.55.69 with SMTP id q5mr5948331lbp.24.1445184048024; Sun, 18 Oct 2015 09:00:48 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.141.74 with SMTP id p71ls439268lfd.77.gmail; Sun, 18 Oct 2015 09:00:47 -0700 (PDT) X-Received: by 10.112.157.74 with SMTP id wk10mr9350024lbb.54.1445184047894; Sun, 18 Oct 2015 09:00:47 -0700 (PDT) Received: from mail-lb0-f173.google.com (mail-lb0-f173.google.com. [209.85.217.173]) by mx.google.com with ESMTPS id gn4si1550898lbc.173.2015.10.18.09.00.47 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 18 Oct 2015 09:00:47 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.173 as permitted sender) client-ip=209.85.217.173; Received: by lbcao8 with SMTP id ao8so126363408lbc.3 for ; Sun, 18 Oct 2015 09:00:47 -0700 (PDT) X-Received: by 10.112.161.168 with SMTP id xt8mr11509273lbb.88.1445184047793; Sun, 18 Oct 2015 09:00:47 -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 w3csp1033846lbq; Sun, 18 Oct 2015 09:00:47 -0700 (PDT) X-Received: by 10.194.108.103 with SMTP id hj7mr27952685wjb.46.1445184047168; Sun, 18 Oct 2015 09:00:47 -0700 (PDT) Received: from mail-wi0-f175.google.com (mail-wi0-f175.google.com. [209.85.212.175]) by mx.google.com with ESMTPS id b2si17144193wiy.83.2015.10.18.09.00.47 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 18 Oct 2015 09:00:47 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 209.85.212.175 as permitted sender) client-ip=209.85.212.175; Received: by wicll6 with SMTP id ll6so67956057wic.1 for ; Sun, 18 Oct 2015 09:00:47 -0700 (PDT) X-Received: by 10.180.92.201 with SMTP id co9mr7685925wib.9.1445184046966; Sun, 18 Oct 2015 09:00:46 -0700 (PDT) Received: from gnx2579.st.com. ([78.232.41.119]) by smtp.gmail.com with ESMTPSA id jd7sm34740323wjb.19.2015.10.18.09.00.45 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 18 Oct 2015 09:00:46 -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 4/4] vfio: platform: use list of registered reset function Date: Sun, 18 Oct 2015 18:00:15 +0200 Message-Id: <1445184015-24414-5-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1445184015-24414-1-git-send-email-eric.auger@linaro.org> References: <1445184015-24414-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.217.173 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. 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 --- drivers/vfio/platform/vfio_platform_common.c | 46 +++++++++++++++------------ drivers/vfio/platform/vfio_platform_private.h | 1 + 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/drivers/vfio/platform/vfio_platform_common.c b/drivers/vfio/platform/vfio_platform_common.c index 31a6a8c..f3b6299 100644 --- a/drivers/vfio/platform/vfio_platform_common.c +++ b/drivers/vfio/platform/vfio_platform_common.c @@ -27,37 +27,41 @@ struct list_head reset_list; 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 vfio_platform_reset_fn_t vfio_platform_lookup_reset(const char *compat, + struct module **module) +{ + struct vfio_platform_reset_node *iter; + + list_for_each_entry(iter, &reset_list, link) { + if (!strcmp(iter->compat, compat) && + try_module_get(iter->owner)) { + *module = iter->owner; + return iter->reset; + } + } + + return NULL; +} static void vfio_platform_get_reset(struct vfio_platform_device *vdev, struct device *dev) { - int (*reset)(struct vfio_platform_device *); - int i; - - 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; - } - } + 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) diff --git a/drivers/vfio/platform/vfio_platform_private.h b/drivers/vfio/platform/vfio_platform_private.h index b274646..2070dcc 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