+/*******************************************************************************
+ *
+ * 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);
+}
+
+