/*
* Copyright (c) 2019-2021, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*    * Redistributions of source code must retain the above copyright
*      notice, this list of conditions and the following disclaimer.
*    * Redistributions in binary form must reproduce the above
*      copyright notice, this list of conditions and the following
*      disclaimer in the documentation and/or other materials provided
*      with the distribution.
*    * Neither the name of The Linux Foundation nor the names of its
*      contributors may be used to endorse or promote products derived
*      from this software without specific prior written permission.

* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

/*
* Changes from Qualcomm Innovation Center are provided under the following license:
*
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted (subject to the limitations in the
* disclaimer below) provided that the following conditions are met:
*
*    * Redistributions of source code must retain the above copyright
*      notice, this list of conditions and the following disclaimer.
*
*    * Redistributions in binary form must reproduce the above
*      copyright notice, this list of conditions and the following
*      disclaimer in the documentation and/or other materials provided
*      with the distribution.
*
*    * Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
*      contributors may be used to endorse or promote products derived
*      from this software without specific prior written permission.
*
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
* GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
* HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifdef PP_DRM_ENABLE
#include <xf86drm.h>
#include <xf86drmMode.h>
#include <display/drm/msm_drm_pp.h>
#endif
#include <errno.h>
#include <drm_logger.h>
#include <cstring>
#include <algorithm>
#include <memory>
#include <map>
#include <string>

#include "drm_pp_manager.h"
#include "drm_property.h"

#define __CLASS__ "DRMPPManager"
namespace sde_drm {

DRMPPManager::DRMPPManager(int fd) : fd_(fd) {
}

DRMPPManager::~DRMPPManager() {
#ifdef PP_DRM_ENABLE
  DRMPPPropInfo prop_info = {};

  /* free previously created blob to avoid memory leak */
  for (int i = 0; i < kPPFeaturesMax; i++) {
    prop_info = pp_prop_map_[i];
    if (prop_info.blob_id > 0) {
      drmModeDestroyPropertyBlob(fd_, prop_info.blob_id);
      prop_info.blob_id = 0;
    }
  }
#endif
  fd_ = -1;
}

