Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
0002 /*******************************************************************************
0003  *
0004  * Module Name: utstate - state object support procedures
0005  *
0006  ******************************************************************************/
0007 
0008 #include <acpi/acpi.h>
0009 #include "accommon.h"
0010 
0011 #define _COMPONENT          ACPI_UTILITIES
0012 ACPI_MODULE_NAME("utstate")
0013 
0014 /*******************************************************************************
0015  *
0016  * FUNCTION:    acpi_ut_push_generic_state
0017  *
0018  * PARAMETERS:  list_head           - Head of the state stack
0019  *              state               - State object to push
0020  *
0021  * RETURN:      None
0022  *
0023  * DESCRIPTION: Push a state object onto a state stack
0024  *
0025  ******************************************************************************/
0026 void
0027 acpi_ut_push_generic_state(union acpi_generic_state **list_head,
0028                union acpi_generic_state *state)
0029 {
0030     ACPI_FUNCTION_ENTRY();
0031 
0032     /* Push the state object onto the front of the list (stack) */
0033 
0034     state->common.next = *list_head;
0035     *list_head = state;
0036     return;
0037 }
0038 
0039 /*******************************************************************************
0040  *
0041  * FUNCTION:    acpi_ut_pop_generic_state
0042  *
0043  * PARAMETERS:  list_head           - Head of the state stack
0044  *
0045  * RETURN:      The popped state object
0046  *
0047  * DESCRIPTION: Pop a state object from a state stack
0048  *
0049  ******************************************************************************/
0050 
0051 union acpi_generic_state *acpi_ut_pop_generic_state(union acpi_generic_state
0052                             **list_head)
0053 {
0054     union acpi_generic_state *state;
0055 
0056     ACPI_FUNCTION_ENTRY();
0057 
0058     /* Remove the state object at the head of the list (stack) */
0059 
0060     state = *list_head;
0061     if (state) {
0062 
0063         /* Update the list head */
0064 
0065         *list_head = state->common.next;
0066     }
0067 
0068     return (state);
0069 }
0070 
0071 /*******************************************************************************
0072  *
0073  * FUNCTION:    acpi_ut_create_generic_state
0074  *
0075  * PARAMETERS:  None
0076  *
0077  * RETURN:      The new state object. NULL on failure.
0078  *
0079  * DESCRIPTION: Create a generic state object. Attempt to obtain one from
0080  *              the global state cache;  If none available, create a new one.
0081  *
0082  ******************************************************************************/
0083 
0084 union acpi_generic_state *acpi_ut_create_generic_state(void)
0085 {
0086     union acpi_generic_state *state;
0087 
0088     ACPI_FUNCTION_ENTRY();
0089 
0090     state = acpi_os_acquire_object(acpi_gbl_state_cache);
0091     if (state) {
0092 
0093         /* Initialize */
0094         state->common.descriptor_type = ACPI_DESC_TYPE_STATE;
0095     }
0096 
0097     return (state);
0098 }
0099 
0100 /*******************************************************************************
0101  *
0102  * FUNCTION:    acpi_ut_create_thread_state
0103  *
0104  * PARAMETERS:  None
0105  *
0106  * RETURN:      New Thread State. NULL on failure
0107  *
0108  * DESCRIPTION: Create a "Thread State" - a flavor of the generic state used
0109  *              to track per-thread info during method execution
0110  *
0111  ******************************************************************************/
0112 
0113 struct acpi_thread_state *acpi_ut_create_thread_state(void)
0114 {
0115     union acpi_generic_state *state;
0116 
0117     ACPI_FUNCTION_ENTRY();
0118 
0119     /* Create the generic state object */
0120 
0121     state = acpi_ut_create_generic_state();
0122     if (!state) {
0123         return (NULL);
0124     }
0125 
0126     /* Init fields specific to the update struct */
0127 
0128     state->common.descriptor_type = ACPI_DESC_TYPE_STATE_THREAD;
0129     state->thread.thread_id = acpi_os_get_thread_id();
0130 
0131     /* Check for invalid thread ID - zero is very bad, it will break things */
0132 
0133     if (!state->thread.thread_id) {
0134         ACPI_ERROR((AE_INFO, "Invalid zero ID from AcpiOsGetThreadId"));
0135         state->thread.thread_id = (acpi_thread_id) 1;
0136     }
0137 
0138     return ((struct acpi_thread_state *)state);
0139 }
0140 
0141 /*******************************************************************************
0142  *
0143  * FUNCTION:    acpi_ut_create_update_state
0144  *
0145  * PARAMETERS:  object          - Initial Object to be installed in the state
0146  *              action          - Update action to be performed
0147  *
0148  * RETURN:      New state object, null on failure
0149  *
0150  * DESCRIPTION: Create an "Update State" - a flavor of the generic state used
0151  *              to update reference counts and delete complex objects such
0152  *              as packages.
0153  *
0154  ******************************************************************************/
0155 
0156 union acpi_generic_state *acpi_ut_create_update_state(union acpi_operand_object
0157                               *object, u16 action)
0158 {
0159     union acpi_generic_state *state;
0160 
0161     ACPI_FUNCTION_ENTRY();
0162 
0163     /* Create the generic state object */
0164 
0165     state = acpi_ut_create_generic_state();
0166     if (!state) {
0167         return (NULL);
0168     }
0169 
0170     /* Init fields specific to the update struct */
0171 
0172     state->common.descriptor_type = ACPI_DESC_TYPE_STATE_UPDATE;
0173     state->update.object = object;
0174     state->update.value = action;
0175     return (state);
0176 }
0177 
0178 /*******************************************************************************
0179  *
0180  * FUNCTION:    acpi_ut_create_pkg_state
0181  *
0182  * PARAMETERS:  object          - Initial Object to be installed in the state
0183  *              action          - Update action to be performed
0184  *
0185  * RETURN:      New state object, null on failure
0186  *
0187  * DESCRIPTION: Create a "Package State"
0188  *
0189  ******************************************************************************/
0190 
0191 union acpi_generic_state *acpi_ut_create_pkg_state(void *internal_object,
0192                            void *external_object,
0193                            u32 index)
0194 {
0195     union acpi_generic_state *state;
0196 
0197     ACPI_FUNCTION_ENTRY();
0198 
0199     /* Create the generic state object */
0200 
0201     state = acpi_ut_create_generic_state();
0202     if (!state) {
0203         return (NULL);
0204     }
0205 
0206     /* Init fields specific to the update struct */
0207 
0208     state->common.descriptor_type = ACPI_DESC_TYPE_STATE_PACKAGE;
0209     state->pkg.source_object = (union acpi_operand_object *)internal_object;
0210     state->pkg.dest_object = external_object;
0211     state->pkg.index = index;
0212     state->pkg.num_packages = 1;
0213 
0214     return (state);
0215 }
0216 
0217 /*******************************************************************************
0218  *
0219  * FUNCTION:    acpi_ut_create_control_state
0220  *
0221  * PARAMETERS:  None
0222  *
0223  * RETURN:      New state object, null on failure
0224  *
0225  * DESCRIPTION: Create a "Control State" - a flavor of the generic state used
0226  *              to support nested IF/WHILE constructs in the AML.
0227  *
0228  ******************************************************************************/
0229 
0230 union acpi_generic_state *acpi_ut_create_control_state(void)
0231 {
0232     union acpi_generic_state *state;
0233 
0234     ACPI_FUNCTION_ENTRY();
0235 
0236     /* Create the generic state object */
0237 
0238     state = acpi_ut_create_generic_state();
0239     if (!state) {
0240         return (NULL);
0241     }
0242 
0243     /* Init fields specific to the control struct */
0244 
0245     state->common.descriptor_type = ACPI_DESC_TYPE_STATE_CONTROL;
0246     state->common.state = ACPI_CONTROL_CONDITIONAL_EXECUTING;
0247 
0248     return (state);
0249 }
0250 
0251 /*******************************************************************************
0252  *
0253  * FUNCTION:    acpi_ut_delete_generic_state
0254  *
0255  * PARAMETERS:  state               - The state object to be deleted
0256  *
0257  * RETURN:      None
0258  *
0259  * DESCRIPTION: Release a state object to the state cache. NULL state objects
0260  *              are ignored.
0261  *
0262  ******************************************************************************/
0263 
0264 void acpi_ut_delete_generic_state(union acpi_generic_state *state)
0265 {
0266     ACPI_FUNCTION_ENTRY();
0267 
0268     /* Ignore null state */
0269 
0270     if (state) {
0271         (void)acpi_os_release_object(acpi_gbl_state_cache, state);
0272     }
0273 
0274     return;
0275 }