From patchwork Fri Oct 23 12:37:10 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 55485 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by patches.linaro.org (Postfix) with ESMTPS id 68DD320581 for ; Fri, 23 Oct 2015 12:37:28 +0000 (UTC) Received: by wicfg8 with SMTP id fg8sf10696599wic.0 for ; Fri, 23 Oct 2015 05:37:27 -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=j62Oy6/CUUg/XiOEjM2KlkgPGFl3bf4+8GEKTn1isjg=; b=iH0e1u9Y8ToWOlKDYKnrBROpKXnqsiQ2IzEbiaqd7MeTAbWupea0yhTCBwkYfYUIpJ Q8anQgMkhZwCyZ675UfSSJwX2XHT1SLyd8jh2scYBX0kFgyb2l6Ih6bn86IgC1MW3jWS 8JfeDfqcJoQFjQJ6Na3T8ZtEaLicirxRuNbZ3ba/k5RL8/8hKM4tyXYIRSaoFMtDQSqB LUhDDCBL5jdEN0P+jWryfztG2dhqHE0YsRHQRx1cCpe8w+k+uewtbMBkGQvDn1MPL9sP 1EFD1ZQxDuuFVstK/bA4WxWRYGxU5AT0s/kyQb8r32uWY+Mlx2KDtVtuR7fhfIO/8Zl6 kv8Q== X-Gm-Message-State: ALoCoQk32YYoyEKXXOmSYLlFJUWct+xXfE4mQ/q1MEc5Wq8wsyiK630oU/zaY2Q1rPy233b24tXY X-Received: by 10.180.89.41 with SMTP id bl9mr823127wib.3.1445603847732; Fri, 23 Oct 2015 05:37:27 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.16.40 with SMTP id f40ls433592lfi.59.gmail; Fri, 23 Oct 2015 05:37:27 -0700 (PDT) X-Received: by 10.25.28.131 with SMTP id c125mr5853944lfc.99.1445603847579; Fri, 23 Oct 2015 05:37:27 -0700 (PDT) Received: from mail-lf0-f48.google.com (mail-lf0-f48.google.com. [209.85.215.48]) by mx.google.com with ESMTPS id q20si12547468lfe.30.2015.10.23.05.37.27 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Oct 2015 05:37:27 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) client-ip=209.85.215.48; Received: by lfbn126 with SMTP id n126so47423882lfb.2 for ; Fri, 23 Oct 2015 05:37:27 -0700 (PDT) X-Received: by 10.25.154.203 with SMTP id c194mr7324979lfe.32.1445603847455; Fri, 23 Oct 2015 05:37:27 -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.59.35 with SMTP id w3csp1204286lbq; Fri, 23 Oct 2015 05:37:26 -0700 (PDT) X-Received: by 10.180.187.178 with SMTP id ft18mr4710165wic.10.1445603844875; Fri, 23 Oct 2015 05:37:24 -0700 (PDT) Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com. [209.85.212.181]) by mx.google.com with ESMTPS id ew8si4758492wic.36.2015.10.23.05.37.24 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Oct 2015 05:37:24 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 209.85.212.181 as permitted sender) client-ip=209.85.212.181; Received: by wikq8 with SMTP id q8so74965080wik.1 for ; Fri, 23 Oct 2015 05:37:24 -0700 (PDT) X-Received: by 10.180.182.103 with SMTP id ed7mr4416908wic.38.1445603844603; Fri, 23 Oct 2015 05:37:24 -0700 (PDT) Received: from gnx2579.home (LMontsouris-657-1-37-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by smtp.gmail.com with ESMTPSA id s16sm2837652wik.16.2015.10.23.05.37.22 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Oct 2015 05:37:23 -0700 (PDT) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, alex.williamson@redhat.com, b.reynal@virtualopensystems.com, arnd@arndb.de, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org Cc: christoffer.dall@linaro.org, linux-kernel@vger.kernel.org, patches@linaro.org Subject: [PATCH v3 2/7] vfio: platform: add capability to register a reset function Date: Fri, 23 Oct 2015 14:37:10 +0200 Message-Id: <1445603835-14506-3-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1445603835-14506-1-git-send-email-eric.auger@linaro.org> References: <1445603835-14506-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.48 as permitted sender) smtp.mailfrom=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: , In preparation for subsequent changes in reset function lookup, lets introduce a dynamic list of reset combos (compat string, reset module, reset function). The list can be populated/voided with two new functions, vfio_platform_register/unregister_reset. Those are not yet used in this patch. Signed-off-by: Eric Auger --- v2 -> v3: - use goto out to have a single mutex_unlock - implement vfio_platform_register_reset as a macro (suggested by Arnd) - move reset_node struct declaration back to vfio_platform_private.h - vfio_platform_unregister_reset does not return any value anymore v1 -> v2: - reset_list becomes static - vfio_platform_register/unregister_reset take a const char * as compat - fix node leak - add reset_lock to protect the reset list manipulation - move vfio_platform_reset_node declaration in vfio_platform_common.c --- drivers/vfio/platform/vfio_platform_common.c | 26 ++++++++++++++++++++++++++ drivers/vfio/platform/vfio_platform_private.h | 20 ++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/drivers/vfio/platform/vfio_platform_common.c b/drivers/vfio/platform/vfio_platform_common.c index 184e9d2..8eccd30 100644 --- a/drivers/vfio/platform/vfio_platform_common.c +++ b/drivers/vfio/platform/vfio_platform_common.c @@ -27,6 +27,7 @@ #define DRIVER_AUTHOR "Antonios Motakis " #define DRIVER_DESC "VFIO platform base module" +static LIST_HEAD(reset_list); static DEFINE_MUTEX(driver_lock); static const struct vfio_platform_reset_combo reset_lookup_table[] = { @@ -578,6 +579,31 @@ struct vfio_platform_device *vfio_platform_remove_common(struct device *dev) } EXPORT_SYMBOL_GPL(vfio_platform_remove_common); +int __vfio_platform_register_reset(struct vfio_platform_reset_node *node) +{ + mutex_lock(&driver_lock); + list_add(&node->link, &reset_list); + mutex_unlock(&driver_lock); + return 0; +} +EXPORT_SYMBOL_GPL(__vfio_platform_register_reset); + +void vfio_platform_unregister_reset(const char *compat) +{ + struct vfio_platform_reset_node *iter, *temp; + + mutex_lock(&driver_lock); + list_for_each_entry_safe(iter, temp, &reset_list, link) { + if (!strcmp(iter->compat, compat)) { + list_del(&iter->link); + break; + } + } + + mutex_unlock(&driver_lock); +} +EXPORT_SYMBOL_GPL(vfio_platform_unregister_reset); + MODULE_VERSION(DRIVER_VERSION); MODULE_LICENSE("GPL v2"); MODULE_AUTHOR(DRIVER_AUTHOR); diff --git a/drivers/vfio/platform/vfio_platform_private.h b/drivers/vfio/platform/vfio_platform_private.h index 7128690..277521a 100644 --- a/drivers/vfio/platform/vfio_platform_private.h +++ b/drivers/vfio/platform/vfio_platform_private.h @@ -71,6 +71,15 @@ struct vfio_platform_device { int (*reset)(struct vfio_platform_device *vdev); }; +typedef int (*vfio_platform_reset_fn_t)(struct vfio_platform_device *vdev); + +struct vfio_platform_reset_node { + struct list_head link; + char *compat; + struct module *owner; + vfio_platform_reset_fn_t reset; +}; + struct vfio_platform_reset_combo { const char *compat; const char *reset_function_name; @@ -90,4 +99,15 @@ extern int vfio_platform_set_irqs_ioctl(struct vfio_platform_device *vdev, unsigned start, unsigned count, void *data); +extern int __vfio_platform_register_reset(struct vfio_platform_reset_node *n); +extern void vfio_platform_unregister_reset(const char *compat); + +#define vfio_platform_register_reset(__compat, __reset) \ +static struct vfio_platform_reset_node __reset ## _node = { \ + .owner = THIS_MODULE, \ + .compat = __compat, \ + .reset = __reset, \ +}; \ +__vfio_platform_register_reset(&__reset ## _node) + #endif /* VFIO_PLATFORM_PRIVATE_H */