From patchwork Thu May 7 14:27:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 48129 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 ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 084382121F for ; Thu, 7 May 2015 14:30:24 +0000 (UTC) Received: by wicmx19 with SMTP id mx19sf16175718wic.3 for ; Thu, 07 May 2015 07:30:23 -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=lLDZt81qHABUnMxqL+b1R7PwD1rGpwxVq35gFTq6GuM=; b=hKg5ZkGqHrt6n+WbWfLfsXRA6W/klm1iZNamt6HJhKuYMXuYj7IJ+T4hBGSu03OrR2 Xc0kfQQo42LIIwn+P9R4z2f3NtAlKYp2NlwJP+RoBZ1W5zrWzGgev37iOGzKPRNZqHbV MY50Df5jmgj05ymJX8ykgVAydfhGCQH+B9rx91rFzglGP96GSjfLcgLVZY4IUrm/laAM 2d36ezVkEMsdd4x/zL2lay4XFJgPv5Aq0lBjQYnP7OshWCRp+Ey04iACkCBuFuvuA5uJ 3+R5N1t9HeGkMvyzxLFw3F9V3PpYLS2dXQazjw/8fvlkBg5isOLLsmoZljOeHlaKZvO6 /tWw== X-Gm-Message-State: ALoCoQnjWMkhutce9e9yoPVAzkyjuo3ayYyF2XLw5SJBOusxTaupjKig2PyYvgPj9cg56Rbyfaxh X-Received: by 10.152.8.17 with SMTP id n17mr2380353laa.0.1431009023297; Thu, 07 May 2015 07:30:23 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.36.34 with SMTP id n2ls193472laj.15.gmail; Thu, 07 May 2015 07:30:23 -0700 (PDT) X-Received: by 10.152.1.4 with SMTP id 4mr3296312lai.25.1431009023143; Thu, 07 May 2015 07:30:23 -0700 (PDT) Received: from mail-la0-f45.google.com (mail-la0-f45.google.com. [209.85.215.45]) by mx.google.com with ESMTPS id pu2si1402976lbb.69.2015.05.07.07.30.23 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 May 2015 07:30:23 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.45 as permitted sender) client-ip=209.85.215.45; Received: by lagv1 with SMTP id v1so31989724lag.3 for ; Thu, 07 May 2015 07:30:23 -0700 (PDT) X-Received: by 10.152.36.2 with SMTP id m2mr3256968laj.72.1431009022886; Thu, 07 May 2015 07:30:22 -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.67.65 with SMTP id l1csp3476086lbt; Thu, 7 May 2015 07:30:22 -0700 (PDT) X-Received: by 10.181.13.170 with SMTP id ez10mr7303977wid.72.1431009022211; Thu, 07 May 2015 07:30:22 -0700 (PDT) Received: from mail-wi0-f173.google.com (mail-wi0-f173.google.com. [209.85.212.173]) by mx.google.com with ESMTPS id p18si4223042wie.12.2015.05.07.07.30.21 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 May 2015 07:30:22 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 209.85.212.173 as permitted sender) client-ip=209.85.212.173; Received: by widdi4 with SMTP id di4so244795303wid.0 for ; Thu, 07 May 2015 07:30:21 -0700 (PDT) X-Received: by 10.180.89.231 with SMTP id br7mr7266619wib.60.1431009021884; Thu, 07 May 2015 07:30:21 -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 z12sm3704874wjw.39.2015.05.07.07.30.20 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 07 May 2015 07:30:21 -0700 (PDT) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, christoffer.dall@linaro.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, alex.williamson@redhat.com, b.reynal@virtualopensystems.com Cc: linux-kernel@vger.kernel.org, patches@linaro.org, agraf@suse.de, Bharat.Bhushan@freescale.com Subject: [PATCH 4/5] VFIO: platform: populate reset function according to compat Date: Thu, 7 May 2015 16:27:22 +0200 Message-Id: <1431008843-28411-5-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1431008843-28411-1-git-send-email-eric.auger@linaro.org> References: <1431008843-28411-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.45 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: , Add the reset function lookup according to the device compat string. This lookup is added at different places: - on VFIO_DEVICE_GET_INFO - on VFIO_DEVICE_RESET - on device release A reference to the module implementing the reset function is taken on first reset function lookup and released on vfio platform device release. Signed-off-by: Eric Auger --- drivers/vfio/platform/vfio_platform_common.c | 50 ++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/drivers/vfio/platform/vfio_platform_common.c b/drivers/vfio/platform/vfio_platform_common.c index 0d10018..bd7e44c 100644 --- a/drivers/vfio/platform/vfio_platform_common.c +++ b/drivers/vfio/platform/vfio_platform_common.c @@ -28,6 +28,52 @@ LIST_HEAD(reset_list); static DEFINE_MUTEX(driver_lock); +static vfio_platform_reset_fn_t vfio_platform_lookup_reset(const char *compat) +{ + struct vfio_platform_reset_node *iter; + + list_for_each_entry(iter, &reset_list, link) { + if (!strcmp(iter->compat, compat) && + try_module_get(iter->owner)) + return iter->reset; + } + + return ERR_PTR(-ENODEV); +} + +static vfio_platform_reset_fn_t vfio_platform_get_reset( + struct vfio_platform_device *vdev) +{ + struct device *dev = vdev->get_device(vdev); + const char *compat_str_array[2]; + vfio_platform_reset_fn_t reset; + int ret; + + if (!IS_ERR_OR_NULL(vdev->reset)) + return vdev->reset; + + ret = device_property_read_string_array(dev, "compatible", + compat_str_array, 2); + if (!ret) + return ERR_PTR(ret); + + reset = vfio_platform_lookup_reset(compat_str_array[0]); + return reset; +} + +static void vfio_platform_put_reset(struct vfio_platform_device *vdev) +{ + struct vfio_platform_reset_node *iter; + + list_for_each_entry(iter, &reset_list, link) { + if (iter->reset == vdev->reset) { + module_put(iter->owner); + vdev->reset = NULL; + return; + } + } +} + static int vfio_platform_regions_init(struct vfio_platform_device *vdev) { int cnt = 0, i; @@ -103,10 +149,12 @@ static void vfio_platform_release(void *device_data) mutex_lock(&driver_lock); if (!(--vdev->refcnt)) { + vdev->reset = vfio_platform_get_reset(vdev); if (!IS_ERR_OR_NULL(vdev->reset)) vdev->reset(vdev); vfio_platform_regions_cleanup(vdev); vfio_platform_irq_cleanup(vdev); + vfio_platform_put_reset(vdev); } mutex_unlock(&driver_lock); @@ -164,6 +212,7 @@ static long vfio_platform_ioctl(void *device_data, if (info.argsz < minsz) return -EINVAL; + vdev->reset = vfio_platform_get_reset(vdev); if (!IS_ERR_OR_NULL(vdev->reset)) vdev->flags |= VFIO_DEVICE_FLAGS_RESET; info.flags = vdev->flags; @@ -260,6 +309,7 @@ static long vfio_platform_ioctl(void *device_data, return ret; } else if (cmd == VFIO_DEVICE_RESET) { + vdev->reset = vfio_platform_get_reset(vdev); if (!IS_ERR_OR_NULL(vdev->reset)) return vdev->reset(vdev); else