1/*
2 * Some or all of this work - Copyright (c) 2006 - 2016, Intel Corp.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * Neither the name of Intel Corporation nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/*
30 * The Test Command Interface with the ACPICA (_TCI)
31 *
32 * Note: _TCI and TCI mean the same in comments below.
33 *       But, actually the name of the relevant predefined
34 *       Method is _TCI.
35 */
36
37Name(z128, 128)
38
39Name(DE00, 0) // Disable reporting errors from m3a4, needed in m3aa (not enough params)
40Name(FOPT, 0) // Flag of optimization
41
42
43/*
44 * Constants
45 */
46
47// Opcodes of the Test Commands provided by _TCI
48
49Name(c200, 0xcd0000)	// _TCI-end statistics
50Name(c201, 0xcd0001)	// _TCI-begin statistics
51Name(c202, 0xcd0002)	// TCI_CMD_CHECK_SUPPORTED
52Name(c203, 0xcd0003)	// TCI_CMD_GET_ID_OF_THREADS
53
54// Tags of commands (to be filled into TCI Package by aslts)
55
56Name(c208, 0xeeee0596)	// TCI_TAG_GET_MC_STAT_AFTER_TCI_TERM
57Name(c209, 0xbbbb063a)	// TCI_TAG_GET_MC_STAT_BEFORE_TCI_RUN
58Name(c20a, 0xcccc07b9)	// TCI_TAG_CHECK_SUPPORTED
59Name(c20b, 0xdddd01f5)	// TCI_TAG_GET_ID_OF_THREADS
60
61/*
62 * The layout of the Package for Memory Consumption Statistics
63 * applied for TCI commands:
64 *   _TCI-end statistics (command TCI_CMD_GET_MC_STAT_AFTER_TCI_TERM)
65 *   _TCI-begin statistics (command TCI_CMD_GET_MC_STAT_BEFORE_TCI_RUN)
66 */
67Name(c210,   0) // Tittle
68Name(c211,   4) // acq0
69Name(c212,   9) // acq1 (-)
70Name(c213,  14) // acq2 (-)
71Name(c214,  19) // acq3
72Name(c215,  24) // acq4 (-)
73Name(c216,  29) // acq5
74Name(c217,  34) // rel0
75Name(c218,  39) // rel1
76Name(c219,  44) // rel2 (-)
77Name(c21a,  49) // rel3
78Name(c21b,  54) // Created Objects
79Name(c21c,  84) // Deleted Objects
80Name(c21d, 114) // Miscellaneous Stat
81
82Name(c220, 121)	// the length of the Package for
83			// Memory Consumption Statistics.
84
85// The layout of header of the common _TCI Package
86
87// Input, data of header passed to ACPICA
88Name(c222, 0)	// Tag of command (to be set up by aslts)
89
90// Output, data of header returned to aslts from ACPICA
91Name(c223, 1)	// Size (number of elements actually packed into TCI package,
92                  // to be filled by ACPICA)
93Name(c224, 2)	// Cmd (command has been executed, to be filled by ACPICA)
94Name(c225, 3)	// CACHE_ENABLED (object cache is enabled info flag,
95                  // to be filled by ACPICA)
96Name(c22b, 4)	// length of the common _TCI Package header
97
98
99// The layout of header of TCI_CMD_GET_ID_OF_THREADS command
100// (returned to aslts from ACPICA)
101Name(c22c, 4)	// TCI_PACKAGE_THR_NUM
102Name(c22d, 5)	// TCI_PACKAGE_THR_NUM_REAL
103Name(c22e, 6)	// TCI_PACKAGE_THR_ID
104Name(c22f, 7)	// length TCI_PACKAGE_THR_HEADER_SIZE
105
106
107Name(c221, 5)	// CACHE_LISTS_NUMBER (Object Caches):
108			//   CLIST_ID_NAMESPACE     0 /* Acpi-Namespace */
109			//   CLIST_ID_STATE         1 /* Acpi-State */
110			//   CLIST_ID_OPERAND       2 /* Acpi-Operand */
111			//   CLIST_ID_PSNODE        3 /* Acpi-Parse */
112			//   CLIST_ID_PSNODE_EXT    4 /* Acpi-ParseExt */
113
114Name(c226, 0)	// CLIST_ID_NAMESPACE
115Name(c227, 1)	// CLIST_ID_STATE
116Name(c228, 2)	// CLIST_ID_OPERAND
117Name(c229, 3)	// CLIST_ID_PSNODE
118Name(c22a, 4)	// CLIST_ID_PSNODE_EXT
119
120
121/*
122 * The main Test Command interface with the ACPICA
123 *
124 * arg0 - opcode of the Test Command
125 * arg1 - Package for different needs depending on the command.
126 *        So, in case of the Memory Consumption Statistics commands it
127 *        is filled by ACPICA with the Memory Consumption Statistics.
128 *        The length of package in this case should be not less than c220,
129 *        otherwise, no any failure arises but not all data are returned
130 *        by Package just only the relevant part of it. It is true for all
131 *        commands.
132 * Note: use m3a0 or m165 to prepare the arg1-package.
133 */
134Method(_TCI, 2)
135{
136	/*
137	 * Before to run this method reset location
138	 * of Command which is to be filled by ACPICA
139	 * to acknowledge the interconnection.
140	 * It is performed in m3a0 and m3a4.
141	 */
142	return (arg1)
143}
144
145/*
146 * Create and initialize the Package for _TCI
147 *
148 * arg0 - opcode of the Test Command.
149 *        Use 0 for allocation without initialization.
150 * arg1 - number of element of Package (for some of commands)
151 *
152 * Return the resulting Package:
153 *
154 *   - if arg0 is zero - the Package of c220 length
155 *   - otherwise - the Package of length depending on
156 *     the command is additionally initialized
157 */
158Method(m165, 2, Serialized)
159{
160	Name(num, 0)
161	Name(tag, 0)
162
163	if (arg0) {
164
165		Switch (ToInteger (arg0)) {
166			Case (0xcd0000) {
167				// _TCI-end statistics
168				Store(c208, tag)
169				Store(c220, num)
170			}
171			Case (0xcd0001) {
172				// _TCI-begin statistics
173				Store(c209, tag)
174				Store(c220, num)
175			}
176			Case (0xcd0002) {
177				// TCI_CMD_CHECK_SUPPORTED
178				Store(c20a, tag)
179				Store(c22b, num)
180			}
181			Case (0xcd0003) {
182				// TCI_CMD_GET_ID_OF_THREADS
183				Store(c20b, tag)
184				Store(arg1, num)
185			}
186			Default {
187				err("m165", z128, 0, 0, 0, arg0, 0)
188			}
189		}
190
191		if (LLess(num, c22b)) {
192			err("m165", z128, 0, 0, 0, num, c22b)
193		} else {
194			Name(p000, Package(num) {})
195			Name(lpN0, 0)
196			Name(lpC0, 0)
197			Store(num, lpN0)
198			Store(0, lpC0)
199			While (lpN0) {
200				Store(0, Index(p000, lpC0))
201				Decrement(lpN0)
202				Increment(lpC0)
203			}
204			Store(tag, Index(p000, 0))
205			Return (p000)
206		}
207	} else {
208		Name(p001, Package(c220) {})
209		Return (p001)
210	}
211
212	Return (0)
213}
214
215/*
216 * Create and initialize the Package for simple cases
217 * entirely specified by the opcode of command.
218 *
219 * a. for Memory Consumption Statistics
220 *    (_TCI-begin or _TCI-end statistics).
221 *
222 * b. TCI_CMD_CHECK_SUPPORTED
223 *
224 * arg0 - opcode of the Test Command.
225 *        Use 0 for allocation without initialization.
226 *
227 * Returns the TCI Package
228 */
229Method(m3a0, 1)
230{
231	Store(m165(arg0, 0), Local0)
232
233	Return (Local0)
234}
235
236Method(m3a1, 2)
237{
238	Store(DeRefOf(Index(NMTP, arg1)), Local0)
239	Concatenate("", arg0, Local2)
240	Concatenate(Local2, " ", Local1)
241	Concatenate(Local1, Local0, Debug)
242}
243
244/*
245 * Print out the Memory Consumption Statistics Package
246 *
247 * arg0 - Memory Consumption Statistics Package
248 * arg1 - opcode of the tittle message
249 */
250Method(m3a2, 2, Serialized)
251{
252	if (LEqual(arg1, 0)) {
253		Store("==== _TCI-end statistics", Debug)
254	} elseif (LEqual(arg1, 1)) {
255		Store("==== _TCI-begin statistics", Debug)
256	} elseif (LEqual(arg1, 2)) {
257		Store("==== _TCI-end-begin difference", Debug)
258	} else {
259		Store("???", Debug)
260	}
261
262	Name(lpN0, 0)
263	Name(lpC0, 0)
264
265	Store(c220, lpN0)
266	Store(0, lpC0)
267
268	Store(0, Local1)
269	Store(0, Local2)
270
271	While (lpN0) {
272
273		if (LEqual(lpC0, c210)) {
274			Store("Tittle:", Debug)
275		} elseif (LEqual(lpC0, c211)) {
276			Store("acq0:  all calls to AcpiUtAcquireFromCache", Debug)
277		} elseif (LEqual(lpC0, c212)) {
278			Store("acq1: +AcpiUtAcquireMutex", Debug)
279		} elseif (LEqual(lpC0, c213)) {
280			Store("acq2: +there is a cache object available", Debug)
281		} elseif (LEqual(lpC0, c214)) {
282			Store("acq3: +AcpiUtReleaseMutex", Debug)
283		} elseif (LEqual(lpC0, c215)) {
284			Store("acq4: +otherwise, the cache is empty, create a new object", Debug)
285		} elseif (LEqual(lpC0, c216)) {
286			Store("acq5: +AcpiUtReleaseMutex", Debug)
287		} elseif (LEqual(lpC0, c217)) {
288			Store("rel0:  all calls to AcpiUtReleaseToCache", Debug)
289		} elseif (LEqual(lpC0, c218)) {
290			Store("rel1: +walk cache is full, just free this object", Debug)
291		} elseif (LEqual(lpC0, c219)) {
292			Store("rel2: +otherwise, put this object back into the cache", Debug)
293		} elseif (LEqual(lpC0, c21a)) {
294			Store("rel3: +AcpiUtAcquireMutex", Debug)
295		} elseif (LEqual(lpC0, c21b)) {
296			Store("Created Objects:", Debug)
297		} elseif (LEqual(lpC0, c21c)) {
298			Store("Deleted Objects:", Debug)
299		} elseif (LEqual(lpC0, c21d)) {
300			Store("Miscellaneous Stat:", Debug)
301		}
302
303		if (LGreaterEqual(lpC0, c21d)) {
304			Store(DerefOf(Index(arg0, lpC0)), Debug)
305		} elseif (LGreaterEqual(lpC0, c21c)) {
306			Store(DerefOf(Index(arg0, lpC0)), Local0)
307			m3a1(Local0, Local1)
308			Increment(Local1)
309		} elseif (LGreaterEqual(lpC0, c21b)) {
310			Store(DerefOf(Index(arg0, lpC0)), Local0)
311			m3a1(Local0, Local2)
312			Increment(Local2)
313		} else {
314			Store(DerefOf(Index(arg0, lpC0)), Debug)
315		}
316
317		Decrement(lpN0)
318		Increment(lpC0)
319	}
320}
321
322/*
323 * Calculate the difference between the two
324 * Memory Consumption Statistics Packages.
325 *
326 * arg0 - Package of _TCI-end statistics
327 * arg1 - Package of _TCI-begin statistics
328 * arg2 - Package for _TCI-end-begin difference
329 */
330Method(m3a3, 3, Serialized)
331{
332	Name(lpN0, 0)
333	Name(lpC0, 0)
334
335	Store(c220, lpN0)
336	Store(0, lpC0)
337
338	While (lpN0) {
339		Store(DerefOf(Index(arg0, lpC0)), Local0)
340		Store(DerefOf(Index(arg1, lpC0)), Local1)
341		Subtract(Local1, Local0, Local2)
342		Store(Local2, Index(arg2, lpC0))
343
344		Decrement(lpN0)
345		Increment(lpC0)
346	}
347}
348
349/*
350 * Verify difference of Memory Consumption Statistics between
351 * two points: _TCI-end statistics and _TCI-begin statistics
352 * (and reset locations of Command of arg0 and arg1 Packages
353 * for the following run).
354 *
355 * Check that the Memory Consumption Statistics measured at the first point
356 * as '_TCI-end statistics' was then changed as expected to the second point
357 * where statistics was measured as '_TCI-begin statistics'. Between these
358 * two points we initiate some AML activity which involves the memory
359 * consumption acquire/release to be then analyzed and verified.
360 *
361 *
362 * arg0 - Package of _TCI-end statistics
363 * arg1 - Package of _TCI-begin statistics
364 * arg2 - Package for _TCI-end-begin difference
365 * arg3 - Package with the benchmark information on Created Objects
366 * arg4 - Package with the benchmark information on Deleted Objects
367 *        (if non-Package, then arg3 is used)
368 * arg5 - Package with the benchmark information on memory acq0 and rel0
369 *        (if non-Package, then compare acq0 and rel0 of arg2,
370 *         otherwise, arg5 is a Package with the expected per-memory
371 *         type differencies, expected: acq0[i] - rel0[i] = arg5[i])
372 * arg6 - index of checking (inside the file)
373 *
374 * Return:
375 *           0 - success
376 *           1 - incorrect Memory Consumption Statistics encountered
377 *   otherwise - failed to determine the Memory Consumption Statistics
378 *
379 * See: the time of execution can be reduced (design and use additional flags):
380 * - exclude initialization before each operation
381 *   (ACPICA writes all elements, benchmarks for the
382 *   following sub-test mostly differ previous ones)
383 * - restrict checkings (use flag) by the acq0 & rel0,
384 *   and add & del.
385 */
386Method(m3a4, 7, Serialized)
387{
388
389	// Flag of printing
390	Name(pr1, 0)
391	Name(pr2, 0)
392
393	Name(lpN0, 0)
394	Name(lpC0, 0)
395
396	if (pr1) {
397		m3a2(arg0, 0)
398		m3a2(arg1, 1)
399	}
400
401	if (pr2) {
402		m3a2(arg2, 2)
403	}
404
405	Store(0, Local7)
406
407
408	// Check headers of Packages
409
410
411	if (m3a6(arg0, 0, arg6)) {
412		Store(2, Local7)
413	}
414
415	if (m3a6(arg1, 1, arg6)) {
416		Store(2, Local7)
417	}
418
419
420	// Check statistics specified by index
421
422
423	if (m3a7(arg0, 0, arg6)) {
424		Store(2, Local7)
425	}
426
427	if (m3a7(arg1, 0, arg6)) {
428		Store(2, Local7)
429	}
430
431	if (m3a7(arg2, 1, arg6)) {
432		Store(2, Local7)
433	}
434
435
436	/*
437	 * acq0 and rel0 of arg2-difference
438	 * are to be equal each to another
439	 * (or correspond to arg5):
440	 */
441
442
443	if (LEqual(ObjectType(arg5), c00c)) {
444		Store(c211, Local0)
445		Store(c217, Local1)
446		Store(0, Local4)
447
448		Store(c221, lpN0)
449		Store(0, lpC0)
450		While (lpN0) {
451			Store(DerefOf(Index(arg2, Local0)), Local2)
452			Store(DerefOf(Index(arg2, Local1)), Local3)
453			Store(DerefOf(Index(arg5, Local4)), Local5)
454
455			Subtract(Local2, Local3, Local6)
456
457			if (LNotEqual(Local6, Local5)) {
458				if (LNot(DE00)) {
459					err("m3a4", z128, 1, 0, arg6, Local6, Local5)
460					Store(lpC0, Debug)
461					Store(Local0, Debug)
462					Store(Local1, Debug)
463					Store(Local4, Debug)
464					Store(Local2, Debug)
465					Store(Local3, Debug)
466					Store(Local5, Debug)
467					Store(Local6, Debug)
468				}
469				Store(1, Local7)
470			}
471
472			Increment(Local0)
473			Increment(Local1)
474			Increment(Local4)
475
476			Decrement(lpN0)
477			Increment(lpC0)
478		}
479	} else {
480		Store(c211, Local0)
481		Store(c217, Local1)
482		Store(c221, lpN0)
483		Store(0, lpC0)
484		While (lpN0) {
485			Store(DerefOf(Index(arg2, Local0)), Local2)
486			Store(DerefOf(Index(arg2, Local1)), Local3)
487			if (LNotEqual(Local2, Local3)) {
488				if (LNot(DE00)) {
489					err("m3a4", z128, 2, 0, arg6, Local2, Local3)
490				}
491				Store(1, Local7)
492			}
493			Increment(Local0)
494			Increment(Local1)
495			Decrement(lpN0)
496			Increment(lpC0)
497		}
498	}
499
500
501	// arg2-difference: acq0 == acq3 + acq5
502
503
504	Store(c211, Local0)
505	Store(c214, Local1)
506	Store(c216, Local2)
507
508	Store(c221, lpN0)
509	Store(0, lpC0)
510
511	While (lpN0) {
512		Store(DerefOf(Index(arg2, Local0)), Local3)
513		Store(DerefOf(Index(arg2, Local1)), Local4)
514		Store(DerefOf(Index(arg2, Local2)), Local5)
515		Add(Local4, Local5, Local6)
516		if (LNotEqual(Local3, Local6)) {
517			if (LNot(DE00)) {
518				err("m3a4", z128, 3, 0, arg6, Local3, Local6)
519			}
520			Store(1, Local7)
521		}
522		Increment(Local0)
523		Increment(Local1)
524		Increment(Local2)
525
526		Decrement(lpN0)
527		Increment(lpC0)
528	}
529
530
531	// arg2-difference: rel0 == rel1 + rel3
532
533
534	Store(c217, Local0)
535	Store(c218, Local1)
536	Store(c21a, Local2)
537
538	Store(c221, lpN0)
539	Store(0, lpC0)
540
541	While (lpN0) {
542		Store(DerefOf(Index(arg2, Local0)), Local3)
543		Store(DerefOf(Index(arg2, Local1)), Local4)
544		Store(DerefOf(Index(arg2, Local2)), Local5)
545		Add(Local4, Local5, Local6)
546		if (LNotEqual(Local3, Local6)) {
547			if (LNot(DE00)) {
548				err("m3a4", z128, 4, 0, arg6, Local3, Local6)
549			}
550			Store(1, Local7)
551		}
552		Increment(Local0)
553		Increment(Local1)
554		Increment(Local2)
555
556		Decrement(lpN0)
557		Increment(lpC0)
558	}
559
560
561	// Check, created Objects are identical to the benchmark ones
562
563
564	if (LEqual(ObjectType(arg3), c00c)) {
565
566		Store(c027, lpN0)
567		Store(c21b, Local0)
568		Store(0, Local1)
569		While (lpN0) {
570			Store(DerefOf(Index(arg2, Local0)), Local2)
571			Store(DerefOf(Index(arg3, Local1)), Local3)
572			if (LNotEqual(Local2, Local3)) {
573				if (LNot(DE00)) {
574					err("m3a4", z128, 5, 0, arg6, Local2, Local3)
575				}
576				Store(1, Local7)
577			}
578
579			Increment(Local0)
580			Increment(Local1)
581
582			Decrement(lpN0)
583		}
584	}
585
586
587	// Check, deleted Objects are identical to the benchmark ones
588
589
590	Store(c027, lpN0)
591
592	Store(c21c, Local0)
593	Store(0, Local1)
594	Store(0, Local4)
595
596	if (Lequal(ObjectType(arg4), c00c)) {
597		Store(arg4, Local4)
598	} elseif (Lequal(ObjectType(arg3), c00c)) {
599		Store(arg3, Local4)
600	}
601
602	if (Lequal(ObjectType(Local4), c00c)) {
603		While (lpN0) {
604			Store(DerefOf(Index(arg2, Local0)), Local2)
605			Store(DerefOf(Index(Local4, Local1)), Local3)
606			if (LNotEqual(Local2, Local3)) {
607				if (LNot(DE00)) {
608					err("m3a4", z128, 6, 0, arg6, Local2, Local3)
609				}
610				Store(1, Local7)
611			}
612
613			Increment(Local0)
614			Increment(Local1)
615
616			Decrement(lpN0)
617		}
618	}
619
620	/*
621	 * Reset locations of Command of arg0 and arg1
622	 * Packages for the following run.
623	 * Store(0, Index(arg0, c224))
624	 * Store(0, Index(arg1, c224))
625	 */
626
627	return (Local7)
628}
629
630/*
631 * Return non-zero in case the Test Command interface
632 * with the ACPICA (_TCI) is supported.
633 */
634Method(m3a5)
635{
636	Store(m3a0(c202), Local0)	// TCI_CMD_CHECK_SUPPORTED
637
638	_TCI(c202, Local0)
639
640	Store(DerefOf(Index(Local0, c224)), Local1)
641
642	if (LNotEqual(Local1, c202)) {
643		return (0)
644	}
645
646	return (1)
647}
648
649/*
650 * Check header of Memory Consumption Statistics Package
651 * arg0 - Memory Consumption Statistics Package
652 * arg1 - Means:
653 *        0         - _TCI-end statistics
654 *        otherwise - _TCI-begin statistics
655 * arg2 - index of checking (inside the file)
656 */
657Method(m3a6, 3)
658{
659	Store(0, Local7)
660
661	// Tag of command
662
663	if (arg1) {
664		Store(c209, Local0)
665	} else {
666		Store(c208, Local0)
667	}
668
669	Store(DerefOf(Index(arg0, 0)), Local1)
670	if (LNotEqual(Local1, Local0)) {
671		err("m3a6", z128, 7, 0, arg2, Local1, Local0)
672		Store(1, Local7)
673	}
674
675	// Number of elements actually packed
676
677	Store(DerefOf(Index(arg0, 1)), Local1)
678	if (LNotEqual(Local1, c220)) {
679		err("m3a6", z128, 8, 0, arg2, Local1, c220)
680		Store(1, Local7)
681	}
682
683	// Command has been executed
684
685	if (arg1) {
686		Store(c201, Local0)
687	} else {
688		Store(c200, Local0)
689	}
690
691	Store(DerefOf(Index(arg0, 2)), Local1)
692	if (LNotEqual(Local1, Local0)) {
693		err("m3a6", z128, 9, 0, arg2, Local1, Local0)
694		Store(1, Local7)
695	}
696
697	// Object cache is enabled
698
699	Store(DerefOf(Index(arg0, 3)), Local1)
700	if (LNot(Local1)) {
701		err("m3a6", z128, 10, 0, arg2, Local1, 1)
702		Store(1, Local7)
703	}
704
705	return (Local7)
706}
707
708/*
709 * Check statistics specified by index
710 *
711 * arg0 - Memory Consumption Statistics Package
712 * arg1 - Means:
713 *        non-zero  - _TCI-end-begin difference Package
714 *        otherwise - usual Memory Consumption Statistics Package
715 * arg2 - index of checking (inside the file)
716 */
717Method(m3a7, 3)
718{
719	Store(0, Local7)
720
721	if (arg1) {
722
723/*
724		// ACPI_STAT_SUCCESS_FREE == ACPI_STAT_SUCCESS_ALLOC
725
726		Add(c21d, 5, Local0)
727		Store(DerefOf(Index(arg0, Local0)), Local1)
728		Increment(Local0)
729		Store(DerefOf(Index(arg0, Local0)), Local2)
730
731		if (LNotEqual(Local2, Local1)) {
732			err("m3a7", z128, 11, 0, arg2, Local2, Local1)
733			Store(1, Local7)
734		}
735*/
736
737	} else {
738
739		// ACPI_STAT_INVALID_EXBUF
740
741		Store(c21d, Local0)
742		Store(DerefOf(Index(arg0, Local0)), Local1)
743		if (Local1) {
744			err("m3a7", z128, 12, 0, arg2, Local1, 0)
745			Store(1, Local7)
746		}
747
748		// ACPI_STAT_ZONE0_CORRUPTED
749
750		Increment(Local0)
751		Store(DerefOf(Index(arg0, Local0)), Local1)
752		if (Local1) {
753			err("m3a7", z128, 13, 0, arg2, Local1, 0)
754			Store(1, Local7)
755		}
756
757		// ACPI_STAT_ZONE1_CORRUPTED
758
759		Increment(Local0)
760		Store(DerefOf(Index(arg0, Local0)), Local1)
761		if (Local1) {
762			err("m3a7", z128, 14, 0, arg2, Local1, 0)
763			Store(1, Local7)
764		}
765
766		// ACPI_STAT_FAILED_ALLOC
767
768		Increment(Local0)
769		Store(DerefOf(Index(arg0, Local0)), Local1)
770		if (Local1) {
771			err("m3a7", z128, 15, 0, arg2, Local1, 0)
772			Store(1, Local7)
773		}
774
775		// ACPI_STAT_NULL_FREE
776
777		Increment(Local0)
778		Store(DerefOf(Index(arg0, Local0)), Local1)
779		if (Local1) {
780			err("m3a7", z128, 16, 0, arg2, Local1, 0)
781			Store(1, Local7)
782		}
783	}
784
785	return (Local7)
786}
787
788/*
789 * Create and initialize the sample Package for the
790 * per-object type benchmark Memory Consumption Statistics
791 */
792Method(m3a8,, Serialized)
793{
794	Name(p000, Package() {
795		0,0,0,0,0,0,0,0,0,0,
796		0,0,0,0,0,0,0,0,0,0,
797		0,0,0,0,0,0,0,0,0,0,
798		0,0})
799
800	return (p000)
801}
802
803/*
804 * Create and initialize the sample Package for the
805 * per-memory type benchmark Memory Consumption Statistics
806 */
807Method(m3a9,, Serialized)
808{
809	Name(p000, Package() {0,0,0,0,0,0,0})
810
811	return (p000)
812}
813
814/*
815 * Determine the flag of optimization: check that
816 * processing of the Add operation corresponds to
817 * the expectation: optimized/non-optimized.
818 *
819 * Mode of run, optimized/non-optimized, is essential
820 * for this kind tests (memory consumption).
821 *
822 * arg0 - Means:
823 *           0 - check for Optimization is tuned off
824 *   otherwise - check for Optimization is tuned on
825 */
826Method(m3aa,, Serialized)
827{
828	Name(i000, 0)
829	Name(p000, Package(1) {})
830	Name(p00b, Package(1) {})
831
832	Store(0xff, FOPT)
833
834	Store(m3a0(c200), Local0)	// _TCI-end statistics
835	Store(m3a0(c201), p00b)		// _TCI-begin statistics
836	Store(m3a0(0), Local1)		// difference
837
838	_TCI(c200, Local0)
839	Store(Add(3, 4), i000)
840	_TCI(c201, p00b)
841
842	m3a3(Local0, p00b, Local1)
843
844	// Statistics expected in case Optimization is tuned off
845	Store(m3a8(), p000)
846	Store(4, Index(p000, c009)) // Integer
847
848	Store(1, DE00)
849	Store(m3a4(Local0, p00b, Local1, p000, 0, 0, 0), Local6)
850	Store(0, DE00)
851
852	if (LEqual(Local6, 2)) {
853		Store("Failed to determine the flag of optimization", Debug)
854		return
855	} else {
856		// Statistics expected in case Optimization is tuned on
857		Store(m3a8(), p000)
858		Store(1, Index(p000, c009)) // Integer
859
860		Store(1, DE00)
861		Store(m3a4(Local0, p00b, Local1, p000, 0, 0, 1), Local7)
862		Store(0, DE00)
863
864		if (LEqual(Local7, 2)) {
865			Store("Failed to determine the flag of optimization", Debug)
866			return
867		}
868	}
869
870	if (LEqual(Local6, Local7)) {
871		Store("Internal error 0", Debug)
872		err("m3aa", z128, 17, 0, 0, Local6, Local7)
873	} elseif (Local6) {
874		Store(1, FOPT)
875	} else {
876		Store(0, FOPT)
877	}
878}
879
880/*
881 * Return Package with the array of thread indexes
882 * otherwise Integer 0.
883 *
884 * arg0 - number of threads
885 */
886Method(m163, 1, Serialized)
887{
888	Name(size, 0)
889
890	Add(c22f, arg0, size)
891
892	Store(m165(c203, size), Local0)	// TCI_CMD_GET_ID_OF_THREADS
893
894	_TCI(c203, Local0)
895
896	Store(DerefOf(Index(Local0, c224)), Local1)
897
898	if (LNotEqual(Local1, c203)) {
899		return (0)
900	}
901
902	return (Local0)
903}
904