![]() |
|
|||
0001 /* 0002 * Copyright (c) 2016 Intel Corporation 0003 * 0004 * Permission to use, copy, modify, distribute, and sell this software and its 0005 * documentation for any purpose is hereby granted without fee, provided that 0006 * the above copyright notice appear in all copies and that both that copyright 0007 * notice and this permission notice appear in supporting documentation, and 0008 * that the name of the copyright holders not be used in advertising or 0009 * publicity pertaining to distribution of the software without specific, 0010 * written prior permission. The copyright holders make no representations 0011 * about the suitability of this software for any purpose. It is provided "as 0012 * is" without express or implied warranty. 0013 * 0014 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 0015 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 0016 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR 0017 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 0018 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 0019 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 0020 * OF THIS SOFTWARE. 0021 */ 0022 0023 #ifndef __DRM_FRAMEBUFFER_H__ 0024 #define __DRM_FRAMEBUFFER_H__ 0025 0026 #include <linux/ctype.h> 0027 #include <linux/list.h> 0028 #include <linux/sched.h> 0029 0030 #include <drm/drm_fourcc.h> 0031 #include <drm/drm_mode_object.h> 0032 0033 struct drm_clip_rect; 0034 struct drm_device; 0035 struct drm_file; 0036 struct drm_framebuffer; 0037 struct drm_gem_object; 0038 0039 /** 0040 * struct drm_framebuffer_funcs - framebuffer hooks 0041 */ 0042 struct drm_framebuffer_funcs { 0043 /** 0044 * @destroy: 0045 * 0046 * Clean up framebuffer resources, specifically also unreference the 0047 * backing storage. The core guarantees to call this function for every 0048 * framebuffer successfully created by calling 0049 * &drm_mode_config_funcs.fb_create. Drivers must also call 0050 * drm_framebuffer_cleanup() to release DRM core resources for this 0051 * framebuffer. 0052 */ 0053 void (*destroy)(struct drm_framebuffer *framebuffer); 0054 0055 /** 0056 * @create_handle: 0057 * 0058 * Create a buffer handle in the driver-specific buffer manager (either 0059 * GEM or TTM) valid for the passed-in &struct drm_file. This is used by 0060 * the core to implement the GETFB IOCTL, which returns (for 0061 * sufficiently priviledged user) also a native buffer handle. This can 0062 * be used for seamless transitions between modesetting clients by 0063 * copying the current screen contents to a private buffer and blending 0064 * between that and the new contents. 0065 * 0066 * GEM based drivers should call drm_gem_handle_create() to create the 0067 * handle. 0068 * 0069 * RETURNS: 0070 * 0071 * 0 on success or a negative error code on failure. 0072 */ 0073 int (*create_handle)(struct drm_framebuffer *fb, 0074 struct drm_file *file_priv, 0075 unsigned int *handle); 0076 /** 0077 * @dirty: 0078 * 0079 * Optional callback for the dirty fb IOCTL. 0080 * 0081 * Userspace can notify the driver via this callback that an area of the 0082 * framebuffer has changed and should be flushed to the display 0083 * hardware. This can also be used internally, e.g. by the fbdev 0084 * emulation, though that's not the case currently. 0085 * 0086 * See documentation in drm_mode.h for the struct drm_mode_fb_dirty_cmd 0087 * for more information as all the semantics and arguments have a one to 0088 * one mapping on this function. 0089 * 0090 * Atomic drivers should use drm_atomic_helper_dirtyfb() to implement 0091 * this hook. 0092 * 0093 * RETURNS: 0094 * 0095 * 0 on success or a negative error code on failure. 0096 */ 0097 int (*dirty)(struct drm_framebuffer *framebuffer, 0098 struct drm_file *file_priv, unsigned flags, 0099 unsigned color, struct drm_clip_rect *clips, 0100 unsigned num_clips); 0101 }; 0102 0103 /** 0104 * struct drm_framebuffer - frame buffer object 0105 * 0106 * Note that the fb is refcounted for the benefit of driver internals, 0107 * for example some hw, disabling a CRTC/plane is asynchronous, and 0108 * scanout does not actually complete until the next vblank. So some 0109 * cleanup (like releasing the reference(s) on the backing GEM bo(s)) 0110 * should be deferred. In cases like this, the driver would like to 0111 * hold a ref to the fb even though it has already been removed from 0112 * userspace perspective. See drm_framebuffer_get() and 0113 * drm_framebuffer_put(). 0114 * 0115 * The refcount is stored inside the mode object @base. 0116 */ 0117 struct drm_framebuffer { 0118 /** 0119 * @dev: DRM device this framebuffer belongs to 0120 */ 0121 struct drm_device *dev; 0122 /** 0123 * @head: Place on the &drm_mode_config.fb_list, access protected by 0124 * &drm_mode_config.fb_lock. 0125 */ 0126 struct list_head head; 0127 0128 /** 0129 * @base: base modeset object structure, contains the reference count. 0130 */ 0131 struct drm_mode_object base; 0132 0133 /** 0134 * @comm: Name of the process allocating the fb, used for fb dumping. 0135 */ 0136 char comm[TASK_COMM_LEN]; 0137 0138 /** 0139 * @format: framebuffer format information 0140 */ 0141 const struct drm_format_info *format; 0142 /** 0143 * @funcs: framebuffer vfunc table 0144 */ 0145 const struct drm_framebuffer_funcs *funcs; 0146 /** 0147 * @pitches: Line stride per buffer. For userspace created object this 0148 * is copied from drm_mode_fb_cmd2. 0149 */ 0150 unsigned int pitches[DRM_FORMAT_MAX_PLANES]; 0151 /** 0152 * @offsets: Offset from buffer start to the actual pixel data in bytes, 0153 * per buffer. For userspace created object this is copied from 0154 * drm_mode_fb_cmd2. 0155 * 0156 * Note that this is a linear offset and does not take into account 0157 * tiling or buffer laytou per @modifier. It meant to be used when the 0158 * actual pixel data for this framebuffer plane starts at an offset, 0159 * e.g. when multiple planes are allocated within the same backing 0160 * storage buffer object. For tiled layouts this generally means it 0161 * @offsets must at least be tile-size aligned, but hardware often has 0162 * stricter requirements. 0163 * 0164 * This should not be used to specifiy x/y pixel offsets into the buffer 0165 * data (even for linear buffers). Specifying an x/y pixel offset is 0166 * instead done through the source rectangle in &struct drm_plane_state. 0167 */ 0168 unsigned int offsets[DRM_FORMAT_MAX_PLANES]; 0169 /** 0170 * @modifier: Data layout modifier. This is used to describe 0171 * tiling, or also special layouts (like compression) of auxiliary 0172 * buffers. For userspace created object this is copied from 0173 * drm_mode_fb_cmd2. 0174 */ 0175 uint64_t modifier; 0176 /** 0177 * @width: Logical width of the visible area of the framebuffer, in 0178 * pixels. 0179 */ 0180 unsigned int width; 0181 /** 0182 * @height: Logical height of the visible area of the framebuffer, in 0183 * pixels. 0184 */ 0185 unsigned int height; 0186 /** 0187 * @flags: Framebuffer flags like DRM_MODE_FB_INTERLACED or 0188 * DRM_MODE_FB_MODIFIERS. 0189 */ 0190 int flags; 0191 /** 0192 * @hot_x: X coordinate of the cursor hotspot. Used by the legacy cursor 0193 * IOCTL when the driver supports cursor through a DRM_PLANE_TYPE_CURSOR 0194 * universal plane. 0195 */ 0196 int hot_x; 0197 /** 0198 * @hot_y: Y coordinate of the cursor hotspot. Used by the legacy cursor 0199 * IOCTL when the driver supports cursor through a DRM_PLANE_TYPE_CURSOR 0200 * universal plane. 0201 */ 0202 int hot_y; 0203 /** 0204 * @filp_head: Placed on &drm_file.fbs, protected by &drm_file.fbs_lock. 0205 */ 0206 struct list_head filp_head; 0207 /** 0208 * @obj: GEM objects backing the framebuffer, one per plane (optional). 0209 * 0210 * This is used by the GEM framebuffer helpers, see e.g. 0211 * drm_gem_fb_create(). 0212 */ 0213 struct drm_gem_object *obj[DRM_FORMAT_MAX_PLANES]; 0214 }; 0215 0216 #define obj_to_fb(x) container_of(x, struct drm_framebuffer, base) 0217 0218 int drm_framebuffer_init(struct drm_device *dev, 0219 struct drm_framebuffer *fb, 0220 const struct drm_framebuffer_funcs *funcs); 0221 struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev, 0222 struct drm_file *file_priv, 0223 uint32_t id); 0224 void drm_framebuffer_remove(struct drm_framebuffer *fb); 0225 void drm_framebuffer_cleanup(struct drm_framebuffer *fb); 0226 void drm_framebuffer_unregister_private(struct drm_framebuffer *fb); 0227 0228 /** 0229 * drm_framebuffer_get - acquire a framebuffer reference 0230 * @fb: DRM framebuffer 0231 * 0232 * This function increments the framebuffer's reference count. 0233 */ 0234 static inline void drm_framebuffer_get(struct drm_framebuffer *fb) 0235 { 0236 drm_mode_object_get(&fb->base); 0237 } 0238 0239 /** 0240 * drm_framebuffer_put - release a framebuffer reference 0241 * @fb: DRM framebuffer 0242 * 0243 * This function decrements the framebuffer's reference count and frees the 0244 * framebuffer if the reference count drops to zero. 0245 */ 0246 static inline void drm_framebuffer_put(struct drm_framebuffer *fb) 0247 { 0248 drm_mode_object_put(&fb->base); 0249 } 0250 0251 /** 0252 * drm_framebuffer_read_refcount - read the framebuffer reference count. 0253 * @fb: framebuffer 0254 * 0255 * This functions returns the framebuffer's reference count. 0256 */ 0257 static inline uint32_t drm_framebuffer_read_refcount(const struct drm_framebuffer *fb) 0258 { 0259 return kref_read(&fb->base.refcount); 0260 } 0261 0262 /** 0263 * drm_framebuffer_assign - store a reference to the fb 0264 * @p: location to store framebuffer 0265 * @fb: new framebuffer (maybe NULL) 0266 * 0267 * This functions sets the location to store a reference to the framebuffer, 0268 * unreferencing the framebuffer that was previously stored in that location. 0269 */ 0270 static inline void drm_framebuffer_assign(struct drm_framebuffer **p, 0271 struct drm_framebuffer *fb) 0272 { 0273 if (fb) 0274 drm_framebuffer_get(fb); 0275 if (*p) 0276 drm_framebuffer_put(*p); 0277 *p = fb; 0278 } 0279 0280 /* 0281 * drm_for_each_fb - iterate over all framebuffers 0282 * @fb: the loop cursor 0283 * @dev: the DRM device 0284 * 0285 * Iterate over all framebuffers of @dev. User must hold 0286 * &drm_mode_config.fb_lock. 0287 */ 0288 #define drm_for_each_fb(fb, dev) \ 0289 for (WARN_ON(!mutex_is_locked(&(dev)->mode_config.fb_lock)), \ 0290 fb = list_first_entry(&(dev)->mode_config.fb_list, \ 0291 struct drm_framebuffer, head); \ 0292 &fb->head != (&(dev)->mode_config.fb_list); \ 0293 fb = list_next_entry(fb, head)) 0294 0295 int drm_framebuffer_plane_width(int width, 0296 const struct drm_framebuffer *fb, int plane); 0297 int drm_framebuffer_plane_height(int height, 0298 const struct drm_framebuffer *fb, int plane); 0299 0300 /** 0301 * struct drm_afbc_framebuffer - a special afbc frame buffer object 0302 * 0303 * A derived class of struct drm_framebuffer, dedicated for afbc use cases. 0304 */ 0305 struct drm_afbc_framebuffer { 0306 /** 0307 * @base: base framebuffer structure. 0308 */ 0309 struct drm_framebuffer base; 0310 /** 0311 * @block_width: width of a single afbc block 0312 */ 0313 u32 block_width; 0314 /** 0315 * @block_height: height of a single afbc block 0316 */ 0317 u32 block_height; 0318 /** 0319 * @aligned_width: aligned frame buffer width 0320 */ 0321 u32 aligned_width; 0322 /** 0323 * @aligned_height: aligned frame buffer height 0324 */ 0325 u32 aligned_height; 0326 /** 0327 * @offset: offset of the first afbc header 0328 */ 0329 u32 offset; 0330 /** 0331 * @afbc_size: minimum size of afbc buffer 0332 */ 0333 u32 afbc_size; 0334 }; 0335 0336 #define fb_to_afbc_fb(x) container_of(x, struct drm_afbc_framebuffer, base) 0337 0338 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |