1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44#include <acpi/acpi.h>
45#include "accommon.h"
46#include "acresrc.h"
47#include "acnamesp.h"
48
49#define _COMPONENT ACPI_RESOURCES
50ACPI_MODULE_NAME("rscreate")
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65acpi_status
66acpi_buffer_to_resource(u8 *aml_buffer,
67 u16 aml_buffer_length,
68 struct acpi_resource **resource_ptr)
69{
70 acpi_status status;
71 acpi_size list_size_needed;
72 void *resource;
73 void *current_resource_ptr;
74
75 ACPI_FUNCTION_TRACE(acpi_buffer_to_resource);
76
77
78
79
80
81
82
83
84 status = acpi_rs_get_list_length(aml_buffer, aml_buffer_length,
85 &list_size_needed);
86 if (status == AE_AML_NO_RESOURCE_END_TAG) {
87 status = AE_OK;
88 }
89 if (ACPI_FAILURE(status)) {
90 return_ACPI_STATUS(status);
91 }
92
93
94
95 resource = ACPI_ALLOCATE_ZEROED(list_size_needed);
96 current_resource_ptr = resource;
97 if (!resource) {
98 return_ACPI_STATUS(AE_NO_MEMORY);
99 }
100
101
102
103 status = acpi_ut_walk_aml_resources(NULL, aml_buffer, aml_buffer_length,
104 acpi_rs_convert_aml_to_resources,
105 ¤t_resource_ptr);
106 if (status == AE_AML_NO_RESOURCE_END_TAG) {
107 status = AE_OK;
108 }
109 if (ACPI_FAILURE(status)) {
110 ACPI_FREE(resource);
111 } else {
112 *resource_ptr = resource;
113 }
114
115 return_ACPI_STATUS(status);
116}
117
118ACPI_EXPORT_SYMBOL(acpi_buffer_to_resource)
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137acpi_status
138acpi_rs_create_resource_list(union acpi_operand_object *aml_buffer,
139 struct acpi_buffer *output_buffer)
140{
141
142 acpi_status status;
143 u8 *aml_start;
144 acpi_size list_size_needed = 0;
145 u32 aml_buffer_length;
146 void *resource;
147
148 ACPI_FUNCTION_TRACE(rs_create_resource_list);
149
150 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "AmlBuffer = %p\n", aml_buffer));
151
152
153
154 aml_buffer_length = aml_buffer->buffer.length;
155 aml_start = aml_buffer->buffer.pointer;
156
157
158
159
160
161 status = acpi_rs_get_list_length(aml_start, aml_buffer_length,
162 &list_size_needed);
163
164 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Status=%X ListSizeNeeded=%X\n",
165 status, (u32) list_size_needed));
166 if (ACPI_FAILURE(status)) {
167 return_ACPI_STATUS(status);
168 }
169
170
171
172 status = acpi_ut_initialize_buffer(output_buffer, list_size_needed);
173 if (ACPI_FAILURE(status)) {
174 return_ACPI_STATUS(status);
175 }
176
177
178
179 resource = output_buffer->pointer;
180 status = acpi_ut_walk_aml_resources(NULL, aml_start, aml_buffer_length,
181 acpi_rs_convert_aml_to_resources,
182 &resource);
183 if (ACPI_FAILURE(status)) {
184 return_ACPI_STATUS(status);
185 }
186
187 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "OutputBuffer %p Length %X\n",
188 output_buffer->pointer, (u32) output_buffer->length));
189 return_ACPI_STATUS(AE_OK);
190}
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213acpi_status
214acpi_rs_create_pci_routing_table(union acpi_operand_object *package_object,
215 struct acpi_buffer *output_buffer)
216{
217 u8 *buffer;
218 union acpi_operand_object **top_object_list;
219 union acpi_operand_object **sub_object_list;
220 union acpi_operand_object *obj_desc;
221 acpi_size buffer_size_needed = 0;
222 u32 number_of_elements;
223 u32 index;
224 struct acpi_pci_routing_table *user_prt;
225 struct acpi_namespace_node *node;
226 acpi_status status;
227 struct acpi_buffer path_buffer;
228
229 ACPI_FUNCTION_TRACE(rs_create_pci_routing_table);
230
231
232
233
234
235 status = acpi_rs_get_pci_routing_table_length(package_object,
236 &buffer_size_needed);
237 if (ACPI_FAILURE(status)) {
238 return_ACPI_STATUS(status);
239 }
240
241 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "BufferSizeNeeded = %X\n",
242 (u32) buffer_size_needed));
243
244
245
246 status = acpi_ut_initialize_buffer(output_buffer, buffer_size_needed);
247 if (ACPI_FAILURE(status)) {
248 return_ACPI_STATUS(status);
249 }
250
251
252
253
254
255
256 top_object_list = package_object->package.elements;
257 number_of_elements = package_object->package.count;
258 buffer = output_buffer->pointer;
259 user_prt = ACPI_CAST_PTR(struct acpi_pci_routing_table, buffer);
260
261 for (index = 0; index < number_of_elements; index++) {
262
263
264
265
266
267
268
269 buffer += user_prt->length;
270 user_prt = ACPI_CAST_PTR(struct acpi_pci_routing_table, buffer);
271
272
273
274
275
276
277 user_prt->length = (sizeof(struct acpi_pci_routing_table) - 4);
278
279
280
281 if ((*top_object_list)->package.count != 4) {
282 ACPI_ERROR((AE_INFO,
283 "(PRT[%u]) Need package of length 4, found length %u",
284 index, (*top_object_list)->package.count));
285 return_ACPI_STATUS(AE_AML_PACKAGE_LIMIT);
286 }
287
288
289
290
291
292
293 sub_object_list = (*top_object_list)->package.elements;
294
295
296
297 obj_desc = sub_object_list[0];
298 if (!obj_desc || obj_desc->common.type != ACPI_TYPE_INTEGER) {
299 ACPI_ERROR((AE_INFO,
300 "(PRT[%u].Address) Need Integer, found %s",
301 index,
302 acpi_ut_get_object_type_name(obj_desc)));
303 return_ACPI_STATUS(AE_BAD_DATA);
304 }
305
306 user_prt->address = obj_desc->integer.value;
307
308
309
310 obj_desc = sub_object_list[1];
311 if (!obj_desc || obj_desc->common.type != ACPI_TYPE_INTEGER) {
312 ACPI_ERROR((AE_INFO,
313 "(PRT[%u].Pin) Need Integer, found %s",
314 index,
315 acpi_ut_get_object_type_name(obj_desc)));
316 return_ACPI_STATUS(AE_BAD_DATA);
317 }
318
319 user_prt->pin = (u32) obj_desc->integer.value;
320
321
322
323
324
325 obj_desc = sub_object_list[2];
326 if (obj_desc) {
327 switch (obj_desc->common.type) {
328 case ACPI_TYPE_LOCAL_REFERENCE:
329
330 if (obj_desc->reference.class !=
331 ACPI_REFCLASS_NAME) {
332 ACPI_ERROR((AE_INFO,
333 "(PRT[%u].Source) Need name, found Reference Class 0x%X",
334 index,
335 obj_desc->reference.class));
336 return_ACPI_STATUS(AE_BAD_DATA);
337 }
338
339 node = obj_desc->reference.node;
340
341
342
343 path_buffer.length = output_buffer->length -
344 (u32) ((u8 *) user_prt->source -
345 (u8 *) output_buffer->pointer);
346 path_buffer.pointer = user_prt->source;
347
348 status =
349 acpi_ns_handle_to_pathname((acpi_handle)
350 node,
351 &path_buffer,
352 FALSE);
353
354
355
356 user_prt->length +=
357 (u32)strlen(user_prt->source) + 1;
358 break;
359
360 case ACPI_TYPE_STRING:
361
362 strcpy(user_prt->source,
363 obj_desc->string.pointer);
364
365
366
367
368
369 user_prt->length += obj_desc->string.length + 1;
370 break;
371
372 case ACPI_TYPE_INTEGER:
373
374
375
376
377
378
379 user_prt->length += sizeof(u32);
380 break;
381
382 default:
383
384 ACPI_ERROR((AE_INFO,
385 "(PRT[%u].Source) Need Ref/String/Integer, found %s",
386 index,
387 acpi_ut_get_object_type_name
388 (obj_desc)));
389 return_ACPI_STATUS(AE_BAD_DATA);
390 }
391 }
392
393
394
395 user_prt->length =
396 (u32) ACPI_ROUND_UP_TO_64BIT(user_prt->length);
397
398
399
400 obj_desc = sub_object_list[3];
401 if (!obj_desc || obj_desc->common.type != ACPI_TYPE_INTEGER) {
402 ACPI_ERROR((AE_INFO,
403 "(PRT[%u].SourceIndex) Need Integer, found %s",
404 index,
405 acpi_ut_get_object_type_name(obj_desc)));
406 return_ACPI_STATUS(AE_BAD_DATA);
407 }
408
409 user_prt->source_index = (u32) obj_desc->integer.value;
410
411
412
413 top_object_list++;
414 }
415
416 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "OutputBuffer %p Length %X\n",
417 output_buffer->pointer, (u32) output_buffer->length));
418 return_ACPI_STATUS(AE_OK);
419}
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438acpi_status
439acpi_rs_create_aml_resources(struct acpi_buffer *resource_list,
440 struct acpi_buffer *output_buffer)
441{
442 acpi_status status;
443 acpi_size aml_size_needed = 0;
444
445 ACPI_FUNCTION_TRACE(rs_create_aml_resources);
446
447
448
449 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "ResourceList Buffer = %p\n",
450 resource_list->pointer));
451
452
453
454 status = acpi_rs_get_aml_length(resource_list->pointer,
455 resource_list->length,
456 &aml_size_needed);
457
458 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "AmlSizeNeeded=%X, %s\n",
459 (u32)aml_size_needed, acpi_format_exception(status)));
460 if (ACPI_FAILURE(status)) {
461 return_ACPI_STATUS(status);
462 }
463
464
465
466 status = acpi_ut_initialize_buffer(output_buffer, aml_size_needed);
467 if (ACPI_FAILURE(status)) {
468 return_ACPI_STATUS(status);
469 }
470
471
472
473 status = acpi_rs_convert_resources_to_aml(resource_list->pointer,
474 aml_size_needed,
475 output_buffer->pointer);
476 if (ACPI_FAILURE(status)) {
477 return_ACPI_STATUS(status);
478 }
479
480 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "OutputBuffer %p Length %X\n",
481 output_buffer->pointer, (u32) output_buffer->length));
482 return_ACPI_STATUS(AE_OK);
483}
484