1/*****************************************************************************
2 *
3 * Module name: bm.h
4 *   $Revision: 1.1.1.1 $
5 *
6 *****************************************************************************/
7
8/*
9 *  Copyright (C) 2000, 2001 Andrew Grover
10 *
11 *  This program is free software; you can redistribute it and/or modify
12 *  it under the terms of the GNU General Public License as published by
13 *  the Free Software Foundation; either version 2 of the License, or
14 *  (at your option) any later version.
15 *
16 *  This program is distributed in the hope that it will be useful,
17 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 *  GNU General Public License for more details.
20 *
21 *  You should have received a copy of the GNU General Public License
22 *  along with this program; if not, write to the Free Software
23 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24 */
25
26#ifndef __BM_H__
27#define __BM_H__
28
29#include <actypes.h>
30#include <acexcep.h>
31
32
33/*****************************************************************************
34 *                               Types & Defines
35 *****************************************************************************/
36
37/*
38 * Output Flags (Debug):
39 * ---------------------
40 */
41#define BM_PRINT_ALL		(0x00000000)
42#define BM_PRINT_GROUP		(0x00000001)
43#define BM_PRINT_LINKAGE	(0x00000002)
44#define BM_PRINT_IDENTIFICATION	(0x00000004)
45#define BM_PRINT_POWER		(0x00000008)
46#define BM_PRINT_PRESENT	(0x00000010)
47
48
49/*
50 * BM_COMMAND:
51 * -----------
52 */
53typedef u32			BM_COMMAND;
54
55#define BM_COMMAND_UNKNOWN	((BM_COMMAND) 0x00)
56
57#define BM_COMMAND_GET_POWER_STATE ((BM_COMMAND) 0x01)
58#define BM_COMMAND_SET_POWER_STATE ((BM_COMMAND) 0x02)
59
60#define BM_COMMAND_DEVICE_SPECIFIC ((BM_COMMAND) 0x80)
61
62/*
63 * BM_NOTIFY:
64 * ----------
65 * Standard ACPI notification values, from section 5.6.3 of the ACPI 2.0
66 * specification.  Note that the Bus Manager internally handles all
67 * standard ACPI notifications -- driver modules are never sent these
68 * values (see "Bus Manager Notifications", below).
69 */
70typedef u32			BM_NOTIFY;
71
72#define BM_NOTIFY_BUS_CHECK	((BM_NOTIFY) 0x00)
73#define BM_NOTIFY_DEVICE_CHECK	((BM_NOTIFY) 0x01)
74#define BM_NOTIFY_DEVICE_WAKE	((BM_NOTIFY) 0x02)
75#define BM_NOTIFY_EJECT_REQUEST	((BM_NOTIFY) 0x03)
76#define BM_NOTIFY_DEVICE_CHECK_LIGHT ((BM_NOTIFY) 0x04)
77#define BM_NOTIFY_FREQUENCY_MISMATCH ((BM_NOTIFY) 0x05)
78#define BM_NOTIFY_BUS_MODE_MISMATCH ((BM_NOTIFY) 0x06)
79#define BM_NOTIFY_POWER_FAULT	((BM_NOTIFY) 0x07)
80
81/*
82 * These are a higher-level abstraction of ACPI notifications, intended
83 * for consumption by driver modules to facilitate Pn_p.
84 */
85#define BM_NOTIFY_UNKNOWN	((BM_NOTIFY) 0x00)
86#define BM_NOTIFY_DEVICE_ADDED	((BM_NOTIFY) 0x01)
87#define BM_NOTIFY_DEVICE_REMOVED ((BM_NOTIFY) 0x02)
88
89
90/*
91 * BM_HANDLE:
92 * ----------
93 */
94typedef u32			BM_HANDLE;
95
96#define BM_HANDLE_ROOT		((BM_HANDLE) 0x00000000)
97#define BM_HANDLE_UNKNOWN	((BM_HANDLE) 0xFFFFFFFF)
98#define BM_HANDLES_MAX		100
99
100
101/*
102 * BM_HANDLE_LIST:
103 * ---------------
104 */
105typedef struct
106{
107	u32			count;
108	BM_HANDLE		handles[BM_HANDLES_MAX];
109} BM_HANDLE_LIST;
110
111
112/*
113 * BM_DEVICE_TYPE:
114 * ---------------
115 */
116typedef u32			BM_DEVICE_TYPE;
117
118#define BM_TYPE_UNKNOWN		((BM_DEVICE_TYPE) 0x00000000)
119
120#define BM_TYPE_SYSTEM		((BM_DEVICE_TYPE) 0x00000001)
121#define BM_TYPE_SCOPE		((BM_DEVICE_TYPE) 0x00000002)
122#define BM_TYPE_PROCESSOR	((BM_DEVICE_TYPE) 0x00000003)
123#define BM_TYPE_THERMAL_ZONE	((BM_DEVICE_TYPE) 0x00000004)
124#define BM_TYPE_POWER_RESOURCE	((BM_DEVICE_TYPE) 0x00000005)
125#define BM_TYPE_DEVICE		((BM_DEVICE_TYPE) 0x00000006)
126#define BM_TYPE_FIXED_BUTTON	((BM_DEVICE_TYPE) 0x00000007)
127
128
129/*
130 * BM_DEVICE_UID:
131 * --------------
132 */
133typedef char			BM_DEVICE_UID[9];
134
135#define BM_UID_UNKNOWN		'0'
136
137
138/*
139 * BM_DEVICE_HID:
140 * --------------
141 */
142typedef char			BM_DEVICE_HID[9];
143
144#define BM_HID_UNKNOWN		'\0'
145#define BM_HID_POWER_BUTTON	"PNP0C0C"
146#define BM_HID_SLEEP_BUTTON	"PNP0C0E"
147
148/*
149 * BM_DEVICE_ADR:
150 * --------------
151 */
152typedef u32			BM_DEVICE_ADR;
153
154#define BM_ADDRESS_UNKNOWN	0
155
156
157/*
158 * BM_DEVICE_FLAGS:
159 * ----------------
160 * The encoding of BM_DEVICE_FLAGS is illustrated below.
161 * Note that a set bit (1) indicates the property is TRUE
162 * (e.g. if bit 0 is set then the device has dynamic status).
163 * +--+------------+-+-+-+-+-+-+-+
164 * |31| Bits 30:7  |6|5|4|3|2|1|0|
165 * +--+------------+-+-+-+-+-+-+-+
166 *   |       |      | | | | | | |
167 *   |       |      | | | | | | +- Dynamic status?
168 *   |       |      | | | | | +--- Identifiable?
169 *   |       |      | | | | +----- Configurable?
170 *   |       |      | | | +------- Power Control?
171 *   |       |      | | +--------- Ejectable?
172 *   |       |      | +----------- Docking Station?
173 *   |       |      +------------- Fixed-Feature?
174 *   |       +-------------------- <Reserved>
175 *   +---------------------------- Driver Control?
176 *
177 * Dynamic status:  Device has a _STA object.
178 * Identifiable:    Device has a _HID and/or _ADR and possibly other
179 *                  identification objects defined.
180 * Configurable:    Device has a _CRS and possibly other configuration
181 *                  objects defined.
182 * Power Control:   Device has a _PR0 and/or _PS0 and possibly other
183 *                  power management objects defined.
184 * Ejectable:       Device has an _EJD and/or _EJx and possibly other
185 *                  dynamic insertion/removal objects defined.
186 * Docking Station: Device has a _DCK object defined.
187 * Fixed-Feature:   Device does not exist in the namespace; was
188 *                  enumerated as a fixed-feature (e.g. power button).
189 * Driver Control:  A driver has been installed for this device.
190 */
191typedef u32			BM_DEVICE_FLAGS;
192
193#define BM_FLAGS_UNKNOWN	((BM_DEVICE_FLAGS) 0x00000000)
194
195#define BM_FLAGS_DYNAMIC_STATUS	((BM_DEVICE_FLAGS) 0x00000001)
196#define BM_FLAGS_IDENTIFIABLE	((BM_DEVICE_FLAGS) 0x00000002)
197#define BM_FLAGS_CONFIGURABLE	((BM_DEVICE_FLAGS) 0x00000004)
198#define BM_FLAGS_POWER_CONTROL	((BM_DEVICE_FLAGS) 0x00000008)
199#define BM_FLAGS_EJECTABLE	((BM_DEVICE_FLAGS) 0x00000010)
200#define BM_FLAGS_DOCKING_STATION ((BM_DEVICE_FLAGS) 0x00000020)
201#define BM_FLAGS_FIXED_FEATURE	((BM_DEVICE_FLAGS) 0x00000040)
202#define BM_FLAGS_DRIVER_CONTROL	((BM_DEVICE_FLAGS) 0x80000000)
203
204
205/*
206 * Device PM Flags:
207 * ----------------
208 * +-----------+-+-+-+-+-+-+-+
209 * | Bits 31:7 |6|5|4|3|2|1|0|
210 * +-----------+-+-+-+-+-+-+-+
211 *       |      | | | | | | |
212 *       |      | | | | | | +- D0 Support?
213 *       |      | | | | | +--- D1 Support?
214 *       |      | | | | +----- D2 Support?
215 *       |      | | | +------- D3 Support?
216 *       |      | | +--------- Power State Queriable?
217 *       |      | +----------- Inrush Current?
218 *       |      +------------- Wake Capable?
219 *       +-------------------- <Reserved>
220 *
221 * D0-D3 Support:   Device supports corresponding Dx state.
222 * Power State:     Device has a _PSC (current power state) object defined.
223 * Inrush Current:  Device has an _IRC (inrush current) object defined.
224 * Wake Capable:    Device has a _PRW (wake-capable) object defined.
225 */
226#define BM_FLAGS_D0_SUPPORT	((BM_DEVICE_FLAGS) 0x00000001)
227#define BM_FLAGS_D1_SUPPORT	((BM_DEVICE_FLAGS) 0x00000002)
228#define BM_FLAGS_D2_SUPPORT	((BM_DEVICE_FLAGS) 0x00000004)
229#define BM_FLAGS_D3_SUPPORT	((BM_DEVICE_FLAGS) 0x00000008)
230#define BM_FLAGS_POWER_STATE	((BM_DEVICE_FLAGS) 0x00000010)
231#define BM_FLAGS_INRUSH_CURRENT	((BM_DEVICE_FLAGS) 0x00000020)
232#define BM_FLAGS_WAKE_CAPABLE	((BM_DEVICE_FLAGS) 0x00000040)
233
234
235/*
236 * BM_DEVICE_STATUS:
237 * -----------------
238 * The encoding of BM_DEVICE_STATUS is illustrated below.
239 * Note that a set bit (1) indicates the property is TRUE
240 * (e.g. if bit 0 is set then the device is present).
241 * +-----------+-+-+-+-+-+
242 * | Bits 31:4 |4|3|2|1|0|
243 * +-----------+-+-+-+-+-+
244 *       |      | | | | |
245 *       |      | | | | +- Present?
246 *       |      | | | +--- Enabled?
247 *       |      | | +----- Show in UI?
248 *       |      | +------- Functioning?
249 *       |      +--------- Battery Present?
250 *       +---------------- <Reserved>
251 */
252typedef u32			BM_DEVICE_STATUS;
253
254#define BM_STATUS_UNKNOWN	((BM_DEVICE_STATUS) 0x00000000)
255#define BM_STATUS_PRESENT	((BM_DEVICE_STATUS) 0x00000001)
256#define BM_STATUS_ENABLED	((BM_DEVICE_STATUS) 0x00000002)
257#define BM_STATUS_SHOW_UI	((BM_DEVICE_STATUS) 0x00000004)
258#define BM_STATUS_FUNCTIONING	((BM_DEVICE_STATUS) 0x00000008)
259#define BM_STATUS_BATTERY_PRESENT ((BM_DEVICE_STATUS) 0x00000010)
260#define BM_STATUS_DEFAULT	((BM_DEVICE_STATUS) 0x0000000F)
261
262
263/*
264 * BM_POWER_STATE:
265 * ---------------
266 */
267typedef u32			BM_POWER_STATE;
268
269
270/*
271 * BM_DEVICE_ID:
272 * -------------
273 */
274typedef struct
275{
276	BM_DEVICE_TYPE		type;
277	BM_DEVICE_UID		uid;
278	BM_DEVICE_HID		hid;
279	BM_DEVICE_ADR		adr;
280} BM_DEVICE_ID;
281
282
283/*
284 * BM_DEVICE_POWER:
285 * ----------------
286 * Structure containing basic device power management information.
287 */
288typedef struct
289{
290	BM_DEVICE_FLAGS		flags;
291	BM_POWER_STATE		state;
292	BM_DEVICE_FLAGS		dx_supported[ACPI_S_STATE_COUNT];
293} BM_DEVICE_POWER;
294
295
296/*
297 * BM_DEVICE:
298 * ----------
299 */
300typedef struct
301{
302	BM_HANDLE		handle;
303	acpi_handle  		acpi_handle;
304	BM_DEVICE_FLAGS		flags;
305	BM_DEVICE_STATUS	status;
306	BM_DEVICE_ID		id;
307	BM_DEVICE_POWER		power;
308} BM_DEVICE;
309
310
311/*
312 * BM_SEARCH:
313 * ----------
314 * Structure used for searching the ACPI Bus Manager's device hierarchy.
315 */
316typedef struct
317{
318	BM_DEVICE_ID		criteria;
319	BM_HANDLE_LIST		results;
320} BM_SEARCH;
321
322
323/*
324 * BM_REQUEST:
325 * -----------
326 * Structure used for sending requests to/through the ACPI Bus Manager.
327 */
328typedef struct
329{
330	acpi_status		status;
331	BM_COMMAND		command;
332	BM_HANDLE		handle;
333	acpi_buffer		buffer;
334} BM_REQUEST;
335
336
337/*
338 * Driver Registration:
339 * --------------------
340 */
341
342/* Driver Context */
343typedef void *			BM_DRIVER_CONTEXT;
344
345/* Notification Callback Function */
346typedef
347acpi_status (*BM_DRIVER_NOTIFY) (
348	BM_NOTIFY		notify_type,
349	BM_HANDLE		device_handle,
350	BM_DRIVER_CONTEXT	*context);
351
352/* Request Callback Function */
353typedef
354acpi_status (*BM_DRIVER_REQUEST) (
355	BM_REQUEST		*request,
356	BM_DRIVER_CONTEXT	context);
357
358/* Driver Registration */
359typedef struct
360{
361	BM_DRIVER_NOTIFY	notify;
362	BM_DRIVER_REQUEST	request;
363	BM_DRIVER_CONTEXT	context;
364} BM_DRIVER;
365
366
367/*
368 * BM_NODE:
369 * --------
370 * Structure used to maintain the device hierarchy.
371 */
372typedef struct _BM_NODE
373{
374	BM_DEVICE		device;
375	BM_DRIVER		driver;
376	struct _BM_NODE		*parent;
377	struct _BM_NODE		*next;
378	struct
379	{
380		struct _BM_NODE		*head;
381		struct _BM_NODE		*tail;
382	}			scope;
383} BM_NODE;
384
385
386/*
387 * BM_NODE_LIST:
388 * -------------
389 * Structure used to maintain an array of node pointers.
390 */
391typedef struct
392{
393	u32			count;
394	BM_NODE			*nodes[BM_HANDLES_MAX];
395} BM_NODE_LIST;
396
397
398/*****************************************************************************
399 *                                  Macros
400 *****************************************************************************/
401
402/*
403 * Device Presence:
404 * ----------------
405 * Note that status (_STA) means something different for power resources
406 * (they're assumed to always be present).
407 */
408#define BM_DEVICE_PRESENT(d)	((d->id.type!=BM_TYPE_POWER_RESOURCE)?(d->status & BM_STATUS_PRESENT):TRUE)
409#define BM_NODE_PRESENT(n)	((n->device.id.type!=BM_TYPE_POWER_RESOURCE)?(n->device.status & BM_STATUS_PRESENT):TRUE)
410
411/*
412 * Device Flags:
413 * -------------
414 */
415#define BM_IS_DRIVER_CONTROL(d)	(d->flags & BM_FLAGS_DRIVER_CONTROL)
416#define BM_IS_POWER_CONTROL(d)	(d->flags & BM_FLAGS_POWER_CONTROL)
417
418 /*
419 * Device Power Flags:
420 * -------------------
421 */
422#define BM_IS_POWER_STATE(d)	(d->power.flags & BM_FLAGS_POWER_STATE)
423
424/*****************************************************************************
425 *                             Function Prototypes
426 *****************************************************************************/
427
428/* bm.c */
429
430acpi_status
431bm_initialize (void);
432
433acpi_status
434bm_terminate (void);
435
436acpi_status
437bm_get_status (
438	BM_DEVICE		*device);
439
440acpi_status
441bm_get_handle (
442	acpi_handle             acpi_handle,
443	BM_HANDLE               *device_handle);
444
445acpi_status
446bm_get_node (
447	BM_HANDLE               device_handle,
448	acpi_handle             acpi_handle,
449	BM_NODE			**node);
450
451/* bmsearch.c */
452
453acpi_status
454bm_search(
455	BM_HANDLE               device_handle,
456	BM_DEVICE_ID            *criteria,
457	BM_HANDLE_LIST          *results);
458
459/* bmnotify.c */
460
461void
462bm_notify (
463	acpi_handle             acpi_handle,
464	u32                     notify_value,
465	void                    *context);
466
467/* bm_request.c */
468
469acpi_status
470bm_request (
471	BM_REQUEST		*request_info);
472
473/* bmdriver.c */
474
475acpi_status
476bm_get_device_power_state (
477	BM_HANDLE               device_handle,
478	BM_POWER_STATE		*state);
479
480acpi_status
481bm_set_device_power_state (
482	BM_HANDLE               device_handle,
483	BM_POWER_STATE		state);
484
485acpi_status
486bm_get_device_status (
487	BM_HANDLE               device_handle,
488	BM_DEVICE_STATUS        *device_status);
489
490acpi_status
491bm_get_device_info (
492	BM_HANDLE               device_handle,
493	BM_DEVICE		**device_info);
494
495acpi_status
496bm_get_device_context (
497	BM_HANDLE               device_handle,
498	BM_DRIVER_CONTEXT	*context);
499
500acpi_status
501bm_register_driver (
502	BM_DEVICE_ID		*criteria,
503	BM_DRIVER		*driver);
504
505acpi_status
506bm_unregister_driver (
507	BM_DEVICE_ID		*criteria,
508	BM_DRIVER		*driver);
509
510/* bmpm.c */
511
512acpi_status
513bm_get_pm_capabilities (
514	BM_NODE			*node);
515
516acpi_status
517bm_get_power_state (
518	BM_NODE			*node);
519
520acpi_status
521bm_set_power_state (
522	BM_NODE			*node,
523	BM_POWER_STATE          target_state);
524
525/* bmpower.c */
526
527acpi_status
528bm_pr_initialize (void);
529
530acpi_status
531bm_pr_terminate (void);
532
533/* bmutils.c */
534
535acpi_status
536bm_cast_buffer (
537	acpi_buffer             *buffer,
538	void                    **pointer,
539	u32                     length);
540
541acpi_status
542bm_copy_to_buffer (
543	acpi_buffer             *buffer,
544	void                    *data,
545	u32                     length);
546
547acpi_status
548bm_extract_package_data (
549	acpi_object             *package,
550	acpi_buffer             *format,
551	acpi_buffer             *buffer);
552
553acpi_status
554bm_evaluate_object (
555	acpi_handle             acpi_handle,
556	acpi_string             pathname,
557	acpi_object_list        *arguments,
558	acpi_buffer             *buffer);
559
560acpi_status
561bm_evaluate_simple_integer (
562	acpi_handle             acpi_handle,
563	acpi_string             pathname,
564	u32                     *data);
565
566acpi_status
567bm_evaluate_reference_list (
568	acpi_handle             acpi_handle,
569	acpi_string             pathname,
570	BM_HANDLE_LIST          *reference_list);
571
572/* ACPI Bus Driver OSL */
573
574acpi_status
575bm_osl_generate_event (
576	BM_HANDLE		device_handle,
577	char			*device_type,
578	char			*device_instance,
579	u32			event_type,
580	u32			event_data);
581
582
583#endif  /* __BM_H__ */
584