From patchwork Thu Oct 22 09:41:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 55420 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by patches.linaro.org (Postfix) with ESMTPS id CA13F230CB for ; Thu, 22 Oct 2015 09:42:13 +0000 (UTC) Received: by wiclg3 with SMTP id lg3sf31196716wic.3 for ; Thu, 22 Oct 2015 02:42:13 -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=TXTaOkBOTGGYQ++vx0XPtoADKzTKJpMvSRLnoV38E2o=; b=HghGAsAN0q4evFpM61+/PDaSwBsh4X+DY+1seA7/qlNbGrH+1Srqpe2SewkQyxhgsi 8c8WAAnlllOk4Kfqv5d5XNZ10K4Bs09lSBNS2YcN8IPc+AbinYVnwZAKE3iDL2kA3Avh Sgl17A+QH5s/2Oss3trsEpuSjwZD0dE5+7ivr8K4ZKWmYNlizVg0LepfMJjosc6xLCoM KpXQLs5kWhinT2RO1fEhYZgYrN8pV2fWiBMCuKL7LghAsKkmT8JsUEa69oQeivn19iOS /112B5hOiMP2RWxKyVuWzrpPpbeKKs+aasrrcKlDmlWTOwcN4DL42n24dyu2ioAYQ/um rk9Q== X-Gm-Message-State: ALoCoQllsyGxnkpq9zP7R53LDsbrnS4lXI4aIwuqNS3RBJs9O3KTTph/ok+2nCWLzKkHEUJ1/2gt X-Received: by 10.180.86.227 with SMTP id s3mr3516627wiz.0.1445506933149; Thu, 22 Oct 2015 02:42:13 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.208.78 with SMTP id h75ls326526lfg.83.gmail; Thu, 22 Oct 2015 02:42:13 -0700 (PDT) X-Received: by 10.25.87.82 with SMTP id l79mr5110584lfb.64.1445506933005; Thu, 22 Oct 2015 02:42:13 -0700 (PDT) Received: from mail-lf0-f46.google.com (mail-lf0-f46.google.com. [209.85.215.46]) by mx.google.com with ESMTPS id wp6si9040351lbb.145.2015.10.22.02.42.12 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Oct 2015 02:42:12 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) client-ip=209.85.215.46; Received: by lffz202 with SMTP id z202so41299686lff.3 for ; Thu, 22 Oct 2015 02:42:12 -0700 (PDT) X-Received: by 10.25.20.24 with SMTP id k24mr5260207lfi.117.1445506932894; Thu, 22 Oct 2015 02:42:12 -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 w3csp485350lbq; Thu, 22 Oct 2015 02:42:12 -0700 (PDT) X-Received: by 10.180.12.206 with SMTP id a14mr17086371wic.25.1445506932159; Thu, 22 Oct 2015 02:42:12 -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 p7si4472996wie.120.2015.10.22.02.42.12 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Oct 2015 02:42:12 -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 wicfx6 with SMTP id fx6so127280385wic.1 for ; Thu, 22 Oct 2015 02:42:12 -0700 (PDT) X-Received: by 10.180.88.227 with SMTP id bj3mr36774739wib.80.1445506931942; Thu, 22 Oct 2015 02:42:11 -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.10 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Oct 2015 02:42:11 -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 2/6] vfio: platform: reset: add vfio_platform_reset_private.h Date: Thu, 22 Oct 2015 11:41:58 +0200 Message-Id: <1445506922-6005-3-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.46 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: , This header is to be included in all vfio reset modules. It defines the module_vfio_reset_handler macro whose role is - to define a module alias - implement module init/exit function which respectively registers and unregisters the reset function. Signed-off-by: Eric Auger --- v2: creation - this defines the module_vfio_reset_handler macro as suggested by Arnd Although Arnd suggested me to remove the vfio_platform_register_reset symbol_get (since the module manager can handle the case where the vfio-platform driver is not loaded), I prefered to keep it while introducing the macro. The rationale is, when using symbol_get/put we are able to release the hold from the reset module on vfio-platform as soon as the registration is complete and I think this makes sense. --- drivers/vfio/platform/reset/Makefile | 2 +- .../platform/reset/vfio_platform_reset_private.h | 66 ++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 drivers/vfio/platform/reset/vfio_platform_reset_private.h diff --git a/drivers/vfio/platform/reset/Makefile b/drivers/vfio/platform/reset/Makefile index 2a486af..154a7d5 100644 --- a/drivers/vfio/platform/reset/Makefile +++ b/drivers/vfio/platform/reset/Makefile @@ -1,5 +1,5 @@ vfio-platform-calxedaxgmac-y := vfio_platform_calxedaxgmac.o -ccflags-y += -Idrivers/vfio/platform +ccflags-y += -Idrivers/vfio/platform -Idrivers/vfio/platform/reset obj-$(CONFIG_VFIO_PLATFORM_CALXEDAXGMAC_RESET) += vfio-platform-calxedaxgmac.o diff --git a/drivers/vfio/platform/reset/vfio_platform_reset_private.h b/drivers/vfio/platform/reset/vfio_platform_reset_private.h new file mode 100644 index 0000000..f212a61 --- /dev/null +++ b/drivers/vfio/platform/reset/vfio_platform_reset_private.h @@ -0,0 +1,66 @@ +/* + * Interface used by VFIO platform reset modules to register/unregister + * their reset function + * + * Copyright (c) 2015 Linaro Ltd. + * www.linaro.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License, version 2, as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifndef VFIO_PLATFORM_RESET_PRIVATE_H +#define VFIO_PLATFORM_RESET_PRIVATE_H + +#include +#include "vfio_platform_private.h" + +static int reset_module_register(struct module *module, + const char *compat, + vfio_platform_reset_fn_t reset) +{ + int (*register_reset)(struct module *, const char*, + vfio_platform_reset_fn_t); + int ret; + + register_reset = symbol_get(vfio_platform_register_reset); + if (!register_reset) + return -EINVAL; + ret = register_reset(module, compat, reset); + symbol_put(vfio_platform_register_reset); + return ret; +} + +static void reset_module_unregister(const char *compat) +{ + int (*unregister_reset)(const char *); + + unregister_reset = symbol_get(vfio_platform_unregister_reset); + if (!unregister_reset) + return; + + unregister_reset(compat); + + symbol_put(vfio_platform_unregister_reset); +} + +#define module_vfio_reset_handler(compat, reset) \ +MODULE_ALIAS("vfio-reset:" compat); \ +static int __init reset ## _module_init(void) \ +{ \ + return reset_module_register(THIS_MODULE, compat, &reset); \ +}; \ +static void __exit reset ## _module_exit(void) \ +{ \ + reset_module_unregister(compat); \ +}; \ +module_init(reset ## _module_init); \ +module_exit(reset ## _module_exit) + +#endif /* VFIO_PLATFORM_RESET_PRIVATE_H */