| 1 |
|
| 2 |
|
| 3 |
#include <console/console.h> |
| 4 |
#include <intelblocks/cse.h> |
| 5 |
#include <timestamp.h> |
| 6 |
|
| 7 |
#define MSEC_TO_USEC(x) ((s64)x * 1000) |
| 8 |
|
| 9 |
enum cb_err cse_get_boot_performance_data(struct cse_boot_perf_rsp *boot_perf_rsp) |
| 10 |
{ |
| 11 |
struct cse_boot_perf_req { |
| 12 |
struct mkhi_hdr hdr; |
| 13 |
uint32_t reserved; |
| 14 |
} __packed; |
| 15 |
|
| 16 |
struct cse_boot_perf_req req = { |
| 17 |
.hdr.group_id = MKHI_GROUP_ID_BUP_COMMON, |
| 18 |
.hdr.command = MKHI_BUP_COMMON_GET_BOOT_PERF_DATA, |
| 19 |
.reserved = 0, |
| 20 |
}; |
| 21 |
|
| 22 |
size_t resp_size = sizeof(struct cse_boot_perf_rsp); |
| 23 |
|
| 24 |
if (heci_send_receive(&req, sizeof(req), boot_perf_rsp, &resp_size, |
| 25 |
HECI_MKHI_ADDR)) { |
| 26 |
printk(BIOS_ERR, "cse: Could not get boot performance data\n"); |
| 27 |
return CB_ERR; |
| 28 |
} |
| 29 |
|
| 30 |
if (boot_perf_rsp->hdr.result) { |
| 31 |
printk(BIOS_ERR, "cse: Get boot performance data resp failed: %d\n", |
| 32 |
boot_perf_rsp->hdr.result); |
| 33 |
return CB_ERR; |
| 34 |
} |
| 35 |
|
| 36 |
return CB_SUCCESS; |
| 37 |
} |
| 38 |
|
| 39 |
static void process_cse_telemetry_data(void) |
| 40 |
{ |
| 41 |
struct cse_boot_perf_rsp cse_perf_data; |
| 42 |
s64 ts[NUM_CSE_BOOT_PERF_DATA] = {0}; |
| 43 |
s64 current_time; |
| 44 |
int zero_point_idx = 0; |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
if (cse_get_boot_performance_data(&cse_perf_data) != CB_SUCCESS) |
| 56 |
return; |
| 57 |
|
| 58 |
current_time = timestamp_get(); |
| 59 |
|
| 60 |
for (unsigned int i = 0; i < NUM_CSE_BOOT_PERF_DATA; i++) { |
| 61 |
if (cse_perf_data.timestamp[i] == 0xffffffff) { |
| 62 |
printk(BIOS_ERR, "%s: CSME timestamps invalid\n", __func__); |
| 63 |
return; |
| 64 |
} |
| 65 |
|
| 66 |
ts[i] = (s64)MSEC_TO_USEC(cse_perf_data.timestamp[i]) * |
| 67 |
timestamp_tick_freq_mhz(); |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
for (unsigned int i = 0; i < NUM_CSE_BOOT_PERF_DATA; i++) { |
| 72 |
if (cse_perf_data.timestamp[i] != 0) { |
| 73 |
zero_point_idx = i; |
| 74 |
break; |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
for (unsigned int i = zero_point_idx + 1; i < NUM_CSE_BOOT_PERF_DATA; i++) { |
| 80 |
if (ts[i] && ts[i] < ts[zero_point_idx]) { |
| 81 |
printk(BIOS_ERR, "%s: CSME timestamps invalid," |
| 82 |
" wraparound detected\n", __func__); |
| 83 |
return; |
| 84 |
} |
| 85 |
|
| 86 |
if (ts[i]) |
| 87 |
ts[i] -= ts[zero_point_idx]; |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
soc_cbmem_inject_telemetry_data(ts, current_time); |
| 92 |
} |
| 93 |
|
| 94 |
void cse_get_telemetry_data(void) |
| 95 |
{ |
| 96 |
|
| 97 |
if (!is_cse_enabled()) { |
| 98 |
printk(BIOS_DEBUG, "CSE is disabled, not sending `Get Boot Perf` message\n"); |
| 99 |
return; |
| 100 |
} |
| 101 |
|
| 102 |
process_cse_telemetry_data(); |
| 103 |
} |