示例#1
0
static void
drmmode_output_dpms(xf86OutputPtr output, int mode)
{
	drmmode_output_private_ptr drmmode_output = output->driver_private;
	drmModeConnectorPtr koutput = drmmode_output->mode_output;
	drmmode_ptr drmmode = drmmode_output->drmmode;
	int i;
	drmModePropertyPtr props;

	for (i = 0; i < koutput->count_props; i++) {
		props = drmModeGetProperty(drmmode->fd, koutput->props[i]);
		if (!props)
			continue;

		if (!strcmp(props->name, "DPMS")) {
                        drmModeConnectorSetProperty(drmmode->fd,
                                drmmode_output->output_id,
                                props->prop_id,
                                mode);
			drmmode_output_dpms_backlight(output,
				drmmode_output->dpms_mode,
				mode);
			drmmode_output->dpms_mode = mode;
                        drmModeFreeProperty(props);
                        return;
		}
		drmModeFreeProperty(props);
	}
}
bool drm_mipi_setMode(int mode)
{
    drmModeConnector *connector = getConnector(gDrmCxt.drmFD, DRM_MODE_CONNECTOR_MIPI);
    if (connector == NULL)
        return false;

    int i = 0;
    drmModePropertyPtr props = NULL;

    // Set MIPI On/Off
    for (i = 0; i < connector->count_props; i++) {
        props = drmModeGetProperty(gDrmCxt.drmFD, connector->props[i]);
        if (!props) continue;

        if (props->name != NULL &&
                !strncmp(props->name, "DPMS", sizeof("DPMS"))) {
            LOGV("%s: %s %u", __func__,
                  (mode == DRM_MIPI_ON) ? "On" : "Off",
                  connector->connector_id);
            drmModeConnectorSetProperty(gDrmCxt.drmFD,
                                        connector->connector_id,
                                        props->prop_id,
                                        (mode == DRM_MIPI_ON)
                                        ? DRM_MODE_DPMS_ON : DRM_MODE_DPMS_OFF);
            drmModeFreeProperty(props);
            break;
        }
        drmModeFreeProperty(props);
    }

    drmModeFreeConnector(connector);
    return true;
}
示例#3
0
void mgm::RealKMSOutput::reset()
{
    DRMModeResources resources{drm_fd};

    /* Update the connector to ensure we have the latest information */
    connector = resources.connector(connector_id);

    if (!connector)
        fatal_error("No DRM connector found");

    // TODO: What if we can't locate the DPMS property?
    for (int i = 0; i < connector->count_props; i++)
    {
        auto prop = drmModeGetProperty(drm_fd, connector->props[i]);
        if (prop && (prop->flags & DRM_MODE_PROP_ENUM)) {
            if (!strcmp(prop->name, "DPMS"))
            {
                dpms_enum_id = connector->props[i];
                drmModeFreeProperty(prop);
                break;
            }
            drmModeFreeProperty(prop);
        }
    }

    /* Discard previously current crtc */
    current_crtc = nullptr;
}
示例#4
0
bool Drm::setDpmsMode(int device, int mode)
{
    Mutex::Autolock _l(mLock);

    int output = getOutputIndex(device);
    if (output < 0 ) {
        return false;
    }

    if (mode != IDisplayDevice::DEVICE_DISPLAY_OFF &&
            mode != IDisplayDevice::DEVICE_DISPLAY_STANDBY &&
            mode != IDisplayDevice::DEVICE_DISPLAY_ON) {
        ELOGTRACE("invalid mode %d", mode);
        return false;
    }

    DrmOutput *out = &mOutputs[output];
    if (!out->connected) {
        ELOGTRACE("device is not connected");
        return false;
    }

    drmModePropertyPtr props;
    for (int i = 0; i < out->connector->count_props; i++) {
        props = drmModeGetProperty(mDrmFd, out->connector->props[i]);
        if (!props) {
            continue;
        }

        if (strcmp(props->name, "DPMS") == 0) {
            int ret = drmModeConnectorSetProperty(
                mDrmFd,
                out->connector->connector_id,
                props->prop_id,
                (mode == IDisplayDevice::DEVICE_DISPLAY_ON) ? DRM_MODE_DPMS_ON :
                        IDisplayDevice::DEVICE_DISPLAY_STANDBY == mode ?
                        DRM_MODE_DPMS_STANDBY : DRM_MODE_DPMS_OFF);
            drmModeFreeProperty(props);
            if (ret != 0) {
                ELOGTRACE("unable to set DPMS %d", mode);
                return false;
            } else {
                return true;
            }
        }
        drmModeFreeProperty(props);
    }
    return false;
}
static int drm_plane_type(int drm_fd, int plane_id)
{
    drmModeObjectPropertiesPtr props;
    drmModePropertyPtr prop;
    int plane_type = -EINVAL;
    int i;

    props = drmModeObjectGetProperties(drm_fd, plane_id, DRM_MODE_OBJECT_PLANE);
    if (!props)
        return -ENODEV;

    for (i = 0; i < props->count_props && plane_type == -EINVAL; i++) {
        prop = drmModeGetProperty(drm_fd, props->props[i]);
        if (prop) {
            if (strcmp(prop->name, "type") == 0)
                plane_type = props->prop_values[i];

            drmModeFreeProperty(prop);
        }
    }

    drmModeFreeObjectProperties(props);

    return plane_type;
}
static int
find_property_index (MetaMonitorManager         *manager,
                     drmModeObjectPropertiesPtr  props,
                     const gchar                *prop_name,
                     drmModePropertyPtr         *found)
{
  MetaMonitorManagerKms *manager_kms = META_MONITOR_MANAGER_KMS (manager);
  unsigned int i;

  for (i = 0; i < props->count_props; i++)
    {
      drmModePropertyPtr prop;

      prop = drmModeGetProperty (manager_kms->fd, props->props[i]);
      if (!prop)
        continue;

      if (strcmp (prop->name, prop_name) == 0)
        {
          *found = prop;
          return i;
        }

      drmModeFreeProperty (prop);
    }

  return -1;
}
static void
find_crtc_properties (MetaMonitorManagerKms *manager_kms,
                      MetaCRTC *meta_crtc)
{
  MetaCRTCKms *crtc_kms;
  drmModeObjectPropertiesPtr props;
  size_t i;

  crtc_kms = meta_crtc->driver_private;

  props = drmModeObjectGetProperties (manager_kms->fd, meta_crtc->crtc_id, DRM_MODE_OBJECT_CRTC);
  if (!props)
    return;

  for (i = 0; i < props->count_props; i++)
    {
      drmModePropertyPtr prop = drmModeGetProperty (manager_kms->fd, props->props[i]);
      if (!prop)
        continue;

      if ((prop->flags & DRM_MODE_PROP_ENUM) && strcmp (prop->name, "underscan") == 0)
        crtc_kms->underscan_prop_id = prop->prop_id;
      else if ((prop->flags & DRM_MODE_PROP_RANGE) && strcmp (prop->name, "underscan hborder") == 0)
        crtc_kms->underscan_hborder_prop_id = prop->prop_id;
      else if ((prop->flags & DRM_MODE_PROP_RANGE) && strcmp (prop->name, "underscan vborder") == 0)
        crtc_kms->underscan_vborder_prop_id = prop->prop_id;

      drmModeFreeProperty (prop);
    }
}
static void
find_connector_properties (MetaMonitorManagerKms *manager_kms,
                           MetaOutputKms         *output_kms)
{
  int i;

  output_kms->hotplug_mode_update = 0;
  output_kms->suggested_x = -1;
  output_kms->suggested_y = -1;
  for (i = 0; i < output_kms->connector->count_props; i++)
    {
      drmModePropertyPtr prop = drmModeGetProperty (manager_kms->fd, output_kms->connector->props[i]);
      if (!prop)
        continue;

      if ((prop->flags & DRM_MODE_PROP_ENUM) && strcmp (prop->name, "DPMS") == 0)
        output_kms->dpms_prop_id = prop->prop_id;
      else if ((prop->flags & DRM_MODE_PROP_BLOB) && strcmp (prop->name, "EDID") == 0)
        output_kms->edid_blob_id = output_kms->connector->prop_values[i];
      else if ((prop->flags & DRM_MODE_PROP_BLOB) &&
               strcmp (prop->name, "TILE") == 0)
        output_kms->tile_blob_id = output_kms->connector->prop_values[i];
      else if ((prop->flags & DRM_MODE_PROP_RANGE) &&
               strcmp (prop->name, "suggested X") == 0)
        output_kms->suggested_x = output_kms->connector->prop_values[i];
      else if ((prop->flags & DRM_MODE_PROP_RANGE) &&
               strcmp (prop->name, "suggested Y") == 0)
        output_kms->suggested_y = output_kms->connector->prop_values[i];
      else if ((prop->flags & DRM_MODE_PROP_RANGE) &&
               strcmp (prop->name, "hotplug_mode_update") == 0)
        output_kms->hotplug_mode_update = output_kms->connector->prop_values[i];
      
      drmModeFreeProperty (prop);
    }
}
示例#9
0
EGLBoolean
drm_terminate(_EGLDriver *drv, _EGLDisplay *dpy)
{
	struct drm_device *dev = lookup_drm_device(dpy);
	struct drm_screen *screen;
	int i = 0;

	_eglReleaseDisplayResources(drv, dpy);
	_eglCleanupDisplay(dpy);

	drmFreeVersion(dev->version);

	for (i = 0; i < dev->count_screens; i++) {
		screen = dev->screens[i];

		if (screen->shown)
			drm_takedown_shown_screen(dpy, screen);

		drmModeFreeProperty(screen->dpms);
		drmModeFreeConnector(screen->connector);
		_eglDestroyScreen(&screen->base);
		dev->screens[i] = NULL;
	}

	dev->screen->destroy(dev->screen);
	dev->winsys = NULL;

	drmClose(dev->drmFD);

	dev->api->destroy(dev->api);
	free(dev);
	dpy->DriverData = NULL;

	return EGL_TRUE;
}
示例#10
0
static void fill_obj_props(int fd, uint32_t id, int type, int num_props,
			   const char **prop_names, uint32_t *prop_ids)
{
	drmModeObjectPropertiesPtr props;
	int i, j;

	props = drmModeObjectGetProperties(fd, id, type);
	igt_assert(props);

	for (i = 0; i < props->count_props; i++) {
		drmModePropertyPtr prop =
			drmModeGetProperty(fd, props->props[i]);

		for (j = 0; j < num_props; j++) {
			if (strcmp(prop->name, prop_names[j]) != 0)
				continue;
			prop_ids[j] = props->props[i];
			break;
		}

		drmModeFreeProperty(prop);
	}

	drmModeFreeObjectProperties(props);
}
示例#11
0
文件: plane.c 项目: robclark/glplane
static void populate_crtc_props(int fd, struct my_crtc *c)
{
    drmModeObjectPropertiesPtr props;
    uint32_t i;

    props = drmModeObjectGetProperties(fd, c->base.crtc_id, DRM_MODE_OBJECT_CRTC);
    if (!props)
        return;

    for (i = 0; i < props->count_props; i++) {
        drmModePropertyPtr prop;

        prop = drmModeGetProperty(fd, props->props[i]);
        if (!prop)
            continue;

        printf("crtc prop %s %u\n", prop->name, prop->prop_id);

//		if (!strcmp(prop->name, "MODE"))
//			c->prop.mode = prop->prop_id;
//		else if (!strcmp(prop->name, "CONNECTOR_IDS"))
//			c->prop.connector_ids = prop->prop_id;

        drmModeFreeProperty(prop);
    }

    drmModeFreeObjectProperties(props);
}
示例#12
0
bool CDRMUtils::OpenDrm()
{
  std::vector<const char*>modules =
  {
    "i915",
    "amdgpu",
    "radeon",
    "nouveau",
    "vmwgfx",
    "msm",
    "imx-drm",
    "rockchip",
    "vc4",
    "virtio_gpu",
    "sun4i-drm",
  };

  for(int i = 0; i < 10; ++i)
  {
    std::string device = "/dev/dri/card";
    device.append(std::to_string(i));

    for (auto module : modules)
    {
      m_fd = drmOpen(module, device.c_str());
      if (m_fd >= 0)
      {
        if(!GetResources())
        {
          continue;
        }

        if(!GetConnector())
        {
          continue;
        }

        drmModeFreeResources(m_drm_resources);
        m_drm_resources = nullptr;

        drmModeFreeConnector(m_connector->connector);
        m_connector->connector = nullptr;

        drmModeFreeObjectProperties(m_connector->props);
        m_connector->props = nullptr;

        drmModeFreeProperty(*m_connector->props_info);
        *m_connector->props_info = nullptr;

        CLog::Log(LOGDEBUG, "CDRMUtils::%s - opened device: %s using module: %s", __FUNCTION__, device.c_str(), module);
        return true;
      }

      drmClose(m_fd);
      m_fd = -1;
    }
  }

  return false;
}
示例#13
0
static int kms_plane_probe(struct kms_plane *plane)
{
	struct kms_device *device = plane->device;
	drmModeObjectPropertiesPtr props;
	drmModePlane *p;
	unsigned int i;

	p = drmModeGetPlane(device->fd, plane->id);
	if (!p)
		return -ENODEV;

	/* TODO: allow dynamic assignment to CRTCs */
	if (p->crtc_id == 0) {
		for (i = 0; i < device->num_crtcs; i++) {
			if (p->possible_crtcs & (1 << i)) {
				p->crtc_id = device->crtcs[i]->id;
				break;
			}
		}
	}

	for (i = 0; i < device->num_crtcs; i++) {
		if (device->crtcs[i]->id == p->crtc_id) {
			plane->crtc = device->crtcs[i];
			break;
		}
	}

	plane->formats = calloc(p->count_formats, sizeof(uint32_t));
	if (!plane->formats)
		return -ENOMEM;

	for (i = 0; i < p->count_formats; i++)
		plane->formats[i] = p->formats[i];

	plane->num_formats = p->count_formats;

	drmModeFreePlane(p);

	props = drmModeObjectGetProperties(device->fd, plane->id,
					   DRM_MODE_OBJECT_PLANE);
	if (!props)
		return -ENODEV;

	for (i = 0; i < props->count_props; i++) {
		drmModePropertyPtr prop;

		prop = drmModeGetProperty(device->fd, props->props[i]);
		if (prop) {
			if (strcmp(prop->name, "type") == 0)
				plane->type = props->prop_values[i];

			drmModeFreeProperty(prop);
		}
	}

	drmModeFreeObjectProperties(props);

	return 0;
}
static void
init_crtc_rotations (MetaMonitorManager *manager,
                     MetaCRTC           *crtc,
                     unsigned int        idx)
{
  MetaMonitorManagerKms *manager_kms = META_MONITOR_MANAGER_KMS (manager);
  drmModeObjectPropertiesPtr props;
  drmModePlaneRes *planes;
  drmModePlane *drm_plane;
  MetaCRTCKms *crtc_kms;
  unsigned int i;

  crtc_kms = crtc->driver_private;

  planes = drmModeGetPlaneResources(manager_kms->fd);
  if (planes == NULL)
    return;

  for (i = 0; i < planes->count_planes; i++)
    {
      drmModePropertyPtr prop;

      drm_plane = drmModeGetPlane (manager_kms->fd, planes->planes[i]);

      if (!drm_plane)
        continue;

      if ((drm_plane->possible_crtcs & (1 << idx)))
        {
          props = drmModeObjectGetProperties (manager_kms->fd,
                                              drm_plane->plane_id,
                                              DRM_MODE_OBJECT_PLANE);

          if (props && is_primary_plane (manager, props))
            {
              int rotation_idx;

              crtc_kms->primary_plane_id = drm_plane->plane_id;
              rotation_idx = find_property_index (manager, props, "rotation", &prop);

              if (rotation_idx >= 0)
                {
                  crtc_kms->rotation_prop_id = props->props[rotation_idx];
                  parse_transforms (manager, prop, crtc);
                  drmModeFreeProperty (prop);
                }
            }

          if (props)
            drmModeFreeObjectProperties (props);
        }

      drmModeFreePlane (drm_plane);
    }

  drmModeFreePlaneResources (planes);
}
示例#15
0
static void printProperties(int fd, uint32_t* props, uint64_t* values, int count) {
	drmModePropertyRes* prop;
	int i;

	for (i = 0; i < count; i++) {
		prop = drmModeGetProperty(fd, props[i]);
		printProperty(fd, prop, values[i]);
		drmModeFreeProperty(prop);
    }
}
示例#16
0
/* Pick a plane.. something that at a minimum can be connected to
 * the chosen crtc, but prefer primary plane.
 *
 * Seems like there is some room for a drmModeObjectGetNamedProperty()
 * type helper in libdrm..
 */
