Fix #8729.
[haiku.git] / src / add-ons / kernel / bus_managers / acpi / SmallResourceData.cpp
blob8fdd388486cfd1b0c94aa0ef5201b773b08a11b6
1 /*
2 * Copyright 2009, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Clemens Zeidler, haiku@clemens-zeidler.de
7 */
9 #include "SmallResourceData.h"
11 #include <stdlib.h>
13 //#define TRACE_SMALLRESOURCEDATA
14 #ifdef TRACE_SMALLRESOURCEDATA
15 # define TRACE(x...) dprintf("Small Resource Data: "x)
16 #else
17 # define TRACE(x...)
18 #endif
21 void
22 io_port::Print()
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)
37 acpi_data buffer;
38 buffer.pointer = NULL;
39 buffer.length = ACPI_ALLOCATE_BUFFER;
41 fStatus = acpi->evaluate_method(acpiCookie, method, NULL, &buffer);
43 if (fStatus != B_OK)
44 return;
46 fBuffer = (acpi_object_type*)buffer.pointer;
48 if (fBuffer[0].object_type != ACPI_TYPE_BUFFER) {
49 fStatus = B_ERROR;
50 return;
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)
65 free(fBuffer);
69 status_t
70 SmallResourceData::InitCheck()
72 return fStatus;
76 int8
77 SmallResourceData::GetType()
79 return *fResourcePointer;
83 status_t
84 SmallResourceData::ReadIOPort(io_port* ioPort)
86 const size_t packageSize = 8;
88 if (fRemainingBufferSize < packageSize)
89 return B_ERROR;
90 if (fResourcePointer[0] != kIOPort)
91 return B_ERROR;
93 ioPort->deviceAddresses16Bit = (fResourcePointer[1] == 1);
95 int16 tmp;
96 tmp = fResourcePointer[3];
97 tmp = tmp << 8;
98 tmp |= fResourcePointer[2];
99 ioPort->minimumBase = tmp;
101 tmp = fResourcePointer[5];
102 tmp = tmp << 8;
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));
113 return B_OK;