0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <acpi/acpi.h>
0011 #include "accommon.h"
0012 #include "acpredef.h"
0013
0014 #define _COMPONENT ACPI_UTILITIES
0015 ACPI_MODULE_NAME("utpredef")
0016
0017
0018
0019
0020
0021 static const char *ut_rtype_names[] = {
0022 "/Integer",
0023 "/String",
0024 "/Buffer",
0025 "/Package",
0026 "/Reference",
0027 };
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043 const union acpi_predefined_info *acpi_ut_get_next_predefined_method(const union
0044 acpi_predefined_info
0045 *this_name)
0046 {
0047
0048
0049
0050
0051
0052 if ((this_name->info.expected_btypes & ACPI_RTYPE_PACKAGE) &&
0053 (this_name->info.expected_btypes != ACPI_RTYPE_ALL)) {
0054 this_name++;
0055 }
0056
0057 this_name++;
0058 return (this_name);
0059 }
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073 const union acpi_predefined_info *acpi_ut_match_predefined_method(char *name)
0074 {
0075 const union acpi_predefined_info *this_name;
0076
0077
0078
0079 if (name[0] != '_') {
0080 return (NULL);
0081 }
0082
0083
0084
0085 this_name = acpi_gbl_predefined_methods;
0086 while (this_name->info.name[0]) {
0087 if (ACPI_COMPARE_NAMESEG(name, this_name->info.name)) {
0088 return (this_name);
0089 }
0090
0091 this_name = acpi_ut_get_next_predefined_method(this_name);
0092 }
0093
0094 return (NULL);
0095 }
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110 void acpi_ut_get_expected_return_types(char *buffer, u32 expected_btypes)
0111 {
0112 u32 this_rtype;
0113 u32 i;
0114 u32 j;
0115
0116 if (!expected_btypes) {
0117 strcpy(buffer, "NONE");
0118 return;
0119 }
0120
0121 j = 1;
0122 buffer[0] = 0;
0123 this_rtype = ACPI_RTYPE_INTEGER;
0124
0125 for (i = 0; i < ACPI_NUM_RTYPES; i++) {
0126
0127
0128
0129 if (expected_btypes & this_rtype) {
0130 strcat(buffer, &ut_rtype_names[i][j]);
0131 j = 0;
0132 }
0133
0134 this_rtype <<= 1;
0135 }
0136 }
0137
0138
0139
0140
0141
0142
0143
0144 #if (defined ACPI_ASL_COMPILER || defined ACPI_HELP_APP)
0145
0146
0147
0148 static u32 acpi_ut_get_argument_types(char *buffer, u16 argument_types);
0149
0150
0151
0152 static const char *ut_external_type_names[] =
0153 {
0154 ", Type_ANY",
0155 ", Integer",
0156 ", String",
0157 ", Buffer",
0158 ", Package"
0159 };
0160
0161
0162
0163 static const char *ut_resource_type_names[] = {
0164 "/1",
0165 "/2",
0166 "/3",
0167 "/8",
0168 "/16",
0169 "/32",
0170 "/64",
0171 "/variable",
0172 };
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188 const union acpi_predefined_info *acpi_ut_match_resource_name(char *name)
0189 {
0190 const union acpi_predefined_info *this_name;
0191
0192
0193
0194
0195
0196 if (name[0] != '_') {
0197 return (NULL);
0198 }
0199
0200
0201
0202 this_name = acpi_gbl_resource_names;
0203 while (this_name->info.name[0]) {
0204 if (ACPI_COMPARE_NAMESEG(name, this_name->info.name)) {
0205 return (this_name);
0206 }
0207
0208 this_name++;
0209 }
0210
0211 return (NULL);
0212 }
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228
0229
0230 void
0231 acpi_ut_display_predefined_method(char *buffer,
0232 const union acpi_predefined_info *this_name,
0233 u8 multi_line)
0234 {
0235 u32 arg_count;
0236
0237
0238
0239
0240
0241 arg_count = acpi_ut_get_argument_types(buffer,
0242 this_name->info.argument_list);
0243
0244 if (multi_line) {
0245 printf(" ");
0246 }
0247
0248 printf("%4.4s Requires %s%u argument%s",
0249 this_name->info.name,
0250 (this_name->info.argument_list & ARG_COUNT_IS_MINIMUM) ?
0251 "(at least) " : "", arg_count, arg_count != 1 ? "s" : "");
0252
0253
0254
0255 if (arg_count > 0) {
0256 printf(" (%s)", buffer);
0257 }
0258
0259 if (multi_line) {
0260 printf("\n ");
0261 }
0262
0263
0264
0265 if (this_name->info.expected_btypes) {
0266 acpi_ut_get_expected_return_types(buffer,
0267 this_name->info.
0268 expected_btypes);
0269 printf(" Return value types: %s\n", buffer);
0270 } else {
0271 printf(" No return value\n");
0272 }
0273 }
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285
0286
0287
0288
0289
0290 static u32 acpi_ut_get_argument_types(char *buffer, u16 argument_types)
0291 {
0292 u16 this_argument_type;
0293 u16 sub_index;
0294 u16 arg_count;
0295 u32 i;
0296
0297 *buffer = 0;
0298 sub_index = 2;
0299
0300
0301
0302 arg_count = METHOD_GET_ARG_COUNT(argument_types);
0303 if (arg_count > METHOD_PREDEF_ARGS_MAX) {
0304 printf("**** Invalid argument count (%u) "
0305 "in predefined info structure\n", arg_count);
0306 return (arg_count);
0307 }
0308
0309
0310
0311 for (i = 0; i < arg_count; i++) {
0312 this_argument_type = METHOD_GET_NEXT_TYPE(argument_types);
0313
0314 if (this_argument_type > METHOD_MAX_ARG_TYPE) {
0315 printf("**** Invalid argument type (%u) "
0316 "in predefined info structure\n",
0317 this_argument_type);
0318 return (arg_count);
0319 }
0320
0321 strcat(buffer,
0322 ut_external_type_names[this_argument_type] + sub_index);
0323 sub_index = 0;
0324 }
0325
0326 return (arg_count);
0327 }
0328
0329
0330
0331
0332
0333
0334
0335
0336
0337
0338
0339
0340
0341
0342 u32 acpi_ut_get_resource_bit_width(char *buffer, u16 types)
0343 {
0344 u32 i;
0345 u16 sub_index;
0346 u32 found;
0347
0348 *buffer = 0;
0349 sub_index = 1;
0350 found = 0;
0351
0352 for (i = 0; i < NUM_RESOURCE_WIDTHS; i++) {
0353 if (types & 1) {
0354 strcat(buffer, &(ut_resource_type_names[i][sub_index]));
0355 sub_index = 0;
0356 found++;
0357 }
0358
0359 types >>= 1;
0360 }
0361
0362 return (found);
0363 }
0364 #endif