Home | History | Annotate | Download | only in common
      1 /*
      2 // Copyright(c)2014 IntelCorporation
      3 //
      4 // LicensedundertheApacheLicense,Version2.0(the"License");
      5 // youmaynotusethisfileexceptincompliancewiththeLicense.
      6 // YoumayobtainacopyoftheLicenseat
      7 //
      8 // http://www.apache.org/licenses/LICENSE-2.0
      9 //
     10 // Unlessrequiredbyapplicablelaworagreedtoinwriting,software
     11 // distributedundertheLicenseisdistributedonan"ASIS"BASIS,
     12 // WITHOUTWARRANTIESORCONDITIONSOFANYKIND,eitherexpressorimplied.
     13 // SeetheLicenseforthespecificlanguagegoverningpermissionsand
     14 // limitationsundertheLicense.
     15 */
     16 #include <HwcTrace.h>
     17 #include <common/Wsbm.h>
     18 
     19 Wsbm::Wsbm(int drmFD)
     20     : mInitialized(false)
     21 {
     22     CTRACE();
     23     mDrmFD = drmFD;
     24 }
     25 
     26 Wsbm::~Wsbm()
     27 {
     28     WARN_IF_NOT_DEINIT();
     29 }
     30 
     31 bool 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 
     48 void Wsbm::deinitialize()
     49 {
     50     if (!mInitialized) {
     51         return;
     52     }
     53     psbWsbmTakedown();
     54     mInitialized = false;
     55 }
     56 
     57 bool 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 
     68 bool 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 
     79 bool 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 
     90 void * Wsbm::getCPUAddress(void * buf)
     91 {
     92     return psbWsbmGetCPUAddress(buf);
     93 }
     94 
     95 uint32_t Wsbm::getGttOffset(void * buf)
     96 {
     97     return psbWsbmGetGttOffset(buf);
     98 }
     99 
    100 bool 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 
    111 bool 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 
    122 uint64_t Wsbm::getKBufHandle(void *buf)
    123 {
    124     return psbWsbmGetKBufHandle(buf);
    125 }
    126 
    127 bool 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