1 /* $NetBSD: drm_fb_helper.h,v 1.8 2018/08/27 13:36:14 riastradh Exp $ */ 2 3 /* 4 * Copyright (c) 2006-2009 Red Hat Inc. 5 * Copyright (c) 2006-2008 Intel Corporation 6 * Copyright (c) 2007 Dave Airlie <airlied@linux.ie> 7 * 8 * DRM framebuffer helper functions 9 * 10 * Permission to use, copy, modify, distribute, and sell this software and its 11 * documentation for any purpose is hereby granted without fee, provided that 12 * the above copyright notice appear in all copies and that both that copyright 13 * notice and this permission notice appear in supporting documentation, and 14 * that the name of the copyright holders not be used in advertising or 15 * publicity pertaining to distribution of the software without specific, 16 * written prior permission. The copyright holders make no representations 17 * about the suitability of this software for any purpose. It is provided "as 18 * is" without express or implied warranty. 19 * 20 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 21 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 22 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR 23 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 24 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 25 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 26 * OF THIS SOFTWARE. 27 * 28 * Authors: 29 * Dave Airlie <airlied@linux.ie> 30 * Jesse Barnes <jesse.barnes@intel.com> 31 */ 32 #ifndef DRM_FB_HELPER_H 33 #define DRM_FB_HELPER_H 34 35 struct drm_fb_helper; 36 37 #include <linux/kgdb.h> 38 39 #ifdef __NetBSD__ 40 #include <sys/device_if.h> 41 #endif 42 43 struct drm_fb_offset { 44 int x, y; 45 }; 46 47 struct drm_fb_helper_crtc { 48 struct drm_mode_set mode_set; 49 struct drm_display_mode *desired_mode; 50 int x, y; 51 }; 52 53 /** 54 * struct drm_fb_helper_surface_size - describes fbdev size and scanout surface size 55 * @fb_width: fbdev width 56 * @fb_height: fbdev height 57 * @surface_width: scanout buffer width 58 * @surface_height: scanout buffer height 59 * @surface_bpp: scanout buffer bpp 60 * @surface_depth: scanout buffer depth 61 * 62 * Note that the scanout surface width/height may be larger than the fbdev 63 * width/height. In case of multiple displays, the scanout surface is sized 64 * according to the largest width/height (so it is large enough for all CRTCs 65 * to scanout). But the fbdev width/height is sized to the minimum width/ 66 * height of all the displays. This ensures that fbcon fits on the smallest 67 * of the attached displays. 68 * 69 * So what is passed to drm_fb_helper_fill_var() should be fb_width/fb_height, 70 * rather than the surface size. 71 */ 72 struct drm_fb_helper_surface_size { 73 u32 fb_width; 74 u32 fb_height; 75 u32 surface_width; 76 u32 surface_height; 77 u32 surface_bpp; 78 u32 surface_depth; 79 }; 80 81 /** 82 * struct drm_fb_helper_funcs - driver callbacks for the fbdev emulation library 83 * @gamma_set: Set the given gamma lut register on the given crtc. 84 * @gamma_get: Read the given gamma lut register on the given crtc, used to 85 * save the current lut when force-restoring the fbdev for e.g. 86 * kdbg. 87 * @fb_probe: Driver callback to allocate and initialize the fbdev info 88 * structure. Furthermore it also needs to allocate the drm 89 * framebuffer used to back the fbdev. 90 * @initial_config: Setup an initial fbdev display configuration 91 * 92 * Driver callbacks used by the fbdev emulation helper library. 93 */ 94 struct drm_fb_helper_funcs { 95 void (*gamma_set)(struct drm_crtc *crtc, u16 red, u16 green, 96 u16 blue, int regno); 97 void (*gamma_get)(struct drm_crtc *crtc, u16 *red, u16 *green, 98 u16 *blue, int regno); 99 100 int (*fb_probe)(struct drm_fb_helper *helper, 101 struct drm_fb_helper_surface_size *sizes); 102 bool (*initial_config)(struct drm_fb_helper *fb_helper, 103 struct drm_fb_helper_crtc **crtcs, 104 struct drm_display_mode **modes, 105 struct drm_fb_offset *offsets, 106 bool *enabled, int width, int height); 107 }; 108 109 struct drm_fb_helper_connector { 110 struct drm_connector *connector; 111 }; 112 113 /** 114 * struct drm_fb_helper - helper to emulate fbdev on top of kms 115 * @fb: Scanout framebuffer object 116 * @dev: DRM device 117 * @crtc_count: number of possible CRTCs 118 * @crtc_info: per-CRTC helper state (mode, x/y offset, etc) 119 * @connector_count: number of connected connectors 120 * @connector_info_alloc_count: size of connector_info 121 * @funcs: driver callbacks for fb helper 122 * @fbdev: emulated fbdev device info struct 123 * @pseudo_palette: fake palette of 16 colors 124 * @kernel_fb_list: list_head in kernel_fb_helper_list 125 * @delayed_hotplug: was there a hotplug while kms master active? 126 */ 127 struct drm_fb_helper { 128 struct drm_framebuffer *fb; 129 struct drm_device *dev; 130 int crtc_count; 131 struct drm_fb_helper_crtc *crtc_info; 132 int connector_count; 133 int connector_info_alloc_count; 134 struct drm_fb_helper_connector **connector_info; 135 const struct drm_fb_helper_funcs *funcs; 136 #ifdef __NetBSD__ /* XXX fb info */ 137 device_t fbdev; 138 #else 139 struct fb_info *fbdev; 140 #endif 141 u32 pseudo_palette[17]; 142 struct list_head kernel_fb_list; 143 144 /* we got a hotplug but fbdev wasn't running the console 145 delay until next set_par */ 146 bool delayed_hotplug; 147 148 /** 149 * @atomic: 150 * 151 * Use atomic updates for restore_fbdev_mode(), etc. This defaults to 152 * true if driver has DRIVER_ATOMIC feature flag, but drivers can 153 * override it to true after drm_fb_helper_init() if they support atomic 154 * modeset but do not yet advertise DRIVER_ATOMIC (note that fb-helper 155 * does not require ASYNC commits). 156 */ 157 bool atomic; 158 }; 159 160 #ifdef CONFIG_DRM_FBDEV_EMULATION 161 void drm_fb_helper_prepare(struct drm_device *dev, struct drm_fb_helper *helper, 162 const struct drm_fb_helper_funcs *funcs); 163 int drm_fb_helper_init(struct drm_device *dev, 164 struct drm_fb_helper *helper, int crtc_count, 165 int max_conn); 166 void drm_fb_helper_fini(struct drm_fb_helper *helper); 167 #ifndef __NetBSD__ /* XXX fb info */ 168 int drm_fb_helper_blank(int blank, struct fb_info *info); 169 int drm_fb_helper_pan_display(struct fb_var_screeninfo *var, 170 struct fb_info *info); 171 int drm_fb_helper_set_par(struct fb_info *info); 172 int drm_fb_helper_check_var(struct fb_var_screeninfo *var, 173 struct fb_info *info); 174 #endif 175 176 int drm_fb_helper_restore_fbdev_mode_unlocked(struct drm_fb_helper *fb_helper); 177 178 #ifndef __NetBSD__ /* XXX fb info */ 179 struct fb_info *drm_fb_helper_alloc_fbi(struct drm_fb_helper *fb_helper); 180 void drm_fb_helper_unregister_fbi(struct drm_fb_helper *fb_helper); 181 void drm_fb_helper_release_fbi(struct drm_fb_helper *fb_helper); 182 void drm_fb_helper_fill_var(struct fb_info *info, struct drm_fb_helper *fb_helper, 183 uint32_t fb_width, uint32_t fb_height); 184 void drm_fb_helper_fill_fix(struct fb_info *info, uint32_t pitch, 185 uint32_t depth); 186 187 void drm_fb_helper_unlink_fbi(struct drm_fb_helper *fb_helper); 188 189 ssize_t drm_fb_helper_sys_read(struct fb_info *info, char __user *buf, 190 size_t count, loff_t *ppos); 191 ssize_t drm_fb_helper_sys_write(struct fb_info *info, const char __user *buf, 192 size_t count, loff_t *ppos); 193 194 void drm_fb_helper_sys_fillrect(struct fb_info *info, 195 const struct fb_fillrect *rect); 196 void drm_fb_helper_sys_copyarea(struct fb_info *info, 197 const struct fb_copyarea *area); 198 void drm_fb_helper_sys_imageblit(struct fb_info *info, 199 const struct fb_image *image); 200 201 void drm_fb_helper_cfb_fillrect(struct fb_info *info, 202 const struct fb_fillrect *rect); 203 void drm_fb_helper_cfb_copyarea(struct fb_info *info, 204 const struct fb_copyarea *area); 205 void drm_fb_helper_cfb_imageblit(struct fb_info *info, 206 const struct fb_image *image); 207 #endif 208 209 void drm_fb_helper_set_suspend(struct drm_fb_helper *fb_helper, int state); 210 211 #ifndef __NetBSD__ /* XXX fb cmap */ 212 int drm_fb_helper_setcmap(struct fb_cmap *cmap, struct fb_info *info); 213 #endif 214 215 int drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper); 216 int drm_fb_helper_initial_config(struct drm_fb_helper *fb_helper, int bpp_sel); 217 int drm_fb_helper_single_add_all_connectors(struct drm_fb_helper *fb_helper); 218 #ifndef __NetBSD__ /* XXX fb info */ 219 int drm_fb_helper_debug_enter(struct fb_info *info); 220 int drm_fb_helper_debug_leave(struct fb_info *info); 221 #endif 222 int drm_fb_helper_debug_enter_fb(struct drm_fb_helper *fb_helper); 223 int drm_fb_helper_debug_leave_fb(struct drm_fb_helper *fb_helper); 224 struct drm_display_mode * 225 drm_has_preferred_mode(struct drm_fb_helper_connector *fb_connector, 226 int width, int height); 227 struct drm_display_mode * 228 drm_pick_cmdline_mode(struct drm_fb_helper_connector *fb_helper_conn, 229 int width, int height); 230 231 int drm_fb_helper_add_one_connector(struct drm_fb_helper *fb_helper, struct drm_connector *connector); 232 int drm_fb_helper_remove_one_connector(struct drm_fb_helper *fb_helper, 233 struct drm_connector *connector); 234 #else 235 static inline void drm_fb_helper_prepare(struct drm_device *dev, 236 struct drm_fb_helper *helper, 237 const struct drm_fb_helper_funcs *funcs) 238 { 239 } 240 241 static inline int drm_fb_helper_init(struct drm_device *dev, 242 struct drm_fb_helper *helper, int crtc_count, 243 int max_conn) 244 { 245 return 0; 246 } 247 248 static inline void drm_fb_helper_fini(struct drm_fb_helper *helper) 249 { 250 } 251 252 static inline int drm_fb_helper_blank(int blank, struct fb_info *info) 253 { 254 return 0; 255 } 256 257 static inline int drm_fb_helper_pan_display(struct fb_var_screeninfo *var, 258 struct fb_info *info) 259 { 260 return 0; 261 } 262 263 static inline int drm_fb_helper_set_par(struct fb_info *info) 264 { 265 return 0; 266 } 267 268 static inline int drm_fb_helper_check_var(struct fb_var_screeninfo *var, 269 struct fb_info *info) 270 { 271 return 0; 272 } 273 274 static inline int 275 drm_fb_helper_restore_fbdev_mode_unlocked(struct drm_fb_helper *fb_helper) 276 { 277 return 0; 278 } 279 280 static inline struct fb_info * 281 drm_fb_helper_alloc_fbi(struct drm_fb_helper *fb_helper) 282 { 283 return NULL; 284 } 285 286 static inline void drm_fb_helper_unregister_fbi(struct drm_fb_helper *fb_helper) 287 { 288 } 289 static inline void drm_fb_helper_release_fbi(struct drm_fb_helper *fb_helper) 290 { 291 } 292 293 static inline void drm_fb_helper_fill_var(struct fb_info *info, 294 struct drm_fb_helper *fb_helper, 295 uint32_t fb_width, uint32_t fb_height) 296 { 297 } 298 299 static inline void drm_fb_helper_fill_fix(struct fb_info *info, uint32_t pitch, 300 uint32_t depth) 301 { 302 } 303 304 static inline int drm_fb_helper_setcmap(struct fb_cmap *cmap, 305 struct fb_info *info) 306 { 307 return 0; 308 } 309 310 static inline void drm_fb_helper_unlink_fbi(struct drm_fb_helper *fb_helper) 311 { 312 } 313 314 static inline ssize_t drm_fb_helper_sys_read(struct fb_info *info, 315 char __user *buf, size_t count, 316 loff_t *ppos) 317 { 318 return -ENODEV; 319 } 320 321 static inline ssize_t drm_fb_helper_sys_write(struct fb_info *info, 322 const char __user *buf, 323 size_t count, loff_t *ppos) 324 { 325 return -ENODEV; 326 } 327 328 static inline void drm_fb_helper_sys_fillrect(struct fb_info *info, 329 const struct fb_fillrect *rect) 330 { 331 } 332 333 static inline void drm_fb_helper_sys_copyarea(struct fb_info *info, 334 const struct fb_copyarea *area) 335 { 336 } 337 338 static inline void drm_fb_helper_sys_imageblit(struct fb_info *info, 339 const struct fb_image *image) 340 { 341 } 342 343 static inline void drm_fb_helper_cfb_fillrect(struct fb_info *info, 344 const struct fb_fillrect *rect) 345 { 346 } 347 348 static inline void drm_fb_helper_cfb_copyarea(struct fb_info *info, 349 const struct fb_copyarea *area) 350 { 351 } 352 353 static inline void drm_fb_helper_cfb_imageblit(struct fb_info *info, 354 const struct fb_image *image) 355 { 356 } 357 358 static inline void drm_fb_helper_set_suspend(struct drm_fb_helper *fb_helper, 359 int state) 360 { 361 } 362 363 static inline int drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper) 364 { 365 return 0; 366 } 367 368 static inline int drm_fb_helper_initial_config(struct drm_fb_helper *fb_helper, 369 int bpp_sel) 370 { 371 return 0; 372 } 373 374 static inline int 375 drm_fb_helper_single_add_all_connectors(struct drm_fb_helper *fb_helper) 376 { 377 return 0; 378 } 379 380 static inline int drm_fb_helper_debug_enter(struct fb_info *info) 381 { 382 return 0; 383 } 384 385 static inline int drm_fb_helper_debug_leave(struct fb_info *info) 386 { 387 return 0; 388 } 389 390 static inline struct drm_display_mode * 391 drm_has_preferred_mode(struct drm_fb_helper_connector *fb_connector, 392 int width, int height) 393 { 394 return NULL; 395 } 396 397 static inline struct drm_display_mode * 398 drm_pick_cmdline_mode(struct drm_fb_helper_connector *fb_helper_conn, 399 int width, int height) 400 { 401 return NULL; 402 } 403 404 static inline int 405 drm_fb_helper_add_one_connector(struct drm_fb_helper *fb_helper, 406 struct drm_connector *connector) 407 { 408 return 0; 409 } 410 411 static inline int 412 drm_fb_helper_remove_one_connector(struct drm_fb_helper *fb_helper, 413 struct drm_connector *connector) 414 { 415 return 0; 416 } 417 #endif 418 #endif 419