hwc: Enable sync-pt for rotator on B-family

Enable sync-pt for rotator on B-family. The already existing
MSMFB_BUF_SYNC ioctl is used, with an extra member for session_id
from rotator.

Change-Id: Ib0ef6b1bc5cf1e6437090a217d7f731a3440f84b
diff --git a/libhwcomposer/hwc_utils.cpp b/libhwcomposer/hwc_utils.cpp
index ffaa9cb..5139f29 100644
--- a/libhwcomposer/hwc_utils.cpp
+++ b/libhwcomposer/hwc_utils.cpp
@@ -903,16 +903,11 @@
     int count = 0;
     int releaseFd = -1;
     int fbFd = -1;
-    int rotFd = -1;
     bool swapzero = false;
     int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion();
 
     struct mdp_buf_sync data;
     memset(&data, 0, sizeof(data));
-    //Until B-family supports sync for rotator
-#ifdef MDSS_TARGET
-    data.flags = MDP_BUF_SYNC_FLAG_WAIT;
-#endif
     data.acq_fen_fd = acquireFd;
     data.rel_fen_fd = &releaseFd;
 
@@ -921,34 +916,37 @@
         if(atoi(property) == 0)
             swapzero = true;
     }
+
     bool isExtAnimating = false;
     if(dpy)
        isExtAnimating = ctx->listStats[dpy].isDisplayAnimating;
 
     //Send acquireFenceFds to rotator
-#ifdef MDSS_TARGET
-    //TODO B-family
-#else
-    //A-family
-    int rotFd = ctx->mRotMgr->getRotDevFd();
-    struct msm_rotator_buf_sync rotData;
-
     for(uint32_t i = 0; i < ctx->mLayerRotMap[dpy]->getCount(); i++) {
+        int rotFd = ctx->mRotMgr->getRotDevFd();
+        int rotReleaseFd = -1;
+        struct mdp_buf_sync rotData;
         memset(&rotData, 0, sizeof(rotData));
-        int& acquireFenceFd =
-                ctx->mLayerRotMap[dpy]->getLayer(i)->acquireFenceFd;
-        rotData.acq_fen_fd = acquireFenceFd;
+        rotData.acq_fen_fd =
+                &ctx->mLayerRotMap[dpy]->getLayer(i)->acquireFenceFd;
+        rotData.rel_fen_fd = &rotReleaseFd; //driver to populate this
         rotData.session_id = ctx->mLayerRotMap[dpy]->getRot(i)->getSessId();
-        ioctl(rotFd, MSM_ROTATOR_IOCTL_BUFFER_SYNC, &rotData);
-        close(acquireFenceFd);
-        //For MDP to wait on.
-        acquireFenceFd = dup(rotData.rel_fen_fd);
-        //A buffer is free to be used by producer as soon as its copied to
-        //rotator.
-        ctx->mLayerRotMap[dpy]->getLayer(i)->releaseFenceFd =
-                rotData.rel_fen_fd;
+        int ret = 0;
+        ret = ioctl(rotFd, MSMFB_BUFFER_SYNC, &rotData);
+        if(ret < 0) {
+            ALOGE("%s: ioctl MSMFB_BUFFER_SYNC failed for rot sync, err=%s",
+                    __FUNCTION__, strerror(errno));
+        } else {
+            close(ctx->mLayerRotMap[dpy]->getLayer(i)->acquireFenceFd);
+            //For MDP to wait on.
+            ctx->mLayerRotMap[dpy]->getLayer(i)->acquireFenceFd =
+                    dup(rotReleaseFd);
+            //A buffer is free to be used by producer as soon as its copied to
+            //rotator
+            ctx->mLayerRotMap[dpy]->getLayer(i)->releaseFenceFd =
+                    rotReleaseFd;
+        }
     }
-#endif
 
     //Accumulate acquireFenceFds for MDP
     for(uint32_t i = 0; i < list->numHwLayers; i++) {
@@ -1022,14 +1020,8 @@
     if (ctx->mCopyBit[dpy])
         ctx->mCopyBit[dpy]->setReleaseFd(releaseFd);
 
-#ifdef MDSS_TARGET
-    //TODO When B is implemented remove #ifdefs from here
-    //The API called applies to RotMem buffers
-#else
-    //A-family
     //Signals when MDP finishes reading rotator buffers.
     ctx->mLayerRotMap[dpy]->setReleaseFd(releaseFd);
-#endif
 
     // if external is animating, close the relaseFd
     if(isExtAnimating) {
diff --git a/liboverlay/overlayRotator.cpp b/liboverlay/overlayRotator.cpp
index 2995580..84a9818 100644
--- a/liboverlay/overlayRotator.cpp
+++ b/liboverlay/overlayRotator.cpp
@@ -174,11 +174,10 @@
 }
 
 int RotMgr::getRotDevFd() {
-    //2nd check just in case
-    if(mRotDevFd < 0 && Rotator::getRotatorHwType() == Rotator::TYPE_MDP) {
-        mRotDevFd = ::open("/dev/msm_rotator", O_RDWR, 0);
+    if(mRotDevFd < 0 && Rotator::getRotatorHwType() == Rotator::TYPE_MDSS) {
+        mRotDevFd = ::open("/dev/graphics/fb0", O_RDWR, 0);
         if(mRotDevFd < 0) {
-            ALOGE("%s failed to open rotator device", __FUNCTION__);
+            ALOGE("%s failed to open fb0", __FUNCTION__);
         }
     }
     return mRotDevFd;
diff --git a/liboverlay/overlayRotator.h b/liboverlay/overlayRotator.h
index a600732..f551f1d 100644
--- a/liboverlay/overlayRotator.h
+++ b/liboverlay/overlayRotator.h
@@ -237,11 +237,11 @@
      * Expects a NULL terminated buffer of big enough size.
      */
     void getDump(char *buf, size_t len);
-    int getRotDevFd(); //Called on A-fam only
+    int getRotDevFd();
 private:
     overlay::Rotator *mRot[MAX_ROT_SESS];
     int mUseCount;
-    int mRotDevFd; //A-fam
+    int mRotDevFd;
 };