hibmc_ttm.c 1.38 KB
Newer Older
1
// SPDX-License-Identifier: GPL-2.0-or-later
2 3 4 5 6 7 8 9 10 11 12 13
/* 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>
 */

14 15
#include <linux/pci.h>

16
#include <drm/drm_atomic_helper.h>
17
#include <drm/drm_gem.h>
18
#include <drm/drm_gem_framebuffer_helper.h>
19 20
#include <drm/drm_gem_vram_helper.h>
#include <drm/drm_print.h>
21 22 23 24 25

#include "hibmc_drm_drv.h"

int hibmc_mm_init(struct hibmc_drm_private *hibmc)
{
26
	struct drm_vram_mm *vmm;
27 28 29
	int ret;
	struct drm_device *dev = hibmc->dev;

30 31
	vmm = drm_vram_helper_alloc_mm(dev,
				       pci_resource_start(dev->pdev, 0),
32
				       hibmc->fb_size);
33 34 35
	if (IS_ERR(vmm)) {
		ret = PTR_ERR(vmm);
		DRM_ERROR("Error initializing VRAM MM; %d\n", ret);
36 37 38 39 40 41 42 43
		return ret;
	}

	return 0;
}

void hibmc_mm_fini(struct hibmc_drm_private *hibmc)
{
44
	if (!hibmc->dev->vram_mm)
45 46
		return;

47
	drm_vram_helper_release_mm(hibmc->dev);
48 49 50 51 52
}

int hibmc_dumb_create(struct drm_file *file, struct drm_device *dev,
		      struct drm_mode_create_dumb *args)
{
53
	return drm_gem_vram_fill_create_dumb(file, dev, 0, 16, args);
54 55
}

56
const struct drm_mode_config_funcs hibmc_mode_funcs = {
57
	.mode_valid = drm_vram_helper_mode_valid,
58 59
	.atomic_check = drm_atomic_helper_check,
	.atomic_commit = drm_atomic_helper_commit,
60
	.fb_create = drm_gem_fb_create,
61
};