-/*******************************************************************************
- *
- * FUNCTION: acpi_ex_get_buffer_datum
- *
- * PARAMETERS: Datum - Where the Datum is returned
- * Buffer - Raw field buffer
- * buffer_length - Entire length (used for big-endian only)
- * byte_granularity - 1/2/4/8 Granularity of the field
- * (aka Datum Size)
- * buffer_offset - Datum offset into the buffer
- *
- * RETURN: none
- *
- * DESCRIPTION: Get a datum from the buffer according to the buffer field
- * byte granularity
- *
- ******************************************************************************/
-
-void
-acpi_ex_get_buffer_datum (
- acpi_integer *datum,
- void *buffer,
- u32 buffer_length,
- u32 byte_granularity,
- u32 buffer_offset)
-{
- u32 index;
-
-
- ACPI_FUNCTION_TRACE_U32 ("ex_get_buffer_datum", byte_granularity);
-
-
- /* Get proper index into buffer (handles big/little endian) */
-
- index = ACPI_BUFFER_INDEX (buffer_length, buffer_offset, byte_granularity);
-
- /* Move the requested number of bytes */
-
- switch (byte_granularity) {
- case ACPI_FIELD_BYTE_GRANULARITY:
-
- *datum = ((u8 *) buffer) [index];
- break;
-
- case ACPI_FIELD_WORD_GRANULARITY:
-
- ACPI_MOVE_16_TO_64 (datum, &(((u16 *) buffer) [index]));
- break;
-
- case ACPI_FIELD_DWORD_GRANULARITY:
-
- ACPI_MOVE_32_TO_64 (datum, &(((u32 *) buffer) [index]));
- break;
-
- case ACPI_FIELD_QWORD_GRANULARITY:
-
- ACPI_MOVE_64_TO_64 (datum, &(((u64 *) buffer) [index]));
- break;
-
- default:
- /* Should not get here */
- break;
- }
-
- return_VOID;
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION: acpi_ex_set_buffer_datum
- *
- * PARAMETERS: merged_datum - Value to store
- * Buffer - Receiving buffer
- * buffer_length - Entire length (used for big-endian only)
- * byte_granularity - 1/2/4/8 Granularity of the field
- * (aka Datum Size)
- * buffer_offset - Datum offset into the buffer
- *
- * RETURN: none
- *
- * DESCRIPTION: Store the merged datum to the buffer according to the
- * byte granularity
- *
- ******************************************************************************/
-
-void
-acpi_ex_set_buffer_datum (
- acpi_integer merged_datum,
- void *buffer,
- u32 buffer_length,
- u32 byte_granularity,
- u32 buffer_offset)
-{
- u32 index;
-
-
- ACPI_FUNCTION_TRACE_U32 ("ex_set_buffer_datum", byte_granularity);
-
-
- /* Get proper index into buffer (handles big/little endian) */
-
- index = ACPI_BUFFER_INDEX (buffer_length, buffer_offset, byte_granularity);
-
- /* Move the requested number of bytes */
-
- switch (byte_granularity) {
- case ACPI_FIELD_BYTE_GRANULARITY:
-
- ((u8 *) buffer) [index] = (u8) merged_datum;
- break;
-
- case ACPI_FIELD_WORD_GRANULARITY:
-
- ACPI_MOVE_64_TO_16 (&(((u16 *) buffer)[index]), &merged_datum);
- break;
-
- case ACPI_FIELD_DWORD_GRANULARITY:
-
- ACPI_MOVE_64_TO_32 (&(((u32 *) buffer)[index]), &merged_datum);
- break;
-
- case ACPI_FIELD_QWORD_GRANULARITY:
-
- ACPI_MOVE_64_TO_64 (&(((u64 *) buffer)[index]), &merged_datum);
- break;
-
- default:
- /* Should not get here */
- break;
- }
-
- return_VOID;
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION: acpi_ex_common_buffer_setup
- *
- * PARAMETERS: obj_desc - Field object
- * buffer_length - Length of caller's buffer
- * datum_count - Where the datum_count is returned
- *
- * RETURN: Status, datum_count
- *
- * DESCRIPTION: Common code to validate the incoming buffer size and compute
- * the number of field "datums" that must be read or written.
- * A "datum" is the smallest unit that can be read or written
- * to the field, it is either 1,2,4, or 8 bytes.
- *
- ******************************************************************************/
-
-acpi_status
-acpi_ex_common_buffer_setup (
- union acpi_operand_object *obj_desc,
- u32 buffer_length,
- u32 *datum_count)
-{
- u32 byte_field_length;
- u32 actual_byte_field_length;
-
-
- ACPI_FUNCTION_TRACE ("ex_common_buffer_setup");
-
-
- /*
- * Incoming buffer must be at least as long as the field, we do not
- * allow "partial" field reads/writes. We do not care if the buffer is
- * larger than the field, this typically happens when an integer is
- * read/written to a field that is actually smaller than an integer.
- */
- byte_field_length = ACPI_ROUND_BITS_UP_TO_BYTES (
- obj_desc->common_field.bit_length);
- if (byte_field_length > buffer_length) {
- ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
- "Field size %X (bytes) is too large for buffer (%X)\n",
- byte_field_length, buffer_length));
-
- return_ACPI_STATUS (AE_BUFFER_OVERFLOW);
- }
-
- /*
- * Create "actual" field byte count (minimum number of bytes that
- * must be read), then convert to datum count (minimum number
- * of datum-sized units that must be read)
- */
- actual_byte_field_length = ACPI_ROUND_BITS_UP_TO_BYTES (
- obj_desc->common_field.start_field_bit_offset +
- obj_desc->common_field.bit_length);
-
-
- *datum_count = ACPI_ROUND_UP_TO (actual_byte_field_length,
- obj_desc->common_field.access_byte_width);
-
- ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
- "buffer_bytes %X, actual_bytes %X, Datums %X, byte_gran %X\n",
- byte_field_length, actual_byte_field_length,
- *datum_count, obj_desc->common_field.access_byte_width));
-
- return_ACPI_STATUS (AE_OK);
-}
-
-