^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Module Name: utalloc - local memory allocation routines
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2000 - 2020, Intel Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *****************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <acpi/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include "accommon.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "acdebug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #define _COMPONENT ACPI_UTILITIES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) ACPI_MODULE_NAME("utalloc")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #if !defined (USE_NATIVE_ALLOCATE_ZEROED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * FUNCTION: acpi_os_allocate_zeroed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * PARAMETERS: size - Size of the allocation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * RETURN: Address of the allocated memory on success, NULL on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * DESCRIPTION: Subsystem equivalent of calloc. Allocate and zero memory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * This is the default implementation. Can be overridden via the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * USE_NATIVE_ALLOCATE_ZEROED flag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) void *acpi_os_allocate_zeroed(acpi_size size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) void *allocation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) ACPI_FUNCTION_ENTRY();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) allocation = acpi_os_allocate(size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) if (allocation) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) /* Clear the memory block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) memset(allocation, 0, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) return (allocation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #endif /* !USE_NATIVE_ALLOCATE_ZEROED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * FUNCTION: acpi_ut_create_caches
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * PARAMETERS: None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * DESCRIPTION: Create all local caches
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) acpi_status acpi_ut_create_caches(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) /* Object Caches, for frequently used objects */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) acpi_os_create_cache("Acpi-Namespace",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) sizeof(struct acpi_namespace_node),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) ACPI_MAX_NAMESPACE_CACHE_DEPTH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) &acpi_gbl_namespace_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) return (status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) acpi_os_create_cache("Acpi-State", sizeof(union acpi_generic_state),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) ACPI_MAX_STATE_CACHE_DEPTH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) &acpi_gbl_state_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) return (status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) acpi_os_create_cache("Acpi-Parse",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) sizeof(struct acpi_parse_obj_common),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) ACPI_MAX_PARSE_CACHE_DEPTH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) &acpi_gbl_ps_node_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) return (status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) acpi_os_create_cache("Acpi-ParseExt",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) sizeof(struct acpi_parse_obj_named),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) ACPI_MAX_EXTPARSE_CACHE_DEPTH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) &acpi_gbl_ps_node_ext_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) return (status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) acpi_os_create_cache("Acpi-Operand",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) sizeof(union acpi_operand_object),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) ACPI_MAX_OBJECT_CACHE_DEPTH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) &acpi_gbl_operand_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) return (status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) #ifdef ACPI_ASL_COMPILER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * For use with the ASL-/ASL+ option. This cache keeps track of regular
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * 0xA9 0x01 comments.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) acpi_os_create_cache("Acpi-Comment",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) sizeof(struct acpi_comment_node),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) ACPI_MAX_COMMENT_CACHE_DEPTH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) &acpi_gbl_reg_comment_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) return (status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) * This cache keeps track of the starting addresses of where the comments
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) * lie. This helps prevent duplication of comments.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) acpi_os_create_cache("Acpi-Comment-Addr",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) sizeof(struct acpi_comment_addr_node),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) ACPI_MAX_COMMENT_CACHE_DEPTH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) &acpi_gbl_comment_addr_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) return (status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) * This cache will be used for nodes that represent files.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) acpi_os_create_cache("Acpi-File", sizeof(struct acpi_file_node),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) ACPI_MAX_COMMENT_CACHE_DEPTH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) &acpi_gbl_file_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) return (status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) #ifdef ACPI_DBG_TRACK_ALLOCATIONS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) /* Memory allocation lists */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) status = acpi_ut_create_list("Acpi-Global", 0, &acpi_gbl_global_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) return (status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) acpi_ut_create_list("Acpi-Namespace",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) sizeof(struct acpi_namespace_node),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) &acpi_gbl_ns_node_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) return (status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) return (AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * FUNCTION: acpi_ut_delete_caches
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) * PARAMETERS: None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) * DESCRIPTION: Purge and delete all local caches
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) acpi_status acpi_ut_delete_caches(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) #ifdef ACPI_DBG_TRACK_ALLOCATIONS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) char buffer[7];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) if (acpi_gbl_display_final_mem_stats) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) strcpy(buffer, "MEMORY");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) (void)acpi_db_display_statistics(buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) (void)acpi_os_delete_cache(acpi_gbl_namespace_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) acpi_gbl_namespace_cache = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) (void)acpi_os_delete_cache(acpi_gbl_state_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) acpi_gbl_state_cache = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) (void)acpi_os_delete_cache(acpi_gbl_operand_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) acpi_gbl_operand_cache = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) (void)acpi_os_delete_cache(acpi_gbl_ps_node_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) acpi_gbl_ps_node_cache = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) (void)acpi_os_delete_cache(acpi_gbl_ps_node_ext_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) acpi_gbl_ps_node_ext_cache = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) #ifdef ACPI_ASL_COMPILER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) (void)acpi_os_delete_cache(acpi_gbl_reg_comment_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) acpi_gbl_reg_comment_cache = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) (void)acpi_os_delete_cache(acpi_gbl_comment_addr_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) acpi_gbl_comment_addr_cache = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) (void)acpi_os_delete_cache(acpi_gbl_file_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) acpi_gbl_file_cache = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) #ifdef ACPI_DBG_TRACK_ALLOCATIONS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) /* Debug only - display leftover memory allocation, if any */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) acpi_ut_dump_allocations(ACPI_UINT32_MAX, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) /* Free memory lists */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) acpi_os_free(acpi_gbl_global_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) acpi_gbl_global_list = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) acpi_os_free(acpi_gbl_ns_node_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) acpi_gbl_ns_node_list = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) return (AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) * FUNCTION: acpi_ut_validate_buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) * PARAMETERS: buffer - Buffer descriptor to be validated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) * DESCRIPTION: Perform parameter validation checks on an struct acpi_buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) acpi_status acpi_ut_validate_buffer(struct acpi_buffer *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) /* Obviously, the structure pointer must be valid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) if (!buffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) return (AE_BAD_PARAMETER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) /* Special semantics for the length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) if ((buffer->length == ACPI_NO_BUFFER) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) (buffer->length == ACPI_ALLOCATE_BUFFER) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) (buffer->length == ACPI_ALLOCATE_LOCAL_BUFFER)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) return (AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) /* Length is valid, the buffer pointer must be also */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) if (!buffer->pointer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) return (AE_BAD_PARAMETER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) return (AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) * FUNCTION: acpi_ut_initialize_buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) * PARAMETERS: buffer - Buffer to be validated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) * required_length - Length needed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) * DESCRIPTION: Validate that the buffer is of the required length or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) * allocate a new buffer. Returned buffer is always zeroed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) acpi_ut_initialize_buffer(struct acpi_buffer *buffer, acpi_size required_length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) acpi_size input_buffer_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) /* Parameter validation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) if (!buffer || !required_length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) return (AE_BAD_PARAMETER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) * Buffer->Length is used as both an input and output parameter. Get the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) * input actual length and set the output required buffer length.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) input_buffer_length = buffer->length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) buffer->length = required_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) * The input buffer length contains the actual buffer length, or the type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) * of buffer to be allocated by this routine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) switch (input_buffer_length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) case ACPI_NO_BUFFER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) /* Return the exception (and the required buffer length) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) return (AE_BUFFER_OVERFLOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) case ACPI_ALLOCATE_BUFFER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) * Allocate a new buffer. We directectly call acpi_os_allocate here to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) * purposefully bypass the (optionally enabled) internal allocation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) * tracking mechanism since we only want to track internal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) * allocations. Note: The caller should use acpi_os_free to free this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) * buffer created via ACPI_ALLOCATE_BUFFER.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) buffer->pointer = acpi_os_allocate(required_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) case ACPI_ALLOCATE_LOCAL_BUFFER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) /* Allocate a new buffer with local interface to allow tracking */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) buffer->pointer = ACPI_ALLOCATE(required_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) /* Existing buffer: Validate the size of the buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) if (input_buffer_length < required_length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) return (AE_BUFFER_OVERFLOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) /* Validate allocation from above or input buffer pointer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) if (!buffer->pointer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) return (AE_NO_MEMORY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) /* Have a valid buffer, clear it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) memset(buffer->pointer, 0, required_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) return (AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) }