Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2562975imu; Mon, 17 Dec 2018 04:15:03 -0800 (PST) X-Google-Smtp-Source: AFSGD/X1tEBPjI6rQ3vf6AE2qqyNWxCABTBrPK+J3eoZElzK9f1mRqEX7A2BCKQl71I2jFrL1fvJ X-Received: by 2002:a62:5182:: with SMTP id f124mr12733118pfb.238.1545048903053; Mon, 17 Dec 2018 04:15:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545048903; cv=none; d=google.com; s=arc-20160816; b=Upzth1JPcdgiItP10PL1hQpjH4uOUj0TN1/seNPvyWFWFmGQSBchFMrYAgSkx5c2Vk PZy3kx3opHSd6NE3fSgR7iJp1nTGwcFA5LQpr0LwBszG/IJxVo2ApffhXKfxEWEP3Wtr TpiDbvEj0HvaAM9rSSYBV90JHs8vhCDj/6UqpC6Ab3ywrf5igTHC2gisULxj+HxeMvXQ QTjQDmjOhDs+TmF92PtnW0lUiTI5u2w3JMv4SYNChK8ChrqyRqtPFfPYRyqm7VhkxBHo 3Vxk/guooe2Z2jmV5cmHf8hymoMAWnpWj5m9cgY06MBRquQD5lnoa0F0SC4ZW4s09Rv0 WoNw== 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=qXNgGsZsa5MAdVq4RMdDOKljg8nygwZE7MjpfWw/W5o=; b=DU0YI1Lvwsb5nx9aVkfB69/uBP8u/YNx/IWhGWtOFudJzyx9sI9Q9WDxUn2fyWn8K+ duRcxi8jBPLrRXWb+k/A9QFmZgJomBAH76N3ZPj7dc8zyGiRu21jcAsoqbru8oY7JtR3 o30YMYGcMCVmpWCON6l/aBeyA9WaWEgzEsbBvbRkEVaAAQHSOvNTfx9QfoEoXoiolVoI h9fptPh/4KbnfS8nNe/LOiwJ4Wx+k/nT4R5MR4LEMsTxAKvuxveTfVBSEeH7UTE3/OBE 18WCxVOZQnFkYZfLfa+6Hw0dWOvtXGSWIbF35eJ6lnQSr+1ExifSo8dQ1fJe8dFUtT13 bYag== 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 n30si10798381pgb.406.2018.12.17.04.14.47; Mon, 17 Dec 2018 04:15:03 -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 S1732003AbeLQKWD (ORCPT + 99 others); Mon, 17 Dec 2018 05:22:03 -0500 Received: from out1.zte.com.cn ([202.103.147.172]:59454 "EHLO mxct.zte.com.cn" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731848AbeLQKWB (ORCPT ); Mon, 17 Dec 2018 05:22:01 -0500 Received: from mse01.zte.com.cn (unknown [10.30.3.20]) by Forcepoint Email with ESMTPS id 388D8AC91C55C661D02D; Mon, 17 Dec 2018 18:21:59 +0800 (CST) Received: from notes_smtp.zte.com.cn ([10.30.1.239]) by mse01.zte.com.cn with ESMTP id wBHALpBP084731; Mon, 17 Dec 2018 18:21:52 +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 2018121718215921-17167721 ; Mon, 17 Dec 2018 18:21:59 +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/3] misc/pvpanic : add pci interface for pvpanic Date: Mon, 17 Dec 2018 18:43:13 +0800 Message-Id: <1545043394-19417-2-git-send-email-peng.hao2@zte.com.cn> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1545043394-19417-1-git-send-email-peng.hao2@zte.com.cn> References: <1545043394-19417-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 2018-12-17 18:21:59, Serialize by Router on notes_smtp/zte_ltd(Release 9.0.1FP7|August 17, 2016) at 2018-12-17 18:21:51, Serialize complete at 2018-12-17 18:21:51 X-MAIL: mse01.zte.com.cn wBHALpBP084731 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Support pvpanic as a pci device in guest kernel. Signed-off-by: Peng Hao --- drivers/misc/pvpanic.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 80 insertions(+), 2 deletions(-) diff --git a/drivers/misc/pvpanic.c b/drivers/misc/pvpanic.c index f84ed30..b8d8dba 100644 --- a/drivers/misc/pvpanic.c +++ b/drivers/misc/pvpanic.c @@ -13,11 +13,14 @@ #include #include #include +#include #include #include static void __iomem *base; +#define PCI_VENDOR_ID_REDHAT 0x1b36 +#define PCI_DEVICE_ID_REDHAT_PVPANIC 0x0101 #define PVPANIC_PANICKED (1 << 0) MODULE_AUTHOR("Hu Tao "); @@ -172,12 +175,86 @@ static int pvpanic_mmio_remove(struct platform_device *pdev) .remove = pvpanic_mmio_remove, }; +#ifdef CONFIG_PCI +static const struct pci_device_id pvpanic_pci_id_tbl[] = { + { PCI_DEVICE(PCI_VENDOR_ID_REDHAT, PCI_DEVICE_ID_REDHAT_PVPANIC),}, + {} +}; + +static int pvpanic_pci_probe(struct pci_dev *pdev, + const struct pci_device_id *ent) +{ + int err; + + err = pci_enable_device(pdev); + if (err) + return err; + if (pci_request_region(pdev, 0, "pvpanic-pci")) + goto disable; + + base = pci_ioremap_bar(pdev, 0); + if (!base) + goto release; + + atomic_notifier_chain_register(&panic_notifier_list, + &pvpanic_panic_nb); + return 0; + +release: + pci_release_region(pdev, 0); +disable: + pci_disable_device(pdev); + + return -ENODEV; +} + +static void pvpanic_pci_remove(struct pci_dev *pdev) +{ + atomic_notifier_chain_unregister(&panic_notifier_list, + &pvpanic_panic_nb); + iounmap(base); + pci_release_region(pdev, 0); + pci_disable_device(pdev); +} + +static struct pci_driver pvpanic_pci_driver = { + .name = "pvpanic-pci", + .id_table = pvpanic_pci_id_tbl, + .probe = pvpanic_pci_probe, + .remove = pvpanic_pci_remove, +}; + +static int pvpanic_register_pci_drvier(void) +{ + return pci_register_driver(&pvpanic_pci_driver); +} + +static void pvpanic_unregister_pci_drvier(void) +{ + pci_unregister_driver(&pvpanic_pci_driver); +} +#else /* CONFIG_PCI */ +static int pvpanic_register_pci_drvier(void) +{ + return 0; +} + +static void pvpanic_unregister_pci_drvier(void) {} +#endif + static int __init pvpanic_mmio_init(void) { + int r1, r2; + if (acpi_disabled) - return platform_driver_register(&pvpanic_mmio_driver); + r1 = platform_driver_register(&pvpanic_mmio_driver); + else + r1 = pvpanic_register_acpi_driver(); + r2 = pvpanic_register_pci_drvier(); + if (r1 && r2) /* all drivers register failed */ + return 1; else - return pvpanic_register_acpi_driver(); + return 0; } static void __exit pvpanic_mmio_exit(void) @@ -186,6 +263,7 @@ static void __exit pvpanic_mmio_exit(void) platform_driver_unregister(&pvpanic_mmio_driver); else pvpanic_unregister_acpi_driver(); + pvpanic_unregister_pci_drvier(); } module_init(pvpanic_mmio_init); -- 1.8.3.1