Home | History | Annotate | Line # | Download | only in amldb
      1  1.3     lukem /*	$NetBSD: region.c,v 1.3 2009/01/18 09:46:59 lukem 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.3     lukem __RCSID("$NetBSD: region.c,v 1.3 2009/01/18 09:46:59 lukem 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.2  gmcgarry #include <aml/aml_common.h>
     45  1.1  christos #include <aml/aml_region.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.3     lukem 	int		state;
    213  1.1  christos 	u_int8_t	val;
    214  1.3     lukem 	u_int32_t	value, i;
    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.3     lukem 	int		state;
    236  1.1  christos 	u_int8_t	val;
    237  1.3     lukem 	u_int32_t	i;
    238  1.1  christos 
    239  1.1  christos 	state = 0;
    240  1.1  christos 	val = 0;
    241  1.1  christos 	for (i = 0; i < h->unit; i++) {
    242  1.1  christos 		val = value & 0xff;
    243  1.1  christos 		state = aml_simulate_regcontent_write(h->regtype,
    244  1.1  christos 		    h->addr + offset + i, &val);
    245  1.1  christos 		if (state == -1) {
    246  1.1  christos 			goto out;
    247  1.1  christos 		}
    248  1.1  christos 		value = value >> 8;
    249  1.1  christos 	}
    250  1.1  christos out:
    251  1.1  christos 	return (state);
    252  1.1  christos }
    253  1.1  christos 
    254  1.1  christos u_int32_t
    255  1.1  christos aml_region_prompt_read(struct aml_region_handle *h, u_int32_t value)
    256  1.1  christos {
    257  1.1  christos 	u_int32_t 	retval;
    258  1.1  christos 	char		buf[64];
    259  1.1  christos 
    260  1.1  christos 	retval = value;
    261  1.1  christos 	sprintf(buf, "[read(%d, 0x%lx)&mask:0x%x]",
    262  1.1  christos 	    h->regtype, h->addr, value);
    263  1.1  christos 	if (aml_debug_prompt_reginput) {
    264  1.1  christos 		retval = aml_simulate_prompt(buf, value);
    265  1.1  christos 	} else {
    266  1.1  christos 		printf("\t%s\n", buf);
    267  1.1  christos 	}
    268  1.1  christos 
    269  1.1  christos 	return (retval);
    270  1.1  christos }
    271  1.1  christos 
    272  1.1  christos u_int32_t
    273  1.1  christos aml_region_prompt_write(struct aml_region_handle *h, u_int32_t value)
    274  1.1  christos {
    275  1.1  christos 	u_int32_t 	retval;
    276  1.1  christos 	char		buf[64];
    277  1.1  christos 
    278  1.1  christos 	retval = value;
    279  1.1  christos 	if (aml_debug_prompt_regoutput) {
    280  1.1  christos 		printf("\n");
    281  1.1  christos 		sprintf(buf, "[write(%d, 0x%x, 0x%lx)]",
    282  1.1  christos 		    h->regtype, value, h->addr);
    283  1.1  christos 		retval = aml_simulate_prompt(buf, value);
    284  1.1  christos 	}
    285  1.1  christos 
    286  1.1  christos 	return (retval);
    287  1.1  christos }
    288  1.1  christos 
    289  1.1  christos int
    290  1.1  christos aml_region_prompt_update_value(u_int32_t orgval, u_int32_t value,
    291  1.1  christos     struct aml_region_handle *h)
    292  1.1  christos {
    293  1.1  christos 	int	state;
    294  1.1  christos 
    295  1.1  christos 	state = 0;
    296  1.1  christos 	if (orgval != value) {
    297  1.1  christos 		state = aml_region_io(h->env, AML_REGION_OUTPUT, h->regtype,
    298  1.1  christos 		    h->flags, &value, h->baseaddr, h->bitoffset, h->bitlen);
    299  1.1  christos 		if (state == -1) {
    300  1.1  christos 			goto out;
    301  1.1  christos 		}
    302  1.1  christos 	}
    303  1.1  christos 
    304  1.1  christos out:
    305  1.1  christos 	return (state);
    306  1.1  christos }
    307  1.1  christos 
    308  1.1  christos static int
    309  1.1  christos aml_simulate_region_io_buffer(int io, int regtype, u_int32_t flags,
    310  1.1  christos     u_int8_t *buffer, u_int32_t baseaddr, u_int32_t bitoffset, u_int32_t bitlen)
    311  1.1  christos {
    312  1.1  christos 	u_int8_t	val;
    313  1.1  christos 	u_int8_t	offsetlow, offsethigh;
    314  1.1  christos 	u_int32_t	addr, byteoffset, bytelen;
    315  1.1  christos 	int		state, i;
    316  1.1  christos 
    317  1.1  christos 	val = 0;
    318  1.1  christos 	offsetlow = offsethigh = 0;
    319  1.1  christos 	state = 0;
    320  1.1  christos 
    321  1.1  christos 	byteoffset = bitoffset / 8;
    322  1.1  christos 	bytelen = bitlen / 8 + ((bitlen % 8) ? 1 : 0);
    323  1.1  christos 	addr = baseaddr + byteoffset;
    324  1.1  christos 	offsetlow = bitoffset % 8;
    325  1.1  christos 	assert(offsetlow == 0);
    326  1.1  christos 
    327  1.1  christos 	if (bytelen > 1) {
    328  1.1  christos 		offsethigh = (bitlen - (8 - offsetlow)) % 8;
    329  1.1  christos 	}
    330  1.1  christos 	assert(offsethigh == 0);
    331  1.1  christos 
    332  1.1  christos 	for (i = bytelen; i > 0; i--, addr++) {
    333  1.1  christos 		switch (io) {
    334  1.1  christos 		case AML_REGION_INPUT:
    335  1.1  christos 			val = 0;
    336  1.1  christos 			state = aml_simulate_regcontent_read(regtype, addr, &val);
    337  1.1  christos 			if (state == -1) {
    338  1.1  christos 				goto finish;
    339  1.1  christos 			}
    340  1.1  christos 			buffer[bytelen - i] = val;
    341  1.1  christos 			break;
    342  1.1  christos 		case AML_REGION_OUTPUT:
    343  1.1  christos 			val = buffer[bytelen - i];
    344  1.1  christos 			state = aml_simulate_regcontent_write(regtype,
    345  1.1  christos 			    addr, &val);
    346  1.1  christos 			if (state == -1) {
    347  1.1  christos 				goto finish;
    348  1.1  christos 			}
    349  1.1  christos 			break;
    350  1.1  christos 		}
    351  1.1  christos 	}
    352  1.1  christos finish:
    353  1.1  christos 	return (state);
    354  1.1  christos }
    355  1.1  christos 
    356  1.1  christos static u_int32_t
    357  1.1  christos aml_simulate_region_read(struct aml_environ *env, int regtype,
    358  1.1  christos     u_int32_t flags, u_int32_t addr, u_int32_t bitoffset, u_int32_t bitlen)
    359  1.1  christos {
    360  1.1  christos 	u_int32_t	value;
    361  1.1  christos 	int	state;
    362  1.1  christos 
    363  1.1  christos 	state = aml_region_io(env, AML_REGION_INPUT, regtype, flags, &value,
    364  1.1  christos 	    addr, bitoffset, bitlen);
    365  1.1  christos 	assert(state != -1);
    366  1.1  christos 	return (value);
    367  1.1  christos }
    368  1.1  christos 
    369  1.1  christos static int
    370  1.1  christos aml_simulate_region_read_into_buffer(int regtype, u_int32_t flags,
    371  1.1  christos     u_int32_t addr, u_int32_t bitoffset, u_int32_t bitlen, u_int8_t *buffer)
    372  1.1  christos {
    373  1.1  christos 	int	state;
    374  1.1  christos 
    375  1.1  christos 	state = aml_simulate_region_io_buffer(AML_REGION_INPUT, regtype, flags,
    376  1.1  christos 	    buffer, addr, bitoffset, bitlen);
    377  1.1  christos 	assert(state != -1);
    378  1.1  christos 	return (state);
    379  1.1  christos }
    380  1.1  christos 
    381  1.1  christos static int
    382  1.1  christos aml_simulate_region_write(struct aml_environ *env, int regtype,
    383  1.1  christos     u_int32_t flags, u_int32_t value, u_int32_t addr, u_int32_t bitoffset,
    384  1.1  christos     u_int32_t bitlen)
    385  1.1  christos {
    386  1.1  christos 	int	state;
    387  1.1  christos 
    388  1.1  christos 	state = aml_region_io(env, AML_REGION_OUTPUT, regtype, flags,
    389  1.1  christos 	    &value, addr, bitoffset, bitlen);
    390  1.1  christos 	assert(state != -1);
    391  1.1  christos 	return (state);
    392  1.1  christos }
    393  1.1  christos 
    394  1.1  christos static int
    395  1.1  christos aml_simulate_region_write_from_buffer(int regtype, u_int32_t flags,
    396  1.1  christos     u_int8_t *buffer, u_int32_t addr, u_int32_t bitoffset, u_int32_t bitlen)
    397  1.1  christos {
    398  1.1  christos 	int	state;
    399  1.1  christos 
    400  1.1  christos 	state = aml_simulate_region_io_buffer(AML_REGION_OUTPUT, regtype,
    401  1.1  christos 	    flags, buffer, addr, bitoffset, bitlen);
    402  1.1  christos 	assert(state != -1);
    403  1.1  christos 	return (state);
    404  1.1  christos }
    405  1.1  christos 
    406  1.1  christos static int
    407  1.1  christos aml_simulate_region_bcopy(struct aml_environ *env, int regtype,
    408  1.1  christos     u_int32_t flags, u_int32_t addr,
    409  1.1  christos     u_int32_t bitoffset, u_int32_t bitlen,
    410  1.1  christos     u_int32_t dflags, u_int32_t daddr,
    411  1.1  christos     u_int32_t dbitoffset, u_int32_t dbitlen)
    412  1.1  christos {
    413  1.1  christos 	u_int32_t	len, i;
    414  1.1  christos 	u_int32_t	value;
    415  1.1  christos 	int		state;
    416  1.1  christos 
    417  1.1  christos 	len = (bitlen > dbitlen) ? dbitlen : bitlen;
    418  1.1  christos 	len = len / 8 + ((len % 8) ? 1 : 0);
    419  1.1  christos 
    420  1.1  christos 	for (i = 0; i < len; i++) {
    421  1.1  christos 		state = aml_region_io(env, AML_REGION_INPUT, regtype,
    422  1.1  christos 		    flags, &value, addr, bitoffset + i * 8, 8);
    423  1.1  christos 		assert(state != -1);
    424  1.1  christos 		state = aml_region_io(env, AML_REGION_OUTPUT, regtype,
    425  1.1  christos 		    dflags, &value, daddr, dbitoffset + i * 8, 8);
    426  1.1  christos 		assert(state != -1);
    427  1.1  christos 	}
    428  1.1  christos 
    429  1.1  christos 	return (0);
    430  1.1  christos }
    431  1.1  christos 
    432  1.1  christos u_int32_t
    433  1.1  christos aml_region_read(struct aml_environ *env, int regtype, u_int32_t flags,
    434  1.1  christos     u_int32_t addr, u_int32_t bitoffset, u_int32_t bitlen)
    435  1.1  christos {
    436  1.1  christos 
    437  1.1  christos 	AML_REGION_READ_DEBUG(regtype, flags, addr, bitoffset, bitlen);
    438  1.1  christos 
    439  1.1  christos 	return (aml_simulate_region_read(env, regtype, flags, addr,
    440  1.1  christos 	    bitoffset, bitlen));
    441  1.1  christos }
    442  1.1  christos 
    443  1.1  christos int
    444  1.1  christos aml_region_read_into_buffer(struct aml_environ *env, int regtype,
    445  1.1  christos     u_int32_t flags, u_int32_t addr, u_int32_t bitoffset,
    446  1.1  christos     u_int32_t bitlen, u_int8_t *buffer)
    447  1.1  christos {
    448  1.1  christos 
    449  1.1  christos 	AML_REGION_READ_INTO_BUFFER_DEBUG(regtype, flags, addr, bitoffset, bitlen);
    450  1.1  christos 
    451  1.1  christos 	return (aml_simulate_region_read_into_buffer(regtype, flags, addr,
    452  1.1  christos 	    bitoffset, bitlen, buffer));
    453  1.1  christos }
    454  1.1  christos 
    455  1.1  christos int
    456  1.1  christos aml_region_write(struct aml_environ *env, int regtype, u_int32_t flags,
    457  1.1  christos     u_int32_t value, u_int32_t addr, u_int32_t bitoffset, u_int32_t bitlen)
    458  1.1  christos {
    459  1.1  christos 
    460  1.1  christos 	AML_REGION_WRITE_DEBUG(regtype, flags, value, addr, bitoffset, bitlen);
    461  1.1  christos 
    462  1.1  christos 	return (aml_simulate_region_write(env, regtype, flags, value, addr,
    463  1.1  christos 	    bitoffset, bitlen));
    464  1.1  christos }
    465  1.1  christos 
    466  1.1  christos int
    467  1.1  christos aml_region_write_from_buffer(struct aml_environ *env, int regtype,
    468  1.1  christos     u_int32_t flags, u_int8_t *buffer, u_int32_t addr, u_int32_t bitoffset,
    469  1.1  christos     u_int32_t bitlen)
    470  1.1  christos {
    471  1.1  christos 
    472  1.1  christos 	AML_REGION_WRITE_FROM_BUFFER_DEBUG(regtype, flags,
    473  1.1  christos 	    addr, bitoffset, bitlen);
    474  1.1  christos 
    475  1.1  christos 	return (aml_simulate_region_write_from_buffer(regtype, flags, buffer,
    476  1.1  christos 	    addr, bitoffset, bitlen));
    477  1.1  christos }
    478  1.1  christos 
    479  1.1  christos int
    480  1.1  christos aml_region_bcopy(struct aml_environ *env, int regtype, u_int32_t flags,
    481  1.1  christos     u_int32_t addr, u_int32_t bitoffset, u_int32_t bitlen,
    482  1.1  christos     u_int32_t dflags, u_int32_t daddr,
    483  1.1  christos     u_int32_t dbitoffset, u_int32_t dbitlen)
    484  1.1  christos {
    485  1.1  christos 
    486  1.1  christos 	AML_REGION_BCOPY_DEBUG(regtype, flags, addr, bitoffset, bitlen,
    487  1.1  christos 	    dflags, daddr, dbitoffset, dbitlen);
    488  1.1  christos 
    489  1.1  christos 	return (aml_simulate_region_bcopy(env, regtype, flags, addr, bitoffset,
    490  1.1  christos 	    bitlen, dflags, daddr, dbitoffset, dbitlen));
    491  1.1  christos }
    492  1.1  christos 
    493  1.1  christos void
    494  1.1  christos aml_simulation_regdump(const char *dumpfile)
    495  1.1  christos {
    496  1.1  christos 	struct	ACPIRegionContent *rc;
    497  1.1  christos 	FILE	*fp;
    498  1.1  christos 
    499  1.1  christos 	if (!aml_simulation_initialized) {
    500  1.1  christos 		return;
    501  1.1  christos 	}
    502  1.1  christos 	if ((fp = fopen(dumpfile, "w")) == NULL) {
    503  1.1  christos 		warn("%s", dumpfile);
    504  1.1  christos 		return;
    505  1.1  christos 	}
    506  1.1  christos 	while (!TAILQ_EMPTY(&RegionContentList)) {
    507  1.1  christos 		rc = TAILQ_FIRST(&RegionContentList);
    508  1.1  christos 		fprintf(fp, "%d	0x%x	0x%x\n",
    509  1.1  christos 		    rc->regtype, rc->addr, rc->value);
    510  1.1  christos 		TAILQ_REMOVE(&RegionContentList, rc, links);
    511  1.1  christos 		free(rc);
    512  1.1  christos 	}
    513  1.1  christos 
    514  1.1  christos 	fclose(fp);
    515  1.1  christos 	TAILQ_INIT(&RegionContentList);
    516  1.1  christos }
    517