From patchwork Thu Jun 11 12:08:46 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 49758 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A76C320C81 for ; Thu, 11 Jun 2015 12:09:16 +0000 (UTC) Received: by lbbti3 with SMTP id ti3sf1458842lbb.1 for ; Thu, 11 Jun 2015 05:09:15 -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=Ib2BlO3rcLl1C1A3MdVc2j8PSpJhXPmwCaRnxLx4San8Jx7B0Zqs2KOHSAoKnRxU7L aL280Ij+pNyYkVLYWSN7uxT/dmJXh9d5VIhl5U1yYOBtGtQ/8s2S3j55/wtZlEPmzu0A Rp7aoHpZAc05AaVIwb7L9hzedHwznjkKrxjPV2NiBgxRtQC+xKsE9i3I8jVlAFEU2iHL z3QjXmEAqBNIqvj+TE3E++li4+AkJ9WnMVQY64wcXzYMedYxmmThXUFsp+AUI+pnwyEN Tr5EXuAjqXapbNBKqn+3DQwaI+Pvy6OJvlNLTHLjHJzfwtt2tCCH2ql4WrPTP7HQ9M6I WJZw== X-Gm-Message-State: ALoCoQmqSonHTfhCD22HgKu0saMEF9NISLqJOic5XgXNNpDsBsOPaIhoa407zYGUGO6k/0j2P8lo X-Received: by 10.152.37.101 with SMTP id x5mr8196196laj.5.1434024555603; Thu, 11 Jun 2015 05:09:15 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.4.73 with SMTP id i9ls388650lai.100.gmail; Thu, 11 Jun 2015 05:09:15 -0700 (PDT) X-Received: by 10.112.168.102 with SMTP id zv6mr9533867lbb.45.1434024555462; Thu, 11 Jun 2015 05:09:15 -0700 (PDT) Received: from mail-la0-f47.google.com (mail-la0-f47.google.com. [209.85.215.47]) by mx.google.com with ESMTPS id mk5si443262lbc.47.2015.06.11.05.09.15 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Jun 2015 05:09:15 -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 lazv15 with SMTP id v15so3306621laz.3 for ; Thu, 11 Jun 2015 05:09:15 -0700 (PDT) X-Received: by 10.152.206.75 with SMTP id lm11mr9337761lac.41.1434024555325; Thu, 11 Jun 2015 05:09:15 -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 hn6csp3995622lbb; Thu, 11 Jun 2015 05:09:14 -0700 (PDT) X-Received: by 10.180.105.38 with SMTP id gj6mr18488888wib.90.1434024554441; Thu, 11 Jun 2015 05:09:14 -0700 (PDT) Received: from mail-wg0-f51.google.com (mail-wg0-f51.google.com. [74.125.82.51]) by mx.google.com with ESMTPS id y20si914632wjq.3.2015.06.11.05.09.14 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Jun 2015 05:09:14 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 74.125.82.51 as permitted sender) client-ip=74.125.82.51; Received: by wgbgq6 with SMTP id gq6so4048860wgb.3 for ; Thu, 11 Jun 2015 05:09:14 -0700 (PDT) X-Received: by 10.180.88.72 with SMTP id be8mr29438859wib.45.1434024554177; Thu, 11 Jun 2015 05:09:14 -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 vz2sm796336wjc.18.2015.06.11.05.09.12 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Jun 2015 05:09:12 -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 v3 3/4] VFIO: platform: populate the reset function on probe Date: Thu, 11 Jun 2015 14:08:46 +0200 Message-Id: <1434024527-13869-4-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1434024527-13869-1-git-send-email-eric.auger@linaro.org> References: <1434024527-13869-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.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; }