From patchwork Sat Jan 21 07:37:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Asahi Lina X-Patchwork-Id: 46782 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp616370wrn; Fri, 20 Jan 2023 23:43:38 -0800 (PST) X-Google-Smtp-Source: AMrXdXvCM1JkxbbYhZGyYqlc1lirqpAGJ4Zh7HOX8KrAhit7gahtS7bBO4PUAelyv2ebBehwv6Dr X-Received: by 2002:a17:90a:c284:b0:229:4b87:4001 with SMTP id f4-20020a17090ac28400b002294b874001mr18758834pjt.38.1674287018597; Fri, 20 Jan 2023 23:43:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674287018; cv=none; d=google.com; s=arc-20160816; b=pERy5KQco8NFPh//D+27nvLNGbZN0MV+yb2afZFTphUwszAtg5rHuG+nUvgym4M4pa S65oqbUDkJP/+yHxLBqwn2Hzlbx+cRMG4d31yyXV+8WQnTqaX/eOOWiGrDFVyPz7cjFG BN0uT6K0aNj8je9pdbWwBrOgonNdeSwkWMoEFRZ8qzpo1PfB5CPPKo0NOHKkqNzXXPzU 7yCW2g3/je+XjmSB4b2Ar0zLkTExY83Jo8dG8t5oyPj+EHuLRGGtnvkaKl/pHlOfarfe 2VIhGMKTI2qtEZfOpoo68DLgc2bfd4sNmmR20R5pp2YWwkQM4dh8yqATDIVYNxK2Oegy VsJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=ykZC9nQwI0X+4HwDCmqTmIMpyNYx8NeCh95MlCGs9Wk=; b=WTwiDDA+XFRvUcJbbE8CIhshcKmbRUR1hnohKC8ZMiuet7RyhTI0FjoGI6seKBfggT QZ6Yaw6lIRzrURp/QcSFX0VtsPCp2S0eKAHkgnUGTxYmWbOuX0rTTUafNMqcwQV2gmVR FsB4v5aDp8/KwSDTbPSmIEMD1Dp60GGto7w5qEm5C++iG4YxEZQ+pMIXNHfKWbJ3yoIa mZ7pzvQemHXQqfDqiLulkzwdgKIj/EG1K8ppSoAk7Cmnl2E+3VSCEK6QACdF0I2533za UkxRurj0Kcil0L8GOYTTvJiqNr9zlf5P1eMKNuw812u5FVAqeqpe5Wzm1SPIfCqn8kiV t+jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@asahilina.net header.s=default header.b=yYmj28nd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=asahilina.net Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gi9-20020a17090b110900b00229791d2de9si4684566pjb.80.2023.01.20.23.43.24; Fri, 20 Jan 2023 23:43:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@asahilina.net header.s=default header.b=yYmj28nd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=asahilina.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229636AbjAUHib (ORCPT + 99 others); Sat, 21 Jan 2023 02:38:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229450AbjAUHia (ORCPT ); Sat, 21 Jan 2023 02:38:30 -0500 Received: from mail.marcansoft.com (marcansoft.com [212.63.210.85]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BA7D3646F for ; Fri, 20 Jan 2023 23:38:28 -0800 (PST) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: linasend@asahilina.net) by mail.marcansoft.com (Postfix) with ESMTPSA id C3AB541EF0; Sat, 21 Jan 2023 07:38:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=asahilina.net; s=default; t=1674286705; bh=q7UBuSh0sNqJzA71lhmY5ZED0bNc4qbRW1noW7A6qYw=; h=From:To:Cc:Subject:Date; b=yYmj28ndySj3bYRPSK8vfFu+T1cou8hjuwnfxx+HdjpmBgfHnOF55c8O1zi8bNKG+ RaRPj87tkE1F40fYCrSXWJPVRnzONuI/1vdKJBvEDTA9lxmCrgFP5P0FdMB9mkqBbn 31PnJI3s+2W14td6akGOixk6d2eoFQUCuDVmTM7gE6t/bRI3oTsZzNcCHzLpuU+bd7 oZ2K2jzQ82T1WfPbLmLe+sA0BWfEm1Mczm6//BB0ZU3QytOslyfUI8Cnnyej+J+qyC QFX0HDeLkXnxSb7JLT1KdK9hBehxe/AzqY6NISr+MNzRmt+Q97n/gyILMyhBlS8JCb 4aZbTFKRJnReA== From: Asahi Lina To: Hector Martin , Sven Peter Cc: Alyssa Rosenzweig , asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Asahi Lina Subject: [PATCH] soc: apple: rtkit: Add register dump decoding to crashlog Date: Sat, 21 Jan 2023 16:37:41 +0900 Message-Id: <20230121073741.3807-1-lina@asahilina.net> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755617185167540368?= X-GMAIL-MSGID: =?utf-8?q?1755617185167540368?= When the coprocessor crashes, it's useful to get a proper register dump so we can find out what the firmware was doing. Add a decoder for this. Originally this had ESR decoding by reusing the ARM64 arch header for this, but that introduces some module linking and cross-arch compilation issues, so let's leave that out for now. Signed-off-by: Asahi Lina Reviewed-by: Sven Peter Signed-off-by: Eric Curtin Reviewed-by: Eric Curtin --- drivers/soc/apple/rtkit-crashlog.c | 83 ++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/drivers/soc/apple/rtkit-crashlog.c b/drivers/soc/apple/rtkit-crashlog.c index 732deed64660..e29ef0a80ab8 100644 --- a/drivers/soc/apple/rtkit-crashlog.c +++ b/drivers/soc/apple/rtkit-crashlog.c @@ -13,6 +13,7 @@ #define APPLE_RTKIT_CRASHLOG_VERSION FOURCC('C', 'v', 'e', 'r') #define APPLE_RTKIT_CRASHLOG_MBOX FOURCC('C', 'm', 'b', 'x') #define APPLE_RTKIT_CRASHLOG_TIME FOURCC('C', 't', 'i', 'm') +#define APPLE_RTKIT_CRASHLOG_REGS FOURCC('C', 'r', 'g', '8') struct apple_rtkit_crashlog_header { u32 fourcc; @@ -31,6 +32,24 @@ struct apple_rtkit_crashlog_mbox_entry { }; static_assert(sizeof(struct apple_rtkit_crashlog_mbox_entry) == 0x18); +struct apple_rtkit_crashlog_regs { + u32 unk_0; + u32 unk_4; + u64 regs[31]; + u64 sp; + u64 pc; + u64 psr; + u64 cpacr; + u64 fpsr; + u64 fpcr; + u64 unk[64]; + u64 far; + u64 unk_X; + u64 esr; + u64 unk_Z; +}; +static_assert(sizeof(struct apple_rtkit_crashlog_regs) == 0x350); + static void apple_rtkit_crashlog_dump_str(struct apple_rtkit *rtk, u8 *bfr, size_t size) { @@ -94,6 +113,66 @@ static void apple_rtkit_crashlog_dump_mailbox(struct apple_rtkit *rtk, u8 *bfr, } } +static void apple_rtkit_crashlog_dump_regs(struct apple_rtkit *rtk, u8 *bfr, + size_t size) +{ + struct apple_rtkit_crashlog_regs regs; + const char *el; + int i; + + if (size < sizeof(regs)) { + dev_warn(rtk->dev, "RTKit: Regs section too small: 0x%lx", size); + return; + } + + memcpy(®s, bfr, sizeof(regs)); + + switch (regs.psr & PSR_MODE_MASK) { + case PSR_MODE_EL0t: + el = "EL0t"; + break; + case PSR_MODE_EL1t: + el = "EL1t"; + break; + case PSR_MODE_EL1h: + el = "EL1h"; + break; + case PSR_MODE_EL2t: + el = "EL2t"; + break; + case PSR_MODE_EL2h: + el = "EL2h"; + break; + default: + el = "unknown"; + break; + } + + dev_warn(rtk->dev, "RTKit: Exception dump:"); + dev_warn(rtk->dev, " == Exception taken from %s ==", el); + dev_warn(rtk->dev, " PSR = 0x%llx", regs.psr); + dev_warn(rtk->dev, " PC = 0x%llx\n", regs.pc); + dev_warn(rtk->dev, " ESR = 0x%llx\n", regs.esr); + dev_warn(rtk->dev, " FAR = 0x%llx\n", regs.far); + dev_warn(rtk->dev, " SP = 0x%llx\n", regs.sp); + dev_warn(rtk->dev, "\n"); + + for (i = 0; i < 31; i += 4) { + if (i < 28) + dev_warn(rtk->dev, + " x%02d-x%02d = %016llx %016llx %016llx %016llx\n", + i, i + 3, + regs.regs[i], regs.regs[i + 1], + regs.regs[i + 2], regs.regs[i + 3]); + else + dev_warn(rtk->dev, + " x%02d-x%02d = %016llx %016llx %016llx\n", i, i + 3, + regs.regs[i], regs.regs[i + 1], regs.regs[i + 2]); + } + + dev_warn(rtk->dev, "\n"); +} + void apple_rtkit_crashlog_dump(struct apple_rtkit *rtk, u8 *bfr, size_t size) { size_t offset; @@ -140,6 +219,10 @@ void apple_rtkit_crashlog_dump(struct apple_rtkit *rtk, u8 *bfr, size_t size) apple_rtkit_crashlog_dump_time(rtk, bfr + offset + 16, section_size); break; + case APPLE_RTKIT_CRASHLOG_REGS: + apple_rtkit_crashlog_dump_regs(rtk, bfr + offset + 16, + section_size); + break; default: dev_warn(rtk->dev, "RTKit: Unknown crashlog section: %x",