From patchwork Thu Oct 22 09:41:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 55419 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lf0-f69.google.com (mail-lf0-f69.google.com [209.85.215.69]) by patches.linaro.org (Postfix) with ESMTPS id 093FB2304B for ; Thu, 22 Oct 2015 09:42:13 +0000 (UTC) Received: by lfu67 with SMTP id 67sf3503514lfu.2 for ; Thu, 22 Oct 2015 02:42:11 -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=OI5cZ2uqBePP31TXYHqmt7h0J7iXh5WPaF3jpMeOwrk=; b=EthR9wDj2wceFpFUblyEVEAmLkDGX8SlOR9qV6DEPWnkD1MGyRDzD8EXTzLhMWOMLI rjAdOvKQiAzeo3RXxC/KAhrwOV4r1+KNLBZb1GLmkInGA5858paFiSi5hUDwW+6m6nHe pITezGmw8718LEvpKwx9Tu9xIe4lrxVSeGdh51F6uUpEv4gT62YIH75bxg5obgWtxxaV KE+SEGT+mjog8czMR6a5TLb3TpjMPKLS5e9QEiSJdE1BjVPIl3sWNfVrx3QWsbnxjrz1 VoAOE4GAXCY1C2s4g+jc6Le37lbnFNHeYnfRaW6SuyEZigIQ0z2vf+JIUai6v4E+Zzlf M0aA== X-Gm-Message-State: ALoCoQntJPjpM3I9CYYczRENRKGAFtwd11S3v1jO9g7efhHAJttCP9v88U0xDvAyho0IiuWn4brD X-Received: by 10.112.159.4 with SMTP id wy4mr3362602lbb.15.1445506931932; Thu, 22 Oct 2015 02:42:11 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.91.195 with SMTP id p186ls140479lfb.28.gmail; Thu, 22 Oct 2015 02:42:11 -0700 (PDT) X-Received: by 10.25.24.27 with SMTP id o27mr5108549lfi.5.1445506931803; Thu, 22 Oct 2015 02:42:11 -0700 (PDT) Received: from mail-lf0-f44.google.com (mail-lf0-f44.google.com. [209.85.215.44]) by mx.google.com with ESMTPS id al9si9053552lbc.51.2015.10.22.02.42.11 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Oct 2015 02:42:11 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) client-ip=209.85.215.44; Received: by lffv3 with SMTP id v3so41204905lff.0 for ; Thu, 22 Oct 2015 02:42:11 -0700 (PDT) X-Received: by 10.25.154.203 with SMTP id c194mr5223138lfe.32.1445506931689; Thu, 22 Oct 2015 02:42:11 -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 w3csp485336lbq; Thu, 22 Oct 2015 02:42:10 -0700 (PDT) X-Received: by 10.194.187.72 with SMTP id fq8mr16273331wjc.131.1445506930953; Thu, 22 Oct 2015 02:42:10 -0700 (PDT) Received: from mail-wi0-f170.google.com (mail-wi0-f170.google.com. [209.85.212.170]) by mx.google.com with ESMTPS id ce5si17284120wjb.106.2015.10.22.02.42.10 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Oct 2015 02:42:10 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 209.85.212.170 as permitted sender) client-ip=209.85.212.170; Received: by wicll6 with SMTP id ll6so110628916wic.1 for ; Thu, 22 Oct 2015 02:42:10 -0700 (PDT) X-Received: by 10.180.93.168 with SMTP id cv8mr40884937wib.54.1445506930573; Thu, 22 Oct 2015 02:42:10 -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 lr6sm9376859wic.3.2015.10.22.02.42.08 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Oct 2015 02:42:09 -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 v2 1/6] vfio: platform: add capability to register a reset function Date: Thu, 22 Oct 2015 11:41:57 +0200 Message-Id: <1445506922-6005-2-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1445506922-6005-1-git-send-email-eric.auger@linaro.org> References: <1445506922-6005-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.44 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 --- 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 | 77 +++++++++++++++++++++++++++ drivers/vfio/platform/vfio_platform_private.h | 7 +++ 2 files changed, 84 insertions(+) diff --git a/drivers/vfio/platform/vfio_platform_common.c b/drivers/vfio/platform/vfio_platform_common.c index e43efb5..52a4c7b 100644 --- a/drivers/vfio/platform/vfio_platform_common.c +++ b/drivers/vfio/platform/vfio_platform_common.c @@ -23,6 +23,15 @@ #include "vfio_platform_private.h" +struct vfio_platform_reset_node { + struct list_head link; + char *compat; + struct module *owner; + vfio_platform_reset_fn_t reset; +}; + +static LIST_HEAD(reset_list); +static DEFINE_MUTEX(reset_lock); static DEFINE_MUTEX(driver_lock); static const struct vfio_platform_reset_combo reset_lookup_table[] = { @@ -573,3 +582,71 @@ struct vfio_platform_device *vfio_platform_remove_common(struct device *dev) return vdev; } EXPORT_SYMBOL_GPL(vfio_platform_remove_common); + +int vfio_platform_register_reset(struct module *reset_owner, + const char *compat, + vfio_platform_reset_fn_t reset) +{ + struct vfio_platform_reset_node *node, *iter; + bool found = false; + + mutex_lock(&reset_lock); + list_for_each_entry(iter, &reset_list, link) { + if (!strcmp(iter->compat, compat)) { + found = true; + break; + } + } + if (found) { + mutex_unlock(&reset_lock); + return -EINVAL; + } + + node = kmalloc(sizeof(*node), GFP_KERNEL); + if (!node) { + mutex_unlock(&reset_lock); + return -ENOMEM; + } + + node->compat = kstrdup(compat, GFP_KERNEL); + if (!node->compat) { + kfree(node); + mutex_unlock(&reset_lock); + return -ENOMEM; + } + + node->owner = reset_owner; + node->reset = reset; + + list_add(&node->link, &reset_list); + mutex_unlock(&reset_lock); + return 0; +} +EXPORT_SYMBOL_GPL(vfio_platform_register_reset); + +int vfio_platform_unregister_reset(const char *compat) +{ + struct vfio_platform_reset_node *iter; + bool found = false; + + mutex_lock(&reset_lock); + list_for_each_entry(iter, &reset_list, link) { + if (!strcmp(iter->compat, compat)) { + found = true; + break; + } + } + if (!found) { + mutex_unlock(&reset_lock); + return -EINVAL; + } + + list_del(&iter->link); + kfree(iter->compat); + kfree(iter); + mutex_unlock(&reset_lock); + + return 0; +} +EXPORT_SYMBOL_GPL(vfio_platform_unregister_reset); + diff --git a/drivers/vfio/platform/vfio_platform_private.h b/drivers/vfio/platform/vfio_platform_private.h index 1c9b3d5..1fb1410 100644 --- a/drivers/vfio/platform/vfio_platform_private.h +++ b/drivers/vfio/platform/vfio_platform_private.h @@ -89,4 +89,11 @@ extern int vfio_platform_set_irqs_ioctl(struct vfio_platform_device *vdev, unsigned start, unsigned count, void *data); +typedef int (*vfio_platform_reset_fn_t)(struct vfio_platform_device *vdev); + +extern int vfio_platform_register_reset(struct module *owner, + const char *compat, + vfio_platform_reset_fn_t reset); +extern int vfio_platform_unregister_reset(const char *compat); + #endif /* VFIO_PLATFORM_PRIVATE_H */