Home | History | Annotate | Line # | Download | only in amldb
region.c revision 1.1
      1  1.1  christos /*	$NetBSD: region.c,v 1.1 2007/01/14 04:36:13 christos Exp $	*/
      2  1.1  christos 
      3  1.1  christos /*-
      4  1.1  christos  * Copyright (c) 1999 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: region.c,v 1.14 2000/08/08 14:12:25 iwasaki Exp
     29  1.1  christos  *	$FreeBSD: src/usr.sbin/acpi/amldb/region.c,v 1.4 2000/11/19 13:29:43 kris Exp $
     30  1.1  christos  */
     31  1.1  christos #include <sys/cdefs.h>
     32  1.1  christos __RCSID("$NetBSD: region.c,v 1.1 2007/01/14 04:36:13 christos Exp $");
     33  1.1  christos 
     34  1.1  christos /*
     35  1.1  christos  * Region I/O subroutine
     36  1.1  christos  */
     37  1.1  christos 
     38  1.1  christos #include <sys/param.h>
     39  1.1  christos #include <sys/queue.h>
     40  1.1  christos 
     41  1.1  christos #include <acpi_common.h>
     42  1.1  christos #include <aml/aml_amlmem.h>
     43  1.1  christos #include <aml/aml_name.h>
     44  1.1  christos #include <aml/aml_region.h>
     45  1.1  christos #include <aml/aml_common.h>
     46  1.1  christos 
     47  1.1  christos #include <assert.h>
     48  1.1  christos #include <err.h>
     49  1.1  christos #include <stdlib.h>
     50  1.1  christos #include <stdio.h>
     51  1.1  christos #include <string.h>
     52  1.1  christos #include <unistd.h>
     53  1.1  christos 
     54  1.1  christos #include "debug.h"
     55  1.1  christos 
     56  1.1  christos int	aml_debug_prompt_regoutput = 0;
     57  1.1  christos int	aml_debug_prompt_reginput = 1;
     58  1.1  christos 
     59  1.1  christos static void	aml_simulation_regload(const char *dumpfile);
     60  1.1  christos 
     61  1.1  christos struct ACPIRegionContent {
     62  1.1  christos 	TAILQ_ENTRY(ACPIRegionContent) links;
     63  1.1  christos 	int		regtype;
     64  1.1  christos 	u_int32_t	addr;
     65  1.1  christos 	u_int8_t	value;
     66  1.1  christos };
     67  1.1  christos 
     68  1.1  christos TAILQ_HEAD(ACPIRegionContentList, ACPIRegionContent);
     69  1.1  christos struct	ACPIRegionContentList RegionContentList;
     70  1.1  christos 
     71  1.1  christos static int	aml_simulation_initialized = 0;
     72  1.1  christos 
     73  1.1  christos static void
     74  1.1  christos aml_simulation_init(void)
     75  1.1  christos {
     76  1.1  christos 
     77  1.1  christos 	aml_simulation_initialized = 1;
     78  1.1  christos 	TAILQ_INIT(&RegionContentList);
     79  1.1  christos 	aml_simulation_regload("region.ini");
     80  1.1  christos }
     81  1.1  christos 
     82  1.1  christos static int
     83  1.1  christos aml_simulate_regcontent_add(int regtype, u_int32_t addr, u_int8_t value)
     84  1.1  christos {
     85  1.1  christos 	struct	ACPIRegionContent *rc;
     86  1.1  christos 
     87  1.1  christos 	rc = malloc(sizeof(struct ACPIRegionContent));
     88  1.1  christos 	if (rc == NULL) {
     89  1.1  christos 		return (-1);	/* malloc fail */
     90  1.1  christos 	}
     91  1.1  christos 	rc->regtype = regtype;
     92  1.1  christos 	rc->addr = addr;
     93  1.1  christos 	rc->value = value;
     94  1.1  christos 
     95  1.1  christos 	TAILQ_INSERT_TAIL(&RegionContentList, rc, links);
     96  1.1  christos 	return (0);
     97  1.1  christos }
     98  1.1  christos 
     99  1.1  christos static int
    100  1.1  christos aml_simulate_regcontent_read(int regtype, u_int32_t addr, u_int8_t *valuep)
    101  1.1  christos {
    102  1.1  christos 	struct	ACPIRegionContent *rc;
    103  1.1  christos 
    104  1.1  christos 	if (!aml_simulation_initialized) {
    105  1.1  christos 		aml_simulation_init();
    106  1.1  christos 	}
    107  1.1  christos 	TAILQ_FOREACH(rc, &RegionContentList, links) {
    108  1.1  christos 		if (rc->regtype == regtype && rc->addr == addr) {
    109  1.1  christos 			*valuep = rc->value;
    110  1.1  christos 			return (1);	/* found */
    111  1.1  christos 		}
    112  1.1  christos 	}
    113  1.1  christos 
    114  1.1  christos 	return (aml_simulate_regcontent_add(regtype, addr, 0));
    115  1.1  christos }
    116  1.1  christos 
    117  1.1  christos static int
    118  1.1  christos aml_simulate_regcontent_write(int regtype, u_int32_t addr, u_int8_t *valuep)
    119  1.1  christos {
    120  1.1  christos 	struct	ACPIRegionContent *rc;
    121  1.1  christos 
    122  1.1  christos 	if (!aml_simulation_initialized) {
    123  1.1  christos 		aml_simulation_init();
    124  1.1  christos 	}
    125  1.1  christos 	TAILQ_FOREACH(rc, &RegionContentList, links) {
    126  1.1  christos 		if (rc->regtype == regtype && rc->addr == addr) {
    127  1.1  christos 			rc->value = *valuep;
    128  1.1  christos 			return (1);	/* exists */
    129  1.1  christos 		}
    130  1.1  christos 	}
    131  1.1  christos 
    132  1.1  christos 	return (aml_simulate_regcontent_add(regtype, addr, *valuep));
    133  1.1  christos }
    134  1.1  christos 
    135  1.1  christos static u_int32_t
    136  1.1  christos aml_simulate_prompt(char *msg, u_int32_t def_val)
    137  1.1  christos {
    138  1.1  christos 	char		buf[16], *ep;
    139  1.1  christos 	u_int32_t	val;
    140  1.1  christos 
    141  1.1  christos 	val = def_val;
    142  1.1  christos 	printf("DEBUG");
    143  1.1  christos 	if (msg != NULL) {
    144  1.1  christos 		printf("%s", msg);
    145  1.1  christos 	}
    146  1.1  christos 	printf("(default: 0x%x / %u) >>", val, val);
    147  1.1  christos 	fflush(stdout);
    148  1.1  christos 
    149  1.1  christos 	bzero(buf, sizeof buf);
    150  1.1  christos 	while (1) {
    151  1.1  christos 		if (read(0, buf, sizeof buf) == 0) {
    152  1.1  christos 			continue;
    153  1.1  christos 		}
    154  1.1  christos 		if (buf[0] == '\n') {
    155  1.1  christos 			break;	/* use default value */
    156  1.1  christos 		}
    157  1.1  christos 		if (buf[0] == '0' && buf[1] == 'x') {
    158  1.1  christos 			val = strtoq(buf, &ep, 16);
    159  1.1  christos 		} else {
    160  1.1  christos 			val = strtoq(buf, &ep, 10);
    161  1.1  christos 		}
    162  1.1  christos 		break;
    163  1.1  christos 	}
    164  1.1  christos 	return (val);
    165  1.1  christos }
    166  1.1  christos 
    167  1.1  christos static void
    168  1.1  christos aml_simulation_regload(const char *dumpfile)
    169  1.1  christos {
    170  1.1  christos 	char	buf[256], *np, *ep;
    171  1.1  christos 	struct	ACPIRegionContent rc;
    172  1.1  christos 	FILE	*fp;
    173  1.1  christos 
    174  1.1  christos 	if (!aml_simulation_initialized) {
    175  1.1  christos 		return;
    176  1.1  christos 	}
    177  1.1  christos 	if ((fp = fopen(dumpfile, "r")) == NULL) {
    178  1.1  christos 		warn("%s", dumpfile);
    179  1.1  christos 		return;
    180  1.1  christos 	}
    181  1.1  christos 	while (fgets(buf, sizeof buf, fp) != NULL) {
    182  1.1  christos 		np = buf;
    183  1.1  christos 		/* reading region type */
    184  1.1  christos 		rc.regtype = strtoq(np, &ep, 10);
    185  1.1  christos 		if (np == ep) {
    186  1.1  christos 			continue;
    187  1.1  christos 		}
    188  1.1  christos 		np = ep;
    189  1.1  christos 
    190  1.1  christos 		/* reading address */
    191  1.1  christos 		rc.addr = strtoq(np, &ep, 16);
    192  1.1  christos 		if (np == ep) {
    193  1.1  christos 			continue;
    194  1.1  christos 		}
    195  1.1  christos 		np = ep;
    196  1.1  christos 
    197  1.1  christos 		/* reading value */
    198  1.1  christos 		rc.value = strtoq(np, &ep, 16);
    199  1.1  christos 		if (np == ep) {
    200  1.1  christos 			continue;
    201  1.1  christos 		}
    202  1.1  christos 		aml_simulate_regcontent_write(rc.regtype, rc.addr, &rc.value);
    203  1.1  christos 	}
    204  1.1  christos 
    205  1.1  christos 	fclose(fp);
    206  1.1  christos }
    207  1.1  christos 
    208  1.1  christos int
    209  1.1  christos aml_region_read_simple(struct aml_region_handle *h, vm_offset_t offset,
    210  1.1  christos     u_int32_t *valuep)
    211  1.1  christos {
    212  1.1  christos 	int		i, state;
    213  1.1  christos 	u_int8_t	val;
    214  1.1  christos 	u_int32_t	value;
    215  1.1  christos 
    216  1.1  christos 	state = 0;
    217  1.1  christos 	value = val = 0;
    218  1.1  christos 	for (i = 0; i < h->unit; i++) {
    219  1.1  christos 		state = aml_simulate_regcontent_read(h->regtype,
    220  1.1  christos 		    h->addr + offset + i, &val);
    221  1.1  christos 		if (state == -1) {
    222  1.1  christos 			goto out;
    223  1.1  christos 		}
    224  1.1  christos 		value |= val << (i * 8);
    225  1.1  christos 	}
    226  1.1  christos 	*valuep = value;
    227  1.1  christos out:
    228  1.1  christos 	return (state);
    229  1.1  christos }
    230  1.1  christos 
    231  1.1  christos int
    232  1.1  christos aml_region_write_simple(struct aml_region_handle *h, vm_offset_t offset,
    233  1.1  christos     u_int32_t value)
    234  1.1  christos {
    235  1.1  christos 	int		i, state;
    236  1.1  christos 	u_int8_t	val;
    237  1.1  christos 
    238  1.1  christos 	state = 0;
    239  1.1  christos 	val = 0;
    240  1.1  christos 	for (i = 0; i < h->unit; i++) {
    241  1.1  christos 		val = value & 0xff;
    242  1.1  christos 		state = aml_simulate_regcontent_write(h->regtype,
    243  1.1  christos 		    h->addr + offset + i, &val);
    244  1.1  christos 		if (state == -1) {
    245  1.1  christos 			goto out;
    246  1.1  christos 		}
    247  1.1  christos 		value = value >> 8;
    248  1.1  christos 	}
    249  1.1  christos out:
    250  1.1  christos 	return (state);
    251  1.1  christos }
    252  1.1  christos 
    253  1.1  christos u_int32_t
    254  1.1  christos aml_region_prompt_read(struct aml_region_handle *h, u_int32_t value)
    255  1.1  christos {
    256  1.1  christos 	u_int32_t 	retval;
    257  1.1  christos 	char		buf[64];
    258  1.1  christos 
    259  1.1  christos 	retval = value;
    260  1.1  christos 	sprintf(buf, "[read(%d, 0x%lx)&mask:0x%x]",
    261  1.1  christos 	    h->regtype, h->addr, value);
    262  1.1  christos 	if (aml_debug_prompt_reginput) {
    263  1.1  christos 		retval = aml_simulate_prompt(buf, value);
    264  1.1  christos 	} else {
    265  1.1  christos 		printf("\t%s\n", buf);
    266  1.1  christos 	}
    267  1.1  christos 
    268  1.1  christos 	return (retval);
    269  1.1  christos }
    270  1.1  christos 
    271  1.1  christos u_int32_t
    272  1.1  christos aml_region_prompt_write(struct aml_region_handle *h, u_int32_t value)
    273  1.1  christos {
    274  1.1  christos 	u_int32_t 	retval;
    275  1.1  christos 	char		buf[64];
    276  1.1  christos 
    277  1.1  christos 	retval = value;
    278  1.1  christos 	if (aml_debug_prompt_regoutput) {
    279  1.1  christos 		printf("\n");
    280  1.1  christos 		sprintf(buf, "[write(%d, 0x%x, 0x%lx)]",
    281  1.1  christos 		    h->regtype, value, h->addr);
    282  1.1  christos 		retval = aml_simulate_prompt(buf, value);
    283  1.1  christos 	}
    284  1.1  christos 
    285  1.1  christos 	return (retval);
    286  1.1  christos }
    287  1.1  christos 
    288  1.1  christos int
    289  1.1  christos aml_region_prompt_update_value(u_int32_t orgval, u_int32_t value,
    290  1.1  christos     struct aml_region_handle *h)
    291  1.1  christos {
    292  1.1  christos 	int	state;
    293  1.1  christos 
    294  1.1  christos 	state = 0;
    295  1.1  christos 	if (orgval != value) {
    296  1.1  christos 		state = aml_region_io(h->env, AML_REGION_OUTPUT, h->regtype,
    297  1.1  christos 		    h->flags, &value, h->baseaddr, h->bitoffset, h->bitlen);
    298  1.1  christos 		if (state == -1) {
    299  1.1  christos 			goto out;
    300  1.1  christos 		}
    301  1.1  christos 	}
    302  1.1  christos 
    303  1.1  christos out:
    304  1.1  christos 	return (state);
    305  1.1  christos }
    306  1.1  christos 
    307  1.1  christos static int
    308  1.1  christos aml_simulate_region_io_buffer(int io, int regtype, u_int32_t flags,
    309  1.1  christos     u_int8_t *buffer, u_int32_t baseaddr, u_int32_t bitoffset, u_int32_t bitlen)
    310  1.1  christos {
    311  1.1  christos 	u_int8_t	val;
    312  1.1  christos 	u_int8_t	offsetlow, offsethigh;
    313  1.1  christos 	u_int32_t	addr, byteoffset, bytelen;
    314  1.1  christos 	int		state, i;
    315  1.1  christos 
    316  1.1  christos 	val = 0;
    317  1.1  christos 	offsetlow = offsethigh = 0;
    318  1.1  christos 	state = 0;
    319  1.1  christos 
    320  1.1  christos 	byteoffset = bitoffset / 8;
    321  1.1  christos 	bytelen = bitlen / 8 + ((bitlen % 8) ? 1 : 0);
    322  1.1  christos 	addr = baseaddr + byteoffset;
    323  1.1  christos 	offsetlow = bitoffset % 8;
    324  1.1  christos 	assert(offsetlow == 0);
    325  1.1  christos 
    326  1.1  christos 	if (bytelen > 1) {
    327  1.1  christos 		offsethigh = (bitlen - (8 - offsetlow)) % 8;
    328  1.1  christos 	}
    329  1.1  christos 	assert(offsethigh == 0);
    330  1.1  christos 
    331  1.1  christos 	for (i = bytelen; i > 0; i--, addr++) {
    332  1.1  christos 		switch (io) {
    333  1.1  christos 		case AML_REGION_INPUT:
    334  1.1  christos 			val = 0;
    335  1.1  christos 			state = aml_simulate_regcontent_read(regtype, addr, &val);
    336  1.1  christos 			if (state == -1) {
    337  1.1  christos 				goto finish;
    338  1.1  christos 			}
    339  1.1  christos 			buffer[bytelen - i] = val;
    340  1.1  christos 			break;
    341  1.1  christos 		case AML_REGION_OUTPUT:
    342  1.1  christos 			val = buffer[bytelen - i];
    343  1.1  christos 			state = aml_simulate_regcontent_write(regtype,
    344  1.1  christos 			    addr, &val);
    345  1.1  christos 			if (state == -1) {
    346  1.1  christos 				goto finish;
    347  1.1  christos 			}
    348  1.1  christos 			break;
    349  1.1  christos 		}
    350  1.1  christos 	}
    351  1.1  christos finish:
    352  1.1  christos 	return (state);
    353  1.1  christos }
    354  1.1  christos 
    355  1.1  christos static u_int32_t
    356  1.1  christos aml_simulate_region_read(struct aml_environ *env, int regtype,
    357  1.1  christos     u_int32_t flags, u_int32_t addr, u_int32_t bitoffset, u_int32_t bitlen)
    358  1.1  christos {
    359  1.1  christos 	u_int32_t	value;
    360  1.1  christos 	int	state;
    361  1.1  christos 
    362  1.1  christos 	state = aml_region_io(env, AML_REGION_INPUT, regtype, flags, &value,
    363  1.1  christos 	    addr, bitoffset, bitlen);
    364  1.1  christos 	assert(state != -1);
    365  1.1  christos 	return (value);
    366  1.1  christos }
    367  1.1  christos 
    368  1.1  christos static int
    369  1.1  christos aml_simulate_region_read_into_buffer(int regtype, u_int32_t flags,
    370  1.1  christos     u_int32_t addr, u_int32_t bitoffset, u_int32_t bitlen, u_int8_t *buffer)
    371  1.1  christos {
    372  1.1  christos 	int	state;
    373  1.1  christos 
    374  1.1  christos 	state = aml_simulate_region_io_buffer(AML_REGION_INPUT, regtype, flags,
    375  1.1  christos 	    buffer, addr, bitoffset, bitlen);
    376  1.1  christos 	assert(state != -1);
    377  1.1  christos 	return (state);
    378  1.1  christos }
    379  1.1  christos 
    380  1.1  christos static int
    381  1.1  christos aml_simulate_region_write(struct aml_environ *env, int regtype,
    382  1.1  christos     u_int32_t flags, u_int32_t value, u_int32_t addr, u_int32_t bitoffset,
    383  1.1  christos     u_int32_t bitlen)
    384  1.1  christos {
    385  1.1  christos 	int	state;
    386  1.1  christos 
    387  1.1  christos 	state = aml_region_io(env, AML_REGION_OUTPUT, regtype, flags,
    388  1.1  christos 	    &value, addr, bitoffset, bitlen);
    389  1.1  christos 	assert(state != -1);
    390  1.1  christos 	return (state);
    391  1.1  christos }
    392  1.1  christos 
    393  1.1  christos static int
    394  1.1  christos aml_simulate_region_write_from_buffer(int regtype, u_int32_t flags,
    395  1.1  christos     u_int8_t *buffer, u_int32_t addr, u_int32_t bitoffset, u_int32_t bitlen)
    396  1.1  christos {
    397  1.1  christos 	int	state;
    398  1.1  christos 
    399  1.1  christos 	state = aml_simulate_region_io_buffer(AML_REGION_OUTPUT, regtype,
    400  1.1  christos 	    flags, buffer, addr, bitoffset, bitlen);
    401  1.1  christos 	assert(state != -1);
    402  1.1  christos 	return (state);
    403  1.1  christos }
    404  1.1  christos 
    405  1.1  christos static int
    406  1.1  christos aml_simulate_region_bcopy(struct aml_environ *env, int regtype,
    407  1.1  christos     u_int32_t flags, u_int32_t addr,
    408  1.1  christos     u_int32_t bitoffset, u_int32_t bitlen,
    409  1.1  christos     u_int32_t dflags, u_int32_t daddr,
    410  1.1  christos     u_int32_t dbitoffset, u_int32_t dbitlen)
    411  1.1  christos {
    412  1.1  christos 	u_int32_t	len, i;
    413  1.1  christos 	u_int32_t	value;
    414  1.1  christos 	int		state;
    415  1.1  christos 
    416  1.1  christos 	len = (bitlen > dbitlen) ? dbitlen : bitlen;
    417  1.1  christos 	len = len / 8 + ((len % 8) ? 1 : 0);
    418  1.1  christos 
    419  1.1  christos 	for (i = 0; i < len; i++) {
    420  1.1  christos 		state = aml_region_io(env, AML_REGION_INPUT, regtype,
    421  1.1  christos 		    flags, &value, addr, bitoffset + i * 8, 8);
    422  1.1  christos 		assert(state != -1);
    423  1.1  christos 		state = aml_region_io(env, AML_REGION_OUTPUT, regtype,
    424  1.1  christos 		    dflags, &value, daddr, dbitoffset + i * 8, 8);
    425  1.1  christos 		assert(state != -1);
    426  1.1  christos 	}
    427  1.1  christos 
    428  1.1  christos 	return (0);
    429  1.1  christos }
    430  1.1  christos 
    431  1.1  christos u_int32_t
    432  1.1  christos aml_region_read(struct aml_environ *env, int regtype, u_int32_t flags,
    433  1.1  christos     u_int32_t addr, u_int32_t bitoffset, u_int32_t bitlen)
    434  1.1  christos {
    435  1.1  christos 
    436  1.1  christos 	AML_REGION_READ_DEBUG(regtype, flags, addr, bitoffset, bitlen);
    437  1.1  christos 
    438  1.1  christos 	return (aml_simulate_region_read(env, regtype, flags, addr,
    439  1.1  christos 	    bitoffset, bitlen));
    440  1.1  christos }
    441  1.1  christos 
    442  1.1  christos int
    443  1.1  christos aml_region_read_into_buffer(struct aml_environ *env, int regtype,
    444  1.1  christos     u_int32_t flags, u_int32_t addr, u_int32_t bitoffset,
    445  1.1  christos     u_int32_t bitlen, u_int8_t *buffer)
    446  1.1  christos {
    447  1.1  christos 
    448  1.1  christos 	AML_REGION_READ_INTO_BUFFER_DEBUG(regtype, flags, addr, bitoffset, bitlen);
    449  1.1  christos 
    450  1.1  christos 	return (aml_simulate_region_read_into_buffer(regtype, flags, addr,
    451  1.1  christos 	    bitoffset, bitlen, buffer));
    452  1.1  christos }
    453  1.1  christos 
    454  1.1  christos int
    455  1.1  christos aml_region_write(struct aml_environ *env, int regtype, u_int32_t flags,
    456  1.1  christos     u_int32_t value, u_int32_t addr, u_int32_t bitoffset, u_int32_t bitlen)
    457  1.1  christos {
    458  1.1  christos 
    459  1.1  christos 	AML_REGION_WRITE_DEBUG(regtype, flags, value, addr, bitoffset, bitlen);
    460  1.1  christos 
    461  1.1  christos 	return (aml_simulate_region_write(env, regtype, flags, value, addr,
    462  1.1  christos 	    bitoffset, bitlen));
    463  1.1  christos }
    464  1.1  christos 
    465  1.1  christos int
    466  1.1  christos aml_region_write_from_buffer(struct aml_environ *env, int regtype,
    467  1.1  christos     u_int32_t flags, u_int8_t *buffer, u_int32_t addr, u_int32_t bitoffset,
    468  1.1  christos     u_int32_t bitlen)
    469  1.1  christos {
    470  1.1  christos 
    471  1.1  christos 	AML_REGION_WRITE_FROM_BUFFER_DEBUG(regtype, flags,
    472  1.1  christos 	    addr, bitoffset, bitlen);
    473  1.1  christos 
    474  1.1  christos 	return (aml_simulate_region_write_from_buffer(regtype, flags, buffer,
    475  1.1  christos 	    addr, bitoffset, bitlen));
    476  1.1  christos }
    477  1.1  christos 
    478  1.1  christos int
    479  1.1  christos aml_region_bcopy(struct aml_environ *env, int regtype, u_int32_t flags,
    480  1.1  christos     u_int32_t addr, u_int32_t bitoffset, u_int32_t bitlen,
    481  1.1  christos     u_int32_t dflags, u_int32_t daddr,
    482  1.1  christos     u_int32_t dbitoffset, u_int32_t dbitlen)
    483  1.1  christos {
    484  1.1  christos 
    485  1.1  christos 	AML_REGION_BCOPY_DEBUG(regtype, flags, addr, bitoffset, bitlen,
    486  1.1  christos 	    dflags, daddr, dbitoffset, dbitlen);
    487  1.1  christos 
    488  1.1  christos 	return (aml_simulate_region_bcopy(env, regtype, flags, addr, bitoffset,
    489  1.1  christos 	    bitlen, dflags, daddr, dbitoffset, dbitlen));
    490  1.1  christos }
    491  1.1  christos 
    492  1.1  christos void
    493  1.1  christos aml_simulation_regdump(const char *dumpfile)
    494  1.1  christos {
    495  1.1  christos 	struct	ACPIRegionContent *rc;
    496  1.1  christos 	FILE	*fp;
    497  1.1  christos 
    498  1.1  christos 	if (!aml_simulation_initialized) {
    499  1.1  christos 		return;
    500  1.1  christos 	}
    501  1.1  christos 	if ((fp = fopen(dumpfile, "w")) == NULL) {
    502  1.1  christos 		warn("%s", dumpfile);
    503  1.1  christos 		return;
    504  1.1  christos 	}
    505  1.1  christos 	while (!TAILQ_EMPTY(&RegionContentList)) {
    506  1.1  christos 		rc = TAILQ_FIRST(&RegionContentList);
    507  1.1  christos 		fprintf(fp, "%d	0x%x	0x%x\n",
    508  1.1  christos 		    rc->regtype, rc->addr, rc->value);
    509  1.1  christos 		TAILQ_REMOVE(&RegionContentList, rc, links);
    510  1.1  christos 		free(rc);
    511  1.1  christos 	}
    512  1.1  christos 
    513  1.1  christos 	fclose(fp);
    514  1.1  christos 	TAILQ_INIT(&RegionContentList);
    515  1.1  christos }
    516