1 /*
2 * Copyright (C) 2016 Noralf Trønnes
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 */
9
10 #ifndef __LINUX_TINYDRM_H
11 #define __LINUX_TINYDRM_H
12
13 #include <drm/drm_gem_cma_helper.h>
14 #include <drm/drm_fb_cma_helper.h>
15 #include <drm/drm_simple_kms_helper.h>
16
17 /**
18 * struct tinydrm_device - tinydrm device
19 */
20 struct tinydrm_device {
21 /**
22 * @drm: DRM device
23 */
24 struct drm_device *drm;
25
26 /**
27 * @pipe: Display pipe structure
28 */
29 struct drm_simple_display_pipe pipe;
30
31 /**
32 * @dirty_lock: Serializes framebuffer flushing
33 */
34 struct mutex dirty_lock;
35
36 /**
37 * @fb_funcs: Framebuffer functions used when creating framebuffers
38 */
39 const struct drm_framebuffer_funcs *fb_funcs;
40
41 /**
42 * @fb_dirty: Framebuffer dirty callback
43 */
44 int (*fb_dirty)(struct drm_framebuffer *framebuffer,
45 struct drm_file *file_priv, unsigned flags,
46 unsigned color, struct drm_clip_rect *clips,
47 unsigned num_clips);
48 };
49
50 static inline struct tinydrm_device *
pipe_to_tinydrm(struct drm_simple_display_pipe * pipe)51 pipe_to_tinydrm(struct drm_simple_display_pipe *pipe)
52 {
53 return container_of(pipe, struct tinydrm_device, pipe);
54 }
55
56 /**
57 * TINYDRM_GEM_DRIVER_OPS - default tinydrm gem operations
58 *
59 * This macro provides a shortcut for setting the tinydrm GEM operations in
60 * the &drm_driver structure.
61 */
62 #define TINYDRM_GEM_DRIVER_OPS \
63 .gem_free_object_unlocked = tinydrm_gem_cma_free_object, \
64 .gem_print_info = drm_gem_cma_print_info, \
65 .gem_vm_ops = &drm_gem_cma_vm_ops, \
66 .prime_handle_to_fd = drm_gem_prime_handle_to_fd, \
67 .prime_fd_to_handle = drm_gem_prime_fd_to_handle, \
68 .gem_prime_import = drm_gem_prime_import, \
69 .gem_prime_export = drm_gem_prime_export, \
70 .gem_prime_get_sg_table = drm_gem_cma_prime_get_sg_table, \
71 .gem_prime_import_sg_table = tinydrm_gem_cma_prime_import_sg_table, \
72 .gem_prime_vmap = drm_gem_cma_prime_vmap, \
73 .gem_prime_vunmap = drm_gem_cma_prime_vunmap, \
74 .gem_prime_mmap = drm_gem_cma_prime_mmap, \
75 .dumb_create = drm_gem_cma_dumb_create
76
77 /**
78 * TINYDRM_MODE - tinydrm display mode
79 * @hd: Horizontal resolution, width
80 * @vd: Vertical resolution, height
81 * @hd_mm: Display width in millimeters
82 * @vd_mm: Display height in millimeters
83 *
84 * This macro creates a &drm_display_mode for use with tinydrm.
85 */
86 #define TINYDRM_MODE(hd, vd, hd_mm, vd_mm) \
87 .hdisplay = (hd), \
88 .hsync_start = (hd), \
89 .hsync_end = (hd), \
90 .htotal = (hd), \
91 .vdisplay = (vd), \
92 .vsync_start = (vd), \
93 .vsync_end = (vd), \
94 .vtotal = (vd), \
95 .width_mm = (hd_mm), \
96 .height_mm = (vd_mm), \
97 .type = DRM_MODE_TYPE_DRIVER, \
98 .clock = 1 /* pass validation */
99
100 void tinydrm_gem_cma_free_object(struct drm_gem_object *gem_obj);
101 struct drm_gem_object *
102 tinydrm_gem_cma_prime_import_sg_table(struct drm_device *drm,
103 struct dma_buf_attachment *attach,
104 struct sg_table *sgt);
105 int devm_tinydrm_init(struct device *parent, struct tinydrm_device *tdev,
106 const struct drm_framebuffer_funcs *fb_funcs,
107 struct drm_driver *driver);
108 int devm_tinydrm_register(struct tinydrm_device *tdev);
109 void tinydrm_shutdown(struct tinydrm_device *tdev);
110
111 void tinydrm_display_pipe_update(struct drm_simple_display_pipe *pipe,
112 struct drm_plane_state *old_state);
113 int
114 tinydrm_display_pipe_init(struct tinydrm_device *tdev,
115 const struct drm_simple_display_pipe_funcs *funcs,
116 int connector_type,
117 const uint32_t *formats,
118 unsigned int format_count,
119 const struct drm_display_mode *mode,
120 unsigned int rotation);
121
122 #endif /* __LINUX_TINYDRM_H */
123