^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Module Name: exserial - field_unit support for serial address spaces
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2000 - 2020, Intel Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *****************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <acpi/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include "accommon.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "acdispat.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include "acinterp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "amlcode.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define _COMPONENT ACPI_EXECUTER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) ACPI_MODULE_NAME("exserial")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * FUNCTION: acpi_ex_read_gpio
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * PARAMETERS: obj_desc - The named field to read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * buffer - Where the return data is returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * DESCRIPTION: Read from a named field that references a Generic Serial Bus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * field
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) acpi_status acpi_ex_read_gpio(union acpi_operand_object *obj_desc, void *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) ACPI_FUNCTION_TRACE_PTR(ex_read_gpio, obj_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * For GPIO (general_purpose_io), the Address will be the bit offset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * from the previous Connection() operator, making it effectively a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * pin number index. The bit_length is the length of the field, which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * is thus the number of pins.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) "GPIO FieldRead [FROM]: Pin %u Bits %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) obj_desc->field.pin_number_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) obj_desc->field.bit_length));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) /* Lock entire transaction if requested */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) acpi_ex_acquire_global_lock(obj_desc->common_field.field_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) /* Perform the read */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) status = acpi_ex_access_region(obj_desc, 0, (u64 *)buffer, ACPI_READ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) acpi_ex_release_global_lock(obj_desc->common_field.field_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * FUNCTION: acpi_ex_write_gpio
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * PARAMETERS: source_desc - Contains data to write. Expect to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * an Integer object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * obj_desc - The named field
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * result_desc - Where the return value is returned, if any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * DESCRIPTION: Write to a named field that references a General Purpose I/O
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) acpi_ex_write_gpio(union acpi_operand_object *source_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) union acpi_operand_object *obj_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) union acpi_operand_object **return_buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) void *buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) ACPI_FUNCTION_TRACE_PTR(ex_write_gpio, obj_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * For GPIO (general_purpose_io), we will bypass the entire field
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * mechanism and handoff the bit address and bit width directly to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * the handler. The Address will be the bit offset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * from the previous Connection() operator, making it effectively a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * pin number index. The bit_length is the length of the field, which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * is thus the number of pins.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) if (source_desc->common.type != ACPI_TYPE_INTEGER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) "GPIO FieldWrite [FROM]: (%s:%X), Value %.8X [TO]: Pin %u Bits %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) acpi_ut_get_type_name(source_desc->common.type),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) source_desc->common.type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) (u32)source_desc->integer.value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) obj_desc->field.pin_number_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) obj_desc->field.bit_length));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) buffer = &source_desc->integer.value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) /* Lock entire transaction if requested */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) acpi_ex_acquire_global_lock(obj_desc->common_field.field_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) /* Perform the write */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) status = acpi_ex_access_region(obj_desc, 0, (u64 *)buffer, ACPI_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) acpi_ex_release_global_lock(obj_desc->common_field.field_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) * FUNCTION: acpi_ex_read_serial_bus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) * PARAMETERS: obj_desc - The named field to read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) * return_buffer - Where the return value is returned, if any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) * DESCRIPTION: Read from a named field that references a serial bus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * (SMBus, IPMI, or GSBus).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) acpi_ex_read_serial_bus(union acpi_operand_object *obj_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) union acpi_operand_object **return_buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) u32 buffer_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) union acpi_operand_object *buffer_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) u32 function;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) u16 accessor_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) ACPI_FUNCTION_TRACE_PTR(ex_read_serial_bus, obj_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) * This is an SMBus, GSBus or IPMI read. We must create a buffer to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) * hold the data and then directly access the region handler.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) * Note: SMBus and GSBus protocol value is passed in upper 16-bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) * of Function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) * Common buffer format:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) * Status; (Byte 0 of the data buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) * Length; (Byte 1 of the data buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) * Data[x-1]: (Bytes 2-x of the arbitrary length data buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) switch (obj_desc->field.region_obj->region.space_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) case ACPI_ADR_SPACE_SMBUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) buffer_length = ACPI_SMBUS_BUFFER_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) function = ACPI_READ | (obj_desc->field.attribute << 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) case ACPI_ADR_SPACE_IPMI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) buffer_length = ACPI_IPMI_BUFFER_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) function = ACPI_READ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) case ACPI_ADR_SPACE_GSBUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) accessor_type = obj_desc->field.attribute;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) if (accessor_type == AML_FIELD_ATTRIB_RAW_PROCESS_BYTES) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) ACPI_ERROR((AE_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) "Invalid direct read using bidirectional write-then-read protocol"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) return_ACPI_STATUS(AE_AML_PROTOCOL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) acpi_ex_get_protocol_buffer_length(accessor_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) &buffer_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) ACPI_ERROR((AE_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) "Invalid protocol ID for GSBus: 0x%4.4X",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) accessor_type));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) /* Add header length to get the full size of the buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) buffer_length += ACPI_SERIAL_HEADER_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) function = ACPI_READ | (accessor_type << 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) return_ACPI_STATUS(AE_AML_INVALID_SPACE_ID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) /* Create the local transfer buffer that is returned to the caller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) buffer_desc = acpi_ut_create_buffer_object(buffer_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) if (!buffer_desc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) return_ACPI_STATUS(AE_NO_MEMORY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) /* Lock entire transaction if requested */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) acpi_ex_acquire_global_lock(obj_desc->common_field.field_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) /* Call the region handler for the write-then-read */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) status = acpi_ex_access_region(obj_desc, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) ACPI_CAST_PTR(u64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) buffer_desc->buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) pointer), function);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) acpi_ex_release_global_lock(obj_desc->common_field.field_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) *return_buffer = buffer_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) * FUNCTION: acpi_ex_write_serial_bus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) * PARAMETERS: source_desc - Contains data to write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) * obj_desc - The named field
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) * return_buffer - Where the return value is returned, if any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) * DESCRIPTION: Write to a named field that references a serial bus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) * (SMBus, IPMI, GSBus).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) acpi_ex_write_serial_bus(union acpi_operand_object *source_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) union acpi_operand_object *obj_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) union acpi_operand_object **return_buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) u32 buffer_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) u32 data_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) void *buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) union acpi_operand_object *buffer_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) u32 function;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) u16 accessor_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) ACPI_FUNCTION_TRACE_PTR(ex_write_serial_bus, obj_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) * This is an SMBus, GSBus or IPMI write. We will bypass the entire
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) * field mechanism and handoff the buffer directly to the handler.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) * For these address spaces, the buffer is bidirectional; on a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) * write, return data is returned in the same buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) * Source must be a buffer of sufficient size, these are fixed size:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) * ACPI_SMBUS_BUFFER_SIZE, or ACPI_IPMI_BUFFER_SIZE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) * Note: SMBus and GSBus protocol type is passed in upper 16-bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) * of Function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) * Common buffer format:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) * Status; (Byte 0 of the data buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) * Length; (Byte 1 of the data buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) * Data[x-1]: (Bytes 2-x of the arbitrary length data buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) if (source_desc->common.type != ACPI_TYPE_BUFFER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) ACPI_ERROR((AE_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) "SMBus/IPMI/GenericSerialBus write requires "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) "Buffer, found type %s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) acpi_ut_get_object_type_name(source_desc)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) switch (obj_desc->field.region_obj->region.space_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) case ACPI_ADR_SPACE_SMBUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) buffer_length = ACPI_SMBUS_BUFFER_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) function = ACPI_WRITE | (obj_desc->field.attribute << 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) case ACPI_ADR_SPACE_IPMI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) buffer_length = ACPI_IPMI_BUFFER_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) function = ACPI_WRITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) case ACPI_ADR_SPACE_GSBUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) accessor_type = obj_desc->field.attribute;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) acpi_ex_get_protocol_buffer_length(accessor_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) &buffer_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) ACPI_ERROR((AE_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) "Invalid protocol ID for GSBus: 0x%4.4X",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) accessor_type));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) /* Add header length to get the full size of the buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) buffer_length += ACPI_SERIAL_HEADER_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) function = ACPI_WRITE | (accessor_type << 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) return_ACPI_STATUS(AE_AML_INVALID_SPACE_ID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) /* Create the transfer/bidirectional/return buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) buffer_desc = acpi_ut_create_buffer_object(buffer_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) if (!buffer_desc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) return_ACPI_STATUS(AE_NO_MEMORY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) /* Copy the input buffer data to the transfer buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) buffer = buffer_desc->buffer.pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) data_length = (buffer_length < source_desc->buffer.length ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) buffer_length : source_desc->buffer.length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) memcpy(buffer, source_desc->buffer.pointer, data_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) /* Lock entire transaction if requested */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) acpi_ex_acquire_global_lock(obj_desc->common_field.field_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) * Perform the write (returns status and perhaps data in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) * same buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) status = acpi_ex_access_region(obj_desc, 0, (u64 *)buffer, function);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) acpi_ex_release_global_lock(obj_desc->common_field.field_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) *return_buffer = buffer_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) }