📄 exfldio.c
字号:
return_ACPI_STATUS (Status); } MergedValue |= (CurrentValue & ~Mask); } break; case AML_FIELD_UPDATE_WRITE_AS_ONES: /* Set positions outside the field to all ones */ MergedValue |= ~Mask; break; case AML_FIELD_UPDATE_WRITE_AS_ZEROS: /* Set positions outside the field to all zeros */ MergedValue &= Mask; break; default: ACPI_ERROR ((AE_INFO, "Unknown UpdateRule value: %X", (ObjDesc->CommonField.FieldFlags & AML_FIELD_UPDATE_RULE_MASK))); return_ACPI_STATUS (AE_AML_OPERAND_VALUE); } } ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, "Mask %8.8X%8.8X, DatumOffset %X, Width %X, Value %8.8X%8.8X, MergedValue %8.8X%8.8X\n", ACPI_FORMAT_UINT64 (Mask), FieldDatumByteOffset, ObjDesc->CommonField.AccessByteWidth, ACPI_FORMAT_UINT64 (FieldValue), ACPI_FORMAT_UINT64 (MergedValue))); /* Write the merged value */ Status = AcpiExFieldDatumIo (ObjDesc, FieldDatumByteOffset, &MergedValue, ACPI_WRITE); return_ACPI_STATUS (Status);}/******************************************************************************* * * FUNCTION: AcpiExExtractFromField * * PARAMETERS: ObjDesc - Field to be read * Buffer - Where to store the field data * BufferLength - Length of Buffer * * RETURN: Status * * DESCRIPTION: Retrieve the current value of the given field * ******************************************************************************/ACPI_STATUSAcpiExExtractFromField ( ACPI_OPERAND_OBJECT *ObjDesc, void *Buffer, UINT32 BufferLength){ ACPI_STATUS Status; ACPI_INTEGER RawDatum; ACPI_INTEGER MergedDatum; UINT32 FieldOffset = 0; UINT32 BufferOffset = 0; UINT32 BufferTailBits; UINT32 DatumCount; UINT32 FieldDatumCount; UINT32 i; ACPI_FUNCTION_TRACE (ExExtractFromField); /* Validate target buffer and clear it */ if (BufferLength < ACPI_ROUND_BITS_UP_TO_BYTES (ObjDesc->CommonField.BitLength)) { ACPI_ERROR ((AE_INFO, "Field size %X (bits) is too large for buffer (%X)", ObjDesc->CommonField.BitLength, BufferLength)); return_ACPI_STATUS (AE_BUFFER_OVERFLOW); } ACPI_MEMSET (Buffer, 0, BufferLength); /* Compute the number of datums (access width data items) */ DatumCount = ACPI_ROUND_UP_TO ( ObjDesc->CommonField.BitLength, ObjDesc->CommonField.AccessBitWidth); FieldDatumCount = ACPI_ROUND_UP_TO ( ObjDesc->CommonField.BitLength + ObjDesc->CommonField.StartFieldBitOffset, ObjDesc->CommonField.AccessBitWidth); /* Priming read from the field */ Status = AcpiExFieldDatumIo (ObjDesc, FieldOffset, &RawDatum, ACPI_READ); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } MergedDatum = RawDatum >> ObjDesc->CommonField.StartFieldBitOffset; /* Read the rest of the field */ for (i = 1; i < FieldDatumCount; i++) { /* Get next input datum from the field */ FieldOffset += ObjDesc->CommonField.AccessByteWidth; Status = AcpiExFieldDatumIo (ObjDesc, FieldOffset, &RawDatum, ACPI_READ); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } /* * Merge with previous datum if necessary. * * Note: Before the shift, check if the shift value will be larger than * the integer size. If so, there is no need to perform the operation. * This avoids the differences in behavior between different compilers * concerning shift values larger than the target data width. */ if ((ObjDesc->CommonField.AccessBitWidth - ObjDesc->CommonField.StartFieldBitOffset) < ACPI_INTEGER_BIT_SIZE) { MergedDatum |= RawDatum << (ObjDesc->CommonField.AccessBitWidth - ObjDesc->CommonField.StartFieldBitOffset); } if (i == DatumCount) { break; } /* Write merged datum to target buffer */ ACPI_MEMCPY (((char *) Buffer) + BufferOffset, &MergedDatum, ACPI_MIN(ObjDesc->CommonField.AccessByteWidth, BufferLength - BufferOffset)); BufferOffset += ObjDesc->CommonField.AccessByteWidth; MergedDatum = RawDatum >> ObjDesc->CommonField.StartFieldBitOffset; } /* Mask off any extra bits in the last datum */ BufferTailBits = ObjDesc->CommonField.BitLength % ObjDesc->CommonField.AccessBitWidth; if (BufferTailBits) { MergedDatum &= ACPI_MASK_BITS_ABOVE (BufferTailBits); } /* Write the last datum to the buffer */ ACPI_MEMCPY (((char *) Buffer) + BufferOffset, &MergedDatum, ACPI_MIN(ObjDesc->CommonField.AccessByteWidth, BufferLength - BufferOffset)); return_ACPI_STATUS (AE_OK);}/******************************************************************************* * * FUNCTION: AcpiExInsertIntoField * * PARAMETERS: ObjDesc - Field to be written * Buffer - Data to be written * BufferLength - Length of Buffer * * RETURN: Status * * DESCRIPTION: Store the Buffer contents into the given field * ******************************************************************************/ACPI_STATUSAcpiExInsertIntoField ( ACPI_OPERAND_OBJECT *ObjDesc, void *Buffer, UINT32 BufferLength){ ACPI_STATUS Status; ACPI_INTEGER Mask; ACPI_INTEGER WidthMask; ACPI_INTEGER MergedDatum; ACPI_INTEGER RawDatum = 0; UINT32 FieldOffset = 0; UINT32 BufferOffset = 0; UINT32 BufferTailBits; UINT32 DatumCount; UINT32 FieldDatumCount; UINT32 i; UINT32 RequiredLength; void *NewBuffer; ACPI_FUNCTION_TRACE (ExInsertIntoField); /* Validate input buffer */ NewBuffer = NULL; RequiredLength = ACPI_ROUND_BITS_UP_TO_BYTES ( ObjDesc->CommonField.BitLength); /* * We must have a buffer that is at least as long as the field * we are writing to. This is because individual fields are * indivisible and partial writes are not supported -- as per * the ACPI specification. */ if (BufferLength < RequiredLength) { /* We need to create a new buffer */ NewBuffer = ACPI_ALLOCATE_ZEROED (RequiredLength); if (!NewBuffer) { return_ACPI_STATUS (AE_NO_MEMORY); } /* * Copy the original data to the new buffer, starting * at Byte zero. All unused (upper) bytes of the * buffer will be 0. */ ACPI_MEMCPY ((char *) NewBuffer, (char *) Buffer, BufferLength); Buffer = NewBuffer; BufferLength = RequiredLength; } /* * Create the bitmasks used for bit insertion. * Note: This if/else is used to bypass compiler differences with the * shift operator */ if (ObjDesc->CommonField.AccessBitWidth == ACPI_INTEGER_BIT_SIZE) { WidthMask = ACPI_INTEGER_MAX; } else { WidthMask = ACPI_MASK_BITS_ABOVE (ObjDesc->CommonField.AccessBitWidth); } Mask = WidthMask & ACPI_MASK_BITS_BELOW (ObjDesc->CommonField.StartFieldBitOffset); /* Compute the number of datums (access width data items) */ DatumCount = ACPI_ROUND_UP_TO (ObjDesc->CommonField.BitLength, ObjDesc->CommonField.AccessBitWidth); FieldDatumCount = ACPI_ROUND_UP_TO (ObjDesc->CommonField.BitLength + ObjDesc->CommonField.StartFieldBitOffset, ObjDesc->CommonField.AccessBitWidth); /* Get initial Datum from the input buffer */ ACPI_MEMCPY (&RawDatum, Buffer, ACPI_MIN(ObjDesc->CommonField.AccessByteWidth, BufferLength - BufferOffset)); MergedDatum = RawDatum << ObjDesc->CommonField.StartFieldBitOffset; /* Write the entire field */ for (i = 1; i < FieldDatumCount; i++) { /* Write merged datum to the target field */ MergedDatum &= Mask; Status = AcpiExWriteWithUpdateRule (ObjDesc, Mask, MergedDatum, FieldOffset); if (ACPI_FAILURE (Status)) { goto Exit; } FieldOffset += ObjDesc->CommonField.AccessByteWidth; /* * Start new output datum by merging with previous input datum * if necessary. * * Note: Before the shift, check if the shift value will be larger than * the integer size. If so, there is no need to perform the operation. * This avoids the differences in behavior between different compilers * concerning shift values larger than the target data width. */ if ((ObjDesc->CommonField.AccessBitWidth - ObjDesc->CommonField.StartFieldBitOffset) < ACPI_INTEGER_BIT_SIZE) { MergedDatum = RawDatum >> (ObjDesc->CommonField.AccessBitWidth - ObjDesc->CommonField.StartFieldBitOffset); } else { MergedDatum = 0; } Mask = WidthMask; if (i == DatumCount) { break; } /* Get the next input datum from the buffer */ BufferOffset += ObjDesc->CommonField.AccessByteWidth; ACPI_MEMCPY (&RawDatum, ((char *) Buffer) + BufferOffset, ACPI_MIN(ObjDesc->CommonField.AccessByteWidth, BufferLength - BufferOffset)); MergedDatum |= RawDatum << ObjDesc->CommonField.StartFieldBitOffset; } /* Mask off any extra bits in the last datum */ BufferTailBits = (ObjDesc->CommonField.BitLength + ObjDesc->CommonField.StartFieldBitOffset) % ObjDesc->CommonField.AccessBitWidth; if (BufferTailBits) { Mask &= ACPI_MASK_BITS_ABOVE (BufferTailBits); } /* Write the last datum to the field */ MergedDatum &= Mask; Status = AcpiExWriteWithUpdateRule (ObjDesc, Mask, MergedDatum, FieldOffset);Exit: /* Free temporary buffer if we used one */ if (NewBuffer) { ACPI_FREE (NewBuffer); } return_ACPI_STATUS (Status);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -