1 /* Hisilicon Hibmc SoC drm driver
2  *
3  * Based on the bochs drm driver.
4  *
5  * Copyright (c) 2016 Huawei Limited.
6  *
7  * Author:
8  *	Rongrong Zou <zourongrong@huawei.com>
9  *	Rongrong Zou <zourongrong@gmail.com>
10  *	Jianhua Li <lijianhua@huawei.com>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  */
18 
19 #ifndef HIBMC_DRM_DRV_H
20 #define HIBMC_DRM_DRV_H
21 
22 #include <drm/drmP.h>
23 #include <drm/drm_atomic.h>
24 #include <drm/drm_fb_helper.h>
25 #include <drm/drm_gem.h>
26 #include <drm/ttm/ttm_bo_driver.h>
27 
28 struct hibmc_framebuffer {
29 	struct drm_framebuffer fb;
30 	struct drm_gem_object *obj;
31 };
32 
33 struct hibmc_fbdev {
34 	struct drm_fb_helper helper;
35 	struct hibmc_framebuffer *fb;
36 	int size;
37 };
38 
39 struct hibmc_drm_private {
40 	/* hw */
41 	void __iomem   *mmio;
42 	void __iomem   *fb_map;
43 	unsigned long  fb_base;
44 	unsigned long  fb_size;
45 	bool msi_enabled;
46 
47 	/* drm */
48 	struct drm_device  *dev;
49 	bool mode_config_initialized;
50 	struct drm_atomic_state *suspend_state;
51 
52 	/* ttm */
53 	struct drm_global_reference mem_global_ref;
54 	struct ttm_bo_global_ref bo_global_ref;
55 	struct ttm_bo_device bdev;
56 	bool initialized;
57 
58 	/* fbdev */
59 	struct hibmc_fbdev *fbdev;
60 	bool mm_inited;
61 };
62 
63 #define to_hibmc_framebuffer(x) container_of(x, struct hibmc_framebuffer, fb)
64 
65 struct hibmc_bo {
66 	struct ttm_buffer_object bo;
67 	struct ttm_placement placement;
68 	struct ttm_bo_kmap_obj kmap;
69 	struct drm_gem_object gem;
70 	struct ttm_place placements[3];
71 	int pin_count;
72 };
73 
74 static inline struct hibmc_bo *hibmc_bo(struct ttm_buffer_object *bo)
75 {
76 	return container_of(bo, struct hibmc_bo, bo);
77 }
78 
79 static inline struct hibmc_bo *gem_to_hibmc_bo(struct drm_gem_object *gem)
80 {
81 	return container_of(gem, struct hibmc_bo, gem);
82 }
83 
84 void hibmc_set_power_mode(struct hibmc_drm_private *priv,
85 			  unsigned int power_mode);
86 void hibmc_set_current_gate(struct hibmc_drm_private *priv,
87 			    unsigned int gate);
88 
89 int hibmc_de_init(struct hibmc_drm_private *priv);
90 int hibmc_vdac_init(struct hibmc_drm_private *priv);
91 int hibmc_fbdev_init(struct hibmc_drm_private *priv);
92 void hibmc_fbdev_fini(struct hibmc_drm_private *priv);
93 
94 int hibmc_gem_create(struct drm_device *dev, u32 size, bool iskernel,
95 		     struct drm_gem_object **obj);
96 struct hibmc_framebuffer *
97 hibmc_framebuffer_init(struct drm_device *dev,
98 		       const struct drm_mode_fb_cmd2 *mode_cmd,
99 		       struct drm_gem_object *obj);
100 
101 int hibmc_mm_init(struct hibmc_drm_private *hibmc);
102 void hibmc_mm_fini(struct hibmc_drm_private *hibmc);
103 int hibmc_bo_pin(struct hibmc_bo *bo, u32 pl_flag, u64 *gpu_addr);
104 int hibmc_bo_unpin(struct hibmc_bo *bo);
105 void hibmc_gem_free_object(struct drm_gem_object *obj);
106 int hibmc_dumb_create(struct drm_file *file, struct drm_device *dev,
107 		      struct drm_mode_create_dumb *args);
108 int hibmc_dumb_mmap_offset(struct drm_file *file, struct drm_device *dev,
109 			   u32 handle, u64 *offset);
110 int hibmc_mmap(struct file *filp, struct vm_area_struct *vma);
111 
112 extern const struct drm_mode_config_funcs hibmc_mode_funcs;
113 
114 #endif
115