Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3636814imu; Tue, 18 Dec 2018 01:28:28 -0800 (PST) X-Google-Smtp-Source: AFSGD/WryN3T5cY68M3SMZvmt8HTLYMgOZzDU2zhoATIc08xuR7a4nPJDICuMH4EeXVThFCjgwCW X-Received: by 2002:a17:902:209:: with SMTP id 9mr16064799plc.288.1545125308525; Tue, 18 Dec 2018 01:28:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545125308; cv=none; d=google.com; s=arc-20160816; b=Pd6J2w+J4q3sBrpLljM/KRo/W7OUvRV+yQxCuIBxNyJmbvb7IYceHHR5dpCIEgdbBo ocEv4AQzvcDXMouF2mJ6g5xDI3aKUrL8LTXMNbhLtB7myaNIKUMNXCQG6n0lIhZzY08n slRwqiHMp5/eD737ng5yqJ8EHc5N4JDY+wFIbkkoZ6TxrX+hVc+PL2PZw1H1vsqD0Mx7 6JCZwGeMOprYjwi/NeCRUwCaggRI3WpdHX5kM0FYLNE4jRj+ptwDMl5QwzmcFUrMMyFE AEQ9jHqkTlrnhAxx5aOWHWMUZa4NLv1XXmIYtijV4kUMb39dYoceJAUBL3pVCMV5KjMc KdXQ== 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=eZcR2ipeIixjFXwzlvExNpdLFju0lFKIUfnCmPKbdLk=; b=X0cVLOfNIaCCiFIEFqgtVY/Jc9b/KmK+ocDOOkcsBlqIzLGRlePRHJfLkZWliMvD1R k6CQPfFKz+fiFuiyKmOB+9r2axZ+AJZbvRvxkjPvI80tgos0Cr7P70WTq/WwRWsBov2v 8OFP14LZxIrwWGucEKqQpA0FQWh48vCm2jjDD7w5vx8/JJTPe5o1gK2K0VW4KKTOxThx /YVDKJO/Y3j8qPVlj6nTO8Tw0SqXmiUnpgLDL4ZGitlj+EkIO6LFwwuStQDg98mFCM7O 80sLD3s2JqjQcGTTjXcmiPMqIQXCjyKuvzoGcTzKRW2IgISRSCIGtVYPP8XhTD6cYglb F0wg== 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 e6si12760289pgl.471.2018.12.18.01.28.13; Tue, 18 Dec 2018 01:28:28 -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 S1726549AbeLRJZy (ORCPT + 99 others); Tue, 18 Dec 2018 04:25:54 -0500 Received: from mxhk.zte.com.cn ([63.217.80.70]:9818 "EHLO mxhk.zte.com.cn" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726365AbeLRJZt (ORCPT ); Tue, 18 Dec 2018 04:25:49 -0500 Received: from mse01.zte.com.cn (unknown [10.30.3.20]) by Forcepoint Email with ESMTPS id 5169C4EB6BEB1C1D85E3; Tue, 18 Dec 2018 17:25:46 +0800 (CST) Received: from notes_smtp.zte.com.cn ([10.30.1.239]) by mse01.zte.com.cn with ESMTP id wBI9PYM4011672; Tue, 18 Dec 2018 17:25:34 +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 2018121817254918-17374563 ; Tue, 18 Dec 2018 17:25:49 +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 V4 2/3] misc/pvpanic : add pci interface for pvpanic Date: Tue, 18 Dec 2018 17:46:42 +0800 Message-Id: <1545126403-25747-2-git-send-email-peng.hao2@zte.com.cn> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1545126403-25747-1-git-send-email-peng.hao2@zte.com.cn> References: <1545126403-25747-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-18 17:25:49, Serialize by Router on notes_smtp/zte_ltd(Release 9.0.1FP7|August 17, 2016) at 2018-12-18 17:25:30, Serialize complete at 2018-12-18 17:25:30 X-MAIL: mse01.zte.com.cn wBI9PYM4011672 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 | 72 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 2 deletions(-) diff --git a/drivers/misc/pvpanic.c b/drivers/misc/pvpanic.c index f84ed30..c30bf62 100644 --- a/drivers/misc/pvpanic.c +++ b/drivers/misc/pvpanic.c @@ -13,9 +13,12 @@ #include #include #include +#include #include #include +#define PCI_VENDOR_ID_REDHAT 0x1b36 +#define PCI_DEVICE_ID_REDHAT_PVPANIC 0x0101 static void __iomem *base; #define PVPANIC_PANICKED (1 << 0) @@ -172,12 +175,76 @@ 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 ret; + + ret = pcim_enable_device(pdev); + if (ret < 0) + return ret; + + ret = pcim_iomap_regions(pdev, 1 << 0, pci_name(pdev)); + if (ret) + return ret; + + base = pcim_iomap_table(pdev)[0]; + + atomic_notifier_chain_register(&panic_notifier_list, + &pvpanic_panic_nb); + return 0; +} + +static void pvpanic_pci_remove(struct pci_dev *pdev) +{ + atomic_notifier_chain_unregister(&panic_notifier_list, + &pvpanic_panic_nb); +} + +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_driver(void) +{ + return pci_register_driver(&pvpanic_pci_driver); +} + +static void pvpanic_unregister_pci_driver(void) +{ + pci_unregister_driver(&pvpanic_pci_driver); +} +#else +static int pvpanic_register_pci_driver(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_driver(); + 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 +253,7 @@ static void __exit pvpanic_mmio_exit(void) platform_driver_unregister(&pvpanic_mmio_driver); else pvpanic_unregister_acpi_driver(); + pvpanic_unregister_pci_driver(); } module_init(pvpanic_mmio_init); -- 1.8.3.1