From patchwork Wed Jan 30 18:48:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dexuan Cui X-Patchwork-Id: 10789135 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E144C14E1 for ; Wed, 30 Jan 2019 18:48:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CC16E29D54 for ; Wed, 30 Jan 2019 18:48:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BE3F129CE5; Wed, 30 Jan 2019 18:48:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3249B2F456 for ; Wed, 30 Jan 2019 18:48:53 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id DF4ED211BFCA3; Wed, 30 Jan 2019 10:48:52 -0800 (PST) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=40.107.130.122; helo=apc01-hk2-obe.outbound.protection.outlook.com; envelope-from=decui@microsoft.com; receiver=linux-nvdimm@lists.01.org Received: from APC01-HK2-obe.outbound.protection.outlook.com (mail-eopbgr1300122.outbound.protection.outlook.com [40.107.130.122]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id E4407211BD612 for ; Wed, 30 Jan 2019 10:48:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ajHjdCLEV7SsuyYmnz6WLsFk2+AvBvyJ+8GtBnC+kyk=; b=cj1L9a3aChiiiWXzIQCC2s2sM5RrvZE56/dNzC4GVuorsZjLtUXxI6so8U5HKZ3umRVXz3D/Mf3jad7s6gx5zHeVSXWwW+JE88L3N3ccfpPMY8p0bZ3EPZDszr6WYGPJ2fhc+voH+d2rz5WUAZhU2MgWDFsa/frAQ8k1chcvu6w= Received: from PU1P153MB0169.APCP153.PROD.OUTLOOK.COM (10.170.189.13) by PU1P153MB0171.APCP153.PROD.OUTLOOK.COM (10.170.189.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1601.4; Wed, 30 Jan 2019 18:48:40 +0000 Received: from PU1P153MB0169.APCP153.PROD.OUTLOOK.COM ([fe80::7822:a20:e63c:de2f]) by PU1P153MB0169.APCP153.PROD.OUTLOOK.COM ([fe80::7822:a20:e63c:de2f%9]) with mapi id 15.20.1601.008; Wed, 30 Jan 2019 18:48:40 +0000 From: Dexuan Cui To: Dan Williams , Ross Zwisler , Vishal Verma , Dave Jiang , "Rafael J. Wysocki" , Len Brown , "linux-nvdimm@lists.01.org" , "linux-acpi@vger.kernel.org" Subject: [PATCH] nfit: Collect shutdown status for NVDIMM_FAMILY_HYPERV Thread-Topic: [PATCH] nfit: Collect shutdown status for NVDIMM_FAMILY_HYPERV Thread-Index: AdS4zD5pzoRrhLrvR3mTKoQx0ZwP5A== Date: Wed, 30 Jan 2019 18:48:40 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Enabled=True; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_SiteId=72f988bf-86f1-41af-91ab-2d7cd011db47; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Owner=decui@microsoft.com; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_SetDate=2019-01-30T18:48:38.1866517Z; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Name=General; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Application=Microsoft Azure Information Protection; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_ActionId=af1da13b-d9bf-4b58-bb62-3363cbf73c82; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Extended_MSFT_Method=Automatic x-originating-ip: [2001:4898:80e8:9:e07a:40bd:14fc:76ab] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; PU1P153MB0171; 6:A2nGMF8LXHbrmKWDRt+ewyC0r8ExQe3PecR11NamwxxL0JPKkAgQ1rSujFCRY7fq/HNqHobYN5DH4V9hZIZXXEl5EFBncTkGNheV83RhfjnPl9KCSJNHHuw13lzgPNnswjEfnrX05MR8OXGizG7F7HZkeN5qelGaE1IvgN09QUx5n5+LFK0NAhpBp4PUHKM0Fhu5rzPj9L+fH3MFi4q2eM9JCnjgSbCgVNRTOovTFc4RXr2tTg24fjsAZ7bFnfkk1E+GK/Hp3OtrFQGuv0ZnzchmTlCXU/jXvCx+hQqaiI65ZtlsV4b55aF3/3rc/J1tWwOMVZm4gS8kbcvb0oqZbOTJv31WZuipBoBzEuKKkKdwJ+yMtrBq9zk7A9frY7/nakuhCfLZkOBoMCeCAFoeD2Bzru8DWhdcS2y55tlY/Zn6Xp59TTK3Gy+xOGG8uzgAsRhsl5DqKsaPG5xnsUBd+Q==; 5:OQ2G9Fe6luGxY6MveGEHZOZfar1k2g+m0JjdJ6PmhETcKXi/2LPD/yGo9y2H50tR4BKEHeewuLJbEt/0MVmF8FP/gMkBXZmPfUGGdALoqEGzJXPA2ReaxLAXpcG943a1ajc62OaZyQJBAqxL4EzpUe4fvrndgyyD1ESsDvf7i0UxeTQRrFrc+UPmnTBexXB0NI69nkYSspQESuU6FMhaiA==; 7:PQnwa9uiwEztWttaM0VdUkroqiHNx090dE3lGKG/fetxuVIBUXgqwzYia7Mkc0eX8AJHVayNBid4VvLPpvNMN23jGNnUOEsMWOXaVHyK6G/DnOzqVGjYjuq8jHpqO9HwX4/gXjySaHtjqFeNEK8phw== x-ms-office365-filtering-correlation-id: 2182b31c-7253-4d6a-b2d0-08d686e38d66 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(5600110)(711020)(4605077)(4618075)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7193020); SRVR:PU1P153MB0171; x-ms-traffictypediagnostic: PU1P153MB0171: x-ms-exchange-purlcount: 1 x-microsoft-antispam-prvs: x-forefront-prvs: 0933E9FD8D x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(396003)(346002)(366004)(136003)(376002)(39860400002)(189003)(199004)(99286004)(9686003)(46003)(86362001)(2201001)(7696005)(476003)(8990500004)(55016002)(105586002)(71200400001)(71190400001)(6306002)(86612001)(102836004)(2906002)(106356001)(256004)(8936002)(81156014)(81166006)(8676002)(6346003)(186003)(110136005)(6506007)(7736002)(54906003)(6436002)(53936002)(2501003)(10090500001)(97736004)(6116002)(966005)(305945005)(107886003)(22452003)(486006)(316002)(4326008)(25786009)(10290500003)(74316002)(33656002)(478600001)(7416002)(68736007)(14454004); DIR:OUT; SFP:1102; SCL:1; SRVR:PU1P153MB0171; H:PU1P153MB0169.APCP153.PROD.OUTLOOK.COM; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=decui@microsoft.com; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: WGB8I2UxhnfdJHtO1XwvRagN1kVZ/4N/nKZA6dYW7Z1GUJkACeplV3S7u5YJWnlnyKBZgEPqAmE6xcATzPZZoH0f8Mvd2lARwYqJDZ1LDxfAPprxKYjqGZOnCcD0yy2Nvk3M4p1kJNfmhpf+FuTkCVagfhYZcmUMVz6DmNUQArem5bM37M7ZFL3M2+66VUpqAcCNZN2nx/U9KCY6Rqq4w+LqUlfGA73YlPv0krkplRZfNaN6qgJAjvizDRxMYEPKuOEP1EDCrw4RvZtVnclc+rMdPwGkfPiPm+XIse9wjv6ZbLfKjj5xNpe//SOkD17WWSdYzuDKkpNNJKUTVsg4SopQlcEjKr2ljXFsA8G0ncaYNpz5+ZotiveeC4JhWhaolxwGHjiqxRByhkjClVXXaGdnz7sdSXycO7nnVn6UWno= MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2182b31c-7253-4d6a-b2d0-08d686e38d66 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Jan 2019 18:48:40.2852 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: PU1P153MB0171 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Josh Poulson , Stephen Hemminger , Haiyang Zhang , "driverdev-devel@linuxdriverproject.org" , "linux-kernel@vger.kernel.org" , Michael Kelley , Sasha Levin , KY Srinivasan Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP See http://www.uefi.org/RFIC_LIST ("Virtual NVDIMM 0x1901"): "Get Unsafe Shutdown Count (Function Index 2)". Let's expose the info to the userspace (e.g. ntctl) via sysfs. Signed-off-by: Dexuan Cui --- drivers/acpi/nfit/core.c | 51 ++++++++++++++++++++++++++++++++++++++ drivers/acpi/nfit/hyperv.h | 26 +++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 drivers/acpi/nfit/hyperv.h diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c index d5a164b6833a..d504da34ce34 100644 --- a/drivers/acpi/nfit/core.c +++ b/drivers/acpi/nfit/core.c @@ -25,6 +25,7 @@ #include #include #include "intel.h" +#include "hyperv.h" #include "nfit.h" /* @@ -1802,6 +1803,54 @@ __weak void nfit_intel_shutdown_status(struct nfit_mem *nfit_mem) } } +__weak void nfit_hyperv_shutdown_status(struct nfit_mem *nfit_mem) +{ + struct device *dev = &nfit_mem->adev->dev; + struct nd_hyperv_shutdown_status status; + union acpi_object in_buf = { + .buffer.type = ACPI_TYPE_BUFFER, + .buffer.length = 0, + }; + union acpi_object in_obj = { + .package.type = ACPI_TYPE_PACKAGE, + .package.count = 1, + .package.elements = &in_buf, + }; + const u8 func = ND_HYPERV_GET_UNSAFE_SHUTDOWN_COUNT; + const guid_t *guid = to_nfit_uuid(nfit_mem->family); + u8 revid = nfit_dsm_revid(nfit_mem->family, func); + struct acpi_device *adev = nfit_mem->adev; + acpi_handle handle = adev->handle; + union acpi_object *out_obj; + + if ((nfit_mem->dsm_mask & BIT(func)) == 0) + return; + + out_obj = acpi_evaluate_dsm(handle, guid, revid, func, &in_obj); + if (!out_obj || out_obj->type != ACPI_TYPE_BUFFER + || out_obj->buffer.length < sizeof(status)) { + dev_dbg(dev->parent, + "%s: failed to get Unsafe Shutdown Count\n", + dev_name(dev)); + ACPI_FREE(out_obj); + return; + } + + memcpy(&status, out_obj->buffer.pointer, sizeof(status)); + ACPI_FREE(out_obj); + + if (status.general_err != 0) { + dev_dbg(dev->parent, + "%s: failed to get Unsafe Shutdown Count: err=0x%x\n", + dev_name(dev), status.status); + return; + } + + set_bit(NFIT_MEM_DIRTY_COUNT, &nfit_mem->flags); + nfit_mem->dirty_shutdown = status.shutdown_count; +} + + static void populate_shutdown_status(struct nfit_mem *nfit_mem) { /* @@ -1811,6 +1860,8 @@ static void populate_shutdown_status(struct nfit_mem *nfit_mem) */ if (nfit_mem->family == NVDIMM_FAMILY_INTEL) nfit_intel_shutdown_status(nfit_mem); + else if (nfit_mem->family == NVDIMM_FAMILY_HYPERV) + nfit_hyperv_shutdown_status(nfit_mem); } static int acpi_nfit_add_dimm(struct acpi_nfit_desc *acpi_desc, diff --git a/drivers/acpi/nfit/hyperv.h b/drivers/acpi/nfit/hyperv.h new file mode 100644 index 000000000000..c4a25b8624cc --- /dev/null +++ b/drivers/acpi/nfit/hyperv.h @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright(c) 2019 Microsoft Corporation. All rights reserved. + * Hyper-V specific definitions for _DSM of Hyper-V Virtual NVDIMM + * + * See http://www.uefi.org/RFIC_LIST (Virtual NVDIMM 0x1901) + */ +#ifndef _NFIT_HYPERV_H_ +#define _NFIT_HYPERV_H_ + +#define ND_HYPERV_GET_UNSAFE_SHUTDOWN_COUNT 2 + +struct nd_hyperv_shutdown_status { + union { + u32 status; + struct { + u16 general_err; + u8 func_err; + u8 vendor_err; + }; + }; + u32 shutdown_count; +} __packed; + + +#endif