2021-06-05 20:05:17 +00:00
|
|
|
/* SPDX-License-Identifier: MIT */
|
|
|
|
|
|
|
|
#include "adt.h"
|
2021-09-20 15:42:19 +00:00
|
|
|
#include "aic.h"
|
2021-08-23 08:01:33 +00:00
|
|
|
#include "aic_regs.h"
|
2021-06-05 20:05:17 +00:00
|
|
|
#include "hv.h"
|
|
|
|
#include "uartproxy.h"
|
|
|
|
#include "utils.h"
|
|
|
|
|
|
|
|
#define IRQTRACE_IRQ BIT(0)
|
|
|
|
|
2022-03-24 07:09:44 +00:00
|
|
|
static u32 trace_hw_num[AIC_MAX_DIES][AIC_MAX_HW_NUM / 32];
|
2021-06-05 20:05:17 +00:00
|
|
|
|
2022-03-24 07:09:44 +00:00
|
|
|
static void emit_irqtrace(u16 die, u16 type, u16 num)
|
2021-06-05 20:05:17 +00:00
|
|
|
{
|
|
|
|
struct hv_evt_irqtrace evt = {
|
|
|
|
.flags = IRQTRACE_IRQ,
|
|
|
|
.type = type,
|
2022-03-24 07:09:44 +00:00
|
|
|
.num = die * aic->max_irq + num,
|
2021-06-05 20:05:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
hv_wdt_suspend();
|
|
|
|
uartproxy_send_event(EVT_IRQTRACE, &evt, sizeof(evt));
|
|
|
|
hv_wdt_resume();
|
|
|
|
}
|
|
|
|
|
2021-09-21 12:10:44 +00:00
|
|
|
static bool trace_aic_event(struct exc_info *ctx, u64 addr, u64 *val, bool write, int width)
|
2021-06-05 20:05:17 +00:00
|
|
|
{
|
2021-09-21 12:10:44 +00:00
|
|
|
if (!hv_pa_rw(ctx, addr, val, write, width))
|
2021-06-05 20:05:17 +00:00
|
|
|
return false;
|
|
|
|
|
2022-03-24 07:09:44 +00:00
|
|
|
if (addr != (aic->base + aic->regs.event) || write || width != 2) {
|
2021-06-05 20:05:17 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-03-24 07:09:44 +00:00
|
|
|
u16 die = FIELD_GET(AIC_EVENT_DIE, *val);
|
|
|
|
u16 type = FIELD_GET(AIC_EVENT_TYPE, *val);
|
|
|
|
u16 num = FIELD_GET(AIC_EVENT_NUM, *val);
|
|
|
|
|
|
|
|
if (die > AIC_MAX_DIES)
|
|
|
|
return true;
|
2021-06-05 20:05:17 +00:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case AIC_EVENT_TYPE_HW:
|
2022-03-24 07:09:44 +00:00
|
|
|
if (trace_hw_num[die][num / 32] & BIT(num & 31)) {
|
|
|
|
emit_irqtrace(die, type, num);
|
2021-06-05 20:05:17 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// ignore
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hv_trace_irq(u32 type, u32 num, u32 count, u32 flags)
|
|
|
|
{
|
|
|
|
dprintf("HV: hv_trace_irq type: %u start: %u num: %u flags: 0x%x\n", type, num, count, flags);
|
|
|
|
if (type == AIC_EVENT_TYPE_HW) {
|
2022-03-24 07:09:44 +00:00
|
|
|
u32 die = num / aic->max_irq;
|
|
|
|
num %= AIC_MAX_HW_NUM;
|
|
|
|
if (die >= aic->max_irq || num >= AIC_MAX_HW_NUM || count > AIC_MAX_HW_NUM - num) {
|
|
|
|
printf("HV: invalid IRQ range: (%u, %u) for die %u\n", num, num + count, die);
|
2021-06-05 20:05:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
for (u32 n = num; n < num + count; n++) {
|
|
|
|
switch (flags) {
|
|
|
|
case IRQTRACE_IRQ:
|
2022-03-24 07:09:44 +00:00
|
|
|
trace_hw_num[die][n / 32] |= BIT(n & 31);
|
2021-06-05 20:05:17 +00:00
|
|
|
break;
|
|
|
|
default:
|
2022-03-24 07:09:44 +00:00
|
|
|
trace_hw_num[die][n / 32] &= ~(BIT(n & 31));
|
2021-06-05 20:05:17 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
printf("HV: not handling AIC event type: 0x%02x num: %u\n", type, num);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-03-24 07:09:44 +00:00
|
|
|
if (!aic) {
|
2021-08-23 08:01:33 +00:00
|
|
|
printf("HV: AIC not initialized\n");
|
|
|
|
return false;
|
2021-06-05 20:05:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool hooked = false;
|
|
|
|
|
2022-03-24 07:09:44 +00:00
|
|
|
if (aic && !hooked) {
|
|
|
|
hv_map_hook(aic->base, trace_aic_event, aic->regs.reg_size);
|
2021-06-05 20:05:17 +00:00
|
|
|
hooked = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|