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: Eric Auger X-Patchwork-Id: 6587951 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 5333CC0020 for ; Thu, 11 Jun 2015 12:12:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 682ED20396 for ; Thu, 11 Jun 2015 12:12:57 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7FA0F2038E for ; Thu, 11 Jun 2015 12:12:56 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Z31JZ-0002L9-3I; Thu, 11 Jun 2015 12:10:33 +0000 Received: from mail-wi0-f174.google.com ([209.85.212.174]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Z31Ie-0000lW-68 for linux-arm-kernel@lists.infradead.org; Thu, 11 Jun 2015 12:09:37 +0000 Received: by wiwd19 with SMTP id d19so73090069wiw.0 for ; Thu, 11 Jun 2015 05:09:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=2ytXNYL/eWDAPmwqdg3qiOzV+x/iWf6ley5ITYyeV60=; b=itMtKTff1M63iJnrcQb1KCZWOBe4TCBT76l9Di4SrnUgw7pzixpOMhUMt4Q6LE9LPW +rWue2LwQ/HjpvYoWtvzwqO6hKZN8n4NMD31qig4NhW4LFLdmZPRzSjsbSxh/02KvXg2 D2kX0tyPEdJx2JtrMMfJG8ecTr6lBZ17VcblpbbyeMlD0E7pYNULsFe5i3OSUkQO7AZV i7n5OOD+uKuIEJmgjDFxX6fu38u5FIIrpfqUQTys2RLxo5WCctUVxIu6+9fxVexlJrTX QTitPDlQk0vDxXwwF5s15si9UfpS7Ogxc1346KkyEMZ142bxFVLPtQgkvghKIfFaNc8B MD6g== X-Gm-Message-State: ALoCoQme0Ho3bkY4opvuGVNCMYHrCZSK6mwMMud7GIdLWcxbJDeurGGGgiRJCs8PrbaWMhYEr3vF 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 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150611_050936_446054_F93C14E4 X-CRM114-Status: GOOD ( 14.43 ) X-Spam-Score: -0.7 (/) Cc: linux-kernel@vger.kernel.org, christoffer.dall@linaro.org, patches@linaro.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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; }