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/Wsbm.h> 18 19Wsbm::Wsbm(int drmFD) 20 : mInitialized(false) 21{ 22 CTRACE(); 23 mDrmFD = drmFD; 24} 25 26Wsbm::~Wsbm() 27{ 28 WARN_IF_NOT_DEINIT(); 29} 30 31bool Wsbm::initialize() 32{ 33 if (mInitialized) { 34 WTRACE("object is initialized"); 35 return true; 36 } 37 38 int ret = psbWsbmInitialize(mDrmFD); 39 if (ret) { 40 ETRACE("failed to initialize Wsbm"); 41 return false; 42 } 43 44 mInitialized = true; 45 return true; 46} 47 48void Wsbm::deinitialize() 49{ 50 if (!mInitialized) { 51 return; 52 } 53 psbWsbmTakedown(); 54 mInitialized = false; 55} 56 57bool Wsbm::allocateTTMBuffer(uint32_t size, uint32_t align, void ** buf) 58{ 59 int ret = psbWsbmAllocateTTMBuffer(size, align, buf); 60 if (ret) { 61 ETRACE("failed to allocate buffer"); 62 return false; 63 } 64 65 return true; 66} 67 68bool Wsbm::allocateTTMBufferUB(uint32_t size, uint32_t align, void ** buf, void *user_pt) 69{ 70 int ret = psbWsbmAllocateFromUB(size, align, buf, user_pt); 71 if (ret) { 72 ETRACE("failed to allocate UB buffer"); 73 return false; 74 } 75 76 return true; 77} 78 79bool Wsbm::destroyTTMBuffer(void * buf) 80{ 81 int ret = psbWsbmDestroyTTMBuffer(buf); 82 if (ret) { 83 ETRACE("failed to destroy buffer"); 84 return false; 85 } 86 87 return true; 88} 89 90void * Wsbm::getCPUAddress(void * buf) 91{ 92 return psbWsbmGetCPUAddress(buf); 93} 94 95uint32_t Wsbm::getGttOffset(void * buf) 96{ 97 return psbWsbmGetGttOffset(buf); 98} 99 100bool Wsbm::wrapTTMBuffer(int64_t handle, void **buf) 101{ 102 int ret = psbWsbmWrapTTMBuffer(handle, buf); 103 if (ret) { 104 ETRACE("failed to wrap buffer"); 105 return false; 106 } 107 108 return true; 109} 110 111bool Wsbm::unreferenceTTMBuffer(void *buf) 112{ 113 int ret = psbWsbmUnReference(buf); 114 if (ret) { 115 ETRACE("failed to unreference buffer"); 116 return false; 117 } 118 119 return true; 120} 121 122uint64_t Wsbm::getKBufHandle(void *buf) 123{ 124 return psbWsbmGetKBufHandle(buf); 125} 126 127bool Wsbm::waitIdleTTMBuffer(void *buf) 128{ 129 int ret = psbWsbmWaitIdle(buf); 130 if (ret) { 131 ETRACE("failed to wait ttm buffer for idle"); 132 return false; 133 } 134 135 return true; 136} 137