From patchwork Mon Jun 15 09:09:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 49845 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f69.google.com (mail-wg0-f69.google.com [74.125.82.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6B4D1211FD for ; Mon, 15 Jun 2015 09:10:18 +0000 (UTC) Received: by wgv5 with SMTP id 5sf23260074wgv.0 for ; Mon, 15 Jun 2015 02:10:17 -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=2ytXNYL/eWDAPmwqdg3qiOzV+x/iWf6ley5ITYyeV60=; b=JWQcwyuuGu/4KzTLXmX/VgGvi9uW+eStxbjltu9izUM8fdhZWuK3Q8OMB3LiikduIW 2vuYcX8TUV/mTUaNMAO8F74JfeO6duq2cUqR9LEzi6dYW6ZjpAmFkSdJKqXy/3eXsB37 Q5SgzYhBbaNBKzELKtQJ83ic4wwN8YG21ayz1cjHpxqqd3jPx5QIM10060LOi4H7vLz7 Vs0jOh/MuPWUfglSuxgmjr/FdzLIKm+RGcMOMLOmeqM0hiAiyV+ae3nuCHyI5WdBK3nL I8m1+E20uXcDFEJK+F2P8AZ0OcQcOw/0NFyxd36Ysd0H3PByByDN4QILbzDD6q12Cnak rd4w== X-Gm-Message-State: ALoCoQnQj8fM8THRpPCKxDZKCyysK+eNP9tQdRSoQjNWifDqAa7AXCdJcE8vd21NmUC4qVnwxNHn X-Received: by 10.152.3.131 with SMTP id c3mr28917539lac.4.1434359417657; Mon, 15 Jun 2015 02:10:17 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.182.228 with SMTP id eh4ls827238lac.45.gmail; Mon, 15 Jun 2015 02:10:17 -0700 (PDT) X-Received: by 10.152.43.37 with SMTP id t5mr25556574lal.96.1434359417491; Mon, 15 Jun 2015 02:10:17 -0700 (PDT) Received: from mail-lb0-f180.google.com (mail-lb0-f180.google.com. [209.85.217.180]) by mx.google.com with ESMTPS id x10si9979014lax.97.2015.06.15.02.10.17 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Jun 2015 02:10:17 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.180 as permitted sender) client-ip=209.85.217.180; Received: by lbbqq2 with SMTP id qq2so49300615lbb.3 for ; Mon, 15 Jun 2015 02:10:17 -0700 (PDT) X-Received: by 10.112.204.6 with SMTP id ku6mr26121029lbc.73.1434359417361; Mon, 15 Jun 2015 02:10:17 -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.108.230 with SMTP id hn6csp1275447lbb; Mon, 15 Jun 2015 02:10:16 -0700 (PDT) X-Received: by 10.180.188.48 with SMTP id fx16mr29527125wic.35.1434359412373; Mon, 15 Jun 2015 02:10:12 -0700 (PDT) Received: from mail-wi0-f179.google.com (mail-wi0-f179.google.com. [209.85.212.179]) by mx.google.com with ESMTPS id ab3si17236745wid.70.2015.06.15.02.10.12 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Jun 2015 02:10:12 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 209.85.212.179 as permitted sender) client-ip=209.85.212.179; Received: by wiga1 with SMTP id a1so70402491wig.0 for ; Mon, 15 Jun 2015 02:10:12 -0700 (PDT) X-Received: by 10.194.157.194 with SMTP id wo2mr50507742wjb.103.1434359412182; Mon, 15 Jun 2015 02:10:12 -0700 (PDT) Received: from gnx2579.home (LCaen-156-56-7-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by mx.google.com with ESMTPSA id 12sm17920944wjw.17.2015.06.15.02.10.10 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Jun 2015 02:10:11 -0700 (PDT) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, linux-arm-kernel@lists.infradead.org, b.reynal@virtualopensystems.com, alex.williamson@redhat.com Cc: linux-kernel@vger.kernel.org, patches@linaro.org, christoffer.dall@linaro.org Subject: [PATCH v4 3/4] VFIO: platform: populate the reset function on probe Date: Mon, 15 Jun 2015 11:09:44 +0200 Message-Id: <1434359385-19916-4-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1434359385-19916-1-git-send-email-eric.auger@linaro.org> References: <1434359385-19916-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.180 as permitted sender) smtp.mail=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: , The reset function lookup happens on vfio-platform probe. The reset module load is requested and a reference to the function symbol is hold. The reference is released on vfio-platform remove. Signed-off-by: Eric Auger --- v2 -> v3: - vfio_platform_get_reset becomes void - use ARRAY_SIZE - use symbol_put_addr v1 -> v2: - [get,put]_reset now is called once on probe/remove - use request_module to automatically load the reset module that matches the compatibility string - lookup table is used instead of list - remove registration mechanism: reset function name is stored in the lookup table. - use device_property_read_string instead of device_property_read_string_array --- drivers/vfio/platform/vfio_platform_common.c | 37 +++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/drivers/vfio/platform/vfio_platform_common.c b/drivers/vfio/platform/vfio_platform_common.c index 6393581..f3391a9 100644 --- a/drivers/vfio/platform/vfio_platform_common.c +++ b/drivers/vfio/platform/vfio_platform_common.c @@ -28,6 +28,36 @@ static DEFINE_MUTEX(driver_lock); static const struct vfio_platform_reset_combo reset_lookup_table[] = { }; +static void vfio_platform_get_reset(struct vfio_platform_device *vdev, + struct device *dev) +{ + const char *compat; + int (*reset)(struct vfio_platform_device *); + int ret, i; + + ret = device_property_read_string(dev, "compatible", &compat); + if (ret) + return; + + for (i = 0 ; i < ARRAY_SIZE(reset_lookup_table); i++) { + if (!strcmp(reset_lookup_table[i].compat, 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; + } + } + } +} + +static void vfio_platform_put_reset(struct vfio_platform_device *vdev) +{ + if (vdev->reset) + symbol_put_addr(vdev->reset); +} + static int vfio_platform_regions_init(struct vfio_platform_device *vdev) { int cnt = 0, i; @@ -516,6 +546,8 @@ int vfio_platform_probe_common(struct vfio_platform_device *vdev, return ret; } + vfio_platform_get_reset(vdev, dev); + mutex_init(&vdev->igate); return 0; @@ -527,8 +559,11 @@ struct vfio_platform_device *vfio_platform_remove_common(struct device *dev) struct vfio_platform_device *vdev; vdev = vfio_del_group_dev(dev); - if (vdev) + + if (vdev) { + vfio_platform_put_reset(vdev); iommu_group_put(dev->iommu_group); + } return vdev; }