1 /*
2 // Copyright (c) 2014 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16 #include <HwcTrace.h>
17 #include <common/TTMBufferMapper.h>
18
19 namespace android {
20 namespace intel {
21
TTMBufferMapper(Wsbm & wsbm,DataBuffer & buffer)22 TTMBufferMapper::TTMBufferMapper(Wsbm& wsbm, DataBuffer& buffer)
23 : BufferMapper(buffer),
24 mRefCount(0),
25 mWsbm(wsbm),
26 mBufferObject(0),
27 mGttOffsetInPage(0),
28 mCpuAddress(0),
29 mSize(0)
30 {
31 CTRACE();
32 }
33
~TTMBufferMapper()34 TTMBufferMapper::~TTMBufferMapper()
35 {
36 CTRACE();
37 }
38
map()39 bool TTMBufferMapper::map()
40 {
41 void *wsbmBufferObject = 0;
42 buffer_handle_t handle;
43 void *virtAddr;
44 uint32_t gttOffsetInPage;
45
46 CTRACE();
47
48 handle = getHandle();
49
50 bool ret = mWsbm.wrapTTMBuffer((int64_t)handle, &wsbmBufferObject);
51 if (ret == false) {
52 ETRACE("failed to map TTM buffer");
53 return false;
54 }
55
56 // TODO: review this later
57 ret = mWsbm.waitIdleTTMBuffer(wsbmBufferObject);
58 if (ret == false) {
59 ETRACE("failed to wait ttm buffer idle");
60 return false;
61 }
62
63 virtAddr = mWsbm.getCPUAddress(wsbmBufferObject);
64 gttOffsetInPage = mWsbm.getGttOffset(wsbmBufferObject);
65
66 if (!gttOffsetInPage || !virtAddr) {
67 WTRACE("offset = %#x, addr = %p.", gttOffsetInPage, virtAddr);
68 return false;
69 }
70
71 // update parameters
72 mBufferObject = wsbmBufferObject;
73 mGttOffsetInPage = gttOffsetInPage;
74 mCpuAddress = virtAddr;
75 mSize = 0;
76 return true;
77 }
78
unmap()79 bool TTMBufferMapper::unmap()
80 {
81 CTRACE();
82
83 if (!mBufferObject)
84 return false;
85
86 mWsbm.unreferenceTTMBuffer(mBufferObject);
87
88 mGttOffsetInPage = 0;
89 mCpuAddress = 0;
90 mSize = 0;
91 mBufferObject = 0;
92 return true;
93 }
94
waitIdle()95 bool TTMBufferMapper::waitIdle()
96 {
97 return mWsbm.waitIdleTTMBuffer(mBufferObject);
98 }
99
100 } // namespace intel
101 } // namespace android
102
103
104