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