void DRMPPManager::Init(const DRMPropertyManager &pm , uint32_t object_type) {
  object_type_ = object_type;
  for (uint32_t i = (uint32_t)DRMProperty::INVALID + 1; i < (uint32_t)DRMProperty::MAX; i++) {
    /* parse all the object properties and store the PP properties
     * into DRMPPManager class
    */
    if (!pm.IsPropertyAvailable((DRMProperty)i)) {
      continue;
    }

    if (i >= (uint32_t)DRMProperty::SDE_DSPP_GAMUT_V3 && i <=
        (uint32_t)DRMProperty::SDE_DSPP_GAMUT_V5) {
      pp_prop_map_[kFeatureGamut].prop_enum = (DRMProperty)i;
      pp_prop_map_[kFeatureGamut].prop_id = pm.GetPropertyId((DRMProperty)i);
      pp_prop_map_[kFeatureGamut].version = i - (uint32_t)DRMProperty::SDE_DSPP_GAMUT_V3 + 3;
      DRM_LOGI("Gamut version %d, prop_id %d", pp_prop_map_[kFeatureGamut].version,
               pp_prop_map_[kFeatureGamut].prop_id);
    } else if (i >= (uint32_t)DRMProperty::SDE_DSPP_GC_V1 && i <=
               (uint32_t)DRMProperty::SDE_DSPP_GC_V2) {
      pp_prop_map_[kFeaturePgc].prop_enum = (DRMProperty)i;
      pp_prop_map_[kFeaturePgc].prop_id = pm.GetPropertyId((DRMProperty)i);
      pp_prop_map_[kFeaturePgc].version = i - (uint32_t)DRMProperty::SDE_DSPP_GC_V1 + 1;
      DRM_LOGI("Pgc version %d, prop_id %d", pp_prop_map_[kFeaturePgc].version,
               pp_prop_map_[kFeaturePgc].prop_id);
    } else if (i >= (uint32_t)DRMProperty::SDE_DSPP_IGC_V2 &&
               i <= (uint32_t)DRMProperty::SDE_DSPP_IGC_V4) {
      pp_prop_map_[kFeatureIgc].prop_enum = (DRMProperty)i;
      pp_prop_map_[kFeatureIgc].prop_id = pm.GetPropertyId((DRMProperty)i);
      pp_prop_map_[kFeatureIgc].version = i - (uint32_t)DRMProperty::SDE_DSPP_IGC_V2 + 2;
      DRM_LOGI("Igc version %d, prop_id %d", pp_prop_map_[kFeatureIgc].version,
               pp_prop_map_[kFeatureIgc].prop_id);
    } else if (i >= (uint32_t)DRMProperty::SDE_DSPP_PCC_V3 &&
               i <= (uint32_t)DRMProperty::SDE_DSPP_PCC_V5) {
      pp_prop_map_[kFeaturePcc].prop_enum = (DRMProperty)i;
      pp_prop_map_[kFeaturePcc].prop_id = pm.GetPropertyId((DRMProperty)i);
      pp_prop_map_[kFeaturePcc].version = i - (uint32_t)DRMProperty::SDE_DSPP_PCC_V3 + 3;
      DRM_LOGI("Pcc version %d, prop_id %d", pp_prop_map_[kFeaturePcc].version,
               pp_prop_map_[kFeaturePcc].prop_id);
    } else if (i >= (uint32_t)DRMProperty::SDE_DSPP_PA_HSIC_V1 &&
               i <= (uint32_t)DRMProperty::SDE_DSPP_PA_HSIC_V2) {
      pp_prop_map_[kFeaturePAHsic].prop_enum = (DRMProperty)i;
      pp_prop_map_[kFeaturePAHsic].prop_id = pm.GetPropertyId((DRMProperty)i);
      pp_prop_map_[kFeaturePAHsic].version = i - (uint32_t)DRMProperty::SDE_DSPP_PA_HSIC_V1 + 1;
      DRM_LOGI("PaHsic version %d, prop_id %d", pp_prop_map_[kFeaturePAHsic].version,
               pp_prop_map_[kFeaturePAHsic].prop_id);
    } else if (i >= (uint32_t)DRMProperty::SDE_DSPP_PA_SIXZONE_V1 &&
               i <= (uint32_t)DRMProperty::SDE_DSPP_PA_SIXZONE_V2) {
      pp_prop_map_[kFeaturePASixZone].prop_enum = (DRMProperty)i;
      pp_prop_map_[kFeaturePASixZone].prop_id = pm.GetPropertyId((DRMProperty)i);
      pp_prop_map_[kFeaturePASixZone].version = i - (uint32_t)DRMProperty::SDE_DSPP_PA_SIXZONE_V1 + 1;
      DRM_LOGI("SixZone version %d, prop_id %d", pp_prop_map_[kFeaturePASixZone].version,
               pp_prop_map_[kFeaturePASixZone].prop_id);
    } else if (i >= (uint32_t)DRMProperty::SDE_DSPP_PA_MEMCOL_SKIN_V1 &&
               i <= (uint32_t)DRMProperty::SDE_DSPP_PA_MEMCOL_SKIN_V2) {
      pp_prop_map_[kFeaturePAMemColSkin].prop_enum = (DRMProperty)i;
      pp_prop_map_[kFeaturePAMemColSkin].prop_id = pm.GetPropertyId((DRMProperty)i);
      pp_prop_map_[kFeaturePAMemColSkin].version = i - (uint32_t)DRMProperty::SDE_DSPP_PA_MEMCOL_SKIN_V1 + 1;
      DRM_LOGI("MemColor skin version %d, prop_id %d", pp_prop_map_[kFeaturePAMemColSkin].version,
               pp_prop_map_[kFeaturePAMemColSkin].prop_id);
    } else if (i >= (uint32_t)DRMProperty::SDE_DSPP_PA_MEMCOL_SKY_V1 &&
               i <= (uint32_t)DRMProperty::SDE_DSPP_PA_MEMCOL_SKY_V2) {
      pp_prop_map_[kFeaturePAMemColSky].prop_enum = (DRMProperty)i;
      pp_prop_map_[kFeaturePAMemColSky].prop_id = pm.GetPropertyId((DRMProperty)i);
      pp_prop_map_[kFeaturePAMemColSky].version = i - (uint32_t)DRMProperty::SDE_DSPP_PA_MEMCOL_SKY_V1 + 1;
      DRM_LOGI("MemColor sky version %d, prop_id %d", pp_prop_map_[kFeaturePAMemColSky].version,
               pp_prop_map_[kFeaturePAMemColSky].prop_id);
    } else if (i >= (uint32_t)DRMProperty::SDE_DSPP_PA_MEMCOL_FOLIAGE_V1 &&
               i <= (uint32_t)DRMProperty::SDE_DSPP_PA_MEMCOL_FOLIAGE_V2) {
      pp_prop_map_[kFeaturePAMemColFoliage].prop_enum = (DRMProperty)i;
      pp_prop_map_[kFeaturePAMemColFoliage].prop_id = pm.GetPropertyId((DRMProperty)i);
      pp_prop_map_[kFeaturePAMemColFoliage].version = i - (uint32_t)DRMProperty::SDE_DSPP_PA_MEMCOL_FOLIAGE_V1 + 1;
      DRM_LOGI("MemColor foliage version %d, prop_id %d", pp_prop_map_[kFeaturePAMemColFoliage].version,
               pp_prop_map_[kFeaturePAMemColFoliage].prop_id);
    } else if (i >= (uint32_t)DRMProperty::SDE_DSPP_PA_MEMCOL_PROT_V1 &&
               i <= (uint32_t)DRMProperty::SDE_DSPP_PA_MEMCOL_PROT_V2) {
      pp_prop_map_[kFeaturePAMemColProt].prop_enum = (DRMProperty)i;
      pp_prop_map_[kFeaturePAMemColProt].prop_id = pm.GetPropertyId((DRMProperty)i);
      pp_prop_map_[kFeaturePAMemColProt].version = i - (uint32_t)DRMProperty::SDE_DSPP_PA_MEMCOL_PROT_V1 + 1;
      DRM_LOGI("MemColor prot version %d, prop_id %d", pp_prop_map_[kFeaturePAMemColProt].version,
               pp_prop_map_[kFeaturePAMemColProt].prop_id);
    } else if (i >= (uint32_t)DRMProperty::SDE_DSPP_PA_DITHER_V1 &&
               i <= (uint32_t)DRMProperty::SDE_DSPP_PA_DITHER_V2) {
      pp_prop_map_[kFeaturePADither].prop_enum = (DRMProperty)i;
      pp_prop_map_[kFeaturePADither].prop_id = pm.GetPropertyId((DRMProperty)i);
      pp_prop_map_[kFeaturePADither].version = i - (uint32_t)DRMProperty::SDE_DSPP_PA_DITHER_V1 + 1;
      DRM_LOGI("PA Dither version %d, prop_id %d", pp_prop_map_[kFeaturePADither].version,
               pp_prop_map_[kFeaturePADither].prop_id);
    } else if (i >= (uint32_t)DRMProperty::SDE_PP_DITHER_V1 &&
               i <= (uint32_t)DRMProperty::SDE_PP_DITHER_V2) {
      pp_prop_map_[kFeatureDither].prop_enum = (DRMProperty)i;
      pp_prop_map_[kFeatureDither].prop_id = pm.GetPropertyId((DRMProperty)i);
      pp_prop_map_[kFeatureDither].version = i - (uint32_t)DRMProperty::SDE_PP_DITHER_V1 + 1;
      DRM_LOGI("PP dither version %d, prop_id %d", pp_prop_map_[kFeatureDither].version,
               pp_prop_map_[kFeatureDither].prop_id);
    }  else if (i >= (uint32_t)DRMProperty::SDE_DSPP_SPR_DITHER_V1 &&
               i <= (uint32_t)DRMProperty::SDE_DSPP_SPR_DITHER_V1) {
      pp_prop_map_[kFeatureSprDither].prop_enum = (DRMProperty)i;
      pp_prop_map_[kFeatureSprDither].prop_id = pm.GetPropertyId((DRMProperty)i);
      pp_prop_map_[kFeatureSprDither].version = i - (uint32_t)DRMProperty::SDE_DSPP_SPR_DITHER_V1 + 1;
      DRM_LOGI("DSPP SPR dither version %d, prop_id %d", pp_prop_map_[kFeatureSprDither].version,
               pp_prop_map_[kFeatureSprDither].prop_id);
    } else if (i >= (uint32_t)DRMProperty::SDE_VIG_3D_LUT_GAMUT_V5 &&
               i <= (uint32_t)DRMProperty::SDE_VIG_3D_LUT_GAMUT_V6) {
      pp_prop_map_[kFeatureVigGamut].prop_enum = (DRMProperty)i;
      pp_prop_map_[kFeatureVigGamut].prop_id = pm.GetPropertyId((DRMProperty)i);
      pp_prop_map_[kFeatureVigGamut].version = i - (uint32_t)DRMProperty::SDE_VIG_3D_LUT_GAMUT_V5 + 5;
      DRM_LOGI("Vig Gamut version %d, prop_id %d", pp_prop_map_[kFeatureVigGamut].version,
               pp_prop_map_[kFeatureVigGamut].prop_id);
    } else if (i >= (uint32_t)DRMProperty::SDE_VIG_1D_LUT_IGC_V5 &&
               i <= (uint32_t)DRMProperty::SDE_VIG_1D_LUT_IGC_V6) {
      pp_prop_map_[kFeatureVigIgc].prop_enum = (DRMProperty)i;
      pp_prop_map_[kFeatureVigIgc].prop_id = pm.GetPropertyId((DRMProperty)i);
      pp_prop_map_[kFeatureVigIgc].version = i - (uint32_t)DRMProperty::SDE_VIG_1D_LUT_IGC_V5 + 5;
      DRM_LOGI("Vig Igc version %d, prop_id %d", pp_prop_map_[kFeatureVigIgc].version,
               pp_prop_map_[kFeatureVigIgc].prop_id);
    } else if (i >= (uint32_t)DRMProperty::SDE_DGM_1D_LUT_IGC_V5 &&
               i <= (uint32_t)DRMProperty::SDE_DGM_1D_LUT_IGC_V5) {
      pp_prop_map_[kFeatureDgmIgc].prop_enum = (DRMProperty)i;
      pp_prop_map_[kFeatureDgmIgc].prop_id = pm.GetPropertyId((DRMProperty)i);
      pp_prop_map_[kFeatureDgmIgc].version = i - (uint32_t)DRMProperty::SDE_DGM_1D_LUT_IGC_V5 + 5;
      DRM_LOGI("Dgm Igc version %d, prop_id %d", pp_prop_map_[kFeatureDgmIgc].version,
               pp_prop_map_[kFeatureDgmIgc].prop_id);
    } else if (i >= (uint32_t)DRMProperty::SDE_DGM_1D_LUT_GC_V5 &&
               i <= (uint32_t)DRMProperty::SDE_DGM_1D_LUT_GC_V5) {
      pp_prop_map_[kFeatureDgmGc].prop_enum = (DRMProperty)i;
      pp_prop_map_[kFeatureDgmGc].prop_id = pm.GetPropertyId((DRMProperty)i);
      pp_prop_map_[kFeatureDgmGc].version = i - (uint32_t)DRMProperty::SDE_DGM_1D_LUT_GC_V5 + 5;
      DRM_LOGI("Dgm Gc version %d, prop_id %d", pp_prop_map_[kFeatureDgmGc].version,
               pp_prop_map_[kFeatureDgmGc].prop_id);
    } else if (i >= (uint32_t)DRMProperty::SDE_PP_CWB_DITHER_V2 &&
               i <= (uint32_t)DRMProperty::SDE_PP_CWB_DITHER_V2) {
      pp_prop_map_[kFeatureCWBDither].prop_enum = (DRMProperty)i;
      pp_prop_map_[kFeatureCWBDither].prop_id = pm.GetPropertyId((DRMProperty)i);
      pp_prop_map_[kFeatureCWBDither].version = i - (uint32_t)DRMProperty::SDE_PP_CWB_DITHER_V2 + 2;
      DRM_LOGI("PP CWB dither version %d, prop_id %d", pp_prop_map_[kFeatureCWBDither].version,
               pp_prop_map_[kFeatureCWBDither].prop_id);
    } else if (i >= (uint32_t)DRMProperty::DIMMING_BL_LUT &&
               i <= (uint32_t)DRMProperty::DIMMING_BL_LUT) {
      pp_prop_map_[kFeatureDimmingBlLut].prop_enum = (DRMProperty)i;
      pp_prop_map_[kFeatureDimmingBlLut].prop_id = pm.GetPropertyId((DRMProperty)i);
      pp_prop_map_[kFeatureDimmingBlLut].version = i - (uint32_t)DRMProperty::DIMMING_BL_LUT;
    } else if (i >= (uint32_t)DRMProperty::DIMMING_DYN_CTRL &&
               i <= (uint32_t)DRMProperty::DIMMING_DYN_CTRL) {
      pp_prop_map_[kFeatureDimmingDynCtrl].prop_enum = (DRMProperty)i;
      pp_prop_map_[kFeatureDimmingDynCtrl].prop_id = pm.GetPropertyId((DRMProperty)i);
      pp_prop_map_[kFeatureDimmingDynCtrl].version = i - (uint32_t)DRMProperty::DIMMING_DYN_CTRL;
    } else if (i >= (uint32_t)DRMProperty::DIMMING_MIN_BL &&
               i <= (uint32_t)DRMProperty::DIMMING_MIN_BL) {
      pp_prop_map_[kFeatureDimmingMinBl].prop_enum = (DRMProperty)i;
      pp_prop_map_[kFeatureDimmingMinBl].prop_id = pm.GetPropertyId((DRMProperty)i);
      pp_prop_map_[kFeatureDimmingMinBl].version = i - (uint32_t)DRMProperty::DIMMING_MIN_BL;
    }
  }
  return;
}

