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: stable/11/sys/dev/acpica/acpi_if.m 359076 2020-03-18 18:02:33Z hrs $
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
56359076Shrs	struct acpi_bix;
57148352Snjl	struct acpi_bif;
58148352Snjl	struct acpi_bst;
59132212Snjl};
60132212Snjl
61132212Snjl#
62132212Snjl# Default implementation for acpi_id_probe().
63132212Snjl#
64131276SnjlCODE {
65131276Snjl	static char *
66131276Snjl	acpi_generic_id_probe(device_t bus, device_t dev, char **ids)
67131276Snjl	{
68131276Snjl		return (NULL);
69131276Snjl	}
70131276Snjl};
71131276Snjl
72131276Snjl#
73132212Snjl# Check a device for a match in a list of ID strings.  The strings can be
74132212Snjl# EISA PNP IDs or ACPI _HID/_CID values.
75131276Snjl#
76132212Snjl# device_t bus:  parent bus for the device
77132212Snjl#
78132212Snjl# device_t dev:  device being considered
79132212Snjl#
80132212Snjl# char **ids:  array of ID strings to consider
81132212Snjl#
82132212Snjl# Returns:  ID string matched or NULL if no match
83132212Snjl#
84131276SnjlMETHOD char * id_probe {
85131276Snjl	device_t	bus;
86131276Snjl	device_t	dev;
87131276Snjl	char		**ids;
88131276Snjl} DEFAULT acpi_generic_id_probe;
89131276Snjl
90131276Snjl#
91132212Snjl# Evaluate an ACPI method or object, given its path.
92131276Snjl#
93132212Snjl# device_t bus:  parent bus for the device
94132212Snjl#
95132212Snjl# device_t dev:  evaluate the object relative to this device's handle.
96132212Snjl#   Specify NULL to begin the search at the ACPI root.
97132212Snjl#
98132212Snjl# ACPI_STRING pathname:  absolute or relative path to this object
99132212Snjl#
100132212Snjl# ACPI_OBJECT_LIST *parameters:  array of arguments to pass to the object.
101132212Snjl#   Specify NULL if there are none.
102132212Snjl#
103132212Snjl# ACPI_BUFFER *ret:  the result (if any) of the evaluation
104132212Snjl#   Specify NULL if there is none.
105132212Snjl#
106132212Snjl# Returns:  AE_OK or an error value
107132212Snjl#
108131276SnjlMETHOD ACPI_STATUS evaluate_object {
109131276Snjl	device_t	bus;
110131276Snjl	device_t	dev;
111131276Snjl	ACPI_STRING 	pathname;
112131276Snjl	ACPI_OBJECT_LIST *parameters;
113131276Snjl	ACPI_BUFFER	*ret;
114131276Snjl};
115131276Snjl
116131276Snjl#
117138305Snjl# Get the highest power state (D0-D3) that is usable for a device when
118138305Snjl# suspending/resuming.  If a bus calls this when suspending a device, it
119138305Snjl# must also call it when resuming.
120138305Snjl#
121138305Snjl# device_t bus:  parent bus for the device
122138305Snjl#
123138305Snjl# device_t dev:  check this device's appropriate power state
124138305Snjl#
125138305Snjl# int *dstate:  if successful, contains the highest valid sleep state
126138305Snjl#
127214072Sjkim# Returns:  0 on success or 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
180202771Sjkim# UINT64 *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;
186202771Sjkim	UINT64		*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
195202771Sjkim# UINT64 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;
201202771Sjkim	UINT64		val;
202143861Snjl	int		width;
203143861Snjl};
204148352Snjl
205148352Snjl#
206359076Shrs# Get battery information (_BIF or _BIX format)
207148352Snjl#
208148352Snjl# device_t dev:  Battery device
209359076Shrs# void *bix:  Pointer to storage for _BIF or _BIX results
210359076Shrs# size_t len: length of acpi_bif or acpi_bix.
211148352Snjl#
212148352SnjlMETHOD int batt_get_info {
213148352Snjl	device_t	dev;
214359076Shrs	void		*bix;
215359076Shrs	size_t		len;
216148352Snjl};
217148352Snjl
218148352Snjl#
219148352Snjl# Get battery status (_BST format)
220148352Snjl#
221148352Snjl# device_t dev:  Battery device
222148352Snjl# struct acpi_bst *bst:  Pointer to storage for _BST results
223148352Snjl#
224148352SnjlMETHOD int batt_get_status {
225148352Snjl	device_t	dev;
226148352Snjl	struct acpi_bst	*bst;
227148352Snjl};
228