0001
0002
0003
0004
0005
0006
0007
0008 #include <acpi/acpi.h>
0009 #include "accommon.h"
0010 #include "acnamesp.h"
0011
0012 #define _COMPONENT ACPI_UTILITIES
0013 ACPI_MODULE_NAME("utownerid")
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 acpi_status acpi_ut_allocate_owner_id(acpi_owner_id *owner_id)
0029 {
0030 u32 i;
0031 u32 j;
0032 u32 k;
0033 acpi_status status;
0034
0035 ACPI_FUNCTION_TRACE(ut_allocate_owner_id);
0036
0037
0038
0039 if (*owner_id) {
0040 ACPI_ERROR((AE_INFO,
0041 "Owner ID [0x%3.3X] already exists", *owner_id));
0042 return_ACPI_STATUS(AE_ALREADY_EXISTS);
0043 }
0044
0045
0046
0047 status = acpi_ut_acquire_mutex(ACPI_MTX_CACHES);
0048 if (ACPI_FAILURE(status)) {
0049 return_ACPI_STATUS(status);
0050 }
0051
0052
0053
0054
0055
0056
0057 for (i = 0, j = acpi_gbl_last_owner_id_index;
0058 i < (ACPI_NUM_OWNERID_MASKS + 1); i++, j++) {
0059 if (j >= ACPI_NUM_OWNERID_MASKS) {
0060 j = 0;
0061 }
0062
0063 for (k = acpi_gbl_next_owner_id_offset; k < 32; k++) {
0064 if (acpi_gbl_owner_id_mask[j] == ACPI_UINT32_MAX) {
0065
0066
0067
0068 break;
0069 }
0070
0071
0072
0073
0074
0075
0076
0077 if (!(acpi_gbl_owner_id_mask[j] & ((u32)1 << k))) {
0078
0079
0080
0081
0082
0083 acpi_gbl_owner_id_mask[j] |= ((u32)1 << k);
0084
0085 acpi_gbl_last_owner_id_index = (u8)j;
0086 acpi_gbl_next_owner_id_offset = (u8)(k + 1);
0087
0088
0089
0090
0091
0092
0093
0094 *owner_id =
0095 (acpi_owner_id)((k + 1) + ACPI_MUL_32(j));
0096
0097 ACPI_DEBUG_PRINT((ACPI_DB_VALUES,
0098 "Allocated OwnerId: 0x%3.3X\n",
0099 (unsigned int)*owner_id));
0100 goto exit;
0101 }
0102 }
0103
0104 acpi_gbl_next_owner_id_offset = 0;
0105 }
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117 status = AE_OWNER_ID_LIMIT;
0118 ACPI_ERROR((AE_INFO,
0119 "Could not allocate new OwnerId (4095 max), AE_OWNER_ID_LIMIT"));
0120
0121 exit:
0122 (void)acpi_ut_release_mutex(ACPI_MTX_CACHES);
0123 return_ACPI_STATUS(status);
0124 }
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140 void acpi_ut_release_owner_id(acpi_owner_id *owner_id_ptr)
0141 {
0142 acpi_owner_id owner_id = *owner_id_ptr;
0143 acpi_status status;
0144 u32 index;
0145 u32 bit;
0146
0147 ACPI_FUNCTION_TRACE_U32(ut_release_owner_id, owner_id);
0148
0149
0150
0151 *owner_id_ptr = 0;
0152
0153
0154
0155 if (owner_id == 0) {
0156 ACPI_ERROR((AE_INFO, "Invalid OwnerId: 0x%3.3X", owner_id));
0157 return_VOID;
0158 }
0159
0160
0161
0162 status = acpi_ut_acquire_mutex(ACPI_MTX_CACHES);
0163 if (ACPI_FAILURE(status)) {
0164 return_VOID;
0165 }
0166
0167
0168
0169 owner_id--;
0170
0171
0172
0173 index = ACPI_DIV_32(owner_id);
0174 bit = (u32)1 << ACPI_MOD_32(owner_id);
0175
0176
0177
0178 if (acpi_gbl_owner_id_mask[index] & bit) {
0179 acpi_gbl_owner_id_mask[index] ^= bit;
0180 } else {
0181 ACPI_ERROR((AE_INFO,
0182 "Attempted release of non-allocated OwnerId: 0x%3.3X",
0183 owner_id + 1));
0184 }
0185
0186 (void)acpi_ut_release_mutex(ACPI_MTX_CACHES);
0187 return_VOID;
0188 }