void DRMPPManager::GetPPInfo(DRMPPFeatureInfo *info) {
  if (!info)
    return;
  if (info->id > kPPFeaturesMax)
    return;

  info->version = pp_prop_map_[info->id].version;
  info->object_type = object_type_;
  return;
}

void DRMPPManager::SetPPFeature(drmModeAtomicReq *req, uint32_t obj_id, DRMPPFeatureInfo &feature) {
  if (!req) {
      DRM_LOGE("Invalid input param: req %pK", req);
      return;
  }

  /* handle event register/de-register */
  if (feature.is_event) {
    SetPPEvent(obj_id, feature);
    return;
  }

  /* handle feature setting */
  if (feature.id >= kPPFeaturesMax)
    return;

  switch (feature.type) {
    case kPropEnum:
      break;
    case kPropRange:
      SetPPRangeProperty(req, obj_id, &pp_prop_map_[feature.id], feature);
      break;
    case kPropBlob:
      SetPPBlobProperty(req, obj_id, &pp_prop_map_[feature.id], feature);
      break;
    default:
      DRM_LOGE("Unsupported feature type %d", feature.type);
      break;
  }

  return;
}

int DRMPPManager::SetPPRangeProperty(drmModeAtomicReq *req, uint32_t obj_id,
                                    struct DRMPPPropInfo *prop_info,
                                    DRMPPFeatureInfo &feature) {
  int ret = DRM_ERR_INVALID;
#ifdef PP_DRM_ENABLE
  uint64_t value = 0;

  if (!feature.payload) {
    DRM_LOGE("invalid payload for feature %d", feature.id);
    return ret;
  }
  value = *((uint64_t *)feature.payload);
  ret = drmModeAtomicAddProperty(req, obj_id, prop_info->prop_id, value);
  if (ret < 0) {
    DRM_LOGE("failed to add property ret %d id %d value %llu", ret, prop_info->prop_id, value);
  } else {
    ret = 0;
  }
#endif
  return ret;
}

