drm_fb_helper.h 12 KB

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