From patchwork Fri Jun 5 15:06:31 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 49579 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f69.google.com (mail-la0-f69.google.com [209.85.215.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 45FE32154F for ; Fri, 5 Jun 2015 15:07:02 +0000 (UTC) Received: by laboh3 with SMTP id oh3sf20434015lab.0 for ; Fri, 05 Jun 2015 08:07:01 -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=lKkcQ2XnxSK1/LKLRtYvemmyVPLyh1+bDwKl0dpEUWY=; b=AfXaHGbFlp6LG5qMLVPh0z28xX8YVTg40p82FxXkjQT104InpnhlDn4q6wfnNRLJ1R BhUGK07T2Jo7oUWSY9pnq3gC4ZMJ9hTSBtf5T/TuQ/JFZ9147drLcn3bZvLQoRft6h69 Ccg6QGq8qX3z5BW2uejbAUpEU9j98JVmg3ACKMlBHHBUix16PJThUCH2iicfcETouMmS OQo6bZxtdGKLgJKetG2V6f3Rz9tFyfuFtNa9UX4mcyY5iUWGF0AI+Tbpbkfetd5UVMIP XpkaXw7vxqytHz3EYyucdZA0c5nUxCG9nayNcBFanirbTVJgSrzUd47Aki79HylHrcAB nzYA== X-Gm-Message-State: ALoCoQkzqGRH99UjcAQHWXA+/W6DtgcUSIv9O/QlpirpOCvsKkbh5URHF+970ipYez05wy8Xn85n X-Received: by 10.113.11.3 with SMTP id ee3mr3620286lbd.9.1433516821176; Fri, 05 Jun 2015 08:07:01 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.205.70 with SMTP id le6ls382048lac.50.gmail; Fri, 05 Jun 2015 08:07:01 -0700 (PDT) X-Received: by 10.112.199.133 with SMTP id jk5mr3914979lbc.32.1433516821036; Fri, 05 Jun 2015 08:07:01 -0700 (PDT) Received: from mail-lb0-f175.google.com (mail-lb0-f175.google.com. [209.85.217.175]) by mx.google.com with ESMTPS id ld2si5031551lab.101.2015.06.05.08.07.01 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 05 Jun 2015 08:07:01 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.175 as permitted sender) client-ip=209.85.217.175; Received: by lbcmx3 with SMTP id mx3so47846877lbc.1 for ; Fri, 05 Jun 2015 08:07:01 -0700 (PDT) X-Received: by 10.112.199.133 with SMTP id jk5mr3914972lbc.32.1433516820911; Fri, 05 Jun 2015 08:07:00 -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 hn6csp1507243lbb; Fri, 5 Jun 2015 08:07:00 -0700 (PDT) X-Received: by 10.194.240.8 with SMTP id vw8mr7010116wjc.114.1433516814180; Fri, 05 Jun 2015 08:06:54 -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 k5si4528982wix.79.2015.06.05.08.06.54 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 05 Jun 2015 08:06:54 -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 wgez8 with SMTP id z8so59090813wge.0 for ; Fri, 05 Jun 2015 08:06:54 -0700 (PDT) X-Received: by 10.180.95.40 with SMTP id dh8mr18923621wib.35.1433516813867; Fri, 05 Jun 2015 08:06:53 -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 dz4sm3827133wib.17.2015.06.05.08.06.52 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 05 Jun 2015 08:06:52 -0700 (PDT) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, linux-arm-kernel@lists.infradead.org, alex.williamson@redhat.com, b.reynal@virtualopensystems.com Cc: christoffer.dall@linaro.org, linux-kernel@vger.kernel.org, patches@linaro.org, agraf@suse.de Subject: [PATCH v2 3/4] VFIO: platform: populate the reset function on probe Date: Fri, 5 Jun 2015 17:06:31 +0200 Message-Id: <1433516792-16397-4-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1433516792-16397-1-git-send-email-eric.auger@linaro.org> References: <1433516792-16397-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.175 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 --- 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 | 48 +++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/drivers/vfio/platform/vfio_platform_common.c b/drivers/vfio/platform/vfio_platform_common.c index 995929b..d474d6a 100644 --- a/drivers/vfio/platform/vfio_platform_common.c +++ b/drivers/vfio/platform/vfio_platform_common.c @@ -31,6 +31,47 @@ static const struct vfio_platform_reset_combo reset_lookup_table[] = { }, }; +static int vfio_platform_get_reset(struct vfio_platform_device *vdev, + struct device *dev) +{ + const char *compat; + const struct vfio_platform_reset_combo *iter = reset_lookup_table; + int (*reset)(struct vfio_platform_device *); + int ret; + + vdev->type = VFIO_PLATFORM_RESET_TYPE_MAX; + ret = device_property_read_string(dev, "compatible", &compat); + if (ret) + return ret; + + while (iter->type < VFIO_PLATFORM_RESET_TYPE_MAX) { + if (!strcmp(iter->compat, compat)) { + request_module(iter->module_name); + reset = __symbol_get(iter->reset_function_name); + if (reset) { + vdev->type = iter->type; + vdev->reset = reset; + return 0; + } + } + iter++; + } + return -1; +} + +static void vfio_platform_put_reset(struct vfio_platform_device *vdev) +{ + const struct vfio_platform_reset_combo *iter = reset_lookup_table; + + while (iter->type < VFIO_PLATFORM_RESET_TYPE_MAX) { + if (iter->type == vdev->type) { + __symbol_put(iter->reset_function_name); + return; + } + iter++; + } +} + static int vfio_platform_regions_init(struct vfio_platform_device *vdev) { int cnt = 0, i; @@ -519,6 +560,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; @@ -530,8 +573,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; }