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