예제 #1
0
/**
 * Get a secondary minor number.
 *
 * \param dev device data structure
 * \param sec-minor structure to hold the assigned minor
 * \return negative number on failure.
 *
 * Search an empty entry and initialize it to the given parameters, and
 * create the proc init entry via proc_init(). This routines assigns
 * minor numbers to secondary heads of multi-headed cards
 */
static int drm_get_minor(struct drm_device *dev, struct drm_minor **minor, int type)
{
	struct drm_minor *new_minor;
	int ret;
	int minor_id;

	DRM_DEBUG("\n");

	minor_id = drm_minor_get_id(dev, type);
	if (minor_id < 0)
		return minor_id;

	new_minor = kzalloc(sizeof(struct drm_minor), GFP_KERNEL);
	if (!new_minor) {
		ret = -ENOMEM;
		goto err_idr;
	}

	new_minor->type = type;
	new_minor->device = MKDEV(DRM_MAJOR, minor_id);
	new_minor->dev = dev;
	new_minor->index = minor_id;

	idr_replace(&drm_minors_idr, new_minor, minor_id);

	if (type == DRM_MINOR_LEGACY) {
		ret = drm_proc_init(new_minor, minor_id, drm_proc_root);
		if (ret) {
			DRM_ERROR("DRM: Failed to initialize /proc/dri.\n");
			goto err_mem;
		}
	} else
		new_minor->dev_root = NULL;

	ret = drm_sysfs_device_add(new_minor);
	if (ret) {
		printk(KERN_ERR
		       "DRM: Error sysfs_device_add.\n");
		goto err_g2;
	}
	*minor = new_minor;

	DRM_DEBUG("new minor assigned %d\n", minor_id);
	return 0;


err_g2:
	if (new_minor->type == DRM_MINOR_LEGACY)
		drm_proc_cleanup(new_minor, drm_proc_root);
err_mem:
	kfree(new_minor);
err_idr:
	idr_remove(&drm_minors_idr, minor_id);
	*minor = NULL;
	return ret;
}
예제 #2
0
파일: drm_stub.c 프로젝트: narenas/nx-libs
/**
 * Get a secondary minor number.
 *
 * \param dev device data structure
 * \param sec-minor structure to hold the assigned minor
 * \return negative number on failure.
 *
 * Search an empty entry and initialize it to the given parameters, and
 * create the proc init entry via proc_init(). This routines assigns
 * minor numbers to secondary heads of multi-headed cards
 */
static int drm_get_head(drm_device_t * dev, drm_head_t * head)
{
    drm_head_t **heads = drm_heads;
    int ret;
    int minor;

    DRM_DEBUG("\n");

    for (minor = 0; minor < cards_limit; minor++, heads++) {
        if (!*heads) {

            *head = (drm_head_t) {
                .dev = dev,
                 .device = MKDEV(DRM_MAJOR, minor),
                  .minor = minor,
            };
            if ((ret =
                        drm_proc_init(dev, minor, drm_proc_root,
                                      &head->dev_root))) {
                printk(KERN_ERR
                       "DRM: Failed to initialize /proc/dri.\n");
                goto err_g1;
            }

            head->dev_class = drm_sysfs_device_add(drm_class, head);
            if (IS_ERR(head->dev_class)) {
                printk(KERN_ERR
                       "DRM: Error sysfs_device_add.\n");
                ret = PTR_ERR(head->dev_class);
                goto err_g2;
            }
            *heads = head;

            DRM_DEBUG("new minor assigned %d\n", minor);
            return 0;
        }
    }
    DRM_ERROR("out of minors\n");
    return -ENOMEM;
err_g2:
    drm_proc_cleanup(minor, drm_proc_root, head->dev_root);
err_g1:
    *head = (drm_head_t) {
        .dev = NULL
    };
    return ret;
}