drm_fb_helper.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. /*
  2. * Copyright (c) 2006-2009 Red Hat Inc.
  3. * Copyright (c) 2006-2008 Intel Corporation
  4. * Copyright (c) 2007 Dave Airlie <[email protected]>
  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 <[email protected]>
  28. * Jesse Barnes <[email protected]>
  29. */
  30. #ifndef DRM_FB_HELPER_H
  31. #define DRM_FB_HELPER_H
  32. struct drm_fb_helper;
  33. #include <drm/drm_client.h>
  34. #include <drm/drm_crtc.h>
  35. #include <drm/drm_device.h>
  36. #include <linux/fb.h>
  37. #include <linux/kgdb.h>
  38. enum mode_set_atomic {
  39. LEAVE_ATOMIC_MODE_SET,
  40. ENTER_ATOMIC_MODE_SET,
  41. };
  42. /**
  43. * struct drm_fb_helper_surface_size - describes fbdev size and scanout surface size
  44. * @fb_width: fbdev width
  45. * @fb_height: fbdev height
  46. * @surface_width: scanout buffer width
  47. * @surface_height: scanout buffer height
  48. * @surface_bpp: scanout buffer bpp
  49. * @surface_depth: scanout buffer depth
  50. *
  51. * Note that the scanout surface width/height may be larger than the fbdev
  52. * width/height. In case of multiple displays, the scanout surface is sized
  53. * according to the largest width/height (so it is large enough for all CRTCs
  54. * to scanout). But the fbdev width/height is sized to the minimum width/
  55. * height of all the displays. This ensures that fbcon fits on the smallest
  56. * of the attached displays. fb_width/fb_height is used by
  57. * drm_fb_helper_fill_info() to fill out the &fb_info.var structure.
  58. */
  59. struct drm_fb_helper_surface_size {
  60. u32 fb_width;
  61. u32 fb_height;
  62. u32 surface_width;
  63. u32 surface_height;
  64. u32 surface_bpp;
  65. u32 surface_depth;
  66. };
  67. /**
  68. * struct drm_fb_helper_funcs - driver callbacks for the fbdev emulation library
  69. *
  70. * Driver callbacks used by the fbdev emulation helper library.
  71. */
  72. struct drm_fb_helper_funcs {
  73. /**
  74. * @fb_probe:
  75. *
  76. * Driver callback to allocate and initialize the fbdev info structure.
  77. * Furthermore it also needs to allocate the DRM framebuffer used to
  78. * back the fbdev.
  79. *
  80. * This callback is mandatory.
  81. *
  82. * RETURNS:
  83. *
  84. * The driver should return 0 on success and a negative error code on
  85. * failure.
  86. */
  87. int (*fb_probe)(struct drm_fb_helper *helper,
  88. struct drm_fb_helper_surface_size *sizes);
  89. };
  90. /**
  91. * struct drm_fb_helper - main structure to emulate fbdev on top of KMS
  92. * @fb: Scanout framebuffer object
  93. * @dev: DRM device
  94. * @funcs: driver callbacks for fb helper
  95. * @fbdev: emulated fbdev device info struct
  96. * @pseudo_palette: fake palette of 16 colors
  97. * @damage_clip: clip rectangle used with deferred_io to accumulate damage to
  98. * the screen buffer
  99. * @damage_lock: spinlock protecting @damage_clip
  100. * @damage_work: worker used to flush the framebuffer
  101. * @resume_work: worker used during resume if the console lock is already taken
  102. *
  103. * This is the main structure used by the fbdev helpers. Drivers supporting
  104. * fbdev emulation should embedded this into their overall driver structure.
  105. * Drivers must also fill out a &struct drm_fb_helper_funcs with a few
  106. * operations.
  107. */
  108. struct drm_fb_helper {
  109. /**
  110. * @client:
  111. *
  112. * DRM client used by the generic fbdev emulation.
  113. */
  114. struct drm_client_dev client;
  115. /**
  116. * @buffer:
  117. *
  118. * Framebuffer used by the generic fbdev emulation.
  119. */
  120. struct drm_client_buffer *buffer;
  121. struct drm_framebuffer *fb;
  122. struct drm_device *dev;
  123. const struct drm_fb_helper_funcs *funcs;
  124. struct fb_info *fbdev;
  125. u32 pseudo_palette[17];
  126. struct drm_clip_rect damage_clip;
  127. spinlock_t damage_lock;
  128. struct work_struct damage_work;
  129. struct work_struct resume_work;
  130. /**
  131. * @lock:
  132. *
  133. * Top-level FBDEV helper lock. This protects all internal data
  134. * structures and lists, such as @connector_info and @crtc_info.
  135. *
  136. * FIXME: fbdev emulation locking is a mess and long term we want to
  137. * protect all helper internal state with this lock as well as reduce
  138. * core KMS locking as much as possible.
  139. */
  140. struct mutex lock;
  141. /**
  142. * @kernel_fb_list:
  143. *
  144. * Entry on the global kernel_fb_helper_list, used for kgdb entry/exit.
  145. */
  146. struct list_head kernel_fb_list;
  147. /**
  148. * @delayed_hotplug:
  149. *
  150. * A hotplug was received while fbdev wasn't in control of the DRM
  151. * device, i.e. another KMS master was active. The output configuration
  152. * needs to be reprobe when fbdev is in control again.
  153. */
  154. bool delayed_hotplug;
  155. /**
  156. * @deferred_setup:
  157. *
  158. * If no outputs are connected (disconnected or unknown) the FB helper
  159. * code will defer setup until at least one of the outputs shows up.
  160. * This field keeps track of the status so that setup can be retried
  161. * at every hotplug event until it succeeds eventually.
  162. *
  163. * Protected by @lock.
  164. */
  165. bool deferred_setup;
  166. /**
  167. * @preferred_bpp:
  168. *
  169. * Temporary storage for the driver's preferred BPP setting passed to
  170. * FB helper initialization. This needs to be tracked so that deferred
  171. * FB helper setup can pass this on.
  172. *
  173. * See also: @deferred_setup
  174. */
  175. int preferred_bpp;
  176. };
  177. static inline struct drm_fb_helper *
  178. drm_fb_helper_from_client(struct drm_client_dev *client)
  179. {
  180. return container_of(client, struct drm_fb_helper, client);
  181. }
  182. /**
  183. * define DRM_FB_HELPER_DEFAULT_OPS - helper define for drm drivers
  184. *
  185. * Helper define to register default implementations of drm_fb_helper
  186. * functions. To be used in struct fb_ops of drm drivers.
  187. */
  188. #define DRM_FB_HELPER_DEFAULT_OPS \
  189. .fb_check_var = drm_fb_helper_check_var, \
  190. .fb_set_par = drm_fb_helper_set_par, \
  191. .fb_setcmap = drm_fb_helper_setcmap, \
  192. .fb_blank = drm_fb_helper_blank, \
  193. .fb_pan_display = drm_fb_helper_pan_display, \
  194. .fb_debug_enter = drm_fb_helper_debug_enter, \
  195. .fb_debug_leave = drm_fb_helper_debug_leave, \
  196. .fb_ioctl = drm_fb_helper_ioctl
  197. #ifdef CONFIG_DRM_FBDEV_EMULATION
  198. void drm_fb_helper_prepare(struct drm_device *dev, struct drm_fb_helper *helper,
  199. const struct drm_fb_helper_funcs *funcs);
  200. int drm_fb_helper_init(struct drm_device *dev, struct drm_fb_helper *helper);
  201. void drm_fb_helper_fini(struct drm_fb_helper *helper);
  202. int drm_fb_helper_blank(int blank, struct fb_info *info);
  203. int drm_fb_helper_pan_display(struct fb_var_screeninfo *var,
  204. struct fb_info *info);
  205. int drm_fb_helper_set_par(struct fb_info *info);
  206. int drm_fb_helper_check_var(struct fb_var_screeninfo *var,
  207. struct fb_info *info);
  208. int drm_fb_helper_restore_fbdev_mode_unlocked(struct drm_fb_helper *fb_helper);
  209. struct fb_info *drm_fb_helper_alloc_fbi(struct drm_fb_helper *fb_helper);
  210. void drm_fb_helper_unregister_fbi(struct drm_fb_helper *fb_helper);
  211. void drm_fb_helper_fill_info(struct fb_info *info,
  212. struct drm_fb_helper *fb_helper,
  213. struct drm_fb_helper_surface_size *sizes);
  214. void drm_fb_helper_deferred_io(struct fb_info *info, struct list_head *pagereflist);
  215. ssize_t drm_fb_helper_sys_read(struct fb_info *info, char __user *buf,
  216. size_t count, loff_t *ppos);
  217. ssize_t drm_fb_helper_sys_write(struct fb_info *info, const char __user *buf,
  218. size_t count, loff_t *ppos);
  219. void drm_fb_helper_sys_fillrect(struct fb_info *info,
  220. const struct fb_fillrect *rect);
  221. void drm_fb_helper_sys_copyarea(struct fb_info *info,
  222. const struct fb_copyarea *area);
  223. void drm_fb_helper_sys_imageblit(struct fb_info *info,
  224. const struct fb_image *image);
  225. void drm_fb_helper_cfb_fillrect(struct fb_info *info,
  226. const struct fb_fillrect *rect);
  227. void drm_fb_helper_cfb_copyarea(struct fb_info *info,
  228. const struct fb_copyarea *area);
  229. void drm_fb_helper_cfb_imageblit(struct fb_info *info,
  230. const struct fb_image *image);
  231. void drm_fb_helper_set_suspend(struct drm_fb_helper *fb_helper, bool suspend);
  232. void drm_fb_helper_set_suspend_unlocked(struct drm_fb_helper *fb_helper,
  233. bool suspend);
  234. int drm_fb_helper_setcmap(struct fb_cmap *cmap, struct fb_info *info);
  235. int drm_fb_helper_ioctl(struct fb_info *info, unsigned int cmd,
  236. unsigned long arg);
  237. int drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper);
  238. int drm_fb_helper_initial_config(struct drm_fb_helper *fb_helper, int bpp_sel);
  239. int drm_fb_helper_debug_enter(struct fb_info *info);
  240. int drm_fb_helper_debug_leave(struct fb_info *info);
  241. void drm_fb_helper_lastclose(struct drm_device *dev);
  242. void drm_fb_helper_output_poll_changed(struct drm_device *dev);
  243. void drm_fbdev_generic_setup(struct drm_device *dev,
  244. unsigned int preferred_bpp);
  245. #else
  246. static inline void drm_fb_helper_prepare(struct drm_device *dev,
  247. struct drm_fb_helper *helper,
  248. const struct drm_fb_helper_funcs *funcs)
  249. {
  250. }
  251. static inline int drm_fb_helper_init(struct drm_device *dev,
  252. struct drm_fb_helper *helper)
  253. {
  254. /* So drivers can use it to free the struct */
  255. helper->dev = dev;
  256. dev->fb_helper = helper;
  257. return 0;
  258. }
  259. static inline void drm_fb_helper_fini(struct drm_fb_helper *helper)
  260. {
  261. if (helper && helper->dev)
  262. helper->dev->fb_helper = NULL;
  263. }
  264. static inline int drm_fb_helper_blank(int blank, struct fb_info *info)
  265. {
  266. return 0;
  267. }
  268. static inline int drm_fb_helper_pan_display(struct fb_var_screeninfo *var,
  269. struct fb_info *info)
  270. {
  271. return 0;
  272. }
  273. static inline int drm_fb_helper_set_par(struct fb_info *info)
  274. {
  275. return 0;
  276. }
  277. static inline int drm_fb_helper_check_var(struct fb_var_screeninfo *var,
  278. struct fb_info *info)
  279. {
  280. return 0;
  281. }
  282. static inline int
  283. drm_fb_helper_restore_fbdev_mode_unlocked(struct drm_fb_helper *fb_helper)
  284. {
  285. return 0;
  286. }
  287. static inline struct fb_info *
  288. drm_fb_helper_alloc_fbi(struct drm_fb_helper *fb_helper)
  289. {
  290. return NULL;
  291. }
  292. static inline void drm_fb_helper_unregister_fbi(struct drm_fb_helper *fb_helper)
  293. {
  294. }
  295. static inline void
  296. drm_fb_helper_fill_info(struct fb_info *info,
  297. struct drm_fb_helper *fb_helper,
  298. struct drm_fb_helper_surface_size *sizes)
  299. {
  300. }
  301. static inline int drm_fb_helper_setcmap(struct fb_cmap *cmap,
  302. struct fb_info *info)
  303. {
  304. return 0;
  305. }
  306. static inline int drm_fb_helper_ioctl(struct fb_info *info, unsigned int cmd,
  307. unsigned long arg)
  308. {
  309. return 0;
  310. }
  311. static inline void drm_fb_helper_deferred_io(struct fb_info *info,
  312. struct list_head *pagelist)
  313. {
  314. }
  315. static inline int drm_fb_helper_defio_init(struct drm_fb_helper *fb_helper)
  316. {
  317. return -ENODEV;
  318. }
  319. static inline ssize_t drm_fb_helper_sys_read(struct fb_info *info,
  320. char __user *buf, size_t count,
  321. loff_t *ppos)
  322. {
  323. return -ENODEV;
  324. }
  325. static inline ssize_t drm_fb_helper_sys_write(struct fb_info *info,
  326. const char __user *buf,
  327. size_t count, loff_t *ppos)
  328. {
  329. return -ENODEV;
  330. }
  331. static inline void drm_fb_helper_sys_fillrect(struct fb_info *info,
  332. const struct fb_fillrect *rect)
  333. {
  334. }
  335. static inline void drm_fb_helper_sys_copyarea(struct fb_info *info,
  336. const struct fb_copyarea *area)
  337. {
  338. }
  339. static inline void drm_fb_helper_sys_imageblit(struct fb_info *info,
  340. const struct fb_image *image)
  341. {
  342. }
  343. static inline void drm_fb_helper_cfb_fillrect(struct fb_info *info,
  344. const struct fb_fillrect *rect)
  345. {
  346. }
  347. static inline void drm_fb_helper_cfb_copyarea(struct fb_info *info,
  348. const struct fb_copyarea *area)
  349. {
  350. }
  351. static inline void drm_fb_helper_cfb_imageblit(struct fb_info *info,
  352. const struct fb_image *image)
  353. {
  354. }
  355. static inline void drm_fb_helper_set_suspend(struct drm_fb_helper *fb_helper,
  356. bool suspend)
  357. {
  358. }
  359. static inline void
  360. drm_fb_helper_set_suspend_unlocked(struct drm_fb_helper *fb_helper, bool suspend)
  361. {
  362. }
  363. static inline int drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper)
  364. {
  365. return 0;
  366. }
  367. static inline int drm_fb_helper_initial_config(struct drm_fb_helper *fb_helper,
  368. int bpp_sel)
  369. {
  370. return 0;
  371. }
  372. static inline int drm_fb_helper_debug_enter(struct fb_info *info)
  373. {
  374. return 0;
  375. }
  376. static inline int drm_fb_helper_debug_leave(struct fb_info *info)
  377. {
  378. return 0;
  379. }
  380. static inline void drm_fb_helper_lastclose(struct drm_device *dev)
  381. {
  382. }
  383. static inline void drm_fb_helper_output_poll_changed(struct drm_device *dev)
  384. {
  385. }
  386. static inline void
  387. drm_fbdev_generic_setup(struct drm_device *dev, unsigned int preferred_bpp)
  388. {
  389. }
  390. #endif
  391. #endif