Skip to content

Commit

Permalink
soc: apple: rtkit: Add register dump decoding to crashlog
Browse files Browse the repository at this point in the history
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 <lina@asahilina.net>
  • Loading branch information
asahilina authored and intel-lab-lkp committed Jan 21, 2023
1 parent f040242 commit 91f957d
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions drivers/soc/apple/rtkit-crashlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
{
Expand Down Expand Up @@ -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(&regs, 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;
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 91f957d

Please sign in to comment.