Merge branch develop-3.10 into develop-3.10-next
[firefly-linux-kernel-4.4.55.git] / drivers / acpi / acpica / aclocal.h
1 /******************************************************************************
2  *
3  * Name: aclocal.h - Internal data types used across the ACPI subsystem
4  *
5  *****************************************************************************/
6
7 /*
8  * Copyright (C) 2000 - 2013, Intel Corp.
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions, and the following disclaimer,
16  *    without modification.
17  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18  *    substantially similar to the "NO WARRANTY" disclaimer below
19  *    ("Disclaimer") and any redistribution must be conditioned upon
20  *    including a substantially similar Disclaimer requirement for further
21  *    binary redistribution.
22  * 3. Neither the names of the above-listed copyright holders nor the names
23  *    of any contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * Alternatively, this software may be distributed under the terms of the
27  * GNU General Public License ("GPL") version 2 as published by the Free
28  * Software Foundation.
29  *
30  * NO WARRANTY
31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41  * POSSIBILITY OF SUCH DAMAGES.
42  */
43
44 #ifndef __ACLOCAL_H__
45 #define __ACLOCAL_H__
46
47 /* acpisrc:struct_defs -- for acpisrc conversion */
48
49 #define ACPI_SERIALIZED                 0xFF
50
51 typedef u32 acpi_mutex_handle;
52 #define ACPI_GLOBAL_LOCK                (acpi_semaphore) (-1)
53
54 /* Total number of aml opcodes defined */
55
56 #define AML_NUM_OPCODES                 0x81
57
58 /* Forward declarations */
59
60 struct acpi_walk_state;
61 struct acpi_obj_mutex;
62 union acpi_parse_object;
63
64 /*****************************************************************************
65  *
66  * Mutex typedefs and structs
67  *
68  ****************************************************************************/
69
70 /*
71  * Predefined handles for the mutex objects used within the subsystem
72  * All mutex objects are automatically created by acpi_ut_mutex_initialize.
73  *
74  * The acquire/release ordering protocol is implied via this list. Mutexes
75  * with a lower value must be acquired before mutexes with a higher value.
76  *
77  * NOTE: any changes here must be reflected in the acpi_gbl_mutex_names
78  * table below also!
79  */
80 #define ACPI_MTX_INTERPRETER            0       /* AML Interpreter, main lock */
81 #define ACPI_MTX_NAMESPACE              1       /* ACPI Namespace */
82 #define ACPI_MTX_TABLES                 2       /* Data for ACPI tables */
83 #define ACPI_MTX_EVENTS                 3       /* Data for ACPI events */
84 #define ACPI_MTX_CACHES                 4       /* Internal caches, general purposes */
85 #define ACPI_MTX_MEMORY                 5       /* Debug memory tracking lists */
86 #define ACPI_MTX_DEBUG_CMD_COMPLETE     6       /* AML debugger */
87 #define ACPI_MTX_DEBUG_CMD_READY        7       /* AML debugger */
88
89 #define ACPI_MAX_MUTEX                  7
90 #define ACPI_NUM_MUTEX                  ACPI_MAX_MUTEX+1
91
92 /* Lock structure for reader/writer interfaces */
93
94 struct acpi_rw_lock {
95         acpi_mutex writer_mutex;
96         acpi_mutex reader_mutex;
97         u32 num_readers;
98 };
99
100 /*
101  * Predefined handles for spinlocks used within the subsystem.
102  * These spinlocks are created by acpi_ut_mutex_initialize
103  */
104 #define ACPI_LOCK_GPES                  0
105 #define ACPI_LOCK_HARDWARE              1
106
107 #define ACPI_MAX_LOCK                   1
108 #define ACPI_NUM_LOCK                   ACPI_MAX_LOCK+1
109
110 /* This Thread ID means that the mutex is not in use (unlocked) */
111
112 #define ACPI_MUTEX_NOT_ACQUIRED         (acpi_thread_id) 0
113
114 /* Table for the global mutexes */
115
116 struct acpi_mutex_info {
117         acpi_mutex mutex;
118         u32 use_count;
119         acpi_thread_id thread_id;
120 };
121
122 /* Lock flag parameter for various interfaces */
123
124 #define ACPI_MTX_DO_NOT_LOCK            0
125 #define ACPI_MTX_LOCK                   1
126
127 /* Field access granularities */
128
129 #define ACPI_FIELD_BYTE_GRANULARITY     1
130 #define ACPI_FIELD_WORD_GRANULARITY     2
131 #define ACPI_FIELD_DWORD_GRANULARITY    4
132 #define ACPI_FIELD_QWORD_GRANULARITY    8
133
134 #define ACPI_ENTRY_NOT_FOUND            NULL
135
136 /*****************************************************************************
137  *
138  * Namespace typedefs and structs
139  *
140  ****************************************************************************/
141
142 /* Operational modes of the AML interpreter/scanner */
143
144 typedef enum {
145         ACPI_IMODE_LOAD_PASS1 = 0x01,
146         ACPI_IMODE_LOAD_PASS2 = 0x02,
147         ACPI_IMODE_EXECUTE = 0x03
148 } acpi_interpreter_mode;
149
150 /*
151  * The Namespace Node describes a named object that appears in the AML.
152  * descriptor_type is used to differentiate between internal descriptors.
153  *
154  * The node is optimized for both 32-bit and 64-bit platforms:
155  * 20 bytes for the 32-bit case, 32 bytes for the 64-bit case.
156  *
157  * Note: The descriptor_type and Type fields must appear in the identical
158  * position in both the struct acpi_namespace_node and union acpi_operand_object
159  * structures.
160  */
161 struct acpi_namespace_node {
162         union acpi_operand_object *object;      /* Interpreter object */
163         u8 descriptor_type;     /* Differentiate object descriptor types */
164         u8 type;                /* ACPI Type associated with this name */
165         u8 flags;               /* Miscellaneous flags */
166         acpi_owner_id owner_id; /* Node creator */
167         union acpi_name_union name;     /* ACPI Name, always 4 chars per ACPI spec */
168         struct acpi_namespace_node *parent;     /* Parent node */
169         struct acpi_namespace_node *child;      /* First child */
170         struct acpi_namespace_node *peer;       /* First peer */
171
172         /*
173          * The following fields are used by the ASL compiler and disassembler only
174          */
175 #ifdef ACPI_LARGE_NAMESPACE_NODE
176         union acpi_parse_object *op;
177         u32 value;
178         u32 length;
179 #endif
180 };
181
182 /* Namespace Node flags */
183
184 #define ANOBJ_RESERVED                  0x01    /* Available for use */
185 #define ANOBJ_TEMPORARY                 0x02    /* Node is create by a method and is temporary */
186 #define ANOBJ_METHOD_ARG                0x04    /* Node is a method argument */
187 #define ANOBJ_METHOD_LOCAL              0x08    /* Node is a method local */
188 #define ANOBJ_SUBTREE_HAS_INI           0x10    /* Used to optimize device initialization */
189 #define ANOBJ_EVALUATED                 0x20    /* Set on first evaluation of node */
190 #define ANOBJ_ALLOCATED_BUFFER          0x40    /* Method AML buffer is dynamic (install_method) */
191
192 #define ANOBJ_IS_EXTERNAL               0x08    /* iASL only: This object created via External() */
193 #define ANOBJ_METHOD_NO_RETVAL          0x10    /* iASL only: Method has no return value */
194 #define ANOBJ_METHOD_SOME_NO_RETVAL     0x20    /* iASL only: Method has at least one return value */
195 #define ANOBJ_IS_REFERENCED             0x80    /* iASL only: Object was referenced */
196
197 /* Internal ACPI table management - master table list */
198
199 struct acpi_table_list {
200         struct acpi_table_desc *tables; /* Table descriptor array */
201         u32 current_table_count;        /* Tables currently in the array */
202         u32 max_table_count;    /* Max tables array will hold */
203         u8 flags;
204 };
205
206 /* Flags for above */
207
208 #define ACPI_ROOT_ORIGIN_UNKNOWN        (0)     /* ~ORIGIN_ALLOCATED */
209 #define ACPI_ROOT_ORIGIN_ALLOCATED      (1)
210 #define ACPI_ROOT_ALLOW_RESIZE          (2)
211
212 /* Predefined (fixed) table indexes */
213
214 #define ACPI_TABLE_INDEX_DSDT           (0)
215 #define ACPI_TABLE_INDEX_FACS           (1)
216
217 struct acpi_find_context {
218         char *search_for;
219         acpi_handle *list;
220         u32 *count;
221 };
222
223 struct acpi_ns_search_data {
224         struct acpi_namespace_node *node;
225 };
226
227 /* Object types used during package copies */
228
229 #define ACPI_COPY_TYPE_SIMPLE           0
230 #define ACPI_COPY_TYPE_PACKAGE          1
231
232 /* Info structure used to convert external<->internal namestrings */
233
234 struct acpi_namestring_info {
235         const char *external_name;
236         const char *next_external_char;
237         char *internal_name;
238         u32 length;
239         u32 num_segments;
240         u32 num_carats;
241         u8 fully_qualified;
242 };
243
244 /* Field creation info */
245
246 struct acpi_create_field_info {
247         struct acpi_namespace_node *region_node;
248         struct acpi_namespace_node *field_node;
249         struct acpi_namespace_node *register_node;
250         struct acpi_namespace_node *data_register_node;
251         struct acpi_namespace_node *connection_node;
252         u8 *resource_buffer;
253         u32 bank_value;
254         u32 field_bit_position;
255         u32 field_bit_length;
256         u16 resource_length;
257         u16 pin_number_index;
258         u8 field_flags;
259         u8 attribute;
260         u8 field_type;
261         u8 access_length;
262 };
263
264 typedef
265 acpi_status(*acpi_internal_method) (struct acpi_walk_state * walk_state);
266
267 /*
268  * Bitmapped ACPI types. Used internally only
269  */
270 #define ACPI_BTYPE_ANY                  0x00000000
271 #define ACPI_BTYPE_INTEGER              0x00000001
272 #define ACPI_BTYPE_STRING               0x00000002
273 #define ACPI_BTYPE_BUFFER               0x00000004
274 #define ACPI_BTYPE_PACKAGE              0x00000008
275 #define ACPI_BTYPE_FIELD_UNIT           0x00000010
276 #define ACPI_BTYPE_DEVICE               0x00000020
277 #define ACPI_BTYPE_EVENT                0x00000040
278 #define ACPI_BTYPE_METHOD               0x00000080
279 #define ACPI_BTYPE_MUTEX                0x00000100
280 #define ACPI_BTYPE_REGION               0x00000200
281 #define ACPI_BTYPE_POWER                0x00000400
282 #define ACPI_BTYPE_PROCESSOR            0x00000800
283 #define ACPI_BTYPE_THERMAL              0x00001000
284 #define ACPI_BTYPE_BUFFER_FIELD         0x00002000
285 #define ACPI_BTYPE_DDB_HANDLE           0x00004000
286 #define ACPI_BTYPE_DEBUG_OBJECT         0x00008000
287 #define ACPI_BTYPE_REFERENCE            0x00010000
288 #define ACPI_BTYPE_RESOURCE             0x00020000
289
290 #define ACPI_BTYPE_COMPUTE_DATA         (ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING | ACPI_BTYPE_BUFFER)
291
292 #define ACPI_BTYPE_DATA                 (ACPI_BTYPE_COMPUTE_DATA  | ACPI_BTYPE_PACKAGE)
293 #define ACPI_BTYPE_DATA_REFERENCE       (ACPI_BTYPE_DATA | ACPI_BTYPE_REFERENCE | ACPI_BTYPE_DDB_HANDLE)
294 #define ACPI_BTYPE_DEVICE_OBJECTS       (ACPI_BTYPE_DEVICE | ACPI_BTYPE_THERMAL | ACPI_BTYPE_PROCESSOR)
295 #define ACPI_BTYPE_OBJECTS_AND_REFS     0x0001FFFF      /* ARG or LOCAL */
296 #define ACPI_BTYPE_ALL_OBJECTS          0x0000FFFF
297
298 #pragma pack(1)
299
300 /*
301  * Information structure for ACPI predefined names.
302  * Each entry in the table contains the following items:
303  *
304  * name                 - The ACPI reserved name
305  * param_count          - Number of arguments to the method
306  * expected_return_btypes - Allowed type(s) for the return value
307  */
308 struct acpi_name_info {
309         char name[ACPI_NAME_SIZE];
310         u16 argument_list;
311         u8 expected_btypes;
312 };
313
314 /*
315  * Secondary information structures for ACPI predefined objects that return
316  * package objects. This structure appears as the next entry in the table
317  * after the NAME_INFO structure above.
318  *
319  * The reason for this is to minimize the size of the predefined name table.
320  */
321
322 /*
323  * Used for ACPI_PTYPE1_FIXED, ACPI_PTYPE1_VAR, ACPI_PTYPE2,
324  * ACPI_PTYPE2_MIN, ACPI_PTYPE2_PKG_COUNT, ACPI_PTYPE2_COUNT,
325  * ACPI_PTYPE2_FIX_VAR
326  */
327 struct acpi_package_info {
328         u8 type;
329         u8 object_type1;
330         u8 count1;
331         u8 object_type2;
332         u8 count2;
333         u16 reserved;
334 };
335
336 /* Used for ACPI_PTYPE2_FIXED */
337
338 struct acpi_package_info2 {
339         u8 type;
340         u8 count;
341         u8 object_type[4];
342         u8 reserved;
343 };
344
345 /* Used for ACPI_PTYPE1_OPTION */
346
347 struct acpi_package_info3 {
348         u8 type;
349         u8 count;
350         u8 object_type[2];
351         u8 tail_object_type;
352         u16 reserved;
353 };
354
355 union acpi_predefined_info {
356         struct acpi_name_info info;
357         struct acpi_package_info ret_info;
358         struct acpi_package_info2 ret_info2;
359         struct acpi_package_info3 ret_info3;
360 };
361
362 /* Reset to default packing */
363
364 #pragma pack()
365
366 /* Data block used during object validation */
367
368 struct acpi_predefined_data {
369         char *pathname;
370         const union acpi_predefined_info *predefined;
371         union acpi_operand_object *parent_package;
372         struct acpi_namespace_node *node;
373         u32 flags;
374         u32 return_btype;
375         u8 node_flags;
376 };
377
378 /* Defines for Flags field above */
379
380 #define ACPI_OBJECT_REPAIRED    1
381 #define ACPI_OBJECT_WRAPPED     2
382
383 /* Return object auto-repair info */
384
385 typedef acpi_status(*acpi_object_converter) (union acpi_operand_object
386                                              *original_object,
387                                              union acpi_operand_object
388                                              **converted_object);
389
390 struct acpi_simple_repair_info {
391         char name[ACPI_NAME_SIZE];
392         u32 unexpected_btypes;
393         u32 package_index;
394         acpi_object_converter object_converter;
395 };
396
397 /*
398  * Bitmapped return value types
399  * Note: the actual data types must be contiguous, a loop in nspredef.c
400  * depends on this.
401  */
402 #define ACPI_RTYPE_ANY                  0x00
403 #define ACPI_RTYPE_NONE                 0x01
404 #define ACPI_RTYPE_INTEGER              0x02
405 #define ACPI_RTYPE_STRING               0x04
406 #define ACPI_RTYPE_BUFFER               0x08
407 #define ACPI_RTYPE_PACKAGE              0x10
408 #define ACPI_RTYPE_REFERENCE            0x20
409 #define ACPI_RTYPE_ALL                  0x3F
410
411 #define ACPI_NUM_RTYPES                 5       /* Number of actual object types */
412
413 /*****************************************************************************
414  *
415  * Event typedefs and structs
416  *
417  ****************************************************************************/
418
419 /* Dispatch info for each GPE -- either a method or handler, cannot be both */
420
421 struct acpi_gpe_handler_info {
422         acpi_gpe_handler address;       /* Address of handler, if any */
423         void *context;          /* Context to be passed to handler */
424         struct acpi_namespace_node *method_node;        /* Method node for this GPE level (saved) */
425         u8 original_flags;      /* Original (pre-handler) GPE info */
426         u8 originally_enabled;  /* True if GPE was originally enabled */
427 };
428
429 /* Notify info for implicit notify, multiple device objects */
430
431 struct acpi_gpe_notify_info {
432         struct acpi_namespace_node *device_node;        /* Device to be notified */
433         struct acpi_gpe_notify_info *next;
434 };
435
436 /*
437  * GPE dispatch info. At any time, the GPE can have at most one type
438  * of dispatch - Method, Handler, or Implicit Notify.
439  */
440 union acpi_gpe_dispatch_info {
441         struct acpi_namespace_node *method_node;        /* Method node for this GPE level */
442         struct acpi_gpe_handler_info *handler;  /* Installed GPE handler */
443         struct acpi_gpe_notify_info *notify_list;       /* List of _PRW devices for implicit notifies */
444 };
445
446 /*
447  * Information about a GPE, one per each GPE in an array.
448  * NOTE: Important to keep this struct as small as possible.
449  */
450 struct acpi_gpe_event_info {
451         union acpi_gpe_dispatch_info dispatch;  /* Either Method, Handler, or notify_list */
452         struct acpi_gpe_register_info *register_info;   /* Backpointer to register info */
453         u8 flags;               /* Misc info about this GPE */
454         u8 gpe_number;          /* This GPE */
455         u8 runtime_count;       /* References to a run GPE */
456 };
457
458 /* Information about a GPE register pair, one per each status/enable pair in an array */
459
460 struct acpi_gpe_register_info {
461         struct acpi_generic_address status_address;     /* Address of status reg */
462         struct acpi_generic_address enable_address;     /* Address of enable reg */
463         u8 enable_for_wake;     /* GPEs to keep enabled when sleeping */
464         u8 enable_for_run;      /* GPEs to keep enabled when running */
465         u8 base_gpe_number;     /* Base GPE number for this register */
466 };
467
468 /*
469  * Information about a GPE register block, one per each installed block --
470  * GPE0, GPE1, and one per each installed GPE Block Device.
471  */
472 struct acpi_gpe_block_info {
473         struct acpi_namespace_node *node;
474         struct acpi_gpe_block_info *previous;
475         struct acpi_gpe_block_info *next;
476         struct acpi_gpe_xrupt_info *xrupt_block;        /* Backpointer to interrupt block */
477         struct acpi_gpe_register_info *register_info;   /* One per GPE register pair */
478         struct acpi_gpe_event_info *event_info; /* One for each GPE */
479         struct acpi_generic_address block_address;      /* Base address of the block */
480         u32 register_count;     /* Number of register pairs in block */
481         u16 gpe_count;          /* Number of individual GPEs in block */
482         u8 block_base_number;   /* Base GPE number for this block */
483         u8 initialized;         /* TRUE if this block is initialized */
484 };
485
486 /* Information about GPE interrupt handlers, one per each interrupt level used for GPEs */
487
488 struct acpi_gpe_xrupt_info {
489         struct acpi_gpe_xrupt_info *previous;
490         struct acpi_gpe_xrupt_info *next;
491         struct acpi_gpe_block_info *gpe_block_list_head;        /* List of GPE blocks for this xrupt */
492         u32 interrupt_number;   /* System interrupt number */
493 };
494
495 struct acpi_gpe_walk_info {
496         struct acpi_namespace_node *gpe_device;
497         struct acpi_gpe_block_info *gpe_block;
498         u16 count;
499         acpi_owner_id owner_id;
500         u8 execute_by_owner_id;
501 };
502
503 struct acpi_gpe_device_info {
504         u32 index;
505         u32 next_block_base_index;
506         acpi_status status;
507         struct acpi_namespace_node *gpe_device;
508 };
509
510 typedef acpi_status(*acpi_gpe_callback) (struct acpi_gpe_xrupt_info *
511                                          gpe_xrupt_info,
512                                          struct acpi_gpe_block_info *gpe_block,
513                                          void *context);
514
515 /* Information about each particular fixed event */
516
517 struct acpi_fixed_event_handler {
518         acpi_event_handler handler;     /* Address of handler. */
519         void *context;          /* Context to be passed to handler */
520 };
521
522 struct acpi_fixed_event_info {
523         u8 status_register_id;
524         u8 enable_register_id;
525         u16 status_bit_mask;
526         u16 enable_bit_mask;
527 };
528
529 /* Information used during field processing */
530
531 struct acpi_field_info {
532         u8 skip_field;
533         u8 field_flag;
534         u32 pkg_length;
535 };
536
537 /*****************************************************************************
538  *
539  * Generic "state" object for stacks
540  *
541  ****************************************************************************/
542
543 #define ACPI_CONTROL_NORMAL                  0xC0
544 #define ACPI_CONTROL_CONDITIONAL_EXECUTING   0xC1
545 #define ACPI_CONTROL_PREDICATE_EXECUTING     0xC2
546 #define ACPI_CONTROL_PREDICATE_FALSE         0xC3
547 #define ACPI_CONTROL_PREDICATE_TRUE          0xC4
548
549 #define ACPI_STATE_COMMON \
550         void                            *next; \
551         u8                              descriptor_type; /* To differentiate various internal objs */\
552         u8                              flags; \
553         u16                             value; \
554         u16                             state;
555
556         /* There are 2 bytes available here until the next natural alignment boundary */
557
558 struct acpi_common_state {
559 ACPI_STATE_COMMON};
560
561 /*
562  * Update state - used to traverse complex objects such as packages
563  */
564 struct acpi_update_state {
565         ACPI_STATE_COMMON union acpi_operand_object *object;
566 };
567
568 /*
569  * Pkg state - used to traverse nested package structures
570  */
571 struct acpi_pkg_state {
572         ACPI_STATE_COMMON u16 index;
573         union acpi_operand_object *source_object;
574         union acpi_operand_object *dest_object;
575         struct acpi_walk_state *walk_state;
576         void *this_target_obj;
577         u32 num_packages;
578 };
579
580 /*
581  * Control state - one per if/else and while constructs.
582  * Allows nesting of these constructs
583  */
584 struct acpi_control_state {
585         ACPI_STATE_COMMON u16 opcode;
586         union acpi_parse_object *predicate_op;
587         u8 *aml_predicate_start;        /* Start of if/while predicate */
588         u8 *package_end;        /* End of if/while block */
589         u32 loop_count;         /* While() loop counter */
590 };
591
592 /*
593  * Scope state - current scope during namespace lookups
594  */
595 struct acpi_scope_state {
596         ACPI_STATE_COMMON struct acpi_namespace_node *node;
597 };
598
599 struct acpi_pscope_state {
600         ACPI_STATE_COMMON u32 arg_count;        /* Number of fixed arguments */
601         union acpi_parse_object *op;    /* Current op being parsed */
602         u8 *arg_end;            /* Current argument end */
603         u8 *pkg_end;            /* Current package end */
604         u32 arg_list;           /* Next argument to parse */
605 };
606
607 /*
608  * Thread state - one per thread across multiple walk states. Multiple walk
609  * states are created when there are nested control methods executing.
610  */
611 struct acpi_thread_state {
612         ACPI_STATE_COMMON u8 current_sync_level;        /* Mutex Sync (nested acquire) level */
613         struct acpi_walk_state *walk_state_list;        /* Head of list of walk_states for this thread */
614         union acpi_operand_object *acquired_mutex_list; /* List of all currently acquired mutexes */
615         acpi_thread_id thread_id;       /* Running thread ID */
616 };
617
618 /*
619  * Result values - used to accumulate the results of nested
620  * AML arguments
621  */
622 struct acpi_result_values {
623         ACPI_STATE_COMMON
624             union acpi_operand_object *obj_desc[ACPI_RESULTS_FRAME_OBJ_NUM];
625 };
626
627 typedef
628 acpi_status(*acpi_parse_downwards) (struct acpi_walk_state * walk_state,
629                                     union acpi_parse_object ** out_op);
630
631 typedef acpi_status(*acpi_parse_upwards) (struct acpi_walk_state * walk_state);
632
633 /* Global handlers for AML Notifies */
634
635 struct acpi_global_notify_handler {
636         acpi_notify_handler handler;
637         void *context;
638 };
639
640 /*
641  * Notify info - used to pass info to the deferred notify
642  * handler/dispatcher.
643  */
644 struct acpi_notify_info {
645         ACPI_STATE_COMMON u8 handler_list_id;
646         struct acpi_namespace_node *node;
647         union acpi_operand_object *handler_list_head;
648         struct acpi_global_notify_handler *global;
649 };
650
651 /* Generic state is union of structs above */
652
653 union acpi_generic_state {
654         struct acpi_common_state common;
655         struct acpi_control_state control;
656         struct acpi_update_state update;
657         struct acpi_scope_state scope;
658         struct acpi_pscope_state parse_scope;
659         struct acpi_pkg_state pkg;
660         struct acpi_thread_state thread;
661         struct acpi_result_values results;
662         struct acpi_notify_info notify;
663 };
664
665 /*****************************************************************************
666  *
667  * Interpreter typedefs and structs
668  *
669  ****************************************************************************/
670
671 typedef acpi_status(*acpi_execute_op) (struct acpi_walk_state * walk_state);
672
673 /* Address Range info block */
674
675 struct acpi_address_range {
676         struct acpi_address_range *next;
677         struct acpi_namespace_node *region_node;
678         acpi_physical_address start_address;
679         acpi_physical_address end_address;
680 };
681
682 /*****************************************************************************
683  *
684  * Parser typedefs and structs
685  *
686  ****************************************************************************/
687
688 /*
689  * AML opcode, name, and argument layout
690  */
691 struct acpi_opcode_info {
692 #if defined(ACPI_DISASSEMBLER) || defined(ACPI_DEBUG_OUTPUT)
693         char *name;             /* Opcode name (disassembler/debug only) */
694 #endif
695         u32 parse_args;         /* Grammar/Parse time arguments */
696         u32 runtime_args;       /* Interpret time arguments */
697         u16 flags;              /* Misc flags */
698         u8 object_type;         /* Corresponding internal object type */
699         u8 class;               /* Opcode class */
700         u8 type;                /* Opcode type */
701 };
702
703 /* Value associated with the parse object */
704
705 union acpi_parse_value {
706         u64 integer;            /* Integer constant (Up to 64 bits) */
707         u32 size;               /* bytelist or field size */
708         char *string;           /* NULL terminated string */
709         u8 *buffer;             /* buffer or string */
710         char *name;             /* NULL terminated string */
711         union acpi_parse_object *arg;   /* arguments and contained ops */
712 };
713
714 #ifdef ACPI_DISASSEMBLER
715 #define ACPI_DISASM_ONLY_MEMBERS(a)     a;
716 #else
717 #define ACPI_DISASM_ONLY_MEMBERS(a)
718 #endif
719
720 #define ACPI_PARSE_COMMON \
721         union acpi_parse_object         *parent;        /* Parent op */\
722         u8                              descriptor_type; /* To differentiate various internal objs */\
723         u8                              flags;          /* Type of Op */\
724         u16                             aml_opcode;     /* AML opcode */\
725         u32                             aml_offset;     /* Offset of declaration in AML */\
726         union acpi_parse_object         *next;          /* Next op */\
727         struct acpi_namespace_node      *node;          /* For use by interpreter */\
728         union acpi_parse_value          value;          /* Value or args associated with the opcode */\
729         u8                              arg_list_length; /* Number of elements in the arg list */\
730         ACPI_DISASM_ONLY_MEMBERS (\
731         u8                              disasm_flags;   /* Used during AML disassembly */\
732         u8                              disasm_opcode;  /* Subtype used for disassembly */\
733         char                            aml_op_name[16])        /* Op name (debug only) */
734
735 /* Flags for disasm_flags field above */
736
737 #define ACPI_DASM_BUFFER                0x00    /* Buffer is a simple data buffer */
738 #define ACPI_DASM_RESOURCE              0x01    /* Buffer is a Resource Descriptor */
739 #define ACPI_DASM_STRING                0x02    /* Buffer is a ASCII string */
740 #define ACPI_DASM_UNICODE               0x03    /* Buffer is a Unicode string */
741 #define ACPI_DASM_PLD_METHOD            0x04    /* Buffer is a _PLD method bit-packed buffer */
742 #define ACPI_DASM_EISAID                0x05    /* Integer is an EISAID */
743 #define ACPI_DASM_MATCHOP               0x06    /* Parent opcode is a Match() operator */
744 #define ACPI_DASM_LNOT_PREFIX           0x07    /* Start of a Lnot_equal (etc.) pair of opcodes */
745 #define ACPI_DASM_LNOT_SUFFIX           0x08    /* End  of a Lnot_equal (etc.) pair of opcodes */
746 #define ACPI_DASM_IGNORE                0x09    /* Not used at this time */
747
748 /*
749  * Generic operation (for example:  If, While, Store)
750  */
751 struct acpi_parse_obj_common {
752 ACPI_PARSE_COMMON};
753
754 /*
755  * Extended Op for named ops (Scope, Method, etc.), deferred ops (Methods and op_regions),
756  * and bytelists.
757  */
758 struct acpi_parse_obj_named {
759         ACPI_PARSE_COMMON u8 *path;
760         u8 *data;               /* AML body or bytelist data */
761         u32 length;             /* AML length */
762         u32 name;               /* 4-byte name or zero if no name */
763 };
764
765 /* This version is used by the iASL compiler only */
766
767 #define ACPI_MAX_PARSEOP_NAME   20
768
769 struct acpi_parse_obj_asl {
770         ACPI_PARSE_COMMON union acpi_parse_object *child;
771         union acpi_parse_object *parent_method;
772         char *filename;
773         char *external_name;
774         char *namepath;
775         char name_seg[4];
776         u32 extra_value;
777         u32 column;
778         u32 line_number;
779         u32 logical_line_number;
780         u32 logical_byte_offset;
781         u32 end_line;
782         u32 end_logical_line;
783         u32 acpi_btype;
784         u32 aml_length;
785         u32 aml_subtree_length;
786         u32 final_aml_length;
787         u32 final_aml_offset;
788         u32 compile_flags;
789         u16 parse_opcode;
790         u8 aml_opcode_length;
791         u8 aml_pkg_len_bytes;
792         u8 extra;
793         char parse_op_name[ACPI_MAX_PARSEOP_NAME];
794 };
795
796 union acpi_parse_object {
797         struct acpi_parse_obj_common common;
798         struct acpi_parse_obj_named named;
799         struct acpi_parse_obj_asl asl;
800 };
801
802 /*
803  * Parse state - one state per parser invocation and each control
804  * method.
805  */
806 struct acpi_parse_state {
807         u8 *aml_start;          /* First AML byte */
808         u8 *aml;                /* Next AML byte */
809         u8 *aml_end;            /* (last + 1) AML byte */
810         u8 *pkg_start;          /* Current package begin */
811         u8 *pkg_end;            /* Current package end */
812         union acpi_parse_object *start_op;      /* Root of parse tree */
813         struct acpi_namespace_node *start_node;
814         union acpi_generic_state *scope;        /* Current scope */
815         union acpi_parse_object *start_scope;
816         u32 aml_size;
817 };
818
819 /* Parse object flags */
820
821 #define ACPI_PARSEOP_GENERIC            0x01
822 #define ACPI_PARSEOP_NAMED              0x02
823 #define ACPI_PARSEOP_DEFERRED           0x04
824 #define ACPI_PARSEOP_BYTELIST           0x08
825 #define ACPI_PARSEOP_IN_STACK           0x10
826 #define ACPI_PARSEOP_TARGET             0x20
827 #define ACPI_PARSEOP_IN_CACHE           0x80
828
829 /* Parse object disasm_flags */
830
831 #define ACPI_PARSEOP_IGNORE             0x01
832 #define ACPI_PARSEOP_PARAMLIST          0x02
833 #define ACPI_PARSEOP_EMPTY_TERMLIST     0x04
834 #define ACPI_PARSEOP_PREDEF_CHECKED     0x08
835 #define ACPI_PARSEOP_SPECIAL            0x10
836
837 /*****************************************************************************
838  *
839  * Hardware (ACPI registers) and PNP
840  *
841  ****************************************************************************/
842
843 struct acpi_bit_register_info {
844         u8 parent_register;
845         u8 bit_position;
846         u16 access_bit_mask;
847 };
848
849 /*
850  * Some ACPI registers have bits that must be ignored -- meaning that they
851  * must be preserved.
852  */
853 #define ACPI_PM1_STATUS_PRESERVED_BITS          0x0800  /* Bit 11 */
854
855 /* Write-only bits must be zeroed by software */
856
857 #define ACPI_PM1_CONTROL_WRITEONLY_BITS         0x2004  /* Bits 13, 2 */
858
859 /* For control registers, both ignored and reserved bits must be preserved */
860
861 /*
862  * For PM1 control, the SCI enable bit (bit 0, SCI_EN) is defined by the
863  * ACPI specification to be a "preserved" bit - "OSPM always preserves this
864  * bit position", section 4.7.3.2.1. However, on some machines the OS must
865  * write a one to this bit after resume for the machine to work properly.
866  * To enable this, we no longer attempt to preserve this bit. No machines
867  * are known to fail if the bit is not preserved. (May 2009)
868  */
869 #define ACPI_PM1_CONTROL_IGNORED_BITS           0x0200  /* Bit 9 */
870 #define ACPI_PM1_CONTROL_RESERVED_BITS          0xC1F8  /* Bits 14-15, 3-8 */
871 #define ACPI_PM1_CONTROL_PRESERVED_BITS \
872                (ACPI_PM1_CONTROL_IGNORED_BITS | ACPI_PM1_CONTROL_RESERVED_BITS)
873
874 #define ACPI_PM2_CONTROL_PRESERVED_BITS         0xFFFFFFFE      /* All except bit 0 */
875
876 /*
877  * Register IDs
878  * These are the full ACPI registers
879  */
880 #define ACPI_REGISTER_PM1_STATUS                0x01
881 #define ACPI_REGISTER_PM1_ENABLE                0x02
882 #define ACPI_REGISTER_PM1_CONTROL               0x03
883 #define ACPI_REGISTER_PM2_CONTROL               0x04
884 #define ACPI_REGISTER_PM_TIMER                  0x05
885 #define ACPI_REGISTER_PROCESSOR_BLOCK           0x06
886 #define ACPI_REGISTER_SMI_COMMAND_BLOCK         0x07
887
888 /* Masks used to access the bit_registers */
889
890 #define ACPI_BITMASK_TIMER_STATUS               0x0001
891 #define ACPI_BITMASK_BUS_MASTER_STATUS          0x0010
892 #define ACPI_BITMASK_GLOBAL_LOCK_STATUS         0x0020
893 #define ACPI_BITMASK_POWER_BUTTON_STATUS        0x0100
894 #define ACPI_BITMASK_SLEEP_BUTTON_STATUS        0x0200
895 #define ACPI_BITMASK_RT_CLOCK_STATUS            0x0400
896 #define ACPI_BITMASK_PCIEXP_WAKE_STATUS         0x4000  /* ACPI 3.0 */
897 #define ACPI_BITMASK_WAKE_STATUS                0x8000
898
899 #define ACPI_BITMASK_ALL_FIXED_STATUS           (\
900         ACPI_BITMASK_TIMER_STATUS          | \
901         ACPI_BITMASK_BUS_MASTER_STATUS     | \
902         ACPI_BITMASK_GLOBAL_LOCK_STATUS    | \
903         ACPI_BITMASK_POWER_BUTTON_STATUS   | \
904         ACPI_BITMASK_SLEEP_BUTTON_STATUS   | \
905         ACPI_BITMASK_RT_CLOCK_STATUS       | \
906         ACPI_BITMASK_PCIEXP_WAKE_STATUS    | \
907         ACPI_BITMASK_WAKE_STATUS)
908
909 #define ACPI_BITMASK_TIMER_ENABLE               0x0001
910 #define ACPI_BITMASK_GLOBAL_LOCK_ENABLE         0x0020
911 #define ACPI_BITMASK_POWER_BUTTON_ENABLE        0x0100
912 #define ACPI_BITMASK_SLEEP_BUTTON_ENABLE        0x0200
913 #define ACPI_BITMASK_RT_CLOCK_ENABLE            0x0400
914 #define ACPI_BITMASK_PCIEXP_WAKE_DISABLE        0x4000  /* ACPI 3.0 */
915
916 #define ACPI_BITMASK_SCI_ENABLE                 0x0001
917 #define ACPI_BITMASK_BUS_MASTER_RLD             0x0002
918 #define ACPI_BITMASK_GLOBAL_LOCK_RELEASE        0x0004
919 #define ACPI_BITMASK_SLEEP_TYPE                 0x1C00
920 #define ACPI_BITMASK_SLEEP_ENABLE               0x2000
921
922 #define ACPI_BITMASK_ARB_DISABLE                0x0001
923
924 /* Raw bit position of each bit_register */
925
926 #define ACPI_BITPOSITION_TIMER_STATUS           0x00
927 #define ACPI_BITPOSITION_BUS_MASTER_STATUS      0x04
928 #define ACPI_BITPOSITION_GLOBAL_LOCK_STATUS     0x05
929 #define ACPI_BITPOSITION_POWER_BUTTON_STATUS    0x08
930 #define ACPI_BITPOSITION_SLEEP_BUTTON_STATUS    0x09
931 #define ACPI_BITPOSITION_RT_CLOCK_STATUS        0x0A
932 #define ACPI_BITPOSITION_PCIEXP_WAKE_STATUS     0x0E    /* ACPI 3.0 */
933 #define ACPI_BITPOSITION_WAKE_STATUS            0x0F
934
935 #define ACPI_BITPOSITION_TIMER_ENABLE           0x00
936 #define ACPI_BITPOSITION_GLOBAL_LOCK_ENABLE     0x05
937 #define ACPI_BITPOSITION_POWER_BUTTON_ENABLE    0x08
938 #define ACPI_BITPOSITION_SLEEP_BUTTON_ENABLE    0x09
939 #define ACPI_BITPOSITION_RT_CLOCK_ENABLE        0x0A
940 #define ACPI_BITPOSITION_PCIEXP_WAKE_DISABLE    0x0E    /* ACPI 3.0 */
941
942 #define ACPI_BITPOSITION_SCI_ENABLE             0x00
943 #define ACPI_BITPOSITION_BUS_MASTER_RLD         0x01
944 #define ACPI_BITPOSITION_GLOBAL_LOCK_RELEASE    0x02
945 #define ACPI_BITPOSITION_SLEEP_TYPE             0x0A
946 #define ACPI_BITPOSITION_SLEEP_ENABLE           0x0D
947
948 #define ACPI_BITPOSITION_ARB_DISABLE            0x00
949
950 /* Structs and definitions for _OSI support and I/O port validation */
951
952 #define ACPI_OSI_WIN_2000               0x01
953 #define ACPI_OSI_WIN_XP                 0x02
954 #define ACPI_OSI_WIN_XP_SP1             0x03
955 #define ACPI_OSI_WINSRV_2003            0x04
956 #define ACPI_OSI_WIN_XP_SP2             0x05
957 #define ACPI_OSI_WINSRV_2003_SP1        0x06
958 #define ACPI_OSI_WIN_VISTA              0x07
959 #define ACPI_OSI_WINSRV_2008            0x08
960 #define ACPI_OSI_WIN_VISTA_SP1          0x09
961 #define ACPI_OSI_WIN_VISTA_SP2          0x0A
962 #define ACPI_OSI_WIN_7                  0x0B
963 #define ACPI_OSI_WIN_8                  0x0C
964
965 #define ACPI_ALWAYS_ILLEGAL             0x00
966
967 struct acpi_interface_info {
968         char *name;
969         struct acpi_interface_info *next;
970         u8 flags;
971         u8 value;
972 };
973
974 #define ACPI_OSI_INVALID                0x01
975 #define ACPI_OSI_DYNAMIC                0x02
976
977 struct acpi_port_info {
978         char *name;
979         u16 start;
980         u16 end;
981         u8 osi_dependency;
982 };
983
984 /*****************************************************************************
985  *
986  * Resource descriptors
987  *
988  ****************************************************************************/
989
990 /* resource_type values */
991
992 #define ACPI_ADDRESS_TYPE_MEMORY_RANGE          0
993 #define ACPI_ADDRESS_TYPE_IO_RANGE              1
994 #define ACPI_ADDRESS_TYPE_BUS_NUMBER_RANGE      2
995
996 /* Resource descriptor types and masks */
997
998 #define ACPI_RESOURCE_NAME_LARGE                0x80
999 #define ACPI_RESOURCE_NAME_SMALL                0x00
1000
1001 #define ACPI_RESOURCE_NAME_SMALL_MASK           0x78    /* Bits 6:3 contain the type */
1002 #define ACPI_RESOURCE_NAME_SMALL_LENGTH_MASK    0x07    /* Bits 2:0 contain the length */
1003 #define ACPI_RESOURCE_NAME_LARGE_MASK           0x7F    /* Bits 6:0 contain the type */
1004
1005 /*
1006  * Small resource descriptor "names" as defined by the ACPI specification.
1007  * Note: Bits 2:0 are used for the descriptor length
1008  */
1009 #define ACPI_RESOURCE_NAME_IRQ                  0x20
1010 #define ACPI_RESOURCE_NAME_DMA                  0x28
1011 #define ACPI_RESOURCE_NAME_START_DEPENDENT      0x30
1012 #define ACPI_RESOURCE_NAME_END_DEPENDENT        0x38
1013 #define ACPI_RESOURCE_NAME_IO                   0x40
1014 #define ACPI_RESOURCE_NAME_FIXED_IO             0x48
1015 #define ACPI_RESOURCE_NAME_FIXED_DMA            0x50
1016 #define ACPI_RESOURCE_NAME_RESERVED_S2          0x58
1017 #define ACPI_RESOURCE_NAME_RESERVED_S3          0x60
1018 #define ACPI_RESOURCE_NAME_RESERVED_S4          0x68
1019 #define ACPI_RESOURCE_NAME_VENDOR_SMALL         0x70
1020 #define ACPI_RESOURCE_NAME_END_TAG              0x78
1021
1022 /*
1023  * Large resource descriptor "names" as defined by the ACPI specification.
1024  * Note: includes the Large Descriptor bit in bit[7]
1025  */
1026 #define ACPI_RESOURCE_NAME_MEMORY24             0x81
1027 #define ACPI_RESOURCE_NAME_GENERIC_REGISTER     0x82
1028 #define ACPI_RESOURCE_NAME_RESERVED_L1          0x83
1029 #define ACPI_RESOURCE_NAME_VENDOR_LARGE         0x84
1030 #define ACPI_RESOURCE_NAME_MEMORY32             0x85
1031 #define ACPI_RESOURCE_NAME_FIXED_MEMORY32       0x86
1032 #define ACPI_RESOURCE_NAME_ADDRESS32            0x87
1033 #define ACPI_RESOURCE_NAME_ADDRESS16            0x88
1034 #define ACPI_RESOURCE_NAME_EXTENDED_IRQ         0x89
1035 #define ACPI_RESOURCE_NAME_ADDRESS64            0x8A
1036 #define ACPI_RESOURCE_NAME_EXTENDED_ADDRESS64   0x8B
1037 #define ACPI_RESOURCE_NAME_GPIO                 0x8C
1038 #define ACPI_RESOURCE_NAME_SERIAL_BUS           0x8E
1039 #define ACPI_RESOURCE_NAME_LARGE_MAX            0x8E
1040
1041 /*****************************************************************************
1042  *
1043  * Miscellaneous
1044  *
1045  ****************************************************************************/
1046
1047 #define ACPI_ASCII_ZERO                 0x30
1048
1049 /*****************************************************************************
1050  *
1051  * Disassembler
1052  *
1053  ****************************************************************************/
1054
1055 struct acpi_external_list {
1056         char *path;
1057         char *internal_path;
1058         struct acpi_external_list *next;
1059         u32 value;
1060         u16 length;
1061         u8 type;
1062         u8 flags;
1063         u8 resolved;
1064 };
1065
1066 /* Values for Flags field above */
1067
1068 #define ACPI_IPATH_ALLOCATED    0x01
1069
1070 struct acpi_external_file {
1071         char *path;
1072         struct acpi_external_file *next;
1073 };
1074
1075 /*****************************************************************************
1076  *
1077  * Debugger
1078  *
1079  ****************************************************************************/
1080
1081 struct acpi_db_method_info {
1082         acpi_handle method;
1083         acpi_handle main_thread_gate;
1084         acpi_handle thread_complete_gate;
1085         acpi_handle info_gate;
1086         acpi_thread_id *threads;
1087         u32 num_threads;
1088         u32 num_created;
1089         u32 num_completed;
1090
1091         char *name;
1092         u32 flags;
1093         u32 num_loops;
1094         char pathname[128];
1095         char **args;
1096         acpi_object_type *types;
1097
1098         /*
1099          * Arguments to be passed to method for the command
1100          * Threads -
1101          *   the Number of threads, ID of current thread and
1102          *   Index of current thread inside all them created.
1103          */
1104         char init_args;
1105         char *arguments[4];
1106         char num_threads_str[11];
1107         char id_of_thread_str[11];
1108         char index_of_thread_str[11];
1109 };
1110
1111 struct acpi_integrity_info {
1112         u32 nodes;
1113         u32 objects;
1114 };
1115
1116 #define ACPI_DB_REDIRECTABLE_OUTPUT     0x01
1117 #define ACPI_DB_CONSOLE_OUTPUT          0x02
1118 #define ACPI_DB_DUPLICATE_OUTPUT        0x03
1119
1120 /*****************************************************************************
1121  *
1122  * Debug
1123  *
1124  ****************************************************************************/
1125
1126 /* Entry for a memory allocation (debug only) */
1127
1128 #define ACPI_MEM_MALLOC                 0
1129 #define ACPI_MEM_CALLOC                 1
1130 #define ACPI_MAX_MODULE_NAME            16
1131
1132 #define ACPI_COMMON_DEBUG_MEM_HEADER \
1133         struct acpi_debug_mem_block     *previous; \
1134         struct acpi_debug_mem_block     *next; \
1135         u32                             size; \
1136         u32                             component; \
1137         u32                             line; \
1138         char                            module[ACPI_MAX_MODULE_NAME]; \
1139         u8                              alloc_type;
1140
1141 struct acpi_debug_mem_header {
1142 ACPI_COMMON_DEBUG_MEM_HEADER};
1143
1144 struct acpi_debug_mem_block {
1145         ACPI_COMMON_DEBUG_MEM_HEADER u64 user_space;
1146 };
1147
1148 #define ACPI_MEM_LIST_GLOBAL            0
1149 #define ACPI_MEM_LIST_NSNODE            1
1150 #define ACPI_MEM_LIST_MAX               1
1151 #define ACPI_NUM_MEM_LISTS              2
1152
1153 /*****************************************************************************
1154  *
1155  * Info/help support
1156  *
1157  ****************************************************************************/
1158
1159 struct ah_predefined_name {
1160         char *name;
1161         char *description;
1162 #ifndef ACPI_ASL_COMPILER
1163         char *action;
1164 #endif
1165 };
1166
1167 #endif                          /* __ACLOCAL_H__ */