2 * Copyright 2009, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
6 * Clemens Zeidler, haiku@clemens-zeidler.de
9 #include "SmallResourceData.h"
13 //#define TRACE_SMALLRESOURCEDATA
14 #ifdef TRACE_SMALLRESOURCEDATA
15 # define TRACE(x...) dprintf("Small Resource Data: "x)
24 dprintf("io_port:\n");
25 int i
= (deviceAddresses16Bit
? 1 : 0);
26 dprintf("deviceAddresses16Bit %i\n", i
);
27 dprintf("minimumBase %i\n", minimumBase
);
28 dprintf("maximumBase %i\n", maximumBase
);
29 dprintf("minimumBaseAlignment %i\n", minimumBaseAlignment
);
30 dprintf("contigiuousIOPorts %i\n", contigiuousIOPorts
);
34 SmallResourceData::SmallResourceData(acpi_device_module_info
* acpi
,
35 acpi_device acpiCookie
, const char* method
)
38 buffer
.pointer
= NULL
;
39 buffer
.length
= ACPI_ALLOCATE_BUFFER
;
41 fStatus
= acpi
->evaluate_method(acpiCookie
, method
, NULL
, &buffer
);
46 fBuffer
= (acpi_object_type
*)buffer
.pointer
;
48 if (fBuffer
[0].object_type
!= ACPI_TYPE_BUFFER
) {
53 fResourcePointer
= (int8
*)fBuffer
[0].data
.buffer
.buffer
;
54 fBufferSize
= fBuffer
[0].data
.buffer
.length
;
55 fRemainingBufferSize
= fBufferSize
;
57 // ToDo: Check checksum of the endtag. The sum of all databytes + checksum
58 // is zero. See section 6.4.2.8.
62 SmallResourceData::~SmallResourceData()
64 if (InitCheck() == B_OK
)
70 SmallResourceData::InitCheck()
77 SmallResourceData::GetType()
79 return *fResourcePointer
;
84 SmallResourceData::ReadIOPort(io_port
* ioPort
)
86 const size_t packageSize
= 8;
88 if (fRemainingBufferSize
< packageSize
)
90 if (fResourcePointer
[0] != kIOPort
)
93 ioPort
->deviceAddresses16Bit
= (fResourcePointer
[1] == 1);
96 tmp
= fResourcePointer
[3];
98 tmp
|= fResourcePointer
[2];
99 ioPort
->minimumBase
= tmp
;
101 tmp
= fResourcePointer
[5];
103 tmp
|= fResourcePointer
[4];
104 ioPort
->maximumBase
= tmp
;
106 ioPort
->minimumBaseAlignment
= fResourcePointer
[6];
107 ioPort
->contigiuousIOPorts
= fResourcePointer
[7];
109 fResourcePointer
+= packageSize
;
110 fRemainingBufferSize
-= packageSize
;
111 TRACE("SmallResourceData: remaining buffer size %i\n",
112 int(fRemainingBufferSize
));