1 /* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
2 /******************************************************************************
3  *
4  * Name: acobject.h - Definition of union acpi_operand_object  (Internal object only)
5  *
6  * Copyright (C) 2000 - 2019, Intel Corp.
7  *
8  *****************************************************************************/
9 
10 #ifndef _ACOBJECT_H
11 #define _ACOBJECT_H
12 
13 /* acpisrc:struct_defs -- for acpisrc conversion */
14 
15 /*
16  * The union acpi_operand_object is used to pass AML operands from the dispatcher
17  * to the interpreter, and to keep track of the various handlers such as
18  * address space handlers and notify handlers. The object is a constant
19  * size in order to allow it to be cached and reused.
20  *
21  * Note: The object is optimized to be aligned and will not work if it is
22  * byte-packed.
23  */
24 #if ACPI_MACHINE_WIDTH == 64
25 #pragma pack(8)
26 #else
27 #pragma pack(4)
28 #endif
29 
30 /*******************************************************************************
31  *
32  * Common Descriptors
33  *
34  ******************************************************************************/
35 
36 /*
37  * Common area for all objects.
38  *
39  * descriptor_type is used to differentiate between internal descriptors, and
40  * must be in the same place across all descriptors
41  *
42  * Note: The descriptor_type and Type fields must appear in the identical
43  * position in both the struct acpi_namespace_node and union acpi_operand_object
44  * structures.
45  */
46 #define ACPI_OBJECT_COMMON_HEADER \
47 	union acpi_operand_object       *next_object;       /* Objects linked to parent NS node */\
48 	u8                              descriptor_type;    /* To differentiate various internal objs */\
49 	u8                              type;               /* acpi_object_type */\
50 	u16                             reference_count;    /* For object deletion management */\
51 	u8                              flags;
52 	/*
53 	 * Note: There are 3 bytes available here before the
54 	 * next natural alignment boundary (for both 32/64 cases)
55 	 */
56 
57 /* Values for Flag byte above */
58 
59 #define AOPOBJ_AML_CONSTANT         0x01	/* Integer is an AML constant */
60 #define AOPOBJ_STATIC_POINTER       0x02	/* Data is part of an ACPI table, don't delete */
61 #define AOPOBJ_DATA_VALID           0x04	/* Object is initialized and data is valid */
62 #define AOPOBJ_OBJECT_INITIALIZED   0x08	/* Region is initialized */
63 #define AOPOBJ_REG_CONNECTED        0x10	/* _REG was run */
64 #define AOPOBJ_SETUP_COMPLETE       0x20	/* Region setup is complete */
65 #define AOPOBJ_INVALID              0x40	/* Host OS won't allow a Region address */
66 
67 /******************************************************************************
68  *
69  * Basic data types
70  *
71  *****************************************************************************/
72 
73 struct acpi_object_common {
74 ACPI_OBJECT_COMMON_HEADER};
75 
76 struct acpi_object_integer {
77 	ACPI_OBJECT_COMMON_HEADER u8 fill[3];	/* Prevent warning on some compilers */
78 	u64 value;
79 };
80 
81 /*
82  * Note: The String and Buffer object must be identical through the
83  * pointer and length elements. There is code that depends on this.
84  *
85  * Fields common to both Strings and Buffers
86  */
87 #define ACPI_COMMON_BUFFER_INFO(_type) \
88 	_type                           *pointer; \
89 	u32                             length;
90 
91 /* Null terminated, ASCII characters only */
92 
93 struct acpi_object_string {
94 	ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_BUFFER_INFO(char)	/* String in AML stream or allocated string */
95 };
96 
97 struct acpi_object_buffer {
98 	ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_BUFFER_INFO(u8)	/* Buffer in AML stream or allocated buffer */
99 	u32 aml_length;
100 	u8 *aml_start;
101 	struct acpi_namespace_node *node;	/* Link back to parent node */
102 };
103 
104 struct acpi_object_package {
105 	ACPI_OBJECT_COMMON_HEADER struct acpi_namespace_node *node;	/* Link back to parent node */
106 	union acpi_operand_object **elements;	/* Array of pointers to acpi_objects */
107 	u8 *aml_start;
108 	u32 aml_length;
109 	u32 count;		/* # of elements in package */
110 };
111 
112 /******************************************************************************
113  *
114  * Complex data types
115  *
116  *****************************************************************************/
117 
118 struct acpi_object_event {
119 	ACPI_OBJECT_COMMON_HEADER acpi_semaphore os_semaphore;	/* Actual OS synchronization object */
120 };
121 
122 struct acpi_object_mutex {
123 	ACPI_OBJECT_COMMON_HEADER u8 sync_level;	/* 0-15, specified in Mutex() call */
124 	u16 acquisition_depth;	/* Allow multiple Acquires, same thread */
125 	acpi_mutex os_mutex;	/* Actual OS synchronization object */
126 	acpi_thread_id thread_id;	/* Current owner of the mutex */
127 	struct acpi_thread_state *owner_thread;	/* Current owner of the mutex */
128 	union acpi_operand_object *prev;	/* Link for list of acquired mutexes */
129 	union acpi_operand_object *next;	/* Link for list of acquired mutexes */
130 	struct acpi_namespace_node *node;	/* Containing namespace node */
131 	u8 original_sync_level;	/* Owner's original sync level (0-15) */
132 };
133 
134 struct acpi_object_region {
135 	ACPI_OBJECT_COMMON_HEADER u8 space_id;
136 	struct acpi_namespace_node *node;	/* Containing namespace node */
137 	union acpi_operand_object *handler;	/* Handler for region access */
138 	union acpi_operand_object *next;
139 	acpi_physical_address address;
140 	u32 length;
141 };
142 
143 struct acpi_object_method {
144 	ACPI_OBJECT_COMMON_HEADER u8 info_flags;
145 	u8 param_count;
146 	u8 sync_level;
147 	union acpi_operand_object *mutex;
148 	union acpi_operand_object *node;
149 	u8 *aml_start;
150 	union {
151 		acpi_internal_method implementation;
152 		union acpi_operand_object *handler;
153 	} dispatch;
154 
155 	u32 aml_length;
156 	acpi_owner_id owner_id;
157 	u8 thread_count;
158 };
159 
160 /* Flags for info_flags field above */
161 
162 #define ACPI_METHOD_MODULE_LEVEL        0x01	/* Method is actually module-level code */
163 #define ACPI_METHOD_INTERNAL_ONLY       0x02	/* Method is implemented internally (_OSI) */
164 #define ACPI_METHOD_SERIALIZED          0x04	/* Method is serialized */
165 #define ACPI_METHOD_SERIALIZED_PENDING  0x08	/* Method is to be marked serialized */
166 #define ACPI_METHOD_IGNORE_SYNC_LEVEL   0x10	/* Method was auto-serialized at table load time */
167 #define ACPI_METHOD_MODIFIED_NAMESPACE  0x20	/* Method modified the namespace */
168 
169 /******************************************************************************
170  *
171  * Objects that can be notified. All share a common notify_info area.
172  *
173  *****************************************************************************/
174 
175 /*
176  * Common fields for objects that support ASL notifications
177  */
178 #define ACPI_COMMON_NOTIFY_INFO \
179 	union acpi_operand_object       *notify_list[2];    /* Handlers for system/device notifies */\
180 	union acpi_operand_object       *handler;	/* Handler for Address space */
181 
182 /* COMMON NOTIFY for POWER, PROCESSOR, DEVICE, and THERMAL */
183 
184 struct acpi_object_notify_common {
185 ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_NOTIFY_INFO};
186 
187 struct acpi_object_device {
188 	ACPI_OBJECT_COMMON_HEADER
189 	    ACPI_COMMON_NOTIFY_INFO struct acpi_gpe_block_info *gpe_block;
190 };
191 
192 struct acpi_object_power_resource {
193 	ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_NOTIFY_INFO u32 system_level;
194 	u32 resource_order;
195 };
196 
197 struct acpi_object_processor {
198 	ACPI_OBJECT_COMMON_HEADER
199 	    /* The next two fields take advantage of the 3-byte space before NOTIFY_INFO */
200 	u8 proc_id;
201 	u8 length;
202 	ACPI_COMMON_NOTIFY_INFO acpi_io_address address;
203 };
204 
205 struct acpi_object_thermal_zone {
206 ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_NOTIFY_INFO};
207 
208 /******************************************************************************
209  *
210  * Fields. All share a common header/info field.
211  *
212  *****************************************************************************/
213 
214 /*
215  * Common bitfield for the field objects
216  * "Field Datum"  -- a datum from the actual field object
217  * "Buffer Datum" -- a datum from a user buffer, read from or to be written to the field
218  */
219 #define ACPI_COMMON_FIELD_INFO \
220 	u8                              field_flags;        /* Access, update, and lock bits */\
221 	u8                              attribute;          /* From access_as keyword */\
222 	u8                              access_byte_width;  /* Read/Write size in bytes */\
223 	struct acpi_namespace_node      *node;              /* Link back to parent node */\
224 	u32                             bit_length;         /* Length of field in bits */\
225 	u32                             base_byte_offset;   /* Byte offset within containing object */\
226 	u32                             value;              /* Value to store into the Bank or Index register */\
227 	u8                              start_field_bit_offset;/* Bit offset within first field datum (0-63) */\
228 	u8                              access_length;	/* For serial regions/fields */
229 
230 
231 /* COMMON FIELD (for BUFFER, REGION, BANK, and INDEX fields) */
232 
233 struct acpi_object_field_common {
234 	ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_FIELD_INFO union acpi_operand_object *region_obj;	/* Parent Operation Region object (REGION/BANK fields only) */
235 };
236 
237 struct acpi_object_region_field {
238 	ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_FIELD_INFO u16 resource_length;
239 	union acpi_operand_object *region_obj;	/* Containing op_region object */
240 	u8 *resource_buffer;	/* resource_template for serial regions/fields */
241 	u16 pin_number_index;	/* Index relative to previous Connection/Template */
242 	u8 *internal_pcc_buffer;	/* Internal buffer for fields associated with PCC */
243 };
244 
245 struct acpi_object_bank_field {
246 	ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_FIELD_INFO union acpi_operand_object *region_obj;	/* Containing op_region object */
247 	union acpi_operand_object *bank_obj;	/* bank_select Register object */
248 };
249 
250 struct acpi_object_index_field {
251 	ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_FIELD_INFO
252 	    /*
253 	     * No "RegionObj" pointer needed since the Index and Data registers
254 	     * are each field definitions unto themselves.
255 	     */
256 	union acpi_operand_object *index_obj;	/* Index register */
257 	union acpi_operand_object *data_obj;	/* Data register */
258 };
259 
260 /* The buffer_field is different in that it is part of a Buffer, not an op_region */
261 
262 struct acpi_object_buffer_field {
263 	ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_FIELD_INFO union acpi_operand_object *buffer_obj;	/* Containing Buffer object */
264 };
265 
266 /******************************************************************************
267  *
268  * Objects for handlers
269  *
270  *****************************************************************************/
271 
272 struct acpi_object_notify_handler {
273 	ACPI_OBJECT_COMMON_HEADER struct acpi_namespace_node *node;	/* Parent device */
274 	u32 handler_type;	/* Type: Device/System/Both */
275 	acpi_notify_handler handler;	/* Handler address */
276 	void *context;
277 	union acpi_operand_object *next[2];	/* Device and System handler lists */
278 };
279 
280 struct acpi_object_addr_handler {
281 	ACPI_OBJECT_COMMON_HEADER u8 space_id;
282 	u8 handler_flags;
283 	acpi_adr_space_handler handler;
284 	struct acpi_namespace_node *node;	/* Parent device */
285 	void *context;
286 	acpi_adr_space_setup setup;
287 	union acpi_operand_object *region_list;	/* Regions using this handler */
288 	union acpi_operand_object *next;
289 };
290 
291 /* Flags for address handler (handler_flags) */
292 
293 #define ACPI_ADDR_HANDLER_DEFAULT_INSTALLED  0x01
294 
295 /******************************************************************************
296  *
297  * Special internal objects
298  *
299  *****************************************************************************/
300 
301 /*
302  * The Reference object is used for these opcodes:
303  * Arg[0-6], Local[0-7], index_op, name_op, ref_of_op, load_op, load_table_op, debug_op
304  * The Reference.Class differentiates these types.
305  */
306 struct acpi_object_reference {
307 	ACPI_OBJECT_COMMON_HEADER u8 class;	/* Reference Class */
308 	u8 target_type;		/* Used for Index Op */
309 	u8 resolved;		/* Reference has been resolved to a value */
310 	void *object;		/* name_op=>HANDLE to obj, index_op=>union acpi_operand_object */
311 	struct acpi_namespace_node *node;	/* ref_of or Namepath */
312 	union acpi_operand_object **where;	/* Target of Index */
313 	u8 *index_pointer;	/* Used for Buffers and Strings */
314 	u8 *aml;		/* Used for deferred resolution of the ref */
315 	u32 value;		/* Used for Local/Arg/Index/ddb_handle */
316 };
317 
318 /* Values for Reference.Class above */
319 
320 typedef enum {
321 	ACPI_REFCLASS_LOCAL = 0,	/* Method local */
322 	ACPI_REFCLASS_ARG = 1,	/* Method argument */
323 	ACPI_REFCLASS_REFOF = 2,	/* Result of ref_of() TBD: Split to Ref/Node and Ref/operand_obj? */
324 	ACPI_REFCLASS_INDEX = 3,	/* Result of Index() */
325 	ACPI_REFCLASS_TABLE = 4,	/* ddb_handle - Load(), load_table() */
326 	ACPI_REFCLASS_NAME = 5,	/* Reference to a named object */
327 	ACPI_REFCLASS_DEBUG = 6,	/* Debug object */
328 
329 	ACPI_REFCLASS_MAX = 6
330 } ACPI_REFERENCE_CLASSES;
331 
332 /*
333  * Extra object is used as additional storage for types that
334  * have AML code in their declarations (term_args) that must be
335  * evaluated at run time.
336  *
337  * Currently: Region and field_unit types
338  */
339 struct acpi_object_extra {
340 	ACPI_OBJECT_COMMON_HEADER struct acpi_namespace_node *method_REG;	/* _REG method for this region (if any) */
341 	struct acpi_namespace_node *scope_node;
342 	void *region_context;	/* Region-specific data */
343 	u8 *aml_start;
344 	u32 aml_length;
345 };
346 
347 /* Additional data that can be attached to namespace nodes */
348 
349 struct acpi_object_data {
350 	ACPI_OBJECT_COMMON_HEADER acpi_object_handler handler;
351 	void *pointer;
352 };
353 
354 /* Structure used when objects are cached for reuse */
355 
356 struct acpi_object_cache_list {
357 	ACPI_OBJECT_COMMON_HEADER union acpi_operand_object *next;	/* Link for object cache and internal lists */
358 };
359 
360 /******************************************************************************
361  *
362  * union acpi_operand_object descriptor - a giant union of all of the above
363  *
364  *****************************************************************************/
365 
366 union acpi_operand_object {
367 	struct acpi_object_common common;
368 	struct acpi_object_integer integer;
369 	struct acpi_object_string string;
370 	struct acpi_object_buffer buffer;
371 	struct acpi_object_package package;
372 	struct acpi_object_event event;
373 	struct acpi_object_method method;
374 	struct acpi_object_mutex mutex;
375 	struct acpi_object_region region;
376 	struct acpi_object_notify_common common_notify;
377 	struct acpi_object_device device;
378 	struct acpi_object_power_resource power_resource;
379 	struct acpi_object_processor processor;
380 	struct acpi_object_thermal_zone thermal_zone;
381 	struct acpi_object_field_common common_field;
382 	struct acpi_object_region_field field;
383 	struct acpi_object_buffer_field buffer_field;
384 	struct acpi_object_bank_field bank_field;
385 	struct acpi_object_index_field index_field;
386 	struct acpi_object_notify_handler notify;
387 	struct acpi_object_addr_handler address_space;
388 	struct acpi_object_reference reference;
389 	struct acpi_object_extra extra;
390 	struct acpi_object_data data;
391 	struct acpi_object_cache_list cache;
392 
393 	/*
394 	 * Add namespace node to union in order to simplify code that accepts both
395 	 * ACPI_OPERAND_OBJECTs and ACPI_NAMESPACE_NODEs. The structures share
396 	 * a common descriptor_type field in order to differentiate them.
397 	 */
398 	struct acpi_namespace_node node;
399 };
400 
401 /******************************************************************************
402  *
403  * union acpi_descriptor - objects that share a common descriptor identifier
404  *
405  *****************************************************************************/
406 
407 /* Object descriptor types */
408 
409 #define ACPI_DESC_TYPE_CACHED           0x01	/* Used only when object is cached */
410 #define ACPI_DESC_TYPE_STATE            0x02
411 #define ACPI_DESC_TYPE_STATE_UPDATE     0x03
412 #define ACPI_DESC_TYPE_STATE_PACKAGE    0x04
413 #define ACPI_DESC_TYPE_STATE_CONTROL    0x05
414 #define ACPI_DESC_TYPE_STATE_RPSCOPE    0x06
415 #define ACPI_DESC_TYPE_STATE_PSCOPE     0x07
416 #define ACPI_DESC_TYPE_STATE_WSCOPE     0x08
417 #define ACPI_DESC_TYPE_STATE_RESULT     0x09
418 #define ACPI_DESC_TYPE_STATE_NOTIFY     0x0A
419 #define ACPI_DESC_TYPE_STATE_THREAD     0x0B
420 #define ACPI_DESC_TYPE_WALK             0x0C
421 #define ACPI_DESC_TYPE_PARSER           0x0D
422 #define ACPI_DESC_TYPE_OPERAND          0x0E
423 #define ACPI_DESC_TYPE_NAMED            0x0F
424 #define ACPI_DESC_TYPE_MAX              0x0F
425 
426 struct acpi_common_descriptor {
427 	void *common_pointer;
428 	u8 descriptor_type;	/* To differentiate various internal objs */
429 };
430 
431 union acpi_descriptor {
432 	struct acpi_common_descriptor common;
433 	union acpi_operand_object object;
434 	struct acpi_namespace_node node;
435 	union acpi_parse_object op;
436 };
437 
438 #pragma pack()
439 
440 #endif				/* _ACOBJECT_H */
441