1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Hisilicon Hibmc SoC drm driver
3 *
4 * Based on the bochs drm driver.
5 *
6 * Copyright (c) 2016 Huawei Limited.
7 *
8 * Author:
9 * Rongrong Zou <zourongrong@huawei.com>
10 * Rongrong Zou <zourongrong@gmail.com>
11 * Jianhua Li <lijianhua@huawei.com>
12 */
13
14 #include <linux/pci.h>
15
16 #include <drm/drm_atomic_helper.h>
17 #include <drm/drm_gem.h>
18 #include <drm/drm_gem_framebuffer_helper.h>
19 #include <drm/drm_gem_vram_helper.h>
20 #include <drm/drm_print.h>
21
22 #include "hibmc_drm_drv.h"
23
hibmc_mm_init(struct hibmc_drm_private * hibmc)24 int hibmc_mm_init(struct hibmc_drm_private *hibmc)
25 {
26 struct drm_vram_mm *vmm;
27 int ret;
28 struct drm_device *dev = hibmc->dev;
29
30 vmm = drm_vram_helper_alloc_mm(dev,
31 pci_resource_start(dev->pdev, 0),
32 hibmc->fb_size);
33 if (IS_ERR(vmm)) {
34 ret = PTR_ERR(vmm);
35 drm_err(dev, "Error initializing VRAM MM; %d\n", ret);
36 return ret;
37 }
38
39 return 0;
40 }
41
hibmc_mm_fini(struct hibmc_drm_private * hibmc)42 void hibmc_mm_fini(struct hibmc_drm_private *hibmc)
43 {
44 if (!hibmc->dev->vram_mm)
45 return;
46
47 drm_vram_helper_release_mm(hibmc->dev);
48 }
49
hibmc_dumb_create(struct drm_file * file,struct drm_device * dev,struct drm_mode_create_dumb * args)50 int hibmc_dumb_create(struct drm_file *file, struct drm_device *dev,
51 struct drm_mode_create_dumb *args)
52 {
53 return drm_gem_vram_fill_create_dumb(file, dev, 0, 128, args);
54 }
55
56 const struct drm_mode_config_funcs hibmc_mode_funcs = {
57 .mode_valid = drm_vram_helper_mode_valid,
58 .atomic_check = drm_atomic_helper_check,
59 .atomic_commit = drm_atomic_helper_commit,
60 .fb_create = drm_gem_fb_create,
61 };
62