int DRMPPManager::SetPPBlobProperty(drmModeAtomicReq *req, uint32_t obj_id,
                                    struct DRMPPPropInfo *prop_info,
                                    DRMPPFeatureInfo &feature) {
  int ret = DRM_ERR_INVALID;
#ifdef PP_DRM_ENABLE
  uint32_t blob_id = 0;

  /* free previously created blob for this feature if exist */
  if (prop_info->blob_id > 0) {
    ret = drmModeDestroyPropertyBlob(fd_, prop_info->blob_id);
    if (ret) {
      DRM_LOGE("failed to destroy property blob for feature %d, ret = %d", feature.id, ret);
      return ret;
    } else {
      prop_info->blob_id = 0;
    }
  }

  if (!feature.payload) {
    // feature disable case
    drmModeAtomicAddProperty(req, obj_id, prop_info->prop_id, 0);
    return 0;
  }

  ret = drmModeCreatePropertyBlob(fd_, feature.payload, feature.payload_size, &blob_id);
  if (ret || blob_id == 0) {
    DRM_LOGE("failed to create property blob ret %d, blob_id = %d", ret, blob_id);
    return DRM_ERR_INVALID;
  }

  prop_info->blob_id = blob_id;
  drmModeAtomicAddProperty(req, obj_id, prop_info->prop_id, blob_id);

#endif
  return ret;
}

