Commit d179ae1f authored by Rafael J. Wysocki's avatar Rafael J. Wysocki
Browse files

ACPI: bus: Split _OSC error processing out of acpi_run_osc()



Split a function for processing _OSC errors called acpi_osc_error_check()
out of acpi_run_osc() to facilitate subsequent changes.

No intentional functional impact.

Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: default avatarJonathan Cameron <jonathan.cameron@huawei.com>
Link: https://patch.msgid.link/6135328.MhkbZ0Pkbq@rafael.j.wysocki
parent 7d703df7
Loading
Loading
Loading
Loading
+53 −42
Original line number Diff line number Diff line
@@ -237,28 +237,14 @@ static int acpi_eval_osc(acpi_handle handle, guid_t *guid, int rev,
	return 0;
}

acpi_status acpi_run_osc(acpi_handle handle, struct acpi_osc_context *context)
static bool acpi_osc_error_check(acpi_handle handle, guid_t *guid, int rev,
				 struct acpi_buffer *cap, u32 *retbuf)
{
	u32 errors, *capbuf = context->cap.pointer;
	union acpi_object in_params[4], *out_obj;
	struct acpi_buffer output;
	acpi_status status = AE_OK;
	guid_t guid;
	int ret;

	if (!context || !context->cap.pointer ||
	    context->cap.length < 2 * sizeof(32) ||
	    guid_parse(context->uuid_str, &guid))
		return AE_BAD_PARAMETER;

	ret = acpi_eval_osc(handle, &guid, context->rev, &context->cap,
			    in_params, &output);
	if (ret)
		return AE_ERROR;

	out_obj = output.pointer;
	/* Only take defined error bits into account. */
	errors = *((u32 *)out_obj->buffer.pointer) & OSC_ERROR_MASK;
	u32 errors = retbuf[OSC_QUERY_DWORD] & OSC_ERROR_MASK;
	u32 *capbuf = cap->pointer;
	bool fail;

	/*
	 * If OSC_QUERY_ENABLE is set, ignore the "capabilities masked"
	 * bit because it merely means that some features have not been
@@ -267,41 +253,66 @@ acpi_status acpi_run_osc(acpi_handle handle, struct acpi_osc_context *context)
	if (capbuf[OSC_QUERY_DWORD] & OSC_QUERY_ENABLE)
		errors &= ~OSC_CAPABILITIES_MASK_ERROR;

	if (errors) {
	if (!errors)
		return false;

	acpi_dump_osc_data(handle, guid, rev, cap);
	/*
		 * As a rule, fail only if OSC_QUERY_ENABLE is set because
		 * otherwise the acknowledged features need to be controlled.
	 * As a rule, fail only if OSC_QUERY_ENABLE is set because otherwise the
	 * acknowledged features need to be controlled.
	 */
		bool fail = !!(capbuf[OSC_QUERY_DWORD] & OSC_QUERY_ENABLE);
	fail = !!(capbuf[OSC_QUERY_DWORD] & OSC_QUERY_ENABLE);

	if (errors & OSC_REQUEST_ERROR)
		acpi_handle_debug(handle, "_OSC: request failed\n");

		acpi_dump_osc_data(handle, &guid, context->rev, &context->cap);
	if (errors & OSC_INVALID_UUID_ERROR) {
			acpi_handle_debug(handle, "_OSC: invalid UUID");
		acpi_handle_debug(handle, "_OSC: invalid UUID\n");
		/*
			 * Always fail if this bit is set because it means that
			 * the request could not be processed.
		 * Always fail if this bit is set because it means that the
		 * request could not be processed.
		 */
		fail = true;
			goto out_kfree;
	}
		if (errors & OSC_REQUEST_ERROR)
			acpi_handle_debug(handle, "_OSC: request failed");

	if (errors & OSC_INVALID_REVISION_ERROR)
			acpi_handle_debug(handle, "_OSC: invalid revision");
		acpi_handle_debug(handle, "_OSC: invalid revision\n");

	if (errors & OSC_CAPABILITIES_MASK_ERROR)
			acpi_handle_debug(handle, "_OSC: capability bits masked");
		acpi_handle_debug(handle, "_OSC: capability bits masked\n");

	return fail;
}

		if (fail) {
acpi_status acpi_run_osc(acpi_handle handle, struct acpi_osc_context *context)
{
	union acpi_object in_params[4], *out_obj;
	struct acpi_buffer output;
	acpi_status status = AE_OK;
	guid_t guid;
	u32 *retbuf;
	int ret;

	if (!context || !context->cap.pointer ||
	    context->cap.length < 2 * sizeof(32) ||
	    guid_parse(context->uuid_str, &guid))
		return AE_BAD_PARAMETER;

	ret = acpi_eval_osc(handle, &guid, context->rev, &context->cap,
			    in_params, &output);
	if (ret)
		return AE_ERROR;

	out_obj = output.pointer;
	retbuf = (u32 *)out_obj->buffer.pointer;

	if (acpi_osc_error_check(handle, &guid, context->rev, &context->cap, retbuf)) {
		status = AE_ERROR;
		goto out_kfree;
	}
	}

	context->ret.length = out_obj->buffer.length;
	context->ret.pointer = kmemdup(out_obj->buffer.pointer,
				       context->ret.length, GFP_KERNEL);
	context->ret.pointer = kmemdup(retbuf, context->ret.length, GFP_KERNEL);
	if (!context->ret.pointer) {
		status =  AE_NO_MEMORY;
		goto out_kfree;