Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp442823imu; Wed, 19 Dec 2018 22:44:00 -0800 (PST) X-Google-Smtp-Source: AFSGD/XiHbIGfZxwrKriTLj9sfr8OmJtaM5J/fMDw0JxazPqq0HQ5kBbwfN0IGRMnUGeBsksplXH X-Received: by 2002:a63:1157:: with SMTP id 23mr22226723pgr.245.1545288240461; Wed, 19 Dec 2018 22:44:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545288240; cv=none; d=google.com; s=arc-20160816; b=F+X2izj/r1o1jC5+MzytHy8R4HOEhAmJJ6VP1Mvh6H0UYJQJ6d4XupGwpWb/OJTMRk C6HUpOkLmyrTt6BvY2KPyCb8WwnHDK/Zn20IdN0f7rmZAOvwPdahWweIpzhHr0R03t6t L36ZxaKYOAhDyLXRx6+tljZdY6quL6Be0dVlj9wmFDvS0VGEMxG3dYzgpnXNuezOmwL0 rEzZzZ6oVCj/XDm/+e0vVZfCZofYUeeyKOfkJyGo2Rc3XhcQeDTs5IlY5iayKxaPTWbV xZiLY7v5SJU8Mx7vQObLjQhyJepRi2+q95j8LiBBRKpSIakufryLQj6AUgGmIMcrnNIg dRFw== 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=tw8+dXMzsk/1nupiJD+tv/nz76FW9wHpewxvB5Jqa1Q=; b=AFEeRTTaDhLCB3+RnNxPp4peSXpkcdFiZKRp77mcYqeRkxYMmxvPnMZjEYF+cKDlCC xJZFGO+NjM1mw0Lf/R/uQn78be9wcCJetBgTdZLv/Nuv+/z7URNvUwgou3+YMugpJXJ/ tbmJu6VYnS6mzG/KKmPRH3HGNNAteg0/1ULg4A0Eil31xp3BOyQDuyhBQLc2aVPrqbCV c+IAO9BgDDKCW4NYQaRKnQ8yj0BpqNRa+briljwW3Y4G5VWUD0L6fkWZND5ih/wANrJP wQFUMPoC4w//TEkNJKJD8wRGfxJ+yOYWrcfXFrZTsbwm5OBQIRRHzMLctDO7xR7uEn6k 5TLw== 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 e11si15553596pls.71.2018.12.19.22.43.45; Wed, 19 Dec 2018 22:44:00 -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 S1730265AbeLTE5U (ORCPT + 99 others); Wed, 19 Dec 2018 23:57:20 -0500 Received: from mxhk.zte.com.cn ([63.217.80.70]:29686 "EHLO mxhk.zte.com.cn" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729180AbeLTE5T (ORCPT ); Wed, 19 Dec 2018 23:57:19 -0500 Received: from mse01.zte.com.cn (unknown [10.30.3.20]) by Forcepoint Email with ESMTPS id 38FC4B3197DF5B0F0456; Thu, 20 Dec 2018 12:57:16 +0800 (CST) Received: from notes_smtp.zte.com.cn ([10.30.1.239]) by mse01.zte.com.cn with ESMTP id wBK4vA2M022347; Thu, 20 Dec 2018 12:57:10 +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 2018122012573882-17743688 ; Thu, 20 Dec 2018 12:57:38 +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 RESEND V5 2/3] misc/pvpanic : add pci interface for pvpanic Date: Thu, 20 Dec 2018 13:14:47 +0800 Message-Id: <1545282888-38059-2-git-send-email-peng.hao2@zte.com.cn> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1545282888-38059-1-git-send-email-peng.hao2@zte.com.cn> References: <1545282888-38059-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-20 12:57:38, Serialize by Router on notes_smtp/zte_ltd(Release 9.0.1FP7|August 17, 2016) at 2018-12-20 12:56:58, Serialize complete at 2018-12-20 12:56:58 X-MAIL: mse01.zte.com.cn wBK4vA2M022347 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. Suggested-by: Andy Shevchenko [Use pcim_* API. - Andy] 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_driver(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