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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316
  1. From b4e57b1905d3d8457b09102c7e61ec1e379bec94 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. Link: https://lore.kernel.org/u-boot/20220609225921.62462-2-agraf@csgraf.de/
  11. Signed-off-by: Alexander Graf <agraf@csgraf.de>
  12. Reported-by: Da Xue <da@libre.computer>
  13. [Alper: Remove depends on CONFIG_DM_VIDEO, replaced by if VIDEO]
  14. Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
  15. ---
  16. drivers/video/Kconfig | 14 ++++++++++++
  17. drivers/video/video-uclass.c | 41 ++++++++++++++++++++++++++++++++++++
  18. include/video.h | 29 +++++++++++++++++++++++--
  19. 3 files changed, 82 insertions(+), 2 deletions(-)
  20. diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
  21. index c841b99bb30d..4a27fac2466d 100644
  22. --- a/drivers/video/Kconfig
  23. +++ b/drivers/video/Kconfig
  24. @@ -62,6 +62,20 @@ config VIDEO_COPY
  25. To use this, your video driver must set @copy_base in
  26. struct video_uc_plat.
  27. +config VIDEO_DAMAGE
  28. + bool "Enable damage tracking of frame buffer regions"
  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 0ce376ca3f14..48a053841e42 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. @@ -254,6 +256,45 @@ void video_set_default_colors(struct udevice *dev, bool invert)
  58. priv->colour_bg = video_index_to_colour(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 43f2e2c02f0f..4b35e97f79ef 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. @@ -211,8 +217,9 @@ int video_fill(struct udevice *dev, u32 colour);
  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. @@ -332,6 +339,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.39.1
  155. From 58484b3194d23f8b2f850aa598f007239a0e36bf 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. Link: https://lore.kernel.org/u-boot/20220609225921.62462-3-agraf@csgraf.de/
  162. Signed-off-by: Alexander Graf <agraf@csgraf.de>
  163. Reported-by: Da Xue <da@libre.computer>
  164. ---
  165. drivers/video/video-uclass.c | 2 ++
  166. 1 file changed, 2 insertions(+)
  167. diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c
  168. index 48a053841e42..f1fbeaadcbba 100644
  169. --- a/drivers/video/video-uclass.c
  170. +++ b/drivers/video/video-uclass.c
  171. @@ -160,6 +160,8 @@ int video_fill(struct udevice *dev, u32 colour)
  172. if (ret)
  173. return ret;
  174. + video_damage(dev, 0, 0, priv->xsize, priv->ysize);
  175. +
  176. return video_sync(dev, false);
  177. }
  178. --
  179. 2.39.1
  180. From 289e75fc23c203a7aead1a8cdf51c8d710d7242e Mon Sep 17 00:00:00 2001
  181. From: Alexander Graf <agraf@csgraf.de>
  182. Date: Fri, 10 Jun 2022 00:59:17 +0200
  183. Subject: [PATCH 3/7] vidconsole: Add damage notifications to all vidconsole
  184. drivers
  185. Now that we have a damage tracking API, let's populate damage done by
  186. vidconsole drivers. We try to declare as little memory as damaged as
  187. possible, with the exception of rotated screens that I couldn't get my
  188. head wrapped around. On those, we revert to the old behavior and mark
  189. the full screen as damaged on every update.
  190. Link: https://lore.kernel.org/u-boot/20220609225921.62462-4-agraf@csgraf.de/
  191. Signed-off-by: Alexander Graf <agraf@csgraf.de>
  192. Reported-by: Da Xue <da@libre.computer>
  193. [Alper: Fix priv->baseline to met->baseline]
  194. Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
  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 6859c9fa1163..5b90a0f91415 100644
  336. --- a/drivers/video/console_truetype.c
  337. +++ b/drivers/video/console_truetype.c
  338. @@ -145,6 +145,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. struct console_tt_metrics *met = priv->cur_met;
  345. void *end, *line;
  346. @@ -188,6 +189,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. @@ -195,6 +199,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. struct console_tt_metrics *met = priv->cur_met;
  361. void *dst;
  362. @@ -213,6 +218,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. @@ -370,6 +378,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 + met->baseline + yoff, width, height);
  376. +
  377. ret = vidconsole_sync_copy(dev, start, line);
  378. if (ret)
  379. return ret;
  380. @@ -437,6 +449,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.39.1
  392. From 2b0c183bd2440bf110c419cb161ce2d19d75db8a 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. Link: https://lore.kernel.org/u-boot/20220609225921.62462-5-agraf@csgraf.de/
  399. Signed-off-by: Alexander Graf <agraf@csgraf.de>
  400. Reported-by: Da Xue <da@libre.computer>
  401. ---
  402. drivers/video/video_bmp.c | 2 ++
  403. 1 file changed, 2 insertions(+)
  404. diff --git a/drivers/video/video_bmp.c b/drivers/video/video_bmp.c
  405. index 6188a13e44e4..7dc5b011a8af 100644
  406. --- a/drivers/video/video_bmp.c
  407. +++ b/drivers/video/video_bmp.c
  408. @@ -424,6 +424,8 @@ int video_bmp_display(struct udevice *dev, ulong bmp_image, int x, int y,
  409. break;
  410. };
  411. + video_damage(dev, x, y, width, height);
  412. +
  413. /* Find the position of the top left of the image in the framebuffer */
  414. fb = (uchar *)(priv->fb + y * priv->line_length + x * bpix / 8);
  415. ret = video_sync_copy(dev, start, fb);
  416. --
  417. 2.39.1
  418. From 48fffb757ef690fc5072e1c05226178cfef1b69a Mon Sep 17 00:00:00 2001
  419. From: Alexander Graf <agraf@csgraf.de>
  420. Date: Fri, 10 Jun 2022 00:59:19 +0200
  421. Subject: [PATCH 5/7] efi_loader: GOP: Add damage notification on BLT
  422. Now that we have a damage tracking API, let's populate damage done by
  423. UEFI payloads when they BLT data onto the screen.
  424. Link: https://lore.kernel.org/u-boot/20220609225921.62462-6-agraf@csgraf.de/
  425. Signed-off-by: Alexander Graf <agraf@csgraf.de>
  426. Reported-by: Da Xue <da@libre.computer>
  427. [Alper: Remove #ifdef DM_VIDEO context, replace DM_VIDEO with VIDEO]
  428. Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
  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 d1dc2f22d0f7..8e7f13bccfee 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_VIDEO))
  448. + video_damage(gopobj->vdev, dx, dy, width, height);
  449. +
  450. return EFI_SUCCESS;
  451. }
  452. @@ -468,7 +472,7 @@ 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;
  457. + struct udevice *vdev = NULL;
  458. struct video_priv *priv;
  459. /* We only support a single video output device for now */
  460. @@ -547,6 +551,7 @@ efi_status_t efi_gop_register(void)
  461. gopobj->info.pixels_per_scanline = col;
  462. gopobj->bpix = bpix;
  463. gopobj->fb = fb;
  464. + gopobj->vdev = vdev;
  465. return EFI_SUCCESS;
  466. }
  467. --
  468. 2.39.1
  469. From 28c2a50ea9f9402de67ce4830814e428f002e66b Mon Sep 17 00:00:00 2001
  470. From: Alexander Graf <agraf@csgraf.de>
  471. Date: Fri, 10 Jun 2022 00:59:20 +0200
  472. Subject: [PATCH 6/7] video: Only dcache flush damaged lines
  473. Now that we have a damage area tells us which parts of the frame buffer
  474. actually need updating, let's only dcache flush those on video_sync()
  475. calls. With this optimization in place, frame buffer updates - especially
  476. on large screen such as 4k displays - speed up significantly.
  477. Link: https://lore.kernel.org/u-boot/20220609225921.62462-7-agraf@csgraf.de/
  478. Signed-off-by: Alexander Graf <agraf@csgraf.de>
  479. Reported-by: Da Xue <da@libre.computer>
  480. ---
  481. drivers/video/video-uclass.c | 51 ++++++++++++++++++++++++++++++------
  482. 1 file changed, 43 insertions(+), 8 deletions(-)
  483. diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c
  484. index f1fbeaadcbba..bf93f524c7a0 100644
  485. --- a/drivers/video/video-uclass.c
  486. +++ b/drivers/video/video-uclass.c
  487. @@ -297,9 +297,45 @@ int video_damage(struct udevice *vid, int x, int y, int width, int height)
  488. return 0;
  489. }
  490. +#if defined(CONFIG_ARM) && !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
  491. +static void video_flush_dcache(struct udevice *vid)
  492. +{
  493. + struct video_priv *priv = dev_get_uclass_priv(vid);
  494. +
  495. + if (!priv->flush_dcache)
  496. + return;
  497. +
  498. + if (!CONFIG_IS_ENABLED(VIDEO_DAMAGE)) {
  499. + flush_dcache_range((ulong)priv->fb,
  500. + ALIGN((ulong)priv->fb + priv->fb_size,
  501. + CONFIG_SYS_CACHELINE_SIZE));
  502. +
  503. + return;
  504. + }
  505. +
  506. + if (priv->damage.endx && priv->damage.endy) {
  507. + int lstart = priv->damage.x * VNBYTES(priv->bpix);
  508. + int lend = priv->damage.endx * VNBYTES(priv->bpix);
  509. + int y;
  510. +
  511. + for (y = priv->damage.y; y < priv->damage.endy; y++) {
  512. + ulong fb = (ulong)priv->fb;
  513. + ulong start = fb + (y * priv->line_length) + lstart;
  514. + ulong end = start + lend - lstart;
  515. +
  516. + start = ALIGN_DOWN(start, CONFIG_SYS_CACHELINE_SIZE);
  517. + end = ALIGN(end, CONFIG_SYS_CACHELINE_SIZE);
  518. +
  519. + flush_dcache_range(start, end);
  520. + }
  521. + }
  522. +}
  523. +#endif
  524. +
  525. /* Flush video activity to the caches */
  526. int video_sync(struct udevice *vid, bool force)
  527. {
  528. + struct video_priv *priv = dev_get_uclass_priv(vid);
  529. struct video_ops *ops = video_get_ops(vid);
  530. int ret;
  531. @@ -315,15 +351,8 @@ int video_sync(struct udevice *vid, bool force)
  532. * out whether it exists? For now, ARM is safe.
  533. */
  534. #if defined(CONFIG_ARM) && !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
  535. - struct video_priv *priv = dev_get_uclass_priv(vid);
  536. -
  537. - if (priv->flush_dcache) {
  538. - flush_dcache_range((ulong)priv->fb,
  539. - ALIGN((ulong)priv->fb + priv->fb_size,
  540. - CONFIG_SYS_CACHELINE_SIZE));
  541. - }
  542. + video_flush_dcache(vid);
  543. #elif defined(CONFIG_VIDEO_SANDBOX_SDL)
  544. - struct video_priv *priv = dev_get_uclass_priv(vid);
  545. static ulong last_sync;
  546. if (force || get_timer(last_sync) > 100) {
  547. @@ -331,6 +360,12 @@ int video_sync(struct udevice *vid, bool force)
  548. last_sync = get_timer(0);
  549. }
  550. #endif
  551. +
  552. + if (CONFIG_IS_ENABLED(VIDEO_DAMAGE)) {
  553. + priv->damage.endx = 0;
  554. + priv->damage.endy = 0;
  555. + }
  556. +
  557. return 0;
  558. }
  559. --
  560. 2.39.1
  561. From 2b45c07c47f3765e3a04016b4618aa7a986d6ec0 Mon Sep 17 00:00:00 2001
  562. From: Alexander Graf <agraf@csgraf.de>
  563. Date: Fri, 10 Jun 2022 00:59:21 +0200
  564. Subject: [PATCH 7/7] video: Use VIDEO_DAMAGE for VIDEO_COPY
  565. CONFIG_VIDEO_COPY implemented a range based copying mechanism: If we
  566. print a single character, it will always copy the full range of bytes
  567. from the top left corner of the character to the lower right onto the
  568. uncached frame buffer. This includes pretty much the full line contents
  569. of the printed character.
  570. Since we now have proper damage tracking, let's make use of that to reduce
  571. the amount of data we need to copy. With this patch applied, we will only
  572. copy the tiny rectangle surrounding characters when we print them,
  573. speeding up the video console.
  574. As a bonus, we remove a lot of code.
  575. Link: https://lore.kernel.org/u-boot/20220609225921.62462-8-agraf@csgraf.de/
  576. Signed-off-by: Alexander Graf <agraf@csgraf.de>
  577. [Alper: Fix DM_VIDEO, met->font_size, memmove(dev, video.h conflict]
  578. Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
  579. ---
  580. configs/chromebook_coral_defconfig | 1 +
  581. configs/chromebook_link_defconfig | 1 +
  582. configs/chromebook_samus_defconfig | 1 +
  583. configs/minnowmax_defconfig | 1 +
  584. configs/sandbox_defconfig | 1 +
  585. configs/xilinx_zynqmp_virt_defconfig | 1 +
  586. drivers/video/Kconfig | 7 ++-
  587. drivers/video/console_normal.c | 14 +----
  588. drivers/video/console_rotate.c | 37 ++---------
  589. drivers/video/console_truetype.c | 22 ++-----
  590. drivers/video/vidconsole-uclass.c | 16 -----
  591. drivers/video/video-uclass.c | 91 ++++++++--------------------
  592. drivers/video/video_bmp.c | 7 ---
  593. include/video.h | 37 -----------
  594. include/video_console.h | 49 ---------------
  595. 15 files changed, 46 insertions(+), 240 deletions(-)
  596. diff --git a/configs/chromebook_coral_defconfig b/configs/chromebook_coral_defconfig
  597. index 45905c6792b8..6a299196ba47 100644
  598. --- a/configs/chromebook_coral_defconfig
  599. +++ b/configs/chromebook_coral_defconfig
  600. @@ -117,6 +117,7 @@ CONFIG_USB_XHCI_HCD=y
  601. CONFIG_USB_STORAGE=y
  602. CONFIG_USB_KEYBOARD=y
  603. CONFIG_VIDEO_COPY=y
  604. +CONFIG_VIDEO_DAMAGE=y
  605. CONFIG_FS_CBFS=y
  606. CONFIG_SPL_FS_CBFS=y
  607. CONFIG_FAT_WRITE=y
  608. diff --git a/configs/chromebook_link_defconfig b/configs/chromebook_link_defconfig
  609. index 541b7fadead4..b6b1734566ac 100644
  610. --- a/configs/chromebook_link_defconfig
  611. +++ b/configs/chromebook_link_defconfig
  612. @@ -74,6 +74,7 @@ CONFIG_TPM_TIS_LPC=y
  613. CONFIG_USB_STORAGE=y
  614. CONFIG_USB_KEYBOARD=y
  615. CONFIG_VIDEO_COPY=y
  616. +CONFIG_VIDEO_DAMAGE=y
  617. CONFIG_FRAMEBUFFER_SET_VESA_MODE=y
  618. CONFIG_FRAMEBUFFER_VESA_MODE_11A=y
  619. CONFIG_VIDEO_IVYBRIDGE_IGD=y
  620. diff --git a/configs/chromebook_samus_defconfig b/configs/chromebook_samus_defconfig
  621. index 27bf046f991a..4a1c6d13decf 100644
  622. --- a/configs/chromebook_samus_defconfig
  623. +++ b/configs/chromebook_samus_defconfig
  624. @@ -78,6 +78,7 @@ CONFIG_TPM_TIS_LPC=y
  625. CONFIG_USB_STORAGE=y
  626. CONFIG_USB_KEYBOARD=y
  627. CONFIG_VIDEO_COPY=y
  628. +CONFIG_VIDEO_DAMAGE=y
  629. CONFIG_FRAMEBUFFER_SET_VESA_MODE=y
  630. CONFIG_FRAMEBUFFER_VESA_MODE_11A=y
  631. CONFIG_TPM=y
  632. diff --git a/configs/minnowmax_defconfig b/configs/minnowmax_defconfig
  633. index e501cc55fb23..75184b512de1 100644
  634. --- a/configs/minnowmax_defconfig
  635. +++ b/configs/minnowmax_defconfig
  636. @@ -69,6 +69,7 @@ CONFIG_SPI=y
  637. CONFIG_USB_STORAGE=y
  638. CONFIG_USB_KEYBOARD=y
  639. CONFIG_VIDEO_COPY=y
  640. +CONFIG_VIDEO_DAMAGE=y
  641. CONFIG_FRAMEBUFFER_SET_VESA_MODE=y
  642. CONFIG_GENERATE_ACPI_TABLE=y
  643. # CONFIG_GZIP is not set
  644. diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
  645. index be46cae7aad7..75ece781fa4d 100644
  646. --- a/configs/sandbox_defconfig
  647. +++ b/configs/sandbox_defconfig
  648. @@ -297,6 +297,7 @@ CONFIG_USB_ETHER=y
  649. CONFIG_USB_ETH_CDC=y
  650. CONFIG_VIDEO=y
  651. CONFIG_VIDEO_COPY=y
  652. +CONFIG_VIDEO_DAMAGE=y
  653. CONFIG_CONSOLE_ROTATION=y
  654. CONFIG_CONSOLE_TRUETYPE=y
  655. CONFIG_CONSOLE_TRUETYPE_MAX_METRICS=10
  656. diff --git a/configs/xilinx_zynqmp_virt_defconfig b/configs/xilinx_zynqmp_virt_defconfig
  657. index 4732c39bdbe1..f42c545d4628 100644
  658. --- a/configs/xilinx_zynqmp_virt_defconfig
  659. +++ b/configs/xilinx_zynqmp_virt_defconfig
  660. @@ -220,6 +220,7 @@ CONFIG_USB_ETHER=y
  661. CONFIG_USB_ETH_CDC=y
  662. CONFIG_VIDEO=y
  663. CONFIG_VIDEO_COPY=y
  664. +CONFIG_VIDEO_DAMAGE=y
  665. CONFIG_DISPLAY=y
  666. CONFIG_VIDEO_SEPS525=y
  667. CONFIG_SPLASH_SCREEN=y
  668. diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
  669. index 4a27fac2466d..faebcbcbffd3 100644
  670. --- a/drivers/video/Kconfig
  671. +++ b/drivers/video/Kconfig
  672. @@ -53,11 +53,14 @@ config VIDEO_PCI_DEFAULT_FB_SIZE
  673. config VIDEO_COPY
  674. bool "Enable copying the frame buffer to a hardware copy"
  675. + depends on VIDEO_DAMAGE
  676. help
  677. On some machines (e.g. x86), reading from the frame buffer is very
  678. slow because it is uncached. To improve performance, this feature
  679. allows the frame buffer to be kept in cached memory (allocated by
  680. U-Boot) and then copied to the hardware frame-buffer as needed.
  681. + It uses the VIDEO_DAMAGE feature to keep track of regions to copy
  682. + and will only copy actually touched regions.
  683. To use this, your video driver must set @copy_base in
  684. struct video_uc_plat.
  685. @@ -71,11 +74,13 @@ config VIDEO_DAMAGE
  686. have to flush frame buffer contents from CPU caches into RAM which
  687. can be a slow operation.
  688. - This patch adds damage tracking to collect information about regions
  689. + This feature adds damage tracking to collect information about regions
  690. that received updates. When we want to sync, we then only flush
  691. regions of the frame buffer that were modified before, speeding up
  692. screen refreshes significantly.
  693. + It is also used by VIDEO_COPY to identify which regions changed.
  694. +
  695. config BACKLIGHT_PWM
  696. bool "Generic PWM based Backlight Driver"
  697. depends on BACKLIGHT && DM_PWM
  698. diff --git a/drivers/video/console_normal.c b/drivers/video/console_normal.c
  699. index e32fb23e3f9f..ebb7fdd69307 100644
  700. --- a/drivers/video/console_normal.c
  701. +++ b/drivers/video/console_normal.c
  702. @@ -21,7 +21,6 @@ static int console_normal_set_row(struct udevice *dev, uint row, int clr)
  703. struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
  704. void *line, *end;
  705. int pixels = VIDEO_FONT_HEIGHT * vid_priv->xsize;
  706. - int ret;
  707. int i;
  708. line = vid_priv->fb + row * VIDEO_FONT_HEIGHT * vid_priv->line_length;
  709. @@ -56,9 +55,6 @@ static int console_normal_set_row(struct udevice *dev, uint row, int clr)
  710. default:
  711. return -ENOSYS;
  712. }
  713. - ret = vidconsole_sync_copy(dev, line, end);
  714. - if (ret)
  715. - return ret;
  716. video_damage(dev->parent, 0, VIDEO_FONT_HEIGHT * row, vid_priv->xsize,
  717. VIDEO_FONT_HEIGHT);
  718. @@ -73,14 +69,11 @@ static int console_normal_move_rows(struct udevice *dev, uint rowdst,
  719. void *dst;
  720. void *src;
  721. int size;
  722. - int ret;
  723. dst = vid_priv->fb + rowdst * VIDEO_FONT_HEIGHT * vid_priv->line_length;
  724. src = vid_priv->fb + rowsrc * VIDEO_FONT_HEIGHT * vid_priv->line_length;
  725. size = VIDEO_FONT_HEIGHT * vid_priv->line_length * count;
  726. - ret = vidconsole_memmove(dev, dst, src, size);
  727. - if (ret)
  728. - return ret;
  729. + memmove(dst, src, size);
  730. video_damage(dev->parent, 0, VIDEO_FONT_HEIGHT * rowdst, vid_priv->xsize,
  731. VIDEO_FONT_HEIGHT * count);
  732. @@ -97,7 +90,6 @@ static int console_normal_putc_xy(struct udevice *dev, uint x_frac, uint y,
  733. int i, row;
  734. void *start;
  735. void *line;
  736. - int ret;
  737. start = vid_priv->fb + y * vid_priv->line_length +
  738. VID_TO_PIXEL(x_frac) * VNBYTES(vid_priv->bpix);
  739. @@ -168,10 +160,6 @@ static int console_normal_putc_xy(struct udevice *dev, uint x_frac, uint y,
  740. video_damage(dev->parent, VID_TO_PIXEL(x_frac), y, VIDEO_FONT_WIDTH,
  741. VIDEO_FONT_HEIGHT);
  742. - ret = vidconsole_sync_copy(dev, start, line);
  743. - if (ret)
  744. - return ret;
  745. -
  746. return VID_TO_POS(VIDEO_FONT_WIDTH);
  747. }
  748. diff --git a/drivers/video/console_rotate.c b/drivers/video/console_rotate.c
  749. index 56e20bb4f32e..ae0cbe41bfe4 100644
  750. --- a/drivers/video/console_rotate.c
  751. +++ b/drivers/video/console_rotate.c
  752. @@ -53,9 +53,6 @@ static int console_set_row_1(struct udevice *dev, uint row, int clr)
  753. }
  754. line += vid_priv->line_length;
  755. }
  756. - ret = vidconsole_sync_copy(dev, start, line);
  757. - if (ret)
  758. - return ret;
  759. video_damage(dev->parent,
  760. vid_priv->xsize - ((row + 1) * VIDEO_FONT_HEIGHT),
  761. @@ -81,10 +78,7 @@ static int console_move_rows_1(struct udevice *dev, uint rowdst, uint rowsrc,
  762. (rowsrc + count) * VIDEO_FONT_HEIGHT * pbytes;
  763. for (j = 0; j < vid_priv->ysize; j++) {
  764. - ret = vidconsole_memmove(dev, dst, src,
  765. - VIDEO_FONT_HEIGHT * pbytes * count);
  766. - if (ret)
  767. - return ret;
  768. + memmove(dst, src, VIDEO_FONT_HEIGHT * pbytes * count);
  769. src += vid_priv->line_length;
  770. dst += vid_priv->line_length;
  771. }
  772. @@ -158,10 +152,6 @@ static int console_putc_xy_1(struct udevice *dev, uint x_frac, uint y, char ch)
  773. mask >>= 1;
  774. }
  775. /* We draw backwards from 'start, so account for the first line */
  776. - ret = vidconsole_sync_copy(dev, start - vid_priv->line_length, line);
  777. - if (ret)
  778. - return ret;
  779. -
  780. video_damage(dev->parent,
  781. vid_priv->xsize - y - VIDEO_FONT_HEIGHT - 1,
  782. linenum - 1,
  783. @@ -213,9 +203,6 @@ static int console_set_row_2(struct udevice *dev, uint row, int clr)
  784. default:
  785. return -ENOSYS;
  786. }
  787. - ret = vidconsole_sync_copy(dev, start, end);
  788. - if (ret)
  789. - return ret;
  790. video_damage(dev->parent,
  791. 0,
  792. @@ -239,8 +226,8 @@ static int console_move_rows_2(struct udevice *dev, uint rowdst, uint rowsrc,
  793. vid_priv->line_length;
  794. src = end - (rowsrc + count) * VIDEO_FONT_HEIGHT *
  795. vid_priv->line_length;
  796. - vidconsole_memmove(dev, dst, src,
  797. - VIDEO_FONT_HEIGHT * vid_priv->line_length * count);
  798. + memmove(dst, src, VIDEO_FONT_HEIGHT *
  799. + vid_priv->line_length * count);
  800. video_damage(dev->parent,
  801. 0,
  802. @@ -313,10 +300,6 @@ static int console_putc_xy_2(struct udevice *dev, uint x_frac, uint y, char ch)
  803. }
  804. line -= vid_priv->line_length;
  805. }
  806. - /* Add 4 bytes to allow for the first pixel writen */
  807. - ret = vidconsole_sync_copy(dev, start + 4, line);
  808. - if (ret)
  809. - return ret;
  810. video_damage(dev->parent,
  811. x - VIDEO_FONT_WIDTH,
  812. @@ -367,9 +350,6 @@ static int console_set_row_3(struct udevice *dev, uint row, int clr)
  813. }
  814. line += vid_priv->line_length;
  815. }
  816. - ret = vidconsole_sync_copy(dev, start, line);
  817. - if (ret)
  818. - return ret;
  819. video_damage(dev->parent,
  820. row * VIDEO_FONT_HEIGHT,
  821. @@ -387,16 +367,13 @@ static int console_move_rows_3(struct udevice *dev, uint rowdst, uint rowsrc,
  822. int pbytes = VNBYTES(vid_priv->bpix);
  823. void *dst;
  824. void *src;
  825. - int j, ret;
  826. + int j;
  827. dst = vid_priv->fb + rowdst * VIDEO_FONT_HEIGHT * pbytes;
  828. src = vid_priv->fb + rowsrc * VIDEO_FONT_HEIGHT * pbytes;
  829. for (j = 0; j < vid_priv->ysize; j++) {
  830. - ret = vidconsole_memmove(dev, dst, src,
  831. - VIDEO_FONT_HEIGHT * pbytes * count);
  832. - if (ret)
  833. - return ret;
  834. + memmove(dst, src, VIDEO_FONT_HEIGHT * pbytes * count);
  835. src += vid_priv->line_length;
  836. dst += vid_priv->line_length;
  837. }
  838. @@ -468,10 +445,6 @@ static int console_putc_xy_3(struct udevice *dev, uint x_frac, uint y, char ch)
  839. mask >>= 1;
  840. }
  841. /* Add a line to allow for the first pixels writen */
  842. - ret = vidconsole_sync_copy(dev, start + vid_priv->line_length, line);
  843. - if (ret)
  844. - return ret;
  845. -
  846. video_damage(dev->parent,
  847. y,
  848. x - VIDEO_FONT_WIDTH + 1,
  849. diff --git a/drivers/video/console_truetype.c b/drivers/video/console_truetype.c
  850. index 5b90a0f91415..552d34191b64 100644
  851. --- a/drivers/video/console_truetype.c
  852. +++ b/drivers/video/console_truetype.c
  853. @@ -149,7 +149,6 @@ static int console_truetype_set_row(struct udevice *dev, uint row, int clr)
  854. struct console_tt_priv *priv = dev_get_priv(dev);
  855. struct console_tt_metrics *met = priv->cur_met;
  856. void *end, *line;
  857. - int ret;
  858. line = vid_priv->fb + row * met->font_size * vid_priv->line_length;
  859. end = line + met->font_size * vid_priv->line_length;
  860. @@ -185,9 +184,6 @@ static int console_truetype_set_row(struct udevice *dev, uint row, int clr)
  861. default:
  862. return -ENOSYS;
  863. }
  864. - ret = vidconsole_sync_copy(dev, line, end);
  865. - if (ret)
  866. - return ret;
  867. video_damage(dev->parent, 0, vc_priv->y_charsize * row, vid_priv->xsize,
  868. vc_priv->y_charsize);
  869. @@ -204,14 +200,11 @@ static int console_truetype_move_rows(struct udevice *dev, uint rowdst,
  870. struct console_tt_metrics *met = priv->cur_met;
  871. void *dst;
  872. void *src;
  873. - int i, diff, ret;
  874. + int i, diff;
  875. dst = vid_priv->fb + rowdst * met->font_size * vid_priv->line_length;
  876. src = vid_priv->fb + rowsrc * met->font_size * vid_priv->line_length;
  877. - ret = vidconsole_memmove(dev, dst, src, met->font_size *
  878. - vid_priv->line_length * count);
  879. - if (ret)
  880. - return ret;
  881. + memmove(dst, src, met->font_size * vid_priv->line_length * count);
  882. /* Scroll up our position history */
  883. diff = (rowsrc - rowdst) * met->font_size;
  884. @@ -241,7 +234,7 @@ static int console_truetype_putc_xy(struct udevice *dev, uint x, uint y,
  885. u8 *bits, *data;
  886. int advance;
  887. void *start, *end, *line;
  888. - int row, ret;
  889. + int row;
  890. /* First get some basic metrics about this character */
  891. stbtt_GetCodepointHMetrics(font, ch, &advance, &lsb);
  892. @@ -382,9 +375,6 @@ static int console_truetype_putc_xy(struct udevice *dev, uint x, uint y,
  893. video_damage(dev->parent, VID_TO_PIXEL(x) + xoff,
  894. y + met->baseline + yoff, width, height);
  895. - ret = vidconsole_sync_copy(dev, start, line);
  896. - if (ret)
  897. - return ret;
  898. free(data);
  899. return width_frac;
  900. @@ -410,7 +400,7 @@ static int console_truetype_erase(struct udevice *dev, int xstart, int ystart,
  901. struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
  902. void *start, *line;
  903. int pixels = xend - xstart;
  904. - int row, i, ret;
  905. + int row, i;
  906. start = vid_priv->fb + ystart * vid_priv->line_length;
  907. start += xstart * VNBYTES(vid_priv->bpix);
  908. @@ -452,10 +442,6 @@ static int console_truetype_erase(struct udevice *dev, int xstart, int ystart,
  909. video_damage(dev->parent, xstart, ystart, xend - xstart, yend - ystart);
  910. - ret = vidconsole_sync_copy(dev, start, line);
  911. - if (ret)
  912. - return ret;
  913. -
  914. return 0;
  915. }
  916. diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c
  917. index f590ab39d5d6..8792b773b942 100644
  918. --- a/drivers/video/vidconsole-uclass.c
  919. +++ b/drivers/video/vidconsole-uclass.c
  920. @@ -647,22 +647,6 @@ UCLASS_DRIVER(vidconsole) = {
  921. .per_device_auto = sizeof(struct vidconsole_priv),
  922. };
  923. -#ifdef CONFIG_VIDEO_COPY
  924. -int vidconsole_sync_copy(struct udevice *dev, void *from, void *to)
  925. -{
  926. - struct udevice *vid = dev_get_parent(dev);
  927. -
  928. - return video_sync_copy(vid, from, to);
  929. -}
  930. -
  931. -int vidconsole_memmove(struct udevice *dev, void *dst, const void *src,
  932. - int size)
  933. -{
  934. - memmove(dst, src, size);
  935. - return vidconsole_sync_copy(dev, dst, dst + size);
  936. -}
  937. -#endif
  938. -
  939. void vidconsole_position_cursor(struct udevice *dev, unsigned col, unsigned row)
  940. {
  941. struct vidconsole_priv *priv = dev_get_uclass_priv(dev);
  942. diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c
  943. index bf93f524c7a0..73601712ef92 100644
  944. --- a/drivers/video/video-uclass.c
  945. +++ b/drivers/video/video-uclass.c
  946. @@ -131,7 +131,6 @@ int video_reserve(ulong *addrp)
  947. int video_fill(struct udevice *dev, u32 colour)
  948. {
  949. struct video_priv *priv = dev_get_uclass_priv(dev);
  950. - int ret;
  951. switch (priv->bpix) {
  952. case VIDEO_BPP16:
  953. @@ -156,9 +155,6 @@ int video_fill(struct udevice *dev, u32 colour)
  954. memset(priv->fb, colour, priv->fb_size);
  955. break;
  956. }
  957. - ret = video_sync_copy(dev, priv->fb, priv->fb + priv->fb_size);
  958. - if (ret)
  959. - return ret;
  960. video_damage(dev, 0, 0, priv->xsize, priv->ysize);
  961. @@ -332,6 +328,27 @@ static void video_flush_dcache(struct udevice *vid)
  962. }
  963. #endif
  964. +static void video_flush_copy(struct udevice *vid)
  965. +{
  966. + struct video_priv *priv = dev_get_uclass_priv(vid);
  967. +
  968. + if (!priv->copy_fb)
  969. + return;
  970. +
  971. + if (priv->damage.endx && priv->damage.endy) {
  972. + int lstart = priv->damage.x * VNBYTES(priv->bpix);
  973. + int lend = priv->damage.endx * VNBYTES(priv->bpix);
  974. + int y;
  975. +
  976. + for (y = priv->damage.y; y < priv->damage.endy; y++) {
  977. + ulong offset = (y * priv->line_length) + lstart;
  978. + ulong len = lend - lstart;
  979. +
  980. + memcpy(priv->copy_fb + offset, priv->fb + offset, len);
  981. + }
  982. + }
  983. +}
  984. +
  985. /* Flush video activity to the caches */
  986. int video_sync(struct udevice *vid, bool force)
  987. {
  988. @@ -339,6 +356,9 @@ int video_sync(struct udevice *vid, bool force)
  989. struct video_ops *ops = video_get_ops(vid);
  990. int ret;
  991. + if (CONFIG_IS_ENABLED(VIDEO_COPY))
  992. + video_flush_copy(vid);
  993. +
  994. if (ops && ops->video_sync) {
  995. ret = ops->video_sync(vid);
  996. if (ret)
  997. @@ -413,69 +433,6 @@ int video_get_ysize(struct udevice *dev)
  998. return priv->ysize;
  999. }
  1000. -#ifdef CONFIG_VIDEO_COPY
  1001. -int video_sync_copy(struct udevice *dev, void *from, void *to)
  1002. -{
  1003. - struct video_priv *priv = dev_get_uclass_priv(dev);
  1004. -
  1005. - if (priv->copy_fb) {
  1006. - long offset, size;
  1007. -
  1008. - /* Find the offset of the first byte to copy */
  1009. - if ((ulong)to > (ulong)from) {
  1010. - size = to - from;
  1011. - offset = from - priv->fb;
  1012. - } else {
  1013. - size = from - to;
  1014. - offset = to - priv->fb;
  1015. - }
  1016. -
  1017. - /*
  1018. - * Allow a bit of leeway for valid requests somewhere near the
  1019. - * frame buffer
  1020. - */
  1021. - if (offset < -priv->fb_size || offset > 2 * priv->fb_size) {
  1022. -#ifdef DEBUG
  1023. - char str[120];
  1024. -
  1025. - snprintf(str, sizeof(str),
  1026. - "[** FAULT sync_copy fb=%p, from=%p, to=%p, offset=%lx]",
  1027. - priv->fb, from, to, offset);
  1028. - console_puts_select_stderr(true, str);
  1029. -#endif
  1030. - return -EFAULT;
  1031. - }
  1032. -
  1033. - /*
  1034. - * Silently crop the memcpy. This allows callers to avoid doing
  1035. - * this themselves. It is common for the end pointer to go a
  1036. - * few lines after the end of the frame buffer, since most of
  1037. - * the update algorithms terminate a line after their last write
  1038. - */
  1039. - if (offset + size > priv->fb_size) {
  1040. - size = priv->fb_size - offset;
  1041. - } else if (offset < 0) {
  1042. - size += offset;
  1043. - offset = 0;
  1044. - }
  1045. -
  1046. - memcpy(priv->copy_fb + offset, priv->fb + offset, size);
  1047. - }
  1048. -
  1049. - return 0;
  1050. -}
  1051. -
  1052. -int video_sync_copy_all(struct udevice *dev)
  1053. -{
  1054. - struct video_priv *priv = dev_get_uclass_priv(dev);
  1055. -
  1056. - video_sync_copy(dev, priv->fb, priv->fb + priv->fb_size);
  1057. -
  1058. - return 0;
  1059. -}
  1060. -
  1061. -#endif
  1062. -
  1063. #define SPLASH_DECL(_name) \
  1064. extern u8 __splash_ ## _name ## _begin[]; \
  1065. extern u8 __splash_ ## _name ## _end[]
  1066. diff --git a/drivers/video/video_bmp.c b/drivers/video/video_bmp.c
  1067. index 7dc5b011a8af..609dc9fef695 100644
  1068. --- a/drivers/video/video_bmp.c
  1069. +++ b/drivers/video/video_bmp.c
  1070. @@ -254,7 +254,6 @@ int video_bmp_display(struct udevice *dev, ulong bmp_image, int x, int y,
  1071. enum video_format eformat;
  1072. struct bmp_color_table_entry *palette;
  1073. int hdr_size;
  1074. - int ret;
  1075. if (!bmp || !(bmp->header.signature[0] == 'B' &&
  1076. bmp->header.signature[1] == 'M')) {
  1077. @@ -426,11 +425,5 @@ int video_bmp_display(struct udevice *dev, ulong bmp_image, int x, int y,
  1078. video_damage(dev, x, y, width, height);
  1079. - /* Find the position of the top left of the image in the framebuffer */
  1080. - fb = (uchar *)(priv->fb + y * priv->line_length + x * bpix / 8);
  1081. - ret = video_sync_copy(dev, start, fb);
  1082. - if (ret)
  1083. - return log_ret(ret);
  1084. -
  1085. return video_sync(dev, false);
  1086. }
  1087. diff --git a/include/video.h b/include/video.h
  1088. index 4b35e97f79ef..e1162fc53311 100644
  1089. --- a/include/video.h
  1090. +++ b/include/video.h
  1091. @@ -302,43 +302,6 @@ void video_set_default_colors(struct udevice *dev, bool invert);
  1092. */
  1093. int video_default_font_height(struct udevice *dev);
  1094. -#ifdef CONFIG_VIDEO_COPY
  1095. -/**
  1096. - * vidconsole_sync_copy() - Sync back to the copy framebuffer
  1097. - *
  1098. - * This ensures that the copy framebuffer has the same data as the framebuffer
  1099. - * for a particular region. It should be called after the framebuffer is updated
  1100. - *
  1101. - * @from and @to can be in either order. The region between them is synced.
  1102. - *
  1103. - * @dev: Vidconsole device being updated
  1104. - * @from: Start/end address within the framebuffer (->fb)
  1105. - * @to: Other address within the frame buffer
  1106. - * Return: 0 if OK, -EFAULT if the start address is before the start of the
  1107. - * frame buffer start
  1108. - */
  1109. -int video_sync_copy(struct udevice *dev, void *from, void *to);
  1110. -
  1111. -/**
  1112. - * video_sync_copy_all() - Sync the entire framebuffer to the copy
  1113. - *
  1114. - * @dev: Vidconsole device being updated
  1115. - * Return: 0 (always)
  1116. - */
  1117. -int video_sync_copy_all(struct udevice *dev);
  1118. -#else
  1119. -static inline int video_sync_copy(struct udevice *dev, void *from, void *to)
  1120. -{
  1121. - return 0;
  1122. -}
  1123. -
  1124. -static inline int video_sync_copy_all(struct udevice *dev)
  1125. -{
  1126. - return 0;
  1127. -}
  1128. -
  1129. -#endif
  1130. -
  1131. /**
  1132. * video_damage() - Notify the video subsystem about screen updates.
  1133. *
  1134. diff --git a/include/video_console.h b/include/video_console.h
  1135. index 1ef7b442fcca..d1e44c4530e2 100644
  1136. --- a/include/video_console.h
  1137. +++ b/include/video_console.h
  1138. @@ -258,55 +258,6 @@ int vidconsole_select_font(struct udevice *dev, const char *name, uint size);
  1139. */
  1140. const char *vidconsole_get_font(struct udevice *dev, uint *sizep);
  1141. -#ifdef CONFIG_VIDEO_COPY
  1142. -/**
  1143. - * vidconsole_sync_copy() - Sync back to the copy framebuffer
  1144. - *
  1145. - * This ensures that the copy framebuffer has the same data as the framebuffer
  1146. - * for a particular region. It should be called after the framebuffer is updated
  1147. - *
  1148. - * @from and @to can be in either order. The region between them is synced.
  1149. - *
  1150. - * @dev: Vidconsole device being updated
  1151. - * @from: Start/end address within the framebuffer (->fb)
  1152. - * @to: Other address within the frame buffer
  1153. - * Return: 0 if OK, -EFAULT if the start address is before the start of the
  1154. - * frame buffer start
  1155. - */
  1156. -int vidconsole_sync_copy(struct udevice *dev, void *from, void *to);
  1157. -
  1158. -/**
  1159. - * vidconsole_memmove() - Perform a memmove() within the frame buffer
  1160. - *
  1161. - * This handles a memmove(), e.g. for scrolling. It also updates the copy
  1162. - * framebuffer.
  1163. - *
  1164. - * @dev: Vidconsole device being updated
  1165. - * @dst: Destination address within the framebuffer (->fb)
  1166. - * @src: Source address within the framebuffer (->fb)
  1167. - * @size: Number of bytes to transfer
  1168. - * Return: 0 if OK, -EFAULT if the start address is before the start of the
  1169. - * frame buffer start
  1170. - */
  1171. -int vidconsole_memmove(struct udevice *dev, void *dst, const void *src,
  1172. - int size);
  1173. -#else
  1174. -static inline int vidconsole_sync_copy(struct udevice *dev, void *from,
  1175. - void *to)
  1176. -{
  1177. - return 0;
  1178. -}
  1179. -
  1180. -static inline int vidconsole_memmove(struct udevice *dev, void *dst,
  1181. - const void *src, int size)
  1182. -{
  1183. - memmove(dst, src, size);
  1184. -
  1185. - return 0;
  1186. -}
  1187. -
  1188. -#endif
  1189. -
  1190. /*
  1191. * Convert an UTF-8 byte into the corresponding character in the CP437
  1192. * code page. Returns 0 if that character is part of a multi-byte sequence.
  1193. --
  1194. 2.39.1