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: Eric Auger X-Patchwork-Id: 7464181 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 76719BEEA4 for ; Thu, 22 Oct 2015 09:46:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 85898205DD for ; Thu, 22 Oct 2015 09:46:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 76BA7205DB for ; Thu, 22 Oct 2015 09:46:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755174AbbJVJoo (ORCPT ); Thu, 22 Oct 2015 05:44:44 -0400 Received: from mail-wi0-f169.google.com ([209.85.212.169]:34511 "EHLO mail-wi0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757146AbbJVJmN (ORCPT ); Thu, 22 Oct 2015 05:42:13 -0400 Received: by wikq8 with SMTP id q8so22994405wik.1 for ; Thu, 22 Oct 2015 02:42:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=TXTaOkBOTGGYQ++vx0XPtoADKzTKJpMvSRLnoV38E2o=; b=T1Zudsx75tDEcNKTVmlJqeCslKsHq4rtPNIkQsVyngebgNUJUe2o3YtkCgM0DmkhSJ in0bZHZkPw4/1M3IbkO5uLoba2pDGeb1JJh6Y48A7paKxDYrGFpZhko2B0poTeXq/V2A fkDlQ8rcluWYo9a/jVXWne5xHMPKG+Sfuf2Ymhz48cfIr2Yyu7uj+G+Dg1Se7o7M+eDh 9wYkrGn/br0iAeWBnU+uLQtZw5v2yrOugGlLeOWBIpbLJOr5LEvrSQRRTDumxJqV0jJE xvy7tdWTZvZx8eYRS88PDtIW0ZM+pRFGAqAwj8Iph8p4S7VBjnDdulTVl4E4dwy4dpYA C0Ow== X-Gm-Message-State: ALoCoQnIt6nwat31JiDZqxCb6cxToRNMqhPPISN0ujjVe8o7b2Y2+y5VrXVC2qIUh1aNtXyPaDK5 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> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 */