1 /* 1 2 * Copyright (c) 2016 Intel Corporation 3 * 4 * Permission to use, copy, modify, distribute 5 * documentation for any purpose is hereby gra 6 * the above copyright notice appear in all co 7 * notice and this permission notice appear in 8 * that the name of the copyright holders not 9 * publicity pertaining to distribution of the 10 * written prior permission. The copyright ho 11 * about the suitability of this software for 12 * is" without express or implied warranty. 13 * 14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTI 15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHAN 16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE 17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSO 18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CO 19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNE 20 * OF THIS SOFTWARE. 21 */ 22 23 #ifndef __DRM_FRAMEBUFFER_H__ 24 #define __DRM_FRAMEBUFFER_H__ 25 26 #include <linux/ctype.h> 27 #include <linux/list.h> 28 #include <linux/sched.h> 29 30 #include <drm/drm_fourcc.h> 31 #include <drm/drm_mode_object.h> 32 33 struct drm_clip_rect; 34 struct drm_device; 35 struct drm_file; 36 struct drm_framebuffer; 37 struct drm_gem_object; 38 39 /** 40 * struct drm_framebuffer_funcs - framebuffer 41 */ 42 struct drm_framebuffer_funcs { 43 /** 44 * @destroy: 45 * 46 * Clean up framebuffer resources, spe 47 * backing storage. The core guarantee 48 * framebuffer successfully created by 49 * &drm_mode_config_funcs.fb_create. D 50 * drm_framebuffer_cleanup() to releas 51 * framebuffer. 52 */ 53 void (*destroy)(struct drm_framebuffer 54 55 /** 56 * @create_handle: 57 * 58 * Create a buffer handle in the drive 59 * GEM or TTM) valid for the passed-in 60 * the core to implement the GETFB IOC 61 * sufficiently priviledged user) also 62 * be used for seamless transitions be 63 * copying the current screen contents 64 * between that and the new contents. 65 * 66 * GEM based drivers should call drm_g 67 * handle. 68 * 69 * RETURNS: 70 * 71 * 0 on success or a negative error co 72 */ 73 int (*create_handle)(struct drm_frameb 74 struct drm_file * 75 unsigned int *han 76 /** 77 * @dirty: 78 * 79 * Optional callback for the dirty fb 80 * 81 * Userspace can notify the driver via 82 * framebuffer has changed and should 83 * hardware. This can also be used int 84 * emulation, though that's not the ca 85 * 86 * See documentation in drm_mode.h for 87 * for more information as all the sem 88 * one mapping on this function. 89 * 90 * Atomic drivers should use drm_atomi 91 * this hook. 92 * 93 * RETURNS: 94 * 95 * 0 on success or a negative error co 96 */ 97 int (*dirty)(struct drm_framebuffer *f 98 struct drm_file *file_pri 99 unsigned color, struct dr 100 unsigned num_clips); 101 }; 102 103 /** 104 * struct drm_framebuffer - frame buffer objec 105 * 106 * Note that the fb is refcounted for the bene 107 * for example some hw, disabling a CRTC/plane 108 * scanout does not actually complete until th 109 * cleanup (like releasing the reference(s) on 110 * should be deferred. In cases like this, th 111 * hold a ref to the fb even though it has alr 112 * userspace perspective. See drm_framebuffer_ 113 * drm_framebuffer_put(). 114 * 115 * The refcount is stored inside the mode obje 116 */ 117 struct drm_framebuffer { 118 /** 119 * @dev: DRM device this framebuffer b 120 */ 121 struct drm_device *dev; 122 /** 123 * @head: Place on the &drm_mode_confi 124 * &drm_mode_config.fb_lock. 125 */ 126 struct list_head head; 127 128 /** 129 * @base: base modeset object structur 130 */ 131 struct drm_mode_object base; 132 133 /** 134 * @comm: Name of the process allocati 135 */ 136 char comm[TASK_COMM_LEN]; 137 138 /** 139 * @format: framebuffer format informa 140 */ 141 const struct drm_format_info *format; 142 /** 143 * @funcs: framebuffer vfunc table 144 */ 145 const struct drm_framebuffer_funcs *fu 146 /** 147 * @pitches: Line stride per buffer. F 148 * is copied from drm_mode_fb_cmd2. 149 */ 150 unsigned int pitches[DRM_FORMAT_MAX_PL 151 /** 152 * @offsets: Offset from buffer start 153 * per buffer. For userspace created o 154 * drm_mode_fb_cmd2. 155 * 156 * Note that this is a linear offset a 157 * tiling or buffer layout per @modifi 158 * the actual pixel data for this fram 159 * e.g. when multiple planes are alloc 160 * storage buffer object. For tiled la 161 * @offsets must at least be tile-size 162 * stricter requirements. 163 * 164 * This should not be used to specifiy 165 * data (even for linear buffers). Spe 166 * instead done through the source rec 167 */ 168 unsigned int offsets[DRM_FORMAT_MAX_PL 169 /** 170 * @modifier: Data layout modifier. Th 171 * tiling, or also special layouts (li 172 * buffers. For userspace created obje 173 * drm_mode_fb_cmd2. 174 */ 175 uint64_t modifier; 176 /** 177 * @width: Logical width of the visibl 178 * pixels. 179 */ 180 unsigned int width; 181 /** 182 * @height: Logical height of the visi 183 * pixels. 184 */ 185 unsigned int height; 186 /** 187 * @flags: Framebuffer flags like DRM_ 188 * DRM_MODE_FB_MODIFIERS. 189 */ 190 int flags; 191 /** 192 * @filp_head: Placed on &drm_file.fbs 193 */ 194 struct list_head filp_head; 195 /** 196 * @obj: GEM objects backing the frame 197 * 198 * This is used by the GEM framebuffer 199 * drm_gem_fb_create(). 200 */ 201 struct drm_gem_object *obj[DRM_FORMAT_ 202 }; 203 204 #define obj_to_fb(x) container_of(x, struct dr 205 206 int drm_framebuffer_init(struct drm_device *de 207 struct drm_framebuffe 208 const struct drm_fram 209 struct drm_framebuffer *drm_framebuffer_lookup 210 211 212 void drm_framebuffer_remove(struct drm_framebu 213 void drm_framebuffer_cleanup(struct drm_frameb 214 void drm_framebuffer_unregister_private(struct 215 216 /** 217 * drm_framebuffer_get - acquire a framebuffer 218 * @fb: DRM framebuffer 219 * 220 * This function increments the framebuffer's 221 */ 222 static inline void drm_framebuffer_get(struct 223 { 224 drm_mode_object_get(&fb->base); 225 } 226 227 /** 228 * drm_framebuffer_put - release a framebuffer 229 * @fb: DRM framebuffer 230 * 231 * This function decrements the framebuffer's 232 * framebuffer if the reference count drops to 233 */ 234 static inline void drm_framebuffer_put(struct 235 { 236 drm_mode_object_put(&fb->base); 237 } 238 239 /** 240 * drm_framebuffer_read_refcount - read the fr 241 * @fb: framebuffer 242 * 243 * This functions returns the framebuffer's re 244 */ 245 static inline uint32_t drm_framebuffer_read_re 246 { 247 return kref_read(&fb->base.refcount); 248 } 249 250 /** 251 * drm_framebuffer_assign - store a reference 252 * @p: location to store framebuffer 253 * @fb: new framebuffer (maybe NULL) 254 * 255 * This functions sets the location to store a 256 * unreferencing the framebuffer that was prev 257 */ 258 static inline void drm_framebuffer_assign(stru 259 stru 260 { 261 if (fb) 262 drm_framebuffer_get(fb); 263 if (*p) 264 drm_framebuffer_put(*p); 265 *p = fb; 266 } 267 268 /* 269 * drm_for_each_fb - iterate over all framebuf 270 * @fb: the loop cursor 271 * @dev: the DRM device 272 * 273 * Iterate over all framebuffers of @dev. User 274 * &drm_mode_config.fb_lock. 275 */ 276 #define drm_for_each_fb(fb, dev) \ 277 for (WARN_ON(!mutex_is_locked(&(dev)-> 278 fb = list_first_entry(&(dev)->mod 279 stru 280 &fb->head != (&(dev)->mode_config 281 fb = list_next_entry(fb, head)) 282 283 /** 284 * struct drm_afbc_framebuffer - a special afb 285 * 286 * A derived class of struct drm_framebuffer, 287 */ 288 struct drm_afbc_framebuffer { 289 /** 290 * @base: base framebuffer structure. 291 */ 292 struct drm_framebuffer base; 293 /** 294 * @block_width: width of a single afb 295 */ 296 u32 block_width; 297 /** 298 * @block_height: height of a single a 299 */ 300 u32 block_height; 301 /** 302 * @aligned_width: aligned frame buffe 303 */ 304 u32 aligned_width; 305 /** 306 * @aligned_height: aligned frame buff 307 */ 308 u32 aligned_height; 309 /** 310 * @offset: offset of the first afbc h 311 */ 312 u32 offset; 313 /** 314 * @afbc_size: minimum size of afbc bu 315 */ 316 u32 afbc_size; 317 }; 318 319 #define fb_to_afbc_fb(x) container_of(x, struc 320 321 #endif 322
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.