/* * rockchip_gem_create_with_handle - allocate an object with the given * size and create a gem handle on it * * returns a struct rockchip_gem_object* on success or ERR_PTR values * on failure. */ static struct rockchip_gem_object * rockchip_gem_create_with_handle(struct drm_file *file_priv, struct drm_device *drm, unsigned int size, unsigned int *handle) { struct rockchip_gem_object *rk_obj; struct drm_gem_object *obj; int ret; rk_obj = rockchip_gem_create_object(drm, size, false); if (IS_ERR(rk_obj)) return ERR_CAST(rk_obj); obj = &rk_obj->base; /* * allocate a id of idr table where the obj is registered * and handle has the id what user can see. */ ret = drm_gem_handle_create(file_priv, obj, handle); if (ret) goto err_handle_create; /* drop reference from allocate - handle holds it now. */ drm_gem_object_unreference_unlocked(obj); return rk_obj; err_handle_create: rockchip_gem_free_object(obj); return ERR_PTR(ret); }
static int rockchip_drm_fbdev_create(struct drm_fb_helper *helper, struct drm_fb_helper_surface_size *sizes) { struct rockchip_drm_private *private = to_drm_private(helper); struct drm_mode_fb_cmd2 mode_cmd = { 0 }; struct drm_device *dev = helper->dev; struct rockchip_gem_object *rk_obj; struct drm_framebuffer *fb; unsigned int bytes_per_pixel; unsigned long offset; struct fb_info *fbi; size_t size; int ret; bytes_per_pixel = DIV_ROUND_UP(sizes->surface_bpp, 8); mode_cmd.width = sizes->surface_width; mode_cmd.height = sizes->surface_height; mode_cmd.pitches[0] = sizes->surface_width * bytes_per_pixel; mode_cmd.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp, sizes->surface_depth); size = mode_cmd.pitches[0] * mode_cmd.height; rk_obj = rockchip_gem_create_object(dev, size, true); if (IS_ERR(rk_obj)) return -ENOMEM; private->fbdev_bo = &rk_obj->base;