Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp493537imu; Tue, 22 Jan 2019 23:54:46 -0800 (PST) X-Google-Smtp-Source: ALg8bN7Txm4/K92oeITGwdDDm/CysQXs4P6DHyGSeX1RS/ErnfRf99DnZsHtHjFsH3KRT/r4VQ6T X-Received: by 2002:a63:82c6:: with SMTP id w189mr1123827pgd.344.1548230086894; Tue, 22 Jan 2019 23:54:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548230086; cv=none; d=google.com; s=arc-20160816; b=0dPP+qEjjc2bpbuk3wObhxZjIM9wmwsR3M7lz5YGVN+teEhEgikOWKvw/7JlYgrOfx suqE5yXsIxK3DsFYH/qx3OmrvfLk4k3U5p7TZ+VCLbBato1wBbww7hJvCmfey/cKEKv1 B6IbSR5pfP0LA4cT7KSFydgbZexZWd2kGMpH6HgCiKmJtdBq3T0dROfB0s6icqMyIxJP J/dxKRqJEvz3GXyy00w55H86jutSBGOjxVq4i+G9KdK8Xuxmwqs7J0mmxW9FwtCOq7iG QkxlRYKHJeOMl2WOTfIj4Josg+uoeRi1iCh/zyUHEktlVj+u8MAb1J7nI8Y6pvtDmXUy D9Ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=m8MhXnl6Mw4eMf782ka0YDLg3r9SgAocqcd64x17KQM=; b=q2p5oJ6fPFWcUVn/WFnqH24BuPRz/Fl12tMquh6+CFgJH+WzjrXggMt/2ebW+ylVhE My7igCh9JRPdQ47zWh849qhFxCnZaKMW08Rw3YN+ZAiAA3Oe5GMrXO3+emqz7n6rHyrj esPTHBDo14qSqgiqMDOU3EUli4QW4smko3foJVGo0hvv2s/tHIEvLPtZ45zxA5nFz1c6 2Pb9GsEv3uFWvRdkAUMFUpkNSMdNCGMNejrf3wojWRQRHkvYvP/6Deedadh3uVS5zWka 2xg4oxjJfwbBwu1n1SsPR1SMcOUUzThFCigzZTu55gGPuf1zrnRs2vJdxF9ZmOu4lNgj T3rg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a28si18004576pgl.530.2019.01.22.23.54.31; Tue, 22 Jan 2019 23:54:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726958AbfAWHxL (ORCPT + 99 others); Wed, 23 Jan 2019 02:53:11 -0500 Received: from out1.zte.com.cn ([202.103.147.172]:44018 "EHLO mxct.zte.com.cn" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726191AbfAWHxK (ORCPT ); Wed, 23 Jan 2019 02:53:10 -0500 Received: from mse01.zte.com.cn (unknown [10.30.3.20]) by Forcepoint Email with ESMTPS id 7D0FC6565A3FB67F4494; Wed, 23 Jan 2019 15:24:33 +0800 (CST) Received: from notes_smtp.zte.com.cn ([10.30.1.239]) by mse01.zte.com.cn with ESMTP id x0N7OPuX027467; Wed, 23 Jan 2019 15:24:25 +0800 (GMT-8) (envelope-from peng.hao2@zte.com.cn) Received: from localhost.localdomain.localdomain ([10.74.120.59]) by szsmtp06.zte.com.cn (Lotus Domino Release 8.5.3FP6) with ESMTP id 2019012315244671-23701697 ; Wed, 23 Jan 2019 15:24:46 +0800 From: Peng Hao To: gregkh@linuxfoundation.org, arnd@arndb.de, andy.shevchenko@gmail.com Cc: linux-kernel@vger.kernel.org, Peng Hao Subject: [PATCH V3 2/6] misc/pvpanic: Add pvpanic driver framework Date: Wed, 23 Jan 2019 23:47:24 +0800 Message-Id: <1548258448-62013-3-git-send-email-peng.hao2@zte.com.cn> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1548258448-62013-1-git-send-email-peng.hao2@zte.com.cn> References: <1548258448-62013-1-git-send-email-peng.hao2@zte.com.cn> X-MIMETrack: Itemize by SMTP Server on SZSMTP06/server/zte_ltd(Release 8.5.3FP6|November 21, 2013) at 2019-01-23 15:24:46, Serialize by Router on notes_smtp/zte_ltd(Release 9.0.1FP7|August 17, 2016) at 2019-01-23 15:24:17, Serialize complete at 2019-01-23 15:24:17 X-MAIL: mse01.zte.com.cn x0N7OPuX027467 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add pvpanic driver framework. Follow-up patches will split the original pvpanic acpi/of driver as the two seperate files and modify code to adapt the framework. Signed-off-by: Peng Hao --- drivers/misc/pvpanic/pvpanic.c | 171 ++++++++++------------------------------- 1 file changed, 39 insertions(+), 132 deletions(-) diff --git a/drivers/misc/pvpanic/pvpanic.c b/drivers/misc/pvpanic/pvpanic.c index 595ac06..6380540 100644 --- a/drivers/misc/pvpanic/pvpanic.c +++ b/drivers/misc/pvpanic/pvpanic.c @@ -8,15 +8,20 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt -#include +#include #include #include -#include -#include #include #include -static void __iomem *base; +static struct { + struct platform_device *pdev; + void __iomem *base; + bool is_ioport; +} pvpanic_data = { + .pdev = NULL, + .is_ioport = false, +}; #define PVPANIC_PANICKED (1 << 0) @@ -27,7 +32,7 @@ static void pvpanic_send_event(unsigned int event) { - iowrite8(event, base); + iowrite8(event, pvpanic_data.base); } static int @@ -43,150 +48,52 @@ .priority = 1, /* let this called before broken drm_fb_helper */ }; -#ifdef CONFIG_ACPI -static int pvpanic_add(struct acpi_device *device); -static int pvpanic_remove(struct acpi_device *device); - -static const struct acpi_device_id pvpanic_device_ids[] = { - { "QEMU0001", 0 }, - { "", 0 } -}; -MODULE_DEVICE_TABLE(acpi, pvpanic_device_ids); - -static struct acpi_driver pvpanic_driver = { - .name = "pvpanic", - .class = "QEMU", - .ids = pvpanic_device_ids, - .ops = { - .add = pvpanic_add, - .remove = pvpanic_remove, - }, - .owner = THIS_MODULE, -}; - -static acpi_status -pvpanic_walk_resources(struct acpi_resource *res, void *context) +static int pvpanic_platform_probe(struct platform_device *pdev) { - struct resource r; - - if (acpi_dev_resource_io(res, &r)) { - base = ioport_map(r.start, resource_size(&r)); - return AE_OK; - } else if (acpi_dev_resource_memory(res, &r)) { - base = ioremap(r.start, resource_size(&r)); - return AE_OK; + struct device *dev = &pdev->dev; + struct resource *res; + void __iomem *base; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (res) { + base = devm_ioremap_resource(dev, res); + if (IS_ERR(base)) + return -ENODEV; + } else { + res = platform_get_resource(pdev, IORESOURCE_IO, 0); + if (!res) + return -ENODEV; + + base = ioport_map(res->start, resource_size(res)); + if (!base) + return -ENODEV; + pvpanic_data.is_ioport = true; } - return AE_ERROR; -} - -static int pvpanic_add(struct acpi_device *device) -{ - int ret; - - ret = acpi_bus_get_status(device); - if (ret < 0) - return ret; - - if (!device->status.enabled || !device->status.functional) - return -ENODEV; - - acpi_walk_resources(device->handle, METHOD_NAME__CRS, - pvpanic_walk_resources, NULL); - - if (!base) - return -ENODEV; - + pvpanic_data.base = base; atomic_notifier_chain_register(&panic_notifier_list, &pvpanic_panic_nb); return 0; } -static int pvpanic_remove(struct acpi_device *device) +static int pvpanic_platform_remove(struct platform_device *pdev) { - atomic_notifier_chain_unregister(&panic_notifier_list, &pvpanic_panic_nb); - iounmap(base); - - return 0; -} - -static int pvpanic_register_acpi_driver(void) -{ - return acpi_bus_register_driver(&pvpanic_driver); -} - -static void pvpanic_unregister_acpi_driver(void) -{ - acpi_bus_unregister_driver(&pvpanic_driver); -} -#else -static int pvpanic_register_acpi_driver(void) -{ - return -ENODEV; -} -static void pvpanic_unregister_acpi_driver(void) {} -#endif - -static int pvpanic_mmio_probe(struct platform_device *pdev) -{ - struct resource *mem; - - mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); - if (!mem) - return -EINVAL; - - base = devm_ioremap_resource(&pdev->dev, mem); - if (IS_ERR(base)) - return PTR_ERR(base); - - atomic_notifier_chain_register(&panic_notifier_list, - &pvpanic_panic_nb); - - return 0; -} - -static int pvpanic_mmio_remove(struct platform_device *pdev) -{ - - atomic_notifier_chain_unregister(&panic_notifier_list, - &pvpanic_panic_nb); + if (pvpanic_data.is_ioport) + iounmap(pvpanic_data.base); return 0; } -static const struct of_device_id pvpanic_mmio_match[] = { - { .compatible = "qemu,pvpanic-mmio", }, - {} -}; - -static struct platform_driver pvpanic_mmio_driver = { +static struct platform_driver pvpanic_driver = { + .probe = pvpanic_platform_probe, + .remove = pvpanic_platform_remove, .driver = { - .name = "pvpanic-mmio", - .of_match_table = pvpanic_mmio_match, - }, - .probe = pvpanic_mmio_probe, - .remove = pvpanic_mmio_remove, + .name = "pvpanic", + } }; -static int __init pvpanic_mmio_init(void) -{ - if (acpi_disabled) - return platform_driver_register(&pvpanic_mmio_driver); - else - return pvpanic_register_acpi_driver(); -} - -static void __exit pvpanic_mmio_exit(void) -{ - if (acpi_disabled) - platform_driver_unregister(&pvpanic_mmio_driver); - else - pvpanic_unregister_acpi_driver(); -} - -module_init(pvpanic_mmio_init); -module_exit(pvpanic_mmio_exit); +module_platform_driver(pvpanic_driver); -- 1.8.3.1