aml_common.h revision 1.2 1 1.2 wiz /* $NetBSD: aml_common.h,v 1.2 2011/06/30 20:09:42 wiz Exp $ */
2 1.1 christos
3 1.1 christos /*-
4 1.1 christos * Copyright (c) 2000 Mitsuru IWASAKI <iwasaki (at) FreeBSD.org>
5 1.1 christos * All rights reserved.
6 1.1 christos *
7 1.1 christos * Redistribution and use in source and binary forms, with or without
8 1.1 christos * modification, are permitted provided that the following conditions
9 1.1 christos * are met:
10 1.1 christos * 1. Redistributions of source code must retain the above copyright
11 1.1 christos * notice, this list of conditions and the following disclaimer.
12 1.1 christos * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 christos * notice, this list of conditions and the following disclaimer in the
14 1.1 christos * documentation and/or other materials provided with the distribution.
15 1.1 christos *
16 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 1.1 christos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 1.1 christos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 1.1 christos * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 1.1 christos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 1.1 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 1.1 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 1.1 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 1.1 christos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.1 christos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.1 christos * SUCH DAMAGE.
27 1.1 christos *
28 1.1 christos * Id: aml_common.h,v 1.4 2000/08/08 14:12:05 iwasaki Exp
29 1.1 christos * $FreeBSD: src/usr.sbin/acpi/amldb/aml/aml_common.h,v 1.4 2000/10/02 08:58:47 iwasaki Exp $
30 1.1 christos */
31 1.1 christos
32 1.1 christos #ifndef _AML_COMMON_H_
33 1.1 christos #define _AML_COMMON_H_
34 1.1 christos
35 1.1 christos /*
36 1.1 christos * General Stuff
37 1.1 christos */
38 1.1 christos #ifdef _KERNEL
39 1.1 christos #define AML_SYSABORT() do { \
40 1.1 christos printf("aml: fatal errer at %s:%d\n", __FILE__, __LINE__); \
41 1.1 christos panic("panic in AML interpreter!"); \
42 1.1 christos } while(0)
43 1.1 christos #define AML_SYSASSERT(x) do { \
44 1.1 christos if (!(x)) { \
45 1.1 christos AML_SYSABORT(); \
46 1.1 christos } \
47 1.1 christos } while(0)
48 1.1 christos #define AML_SYSERRX(eval, fmt, args...) do { \
49 1.1 christos printf(fmt, args); \
50 1.1 christos } while(0)
51 1.1 christos #define AML_DEBUGGER(x, y) /* no debugger in kernel */
52 1.1 christos #define AML_STALL(micro) OsdSleepUsec(micro)
53 1.1 christos #define AML_SLEEP(sec, milli) OsdSleep(sec, milli)
54 1.1 christos #else /* !_KERNEL */
55 1.1 christos #define AML_SYSASSERT(x) assert(x)
56 1.1 christos #define AML_SYSABORT() abort()
57 1.1 christos #define AML_SYSERRX(eval, fmt, args...) errx(eval, fmt, args)
58 1.1 christos #define AML_DEBUGGER(x, y) aml_dbgr(x, y)
59 1.1 christos #define AML_STALL(micro) /* not required in userland */
60 1.1 christos #define AML_SLEEP(sec, milli) /* not required in userland */
61 1.1 christos #endif /* _KERNEL */
62 1.1 christos
63 1.1 christos union aml_object;
64 1.1 christos struct aml_name;
65 1.1 christos
66 1.1 christos extern int aml_debug;
67 1.1 christos
68 1.1 christos #define AML_DEBUGPRINT(args...) do { \
69 1.1 christos if (aml_debug) { \
70 1.1 christos printf(args); \
71 1.1 christos } \
72 1.1 christos } while(0)
73 1.1 christos
74 1.1 christos void aml_showobject(union aml_object *);
75 1.1 christos void aml_showtree(struct aml_name *, int);
76 1.1 christos int aml_print_curname(struct aml_name *);
77 1.1 christos void aml_print_namestring(u_int8_t *);
78 1.1 christos void aml_print_indent(int);
79 1.1 christos
80 1.1 christos /*
81 1.1 christos * Reigion I/O Stuff for both kernel/userland.
82 1.1 christos */
83 1.1 christos
84 1.1 christos /*
85 1.1 christos * Field Flags
86 1.1 christos */
87 1.1 christos /* bit 0 -3: AccessType */
88 1.1 christos #define AML_FIELDFLAGS_ACCESS_ANYACC 0x00
89 1.1 christos #define AML_FIELDFLAGS_ACCESS_BYTEACC 0x01
90 1.1 christos #define AML_FIELDFLAGS_ACCESS_WORDACC 0x02
91 1.1 christos #define AML_FIELDFLAGS_ACCESS_DWORDACC 0x03
92 1.1 christos #define AML_FIELDFLAGS_ACCESS_BLOCKACC 0x04
93 1.1 christos #define AML_FIELDFLAGS_ACCESS_SMBSENDRECVACC 0x05
94 1.1 christos #define AML_FIELDFLAGS_ACCESS_SMBQUICKACC 0x06
95 1.1 christos #define AML_FIELDFLAGS_ACCESSTYPE(flags) (flags & 0x0f)
96 1.1 christos /* bit 4: LockRule */
97 1.1 christos #define AML_FIELDFLAGS_LOCK_NOLOCK 0x00
98 1.1 christos #define AML_FIELDFLAGS_LOCK_LOCK 0x10
99 1.1 christos #define AML_FIELDFLAGS_LOCKRULE(flags) (flags & 0x10)
100 1.1 christos /* bit 5 - 6: UpdateRule */
101 1.1 christos #define AML_FIELDFLAGS_UPDATE_PRESERVE 0x00
102 1.1 christos #define AML_FIELDFLAGS_UPDATE_WRITEASONES 0x20
103 1.1 christos #define AML_FIELDFLAGS_UPDATE_WRITEASZEROS 0x40
104 1.1 christos #define AML_FIELDFLAGS_UPDATERULE(flags) (flags & 0x60)
105 1.1 christos /* bit 7: reserved (must be 0) */
106 1.1 christos
107 1.1 christos #define AML_REGION_INPUT 0
108 1.1 christos #define AML_REGION_OUTPUT 1
109 1.1 christos
110 1.1 christos #define AML_REGION_SYSMEM 0
111 1.1 christos #define AML_REGION_SYSIO 1
112 1.1 christos #define AML_REGION_PCICFG 2
113 1.1 christos #define AML_REGION_EMBCTL 3
114 1.1 christos #define AML_REGION_SMBUS 4
115 1.1 christos
116 1.1 christos struct aml_region_handle {
117 1.1 christos /* These are copies of values used on initialization */
118 1.1 christos struct aml_environ *env;
119 1.1 christos int regtype;
120 1.1 christos u_int32_t flags;
121 1.1 christos u_int32_t baseaddr;
122 1.1 christos u_int32_t bitoffset;
123 1.1 christos u_int32_t bitlen;
124 1.1 christos
125 1.1 christos /* following is determined on initialization */
126 1.1 christos vm_offset_t addr, bytelen;
127 1.1 christos u_int32_t unit; /* access unit in bytes */
128 1.1 christos
129 1.2 wiz /* region type dependent */
130 1.1 christos vm_offset_t vaddr; /* SystemMemory */
131 1.1 christos u_int32_t pci_bus, pci_devfunc; /* PCI_Config */
132 1.1 christos };
133 1.1 christos
134 1.1 christos u_int32_t aml_adjust_readvalue(u_int32_t, u_int32_t, u_int32_t,
135 1.1 christos u_int32_t);
136 1.1 christos u_int32_t aml_adjust_updatevalue(u_int32_t, u_int32_t, u_int32_t,
137 1.1 christos u_int32_t, u_int32_t);
138 1.1 christos
139 1.1 christos u_int32_t aml_bufferfield_read(u_int8_t *, u_int32_t, u_int32_t);
140 1.1 christos int aml_bufferfield_write(u_int32_t, u_int8_t *,
141 1.1 christos u_int32_t, u_int32_t);
142 1.1 christos
143 1.1 christos int aml_region_handle_alloc(struct aml_environ *, int, u_int32_t,
144 1.1 christos u_int32_t, u_int32_t, u_int32_t,
145 1.1 christos struct aml_region_handle *);
146 1.1 christos void aml_region_handle_free(struct aml_region_handle *);
147 1.1 christos
148 1.1 christos int aml_region_io(struct aml_environ *, int, int,
149 1.1 christos u_int32_t, u_int32_t *, u_int32_t,
150 1.1 christos u_int32_t, u_int32_t);
151 1.1 christos int aml_region_read_simple(struct aml_region_handle *, vm_offset_t,
152 1.1 christos u_int32_t *);
153 1.1 christos int aml_region_write_simple(struct aml_region_handle *, vm_offset_t,
154 1.1 christos u_int32_t);
155 1.1 christos u_int32_t aml_region_prompt_read(struct aml_region_handle *,
156 1.1 christos u_int32_t);
157 1.1 christos u_int32_t aml_region_prompt_write(struct aml_region_handle *,
158 1.1 christos u_int32_t);
159 1.1 christos int aml_region_prompt_update_value(u_int32_t, u_int32_t,
160 1.1 christos struct aml_region_handle *);
161 1.1 christos void aml_dbgr(struct aml_environ *, struct aml_environ *);
162 1.1 christos #endif /* !_AML_COMMON_H_ */
163