acpi_if.m revision 193530
1139749Simp#-
2131276Snjl# Copyright (c) 2004 Nate Lawson
3131276Snjl# All rights reserved.
4131276Snjl#
5131276Snjl# Redistribution and use in source and binary forms, with or without
6131276Snjl# modification, are permitted provided that the following conditions
7131276Snjl# are met:
8131276Snjl# 1. Redistributions of source code must retain the above copyright
9131276Snjl#    notice, this list of conditions and the following disclaimer.
10131276Snjl# 2. Redistributions in binary form must reproduce the above copyright
11131276Snjl#    notice, this list of conditions and the following disclaimer in the
12131276Snjl#    documentation and/or other materials provided with the distribution.
13131276Snjl#
14131276Snjl# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15131276Snjl# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16131276Snjl# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17131276Snjl# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18131276Snjl# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19131276Snjl# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20131276Snjl# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21131276Snjl# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22131276Snjl# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23131276Snjl# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24131276Snjl# SUCH DAMAGE.
25131276Snjl#
26131276Snjl# $FreeBSD: head/sys/dev/acpica/acpi_if.m 193530 2009-06-05 18:44:36Z jkim $
27131276Snjl#
28131276Snjl
29131276Snjl#include <sys/bus.h>
30131276Snjl#include <sys/types.h>
31131276Snjl
32193530Sjkim#include <contrib/dev/acpica/include/acpi.h>
33193530Sjkim
34131276SnjlINTERFACE acpi;
35131276Snjl
36131276Snjl#
37132212Snjl# Callback function for each child handle traversed in acpi_scan_children().
38131276Snjl#
39132212Snjl# ACPI_HANDLE h:  current child device being considered
40132212Snjl#
41132212Snjl# device_t *dev:  pointer to the child's original device_t or NULL if there
42132212Snjl#   was none.  The callback should store a new device in *dev if it has
43132212Snjl#   created one.  The method implementation will automatically clean up the
44132212Snjl#   previous device and properly associate the current ACPI_HANDLE with it.
45132212Snjl#
46132212Snjl# level:  current level being scanned
47132212Snjl#
48132212Snjl# void *arg:  argument passed in original call to acpi_scan_children()
49132212Snjl#
50132212Snjl# Returns:  AE_OK if the scan should continue, otherwise an error
51132212Snjl#
52132212SnjlHEADER {
53132212Snjl	typedef ACPI_STATUS (*acpi_scan_cb_t)(ACPI_HANDLE h, device_t *dev,
54132212Snjl	    int level, void *arg);
55148352Snjl
56148352Snjl	struct acpi_bif;
57148352Snjl	struct acpi_bst;
58132212Snjl};
59132212Snjl
60132212Snjl#
61132212Snjl# Default implementation for acpi_id_probe().
62132212Snjl#
63131276SnjlCODE {
64131276Snjl	static char *
65131276Snjl	acpi_generic_id_probe(device_t bus, device_t dev, char **ids)
66131276Snjl	{
67131276Snjl		return (NULL);
68131276Snjl	}
69131276Snjl};
70131276Snjl
71131276Snjl#
72132212Snjl# Check a device for a match in a list of ID strings.  The strings can be
73132212Snjl# EISA PNP IDs or ACPI _HID/_CID values.
74131276Snjl#
75132212Snjl# device_t bus:  parent bus for the device
76132212Snjl#
77132212Snjl# device_t dev:  device being considered
78132212Snjl#
79132212Snjl# char **ids:  array of ID strings to consider
80132212Snjl#
81132212Snjl# Returns:  ID string matched or NULL if no match
82132212Snjl#
83131276SnjlMETHOD char * id_probe {
84131276Snjl	device_t	bus;
85131276Snjl	device_t	dev;
86131276Snjl	char		**ids;
87131276Snjl} DEFAULT acpi_generic_id_probe;
88131276Snjl
89131276Snjl#
90132212Snjl# Evaluate an ACPI method or object, given its path.
91131276Snjl#
92132212Snjl# device_t bus:  parent bus for the device
93132212Snjl#
94132212Snjl# device_t dev:  evaluate the object relative to this device's handle.
95132212Snjl#   Specify NULL to begin the search at the ACPI root.
96132212Snjl#
97132212Snjl# ACPI_STRING pathname:  absolute or relative path to this object
98132212Snjl#
99132212Snjl# ACPI_OBJECT_LIST *parameters:  array of arguments to pass to the object.
100132212Snjl#   Specify NULL if there are none.
101132212Snjl#
102132212Snjl# ACPI_BUFFER *ret:  the result (if any) of the evaluation
103132212Snjl#   Specify NULL if there is none.
104132212Snjl#
105132212Snjl# Returns:  AE_OK or an error value
106132212Snjl#
107131276SnjlMETHOD ACPI_STATUS evaluate_object {
108131276Snjl	device_t	bus;
109131276Snjl	device_t	dev;
110131276Snjl	ACPI_STRING 	pathname;
111131276Snjl	ACPI_OBJECT_LIST *parameters;
112131276Snjl	ACPI_BUFFER	*ret;
113131276Snjl};
114131276Snjl
115131276Snjl#
116138305Snjl# Get the highest power state (D0-D3) that is usable for a device when
117138305Snjl# suspending/resuming.  If a bus calls this when suspending a device, it
118138305Snjl# must also call it when resuming.
119138305Snjl#
120138305Snjl# device_t bus:  parent bus for the device
121138305Snjl#
122138305Snjl# device_t dev:  check this device's appropriate power state
123138305Snjl#
124138305Snjl# int *dstate:  if successful, contains the highest valid sleep state
125138305Snjl#
126138305Snjl# Returns:  0 on success, ESRCH if device has no special state, or
127138305Snjl#   some other error value.
128138305Snjl#
129138305SnjlMETHOD int pwr_for_sleep {
130138305Snjl	device_t	bus;
131138305Snjl	device_t	dev;
132138305Snjl	int		*dstate;
133138305Snjl};
134138305Snjl
135138305Snjl#
136132212Snjl# Rescan a subtree and optionally reattach devices to handles.  Users
137132212Snjl# specify a callback that is called for each ACPI_HANDLE of type Device
138132212Snjl# that is a child of "dev".
139131276Snjl#
140132212Snjl# device_t bus:  parent bus for the device
141132212Snjl#
142132212Snjl# device_t dev:  begin the scan starting with this device's handle.
143132212Snjl#   Specify NULL to begin the scan at the ACPI root.
144132212Snjl# 
145132212Snjl# int max_depth:  number of levels to traverse (i.e., 1 means just the
146132212Snjl#   immediate children.
147132212Snjl#
148132212Snjl# acpi_scan_cb_t user_fn:  called for each child handle
149132212Snjl#
150132212Snjl# void *arg:  argument to pass to the callback function
151132212Snjl#
152132212Snjl# Returns:  AE_OK or an error value, based on the callback return value
153132212Snjl#
154132212SnjlMETHOD ACPI_STATUS scan_children {
155131276Snjl	device_t	bus;
156131276Snjl	device_t	dev;
157132212Snjl	int		max_depth;
158132212Snjl	acpi_scan_cb_t	user_fn;
159132212Snjl	void		*arg;
160131276Snjl};
161143861Snjl
162143861Snjl#
163144629Snjl# Query a given driver for its supported feature(s).  This should be
164144629Snjl# called by the parent bus before the driver is probed.
165144629Snjl#
166144629Snjl# driver_t *driver:  child driver
167144629Snjl#
168144629Snjl# u_int *features:  returned bitmask of all supported features
169144629Snjl#
170144629SnjlSTATICMETHOD int get_features {
171144629Snjl	driver_t	*driver;
172144629Snjl	u_int		*features;
173144629Snjl};
174144629Snjl
175144629Snjl#
176143861Snjl# Read embedded controller (EC) address space
177143861Snjl#
178143861Snjl# device_t dev:  EC device
179143861Snjl# u_int addr:  Address to read from in EC space
180143861Snjl# ACPI_INTEGER *val:  Location to store read value
181143861Snjl# int width:  Size of area to read in bytes
182143861Snjl#
183143861SnjlMETHOD int ec_read {
184143861Snjl	device_t	dev;
185143861Snjl	u_int		addr;
186143861Snjl	ACPI_INTEGER	*val;
187143861Snjl	int		width;
188143861Snjl};
189143861Snjl
190143861Snjl#
191143861Snjl# Write embedded controller (EC) address space
192143861Snjl#
193143861Snjl# device_t dev:  EC device
194143861Snjl# u_int addr:  Address to write to in EC space
195143861Snjl# ACPI_INTEGER val:  Value to write
196143861Snjl# int width:  Size of value to write in bytes
197143861Snjl#
198143861SnjlMETHOD int ec_write {
199143861Snjl	device_t	dev;
200143861Snjl	u_int		addr;
201143861Snjl	ACPI_INTEGER	val;
202143861Snjl	int		width;
203143861Snjl};
204148352Snjl
205148352Snjl#
206148352Snjl# Get battery information (_BIF format)
207148352Snjl#
208148352Snjl# device_t dev:  Battery device
209148352Snjl# struct acpi_bif *bif:  Pointer to storage for _BIF results
210148352Snjl#
211148352SnjlMETHOD int batt_get_info {
212148352Snjl	device_t	dev;
213148352Snjl	struct acpi_bif	*bif;
214148352Snjl};
215148352Snjl
216148352Snjl#
217148352Snjl# Get battery status (_BST format)
218148352Snjl#
219148352Snjl# device_t dev:  Battery device
220148352Snjl# struct acpi_bst *bst:  Pointer to storage for _BST results
221148352Snjl#
222148352SnjlMETHOD int batt_get_status {
223148352Snjl	device_t	dev;
224148352Snjl	struct acpi_bst	*bst;
225148352Snjl};
226