drm_fb_helper.h 14 KB

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