brintos

brintos / linux-shallow public Read only

0
0
Text · 9.8 KiB · 6680770 Raw
322 lines · c
1/*2 * Copyright (c) 2016 Intel Corporation3 *4 * Permission to use, copy, modify, distribute, and sell this software and its5 * documentation for any purpose is hereby granted without fee, provided that6 * the above copyright notice appear in all copies and that both that copyright7 * notice and this permission notice appear in supporting documentation, and8 * that the name of the copyright holders not be used in advertising or9 * publicity pertaining to distribution of the software without specific,10 * written prior permission.  The copyright holders make no representations11 * about the suitability of this software for any purpose.  It is provided "as12 * is" without express or implied warranty.13 *14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE20 * 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 33struct drm_clip_rect;34struct drm_device;35struct drm_file;36struct drm_framebuffer;37struct drm_gem_object;38 39/**40 * struct drm_framebuffer_funcs - framebuffer hooks41 */42struct drm_framebuffer_funcs {43	/**44	 * @destroy:45	 *46	 * Clean up framebuffer resources, specifically also unreference the47	 * backing storage. The core guarantees to call this function for every48	 * framebuffer successfully created by calling49	 * &drm_mode_config_funcs.fb_create. Drivers must also call50	 * drm_framebuffer_cleanup() to release DRM core resources for this51	 * framebuffer.52	 */53	void (*destroy)(struct drm_framebuffer *framebuffer);54 55	/**56	 * @create_handle:57	 *58	 * Create a buffer handle in the driver-specific buffer manager (either59	 * GEM or TTM) valid for the passed-in &struct drm_file. This is used by60	 * the core to implement the GETFB IOCTL, which returns (for61	 * sufficiently priviledged user) also a native buffer handle. This can62	 * be used for seamless transitions between modesetting clients by63	 * copying the current screen contents to a private buffer and blending64	 * between that and the new contents.65	 *66	 * GEM based drivers should call drm_gem_handle_create() to create the67	 * handle.68	 *69	 * RETURNS:70	 *71	 * 0 on success or a negative error code on failure.72	 */73	int (*create_handle)(struct drm_framebuffer *fb,74			     struct drm_file *file_priv,75			     unsigned int *handle);76	/**77	 * @dirty:78	 *79	 * Optional callback for the dirty fb IOCTL.80	 *81	 * Userspace can notify the driver via this callback that an area of the82	 * framebuffer has changed and should be flushed to the display83	 * hardware. This can also be used internally, e.g. by the fbdev84	 * emulation, though that's not the case currently.85	 *86	 * See documentation in drm_mode.h for the struct drm_mode_fb_dirty_cmd87	 * for more information as all the semantics and arguments have a one to88	 * one mapping on this function.89	 *90	 * Atomic drivers should use drm_atomic_helper_dirtyfb() to implement91	 * this hook.92	 *93	 * RETURNS:94	 *95	 * 0 on success or a negative error code on failure.96	 */97	int (*dirty)(struct drm_framebuffer *framebuffer,98		     struct drm_file *file_priv, unsigned flags,99		     unsigned color, struct drm_clip_rect *clips,100		     unsigned num_clips);101};102 103/**104 * struct drm_framebuffer - frame buffer object105 *106 * Note that the fb is refcounted for the benefit of driver internals,107 * for example some hw, disabling a CRTC/plane is asynchronous, and108 * scanout does not actually complete until the next vblank.  So some109 * cleanup (like releasing the reference(s) on the backing GEM bo(s))110 * should be deferred.  In cases like this, the driver would like to111 * hold a ref to the fb even though it has already been removed from112 * userspace perspective. See drm_framebuffer_get() and113 * drm_framebuffer_put().114 *115 * The refcount is stored inside the mode object @base.116 */117struct drm_framebuffer {118	/**119	 * @dev: DRM device this framebuffer belongs to120	 */121	struct drm_device *dev;122	/**123	 * @head: Place on the &drm_mode_config.fb_list, access protected by124	 * &drm_mode_config.fb_lock.125	 */126	struct list_head head;127 128	/**129	 * @base: base modeset object structure, contains the reference count.130	 */131	struct drm_mode_object base;132 133	/**134	 * @comm: Name of the process allocating the fb, used for fb dumping.135	 */136	char comm[TASK_COMM_LEN];137 138	/**139	 * @format: framebuffer format information140	 */141	const struct drm_format_info *format;142	/**143	 * @funcs: framebuffer vfunc table144	 */145	const struct drm_framebuffer_funcs *funcs;146	/**147	 * @pitches: Line stride per buffer. For userspace created object this148	 * is copied from drm_mode_fb_cmd2.149	 */150	unsigned int pitches[DRM_FORMAT_MAX_PLANES];151	/**152	 * @offsets: Offset from buffer start to the actual pixel data in bytes,153	 * per buffer. For userspace created object this is copied from154	 * drm_mode_fb_cmd2.155	 *156	 * Note that this is a linear offset and does not take into account157	 * tiling or buffer layout per @modifier. It is meant to be used when158	 * the actual pixel data for this framebuffer plane starts at an offset,159	 * e.g. when multiple planes are allocated within the same backing160	 * storage buffer object. For tiled layouts this generally means its161	 * @offsets must at least be tile-size aligned, but hardware often has162	 * stricter requirements.163	 *164	 * This should not be used to specifiy x/y pixel offsets into the buffer165	 * data (even for linear buffers). Specifying an x/y pixel offset is166	 * instead done through the source rectangle in &struct drm_plane_state.167	 */168	unsigned int offsets[DRM_FORMAT_MAX_PLANES];169	/**170	 * @modifier: Data layout modifier. This is used to describe171	 * tiling, or also special layouts (like compression) of auxiliary172	 * buffers. For userspace created object this is copied from173	 * drm_mode_fb_cmd2.174	 */175	uint64_t modifier;176	/**177	 * @width: Logical width of the visible area of the framebuffer, in178	 * pixels.179	 */180	unsigned int width;181	/**182	 * @height: Logical height of the visible area of the framebuffer, in183	 * pixels.184	 */185	unsigned int height;186	/**187	 * @flags: Framebuffer flags like DRM_MODE_FB_INTERLACED or188	 * DRM_MODE_FB_MODIFIERS.189	 */190	int flags;191	/**192	 * @filp_head: Placed on &drm_file.fbs, protected by &drm_file.fbs_lock.193	 */194	struct list_head filp_head;195	/**196	 * @obj: GEM objects backing the framebuffer, one per plane (optional).197	 *198	 * This is used by the GEM framebuffer helpers, see e.g.199	 * drm_gem_fb_create().200	 */201	struct drm_gem_object *obj[DRM_FORMAT_MAX_PLANES];202};203 204#define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)205 206int drm_framebuffer_init(struct drm_device *dev,207			 struct drm_framebuffer *fb,208			 const struct drm_framebuffer_funcs *funcs);209struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev,210					       struct drm_file *file_priv,211					       uint32_t id);212void drm_framebuffer_remove(struct drm_framebuffer *fb);213void drm_framebuffer_cleanup(struct drm_framebuffer *fb);214void drm_framebuffer_unregister_private(struct drm_framebuffer *fb);215 216/**217 * drm_framebuffer_get - acquire a framebuffer reference218 * @fb: DRM framebuffer219 *220 * This function increments the framebuffer's reference count.221 */222static inline void drm_framebuffer_get(struct drm_framebuffer *fb)223{224	drm_mode_object_get(&fb->base);225}226 227/**228 * drm_framebuffer_put - release a framebuffer reference229 * @fb: DRM framebuffer230 *231 * This function decrements the framebuffer's reference count and frees the232 * framebuffer if the reference count drops to zero.233 */234static inline void drm_framebuffer_put(struct drm_framebuffer *fb)235{236	drm_mode_object_put(&fb->base);237}238 239/**240 * drm_framebuffer_read_refcount - read the framebuffer reference count.241 * @fb: framebuffer242 *243 * This functions returns the framebuffer's reference count.244 */245static inline uint32_t drm_framebuffer_read_refcount(const struct drm_framebuffer *fb)246{247	return kref_read(&fb->base.refcount);248}249 250/**251 * drm_framebuffer_assign - store a reference to the fb252 * @p: location to store framebuffer253 * @fb: new framebuffer (maybe NULL)254 *255 * This functions sets the location to store a reference to the framebuffer,256 * unreferencing the framebuffer that was previously stored in that location.257 */258static inline void drm_framebuffer_assign(struct drm_framebuffer **p,259					  struct drm_framebuffer *fb)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 framebuffers270 * @fb: the loop cursor271 * @dev: the DRM device272 *273 * Iterate over all framebuffers of @dev. User must hold274 * &drm_mode_config.fb_lock.275 */276#define drm_for_each_fb(fb, dev) \277	for (WARN_ON(!mutex_is_locked(&(dev)->mode_config.fb_lock)),		\278	     fb = list_first_entry(&(dev)->mode_config.fb_list,	\279					  struct drm_framebuffer, head);	\280	     &fb->head != (&(dev)->mode_config.fb_list);			\281	     fb = list_next_entry(fb, head))282 283/**284 * struct drm_afbc_framebuffer - a special afbc frame buffer object285 *286 * A derived class of struct drm_framebuffer, dedicated for afbc use cases.287 */288struct drm_afbc_framebuffer {289	/**290	 * @base: base framebuffer structure.291	 */292	struct drm_framebuffer base;293	/**294	 * @block_width: width of a single afbc block295	 */296	u32 block_width;297	/**298	 * @block_height: height of a single afbc block299	 */300	u32 block_height;301	/**302	 * @aligned_width: aligned frame buffer width303	 */304	u32 aligned_width;305	/**306	 * @aligned_height: aligned frame buffer height307	 */308	u32 aligned_height;309	/**310	 * @offset: offset of the first afbc header311	 */312	u32 offset;313	/**314	 * @afbc_size: minimum size of afbc buffer315	 */316	u32 afbc_size;317};318 319#define fb_to_afbc_fb(x) container_of(x, struct drm_afbc_framebuffer, base)320 321#endif322