Autodoc formatting fixes.
[AROS.git] / arch / all-pc / acpi / writereg.c
blob6c9950a3daf0e3c6b3fd2231b361925d3646637a
1 #include <asm/io.h>
2 #include <resources/acpi.h>
4 #include "gas_io.h"
6 /*****************************************************************************
8 NAME */
9 #include <proto/acpi.h>
11 AROS_LH2I(void, ACPI_WriteReg,
13 /* SYNOPSIS */
14 AROS_LHA(struct GENERIC_ACPI_ADDR *, reg, A0),
15 AROS_LHA(IPTR, value, D0),
17 /* LOCATION */
18 struct ACPIBase *, ACPIBase, 4, Acpi)
20 /* FUNCTION
21 Write a value from the register specified by GAS
23 INPUTS
24 reg - a pointer to a generic address structure
25 value - a value to write to the register
27 RESULT
28 None
30 NOTES
31 Only memory and I/O spaces are supported.
32 64-bit registers are supported only in memory space and only on 64-bit platforms.
33 The given GAS must address a complete register, not a data structure.
35 EXAMPLE
37 BUGS
39 SEE ALSO
41 INTERNALS
43 ******************************************************************************/
45 AROS_LIBFUNC_INIT
47 unsigned char size = GetSize(reg);
49 if (reg->register_bit_width != FullSize[reg->size])
52 * Partial bit field.
53 * Read original value from the register and replace the needed bits.
55 unsigned long mask = ((1 << reg->register_bit_width) - 1) << reg->register_bit_offset;
56 unsigned long old = ReadRegInt(reg, size);
58 value = (value << reg->register_bit_offset) & mask;
59 value |= (old & ~mask);
62 switch (reg->address_space_id)
64 case ACPI_SPACE_MEM:
65 switch (size)
67 case ACPI_SIZE_BYTE:
68 *((UBYTE *)(IPTR)reg->address) = value;
69 break;
71 case ACPI_SIZE_WORD:
72 *((UWORD *)(IPTR)reg->address) = value;
73 break;
75 case ACPI_SIZE_DWORD:
76 *((ULONG *)(IPTR)reg->address) = value;
77 break;
79 #if __WORDSIZE == 64
80 case ACPI_SIZE_QUAD:
81 *((UQUAD *)(IPTR)reg->address) = value;
82 break;
83 #endif
85 break;
87 case ACPI_SPACE_IO:
88 switch (size)
90 case ACPI_SIZE_BYTE:
91 outb(value, reg->address);
92 break;
94 case ACPI_SIZE_WORD:
95 outw(value, reg->address);
96 break;
98 case ACPI_SIZE_DWORD:
99 outl(value, reg->address);
100 break;
102 /* ACPI_SIZE_QUAD - not supported ? */
104 break;
107 AROS_LIBFUNC_EXIT