Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4936178imu; Wed, 19 Dec 2018 02:54:13 -0800 (PST) X-Google-Smtp-Source: AFSGD/XxhfYdpCh7S15lHNoW+vTo1a8Acs7pcRePz4Ar2cV8XBpEpez+PgjiHlolLK+DIag+UVaH X-Received: by 2002:a63:77ce:: with SMTP id s197mr18826963pgc.89.1545216853441; Wed, 19 Dec 2018 02:54:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545216853; cv=none; d=google.com; s=arc-20160816; b=at7wqR5WTvjo2LlkI1uOV7C7E38YRuUVkTI1iLF4ZhKI/419UMlGpbsqz2duiq7fYl y3/SytjrgLgzlOuwa86gFsdmrsmbdYX9IGQLEWwSwKe8XIfya077bqr4BTCHyFQaJvBz TZm5pnqhgy52O2vdyVfYUu5CkOBq44ukG4MzilYvE7tpBcyweeVFZB0IYqZvYsksxJoP pX87T+yBC39Uy71r8ym8daX4AXySusqi4WWM1ZBdzppTH1Ltrw2jKuvOy63WIEG+TF18 tV1r4DS9FkmdzSYrPlWKtnqcpHjBpDRFpxQG8mMivzDf8lhEPQDZzCJdssOAwb64yClW vTiQ== 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=wYfOedOGcRlSaJUiZHOGHkoO5ZNLtGksxpn286g35l0=; b=dxJ1Vj9hcL6XWaIV24Jqkk+FoKe7Fp7Nwp62S2KgUn5aqiA2sR+fXxnKcE4DI+5TKw 7oCth65zugQxdX6XarsCfC8s0QrfeZZLbZ2HwUbL6W/LFvMY3F9ww1Xi30QuNLC102xQ L4xlZBo5KqZpUKI1H7pmc/3HaL1T0oGWMaDOch4iAdxtDKE41AWDzgoLpvTt9fGNgo1M tt4RHA9tc+SRvqBYI7CPWhbKs07rAxvUNI6nDu1mobuSa42v6dmrirgAEFBE5ytjNm9S +pQLJ4b45GTw1FxbZ6tP7gDNHMg9jw4Ld2OufoyePkMoN9Ou9BMwsXy7NESCRNZDbF0S DaSw== 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 189si3734924pfd.142.2018.12.19.02.53.58; Wed, 19 Dec 2018 02:54:13 -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 S1728047AbeLSHnu (ORCPT + 99 others); Wed, 19 Dec 2018 02:43:50 -0500 Received: from mxhk.zte.com.cn ([63.217.80.70]:29740 "EHLO mxhk.zte.com.cn" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726704AbeLSHnt (ORCPT ); Wed, 19 Dec 2018 02:43:49 -0500 Received: from mse01.zte.com.cn (unknown [10.30.3.20]) by Forcepoint Email with ESMTPS id 4C8D2335D42E3AAA5787; Wed, 19 Dec 2018 15:43:47 +0800 (CST) Received: from notes_smtp.zte.com.cn ([10.30.1.239]) by mse01.zte.com.cn with ESMTP id wBJ7hWwK050157; Wed, 19 Dec 2018 15:43:32 +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 2018121915435413-17580349 ; Wed, 19 Dec 2018 15:43:54 +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 V5 2/3] misc/pvpanic : add pci interface for pvpanic Date: Wed, 19 Dec 2018 16:04:51 +0800 Message-Id: <1545206692-32183-2-git-send-email-peng.hao2@zte.com.cn> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1545206692-32183-1-git-send-email-peng.hao2@zte.com.cn> References: <1545206692-32183-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-19 15:43:54, Serialize by Router on notes_smtp/zte_ltd(Release 9.0.1FP7|August 17, 2016) at 2018-12-19 15:43:24, Serialize complete at 2018-12-19 15:43:24 X-MAIL: mse01.zte.com.cn wBJ7hWwK050157 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_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