From nobody Sun Dec 14 06:15:22 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=oracle.com); dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=2; a=rsa-sha256; t=1633627764; cv=pass; d=zohomail.com; s=zohoarc; b=dlWZbsPofbGNRke1M4Fy7hVj92vvjxlYmt3j+HWsFK5WvtE2oJATMPyWjDdxcdDPK73Jkn/FtpnnwPwr4vFHn1BFw/44/cU+BFc+F7gt4FvqcOaLfLodnA5Uxqh9u/TbkJCCzpM3qsGVo0WFodhg1h4p++4plylJrVRGMUMj5Fs= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1633627764; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Lbb75QDmRkagqrdz6YyHWHrXBDOMop5m+OWvcmp/43g=; b=E5lDQ/7tXkkMoeI0RS4Zd9qtlr/gRFIb1o0sHsvPtdX+KxmPba4kxSZn60PtJy2L0E3LudF5cnBZX9WKAVqRQjMAuuIz6k/LS/W8W5utH4YrfMR4hyMxgSgycOnV522uaaiT1/gyu6pERw/G312xoErb+bDxJbHW9gN2YvIU+no= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=oracle.com); dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1633627764923154.19215125918026; Thu, 7 Oct 2021 10:29:24 -0700 (PDT) Received: from localhost ([::1]:47760 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mYXCt-0007R1-Od for importer@patchew.org; Thu, 07 Oct 2021 13:29:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59602) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mYWzD-0001np-Cf for qemu-devel@nongnu.org; Thu, 07 Oct 2021 13:15:15 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:26968) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mYWz7-0001td-GX for qemu-devel@nongnu.org; Thu, 07 Oct 2021 13:15:15 -0400 Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 197H5OEe014733; Thu, 7 Oct 2021 17:15:04 GMT Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3bj02jjcr5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Oct 2021 17:15:03 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 197HAnrk066991; Thu, 7 Oct 2021 17:15:02 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2171.outbound.protection.outlook.com [104.47.58.171]) by userp3020.oracle.com with ESMTP id 3bf16x5tk4-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Oct 2021 17:15:01 +0000 Received: from CO1PR10MB4531.namprd10.prod.outlook.com (2603:10b6:303:6c::22) by CO1PR10MB5524.namprd10.prod.outlook.com (2603:10b6:303:163::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.19; Thu, 7 Oct 2021 17:14:58 +0000 Received: from CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::90ef:e061:a4c2:acd6]) by CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::90ef:e061:a4c2:acd6%7]) with mapi id 15.20.4566.023; Thu, 7 Oct 2021 17:14:58 +0000 Received: from ban25x6uut23.us.oracle.com (138.3.201.23) by MN2PR08CA0015.namprd08.prod.outlook.com (2603:10b6:208:239::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.18 via Frontend Transport; Thu, 7 Oct 2021 17:14:56 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2021-07-09; bh=Lbb75QDmRkagqrdz6YyHWHrXBDOMop5m+OWvcmp/43g=; b=Cok3aTLhKY83Oz8IOFo4GR4ECdUSk6OJBOJnjmnyqLU8fQ3L22FoLeH2ylLtWF/Bt4yd sdd9PP9xC3L4QVSXiKNRX4iq7vOvYwGV/nvkF39S7vjlzQ9TFF14szPbOH9Tk+J1m/Mz hof68CK41IsR2KrKEztsjy5yyg2HngKhGv1ZgDaQtydrsmw6p0HVE/wke+vxtDC8z8wa CqMqdZw/TdbVwh7lr9muTj6O/p63ypfl0gCcTbzVE/vzh6k71ip6+L3FbGlb0pstgp8D 42DsOsKxNEOOYnd5kRDyhWAub/V9nUsg6hQUF0+Z0LhRvj3yiev2wG6I+yPvifer6kWG oA== ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RwWHZke7Sd6iA3raW5kog5vqzqhEvdg0a/a6vJxuJICHVKD2WYJ49SksLG2PEO+BhMMYjYK/BI9pVacngUqu8otc0lXlGEKdz+SkZd2kglw+dY9BDZefUpMElceqoe0V/U/LQr48PORZsnDU/kjp968T00ZuiuNQS2TaUliMEgHoSwdXGSdVOscG1YRloZpk8jEsPlcuqp3ZebXZAo7Exkj85pxUlZ3tTUcm6txguUt7n5pXfhIlAVZdoRpJsgOOePdXCeYsl82m85cMnnasuUUxalyV1sN9qQ685qmKUkTnENZXk68YGvPLMlGt9Bf0azQ+ROJK7KdUvjP6fvdQ+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Lbb75QDmRkagqrdz6YyHWHrXBDOMop5m+OWvcmp/43g=; b=NTKibV7TjBxPXvrzvpnmcIRolGTNL4o7r8lMX9LdUzcxOwW4HVAjR1MbcbqvnGqaXJre9anKJhXjxtUrtQjhB+8diC9WpHVYd+fQS4XZoC1lM53ZDZ8numnKiqje7cTlGjYyZTrv8z7iCfAy8htYCpFnxz8kLCQxg/Ms4ecP7HM7qpTZq4AvWUbDNZU8lllfwlXKpddqtPz5C3pHNGVIUgqjZsk/QNNiZqy37LI1DLeFfc2gybmwOm06SUix2W0NsN1rgGpUMmKcd15/FWTW+8inmacmZxHgRcb41D2kaKNu3s5vD+EfhtKGT8wqw0BJmEotE7cO4rKuWolry8VQUA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Lbb75QDmRkagqrdz6YyHWHrXBDOMop5m+OWvcmp/43g=; b=X3uQpSTv26jbexBoJBF3yZV/deh7CG/DnjAQ1ZSx31APfaxpSZgmWL8Ytqpy6aYsUXgUvSZTMl3/JigwCtjqj76NWAD4wP7/r6oc9RVYtl/KktdMnqfF1zF0uLZfDsIsVfK47PGhNtkz9xvRV1QhB7klq5VwQAal0Nt1NnjTWas= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; From: Eric DeVolder To: qemu-devel@nongnu.org Subject: [PATCH v7 04/10] ACPI ERST: support for ACPI ERST feature Date: Thu, 7 Oct 2021 13:14:30 -0400 Message-Id: <1633626876-12115-5-git-send-email-eric.devolder@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1633626876-12115-1-git-send-email-eric.devolder@oracle.com> References: <1633626876-12115-1-git-send-email-eric.devolder@oracle.com> X-ClientProxiedBy: MN2PR08CA0015.namprd08.prod.outlook.com (2603:10b6:208:239::20) To CO1PR10MB4531.namprd10.prod.outlook.com (2603:10b6:303:6c::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b26086ed-9547-408a-f8a4-08d989b5fd6d X-MS-TrafficTypeDiagnostic: CO1PR10MB5524: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2803; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: CNsLXxZxvd0VuocgV3yidEEFgiDrjBOhjRo2JpFjAOMq4P9lQqlPTCDMjxEC0YSt3VvJ0gu1+ndTaqAOU3ZS/gDRL5Tu8lhEMXEUv/6A4LyLywBdhKBVxuBQH73wf+VbhETFywd4yX9Y5ejg2HFM1twC3Qs+WimlxlQJjh3AZ+cDFLaf74XP5rMg5wSBon0wTl2r1RvsQoC9O50WU/Q/f0xba5N0yrZmg2dSIqTvgWtNSCaZFGfB9m89Xp2L8sbF13JQ6EozBDdrXhrosCzdWn8Kaln1ze3LGFuwKmwBSej2SdTp5DRYBIUA6Bmz4AlopKYdVmmVIJ8vUUYFZH17pdUmhPt3XVMImI6Tkmysnl7VbwHUQnFKpxDGwCCWqaeq+uSobnduizsTPa3liQoUBnKzRaZ1pTbcIRGVb4YXL+XKoIyggRqGvyReYb3dBWuNEhz2gUveZCtc8hmow2E4TidtVVT1MOMtYXe51KUK+ltvVoIaqGVPzwHzJVghxORUdQQNlEK/Nlj18y41paI0fJfYNdb0awON0BcNarHVP3lWETyFxMaZR6IVfnvJmiwJF4EjNyFAXYrvtI6N6ZhYhd4O0UMBGVUoVpck9FsxUalzKoxOm53b9T4QGb3wbIRGJ8IcOe803caZCbiDWc8dp3bnAVfZabwrEwVz06rjfaJF7BUEXuklvnX4iSwe1YK09u0CasR7A7HyP03PK9NhpA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CO1PR10MB4531.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(30864003)(66946007)(6916009)(38350700002)(66476007)(2906002)(36756003)(66556008)(107886003)(5660300002)(316002)(86362001)(8676002)(83380400001)(2616005)(8936002)(6666004)(956004)(4326008)(508600001)(186003)(6486002)(52116002)(7696005)(26005)(38100700002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?ksCGRBndTUNzuVEs0JCzbzAaIEY3aOTG5W1UlVxYng4Y1X0dTrm3srClCXEi?= =?us-ascii?Q?ct6hVoJSW5xwlHeelKiwIN0D38qyxP2DcfeZP0gRH32/c0N1EapSnLGkd/Db?= =?us-ascii?Q?QsiwhAza2QCF6iHiDeUpbXdiKsATVWZXXedhicbD6GpQVp/LrxlJMfnlGC/D?= =?us-ascii?Q?Cmmi2Wif+/NBVopoJrfzXi/p033HHh7ZeKAd31ogphOrzWw2qgqOwXDlpMxw?= =?us-ascii?Q?/3O1YYtoHg+KLbb2sEPCI8HiU+aCRrBhXnqEFIpYbaQhKlbiYtcjDbiI2qfZ?= =?us-ascii?Q?35jCg5wBLomvSXRzG/4gtIDYCqrFZTd/e0AivQ6nM9AEEBy6QCNuaV0HtXK8?= =?us-ascii?Q?TyalApCy4qRl6jjYDjAB/EyRgREnr6xDmSpQIZZ4S4HUfhmTQbqv0TIitZan?= =?us-ascii?Q?Csv8sbh3kWv5trKsFF0cO+TwVy6JSMKv75Gy0YoFWFs/ok40QtxhL59a9Bi/?= =?us-ascii?Q?9CYm/P4LfWFz21iJLvhO3zAtzSOBzugkuT3lrxurDRVE+6ikAXnRcKHXJIkm?= =?us-ascii?Q?WgzZmanexv1lqCAWpY7NH6XeQyA5Ggn+ZybEc2jMbG2EfUkW5u32sxhLifk1?= =?us-ascii?Q?El5WsBpvIoPZ2t0XmEFSN19QIiYtYOFL/PDlAAj0bpJ0sjVi4lRFlOaZoTR7?= =?us-ascii?Q?hxxPynZybh91xVOaKmlMRoP96AoZuNQA6bTHe4gnxXHVypUYrV02bATVg3m0?= =?us-ascii?Q?U4/HN1AEhvr2ob0H1teOVvR3ZmCSKGitKWoUPY1NzeTuZOX0FgWJwCxzPz2x?= =?us-ascii?Q?lpVxvr1Q51BwreXxIDRb7P3W6qPAZ7UnJGteqq4HIgaHmSqNN01eMz5i7j96?= =?us-ascii?Q?hhlPVzBCQFrDLUIQApnGuaXT3fhvEuqDITVXNB4X+0mYpkAIiTpKtAX9ePP/?= =?us-ascii?Q?Kr459R91Vt6XNp6I2cWm9/DB/Zg6FDmRb9PDEGIoNMij6K0+lGvif1ZyK3XM?= =?us-ascii?Q?6Mtzpe4/8WccH4YGvj6LaKl/9QD2mMfMvgeICwvYlmH/wgcoOEFC99pHbaGf?= =?us-ascii?Q?F7gFfCooe7zoCB63ZhbXkUJeOD/HGEJGwYnaIpwlAaUaXbmZjSn1LHfBqjZp?= =?us-ascii?Q?nxfyqVcZVISB/cZFe+89RT3vC8U2CoTg5HUvjsG11cuCrgfyvNtuePKx5RVQ?= =?us-ascii?Q?/6khXEvQRD5nouMyLAmIF/DQYdCRBmSOwbOTGzZWJMV+wp4ie1GxnmrGeqMY?= =?us-ascii?Q?XWZY2L9+40uRzBDOZyUutaYqvwZxoKzEjx6P/oqlBktjmNSsA9+WePoU7qIc?= =?us-ascii?Q?S0Pvq+C7/EMxKs8Oo/J03noCeot9HCBYP5fGaVNfnErG+rQWh1K45RtEx8A+?= =?us-ascii?Q?8MinTuV3jkLIjmPd9gOv3+pM?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: b26086ed-9547-408a-f8a4-08d989b5fd6d X-MS-Exchange-CrossTenant-AuthSource: CO1PR10MB4531.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Oct 2021 17:14:58.5067 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: qy9GG3aNApiZtUTIG+0NgtkptbPlpHxY0YxXLtGM1wMstQX0SoZ0R1oIT7wXuLTE8xyd+0auRywNSZRf2QOuYvMARk8iFYalLgOBNtpS6Dc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR10MB5524 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10130 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 adultscore=0 phishscore=0 malwarescore=0 bulkscore=0 mlxlogscore=999 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2109230001 definitions=main-2110070112 X-Proofpoint-ORIG-GUID: Jf4EB6gGrTJb9pMbLnsuA1qtQl5Kro1I X-Proofpoint-GUID: Jf4EB6gGrTJb9pMbLnsuA1qtQl5Kro1I Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.220.165.32; envelope-from=eric.devolder@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: berrange@redhat.com, ehabkost@redhat.com, mst@redhat.com, konrad.wilk@oracle.com, pbonzini@redhat.com, ani@anisinha.ca, imammedo@redhat.com, boris.ostrovsky@oracle.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @oracle.onmicrosoft.com) X-ZM-MESSAGEID: 1633627766276100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This implements a PCI device for ACPI ERST. This implements the non-NVRAM "mode" of operation for ERST as it is supported by Linux and Windows. Signed-off-by: Eric DeVolder --- hw/acpi/erst.c | 836 +++++++++++++++++++++++++++++++++++++++++++++++= ++++ hw/acpi/meson.build | 1 + hw/acpi/trace-events | 15 + 3 files changed, 852 insertions(+) create mode 100644 hw/acpi/erst.c diff --git a/hw/acpi/erst.c b/hw/acpi/erst.c new file mode 100644 index 0000000..af7e1a9 --- /dev/null +++ b/hw/acpi/erst.c @@ -0,0 +1,836 @@ +/* + * ACPI Error Record Serialization Table, ERST, Implementation + * + * ACPI ERST introduced in ACPI 4.0, June 16, 2009. + * ACPI Platform Error Interfaces : Error Serialization + * + * Copyright (c) 2021 Oracle and/or its affiliates. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include +#include +#include + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "hw/qdev-core.h" +#include "exec/memory.h" +#include "qom/object.h" +#include "hw/pci/pci.h" +#include "qom/object_interfaces.h" +#include "qemu/error-report.h" +#include "migration/vmstate.h" +#include "hw/qdev-properties.h" +#include "hw/acpi/acpi.h" +#include "hw/acpi/acpi-defs.h" +#include "hw/acpi/aml-build.h" +#include "hw/acpi/bios-linker-loader.h" +#include "exec/address-spaces.h" +#include "sysemu/hostmem.h" +#include "hw/acpi/erst.h" +#include "trace.h" + +/* ACPI 4.0: Table 17-16 Serialization Actions */ +#define ACTION_BEGIN_WRITE_OPERATION 0x0 +#define ACTION_BEGIN_READ_OPERATION 0x1 +#define ACTION_BEGIN_CLEAR_OPERATION 0x2 +#define ACTION_END_OPERATION 0x3 +#define ACTION_SET_RECORD_OFFSET 0x4 +#define ACTION_EXECUTE_OPERATION 0x5 +#define ACTION_CHECK_BUSY_STATUS 0x6 +#define ACTION_GET_COMMAND_STATUS 0x7 +#define ACTION_GET_RECORD_IDENTIFIER 0x8 +#define ACTION_SET_RECORD_IDENTIFIER 0x9 +#define ACTION_GET_RECORD_COUNT 0xA +#define ACTION_BEGIN_DUMMY_WRITE_OPERATION 0xB +#define ACTION_RESERVED 0xC +#define ACTION_GET_ERROR_LOG_ADDRESS_RANGE 0xD +#define ACTION_GET_ERROR_LOG_ADDRESS_LENGTH 0xE +#define ACTION_GET_ERROR_LOG_ADDRESS_RANGE_ATTRIBUTES 0xF +#define ACTION_GET_EXECUTE_OPERATION_TIMINGS 0x10 + +/* ACPI 4.0: Table 17-17 Command Status Definitions */ +#define STATUS_SUCCESS 0x00 +#define STATUS_NOT_ENOUGH_SPACE 0x01 +#define STATUS_HARDWARE_NOT_AVAILABLE 0x02 +#define STATUS_FAILED 0x03 +#define STATUS_RECORD_STORE_EMPTY 0x04 +#define STATUS_RECORD_NOT_FOUND 0x05 + + +/* UEFI 2.1: Appendix N Common Platform Error Record */ +#define UEFI_CPER_RECORD_MIN_SIZE 128U +#define UEFI_CPER_RECORD_LENGTH_OFFSET 20U +#define UEFI_CPER_RECORD_ID_OFFSET 96U +#define IS_UEFI_CPER_RECORD(ptr) \ + (((ptr)[0] =3D=3D 'C') && \ + ((ptr)[1] =3D=3D 'P') && \ + ((ptr)[2] =3D=3D 'E') && \ + ((ptr)[3] =3D=3D 'R')) + +/* + * NOTE that when accessing CPER fields within a record, memcpy() + * is utilized to avoid a possible misaligned access on the host. + */ + +/* + * This implementation is an ACTION (cmd) and VALUE (data) + * interface consisting of just two 64-bit registers. + */ +#define ERST_REG_SIZE (16UL) +#define ERST_ACTION_OFFSET (0UL) /* action (cmd) */ +#define ERST_VALUE_OFFSET (8UL) /* argument/value (data) */ + +/* + * ERST_RECORD_SIZE is the buffer size for exchanging ERST + * record contents. Thus, it defines the maximum record size. + * As this is mapped through a PCI BAR, it must be a power of + * two and larger than UEFI_CPER_RECORD_MIN_SIZE. + * The backing storage is divided into fixed size "slots", + * each ERST_RECORD_SIZE in length, and each "slot" + * storing a single record. No attempt at optimizing storage + * through compression, compaction, etc is attempted. + * NOTE that slot 0 is reserved for the backing storage header. + * Depending upon the size of the backing storage, additional + * slots will be part of the slot 0 header in order to account + * for a record_id for each available remaining slot. + */ +/* 8KiB records, not too small, not too big */ +#define ERST_RECORD_SIZE (8192UL) + +#define ACPI_ERST_MEMDEV_PROP "memdev" +#define ACPI_ERST_RECORD_SIZE_PROP "record_size" + +/* + * From the ACPI ERST spec sections: + * A record id of all 0s is used to indicate 'unspecified' record id. + * A record id of all 1s is used to indicate empty or end. + */ +#define ERST_UNSPECIFIED_RECORD_ID (0UL) +#define ERST_EMPTY_END_RECORD_ID (~0UL) +#define ERST_EXECUTE_OPERATION_MAGIC 0x9CUL +#define ERST_IS_VALID_RECORD_ID(rid) \ + ((rid !=3D ERST_UNSPECIFIED_RECORD_ID) && \ + (rid !=3D ERST_EMPTY_END_RECORD_ID)) +#define ERST_STORE_MAGIC 0x524F545354535245UL /* ERSTSTOR */ + +typedef struct { + uint64_t magic; + uint32_t record_size; + uint32_t storage_offset; /* offset to record storage beyond header */ + uint16_t version; + uint16_t reserved; + uint32_t record_count; + uint64_t map[]; /* contains record_ids, and position indicates index */ +} __attribute__((packed)) ERSTStorageHeader; + +/* + * Object cast macro + */ +#define ACPIERST(obj) \ + OBJECT_CHECK(ERSTDeviceState, (obj), TYPE_ACPI_ERST) + +/* + * Main ERST device state structure + */ +typedef struct { + PCIDevice parent_obj; + + /* Backend storage */ + HostMemoryBackend *hostmem; + MemoryRegion *hostmem_mr; + uint32_t storage_size; + uint32_t default_record_size; + + /* Programming registers */ + MemoryRegion iomem_mr; + + /* Exchange buffer */ + MemoryRegion exchange_mr; + + /* Interface state */ + uint8_t operation; + uint8_t busy_status; + uint8_t command_status; + uint32_t record_offset; + uint64_t reg_action; + uint64_t reg_value; + uint64_t record_identifier; + ERSTStorageHeader *header; + unsigned first_record_index; + unsigned last_record_index; + unsigned next_record_index; + +} ERSTDeviceState; + +/*******************************************************************/ +/*******************************************************************/ + +static uint8_t *get_nvram_ptr_by_index(ERSTDeviceState *s, unsigned index) +{ + uint8_t *rc =3D NULL; + off_t offset =3D (index * le32_to_cpu(s->header->record_size)); + + g_assert(offset < s->storage_size); + + rc =3D memory_region_get_ram_ptr(s->hostmem_mr); + rc +=3D offset; + + return rc; +} + +static void make_erst_storage_header(ERSTDeviceState *s) +{ + ERSTStorageHeader *header =3D s->header; + unsigned mapsz, headersz; + + header->magic =3D cpu_to_le64(ERST_STORE_MAGIC); + header->record_size =3D cpu_to_le32(s->default_record_size); + header->version =3D cpu_to_le16(0x0100); + header->reserved =3D cpu_to_le16(0x0000); + + /* Compute mapsize */ + mapsz =3D s->storage_size / s->default_record_size; + mapsz *=3D sizeof(uint64_t); + /* Compute header+map size */ + headersz =3D sizeof(ERSTStorageHeader) + mapsz; + /* Round up to nearest integer multiple of ERST_RECORD_SIZE */ + headersz =3D QEMU_ALIGN_UP(headersz, s->default_record_size); + header->storage_offset =3D cpu_to_le32(headersz); + + /* + * The HostMemoryBackend initializes contents to zero, + * so all record_ids stashed in the map are zero'd. + * As well the record_count is zero. Properly initialized. + */ +} + +static void check_erst_backend_storage(ERSTDeviceState *s, Error **errp) +{ + ERSTStorageHeader *header; + uint32_t record_size; + + header =3D memory_region_get_ram_ptr(s->hostmem_mr); + s->header =3D header; + + /* Ensure pointer to header is 64-bit aligned */ + g_assert(QEMU_PTR_IS_ALIGNED(header, sizeof(uint64_t))); + + /* + * Check if header is uninitialized; HostMemoryBackend inits to 0 + */ + if (le64_to_cpu(header->magic) =3D=3D 0UL) { + make_erst_storage_header(s); + } + + /* Validity check record_size */ + record_size =3D le32_to_cpu(header->record_size); + if (!( + (record_size) && /* non zero */ + (record_size >=3D UEFI_CPER_RECORD_MIN_SIZE) && + (((record_size - 1) & record_size) =3D=3D 0) && /* is power of 2 */ + (record_size >=3D 4096) /* PAGE_SIZE */ + )) { + error_setg(errp, "ERST record_size %u is invalid", record_size); + } + + /* Validity check header */ + if (!( + (le64_to_cpu(header->magic) =3D=3D ERST_STORE_MAGIC) && + ((le32_to_cpu(header->storage_offset) % record_size) =3D=3D 0) && + (le16_to_cpu(header->version) =3D=3D 0x0100) && + (le16_to_cpu(header->reserved) =3D=3D 0) + )) { + error_setg(errp, "ERST backend storage header is invalid"); + } + + /* Check storage_size against record_size */ + if (((s->storage_size % record_size) !=3D 0) || + (record_size > s->storage_size)) { + error_setg(errp, "ACPI ERST requires size be multiple of " + "record size (%uKiB)", record_size); + } + + /* Compute offset of first and last record storage slot */ + s->first_record_index =3D le32_to_cpu(header->storage_offset) + / record_size; + s->last_record_index =3D (s->storage_size / record_size); +} + +static void update_map_entry(ERSTDeviceState *s, unsigned index, + uint64_t record_id) +{ + if (index < s->last_record_index) { + s->header->map[index] =3D cpu_to_le64(record_id); + } +} + +static unsigned allocate_erst_record(ERSTDeviceState *s) +{ + unsigned rc =3D 0; /* 0 not a valid index */ + unsigned index =3D s->first_record_index; + + for (; index < s->last_record_index; ++index) { + if (le64_to_cpu(s->header->map[index]) =3D=3D ERST_UNSPECIFIED_REC= ORD_ID) { + rc =3D index; + break; + } + } + + return rc; +} + +static unsigned lookup_erst_record(ERSTDeviceState *s, + uint64_t record_identifier) +{ + unsigned rc =3D 0; /* 0 not a valid index */ + + /* Find the record_identifier in the map */ + if (record_identifier !=3D ERST_UNSPECIFIED_RECORD_ID) { + /* + * Count number of valid records encountered, and + * short-circuit the loop if identifier not found + */ + uint32_t record_count =3D le32_to_cpu(s->header->record_count); + unsigned count =3D 0; + unsigned index; + for (index =3D s->first_record_index; index < s->last_record_index= && + count < record_count; ++index) { + if (le64_to_cpu(s->header->map[index]) =3D=3D record_identifie= r) { + rc =3D index; + break; + } + if (le64_to_cpu(s->header->map[index]) !=3D + ERST_UNSPECIFIED_RECORD_ID) { + ++count; + } + } + } + + return rc; +} + +/* + * ACPI 4.0: 17.4.1.1 Serialization Actions, also see + * ACPI 4.0: 17.4.2.2 Operations - Reading 6.c and 2.c + */ +static unsigned get_next_record_identifier(ERSTDeviceState *s, + uint64_t *record_identifier, bool first) +{ + unsigned found =3D 0; + unsigned index; + + /* For operations needing to return 'first' record identifer */ + if (first) { + /* Reset initial index to beginning */ + s->next_record_index =3D s->first_record_index; + } + index =3D s->next_record_index; + + *record_identifier =3D ERST_EMPTY_END_RECORD_ID; + + if (le32_to_cpu(s->header->record_count)) { + for (; index < s->last_record_index; ++index) { + if (le64_to_cpu(s->header->map[index]) !=3D + ERST_UNSPECIFIED_RECORD_ID) { + /* where to start next time */ + s->next_record_index =3D index + 1; + *record_identifier =3D le64_to_cpu(s->header->map[inde= x]); + found =3D 1; + break; + } + } + } + if (!found) { + /* at end (ie scan complete), reset */ + s->next_record_index =3D s->first_record_index; + } + + return STATUS_SUCCESS; +} + +/* ACPI 4.0: 17.4.2.3 Operations - Clearing */ +static unsigned clear_erst_record(ERSTDeviceState *s) +{ + unsigned rc =3D STATUS_RECORD_NOT_FOUND; + unsigned index; + + /* Check for valid record identifier */ + if (!ERST_IS_VALID_RECORD_ID(s->record_identifier)) { + return STATUS_FAILED; + } + + index =3D lookup_erst_record(s, s->record_identifier); + if (index) { + /* No need to wipe record, just invalidate its map entry */ + uint32_t record_count; + update_map_entry(s, index, ERST_UNSPECIFIED_RECORD_ID); + record_count =3D le32_to_cpu(s->header->record_count); + record_count -=3D 1; + s->header->record_count =3D cpu_to_le32(record_count); + rc =3D STATUS_SUCCESS; + } + + return rc; +} + +/* ACPI 4.0: 17.4.2.2 Operations - Reading */ +static unsigned read_erst_record(ERSTDeviceState *s) +{ + unsigned rc =3D STATUS_RECORD_NOT_FOUND; + unsigned exchange_length; + unsigned index; + + /* Check if backend storage is empty */ + if (le32_to_cpu(s->header->record_count) =3D=3D 0) { + return STATUS_RECORD_STORE_EMPTY; + } + + exchange_length =3D memory_region_size(&s->exchange_mr); + + /* Check for record identifier of all 0s */ + if (s->record_identifier =3D=3D ERST_UNSPECIFIED_RECORD_ID) { + /* Set to 'first' record in storage */ + get_next_record_identifier(s, &s->record_identifier, true); + /* record_identifier is now a valid id, or all 1s */ + } + + /* Check for record identifier of all 1s */ + if (s->record_identifier =3D=3D ERST_EMPTY_END_RECORD_ID) { + return STATUS_FAILED; + } + + /* Validate record_offset */ + if (s->record_offset > (exchange_length - UEFI_CPER_RECORD_MIN_SIZE)) { + return STATUS_FAILED; + } + + index =3D lookup_erst_record(s, s->record_identifier); + if (index) { + uint8_t *nvram; + uint8_t *exchange; + uint32_t record_length; + + /* Obtain pointer to the exchange buffer */ + exchange =3D memory_region_get_ram_ptr(&s->exchange_mr); + exchange +=3D s->record_offset; + /* Obtain pointer to slot in storage */ + nvram =3D get_nvram_ptr_by_index(s, index); + /* Validate CPER record_length */ + memcpy((uint8_t *)&record_length, + &nvram[UEFI_CPER_RECORD_LENGTH_OFFSET], + sizeof(uint32_t)); + record_length =3D le32_to_cpu(record_length); + if (record_length < UEFI_CPER_RECORD_MIN_SIZE) { + rc =3D STATUS_FAILED; + } + if ((s->record_offset + record_length) > exchange_length) { + rc =3D STATUS_FAILED; + } + /* If all is ok, copy the record to the exchange buffer */ + if (rc !=3D STATUS_FAILED) { + memcpy(exchange, nvram, record_length); + rc =3D STATUS_SUCCESS; + } + } else { + /* Set to 'first' record in storage */ + get_next_record_identifier(s, &s->record_identifier, true); + } + + return rc; +} + +/* ACPI 4.0: 17.4.2.1 Operations - Writing */ +static unsigned write_erst_record(ERSTDeviceState *s) +{ + unsigned rc =3D STATUS_FAILED; + unsigned exchange_length; + unsigned index; + uint64_t record_identifier; + uint32_t record_length; + uint8_t *exchange; + uint8_t *nvram =3D NULL; + bool record_found =3D false; + + exchange_length =3D memory_region_size(&s->exchange_mr); + + /* Validate record_offset */ + if (s->record_offset > (exchange_length - UEFI_CPER_RECORD_MIN_SIZE)) { + return STATUS_FAILED; + } + + /* Obtain pointer to record in the exchange buffer */ + exchange =3D memory_region_get_ram_ptr(&s->exchange_mr); + exchange +=3D s->record_offset; + + /* Validate CPER record_length */ + memcpy((uint8_t *)&record_length, &exchange[UEFI_CPER_RECORD_LENGTH_OF= FSET], + sizeof(uint32_t)); + record_length =3D le32_to_cpu(record_length); + if (record_length < UEFI_CPER_RECORD_MIN_SIZE) { + return STATUS_FAILED; + } + if ((s->record_offset + record_length) > exchange_length) { + return STATUS_FAILED; + } + + /* Extract record identifier */ + memcpy((uint8_t *)&record_identifier, &exchange[UEFI_CPER_RECORD_ID_OF= FSET], + sizeof(uint64_t)); + record_identifier =3D le64_to_cpu(record_identifier); + + /* Check for valid record identifier */ + if (!ERST_IS_VALID_RECORD_ID(record_identifier)) { + return STATUS_FAILED; + } + + index =3D lookup_erst_record(s, record_identifier); + if (index) { + /* Record found, overwrite existing record */ + nvram =3D get_nvram_ptr_by_index(s, index); + record_found =3D true; + } else { + /* Record not found, not an overwrite, allocate for write */ + index =3D allocate_erst_record(s); + if (index) { + nvram =3D get_nvram_ptr_by_index(s, index); + } else { + rc =3D STATUS_NOT_ENOUGH_SPACE; + } + } + if (nvram) { + /* Write the record into the slot */ + memcpy(nvram, exchange, record_length); + memset(nvram + record_length, exchange_length - record_length, 0xF= F); + /* If a new record, increment the record_count */ + if (!record_found) { + uint32_t record_count; + record_count =3D le32_to_cpu(s->header->record_count); + record_count +=3D 1; /* writing new record */ + s->header->record_count =3D cpu_to_le32(record_count); + } + update_map_entry(s, index, record_identifier); + rc =3D STATUS_SUCCESS; + } + + return rc; +} + +/*******************************************************************/ + +static uint64_t erst_rd_reg64(hwaddr addr, + uint64_t reg, unsigned size) +{ + uint64_t rdval; + uint64_t mask; + unsigned shift; + + if (size =3D=3D sizeof(uint64_t)) { + /* 64b access */ + mask =3D 0xFFFFFFFFFFFFFFFFUL; + shift =3D 0; + } else { + /* 32b access */ + mask =3D 0x00000000FFFFFFFFUL; + shift =3D ((addr & 0x4) =3D=3D 0x4) ? 32 : 0; + } + + rdval =3D reg; + rdval >>=3D shift; + rdval &=3D mask; + + return rdval; +} + +static uint64_t erst_wr_reg64(hwaddr addr, + uint64_t reg, uint64_t val, unsigned size) +{ + uint64_t wrval; + uint64_t mask; + unsigned shift; + + if (size =3D=3D sizeof(uint64_t)) { + /* 64b access */ + mask =3D 0xFFFFFFFFFFFFFFFFUL; + shift =3D 0; + } else { + /* 32b access */ + mask =3D 0x00000000FFFFFFFFUL; + shift =3D ((addr & 0x4) =3D=3D 0x4) ? 32 : 0; + } + + val &=3D mask; + val <<=3D shift; + mask <<=3D shift; + wrval =3D reg; + wrval &=3D ~mask; + wrval |=3D val; + + return wrval; +} + +static void erst_reg_write(void *opaque, hwaddr addr, + uint64_t val, unsigned size) +{ + ERSTDeviceState *s =3D (ERSTDeviceState *)opaque; + + /* + * NOTE: All actions/operations/side effects happen on the WRITE, + * by this implementation's design. The READs simply return the + * reg_value contents. + */ + trace_acpi_erst_reg_write(addr, val, size); + + switch (addr) { + case ERST_VALUE_OFFSET + 0: + case ERST_VALUE_OFFSET + 4: + s->reg_value =3D erst_wr_reg64(addr, s->reg_value, val, size); + break; + case ERST_ACTION_OFFSET + 0: + /* + * NOTE: all valid values written to this register are of the + * ACTION_* variety. Thus there is no need to make this a 64-bit + * register, 32-bits is appropriate. As such ERST_ACTION_OFFSET+4 + * is not needed. + */ + switch (val) { + case ACTION_BEGIN_WRITE_OPERATION: + case ACTION_BEGIN_READ_OPERATION: + case ACTION_BEGIN_CLEAR_OPERATION: + case ACTION_BEGIN_DUMMY_WRITE_OPERATION: + case ACTION_END_OPERATION: + s->operation =3D val; + break; + case ACTION_SET_RECORD_OFFSET: + s->record_offset =3D s->reg_value; + break; + case ACTION_EXECUTE_OPERATION: + if ((uint8_t)s->reg_value =3D=3D ERST_EXECUTE_OPERATION_MAGIC)= { + s->busy_status =3D 1; + switch (s->operation) { + case ACTION_BEGIN_WRITE_OPERATION: + s->command_status =3D write_erst_record(s); + break; + case ACTION_BEGIN_READ_OPERATION: + s->command_status =3D read_erst_record(s); + break; + case ACTION_BEGIN_CLEAR_OPERATION: + s->command_status =3D clear_erst_record(s); + break; + case ACTION_BEGIN_DUMMY_WRITE_OPERATION: + s->command_status =3D STATUS_SUCCESS; + break; + case ACTION_END_OPERATION: + s->command_status =3D STATUS_SUCCESS; + break; + default: + s->command_status =3D STATUS_FAILED; + break; + } + s->busy_status =3D 0; + } + break; + case ACTION_CHECK_BUSY_STATUS: + s->reg_value =3D s->busy_status; + break; + case ACTION_GET_COMMAND_STATUS: + s->reg_value =3D s->command_status; + break; + case ACTION_GET_RECORD_IDENTIFIER: + s->command_status =3D get_next_record_identifier(s, + &s->reg_value, false); + break; + case ACTION_SET_RECORD_IDENTIFIER: + s->record_identifier =3D s->reg_value; + break; + case ACTION_GET_RECORD_COUNT: + s->reg_value =3D le32_to_cpu(s->header->record_count); + break; + case ACTION_GET_ERROR_LOG_ADDRESS_RANGE: + s->reg_value =3D (hwaddr)pci_get_bar_addr(PCI_DEVICE(s), 1); + break; + case ACTION_GET_ERROR_LOG_ADDRESS_LENGTH: + s->reg_value =3D le32_to_cpu(s->header->record_size); + break; + case ACTION_GET_ERROR_LOG_ADDRESS_RANGE_ATTRIBUTES: + s->reg_value =3D 0x0; /* intentional, not NVRAM mode */ + break; + case ACTION_GET_EXECUTE_OPERATION_TIMINGS: + s->reg_value =3D + (100ULL << 32) | /* 100us max time */ + (10ULL << 0) ; /* 10us min time */ + break; + default: + /* Unknown action/command, NOP */ + break; + } + break; + default: + /* This should not happen, but if it does, NOP */ + break; + } +} + +static uint64_t erst_reg_read(void *opaque, hwaddr addr, + unsigned size) +{ + ERSTDeviceState *s =3D (ERSTDeviceState *)opaque; + uint64_t val =3D 0; + + switch (addr) { + case ERST_ACTION_OFFSET + 0: + case ERST_ACTION_OFFSET + 4: + val =3D erst_rd_reg64(addr, s->reg_action, size); + break; + case ERST_VALUE_OFFSET + 0: + case ERST_VALUE_OFFSET + 4: + val =3D erst_rd_reg64(addr, s->reg_value, size); + break; + default: + break; + } + trace_acpi_erst_reg_read(addr, val, size); + return val; +} + +static const MemoryRegionOps erst_reg_ops =3D { + .read =3D erst_reg_read, + .write =3D erst_reg_write, + .endianness =3D DEVICE_NATIVE_ENDIAN, +}; + +/*******************************************************************/ +/*******************************************************************/ +static int erst_post_load(void *opaque, int version_id) +{ + ERSTDeviceState *s =3D opaque; + + /* Recompute pointer to header */ + s->header =3D (ERSTStorageHeader *)get_nvram_ptr_by_index(s, 0); + trace_acpi_erst_post_load(s->header, le32_to_cpu(s->header->record_siz= e)); + + return 0; +} + +static const VMStateDescription erst_vmstate =3D { + .name =3D "acpi-erst", + .version_id =3D 1, + .minimum_version_id =3D 1, + .post_load =3D erst_post_load, + .fields =3D (VMStateField[]) { + VMSTATE_UINT8(operation, ERSTDeviceState), + VMSTATE_UINT8(busy_status, ERSTDeviceState), + VMSTATE_UINT8(command_status, ERSTDeviceState), + VMSTATE_UINT32(record_offset, ERSTDeviceState), + VMSTATE_UINT64(reg_action, ERSTDeviceState), + VMSTATE_UINT64(reg_value, ERSTDeviceState), + VMSTATE_UINT64(record_identifier, ERSTDeviceState), + VMSTATE_UINT32(next_record_index, ERSTDeviceState), + VMSTATE_END_OF_LIST() + } +}; + +static void erst_realizefn(PCIDevice *pci_dev, Error **errp) +{ + ERSTDeviceState *s =3D ACPIERST(pci_dev); + + trace_acpi_erst_realizefn_in(); + + if (!s->hostmem) { + error_setg(errp, "'" ACPI_ERST_MEMDEV_PROP "' property is not set"= ); + return; + } else if (host_memory_backend_is_mapped(s->hostmem)) { + error_setg(errp, "can't use already busy memdev: %s", + object_get_canonical_path_component(OBJECT(s->hostmem))= ); + return; + } + + s->hostmem_mr =3D host_memory_backend_get_memory(s->hostmem); + + /* HostMemoryBackend size will be multiple of PAGE_SIZE */ + s->storage_size =3D object_property_get_int(OBJECT(s->hostmem), "size"= , errp); + + /* Initialize backend storage and record_count */ + check_erst_backend_storage(s, errp); + + /* BAR 0: Programming registers */ + memory_region_init_io(&s->iomem_mr, OBJECT(pci_dev), &erst_reg_ops, s, + TYPE_ACPI_ERST, ERST_REG_SIZE); + pci_register_bar(pci_dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->iomem_= mr); + + /* BAR 1: Exchange buffer memory */ + memory_region_init_ram(&s->exchange_mr, OBJECT(pci_dev), + "erst.exchange", + le32_to_cpu(s->header->record_size), errp); + pci_register_bar(pci_dev, 1, PCI_BASE_ADDRESS_SPACE_MEMORY, + &s->exchange_mr); + + /* Include the backend storage in the migration stream */ + vmstate_register_ram_global(s->hostmem_mr); + + trace_acpi_erst_realizefn_out(s->storage_size); +} + +static void erst_reset(DeviceState *dev) +{ + ERSTDeviceState *s =3D ACPIERST(dev); + + trace_acpi_erst_reset_in(le32_to_cpu(s->header->record_count)); + s->operation =3D 0; + s->busy_status =3D 0; + s->command_status =3D STATUS_SUCCESS; + s->record_identifier =3D ERST_UNSPECIFIED_RECORD_ID; + s->record_offset =3D 0; + s->next_record_index =3D s->first_record_index; + /* NOTE: first/last_record_index are computed only once */ + trace_acpi_erst_reset_out(le32_to_cpu(s->header->record_count)); +} + +static Property erst_properties[] =3D { + DEFINE_PROP_LINK(ACPI_ERST_MEMDEV_PROP, ERSTDeviceState, hostmem, + TYPE_MEMORY_BACKEND, HostMemoryBackend *), + DEFINE_PROP_UINT32(ACPI_ERST_RECORD_SIZE_PROP, ERSTDeviceState, + default_record_size, ERST_RECORD_SIZE), + DEFINE_PROP_END_OF_LIST(), +}; + +static void erst_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + PCIDeviceClass *k =3D PCI_DEVICE_CLASS(klass); + + trace_acpi_erst_class_init_in(); + k->realize =3D erst_realizefn; + k->vendor_id =3D PCI_VENDOR_ID_REDHAT; + k->device_id =3D PCI_DEVICE_ID_REDHAT_ACPI_ERST; + k->revision =3D 0x00; + k->class_id =3D PCI_CLASS_OTHERS; + dc->reset =3D erst_reset; + dc->vmsd =3D &erst_vmstate; + dc->user_creatable =3D true; + dc->hotpluggable =3D false; + device_class_set_props(dc, erst_properties); + dc->desc =3D "ACPI Error Record Serialization Table (ERST) device"; + set_bit(DEVICE_CATEGORY_MISC, dc->categories); + trace_acpi_erst_class_init_out(); +} + +static const TypeInfo erst_type_info =3D { + .name =3D TYPE_ACPI_ERST, + .parent =3D TYPE_PCI_DEVICE, + .class_init =3D erst_class_init, + .instance_size =3D sizeof(ERSTDeviceState), + .interfaces =3D (InterfaceInfo[]) { + { INTERFACE_CONVENTIONAL_PCI_DEVICE }, + { } + } +}; + +static void erst_register_types(void) +{ + type_register_static(&erst_type_info); +} + +type_init(erst_register_types) diff --git a/hw/acpi/meson.build b/hw/acpi/meson.build index 7d8c0eb..348b94f 100644 --- a/hw/acpi/meson.build +++ b/hw/acpi/meson.build @@ -5,6 +5,7 @@ acpi_ss.add(files( 'bios-linker-loader.c', 'core.c', 'utils.c', + 'erst.c', )) acpi_ss.add(when: 'CONFIG_ACPI_CPU_HOTPLUG', if_true: files('cpu.c', 'cpu_= hotplug.c')) acpi_ss.add(when: 'CONFIG_ACPI_CPU_HOTPLUG', if_false: files('acpi-cpu-hot= plug-stub.c')) diff --git a/hw/acpi/trace-events b/hw/acpi/trace-events index 974d770..2250126 100644 --- a/hw/acpi/trace-events +++ b/hw/acpi/trace-events @@ -55,3 +55,18 @@ piix4_gpe_writeb(uint64_t addr, unsigned width, uint64_t= val) "addr: 0x%" PRIx64 # tco.c tco_timer_reload(int ticks, int msec) "ticks=3D%d (%d ms)" tco_timer_expired(int timeouts_no, bool strap, bool no_reboot) "timeouts_n= o=3D%d no_reboot=3D%d/%d" + +# erst.c +acpi_erst_reg_write(uint64_t addr, uint64_t val, unsigned size) "addr: 0x%= 04" PRIx64 " <=3D=3D 0x%016" PRIx64 " (size: %u)" +acpi_erst_reg_read(uint64_t addr, uint64_t val, unsigned size) " addr: 0x%= 04" PRIx64 " =3D=3D> 0x%016" PRIx64 " (size: %u)" +acpi_erst_mem_write(uint64_t addr, uint64_t val, unsigned size) "addr: 0x%= 06" PRIx64 " <=3D=3D 0x%016" PRIx64 " (size: %u)" +acpi_erst_mem_read(uint64_t addr, uint64_t val, unsigned size) " addr: 0x%= 06" PRIx64 " =3D=3D> 0x%016" PRIx64 " (size: %u)" +acpi_erst_pci_bar_0(uint64_t addr) "BAR0: 0x%016" PRIx64 +acpi_erst_pci_bar_1(uint64_t addr) "BAR1: 0x%016" PRIx64 +acpi_erst_realizefn_in(void) +acpi_erst_realizefn_out(unsigned size) "total nvram size %u bytes" +acpi_erst_reset_in(unsigned record_count) "record_count %u" +acpi_erst_reset_out(unsigned record_count) "record_count %u" +acpi_erst_post_load(void *header, unsigned slot_size) "header: 0x%p slot_s= ize %u" +acpi_erst_class_init_in(void) +acpi_erst_class_init_out(void) --=20 1.8.3.1