static int get_plane_id(void)
{
	drmModePlaneResPtr plane_resources;
	uint32_t i, j;
	int ret = -EINVAL;
	int found_primary = 0;

	plane_resources = drmModeGetPlaneResources(drm.fd);
	if (!plane_resources) {
		printf("drmModeGetPlaneResources failed: %s\n", strerror(errno));
		return -1;
	}

	for (i = 0; (i < plane_resources->count_planes) && !found_primary; i++) {
		uint32_t id = plane_resources->planes[i];
		drmModePlanePtr plane = drmModeGetPlane(drm.fd, id);
		if (!plane) {
			printf("drmModeGetPlane(%u) failed: %s\n", id, strerror(errno));
			continue;
		}

		if (plane->possible_crtcs & (1 << drm.crtc_index)) {
			drmModeObjectPropertiesPtr props =
				drmModeObjectGetProperties(drm.fd, id, DRM_MODE_OBJECT_PLANE);

			/* primary or not, this plane is good enough to use: */
			ret = id;

			for (j = 0; j < props->count_props; j++) {
				drmModePropertyPtr p =
					drmModeGetProperty(drm.fd, props->props[j]);

				if ((strcmp(p->name, "type") == 0) &&
						(props->prop_values[j] == DRM_PLANE_TYPE_PRIMARY)) {
					/* found our primary plane, lets use that: */
					found_primary = 1;
				}

				drmModeFreeProperty(p);
			}

			drmModeFreeObjectProperties(props);
		}

		drmModeFreePlane(plane);
	}

	drmModeFreePlaneResources(plane_resources);

	return ret;
}
示例#17
0
static int get_dpms(struct uterm_display *disp, drmModeConnector *conn)
{
	int i, ret;
	drmModePropertyRes *prop;

	for (i = 0; i < conn->count_props; ++i) {
		prop = drmModeGetProperty(disp->video->dumb.fd, conn->props[i]);
		if (!prop) {
			log_error("cannot get DRM property (%d): %m", errno);
			continue;
		}

		if (!strcmp(prop->name, "DPMS")) {
			switch (conn->prop_values[i]) {
			case DRM_MODE_DPMS_ON:
				ret = UTERM_DPMS_ON;
				break;
			case DRM_MODE_DPMS_STANDBY:
				ret = UTERM_DPMS_STANDBY;
				break;
			case DRM_MODE_DPMS_SUSPEND:
				ret = UTERM_DPMS_SUSPEND;
				break;
			case DRM_MODE_DPMS_OFF:
			default:
				ret = UTERM_DPMS_OFF;
			}

			drmModeFreeProperty(prop);
			return ret;
		}
		drmModeFreeProperty(prop);
	}

	if (i == conn->count_props)
		log_warn("display does not support DPMS");
	return UTERM_DPMS_UNKNOWN;
}
static gboolean
is_primary_plane (MetaMonitorManager         *manager,
                  drmModeObjectPropertiesPtr  props)
{
  drmModePropertyPtr prop;
  int idx;

  idx = find_property_index (manager, props, "type", &prop);
  if (idx < 0)
    return FALSE;

  drmModeFreeProperty (prop);
  return props->prop_values[idx] == DRM_PLANE_TYPE_PRIMARY;
}
示例#19
0
static void fill_obj_prop_map(int fd, uint32_t id, int type, const char *name,
			      int num_enums, const char **enum_names,
			      uint64_t *enum_ids)
{
	drmModeObjectPropertiesPtr props;
	int i, j, k;

	props = drmModeObjectGetProperties(fd, id, type);
	igt_assert(props);

	for (i = 0; i < props->count_props; i++) {
		drmModePropertyPtr prop =
			drmModeGetProperty(fd, props->props[i]);

		igt_assert(prop);

		if (strcmp(prop->name, name) != 0) {
			drmModeFreeProperty(prop);
			continue;
		}

		for (j = 0; j < prop->count_enums; j++) {
			struct drm_mode_property_enum *e = &prop->enums[j];

			for (k = 0; k < num_enums; k++) {
				if (strcmp(e->name, enum_names[k]) != 0)
					continue;

				enum_ids[k] = e->value;
				break;
			}
		}

		drmModeFreeProperty(prop);
	}
}
示例#20
0
static uint32_t get_prop_id(struct sp_dev *dev,
			    drmModeObjectPropertiesPtr props, const char *name){
	drmModePropertyPtr p;
	uint32_t i, prop_id = 0; /* Property ID should always be > 0 */

	for (i = 0; !prop_id && i < props->count_props; i++) {
		p = drmModeGetProperty(dev->fd, props->props[i]);
		if (!strcmp(p->name, name))
		prop_id = p->prop_id;
		drmModeFreeProperty(p);
	}
	if (!prop_id)
	printf("Could not find %s property\n", name);
	return prop_id;
}
示例#21
0
文件: DRMUtils.cpp 项目: Arcko/xbmc
static void FreeProperties(struct drm_object *object)
{
  if (object->props_info)
  {
    for (uint32_t i = 0; i < object->props->count_props; i++)
      drmModeFreeProperty(object->props_info[i]);

    delete [] object->props_info;
    object->props_info = nullptr;
  }

  drmModeFreeObjectProperties(object->props);
  object->props = nullptr;
  object->type = 0;
  object->id = 0;
}
示例#22
0
void drm_object_free_properties(struct drm_object *object)
{
    if (object->props) {
        for (int i = 0; i < object->props->count_props; i++) {
            if (object->props_info[i]) {
                drmModeFreeProperty(object->props_info[i]);
                object->props_info[i] = NULL;
            }
        }

        talloc_free(object->props_info);
        object->props_info = NULL;

        drmModeFreeObjectProperties(object->props);
        object->props = NULL;
    }
}
示例#23
0
static void
drm_find_dpms(struct drm_device *dev, struct drm_screen *screen)
{
	drmModeConnectorPtr c = screen->connector;
	drmModePropertyPtr p;
	int i;

	for (i = 0; i < c->count_props; i++) {
		p = drmModeGetProperty(dev->drmFD, c->props[i]);
		if (!strcmp(p->name, "DPMS"))
			break;

		drmModeFreeProperty(p);
		p = NULL;
	}

	screen->dpms = p;
}
示例#24
0
文件: plane.c 项目: robclark/glplane
static void populate_plane_props(int fd, struct my_plane *p)
{
    drmModeObjectPropertiesPtr props;
    uint32_t i;

    props = drmModeObjectGetProperties(fd, p->base.plane_id, DRM_MODE_OBJECT_PLANE);
    if (!props)
        return;

    for (i = 0; i < props->count_props; i++) {
        drmModePropertyPtr prop;

        prop = drmModeGetProperty(fd, props->props[i]);
        if (!prop)
            continue;

        printf("plane prop %s %u\n", prop->name, prop->prop_id);

        if (!strcmp(prop->name, "SRC_X"))
            p->prop.src_x = prop->prop_id;
        else if (!strcmp(prop->name, "SRC_Y"))
            p->prop.src_y = prop->prop_id;
        else if (!strcmp(prop->name, "SRC_W"))
            p->prop.src_w = prop->prop_id;
        else if (!strcmp(prop->name, "SRC_H"))
            p->prop.src_h = prop->prop_id;
        else if (!strcmp(prop->name, "CRTC_X"))
            p->prop.crtc_x = prop->prop_id;
        else if (!strcmp(prop->name, "CRTC_Y"))
            p->prop.crtc_y = prop->prop_id;
        else if (!strcmp(prop->name, "CRTC_W"))
            p->prop.crtc_w = prop->prop_id;
        else if (!strcmp(prop->name, "CRTC_H"))
            p->prop.crtc_h = prop->prop_id;
        else if (!strcmp(prop->name, "FB_ID"))
            p->prop.fb = prop->prop_id;
        else if (!strcmp(prop->name, "CRTC_ID"))
            p->prop.crtc = prop->prop_id;

        drmModeFreeProperty(prop);
    }

    drmModeFreeObjectProperties(props);
}
示例#25
0
static void
drmmode_output_destroy(xf86OutputPtr output)
{
	drmmode_output_private_ptr drmmode_output = output->driver_private;
	int i;

	if (drmmode_output->edid_blob)
		drmModeFreePropertyBlob(drmmode_output->edid_blob);
	for (i = 0; i < drmmode_output->num_props; i++) {
	    drmModeFreeProperty(drmmode_output->props[i].mode_prop);
	    free(drmmode_output->props[i].atoms);
	}
	free(drmmode_output->props);
	drmModeFreeConnector(drmmode_output->mode_output);
	if (drmmode_output->private_data) {
		free(drmmode_output->private_data);
		drmmode_output->private_data = NULL;
	}
	if (drmmode_output->backlight_iface)
		drmmode_backlight_set(output, drmmode_output->backlight_active_level);
	free(drmmode_output);
	output->driver_private = NULL;
}
示例#26
0
int DrmResources::GetProperty(uint32_t obj_id, uint32_t obj_type,
                              const char *prop_name, DrmProperty *property) {
    drmModeObjectPropertiesPtr props;

    props = drmModeObjectGetProperties(fd_, obj_id, obj_type);
    if (!props) {
        ALOGE("Failed to get properties for %d/%x", obj_id, obj_type);
        return -ENODEV;
    }

    bool found = false;
    for (int i = 0; !found && (size_t)i < props->count_props; ++i) {
        drmModePropertyPtr p = drmModeGetProperty(fd_, props->props[i]);
        if (!strcmp(p->name, prop_name)) {
            property->Init(p, props->prop_values[i]);
            found = true;
        }
        drmModeFreeProperty(p);
    }

    drmModeFreeObjectProperties(props);
    return found ? 0 : -ENOENT;
}
static void
find_properties (MetaMonitorManagerKms *manager_kms,
                 MetaOutputKms         *output_kms)
{
  drmModePropertyPtr prop;
  int i;

  for (i = 0; i < output_kms->connector->count_props; i++)
    {
      prop = drmModeGetProperty (manager_kms->fd, output_kms->connector->props[i]);
      if (!prop)
        continue;

      if ((prop->flags & DRM_MODE_PROP_ENUM) &&
          strcmp(prop->name, "DPMS") == 0)
        output_kms->dpms_prop_id = prop->prop_id;
      else if ((prop->flags & DRM_MODE_PROP_BLOB) &&
               strcmp (prop->name, "EDID") == 0)
        output_kms->edid_blob_id = output_kms->connector->prop_values[i];

      drmModeFreeProperty(prop);
    }
}
示例#28
0
static DFBResult
drmkmsPlaneInitLayer( CoreLayer                  *layer,
                      void                       *driver_data,
                      void                       *layer_data,
                      DFBDisplayLayerDescription *description,
                      DFBDisplayLayerConfig      *config,
                      DFBColorAdjustment         *adjustment )
{
     DRMKMSData       *drmkms = driver_data;
     DRMKMSDataShared *shared = drmkms->shared;
     DRMKMSLayerData  *data   = layer_data;
     drmModeObjectPropertiesPtr props;

     D_DEBUG_AT( DRMKMS_Layer, "%s()\n", __FUNCTION__ );

     data->index       = shared->layerplane_index_count++;
     data->plane_index = shared->plane_index_count++;
     data->level       = data->index;

     D_DEBUG_AT( DRMKMS_Layer, "  -> getting plane with index %d\n", data->plane_index );

     data->plane = drmModeGetPlane(drmkms->fd, drmkms->plane_resources->planes[data->plane_index]);

     D_DEBUG_AT( DRMKMS_Layer, "     ->  plane_id is %d\n", data->plane->plane_id );

     description->type             = DLTF_GRAPHICS;
     description->caps             = DLCAPS_SURFACE | DLCAPS_SCREEN_POSITION | DLCAPS_ALPHACHANNEL;
     description->surface_caps     = DSCAPS_NONE;
     description->surface_accessor = CSAID_LAYER0;

     snprintf( description->name, DFB_DISPLAY_LAYER_DESC_NAME_LENGTH, "DRMKMS Plane Layer %d", data->plane_index );


     config->flags      = DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT | DLCONF_BUFFERMODE;
     config->width      = dfb_config->mode.width  ?: shared->mode[0].hdisplay;
     config->height     = dfb_config->mode.height ?: shared->mode[0].vdisplay;

     config->pixelformat = dfb_config->mode.format ?: DSPF_ARGB;
     config->buffermode  = DLBM_FRONTONLY;


     props = drmModeObjectGetProperties( drmkms->fd, data->plane->plane_id, DRM_MODE_OBJECT_PLANE );
     if (props) {
          int                i;
          drmModePropertyPtr prop;

          D_INFO( "DirectFB/DRMKMS: supported properties for layer id %d\n", data->plane->plane_id );
          for (i = 0; i < props->count_props; i++) {
               prop = drmModeGetProperty( drmkms->fd, props->props[i] );
               if (!strcmp(prop->name, "colorkey")) {
                    description->caps |= DLCAPS_SRC_COLORKEY;
                    data->colorkey_propid = prop->prop_id;
                    D_INFO( "     colorkey\n" );
               }
               else if (!strcmp(prop->name, "zpos")) {
                    description->caps |= DLCAPS_LEVELS;
                    data->zpos_propid = prop->prop_id;
                    D_INFO( "     zpos\n" );

                    drmModeObjectSetProperty( drmkms->fd, data->plane->plane_id, DRM_MODE_OBJECT_PLANE, data->zpos_propid, data->level );
               }
               else if (!strcmp(prop->name, "alpha")) {
                    description->caps |= DLCAPS_OPACITY;
                    data->alpha_propid = prop->prop_id;
                    D_INFO( "     alpha\n" );
               }

               drmModeFreeProperty( prop );
          }
          drmModeFreeObjectProperties( props );
     }

     shared->layer_data[data->index] = data;

     return DFB_OK;
}
// DPMS
bool IntelHWComposerDrm::setDisplayDpms(int disp, bool blank)
{
    int ret=0;

    if (disp == OUTPUT_MIPI0) {
        // Set MIPI On/Off
        drmModeConnectorPtr connector;
        drmModePropertyPtr props = NULL;

        if ((connector = getConnector(disp)) == NULL) {
            ALOGW("%s: failed to get connector :%d!\n", __func__, disp);
            goto err;
        }

        if (connector->connection != DRM_MODE_CONNECTED) {
            ALOGW("%s: connector %d is not connected!\n", __func__, disp);
            freeConnector(connector);
            goto err;
        }

        for (int i = 0; i < connector->count_props; i++) {
            props = drmModeGetProperty(mDrmFd, connector->props[i]);
            if (!props) continue;

            if (!strcmp(props->name, "DPMS")) {
                ALOGD_IF(ALLOW_MONITOR_PRINT,
                         "%s: %s %u", __func__,
                         (blank == 0) ? "On" : "Off",
                         connector->connector_id);
                ret = drmModeConnectorSetProperty(mDrmFd,
                                connector->connector_id,
                                props->prop_id,
                                (blank==0) ? DRM_MODE_DPMS_ON : DRM_MODE_DPMS_OFF);
                drmModeFreeProperty(props);
                break;
            }
            drmModeFreeProperty(props);
        }
    } else if (disp == OUTPUT_HDMI) {
        // Set HDMI On/Off
        struct drm_psb_disp_ctrl dp_ctrl;

        ALOGD_IF(ALLOW_MONITOR_PRINT,
                 "%s: %s", __func__,
                 (blank == 0) ? "On" : "Off");
        memset(&dp_ctrl, 0, sizeof(dp_ctrl));
        dp_ctrl.cmd =
              (blank==0) ? DRM_PSB_DISP_PLANEB_ENABLE : DRM_PSB_DISP_PLANEB_DISABLE;

        ret = drmCommandWriteRead(mDrmFd, DRM_PSB_HDMI_FB_CMD, &dp_ctrl, sizeof(dp_ctrl));
    }

    if (ret != 0) {
        ALOGW("%s: connector %d dpms failed!\n", __func__, disp);
        goto err;
    }

    return true;
err:
    return false;
}
示例#30
0
文件: DRMUtils.cpp 项目: Arcko/xbmc
bool CDRMUtils::GetPlanes()
{
  drmModePlaneResPtr plane_resources;
  uint32_t primary_plane_id = 0;
  uint32_t overlay_plane_id = 0;
  uint32_t fourcc = 0;

  plane_resources = drmModeGetPlaneResources(m_fd);
  if (!plane_resources)
  {
    CLog::Log(LOGERROR, "CDRMUtils::%s - drmModeGetPlaneResources failed: %s", __FUNCTION__, strerror(errno));
    return false;
  }

  for (uint32_t i = 0; i < plane_resources->count_planes; i++)
  {
    uint32_t id = plane_resources->planes[i];
    drmModePlanePtr plane = drmModeGetPlane(m_fd, id);
    if (!plane)
    {
      CLog::Log(LOGERROR, "CDRMUtils::%s - drmModeGetPlane(%u) failed: %s", __FUNCTION__, id, strerror(errno));
      continue;
    }

    if (plane->possible_crtcs & (1 << m_crtc_index))
    {
      drmModeObjectPropertiesPtr props = drmModeObjectGetProperties(m_fd, id, DRM_MODE_OBJECT_PLANE);

      for (uint32_t j = 0; j < props->count_props; j++)
      {
        drmModePropertyPtr p = drmModeGetProperty(m_fd, props->props[j]);

        if ((strcmp(p->name, "type") == 0) && (props->prop_values[j] == DRM_PLANE_TYPE_PRIMARY) && (primary_plane_id == 0))
        {
          CLog::Log(LOGDEBUG, "CDRMUtils::%s - found primary plane: %u", __FUNCTION__, id);
          primary_plane_id = id;
        }
        else if ((strcmp(p->name, "type") == 0) && (props->prop_values[j] == DRM_PLANE_TYPE_OVERLAY) && (overlay_plane_id == 0))
        {
          CLog::Log(LOGDEBUG, "CDRMUtils::%s - found overlay plane: %u", __FUNCTION__, id);
          overlay_plane_id = id;
        }

        drmModeFreeProperty(p);
      }

      drmModeFreeObjectProperties(props);
    }

    drmModeFreePlane(plane);
  }

  drmModeFreePlaneResources(plane_resources);

  // primary plane
  m_primary_plane->plane = drmModeGetPlane(m_fd, primary_plane_id);
  if (!m_primary_plane->plane)
  {
    CLog::Log(LOGERROR, "CDRMUtils::%s - could not get primary plane %u: %s", __FUNCTION__, primary_plane_id, strerror(errno));
    return false;
  }

  if (!GetProperties(m_fd, primary_plane_id, DRM_MODE_OBJECT_PLANE, m_primary_plane))
  {
    CLog::Log(LOGERROR, "CDRMUtils::%s - could not get primary plane %u properties: %s", __FUNCTION__, primary_plane_id, strerror(errno));
    return false;
  }

  for (uint32_t i = 0; i < m_primary_plane->plane->count_formats; i++)
  {
    /* we want an alpha layer so break if we find one */
    if (m_primary_plane->plane->formats[i] == DRM_FORMAT_XRGB8888)
    {
      fourcc = DRM_FORMAT_XRGB8888;
      m_primary_plane->format = fourcc;
    }
    else if (m_primary_plane->plane->formats[i] == DRM_FORMAT_ARGB8888)
    {
      fourcc = DRM_FORMAT_ARGB8888;
      m_primary_plane->format = fourcc;
      break;
    }
  }

  if (fourcc == 0)
  {
    CLog::Log(LOGERROR, "CDRMUtils::%s - could not find a suitable primary plane format", __FUNCTION__);
    return false;
  }

  CLog::Log(LOGDEBUG, "CDRMUtils::%s - primary plane format: %c%c%c%c", __FUNCTION__, fourcc, fourcc >> 8, fourcc >> 16, fourcc >> 24);

  if (overlay_plane_id != 0)
  {
    // overlay plane
    m_overlay_plane->plane = drmModeGetPlane(m_fd, overlay_plane_id);
    if (!m_overlay_plane->plane)
    {
      CLog::Log(LOGERROR, "CDRMUtils::%s - could not get overlay plane %u: %s", __FUNCTION__, overlay_plane_id, strerror(errno));
      return false;
    }

    if (!GetProperties(m_fd, overlay_plane_id, DRM_MODE_OBJECT_PLANE, m_overlay_plane))
    {
      CLog::Log(LOGERROR, "CDRMUtils::%s - could not get overlay plane %u properties: %s", __FUNCTION__, overlay_plane_id, strerror(errno));
      return false;
    }

    fourcc = 0;

    for (uint32_t i = 0; i < m_overlay_plane->plane->count_formats; i++)
    {
      /* we want an alpha layer so break if we find one */
      if (m_overlay_plane->plane->formats[i] == DRM_FORMAT_XRGB8888)
      {
        fourcc = DRM_FORMAT_XRGB8888;
        m_overlay_plane->format = fourcc;
      }
      else if(m_overlay_plane->plane->formats[i] == DRM_FORMAT_ARGB8888)
      {
        fourcc = DRM_FORMAT_ARGB8888;
        m_overlay_plane->format = fourcc;
        break;
      }
    }

    if (fourcc == 0)
    {
      CLog::Log(LOGERROR, "CDRMUtils::%s - could not find a suitable overlay plane format", __FUNCTION__);
      return false;
    }

    CLog::Log(LOGDEBUG, "CDRMUtils::%s - overlay plane format: %c%c%c%c", __FUNCTION__, fourcc, fourcc >> 8, fourcc >> 16, fourcc >> 24);
  }