2019-05-27 14:55:01 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2016-11-16 21:31:51 +08:00
|
|
|
/* Hisilicon Hibmc SoC drm driver
|
|
|
|
*
|
|
|
|
* Based on the bochs drm driver.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2016 Huawei Limited.
|
|
|
|
*
|
|
|
|
* Author:
|
|
|
|
* Rongrong Zou <zourongrong@huawei.com>
|
|
|
|
* Rongrong Zou <zourongrong@gmail.com>
|
|
|
|
* Jianhua Li <lijianhua@huawei.com>
|
|
|
|
*/
|
|
|
|
|
2016-11-16 20:52:37 +08:00
|
|
|
#include <drm/drm_atomic_helper.h>
|
2016-11-16 21:31:51 +08:00
|
|
|
|
|
|
|
#include "hibmc_drm_drv.h"
|
|
|
|
|
|
|
|
int hibmc_mm_init(struct hibmc_drm_private *hibmc)
|
|
|
|
{
|
2019-05-08 16:26:30 +08:00
|
|
|
struct drm_vram_mm *vmm;
|
2016-11-16 21:31:51 +08:00
|
|
|
int ret;
|
|
|
|
struct drm_device *dev = hibmc->dev;
|
|
|
|
|
2019-05-08 16:26:30 +08:00
|
|
|
vmm = drm_vram_helper_alloc_mm(dev,
|
|
|
|
pci_resource_start(dev->pdev, 0),
|
|
|
|
hibmc->fb_size, &drm_gem_vram_mm_funcs);
|
|
|
|
if (IS_ERR(vmm)) {
|
|
|
|
ret = PTR_ERR(vmm);
|
|
|
|
DRM_ERROR("Error initializing VRAM MM; %d\n", ret);
|
2016-11-16 21:31:51 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void hibmc_mm_fini(struct hibmc_drm_private *hibmc)
|
|
|
|
{
|
2019-05-08 16:26:30 +08:00
|
|
|
if (!hibmc->dev->vram_mm)
|
2016-11-16 21:31:51 +08:00
|
|
|
return;
|
|
|
|
|
2019-05-08 16:26:30 +08:00
|
|
|
drm_vram_helper_release_mm(hibmc->dev);
|
2016-11-16 21:31:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int hibmc_gem_create(struct drm_device *dev, u32 size, bool iskernel,
|
|
|
|
struct drm_gem_object **obj)
|
|
|
|
{
|
2019-05-08 16:26:29 +08:00
|
|
|
struct drm_gem_vram_object *gbo;
|
2016-11-16 21:31:51 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
*obj = NULL;
|
|
|
|
|
2019-05-08 16:26:29 +08:00
|
|
|
size = roundup(size, PAGE_SIZE);
|
|
|
|
if (size == 0)
|
2016-11-16 21:31:51 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2019-05-08 16:26:30 +08:00
|
|
|
gbo = drm_gem_vram_create(dev, &dev->vram_mm->bdev, size, 0, false);
|
2019-05-08 16:26:29 +08:00
|
|
|
if (IS_ERR(gbo)) {
|
|
|
|
ret = PTR_ERR(gbo);
|
2016-11-16 21:31:51 +08:00
|
|
|
if (ret != -ERESTARTSYS)
|
|
|
|
DRM_ERROR("failed to allocate GEM object: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
2019-05-08 16:26:29 +08:00
|
|
|
*obj = &gbo->gem;
|
2016-11-16 21:31:51 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int hibmc_dumb_create(struct drm_file *file, struct drm_device *dev,
|
|
|
|
struct drm_mode_create_dumb *args)
|
|
|
|
{
|
|
|
|
struct drm_gem_object *gobj;
|
|
|
|
u32 handle;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
args->pitch = ALIGN(args->width * DIV_ROUND_UP(args->bpp, 8), 16);
|
|
|
|
args->size = args->pitch * args->height;
|
|
|
|
|
|
|
|
ret = hibmc_gem_create(dev, args->size, false,
|
|
|
|
&gobj);
|
|
|
|
if (ret) {
|
|
|
|
DRM_ERROR("failed to create GEM object: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = drm_gem_handle_create(file, gobj, &handle);
|
2017-08-11 20:32:56 +08:00
|
|
|
drm_gem_object_put_unlocked(gobj);
|
2016-11-16 21:31:51 +08:00
|
|
|
if (ret) {
|
|
|
|
DRM_ERROR("failed to unreference GEM object: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
args->handle = handle;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-11-16 20:52:37 +08:00
|
|
|
static void hibmc_user_framebuffer_destroy(struct drm_framebuffer *fb)
|
|
|
|
{
|
|
|
|
struct hibmc_framebuffer *hibmc_fb = to_hibmc_framebuffer(fb);
|
|
|
|
|
2017-08-11 20:32:56 +08:00
|
|
|
drm_gem_object_put_unlocked(hibmc_fb->obj);
|
2016-11-16 20:52:37 +08:00
|
|
|
drm_framebuffer_cleanup(fb);
|
|
|
|
kfree(hibmc_fb);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct drm_framebuffer_funcs hibmc_fb_funcs = {
|
|
|
|
.destroy = hibmc_user_framebuffer_destroy,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct hibmc_framebuffer *
|
|
|
|
hibmc_framebuffer_init(struct drm_device *dev,
|
|
|
|
const struct drm_mode_fb_cmd2 *mode_cmd,
|
|
|
|
struct drm_gem_object *obj)
|
|
|
|
{
|
|
|
|
struct hibmc_framebuffer *hibmc_fb;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
hibmc_fb = kzalloc(sizeof(*hibmc_fb), GFP_KERNEL);
|
|
|
|
if (!hibmc_fb) {
|
|
|
|
DRM_ERROR("failed to allocate hibmc_fb\n");
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
}
|
|
|
|
|
drm: Pass 'dev' to drm_helper_mode_fill_fb_struct()
Pass the drm_device to drm_helper_mode_fill_fb_struct() so that we can
populate fb->dev early. Will make it easier to use the fb before we
register it.
@@
identifier fb, mode_cmd;
@@
void drm_helper_mode_fill_fb_struct(
+ struct drm_device *dev,
struct drm_framebuffer *fb,
const struct drm_mode_fb_cmd2 *mode_cmd
);
@@
identifier fb, mode_cmd;
@@
void drm_helper_mode_fill_fb_struct(
+ struct drm_device *dev,
struct drm_framebuffer *fb,
const struct drm_mode_fb_cmd2 *mode_cmd
)
{ ... }
@@
function func;
identifier dev;
expression E1, E2;
@@
func(struct drm_device *dev, ...)
{
...
drm_helper_mode_fill_fb_struct(
+ dev,
E1, E2);
...
}
@@
expression E1, E2;
@@
drm_helper_mode_fill_fb_struct(
+ dev,
E1, E2);
v2: Rerun spatch due to code changes
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Link: http://patchwork.freedesktop.org/patch/msgid/1481748539-18283-1-git-send-email-ville.syrjala@linux.intel.com
2016-12-15 04:48:59 +08:00
|
|
|
drm_helper_mode_fill_fb_struct(dev, &hibmc_fb->fb, mode_cmd);
|
2016-11-16 20:52:37 +08:00
|
|
|
hibmc_fb->obj = obj;
|
|
|
|
ret = drm_framebuffer_init(dev, &hibmc_fb->fb, &hibmc_fb_funcs);
|
|
|
|
if (ret) {
|
|
|
|
DRM_ERROR("drm_framebuffer_init failed: %d\n", ret);
|
|
|
|
kfree(hibmc_fb);
|
|
|
|
return ERR_PTR(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hibmc_fb;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct drm_framebuffer *
|
|
|
|
hibmc_user_framebuffer_create(struct drm_device *dev,
|
|
|
|
struct drm_file *filp,
|
|
|
|
const struct drm_mode_fb_cmd2 *mode_cmd)
|
|
|
|
{
|
|
|
|
struct drm_gem_object *obj;
|
|
|
|
struct hibmc_framebuffer *hibmc_fb;
|
|
|
|
|
|
|
|
DRM_DEBUG_DRIVER("%dx%d, format %c%c%c%c\n",
|
|
|
|
mode_cmd->width, mode_cmd->height,
|
|
|
|
(mode_cmd->pixel_format) & 0xff,
|
|
|
|
(mode_cmd->pixel_format >> 8) & 0xff,
|
|
|
|
(mode_cmd->pixel_format >> 16) & 0xff,
|
|
|
|
(mode_cmd->pixel_format >> 24) & 0xff);
|
|
|
|
|
|
|
|
obj = drm_gem_object_lookup(filp, mode_cmd->handles[0]);
|
|
|
|
if (!obj)
|
|
|
|
return ERR_PTR(-ENOENT);
|
|
|
|
|
|
|
|
hibmc_fb = hibmc_framebuffer_init(dev, mode_cmd, obj);
|
|
|
|
if (IS_ERR(hibmc_fb)) {
|
2017-08-11 20:32:56 +08:00
|
|
|
drm_gem_object_put_unlocked(obj);
|
2016-11-16 20:52:37 +08:00
|
|
|
return ERR_PTR((long)hibmc_fb);
|
|
|
|
}
|
|
|
|
return &hibmc_fb->fb;
|
|
|
|
}
|
2016-11-16 20:54:52 +08:00
|
|
|
|
|
|
|
const struct drm_mode_config_funcs hibmc_mode_funcs = {
|
|
|
|
.atomic_check = drm_atomic_helper_check,
|
|
|
|
.atomic_commit = drm_atomic_helper_commit,
|
|
|
|
.fb_create = hibmc_user_framebuffer_create,
|
|
|
|
};
|