void DRMPPManager::SetPPEvent(uint32_t obj_id, DRMPPFeatureInfo &feature) {
#ifdef PP_DRM_ENABLE
  int ret  = 0;
  bool enable;
  struct drm_msm_event_req event_req = {};

  if (!feature.payload || feature.payload_size != sizeof(bool)) {
    DRM_LOGE("Invalid input params: payload %pK payload_size %d exp size %d",
             feature.payload, feature.payload_size, sizeof(bool));
    return;
  }

  enable = *(reinterpret_cast<bool *>(feature.payload));
  event_req.object_id = obj_id;
  event_req.object_type = object_type_;
  event_req.event = feature.event_type;
  if (enable)
    ret = drmIoctl(feature.drm_fd, DRM_IOCTL_MSM_REGISTER_EVENT, &event_req);
  else
    ret = drmIoctl(feature.drm_fd, DRM_IOCTL_MSM_DEREGISTER_EVENT, &event_req);
  if (ret) {
    ret = -errno;
    if (ret == -EALREADY) {
      DRM_LOGI("Duplicated request to set event 0x%x, object_id %u, object_type 0x%x, enable %d",
          event_req.event, event_req.object_id, object_type_, enable);
    } else if (ret == -ENOENT || ret == -ENODEV || ret == -EACCES) {
      DRM_LOGW("Event 0x%x, object_id %u, object_type 0x%x, enable %d, ret %d",
          event_req.event, event_req.object_id, object_type_, enable, ret);
    } else {
      DRM_LOGE("Failed to set event 0x%x, object_id %u, object_type 0x%x, enable %d, ret %d",
          event_req.event, event_req.object_id, object_type_, enable, ret);
    }
  } else {
    DRM_LOGI("set event, 0x%x, object_id %u, object_type 0x%x, enable %d",
             event_req.event, event_req.object_id, object_type_, enable);
  }
#endif
  return;
}

}  // namespace sde_drm
