xref: /netbsd-src/usr.sbin/acpitools/aml/aml_common.h (revision 98a4945edbec0997da92df1a69deb322181c233c)
1*98a4945eSandvar /*	$NetBSD: aml_common.h,v 1.3 2024/01/28 10:09:54 andvar Exp $	*/
253e202c1Schristos 
353e202c1Schristos /*-
453e202c1Schristos  * Copyright (c) 2000 Mitsuru IWASAKI <iwasaki@FreeBSD.org>
553e202c1Schristos  * All rights reserved.
653e202c1Schristos  *
753e202c1Schristos  * Redistribution and use in source and binary forms, with or without
853e202c1Schristos  * modification, are permitted provided that the following conditions
953e202c1Schristos  * are met:
1053e202c1Schristos  * 1. Redistributions of source code must retain the above copyright
1153e202c1Schristos  *    notice, this list of conditions and the following disclaimer.
1253e202c1Schristos  * 2. Redistributions in binary form must reproduce the above copyright
1353e202c1Schristos  *    notice, this list of conditions and the following disclaimer in the
1453e202c1Schristos  *    documentation and/or other materials provided with the distribution.
1553e202c1Schristos  *
1653e202c1Schristos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1753e202c1Schristos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1853e202c1Schristos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1953e202c1Schristos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2053e202c1Schristos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2153e202c1Schristos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2253e202c1Schristos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2353e202c1Schristos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2453e202c1Schristos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2553e202c1Schristos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2653e202c1Schristos  * SUCH DAMAGE.
2753e202c1Schristos  *
2853e202c1Schristos  *	Id: aml_common.h,v 1.4 2000/08/08 14:12:05 iwasaki Exp
2953e202c1Schristos  *	$FreeBSD: src/usr.sbin/acpi/amldb/aml/aml_common.h,v 1.4 2000/10/02 08:58:47 iwasaki Exp $
3053e202c1Schristos  */
3153e202c1Schristos 
3253e202c1Schristos #ifndef _AML_COMMON_H_
3353e202c1Schristos #define _AML_COMMON_H_
3453e202c1Schristos 
3553e202c1Schristos /*
3653e202c1Schristos  * General Stuff
3753e202c1Schristos  */
3853e202c1Schristos #ifdef _KERNEL
3953e202c1Schristos #define AML_SYSABORT() do {						\
40*98a4945eSandvar 	printf("aml: fatal error at %s:%d\n", __FILE__, __LINE__);	\
4153e202c1Schristos 	panic("panic in AML interpreter!");				\
4253e202c1Schristos } while(0)
4353e202c1Schristos #define AML_SYSASSERT(x) do {						\
4453e202c1Schristos 	if (!(x)) {							\
4553e202c1Schristos 		AML_SYSABORT();						\
4653e202c1Schristos 	}								\
4753e202c1Schristos } while(0)
4853e202c1Schristos #define AML_SYSERRX(eval, fmt, args...) do {				\
4953e202c1Schristos 	printf(fmt, args);						\
5053e202c1Schristos } while(0)
5153e202c1Schristos #define AML_DEBUGGER(x, y)	/* no debugger in kernel */
5253e202c1Schristos #define AML_STALL(micro)	OsdSleepUsec(micro)
5353e202c1Schristos #define AML_SLEEP(sec, milli)	OsdSleep(sec, milli)
5453e202c1Schristos #else /* !_KERNEL */
5553e202c1Schristos #define AML_SYSASSERT(x)	assert(x)
5653e202c1Schristos #define AML_SYSABORT()  	abort()
5753e202c1Schristos #define AML_SYSERRX(eval, fmt, args...)	errx(eval, fmt, args)
5853e202c1Schristos #define AML_DEBUGGER(x, y)	aml_dbgr(x, y)
5953e202c1Schristos #define AML_STALL(micro)	/* not required in userland */
6053e202c1Schristos #define AML_SLEEP(sec, milli)	/* not required in userland */
6153e202c1Schristos #endif /* _KERNEL */
6253e202c1Schristos 
6353e202c1Schristos union	aml_object;
6453e202c1Schristos struct	aml_name;
6553e202c1Schristos 
6653e202c1Schristos extern int	aml_debug;
6753e202c1Schristos 
6853e202c1Schristos #define AML_DEBUGPRINT(args...) do {					\
6953e202c1Schristos 	if (aml_debug) {						\
7053e202c1Schristos 		printf(args);						\
7153e202c1Schristos 	}								\
7253e202c1Schristos } while(0)
7353e202c1Schristos 
7453e202c1Schristos void		 aml_showobject(union aml_object *);
7553e202c1Schristos void		 aml_showtree(struct aml_name *, int);
7653e202c1Schristos int		 aml_print_curname(struct aml_name *);
7753e202c1Schristos void		 aml_print_namestring(u_int8_t *);
7853e202c1Schristos void		 aml_print_indent(int);
7953e202c1Schristos 
8053e202c1Schristos /*
8153e202c1Schristos  * Reigion I/O Stuff for both kernel/userland.
8253e202c1Schristos  */
8353e202c1Schristos 
8453e202c1Schristos /*
8553e202c1Schristos  * Field Flags
8653e202c1Schristos  */
8753e202c1Schristos /* bit 0 -3:	AccessType */
8853e202c1Schristos #define AML_FIELDFLAGS_ACCESS_ANYACC		0x00
8953e202c1Schristos #define AML_FIELDFLAGS_ACCESS_BYTEACC		0x01
9053e202c1Schristos #define AML_FIELDFLAGS_ACCESS_WORDACC		0x02
9153e202c1Schristos #define AML_FIELDFLAGS_ACCESS_DWORDACC		0x03
9253e202c1Schristos #define AML_FIELDFLAGS_ACCESS_BLOCKACC		0x04
9353e202c1Schristos #define AML_FIELDFLAGS_ACCESS_SMBSENDRECVACC	0x05
9453e202c1Schristos #define AML_FIELDFLAGS_ACCESS_SMBQUICKACC	0x06
9553e202c1Schristos #define AML_FIELDFLAGS_ACCESSTYPE(flags)	(flags & 0x0f)
9653e202c1Schristos /* bit 4:	LockRule */
9753e202c1Schristos #define AML_FIELDFLAGS_LOCK_NOLOCK		0x00
9853e202c1Schristos #define AML_FIELDFLAGS_LOCK_LOCK		0x10
9953e202c1Schristos #define AML_FIELDFLAGS_LOCKRULE(flags)		(flags & 0x10)
10053e202c1Schristos /* bit 5 - 6:	UpdateRule */
10153e202c1Schristos #define AML_FIELDFLAGS_UPDATE_PRESERVE		0x00
10253e202c1Schristos #define AML_FIELDFLAGS_UPDATE_WRITEASONES	0x20
10353e202c1Schristos #define AML_FIELDFLAGS_UPDATE_WRITEASZEROS	0x40
10453e202c1Schristos #define AML_FIELDFLAGS_UPDATERULE(flags)	(flags & 0x60)
10553e202c1Schristos /* bit 7:	reserved (must be 0) */
10653e202c1Schristos 
10753e202c1Schristos #define AML_REGION_INPUT	0
10853e202c1Schristos #define AML_REGION_OUTPUT	1
10953e202c1Schristos 
11053e202c1Schristos #define AML_REGION_SYSMEM	0
11153e202c1Schristos #define AML_REGION_SYSIO	1
11253e202c1Schristos #define AML_REGION_PCICFG	2
11353e202c1Schristos #define AML_REGION_EMBCTL	3
11453e202c1Schristos #define AML_REGION_SMBUS	4
11553e202c1Schristos 
11653e202c1Schristos struct aml_region_handle {
11753e202c1Schristos 	/* These are copies of values used on initialization */
11853e202c1Schristos 	struct		aml_environ *env;
11953e202c1Schristos 	int		regtype;
12053e202c1Schristos 	u_int32_t	flags;
12153e202c1Schristos 	u_int32_t	baseaddr;
12253e202c1Schristos 	u_int32_t	bitoffset;
12353e202c1Schristos 	u_int32_t	bitlen;
12453e202c1Schristos 
12553e202c1Schristos 	/* following is determined on initialization */
12653e202c1Schristos 	vm_offset_t	addr, bytelen;
12753e202c1Schristos 	u_int32_t	unit;		/* access unit in bytes */
12853e202c1Schristos 
1294cbd24b2Swiz 	/* region type dependent */
13053e202c1Schristos 	vm_offset_t	vaddr;			/* SystemMemory */
13153e202c1Schristos 	u_int32_t	pci_bus, pci_devfunc;	/* PCI_Config */
13253e202c1Schristos };
13353e202c1Schristos 
13453e202c1Schristos u_int32_t	 aml_adjust_readvalue(u_int32_t, u_int32_t, u_int32_t,
13553e202c1Schristos 				      u_int32_t);
13653e202c1Schristos u_int32_t	 aml_adjust_updatevalue(u_int32_t, u_int32_t, u_int32_t,
13753e202c1Schristos 					u_int32_t, u_int32_t);
13853e202c1Schristos 
13953e202c1Schristos u_int32_t	 aml_bufferfield_read(u_int8_t *, u_int32_t, u_int32_t);
14053e202c1Schristos int		 aml_bufferfield_write(u_int32_t, u_int8_t *,
14153e202c1Schristos 				       u_int32_t, u_int32_t);
14253e202c1Schristos 
14353e202c1Schristos int		 aml_region_handle_alloc(struct aml_environ *, int, u_int32_t,
14453e202c1Schristos 					 u_int32_t, u_int32_t, u_int32_t,
14553e202c1Schristos 					 struct aml_region_handle *);
14653e202c1Schristos void		 aml_region_handle_free(struct aml_region_handle *);
14753e202c1Schristos 
14853e202c1Schristos int		 aml_region_io(struct aml_environ *, int, int,
14953e202c1Schristos 			       u_int32_t, u_int32_t *, u_int32_t,
15053e202c1Schristos 			       u_int32_t, u_int32_t);
15153e202c1Schristos int		 aml_region_read_simple(struct aml_region_handle *, vm_offset_t,
15253e202c1Schristos 					u_int32_t *);
15353e202c1Schristos int		 aml_region_write_simple(struct aml_region_handle *, vm_offset_t,
15453e202c1Schristos 					 u_int32_t);
15553e202c1Schristos u_int32_t	 aml_region_prompt_read(struct aml_region_handle *,
15653e202c1Schristos 					u_int32_t);
15753e202c1Schristos u_int32_t	 aml_region_prompt_write(struct aml_region_handle *,
15853e202c1Schristos 					 u_int32_t);
15953e202c1Schristos int		 aml_region_prompt_update_value(u_int32_t, u_int32_t,
16053e202c1Schristos 					        struct aml_region_handle *);
16153e202c1Schristos void		 aml_dbgr(struct aml_environ *, struct aml_environ *);
16253e202c1Schristos #endif /* !_AML_COMMON_H_ */
163