0003-Add-video-damage-tracking.patch 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295
  1. From 796a8816a663d2b63dc9e6aa9a684b9ace15d557 Mon Sep 17 00:00:00 2001
  2. From: Alexander Graf <agraf@csgraf.de>
  3. Date: Fri, 10 Jun 2022 00:59:15 +0200
  4. Subject: [PATCH 1/7] dm: video: Add damage tracking API
  5. We are going to introduce image damage tracking to fasten up screen
  6. refresh on large displays. This patch adds damage tracking for up to
  7. one rectangle of the screen which is typically enough to hold blt or
  8. text print updates. Callers into this API and a reduced dcache flush
  9. code path will follow in later patches.
  10. Signed-off-by: Alexander Graf <agraf@csgraf.de>
  11. Reported-by: Da Xue <da@libre.computer>
  12. Tested-by: Matthias Brugger <mbrugger@suse.com>
  13. Link: https://lore.kernel.org/r/20220609225921.62462-2-agraf@csgraf.de
  14. ---
  15. drivers/video/Kconfig | 15 +++++++++++++
  16. drivers/video/video-uclass.c | 41 ++++++++++++++++++++++++++++++++++++
  17. include/video.h | 29 +++++++++++++++++++++++--
  18. 3 files changed, 83 insertions(+), 2 deletions(-)
  19. diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
  20. index 4ecc158c4605..21fca141a087 100644
  21. --- a/drivers/video/Kconfig
  22. +++ b/drivers/video/Kconfig
  23. @@ -64,6 +64,21 @@ config VIDEO_COPY
  24. To use this, your video driver must set @copy_base in
  25. struct video_uc_plat.
  26. +config VIDEO_DAMAGE
  27. + bool "Enable damage tracking of frame buffer regions"
  28. + depends on DM_VIDEO
  29. + default y if ARM && !SYS_DCACHE_OFF
  30. + help
  31. + On some machines (most ARM), the display frame buffer resides in
  32. + RAM. To make the display controller pick up screen updates, we
  33. + have to flush frame buffer contents from CPU caches into RAM which
  34. + can be a slow operation.
  35. +
  36. + This patch adds damage tracking to collect information about regions
  37. + that received updates. When we want to sync, we then only flush
  38. + regions of the frame buffer that were modified before, speeding up
  39. + screen refreshes significantly.
  40. +
  41. config BACKLIGHT_PWM
  42. bool "Generic PWM based Backlight Driver"
  43. depends on BACKLIGHT && DM_PWM
  44. diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c
  45. index 01e8af5ac677..17793490d1b6 100644
  46. --- a/drivers/video/video-uclass.c
  47. +++ b/drivers/video/video-uclass.c
  48. @@ -21,6 +21,8 @@
  49. #include <dm/device_compat.h>
  50. #include <dm/device-internal.h>
  51. #include <dm/uclass-internal.h>
  52. +#include <linux/types.h>
  53. +#include <linux/bitmap.h>
  54. #ifdef CONFIG_SANDBOX
  55. #include <asm/sdl.h>
  56. #endif
  57. @@ -180,6 +182,45 @@ void video_set_default_colors(struct udevice *dev, bool invert)
  58. priv->colour_bg = vid_console_color(priv, back);
  59. }
  60. +/* Notify about changes in the frame buffer */
  61. +int video_damage(struct udevice *vid, int x, int y, int width, int height)
  62. +{
  63. + struct video_priv *priv = dev_get_uclass_priv(vid);
  64. + int endx = x + width;
  65. + int endy = y + height;
  66. +
  67. + if (!CONFIG_IS_ENABLED(VIDEO_DAMAGE))
  68. + return 0;
  69. +
  70. + if (x > priv->xsize)
  71. + return 0;
  72. +
  73. + if (y > priv->ysize)
  74. + return 0;
  75. +
  76. + if (endx > priv->xsize)
  77. + endx = priv->xsize;
  78. +
  79. + if (endy > priv->ysize)
  80. + endy = priv->ysize;
  81. +
  82. + if (priv->damage.endx && priv->damage.endy) {
  83. + /* Span a rectangle across all old and new damage */
  84. + priv->damage.x = min(x, priv->damage.x);
  85. + priv->damage.y = min(y, priv->damage.y);
  86. + priv->damage.endx = max(endx, priv->damage.endx);
  87. + priv->damage.endy = max(endy, priv->damage.endy);
  88. + } else {
  89. + /* First damage, setting the rectangle to span it */
  90. + priv->damage.x = x;
  91. + priv->damage.y = y;
  92. + priv->damage.endx = endx;
  93. + priv->damage.endy = endy;
  94. + }
  95. +
  96. + return 0;
  97. +}
  98. +
  99. /* Flush video activity to the caches */
  100. int video_sync(struct udevice *vid, bool force)
  101. {
  102. diff --git a/include/video.h b/include/video.h
  103. index 43e2c8997783..acb65d70a2d9 100644
  104. --- a/include/video.h
  105. +++ b/include/video.h
  106. @@ -109,6 +109,12 @@ struct video_priv {
  107. void *fb;
  108. int fb_size;
  109. void *copy_fb;
  110. + struct {
  111. + int x;
  112. + int y;
  113. + int endx;
  114. + int endy;
  115. + } damage;
  116. int line_length;
  117. u32 colour_fg;
  118. u32 colour_bg;
  119. @@ -167,8 +173,9 @@ int video_clear(struct udevice *dev);
  120. * @return: 0 on success, error code otherwise
  121. *
  122. * Some frame buffers are cached or have a secondary frame buffer. This
  123. - * function syncs these up so that the current contents of the U-Boot frame
  124. - * buffer are displayed to the user.
  125. + * function syncs the damaged parts of them up so that the current contents
  126. + * of the U-Boot frame buffer are displayed to the user. It clears the damage
  127. + * buffer.
  128. */
  129. int video_sync(struct udevice *vid, bool force);
  130. @@ -268,6 +275,24 @@ static inline int video_sync_copy_all(struct udevice *dev)
  131. #endif
  132. +/**
  133. + * video_damage() - Notify the video subsystem about screen updates.
  134. + *
  135. + * @vid: Device to sync
  136. + * @x: Upper left X coordinate of the damaged rectangle
  137. + * @y: Upper left Y coordinate of the damaged rectangle
  138. + * @width: Width of the damaged rectangle
  139. + * @height: Height of the damaged rectangle
  140. + *
  141. + * @return: 0
  142. + *
  143. + * Some frame buffers are cached or have a secondary frame buffer. This
  144. + * function notifies the video subsystem about rectangles that were updated
  145. + * within the frame buffer. They may only get written to the screen on the
  146. + * next call to video_sync().
  147. + */
  148. +int video_damage(struct udevice *vid, int x, int y, int width, int height);
  149. +
  150. /**
  151. * video_is_active() - Test if one video device it active
  152. *
  153. --
  154. 2.38.1
  155. From cb8cd1f44f4b2db9ec306dc81c36f4d84b8fd63c Mon Sep 17 00:00:00 2001
  156. From: Alexander Graf <agraf@csgraf.de>
  157. Date: Fri, 10 Jun 2022 00:59:16 +0200
  158. Subject: [PATCH 2/7] dm: video: Add damage notification on display clear
  159. Let's report the video damage when we clear the screen. This
  160. way we can later lazily flush only relevant regions to hardware.
  161. Signed-off-by: Alexander Graf <agraf@csgraf.de>
  162. Reported-by: Da Xue <da@libre.computer>
  163. Tested-by: Matthias Brugger <mbrugger@suse.com>
  164. Link: https://lore.kernel.org/r/20220609225921.62462-3-agraf@csgraf.de
  165. ---
  166. drivers/video/video-uclass.c | 2 ++
  167. 1 file changed, 2 insertions(+)
  168. diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c
  169. index 17793490d1b6..66df4c97ef7e 100644
  170. --- a/drivers/video/video-uclass.c
  171. +++ b/drivers/video/video-uclass.c
  172. @@ -153,6 +153,8 @@ int video_clear(struct udevice *dev)
  173. if (ret)
  174. return ret;
  175. + video_damage(dev, 0, 0, priv->xsize, priv->ysize);
  176. +
  177. return video_sync(dev, false);
  178. }
  179. --
  180. 2.38.1
  181. From 724577232caec0e7d19e055a2a500046ea869ebd Mon Sep 17 00:00:00 2001
  182. From: Alexander Graf <agraf@csgraf.de>
  183. Date: Fri, 10 Jun 2022 00:59:17 +0200
  184. Subject: [PATCH 3/7] vidconsole: Add damage notifications to all vidconsole
  185. drivers
  186. Now that we have a damage tracking API, let's populate damage done by
  187. vidconsole drivers. We try to declare as little memory as damaged as
  188. possible, with the exception of rotated screens that I couldn't get my
  189. head wrapped around. On those, we revert to the old behavior and mark
  190. the full screen as damaged on every update.
  191. Signed-off-by: Alexander Graf <agraf@csgraf.de>
  192. Reported-by: Da Xue <da@libre.computer>
  193. Tested-by: Matthias Brugger <mbrugger@suse.com>
  194. Link: https://lore.kernel.org/r/20220609225921.62462-4-agraf@csgraf.de
  195. ---
  196. drivers/video/console_normal.c | 10 ++++++
  197. drivers/video/console_rotate.c | 54 ++++++++++++++++++++++++++++++++
  198. drivers/video/console_truetype.c | 15 +++++++++
  199. 3 files changed, 79 insertions(+)
  200. diff --git a/drivers/video/console_normal.c b/drivers/video/console_normal.c
  201. index 9f552d02b308..e32fb23e3f9f 100644
  202. --- a/drivers/video/console_normal.c
  203. +++ b/drivers/video/console_normal.c
  204. @@ -60,6 +60,9 @@ static int console_normal_set_row(struct udevice *dev, uint row, int clr)
  205. if (ret)
  206. return ret;
  207. + video_damage(dev->parent, 0, VIDEO_FONT_HEIGHT * row, vid_priv->xsize,
  208. + VIDEO_FONT_HEIGHT);
  209. +
  210. return 0;
  211. }
  212. @@ -79,6 +82,9 @@ static int console_normal_move_rows(struct udevice *dev, uint rowdst,
  213. if (ret)
  214. return ret;
  215. + video_damage(dev->parent, 0, VIDEO_FONT_HEIGHT * rowdst, vid_priv->xsize,
  216. + VIDEO_FONT_HEIGHT * count);
  217. +
  218. return 0;
  219. }
  220. @@ -158,6 +164,10 @@ static int console_normal_putc_xy(struct udevice *dev, uint x_frac, uint y,
  221. }
  222. line += vid_priv->line_length;
  223. }
  224. +
  225. + video_damage(dev->parent, VID_TO_PIXEL(x_frac), y, VIDEO_FONT_WIDTH,
  226. + VIDEO_FONT_HEIGHT);
  227. +
  228. ret = vidconsole_sync_copy(dev, start, line);
  229. if (ret)
  230. return ret;
  231. diff --git a/drivers/video/console_rotate.c b/drivers/video/console_rotate.c
  232. index 36c8d0609d87..56e20bb4f32e 100644
  233. --- a/drivers/video/console_rotate.c
  234. +++ b/drivers/video/console_rotate.c
  235. @@ -57,6 +57,12 @@ static int console_set_row_1(struct udevice *dev, uint row, int clr)
  236. if (ret)
  237. return ret;
  238. + video_damage(dev->parent,
  239. + vid_priv->xsize - ((row + 1) * VIDEO_FONT_HEIGHT),
  240. + 0,
  241. + VIDEO_FONT_HEIGHT,
  242. + vid_priv->ysize);
  243. +
  244. return 0;
  245. }
  246. @@ -83,6 +89,12 @@ static int console_move_rows_1(struct udevice *dev, uint rowdst, uint rowsrc,
  247. dst += vid_priv->line_length;
  248. }
  249. + video_damage(dev->parent,
  250. + vid_priv->xsize - ((rowdst + count) * VIDEO_FONT_HEIGHT),
  251. + 0,
  252. + count * VIDEO_FONT_HEIGHT,
  253. + vid_priv->ysize);
  254. +
  255. return 0;
  256. }
  257. @@ -150,6 +162,12 @@ static int console_putc_xy_1(struct udevice *dev, uint x_frac, uint y, char ch)
  258. if (ret)
  259. return ret;
  260. + video_damage(dev->parent,
  261. + vid_priv->xsize - y - VIDEO_FONT_HEIGHT - 1,
  262. + linenum - 1,
  263. + VIDEO_FONT_HEIGHT,
  264. + VIDEO_FONT_WIDTH);
  265. +
  266. return VID_TO_POS(VIDEO_FONT_WIDTH);
  267. }
  268. @@ -199,6 +217,12 @@ static int console_set_row_2(struct udevice *dev, uint row, int clr)
  269. if (ret)
  270. return ret;
  271. + video_damage(dev->parent,
  272. + 0,
  273. + vid_priv->ysize - (row + 1) * VIDEO_FONT_HEIGHT,
  274. + vid_priv->xsize,
  275. + VIDEO_FONT_HEIGHT);
  276. +
  277. return 0;
  278. }
  279. @@ -218,6 +242,12 @@ static int console_move_rows_2(struct udevice *dev, uint rowdst, uint rowsrc,
  280. vidconsole_memmove(dev, dst, src,
  281. VIDEO_FONT_HEIGHT * vid_priv->line_length * count);
  282. + video_damage(dev->parent,
  283. + 0,
  284. + vid_priv->ysize - (rowdst + count) * VIDEO_FONT_HEIGHT,
  285. + vid_priv->xsize,
  286. + count * VIDEO_FONT_HEIGHT);
  287. +
  288. return 0;
  289. }
  290. @@ -288,6 +318,12 @@ static int console_putc_xy_2(struct udevice *dev, uint x_frac, uint y, char ch)
  291. if (ret)
  292. return ret;
  293. + video_damage(dev->parent,
  294. + x - VIDEO_FONT_WIDTH,
  295. + linenum - VIDEO_FONT_HEIGHT + 1,
  296. + VIDEO_FONT_WIDTH,
  297. + VIDEO_FONT_HEIGHT);
  298. +
  299. return VID_TO_POS(VIDEO_FONT_WIDTH);
  300. }
  301. @@ -335,6 +371,12 @@ static int console_set_row_3(struct udevice *dev, uint row, int clr)
  302. if (ret)
  303. return ret;
  304. + video_damage(dev->parent,
  305. + row * VIDEO_FONT_HEIGHT,
  306. + 0,
  307. + VIDEO_FONT_HEIGHT,
  308. + vid_priv->ysize);
  309. +
  310. return 0;
  311. }
  312. @@ -359,6 +401,12 @@ static int console_move_rows_3(struct udevice *dev, uint rowdst, uint rowsrc,
  313. dst += vid_priv->line_length;
  314. }
  315. + video_damage(dev->parent,
  316. + rowdst * VIDEO_FONT_HEIGHT,
  317. + 0,
  318. + count * VIDEO_FONT_HEIGHT,
  319. + vid_priv->ysize);
  320. +
  321. return 0;
  322. }
  323. @@ -424,6 +472,12 @@ static int console_putc_xy_3(struct udevice *dev, uint x_frac, uint y, char ch)
  324. if (ret)
  325. return ret;
  326. + video_damage(dev->parent,
  327. + y,
  328. + x - VIDEO_FONT_WIDTH + 1,
  329. + VIDEO_FONT_HEIGHT,
  330. + VIDEO_FONT_WIDTH);
  331. +
  332. return VID_TO_POS(VIDEO_FONT_WIDTH);
  333. }
  334. diff --git a/drivers/video/console_truetype.c b/drivers/video/console_truetype.c
  335. index c04b449a6d5d..cfeeed71db39 100644
  336. --- a/drivers/video/console_truetype.c
  337. +++ b/drivers/video/console_truetype.c
  338. @@ -126,6 +126,7 @@ struct console_tt_priv {
  339. static int console_truetype_set_row(struct udevice *dev, uint row, int clr)
  340. {
  341. struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
  342. + struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
  343. struct console_tt_priv *priv = dev_get_priv(dev);
  344. void *end, *line;
  345. int ret;
  346. @@ -168,6 +169,9 @@ static int console_truetype_set_row(struct udevice *dev, uint row, int clr)
  347. if (ret)
  348. return ret;
  349. + video_damage(dev->parent, 0, vc_priv->y_charsize * row, vid_priv->xsize,
  350. + vc_priv->y_charsize);
  351. +
  352. return 0;
  353. }
  354. @@ -175,6 +179,7 @@ static int console_truetype_move_rows(struct udevice *dev, uint rowdst,
  355. uint rowsrc, uint count)
  356. {
  357. struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
  358. + struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
  359. struct console_tt_priv *priv = dev_get_priv(dev);
  360. void *dst;
  361. void *src;
  362. @@ -192,6 +197,9 @@ static int console_truetype_move_rows(struct udevice *dev, uint rowdst,
  363. for (i = 0; i < priv->pos_ptr; i++)
  364. priv->pos[i].ypos -= diff;
  365. + video_damage(dev->parent, 0, vc_priv->y_charsize * rowdst, vid_priv->xsize,
  366. + vc_priv->y_charsize * count);
  367. +
  368. return 0;
  369. }
  370. @@ -348,6 +356,10 @@ static int console_truetype_putc_xy(struct udevice *dev, uint x, uint y,
  371. line += vid_priv->line_length;
  372. }
  373. +
  374. + video_damage(dev->parent, VID_TO_PIXEL(x) + xoff,
  375. + y + priv->baseline + yoff, width, height);
  376. +
  377. ret = vidconsole_sync_copy(dev, start, line);
  378. if (ret)
  379. return ret;
  380. @@ -415,6 +427,9 @@ static int console_truetype_erase(struct udevice *dev, int xstart, int ystart,
  381. }
  382. line += vid_priv->line_length;
  383. }
  384. +
  385. + video_damage(dev->parent, xstart, ystart, xend - xstart, yend - ystart);
  386. +
  387. ret = vidconsole_sync_copy(dev, start, line);
  388. if (ret)
  389. return ret;
  390. --
  391. 2.38.1
  392. From b5aa2573a8976ce983ecb42c312d4c64ea118550 Mon Sep 17 00:00:00 2001
  393. From: Alexander Graf <agraf@csgraf.de>
  394. Date: Fri, 10 Jun 2022 00:59:18 +0200
  395. Subject: [PATCH 4/7] video: Add damage notification on bmp display
  396. Let's report the video damage when we draw a bitmap on the screen. This
  397. way we can later lazily flush only relevant regions to hardware.
  398. Signed-off-by: Alexander Graf <agraf@csgraf.de>
  399. Reported-by: Da Xue <da@libre.computer>
  400. Tested-by: Matthias Brugger <mbrugger@suse.com>
  401. Link: https://lore.kernel.org/r/20220609225921.62462-5-agraf@csgraf.de
  402. ---
  403. drivers/video/video_bmp.c | 2 ++
  404. 1 file changed, 2 insertions(+)
  405. diff --git a/drivers/video/video_bmp.c b/drivers/video/video_bmp.c
  406. index 4d2d961696aa..da8a7b37019b 100644
  407. --- a/drivers/video/video_bmp.c
  408. +++ b/drivers/video/video_bmp.c
  409. @@ -416,6 +416,8 @@ int video_bmp_display(struct udevice *dev, ulong bmp_image, int x, int y,
  410. break;
  411. };
  412. + video_damage(dev, x, y, width, height);
  413. +
  414. /* Find the position of the top left of the image in the framebuffer */
  415. fb = (uchar *)(priv->fb + y * priv->line_length + x * bpix / 8);
  416. ret = video_sync_copy(dev, start, fb);
  417. --
  418. 2.38.1
  419. From a5192a72ecdb522e0d8d0e2af93049fa6c70b947 Mon Sep 17 00:00:00 2001
  420. From: Alexander Graf <agraf@csgraf.de>
  421. Date: Fri, 10 Jun 2022 00:59:19 +0200
  422. Subject: [PATCH 5/7] efi_loader: GOP: Add damage notification on BLT
  423. Now that we have a damage tracking API, let's populate damage done by
  424. UEFI payloads when they BLT data onto the screen.
  425. Signed-off-by: Alexander Graf <agraf@csgraf.de>
  426. Reported-by: Da Xue <da@libre.computer>
  427. Tested-by: Matthias Brugger <mbrugger@suse.com>
  428. Link: https://lore.kernel.org/r/20220609225921.62462-6-agraf@csgraf.de
  429. ---
  430. lib/efi_loader/efi_gop.c | 7 ++++++-
  431. 1 file changed, 6 insertions(+), 1 deletion(-)
  432. diff --git a/lib/efi_loader/efi_gop.c b/lib/efi_loader/efi_gop.c
  433. index 5908b5c64669..c50880806ddb 100644
  434. --- a/lib/efi_loader/efi_gop.c
  435. +++ b/lib/efi_loader/efi_gop.c
  436. @@ -32,6 +32,7 @@ struct efi_gop_obj {
  437. struct efi_gop ops;
  438. struct efi_gop_mode_info info;
  439. struct efi_gop_mode mode;
  440. + struct udevice *vdev;
  441. /* Fields we only have access to during init */
  442. u32 bpix;
  443. void *fb;
  444. @@ -243,6 +244,9 @@ static __always_inline efi_status_t gop_blt_int(struct efi_gop *this,
  445. dlineoff += dwidth;
  446. }
  447. + if (IS_ENABLED(CONFIG_DM_VIDEO))
  448. + video_damage(gopobj->vdev, dx, dy, width, height);
  449. +
  450. return EFI_SUCCESS;
  451. }
  452. @@ -476,9 +480,9 @@ efi_status_t efi_gop_register(void)
  453. u64 fb_base, fb_size;
  454. void *fb;
  455. efi_status_t ret;
  456. + struct udevice *vdev = NULL;
  457. #ifdef CONFIG_DM_VIDEO
  458. - struct udevice *vdev;
  459. struct video_priv *priv;
  460. /* We only support a single video output device for now */
  461. @@ -577,6 +581,7 @@ efi_status_t efi_gop_register(void)
  462. gopobj->info.pixels_per_scanline = col;
  463. gopobj->bpix = bpix;
  464. gopobj->fb = fb;
  465. + gopobj->vdev = vdev;
  466. return EFI_SUCCESS;
  467. }
  468. --
  469. 2.38.1
  470. From 6b0f2545fe828d5f6fa262d10f7c9eef003a9bd8 Mon Sep 17 00:00:00 2001
  471. From: Alexander Graf <agraf@csgraf.de>
  472. Date: Fri, 10 Jun 2022 00:59:20 +0200
  473. Subject: [PATCH 6/7] video: Only dcache flush damaged lines
  474. Now that we have a damage area tells us which parts of the frame buffer
  475. actually need updating, let's only dcache flush those on video_sync()
  476. calls. With this optimization in place, frame buffer updates - especially
  477. on large screen such as 4k displays - speed up significantly.
  478. Signed-off-by: Alexander Graf <agraf@csgraf.de>
  479. Reported-by: Da Xue <da@libre.computer>
  480. Tested-by: Matthias Brugger <mbrugger@suse.com>
  481. Link: https://lore.kernel.org/r/20220609225921.62462-7-agraf@csgraf.de
  482. ---
  483. drivers/video/video-uclass.c | 51 ++++++++++++++++++++++++++++++------
  484. 1 file changed, 43 insertions(+), 8 deletions(-)
  485. diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c
  486. index 66df4c97ef7e..95126b9bdb02 100644
  487. --- a/drivers/video/video-uclass.c
  488. +++ b/drivers/video/video-uclass.c
  489. @@ -223,9 +223,45 @@ int video_damage(struct udevice *vid, int x, int y, int width, int height)
  490. return 0;
  491. }
  492. +#if defined(CONFIG_ARM) && !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
  493. +static void video_flush_dcache(struct udevice *vid)
  494. +{
  495. + struct video_priv *priv = dev_get_uclass_priv(vid);
  496. +
  497. + if (!priv->flush_dcache)
  498. + return;
  499. +
  500. + if (!CONFIG_IS_ENABLED(VIDEO_DAMAGE)) {
  501. + flush_dcache_range((ulong)priv->fb,
  502. + ALIGN((ulong)priv->fb + priv->fb_size,
  503. + CONFIG_SYS_CACHELINE_SIZE));
  504. +
  505. + return;
  506. + }
  507. +
  508. + if (priv->damage.endx && priv->damage.endy) {
  509. + int lstart = priv->damage.x * VNBYTES(priv->bpix);
  510. + int lend = priv->damage.endx * VNBYTES(priv->bpix);
  511. + int y;
  512. +
  513. + for (y = priv->damage.y; y < priv->damage.endy; y++) {
  514. + ulong fb = (ulong)priv->fb;
  515. + ulong start = fb + (y * priv->line_length) + lstart;
  516. + ulong end = start + lend - lstart;
  517. +
  518. + start = ALIGN_DOWN(start, CONFIG_SYS_CACHELINE_SIZE);
  519. + end = ALIGN(end, CONFIG_SYS_CACHELINE_SIZE);
  520. +
  521. + flush_dcache_range(start, end);
  522. + }
  523. + }
  524. +}
  525. +#endif
  526. +
  527. /* Flush video activity to the caches */
  528. int video_sync(struct udevice *vid, bool force)
  529. {
  530. + struct video_priv *priv = dev_get_uclass_priv(vid);
  531. struct video_ops *ops = video_get_ops(vid);
  532. int ret;
  533. @@ -241,15 +277,8 @@ int video_sync(struct udevice *vid, bool force)
  534. * out whether it exists? For now, ARM is safe.
  535. */
  536. #if defined(CONFIG_ARM) && !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
  537. - struct video_priv *priv = dev_get_uclass_priv(vid);
  538. -
  539. - if (priv->flush_dcache) {
  540. - flush_dcache_range((ulong)priv->fb,
  541. - ALIGN((ulong)priv->fb + priv->fb_size,
  542. - CONFIG_SYS_CACHELINE_SIZE));
  543. - }
  544. + video_flush_dcache(vid);
  545. #elif defined(CONFIG_VIDEO_SANDBOX_SDL)
  546. - struct video_priv *priv = dev_get_uclass_priv(vid);
  547. static ulong last_sync;
  548. if (force || get_timer(last_sync) > 100) {
  549. @@ -257,6 +286,12 @@ int video_sync(struct udevice *vid, bool force)
  550. last_sync = get_timer(0);
  551. }
  552. #endif
  553. +
  554. + if (CONFIG_IS_ENABLED(VIDEO_DAMAGE)) {
  555. + priv->damage.endx = 0;
  556. + priv->damage.endy = 0;
  557. + }
  558. +
  559. return 0;
  560. }
  561. --
  562. 2.38.1
  563. From d2a78b028083bf1b17e8a72ce84b65d8861951a6 Mon Sep 17 00:00:00 2001
  564. From: Alexander Graf <agraf@csgraf.de>
  565. Date: Fri, 10 Jun 2022 00:59:21 +0200
  566. Subject: [PATCH 7/7] video: Use VIDEO_DAMAGE for VIDEO_COPY
  567. CONFIG_VIDEO_COPY implemented a range based copying mechanism: If we
  568. print a single character, it will always copy the full range of bytes
  569. from the top left corner of the character to the lower right onto the
  570. uncached frame buffer. This includes pretty much the full line contents
  571. of the printed character.
  572. Since we now have proper damage tracking, let's make use of that to reduce
  573. the amount of data we need to copy. With this patch applied, we will only
  574. copy the tiny rectangle surrounding characters when we print them,
  575. speeding up the video console.
  576. As a bonus, we remove a lot of code.
  577. Signed-off-by: Alexander Graf <agraf@csgraf.de>
  578. Tested-by: Matthias Brugger <mbrugger@suse.com>
  579. Link: https://lore.kernel.org/r/20220609225921.62462-8-agraf@csgraf.de
  580. [Alper: Fix instances of memmove(dev, ...)]
  581. Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
  582. ---
  583. configs/chromebook_coral_defconfig | 1 +
  584. configs/chromebook_link_defconfig | 1 +
  585. configs/chromebook_samus_defconfig | 1 +
  586. configs/minnowmax_defconfig | 1 +
  587. configs/sandbox_defconfig | 1 +
  588. configs/xilinx_zynqmp_virt_defconfig | 1 +
  589. drivers/video/Kconfig | 8 ++-
  590. drivers/video/console_normal.c | 14 +----
  591. drivers/video/console_rotate.c | 37 ++---------
  592. drivers/video/console_truetype.c | 17 +-----
  593. drivers/video/vidconsole-uclass.c | 16 -----
  594. drivers/video/video-uclass.c | 91 ++++++++--------------------
  595. drivers/video/video_bmp.c | 7 ---
  596. include/video.h | 37 -----------
  597. include/video_console.h | 49 ---------------
  598. 15 files changed, 44 insertions(+), 238 deletions(-)
  599. diff --git a/configs/chromebook_coral_defconfig b/configs/chromebook_coral_defconfig
  600. index 60c50e75be65..9518fb6b867e 100644
  601. --- a/configs/chromebook_coral_defconfig
  602. +++ b/configs/chromebook_coral_defconfig
  603. @@ -117,6 +117,7 @@ CONFIG_USB_XHCI_HCD=y
  604. CONFIG_USB_STORAGE=y
  605. CONFIG_USB_KEYBOARD=y
  606. CONFIG_VIDEO_COPY=y
  607. +CONFIG_VIDEO_DAMAGE=y
  608. CONFIG_FS_CBFS=y
  609. CONFIG_SPL_FS_CBFS=y
  610. CONFIG_FAT_WRITE=y
  611. diff --git a/configs/chromebook_link_defconfig b/configs/chromebook_link_defconfig
  612. index fa3641e42f53..bfaf4dbb7feb 100644
  613. --- a/configs/chromebook_link_defconfig
  614. +++ b/configs/chromebook_link_defconfig
  615. @@ -74,6 +74,7 @@ CONFIG_TPM_TIS_LPC=y
  616. CONFIG_USB_STORAGE=y
  617. CONFIG_USB_KEYBOARD=y
  618. CONFIG_VIDEO_COPY=y
  619. +CONFIG_VIDEO_DAMAGE=y
  620. CONFIG_FRAMEBUFFER_SET_VESA_MODE=y
  621. CONFIG_FRAMEBUFFER_VESA_MODE_11A=y
  622. CONFIG_VIDEO_IVYBRIDGE_IGD=y
  623. diff --git a/configs/chromebook_samus_defconfig b/configs/chromebook_samus_defconfig
  624. index 56a0d6c8a8ee..53ca6225cd4b 100644
  625. --- a/configs/chromebook_samus_defconfig
  626. +++ b/configs/chromebook_samus_defconfig
  627. @@ -78,6 +78,7 @@ CONFIG_TPM_TIS_LPC=y
  628. CONFIG_USB_STORAGE=y
  629. CONFIG_USB_KEYBOARD=y
  630. CONFIG_VIDEO_COPY=y
  631. +CONFIG_VIDEO_DAMAGE=y
  632. CONFIG_FRAMEBUFFER_SET_VESA_MODE=y
  633. CONFIG_FRAMEBUFFER_VESA_MODE_11A=y
  634. CONFIG_TPM=y
  635. diff --git a/configs/minnowmax_defconfig b/configs/minnowmax_defconfig
  636. index 2e9edc6c4ee6..eb6cebaf8879 100644
  637. --- a/configs/minnowmax_defconfig
  638. +++ b/configs/minnowmax_defconfig
  639. @@ -69,6 +69,7 @@ CONFIG_SPI=y
  640. CONFIG_USB_STORAGE=y
  641. CONFIG_USB_KEYBOARD=y
  642. CONFIG_VIDEO_COPY=y
  643. +CONFIG_VIDEO_DAMAGE=y
  644. CONFIG_FRAMEBUFFER_SET_VESA_MODE=y
  645. CONFIG_GENERATE_ACPI_TABLE=y
  646. # CONFIG_GZIP is not set
  647. diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
  648. index ab5d3f19bf96..d2b9486d7d6c 100644
  649. --- a/configs/sandbox_defconfig
  650. +++ b/configs/sandbox_defconfig
  651. @@ -292,6 +292,7 @@ CONFIG_USB_ETHER=y
  652. CONFIG_USB_ETH_CDC=y
  653. CONFIG_DM_VIDEO=y
  654. CONFIG_VIDEO_COPY=y
  655. +CONFIG_VIDEO_DAMAGE=y
  656. CONFIG_CONSOLE_ROTATION=y
  657. CONFIG_CONSOLE_TRUETYPE=y
  658. CONFIG_CONSOLE_TRUETYPE_CANTORAONE=y
  659. diff --git a/configs/xilinx_zynqmp_virt_defconfig b/configs/xilinx_zynqmp_virt_defconfig
  660. index e5ac26e0381f..e0dbf4b51070 100644
  661. --- a/configs/xilinx_zynqmp_virt_defconfig
  662. +++ b/configs/xilinx_zynqmp_virt_defconfig
  663. @@ -221,6 +221,7 @@ CONFIG_USB_ETHER=y
  664. CONFIG_USB_ETH_CDC=y
  665. CONFIG_DM_VIDEO=y
  666. CONFIG_VIDEO_COPY=y
  667. +CONFIG_VIDEO_DAMAGE=y
  668. CONFIG_DISPLAY=y
  669. CONFIG_VIDEO_SEPS525=y
  670. CONFIG_LCD=y
  671. diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
  672. index 21fca141a087..5f84d8ad0571 100644
  673. --- a/drivers/video/Kconfig
  674. +++ b/drivers/video/Kconfig
  675. @@ -54,12 +54,14 @@ config VIDEO_PCI_DEFAULT_FB_SIZE
  676. config VIDEO_COPY
  677. bool "Enable copying the frame buffer to a hardware copy"
  678. - depends on DM_VIDEO
  679. + depends on DM_VIDEO && VIDEO_DAMAGE
  680. help
  681. On some machines (e.g. x86), reading from the frame buffer is very
  682. slow because it is uncached. To improve performance, this feature
  683. allows the frame buffer to be kept in cached memory (allocated by
  684. U-Boot) and then copied to the hardware frame-buffer as needed.
  685. + It uses the VIDEO_DAMAGE feature to keep track of regions to copy
  686. + and will only copy actually touched regions.
  687. To use this, your video driver must set @copy_base in
  688. struct video_uc_plat.
  689. @@ -74,11 +76,13 @@ config VIDEO_DAMAGE
  690. have to flush frame buffer contents from CPU caches into RAM which
  691. can be a slow operation.
  692. - This patch adds damage tracking to collect information about regions
  693. + This feature adds damage tracking to collect information about regions
  694. that received updates. When we want to sync, we then only flush
  695. regions of the frame buffer that were modified before, speeding up
  696. screen refreshes significantly.
  697. + It is also used by VIDEO_COPY to identify which regions changed.
  698. +
  699. config BACKLIGHT_PWM
  700. bool "Generic PWM based Backlight Driver"
  701. depends on BACKLIGHT && DM_PWM
  702. diff --git a/drivers/video/console_normal.c b/drivers/video/console_normal.c
  703. index e32fb23e3f9f..ebb7fdd69307 100644
  704. --- a/drivers/video/console_normal.c
  705. +++ b/drivers/video/console_normal.c
  706. @@ -21,7 +21,6 @@ static int console_normal_set_row(struct udevice *dev, uint row, int clr)
  707. struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
  708. void *line, *end;
  709. int pixels = VIDEO_FONT_HEIGHT * vid_priv->xsize;
  710. - int ret;
  711. int i;
  712. line = vid_priv->fb + row * VIDEO_FONT_HEIGHT * vid_priv->line_length;
  713. @@ -56,9 +55,6 @@ static int console_normal_set_row(struct udevice *dev, uint row, int clr)
  714. default:
  715. return -ENOSYS;
  716. }
  717. - ret = vidconsole_sync_copy(dev, line, end);
  718. - if (ret)
  719. - return ret;
  720. video_damage(dev->parent, 0, VIDEO_FONT_HEIGHT * row, vid_priv->xsize,
  721. VIDEO_FONT_HEIGHT);
  722. @@ -73,14 +69,11 @@ static int console_normal_move_rows(struct udevice *dev, uint rowdst,
  723. void *dst;
  724. void *src;
  725. int size;
  726. - int ret;
  727. dst = vid_priv->fb + rowdst * VIDEO_FONT_HEIGHT * vid_priv->line_length;
  728. src = vid_priv->fb + rowsrc * VIDEO_FONT_HEIGHT * vid_priv->line_length;
  729. size = VIDEO_FONT_HEIGHT * vid_priv->line_length * count;
  730. - ret = vidconsole_memmove(dev, dst, src, size);
  731. - if (ret)
  732. - return ret;
  733. + memmove(dst, src, size);
  734. video_damage(dev->parent, 0, VIDEO_FONT_HEIGHT * rowdst, vid_priv->xsize,
  735. VIDEO_FONT_HEIGHT * count);
  736. @@ -97,7 +90,6 @@ static int console_normal_putc_xy(struct udevice *dev, uint x_frac, uint y,
  737. int i, row;
  738. void *start;
  739. void *line;
  740. - int ret;
  741. start = vid_priv->fb + y * vid_priv->line_length +
  742. VID_TO_PIXEL(x_frac) * VNBYTES(vid_priv->bpix);
  743. @@ -168,10 +160,6 @@ static int console_normal_putc_xy(struct udevice *dev, uint x_frac, uint y,
  744. video_damage(dev->parent, VID_TO_PIXEL(x_frac), y, VIDEO_FONT_WIDTH,
  745. VIDEO_FONT_HEIGHT);
  746. - ret = vidconsole_sync_copy(dev, start, line);
  747. - if (ret)
  748. - return ret;
  749. -
  750. return VID_TO_POS(VIDEO_FONT_WIDTH);
  751. }
  752. diff --git a/drivers/video/console_rotate.c b/drivers/video/console_rotate.c
  753. index 56e20bb4f32e..ae0cbe41bfe4 100644
  754. --- a/drivers/video/console_rotate.c
  755. +++ b/drivers/video/console_rotate.c
  756. @@ -53,9 +53,6 @@ static int console_set_row_1(struct udevice *dev, uint row, int clr)
  757. }
  758. line += vid_priv->line_length;
  759. }
  760. - ret = vidconsole_sync_copy(dev, start, line);
  761. - if (ret)
  762. - return ret;
  763. video_damage(dev->parent,
  764. vid_priv->xsize - ((row + 1) * VIDEO_FONT_HEIGHT),
  765. @@ -81,10 +78,7 @@ static int console_move_rows_1(struct udevice *dev, uint rowdst, uint rowsrc,
  766. (rowsrc + count) * VIDEO_FONT_HEIGHT * pbytes;
  767. for (j = 0; j < vid_priv->ysize; j++) {
  768. - ret = vidconsole_memmove(dev, dst, src,
  769. - VIDEO_FONT_HEIGHT * pbytes * count);
  770. - if (ret)
  771. - return ret;
  772. + memmove(dst, src, VIDEO_FONT_HEIGHT * pbytes * count);
  773. src += vid_priv->line_length;
  774. dst += vid_priv->line_length;
  775. }
  776. @@ -158,10 +152,6 @@ static int console_putc_xy_1(struct udevice *dev, uint x_frac, uint y, char ch)
  777. mask >>= 1;
  778. }
  779. /* We draw backwards from 'start, so account for the first line */
  780. - ret = vidconsole_sync_copy(dev, start - vid_priv->line_length, line);
  781. - if (ret)
  782. - return ret;
  783. -
  784. video_damage(dev->parent,
  785. vid_priv->xsize - y - VIDEO_FONT_HEIGHT - 1,
  786. linenum - 1,
  787. @@ -213,9 +203,6 @@ static int console_set_row_2(struct udevice *dev, uint row, int clr)
  788. default:
  789. return -ENOSYS;
  790. }
  791. - ret = vidconsole_sync_copy(dev, start, end);
  792. - if (ret)
  793. - return ret;
  794. video_damage(dev->parent,
  795. 0,
  796. @@ -239,8 +226,8 @@ static int console_move_rows_2(struct udevice *dev, uint rowdst, uint rowsrc,
  797. vid_priv->line_length;
  798. src = end - (rowsrc + count) * VIDEO_FONT_HEIGHT *
  799. vid_priv->line_length;
  800. - vidconsole_memmove(dev, dst, src,
  801. - VIDEO_FONT_HEIGHT * vid_priv->line_length * count);
  802. + memmove(dst, src, VIDEO_FONT_HEIGHT *
  803. + vid_priv->line_length * count);
  804. video_damage(dev->parent,
  805. 0,
  806. @@ -313,10 +300,6 @@ static int console_putc_xy_2(struct udevice *dev, uint x_frac, uint y, char ch)
  807. }
  808. line -= vid_priv->line_length;
  809. }
  810. - /* Add 4 bytes to allow for the first pixel writen */
  811. - ret = vidconsole_sync_copy(dev, start + 4, line);
  812. - if (ret)
  813. - return ret;
  814. video_damage(dev->parent,
  815. x - VIDEO_FONT_WIDTH,
  816. @@ -367,9 +350,6 @@ static int console_set_row_3(struct udevice *dev, uint row, int clr)
  817. }
  818. line += vid_priv->line_length;
  819. }
  820. - ret = vidconsole_sync_copy(dev, start, line);
  821. - if (ret)
  822. - return ret;
  823. video_damage(dev->parent,
  824. row * VIDEO_FONT_HEIGHT,
  825. @@ -387,16 +367,13 @@ static int console_move_rows_3(struct udevice *dev, uint rowdst, uint rowsrc,
  826. int pbytes = VNBYTES(vid_priv->bpix);
  827. void *dst;
  828. void *src;
  829. - int j, ret;
  830. + int j;
  831. dst = vid_priv->fb + rowdst * VIDEO_FONT_HEIGHT * pbytes;
  832. src = vid_priv->fb + rowsrc * VIDEO_FONT_HEIGHT * pbytes;
  833. for (j = 0; j < vid_priv->ysize; j++) {
  834. - ret = vidconsole_memmove(dev, dst, src,
  835. - VIDEO_FONT_HEIGHT * pbytes * count);
  836. - if (ret)
  837. - return ret;
  838. + memmove(dst, src, VIDEO_FONT_HEIGHT * pbytes * count);
  839. src += vid_priv->line_length;
  840. dst += vid_priv->line_length;
  841. }
  842. @@ -468,10 +445,6 @@ static int console_putc_xy_3(struct udevice *dev, uint x_frac, uint y, char ch)
  843. mask >>= 1;
  844. }
  845. /* Add a line to allow for the first pixels writen */
  846. - ret = vidconsole_sync_copy(dev, start + vid_priv->line_length, line);
  847. - if (ret)
  848. - return ret;
  849. -
  850. video_damage(dev->parent,
  851. y,
  852. x - VIDEO_FONT_WIDTH + 1,
  853. diff --git a/drivers/video/console_truetype.c b/drivers/video/console_truetype.c
  854. index cfeeed71db39..4118add1cf79 100644
  855. --- a/drivers/video/console_truetype.c
  856. +++ b/drivers/video/console_truetype.c
  857. @@ -165,9 +165,6 @@ static int console_truetype_set_row(struct udevice *dev, uint row, int clr)
  858. default:
  859. return -ENOSYS;
  860. }
  861. - ret = vidconsole_sync_copy(dev, line, end);
  862. - if (ret)
  863. - return ret;
  864. video_damage(dev->parent, 0, vc_priv->y_charsize * row, vid_priv->xsize,
  865. vc_priv->y_charsize);
  866. @@ -183,14 +180,11 @@ static int console_truetype_move_rows(struct udevice *dev, uint rowdst,
  867. struct console_tt_priv *priv = dev_get_priv(dev);
  868. void *dst;
  869. void *src;
  870. - int i, diff, ret;
  871. + int i, diff;
  872. dst = vid_priv->fb + rowdst * priv->font_size * vid_priv->line_length;
  873. src = vid_priv->fb + rowsrc * priv->font_size * vid_priv->line_length;
  874. - ret = vidconsole_memmove(dev, dst, src, priv->font_size *
  875. - vid_priv->line_length * count);
  876. - if (ret)
  877. - return ret;
  878. + memmove(dst, src, priv->font_size * vid_priv->line_length * count);
  879. /* Scroll up our position history */
  880. diff = (rowsrc - rowdst) * priv->font_size;
  881. @@ -360,9 +354,6 @@ static int console_truetype_putc_xy(struct udevice *dev, uint x, uint y,
  882. video_damage(dev->parent, VID_TO_PIXEL(x) + xoff,
  883. y + priv->baseline + yoff, width, height);
  884. - ret = vidconsole_sync_copy(dev, start, line);
  885. - if (ret)
  886. - return ret;
  887. free(data);
  888. return width_frac;
  889. @@ -430,10 +421,6 @@ static int console_truetype_erase(struct udevice *dev, int xstart, int ystart,
  890. video_damage(dev->parent, xstart, ystart, xend - xstart, yend - ystart);
  891. - ret = vidconsole_sync_copy(dev, start, line);
  892. - if (ret)
  893. - return ret;
  894. -
  895. return 0;
  896. }
  897. diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c
  898. index ca6e1a2620cc..9fe14ebc60a3 100644
  899. --- a/drivers/video/vidconsole-uclass.c
  900. +++ b/drivers/video/vidconsole-uclass.c
  901. @@ -702,22 +702,6 @@ UCLASS_DRIVER(vidconsole) = {
  902. .per_device_auto = sizeof(struct vidconsole_priv),
  903. };
  904. -#ifdef CONFIG_VIDEO_COPY
  905. -int vidconsole_sync_copy(struct udevice *dev, void *from, void *to)
  906. -{
  907. - struct udevice *vid = dev_get_parent(dev);
  908. -
  909. - return video_sync_copy(vid, from, to);
  910. -}
  911. -
  912. -int vidconsole_memmove(struct udevice *dev, void *dst, const void *src,
  913. - int size)
  914. -{
  915. - memmove(dst, src, size);
  916. - return vidconsole_sync_copy(dev, dst, dst + size);
  917. -}
  918. -#endif
  919. -
  920. #if CONFIG_IS_ENABLED(CMD_VIDCONSOLE)
  921. void vidconsole_position_cursor(struct udevice *dev, unsigned col, unsigned row)
  922. {
  923. diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c
  924. index 95126b9bdb02..6dffa5be814a 100644
  925. --- a/drivers/video/video-uclass.c
  926. +++ b/drivers/video/video-uclass.c
  927. @@ -124,7 +124,6 @@ int video_reserve(ulong *addrp)
  928. int video_clear(struct udevice *dev)
  929. {
  930. struct video_priv *priv = dev_get_uclass_priv(dev);
  931. - int ret;
  932. switch (priv->bpix) {
  933. case VIDEO_BPP16:
  934. @@ -149,9 +148,6 @@ int video_clear(struct udevice *dev)
  935. memset(priv->fb, priv->colour_bg, priv->fb_size);
  936. break;
  937. }
  938. - ret = video_sync_copy(dev, priv->fb, priv->fb + priv->fb_size);
  939. - if (ret)
  940. - return ret;
  941. video_damage(dev, 0, 0, priv->xsize, priv->ysize);
  942. @@ -258,6 +254,27 @@ static void video_flush_dcache(struct udevice *vid)
  943. }
  944. #endif
  945. +static void video_flush_copy(struct udevice *vid)
  946. +{
  947. + struct video_priv *priv = dev_get_uclass_priv(vid);
  948. +
  949. + if (!priv->copy_fb)
  950. + return;
  951. +
  952. + if (priv->damage.endx && priv->damage.endy) {
  953. + int lstart = priv->damage.x * VNBYTES(priv->bpix);
  954. + int lend = priv->damage.endx * VNBYTES(priv->bpix);
  955. + int y;
  956. +
  957. + for (y = priv->damage.y; y < priv->damage.endy; y++) {
  958. + ulong offset = (y * priv->line_length) + lstart;
  959. + ulong len = lend - lstart;
  960. +
  961. + memcpy(priv->copy_fb + offset, priv->fb + offset, len);
  962. + }
  963. + }
  964. +}
  965. +
  966. /* Flush video activity to the caches */
  967. int video_sync(struct udevice *vid, bool force)
  968. {
  969. @@ -265,6 +282,9 @@ int video_sync(struct udevice *vid, bool force)
  970. struct video_ops *ops = video_get_ops(vid);
  971. int ret;
  972. + if (CONFIG_IS_ENABLED(VIDEO_COPY))
  973. + video_flush_copy(vid);
  974. +
  975. if (ops && ops->video_sync) {
  976. ret = ops->video_sync(vid);
  977. if (ret)
  978. @@ -339,69 +359,6 @@ int video_get_ysize(struct udevice *dev)
  979. return priv->ysize;
  980. }
  981. -#ifdef CONFIG_VIDEO_COPY
  982. -int video_sync_copy(struct udevice *dev, void *from, void *to)
  983. -{
  984. - struct video_priv *priv = dev_get_uclass_priv(dev);
  985. -
  986. - if (priv->copy_fb) {
  987. - long offset, size;
  988. -
  989. - /* Find the offset of the first byte to copy */
  990. - if ((ulong)to > (ulong)from) {
  991. - size = to - from;
  992. - offset = from - priv->fb;
  993. - } else {
  994. - size = from - to;
  995. - offset = to - priv->fb;
  996. - }
  997. -
  998. - /*
  999. - * Allow a bit of leeway for valid requests somewhere near the
  1000. - * frame buffer
  1001. - */
  1002. - if (offset < -priv->fb_size || offset > 2 * priv->fb_size) {
  1003. -#ifdef DEBUG
  1004. - char str[120];
  1005. -
  1006. - snprintf(str, sizeof(str),
  1007. - "[** FAULT sync_copy fb=%p, from=%p, to=%p, offset=%lx]",
  1008. - priv->fb, from, to, offset);
  1009. - console_puts_select_stderr(true, str);
  1010. -#endif
  1011. - return -EFAULT;
  1012. - }
  1013. -
  1014. - /*
  1015. - * Silently crop the memcpy. This allows callers to avoid doing
  1016. - * this themselves. It is common for the end pointer to go a
  1017. - * few lines after the end of the frame buffer, since most of
  1018. - * the update algorithms terminate a line after their last write
  1019. - */
  1020. - if (offset + size > priv->fb_size) {
  1021. - size = priv->fb_size - offset;
  1022. - } else if (offset < 0) {
  1023. - size += offset;
  1024. - offset = 0;
  1025. - }
  1026. -
  1027. - memcpy(priv->copy_fb + offset, priv->fb + offset, size);
  1028. - }
  1029. -
  1030. - return 0;
  1031. -}
  1032. -
  1033. -int video_sync_copy_all(struct udevice *dev)
  1034. -{
  1035. - struct video_priv *priv = dev_get_uclass_priv(dev);
  1036. -
  1037. - video_sync_copy(dev, priv->fb, priv->fb + priv->fb_size);
  1038. -
  1039. - return 0;
  1040. -}
  1041. -
  1042. -#endif
  1043. -
  1044. #define SPLASH_DECL(_name) \
  1045. extern u8 __splash_ ## _name ## _begin[]; \
  1046. extern u8 __splash_ ## _name ## _end[]
  1047. diff --git a/drivers/video/video_bmp.c b/drivers/video/video_bmp.c
  1048. index da8a7b37019b..8281a8344935 100644
  1049. --- a/drivers/video/video_bmp.c
  1050. +++ b/drivers/video/video_bmp.c
  1051. @@ -244,7 +244,6 @@ int video_bmp_display(struct udevice *dev, ulong bmp_image, int x, int y,
  1052. enum video_format eformat;
  1053. struct bmp_color_table_entry *palette;
  1054. int hdr_size;
  1055. - int ret;
  1056. if (!bmp || !(bmp->header.signature[0] == 'B' &&
  1057. bmp->header.signature[1] == 'M')) {
  1058. @@ -418,11 +417,5 @@ int video_bmp_display(struct udevice *dev, ulong bmp_image, int x, int y,
  1059. video_damage(dev, x, y, width, height);
  1060. - /* Find the position of the top left of the image in the framebuffer */
  1061. - fb = (uchar *)(priv->fb + y * priv->line_length + x * bpix / 8);
  1062. - ret = video_sync_copy(dev, start, fb);
  1063. - if (ret)
  1064. - return log_ret(ret);
  1065. -
  1066. return video_sync(dev, false);
  1067. }
  1068. diff --git a/include/video.h b/include/video.h
  1069. index acb65d70a2d9..11b81952f50b 100644
  1070. --- a/include/video.h
  1071. +++ b/include/video.h
  1072. @@ -238,43 +238,6 @@ void video_set_flush_dcache(struct udevice *dev, bool flush);
  1073. */
  1074. void video_set_default_colors(struct udevice *dev, bool invert);
  1075. -#ifdef CONFIG_VIDEO_COPY
  1076. -/**
  1077. - * vidconsole_sync_copy() - Sync back to the copy framebuffer
  1078. - *
  1079. - * This ensures that the copy framebuffer has the same data as the framebuffer
  1080. - * for a particular region. It should be called after the framebuffer is updated
  1081. - *
  1082. - * @from and @to can be in either order. The region between them is synced.
  1083. - *
  1084. - * @dev: Vidconsole device being updated
  1085. - * @from: Start/end address within the framebuffer (->fb)
  1086. - * @to: Other address within the frame buffer
  1087. - * Return: 0 if OK, -EFAULT if the start address is before the start of the
  1088. - * frame buffer start
  1089. - */
  1090. -int video_sync_copy(struct udevice *dev, void *from, void *to);
  1091. -
  1092. -/**
  1093. - * video_sync_copy_all() - Sync the entire framebuffer to the copy
  1094. - *
  1095. - * @dev: Vidconsole device being updated
  1096. - * Return: 0 (always)
  1097. - */
  1098. -int video_sync_copy_all(struct udevice *dev);
  1099. -#else
  1100. -static inline int video_sync_copy(struct udevice *dev, void *from, void *to)
  1101. -{
  1102. - return 0;
  1103. -}
  1104. -
  1105. -static inline int video_sync_copy_all(struct udevice *dev)
  1106. -{
  1107. - return 0;
  1108. -}
  1109. -
  1110. -#endif
  1111. -
  1112. /**
  1113. * video_damage() - Notify the video subsystem about screen updates.
  1114. *
  1115. diff --git a/include/video_console.h b/include/video_console.h
  1116. index 8cc8d21d6e49..9f0a2eea389f 100644
  1117. --- a/include/video_console.h
  1118. +++ b/include/video_console.h
  1119. @@ -258,55 +258,6 @@ void vidconsole_position_cursor(struct udevice *dev, unsigned col,
  1120. */
  1121. u32 vid_console_color(struct video_priv *priv, unsigned int idx);
  1122. -#ifdef CONFIG_VIDEO_COPY
  1123. -/**
  1124. - * vidconsole_sync_copy() - Sync back to the copy framebuffer
  1125. - *
  1126. - * This ensures that the copy framebuffer has the same data as the framebuffer
  1127. - * for a particular region. It should be called after the framebuffer is updated
  1128. - *
  1129. - * @from and @to can be in either order. The region between them is synced.
  1130. - *
  1131. - * @dev: Vidconsole device being updated
  1132. - * @from: Start/end address within the framebuffer (->fb)
  1133. - * @to: Other address within the frame buffer
  1134. - * Return: 0 if OK, -EFAULT if the start address is before the start of the
  1135. - * frame buffer start
  1136. - */
  1137. -int vidconsole_sync_copy(struct udevice *dev, void *from, void *to);
  1138. -
  1139. -/**
  1140. - * vidconsole_memmove() - Perform a memmove() within the frame buffer
  1141. - *
  1142. - * This handles a memmove(), e.g. for scrolling. It also updates the copy
  1143. - * framebuffer.
  1144. - *
  1145. - * @dev: Vidconsole device being updated
  1146. - * @dst: Destination address within the framebuffer (->fb)
  1147. - * @src: Source address within the framebuffer (->fb)
  1148. - * @size: Number of bytes to transfer
  1149. - * Return: 0 if OK, -EFAULT if the start address is before the start of the
  1150. - * frame buffer start
  1151. - */
  1152. -int vidconsole_memmove(struct udevice *dev, void *dst, const void *src,
  1153. - int size);
  1154. -#else
  1155. -static inline int vidconsole_sync_copy(struct udevice *dev, void *from,
  1156. - void *to)
  1157. -{
  1158. - return 0;
  1159. -}
  1160. -
  1161. -static inline int vidconsole_memmove(struct udevice *dev, void *dst,
  1162. - const void *src, int size)
  1163. -{
  1164. - memmove(dst, src, size);
  1165. -
  1166. - return 0;
  1167. -}
  1168. -
  1169. -#endif
  1170. -
  1171. /*
  1172. * Convert an UTF-8 byte into the corresponding character in the CP437
  1173. * code page. Returns 0 if that character is part of a multi-byte sequence.
  1174. --
  1175. 2.38.1