Commit b4761029 authored by Zaid Alali's avatar Zaid Alali Committed by Rafael J. Wysocki
Browse files

ACPI: APEI: EINJ: Enable EINJv2 error injections



Enable injection using EINJv2 mode of operation.

[Tony: Mostly Zaid's original code. I just changed how the error ID
and syndrome bits are implemented. Also swapped out some camelcase
variable names]

Co-developed-by: default avatarTony Luck <tony.luck@intel.com>
Signed-off-by: default avatarTony Luck <tony.luck@intel.com>
Signed-off-by: default avatarZaid Alali <zaidal@os.amperecomputing.com>
Link: https://patch.msgid.link/20250617193026.637510-7-zaidal@os.amperecomputing.com


Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent 90711f7b
Loading
Loading
Loading
Loading
+47 −11
Original line number Diff line number Diff line
@@ -87,6 +87,7 @@ enum {
	SETWA_FLAGS_APICID = 1,
	SETWA_FLAGS_MEM = 2,
	SETWA_FLAGS_PCIE_SBDF = 4,
	SETWA_FLAGS_EINJV2 = 8,
};

/*
@@ -181,6 +182,7 @@ bool einj_initialized __ro_after_init;

static void __iomem *einj_param;
static u32 v5param_size;
static bool is_v2;

static void einj_exec_ctx_init(struct apei_exec_context *ctx)
{
@@ -507,12 +509,20 @@ static int __einj_error_trigger(u64 trigger_paddr, u32 type,
	return rc;
}

static bool is_end_of_list(u8 *val)
{
	for (int i = 0; i < COMPONENT_LEN; ++i) {
		if (val[i] != 0xFF)
			return false;
	}
	return true;
}
static int __einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2,
			       u64 param3, u64 param4)
{
	struct apei_exec_context ctx;
	u64 val, trigger_paddr, timeout = FIRMWARE_TIMEOUT;
	int rc;
	int i, rc;

	einj_exec_ctx_init(&ctx);

@@ -521,10 +531,10 @@ static int __einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2,
		return rc;
	apei_exec_ctx_set_input(&ctx, type);
	if (acpi5) {
		struct set_error_type_with_address *v5param, v5_struct;
		struct set_error_type_with_address *v5param;

		v5param = &v5_struct;
		memcpy_fromio(v5param, einj_param, sizeof(*v5param));
		v5param = kmalloc(v5param_size, GFP_KERNEL);
		memcpy_fromio(v5param, einj_param, v5param_size);
		v5param->type = type;
		if (type & ACPI5_VENDOR_BIT) {
			switch (vendor_flags) {
@@ -544,8 +554,21 @@ static int __einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2,
			v5param->flags = flags;
			v5param->memory_address = param1;
			v5param->memory_address_range = param2;

			if (is_v2) {
				for (i = 0; i < max_nr_components; i++) {
					if (is_end_of_list(syndrome_data[i].comp_id.acpi_id))
						break;
					v5param->einjv2_struct.component_arr[i].comp_id =
						syndrome_data[i].comp_id;
					v5param->einjv2_struct.component_arr[i].comp_synd =
						syndrome_data[i].comp_synd;
				}
				v5param->einjv2_struct.component_arr_count = i;
			} else {
				v5param->apicid = param3;
				v5param->pcie_sbdf = param4;
			}
		} else {
			switch (type) {
			case ACPI_EINJ_PROCESSOR_CORRECTABLE:
@@ -569,7 +592,8 @@ static int __einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2,
				break;
			}
		}
		memcpy_toio(einj_param, v5param, sizeof(*v5param));
		memcpy_toio(einj_param, v5param, v5param_size);
		kfree(v5param);
	} else {
		rc = apei_exec_run(&ctx, ACPI_EINJ_SET_ERROR_TYPE);
		if (rc)
@@ -631,10 +655,15 @@ int einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2, u64 param3,
	u64 base_addr, size;

	/* If user manually set "flags", make sure it is legal */
	if (flags && (flags &
		~(SETWA_FLAGS_APICID|SETWA_FLAGS_MEM|SETWA_FLAGS_PCIE_SBDF)))
	if (flags && (flags & ~(SETWA_FLAGS_APICID | SETWA_FLAGS_MEM |
		      SETWA_FLAGS_PCIE_SBDF | SETWA_FLAGS_EINJV2)))
		return -EINVAL;

	/* check if type is a valid EINJv2 error type */
	if (is_v2) {
		if (!(type & available_error_type_v2))
			return -EINVAL;
	}
	/*
	 * We need extra sanity checks for memory errors.
	 * Other types leap directly to injection.
@@ -743,7 +772,7 @@ static int available_error_type_show(struct seq_file *m, void *v)
		if (available_error_type & einj_error_type_string[pos].mask)
			seq_printf(m, "0x%08x\t%s\n", einj_error_type_string[pos].mask,
				   einj_error_type_string[pos].str);
	if (available_error_type & ACPI65_EINJV2_SUPP) {
	if ((available_error_type & ACPI65_EINJV2_SUPP) && einj_v2_enabled) {
		for (int pos = 0; pos < ARRAY_SIZE(einjv2_error_type_string); pos++) {
			if (available_error_type_v2 & einjv2_error_type_string[pos].mask)
				seq_printf(m, "V2_0x%08x\t%s\n", einjv2_error_type_string[pos].mask,
@@ -785,7 +814,7 @@ int einj_validate_error_type(u64 type)
	if (tval & (tval - 1))
		return -EINVAL;
	if (!vendor)
		if (!(type & available_error_type))
		if (!(type & (available_error_type | available_error_type_v2)))
			return -EINVAL;

	return 0;
@@ -804,9 +833,11 @@ static ssize_t error_type_set(struct file *file, const char __user *buf,
	if (strncmp(einj_buf, "V2_", 3) == 0) {
		if (!sscanf(einj_buf, "V2_%llx", &val))
			return -EINVAL;
		is_v2 = true;
	} else {
		if (!sscanf(einj_buf, "%llx", &val))
			return -EINVAL;
		is_v2 = false;
	}

	rc = einj_validate_error_type(val);
@@ -828,6 +859,11 @@ static int error_inject_set(void *data, u64 val)
	if (!error_type)
		return -EINVAL;

	if (is_v2)
		error_flags |= SETWA_FLAGS_EINJV2;
	else
		error_flags &= ~SETWA_FLAGS_EINJV2;

	return einj_error_inject(error_type, error_flags, error_param1, error_param2,
		error_param3, error_param4);
}