![]() |
|
|||
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_ENCODER_H__ 0024 #define __DRM_ENCODER_H__ 0025 0026 #include <linux/list.h> 0027 #include <linux/ctype.h> 0028 #include <drm/drm_crtc.h> 0029 #include <drm/drm_mode.h> 0030 #include <drm/drm_mode_object.h> 0031 #include <drm/drm_util.h> 0032 0033 struct drm_encoder; 0034 0035 /** 0036 * struct drm_encoder_funcs - encoder controls 0037 * 0038 * Encoders sit between CRTCs and connectors. 0039 */ 0040 struct drm_encoder_funcs { 0041 /** 0042 * @reset: 0043 * 0044 * Reset encoder hardware and software state to off. This function isn't 0045 * called by the core directly, only through drm_mode_config_reset(). 0046 * It's not a helper hook only for historical reasons. 0047 */ 0048 void (*reset)(struct drm_encoder *encoder); 0049 0050 /** 0051 * @destroy: 0052 * 0053 * Clean up encoder resources. This is only called at driver unload time 0054 * through drm_mode_config_cleanup() since an encoder cannot be 0055 * hotplugged in DRM. 0056 */ 0057 void (*destroy)(struct drm_encoder *encoder); 0058 0059 /** 0060 * @late_register: 0061 * 0062 * This optional hook can be used to register additional userspace 0063 * interfaces attached to the encoder like debugfs interfaces. 0064 * It is called late in the driver load sequence from drm_dev_register(). 0065 * Everything added from this callback should be unregistered in 0066 * the early_unregister callback. 0067 * 0068 * Returns: 0069 * 0070 * 0 on success, or a negative error code on failure. 0071 */ 0072 int (*late_register)(struct drm_encoder *encoder); 0073 0074 /** 0075 * @early_unregister: 0076 * 0077 * This optional hook should be used to unregister the additional 0078 * userspace interfaces attached to the encoder from 0079 * @late_register. It is called from drm_dev_unregister(), 0080 * early in the driver unload sequence to disable userspace access 0081 * before data structures are torndown. 0082 */ 0083 void (*early_unregister)(struct drm_encoder *encoder); 0084 }; 0085 0086 /** 0087 * struct drm_encoder - central DRM encoder structure 0088 * @dev: parent DRM device 0089 * @head: list management 0090 * @base: base KMS object 0091 * @name: human readable name, can be overwritten by the driver 0092 * @funcs: control functions, can be NULL for simple managed encoders 0093 * @helper_private: mid-layer private data 0094 * 0095 * CRTCs drive pixels to encoders, which convert them into signals 0096 * appropriate for a given connector or set of connectors. 0097 */ 0098 struct drm_encoder { 0099 struct drm_device *dev; 0100 struct list_head head; 0101 0102 struct drm_mode_object base; 0103 char *name; 0104 /** 0105 * @encoder_type: 0106 * 0107 * One of the DRM_MODE_ENCODER_<foo> types in drm_mode.h. The following 0108 * encoder types are defined thus far: 0109 * 0110 * - DRM_MODE_ENCODER_DAC for VGA and analog on DVI-I/DVI-A. 0111 * 0112 * - DRM_MODE_ENCODER_TMDS for DVI, HDMI and (embedded) DisplayPort. 0113 * 0114 * - DRM_MODE_ENCODER_LVDS for display panels, or in general any panel 0115 * with a proprietary parallel connector. 0116 * 0117 * - DRM_MODE_ENCODER_TVDAC for TV output (Composite, S-Video, 0118 * Component, SCART). 0119 * 0120 * - DRM_MODE_ENCODER_VIRTUAL for virtual machine displays 0121 * 0122 * - DRM_MODE_ENCODER_DSI for panels connected using the DSI serial bus. 0123 * 0124 * - DRM_MODE_ENCODER_DPI for panels connected using the DPI parallel 0125 * bus. 0126 * 0127 * - DRM_MODE_ENCODER_DPMST for special fake encoders used to allow 0128 * mutliple DP MST streams to share one physical encoder. 0129 */ 0130 int encoder_type; 0131 0132 /** 0133 * @index: Position inside the mode_config.list, can be used as an array 0134 * index. It is invariant over the lifetime of the encoder. 0135 */ 0136 unsigned index; 0137 0138 /** 0139 * @possible_crtcs: Bitmask of potential CRTC bindings, using 0140 * drm_crtc_index() as the index into the bitfield. The driver must set 0141 * the bits for all &drm_crtc objects this encoder can be connected to 0142 * before calling drm_dev_register(). 0143 * 0144 * You will get a WARN if you get this wrong in the driver. 0145 * 0146 * Note that since CRTC objects can't be hotplugged the assigned indices 0147 * are stable and hence known before registering all objects. 0148 */ 0149 uint32_t possible_crtcs; 0150 0151 /** 0152 * @possible_clones: Bitmask of potential sibling encoders for cloning, 0153 * using drm_encoder_index() as the index into the bitfield. The driver 0154 * must set the bits for all &drm_encoder objects which can clone a 0155 * &drm_crtc together with this encoder before calling 0156 * drm_dev_register(). Drivers should set the bit representing the 0157 * encoder itself, too. Cloning bits should be set such that when two 0158 * encoders can be used in a cloned configuration, they both should have 0159 * each another bits set. 0160 * 0161 * As an exception to the above rule if the driver doesn't implement 0162 * any cloning it can leave @possible_clones set to 0. The core will 0163 * automagically fix this up by setting the bit for the encoder itself. 0164 * 0165 * You will get a WARN if you get this wrong in the driver. 0166 * 0167 * Note that since encoder objects can't be hotplugged the assigned indices 0168 * are stable and hence known before registering all objects. 0169 */ 0170 uint32_t possible_clones; 0171 0172 /** 0173 * @crtc: Currently bound CRTC, only really meaningful for non-atomic 0174 * drivers. Atomic drivers should instead check 0175 * &drm_connector_state.crtc. 0176 */ 0177 struct drm_crtc *crtc; 0178 0179 /** 0180 * @bridge_chain: Bridges attached to this encoder. Drivers shall not 0181 * access this field directly. 0182 */ 0183 struct list_head bridge_chain; 0184 0185 const struct drm_encoder_funcs *funcs; 0186 const struct drm_encoder_helper_funcs *helper_private; 0187 }; 0188 0189 #define obj_to_encoder(x) container_of(x, struct drm_encoder, base) 0190 0191 __printf(5, 6) 0192 int drm_encoder_init(struct drm_device *dev, 0193 struct drm_encoder *encoder, 0194 const struct drm_encoder_funcs *funcs, 0195 int encoder_type, const char *name, ...); 0196 0197 __printf(6, 7) 0198 void *__drmm_encoder_alloc(struct drm_device *dev, 0199 size_t size, size_t offset, 0200 const struct drm_encoder_funcs *funcs, 0201 int encoder_type, 0202 const char *name, ...); 0203 0204 /** 0205 * drmm_encoder_alloc - Allocate and initialize an encoder 0206 * @dev: drm device 0207 * @type: the type of the struct which contains struct &drm_encoder 0208 * @member: the name of the &drm_encoder within @type 0209 * @funcs: callbacks for this encoder (optional) 0210 * @encoder_type: user visible type of the encoder 0211 * @name: printf style format string for the encoder name, or NULL for default name 0212 * 0213 * Allocates and initializes an encoder. Encoder should be subclassed as part of 0214 * driver encoder objects. Cleanup is automatically handled through registering 0215 * drm_encoder_cleanup() with drmm_add_action(). 0216 * 0217 * The @drm_encoder_funcs.destroy hook must be NULL. 0218 * 0219 * Returns: 0220 * Pointer to new encoder, or ERR_PTR on failure. 0221 */ 0222 #define drmm_encoder_alloc(dev, type, member, funcs, encoder_type, name, ...) \ 0223 ((type *)__drmm_encoder_alloc(dev, sizeof(type), \ 0224 offsetof(type, member), funcs, \ 0225 encoder_type, name, ##__VA_ARGS__)) 0226 0227 /** 0228 * drmm_plain_encoder_alloc - Allocate and initialize an encoder 0229 * @dev: drm device 0230 * @funcs: callbacks for this encoder (optional) 0231 * @encoder_type: user visible type of the encoder 0232 * @name: printf style format string for the encoder name, or NULL for default name 0233 * 0234 * This is a simplified version of drmm_encoder_alloc(), which only allocates 0235 * and returns a struct drm_encoder instance, with no subclassing. 0236 * 0237 * Returns: 0238 * Pointer to the new drm_encoder struct, or ERR_PTR on failure. 0239 */ 0240 #define drmm_plain_encoder_alloc(dev, funcs, encoder_type, name, ...) \ 0241 ((struct drm_encoder *) \ 0242 __drmm_encoder_alloc(dev, sizeof(struct drm_encoder), \ 0243 0, funcs, encoder_type, name, ##__VA_ARGS__)) 0244 0245 /** 0246 * drm_encoder_index - find the index of a registered encoder 0247 * @encoder: encoder to find index for 0248 * 0249 * Given a registered encoder, return the index of that encoder within a DRM 0250 * device's list of encoders. 0251 */ 0252 static inline unsigned int drm_encoder_index(const struct drm_encoder *encoder) 0253 { 0254 return encoder->index; 0255 } 0256 0257 /** 0258 * drm_encoder_mask - find the mask of a registered encoder 0259 * @encoder: encoder to find mask for 0260 * 0261 * Given a registered encoder, return the mask bit of that encoder for an 0262 * encoder's possible_clones field. 0263 */ 0264 static inline u32 drm_encoder_mask(const struct drm_encoder *encoder) 0265 { 0266 return 1 << drm_encoder_index(encoder); 0267 } 0268 0269 /** 0270 * drm_encoder_crtc_ok - can a given crtc drive a given encoder? 0271 * @encoder: encoder to test 0272 * @crtc: crtc to test 0273 * 0274 * Returns false if @encoder can't be driven by @crtc, true otherwise. 0275 */ 0276 static inline bool drm_encoder_crtc_ok(struct drm_encoder *encoder, 0277 struct drm_crtc *crtc) 0278 { 0279 return !!(encoder->possible_crtcs & drm_crtc_mask(crtc)); 0280 } 0281 0282 /** 0283 * drm_encoder_find - find a &drm_encoder 0284 * @dev: DRM device 0285 * @file_priv: drm file to check for lease against. 0286 * @id: encoder id 0287 * 0288 * Returns the encoder with @id, NULL if it doesn't exist. Simple wrapper around 0289 * drm_mode_object_find(). 0290 */ 0291 static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev, 0292 struct drm_file *file_priv, 0293 uint32_t id) 0294 { 0295 struct drm_mode_object *mo; 0296 0297 mo = drm_mode_object_find(dev, file_priv, id, DRM_MODE_OBJECT_ENCODER); 0298 0299 return mo ? obj_to_encoder(mo) : NULL; 0300 } 0301 0302 void drm_encoder_cleanup(struct drm_encoder *encoder); 0303 0304 /** 0305 * drm_for_each_encoder_mask - iterate over encoders specified by bitmask 0306 * @encoder: the loop cursor 0307 * @dev: the DRM device 0308 * @encoder_mask: bitmask of encoder indices 0309 * 0310 * Iterate over all encoders specified by bitmask. 0311 */ 0312 #define drm_for_each_encoder_mask(encoder, dev, encoder_mask) \ 0313 list_for_each_entry((encoder), &(dev)->mode_config.encoder_list, head) \ 0314 for_each_if ((encoder_mask) & drm_encoder_mask(encoder)) 0315 0316 /** 0317 * drm_for_each_encoder - iterate over all encoders 0318 * @encoder: the loop cursor 0319 * @dev: the DRM device 0320 * 0321 * Iterate over all encoders of @dev. 0322 */ 0323 #define drm_for_each_encoder(encoder, dev) \ 0324 list_for_each_entry(encoder, &(dev)->mode_config.encoder_list, head) 0325 0326 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |