FreeBSD/sys/contrib/dev/acpica/components/hardware/hwregs.c
/******************************************************************************
 *
 * FUNCTION:    AcpiHwRegisterWrite
 *
 * PARAMETERS:  RegisterId          - ACPI Register ID
 *              Value               - The value to write
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Write to the specified ACPI register
 *
 * NOTE: In accordance with the ACPI specification, this function automatically
 * preserves the value of the following bits, meaning that these bits cannot be
 * changed via this interface:
 *
 * PM1_CONTROL[0] = SCI_EN
 * PM1_CONTROL[9]
 * PM1_STATUS[11]
 *
 * ACPI References:
 * 1) Hardware Ignored Bits: When software writes to a register with ignored
 *      bit fields, it preserves the ignored bit fields
 * 2) SCI_EN: OSPM always preserves this bit position
 *
 ******************************************************************************/
AcpiHwRegisterWrite
PARAMETERS:  RegisterId          - ACPI Register ID
Value               - The value to write

Status

Write to the specified ACPI register

In accordance with the ACPI specification, this function automatically
preserves the value of the following bits, meaning that these bits cannot be
changed via this interface.



ACPI References:
1) Hardware Ignored Bits: When software writes to a register with ignored
bit fields, it preserves the ignored bit fields
2) SCI_EN: OSPM always preserves this bit position
AcpiHwRegisterWrite PARAMETERS : RegisterId - ACPI Register ID Value - The value to write Status Write to the specified ACPI register In accordance with the ACPI specification this function automatically preserves the value of the following bits meaning that these bits cannot be changed via this interface . ACPI References : 1 ) Hardware Ignored Bits : When software writes to a register with ignored bit fields it preserves the ignored bit fields 2 ) SCI_EN : OSPM always preserves this bit position
ACPI_STATUS
AcpiHwRegisterWrite (
    UINT32                  RegisterId,
    UINT32                  Value)
{
    ACPI_STATUS             Status;
    UINT32                  ReadValue;
    ACPI_FUNCTION_TRACE (HwRegisterWrite);
    switch (RegisterId)
    {
    case ACPI_REGISTER_PM1_STATUS:           
        Value &= ~ACPI_PM1_STATUS_PRESERVED_BITS;
        Status = AcpiHwWriteMultiple (Value,
            &AcpiGbl_XPm1aStatus,
            &AcpiGbl_XPm1bStatus);
        break;
    case ACPI_REGISTER_PM1_ENABLE:           
        Status = AcpiHwWriteMultiple (Value,
            &AcpiGbl_XPm1aEnable,
            &AcpiGbl_XPm1bEnable);
        break;
    case ACPI_REGISTER_PM1_CONTROL:          
        Status = AcpiHwReadMultiple (&ReadValue,
            &AcpiGbl_FADT.XPm1aControlBlock,
            &AcpiGbl_FADT.XPm1bControlBlock);
        if (ACPI_FAILURE (Status))
        {
            goto Exit;
        }
        ACPI_INSERT_BITS (Value, ACPI_PM1_CONTROL_PRESERVED_BITS, ReadValue);
        Status = AcpiHwWriteMultiple (Value,
            &AcpiGbl_FADT.XPm1aControlBlock,
            &AcpiGbl_FADT.XPm1bControlBlock);
        break;
    case ACPI_REGISTER_PM2_CONTROL:          
        Status = AcpiHwRead (&ReadValue, &AcpiGbl_FADT.XPm2ControlBlock);
        if (ACPI_FAILURE (Status))
        {
            goto Exit;
        }
        ACPI_INSERT_BITS (Value, ACPI_PM2_CONTROL_PRESERVED_BITS, ReadValue);
        Status = AcpiHwWrite (Value, &AcpiGbl_FADT.XPm2ControlBlock);
        break;
    case ACPI_REGISTER_PM_TIMER:             
        Status = AcpiHwWrite (Value, &AcpiGbl_FADT.XPmTimerBlock);
        break;
    case ACPI_REGISTER_SMI_COMMAND_BLOCK:    
        Status = AcpiHwWritePort (AcpiGbl_FADT.SmiCommand, Value, 8);
        break;
    default:
        ACPI_ERROR ((AE_INFO, "Unknown Register ID: 0x%X",
            RegisterId));
        Status = AE_BAD_PARAMETER;
        break;
    }
Exit:
    return_ACPI_STATUS (Status);
}
ACPI_STATUS AcpiHwRegisterWrite ( UINT32 RegisterId , UINT32 Value ) { ACPI_STATUS Status ; UINT32 ReadValue ; ACPI_FUNCTION_TRACE ( HwRegisterWrite ) ; switch ( RegisterId ) { case ACPI_REGISTER_PM1_STATUS : Value &= ~ ACPI_PM1_STATUS_PRESERVED_BITS ; Status = AcpiHwWriteMultiple ( Value , & AcpiGbl_XPm1aStatus , & AcpiGbl_XPm1bStatus ) ; break ; case ACPI_REGISTER_PM1_ENABLE : Status = AcpiHwWriteMultiple ( Value , & AcpiGbl_XPm1aEnable , & AcpiGbl_XPm1bEnable ) ; break ; case ACPI_REGISTER_PM1_CONTROL : Status = AcpiHwReadMultiple ( & ReadValue , & AcpiGbl_FADT . XPm1aControlBlock , & AcpiGbl_FADT . XPm1bControlBlock ) ; if ( ACPI_FAILURE ( Status ) ) { goto Exit ; } ACPI_INSERT_BITS ( Value , ACPI_PM1_CONTROL_PRESERVED_BITS , ReadValue ) ; Status = AcpiHwWriteMultiple ( Value , & AcpiGbl_FADT . XPm1aControlBlock , & AcpiGbl_FADT . XPm1bControlBlock ) ; break ; case ACPI_REGISTER_PM2_CONTROL : Status = AcpiHwRead ( & ReadValue , & AcpiGbl_FADT . XPm2ControlBlock ) ; if ( ACPI_FAILURE ( Status ) ) { goto Exit ; } ACPI_INSERT_BITS ( Value , ACPI_PM2_CONTROL_PRESERVED_BITS , ReadValue ) ; Status = AcpiHwWrite ( Value , & AcpiGbl_FADT . XPm2ControlBlock ) ; break ; case ACPI_REGISTER_PM_TIMER : Status = AcpiHwWrite ( Value , & AcpiGbl_FADT . XPmTimerBlock ) ; break ; case ACPI_REGISTER_SMI_COMMAND_BLOCK : Status = AcpiHwWritePort ( AcpiGbl_FADT . SmiCommand , Value , 8 ) ; break ; default : ACPI_ERROR ( ( AE_INFO , " " , RegisterId ) ) ; Status = AE_BAD_PARAMETER ; break ; } Exit : return_ACPI_STATUS ( Status ) ; }
FUNCTION:    AcpiHwRegisterWrite
 PARAMETERS:  RegisterId          - ACPI Register ID
              Value               - The value to write
FUNCTION : AcpiHwRegisterWrite PARAMETERS : RegisterId - ACPI Register ID Value - The value to write
/* PM1 A/B: 16-bit access each */ /*
         * Handle the "ignored" bit in PM1 Status. According to the ACPI
         * specification, ignored bits are to be preserved when writing.
         * Normally, this would mean a read/modify/write sequence. However,
         * preserving a bit in the status register is different. Writing a
         * one clears the status, and writing a zero preserves the status.
         * Therefore, we must always write zero to the ignored bit.
         *
         * This behavior is clarified in the ACPI 4.0 specification.
         */ /* PM1 A/B: 16-bit access each */ /* PM1 A/B: 16-bit access each */ /*
         * Perform a read first to preserve certain bits (per ACPI spec)
         * Note: This includes SCI_EN, we never want to change this bit
         */ /* Insert the bits to be preserved */ /* Now we can write the data */ /* 8-bit access */ /*
         * For control registers, all reserved bits must be preserved,
         * as per the ACPI spec.
         */ /* Insert the bits to be preserved */ /* 32-bit access */ /* 8-bit access */ /* SMI_CMD is currently always in IO space */