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/TTMBufferMapper.h>
     18 
     19 namespace android {
     20 namespace intel {
     21 
     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 
     34 TTMBufferMapper::~TTMBufferMapper()
     35 {
     36     CTRACE();
     37 }
     38 
     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 
     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 
     95 bool TTMBufferMapper::waitIdle()
     96 {
     97     return mWsbm.waitIdleTTMBuffer(mBufferObject);
     98 }
     99 
    100 } // namespace intel
    101 } // namespace android
    102 
    103 
    104