2 #include <resources/acpi.h>
6 /*****************************************************************************
9 #include <proto/acpi.h>
11 AROS_LH1I(IPTR
, ACPI_ReadReg
,
14 AROS_LHA(struct GENERIC_ACPI_ADDR
*, reg
, A0
),
17 struct ACPIBase
*, ACPIBase
, 3, Acpi
)
20 Read a value from the register specified by GAS
23 reg - a pointer to a generic address structure
26 A value read from the register
29 Only memory and I/O spaces are supported.
30 64-bit registers are supported only in memory space and only on 64-bit platforms.
31 The given GAS must address a complete register, not a data structure.
41 ******************************************************************************/
45 unsigned char size
= GetSize(reg
);
46 IPTR val
= ReadRegInt(reg
, size
);
48 if (reg
->register_bit_width
!= FullSize
[reg
->size
])
52 * Mask out the needed bits and shift to the right.
54 unsigned long mask
= (1 << reg
->register_bit_width
) - 1;
56 val
= (val
>> reg
->register_bit_offset
) & mask
;
64 const unsigned char FullSize
[] = {0, 8, 16, 32, 64};
66 unsigned char GetSize(struct GENERIC_ACPI_ADDR
*reg
)
68 unsigned char size
= reg
->size
;
70 if (size
== ACPI_SIZE_UNDEFINED
)
72 /* Need to compute register size */
73 unsigned char bits
= reg
->register_bit_offset
+ reg
->register_bit_width
;
76 size
= ACPI_SIZE_BYTE
;
78 size
= ACPI_SIZE_WORD
;
80 size
= ACPI_SIZE_DWORD
;
82 size
= ACPI_SIZE_QUAD
;
87 IPTR
ReadRegInt(struct GENERIC_ACPI_ADDR
*reg
, unsigned char size
)
91 switch (reg
->address_space_id
)
97 val
= *((UBYTE
*)(IPTR
)reg
->address
);
101 val
= *((UWORD
*)(IPTR
)reg
->address
);
104 case ACPI_SIZE_DWORD
:
105 val
= *((ULONG
*)(IPTR
)reg
->address
);
110 val
= *((UQUAD
*)(IPTR
)reg
->address
);
120 val
= inb(reg
->address
);
124 val
= inw(reg
->address
);
127 case ACPI_SIZE_DWORD
:
128 val
= inl(reg
->address
);
131 /* ACPI_SIZE_QUAD - not supported ? */