Skip to content

Commit f99b89e

Browse files
acpibobrafaeljw
authored andcommitted
ACPICA: Update for generic_serial_bus and attrib_raw_process_bytes protocol
Cleanup for this write-then-read protocol. The ACPI specification is rather unclear for the entire generic_serial_bus, but this change works correctly on the Surface 3. Reported-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Bob Moore <robert.moore@intel.com> Signed-off-by: Erik Schmauss <erik.schmauss@intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 17b57b1 commit f99b89e

3 files changed

Lines changed: 44 additions & 12 deletions

File tree

‎drivers/acpi/acpica/exfield.c‎

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,19 @@ acpi_ex_get_serial_access_length(u32 accessor_type, u32 access_length)
6060

6161
case AML_FIELD_ATTRIB_MULTIBYTE:
6262
case AML_FIELD_ATTRIB_RAW_BYTES:
63-
case AML_FIELD_ATTRIB_RAW_PROCESS:
6463

6564
length = access_length;
6665
break;
6766

67+
case AML_FIELD_ATTRIB_RAW_PROCESS:
68+
/*
69+
* Worst case bidirectional buffer size. This ignores the
70+
* access_length argument to access_as because it is not needed.
71+
* August 2018.
72+
*/
73+
length = ACPI_MAX_GSBUS_BUFFER_SIZE;
74+
break;
75+
6876
case AML_FIELD_ATTRIB_BLOCK:
6977
case AML_FIELD_ATTRIB_BLOCK_CALL:
7078
default:
@@ -147,6 +155,13 @@ acpi_ex_read_data_from_field(struct acpi_walk_state *walk_state,
147155
} else if (obj_desc->field.region_obj->region.space_id ==
148156
ACPI_ADR_SPACE_GSBUS) {
149157
accessor_type = obj_desc->field.attribute;
158+
if (accessor_type == AML_FIELD_ATTRIB_RAW_PROCESS) {
159+
ACPI_ERROR((AE_INFO,
160+
"Invalid direct read using bidirectional write-then-read protocol"));
161+
162+
return_ACPI_STATUS(AE_AML_PROTOCOL);
163+
}
164+
150165
length =
151166
acpi_ex_get_serial_access_length(accessor_type,
152167
obj_desc->field.
@@ -305,6 +320,7 @@ acpi_ex_write_data_to_field(union acpi_operand_object *source_desc,
305320
{
306321
acpi_status status;
307322
u32 length;
323+
u32 data_length;
308324
void *buffer;
309325
union acpi_operand_object *buffer_desc;
310326
u32 function;
@@ -361,6 +377,7 @@ acpi_ex_write_data_to_field(union acpi_operand_object *source_desc,
361377
if (obj_desc->field.region_obj->region.space_id ==
362378
ACPI_ADR_SPACE_SMBUS) {
363379
length = ACPI_SMBUS_BUFFER_SIZE;
380+
data_length = length;
364381
function =
365382
ACPI_WRITE | (obj_desc->field.attribute << 16);
366383
} else if (obj_desc->field.region_obj->region.space_id ==
@@ -372,38 +389,47 @@ acpi_ex_write_data_to_field(union acpi_operand_object *source_desc,
372389
access_length);
373390

374391
/*
375-
* Add additional 2 bytes for the generic_serial_bus data buffer:
376-
*
392+
* Buffer format for Generic Serial Bus protocols:
377393
* Status; (Byte 0 of the data buffer)
378394
* Length; (Byte 1 of the data buffer)
379395
* Data[x-1]: (Bytes 2-x of the arbitrary length data buffer)
380396
*/
381-
length += 2;
397+
data_length = source_desc->buffer.pointer[1]; /* Data length is 2nd byte */
398+
if (!data_length) {
399+
ACPI_ERROR((AE_INFO,
400+
"Invalid zero data length in transfer buffer"));
401+
402+
return_ACPI_STATUS(AE_AML_BUFFER_LENGTH);
403+
}
404+
382405
function = ACPI_WRITE | (accessor_type << 16);
383406
} else { /* IPMI */
384407

385408
length = ACPI_IPMI_BUFFER_SIZE;
409+
data_length = length;
386410
function = ACPI_WRITE;
387411
}
388412

389-
if (source_desc->buffer.length < length) {
413+
if (source_desc->buffer.length < data_length) {
390414
ACPI_ERROR((AE_INFO,
391415
"SMBus/IPMI/GenericSerialBus write requires "
392-
"Buffer of length %u, found length %u",
393-
length, source_desc->buffer.length));
416+
"Buffer data length %u, found buffer length %u",
417+
data_length, source_desc->buffer.length));
394418

395419
return_ACPI_STATUS(AE_AML_BUFFER_LIMIT);
396420
}
397421

398-
/* Create the bi-directional buffer */
422+
/* Create the transfer/bidirectional buffer */
399423

400424
buffer_desc = acpi_ut_create_buffer_object(length);
401425
if (!buffer_desc) {
402426
return_ACPI_STATUS(AE_NO_MEMORY);
403427
}
404428

429+
/* Copy the input buffer data to the transfer buffer */
430+
405431
buffer = buffer_desc->buffer.pointer;
406-
memcpy(buffer, source_desc->buffer.pointer, length);
432+
memcpy(buffer, source_desc->buffer.pointer, data_length);
407433

408434
/* Lock entire transaction if requested */
409435

‎include/acpi/acconfig.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,9 @@
176176
/* SMBus, GSBus and IPMI bidirectional buffer size */
177177

178178
#define ACPI_SMBUS_BUFFER_SIZE 34
179-
#define ACPI_GSBUS_BUFFER_SIZE 34
180179
#define ACPI_IPMI_BUFFER_SIZE 66
180+
#define ACPI_GSBUS_BUFFER_SIZE 34 /* Not clear if this is needed */
181+
#define ACPI_MAX_GSBUS_BUFFER_SIZE 255 /* Worst-case bidirectional buffer */
181182

182183
/* _sx_d and _sx_w control methods */
183184

‎include/acpi/acexcep.h‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,10 @@ struct acpi_exception_info {
171171
#define AE_AML_LOOP_TIMEOUT EXCEP_AML (0x0021)
172172
#define AE_AML_UNINITIALIZED_NODE EXCEP_AML (0x0022)
173173
#define AE_AML_TARGET_TYPE EXCEP_AML (0x0023)
174+
#define AE_AML_PROTOCOL EXCEP_AML (0x0024)
175+
#define AE_AML_BUFFER_LENGTH EXCEP_AML (0x0025)
174176

175-
#define AE_CODE_AML_MAX 0x0023
177+
#define AE_CODE_AML_MAX 0x0025
176178

177179
/*
178180
* Internal exceptions used for control
@@ -347,7 +349,10 @@ static const struct acpi_exception_info acpi_gbl_exception_names_aml[] = {
347349
EXCEP_TXT("AE_AML_UNINITIALIZED_NODE",
348350
"A namespace node is uninitialized or unresolved"),
349351
EXCEP_TXT("AE_AML_TARGET_TYPE",
350-
"A target operand of an incorrect type was encountered")
352+
"A target operand of an incorrect type was encountered"),
353+
EXCEP_TXT("AE_AML_PROTOCOL", "Violation of a fixed ACPI protocol"),
354+
EXCEP_TXT("AE_AML_BUFFER_LENGTH",
355+
"The length of the buffer is invalid/incorrect")
351356
};
352357

353358
static const struct acpi_exception_info acpi_gbl_exception_names_ctrl[] = {

0 commit comments

Comments
 (0)