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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405
  1. From 3efc90a6ea3bb88b66af7f7096e8168c2cc34aa6 Mon Sep 17 00:00:00 2001
  2. From: Alper Nebi Yasak <alpernebiyasak@gmail.com>
  3. Date: Fri, 18 Aug 2023 13:31:36 +0300
  4. Subject: [PATCH 01/13] video: test: Split copy frame buffer check into a
  5. function
  6. While checking frame buffer contents, the video tests also check if the
  7. copy frame buffer contents match the main frame buffer. To test if only
  8. the modified regions are updated after a sync, we will need to create
  9. situations where the two are mismatched. Split this check into another
  10. function that we can skip calling, since we won't want it to error on
  11. those mismatched cases.
  12. Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
  13. Reviewed-by: Simon Glass <sjg@chromium.org>
  14. Link: https://lore.kernel.org/u-boot/20230821135111.3558478-2-alpernebiyasak@gmail.com/
  15. ---
  16. test/dm/video.c | 69 +++++++++++++++++++++++++++++++++++++++++--------
  17. 1 file changed, 58 insertions(+), 11 deletions(-)
  18. diff --git a/test/dm/video.c b/test/dm/video.c
  19. index 7dfbeb9555d1..14e6af5181f1 100644
  20. --- a/test/dm/video.c
  21. +++ b/test/dm/video.c
  22. @@ -54,9 +54,6 @@ DM_TEST(dm_test_video_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
  23. * size of the compressed data. This provides a pretty good level of
  24. * certainty and the resulting tests need only check a single value.
  25. *
  26. - * If the copy framebuffer is enabled, this compares it to the main framebuffer
  27. - * too.
  28. - *
  29. * @uts: Test state
  30. * @dev: Video device
  31. * Return: compressed size of the frame buffer, or -ve on error
  32. @@ -65,7 +62,6 @@ static int compress_frame_buffer(struct unit_test_state *uts,
  33. struct udevice *dev)
  34. {
  35. struct video_priv *priv = dev_get_uclass_priv(dev);
  36. - struct video_priv *uc_priv = dev_get_uclass_priv(dev);
  37. uint destlen;
  38. void *dest;
  39. int ret;
  40. @@ -81,16 +77,34 @@ static int compress_frame_buffer(struct unit_test_state *uts,
  41. if (ret)
  42. return ret;
  43. - /* Check here that the copy frame buffer is working correctly */
  44. - if (IS_ENABLED(CONFIG_VIDEO_COPY)) {
  45. - ut_assertf(!memcmp(uc_priv->fb, uc_priv->copy_fb,
  46. - uc_priv->fb_size),
  47. - "Copy framebuffer does not match fb");
  48. - }
  49. -
  50. return destlen;
  51. }
  52. +/**
  53. + * check_copy_frame_buffer() - Compare main frame buffer to copy
  54. + *
  55. + * If the copy frame buffer is enabled, this compares it to the main
  56. + * frame buffer. Normally they should have the same contents after a
  57. + * sync.
  58. + *
  59. + * @uts: Test state
  60. + * @dev: Video device
  61. + * Return: 0, or -ve on error
  62. + */
  63. +static int check_copy_frame_buffer(struct unit_test_state *uts,
  64. + struct udevice *dev)
  65. +{
  66. + struct video_priv *priv = dev_get_uclass_priv(dev);
  67. +
  68. + if (!IS_ENABLED(CONFIG_VIDEO_COPY))
  69. + return 0;
  70. +
  71. + ut_assertf(!memcmp(priv->fb, priv->copy_fb, priv->fb_size),
  72. + "Copy framebuffer does not match fb");
  73. +
  74. + return 0;
  75. +}
  76. +
  77. /*
  78. * Call this function at any point to halt and show the current display. Be
  79. * sure to run the test with the -l flag.
  80. @@ -154,24 +168,30 @@ static int dm_test_video_text(struct unit_test_state *uts)
  81. ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
  82. ut_assertok(vidconsole_select_font(con, "8x16", 0));
  83. ut_asserteq(46, compress_frame_buffer(uts, dev));
  84. + ut_assertok(check_copy_frame_buffer(uts, dev));
  85. ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
  86. vidconsole_putc_xy(con, 0, 0, 'a');
  87. ut_asserteq(79, compress_frame_buffer(uts, dev));
  88. + ut_assertok(check_copy_frame_buffer(uts, dev));
  89. vidconsole_putc_xy(con, 0, 0, ' ');
  90. ut_asserteq(46, compress_frame_buffer(uts, dev));
  91. + ut_assertok(check_copy_frame_buffer(uts, dev));
  92. for (i = 0; i < 20; i++)
  93. vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i);
  94. ut_asserteq(273, compress_frame_buffer(uts, dev));
  95. + ut_assertok(check_copy_frame_buffer(uts, dev));
  96. vidconsole_set_row(con, 0, WHITE);
  97. ut_asserteq(46, compress_frame_buffer(uts, dev));
  98. + ut_assertok(check_copy_frame_buffer(uts, dev));
  99. for (i = 0; i < 20; i++)
  100. vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i);
  101. ut_asserteq(273, compress_frame_buffer(uts, dev));
  102. + ut_assertok(check_copy_frame_buffer(uts, dev));
  103. return 0;
  104. }
  105. @@ -190,24 +210,30 @@ static int dm_test_video_text_12x22(struct unit_test_state *uts)
  106. ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
  107. ut_assertok(vidconsole_select_font(con, "12x22", 0));
  108. ut_asserteq(46, compress_frame_buffer(uts, dev));
  109. + ut_assertok(check_copy_frame_buffer(uts, dev));
  110. ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
  111. vidconsole_putc_xy(con, 0, 0, 'a');
  112. ut_asserteq(89, compress_frame_buffer(uts, dev));
  113. + ut_assertok(check_copy_frame_buffer(uts, dev));
  114. vidconsole_putc_xy(con, 0, 0, ' ');
  115. ut_asserteq(46, compress_frame_buffer(uts, dev));
  116. + ut_assertok(check_copy_frame_buffer(uts, dev));
  117. for (i = 0; i < 20; i++)
  118. vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i);
  119. ut_asserteq(363, compress_frame_buffer(uts, dev));
  120. + ut_assertok(check_copy_frame_buffer(uts, dev));
  121. vidconsole_set_row(con, 0, WHITE);
  122. ut_asserteq(46, compress_frame_buffer(uts, dev));
  123. + ut_assertok(check_copy_frame_buffer(uts, dev));
  124. for (i = 0; i < 20; i++)
  125. vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i);
  126. ut_asserteq(363, compress_frame_buffer(uts, dev));
  127. + ut_assertok(check_copy_frame_buffer(uts, dev));
  128. return 0;
  129. }
  130. @@ -225,6 +251,7 @@ static int dm_test_video_chars(struct unit_test_state *uts)
  131. ut_assertok(vidconsole_select_font(con, "8x16", 0));
  132. vidconsole_put_string(con, test_string);
  133. ut_asserteq(466, compress_frame_buffer(uts, dev));
  134. + ut_assertok(check_copy_frame_buffer(uts, dev));
  135. return 0;
  136. }
  137. @@ -246,19 +273,23 @@ static int dm_test_video_ansi(struct unit_test_state *uts)
  138. video_clear(con->parent);
  139. video_sync(con->parent, false);
  140. ut_asserteq(46, compress_frame_buffer(uts, dev));
  141. + ut_assertok(check_copy_frame_buffer(uts, dev));
  142. /* test clear escape sequence: [2J */
  143. vidconsole_put_string(con, "A\tB\tC"ANSI_ESC"[2J");
  144. ut_asserteq(46, compress_frame_buffer(uts, dev));
  145. + ut_assertok(check_copy_frame_buffer(uts, dev));
  146. /* test set-cursor: [%d;%df */
  147. vidconsole_put_string(con, "abc"ANSI_ESC"[2;2fab"ANSI_ESC"[4;4fcd");
  148. ut_asserteq(143, compress_frame_buffer(uts, dev));
  149. + ut_assertok(check_copy_frame_buffer(uts, dev));
  150. /* test colors (30-37 fg color, 40-47 bg color) */
  151. vidconsole_put_string(con, ANSI_ESC"[30;41mfoo"); /* black on red */
  152. vidconsole_put_string(con, ANSI_ESC"[33;44mbar"); /* yellow on blue */
  153. ut_asserteq(272, compress_frame_buffer(uts, dev));
  154. + ut_assertok(check_copy_frame_buffer(uts, dev));
  155. return 0;
  156. }
  157. @@ -291,11 +322,13 @@ static int check_vidconsole_output(struct unit_test_state *uts, int rot,
  158. ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
  159. ut_assertok(vidconsole_select_font(con, "8x16", 0));
  160. ut_asserteq(46, compress_frame_buffer(uts, dev));
  161. + ut_assertok(check_copy_frame_buffer(uts, dev));
  162. /* Check display wrap */
  163. for (i = 0; i < 120; i++)
  164. vidconsole_put_char(con, 'A' + i % 50);
  165. ut_asserteq(wrap_size, compress_frame_buffer(uts, dev));
  166. + ut_assertok(check_copy_frame_buffer(uts, dev));
  167. /* Check display scrolling */
  168. for (i = 0; i < SCROLL_LINES; i++) {
  169. @@ -303,11 +336,13 @@ static int check_vidconsole_output(struct unit_test_state *uts, int rot,
  170. vidconsole_put_char(con, '\n');
  171. }
  172. ut_asserteq(scroll_size, compress_frame_buffer(uts, dev));
  173. + ut_assertok(check_copy_frame_buffer(uts, dev));
  174. /* If we scroll enough, the screen becomes blank again */
  175. for (i = 0; i < SCROLL_LINES; i++)
  176. vidconsole_put_char(con, '\n');
  177. ut_asserteq(46, compress_frame_buffer(uts, dev));
  178. + ut_assertok(check_copy_frame_buffer(uts, dev));
  179. return 0;
  180. }
  181. @@ -382,6 +417,7 @@ static int dm_test_video_bmp(struct unit_test_state *uts)
  182. ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
  183. ut_asserteq(1368, compress_frame_buffer(uts, dev));
  184. + ut_assertok(check_copy_frame_buffer(uts, dev));
  185. return 0;
  186. }
  187. @@ -401,6 +437,7 @@ static int dm_test_video_bmp8(struct unit_test_state *uts)
  188. ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
  189. ut_asserteq(1247, compress_frame_buffer(uts, dev));
  190. + ut_assertok(check_copy_frame_buffer(uts, dev));
  191. return 0;
  192. }
  193. @@ -424,6 +461,7 @@ static int dm_test_video_bmp16(struct unit_test_state *uts)
  194. ut_assertok(video_bmp_display(dev, dst, 0, 0, false));
  195. ut_asserteq(3700, compress_frame_buffer(uts, dev));
  196. + ut_assertok(check_copy_frame_buffer(uts, dev));
  197. return 0;
  198. }
  199. @@ -447,6 +485,7 @@ static int dm_test_video_bmp24(struct unit_test_state *uts)
  200. ut_assertok(video_bmp_display(dev, dst, 0, 0, false));
  201. ut_asserteq(3656, compress_frame_buffer(uts, dev));
  202. + ut_assertok(check_copy_frame_buffer(uts, dev));
  203. return 0;
  204. }
  205. @@ -470,6 +509,7 @@ static int dm_test_video_bmp24_32(struct unit_test_state *uts)
  206. ut_assertok(video_bmp_display(dev, dst, 0, 0, false));
  207. ut_asserteq(6827, compress_frame_buffer(uts, dev));
  208. + ut_assertok(check_copy_frame_buffer(uts, dev));
  209. return 0;
  210. }
  211. @@ -488,6 +528,7 @@ static int dm_test_video_bmp32(struct unit_test_state *uts)
  212. ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
  213. ut_asserteq(2024, compress_frame_buffer(uts, dev));
  214. + ut_assertok(check_copy_frame_buffer(uts, dev));
  215. return 0;
  216. }
  217. @@ -504,6 +545,7 @@ static int dm_test_video_bmp_comp(struct unit_test_state *uts)
  218. ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
  219. ut_asserteq(1368, compress_frame_buffer(uts, dev));
  220. + ut_assertok(check_copy_frame_buffer(uts, dev));
  221. return 0;
  222. }
  223. @@ -523,6 +565,7 @@ static int dm_test_video_comp_bmp32(struct unit_test_state *uts)
  224. ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
  225. ut_asserteq(2024, compress_frame_buffer(uts, dev));
  226. + ut_assertok(check_copy_frame_buffer(uts, dev));
  227. return 0;
  228. }
  229. @@ -542,6 +585,7 @@ static int dm_test_video_comp_bmp8(struct unit_test_state *uts)
  230. ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
  231. ut_asserteq(1247, compress_frame_buffer(uts, dev));
  232. + ut_assertok(check_copy_frame_buffer(uts, dev));
  233. return 0;
  234. }
  235. @@ -557,6 +601,7 @@ static int dm_test_video_truetype(struct unit_test_state *uts)
  236. ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
  237. vidconsole_put_string(con, test_string);
  238. ut_asserteq(12174, compress_frame_buffer(uts, dev));
  239. + ut_assertok(check_copy_frame_buffer(uts, dev));
  240. return 0;
  241. }
  242. @@ -578,6 +623,7 @@ static int dm_test_video_truetype_scroll(struct unit_test_state *uts)
  243. ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
  244. vidconsole_put_string(con, test_string);
  245. ut_asserteq(34287, compress_frame_buffer(uts, dev));
  246. + ut_assertok(check_copy_frame_buffer(uts, dev));
  247. return 0;
  248. }
  249. @@ -599,6 +645,7 @@ static int dm_test_video_truetype_bs(struct unit_test_state *uts)
  250. ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
  251. vidconsole_put_string(con, test_string);
  252. ut_asserteq(29471, compress_frame_buffer(uts, dev));
  253. + ut_assertok(check_copy_frame_buffer(uts, dev));
  254. return 0;
  255. }
  256. base-commit: 475aa8345a78396d39b42f96eccecd37ebe24e99
  257. --
  258. 2.45.2
  259. From 19c878635c1271c79a017ea3a860b9a2f1a3fed9 Mon Sep 17 00:00:00 2001
  260. From: Alper Nebi Yasak <alpernebiyasak@gmail.com>
  261. Date: Sun, 20 Aug 2023 17:46:46 +0300
  262. Subject: [PATCH 02/13] video: test: Support checking copy frame buffer
  263. contents
  264. The video tests have a helper function to generate a pseudo-digest of
  265. frame buffer contents, but it only does so for the main one. There is
  266. another check that the copy frame buffer is the same as that. But
  267. neither is enough to test if only the modified regions are copied to the
  268. copy frame buffer, since we will want the two to be different in very
  269. specific ways.
  270. Add a boolean argument to the existing helper function to indicate which
  271. frame buffer we want to inspect, and update the existing callers.
  272. Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
  273. Reviewed-by: Simon Glass <sjg@chromium.org>
  274. Link: https://lore.kernel.org/u-boot/20230821135111.3558478-3-alpernebiyasak@gmail.com/
  275. ---
  276. test/dm/video.c | 76 ++++++++++++++++++++++++++-----------------------
  277. 1 file changed, 41 insertions(+), 35 deletions(-)
  278. diff --git a/test/dm/video.c b/test/dm/video.c
  279. index 14e6af5181f1..50374cafc009 100644
  280. --- a/test/dm/video.c
  281. +++ b/test/dm/video.c
  282. @@ -56,22 +56,28 @@ DM_TEST(dm_test_video_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
  283. *
  284. * @uts: Test state
  285. * @dev: Video device
  286. + * @use_copy: Use copy frame buffer if available
  287. * Return: compressed size of the frame buffer, or -ve on error
  288. */
  289. static int compress_frame_buffer(struct unit_test_state *uts,
  290. - struct udevice *dev)
  291. + struct udevice *dev,
  292. + bool use_copy)
  293. {
  294. struct video_priv *priv = dev_get_uclass_priv(dev);
  295. uint destlen;
  296. void *dest;
  297. int ret;
  298. + if (!IS_ENABLED(CONFIG_VIDEO_COPY))
  299. + use_copy = false;
  300. +
  301. destlen = priv->fb_size;
  302. dest = malloc(priv->fb_size);
  303. if (!dest)
  304. return -ENOMEM;
  305. ret = BZ2_bzBuffToBuffCompress(dest, &destlen,
  306. - priv->fb, priv->fb_size,
  307. + use_copy ? priv->copy_fb : priv->fb,
  308. + priv->fb_size,
  309. 3, 0, 0);
  310. free(dest);
  311. if (ret)
  312. @@ -167,30 +173,30 @@ static int dm_test_video_text(struct unit_test_state *uts)
  313. ut_assertok(video_get_nologo(uts, &dev));
  314. ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
  315. ut_assertok(vidconsole_select_font(con, "8x16", 0));
  316. - ut_asserteq(46, compress_frame_buffer(uts, dev));
  317. + ut_asserteq(46, compress_frame_buffer(uts, dev, false));
  318. ut_assertok(check_copy_frame_buffer(uts, dev));
  319. ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
  320. vidconsole_putc_xy(con, 0, 0, 'a');
  321. - ut_asserteq(79, compress_frame_buffer(uts, dev));
  322. + ut_asserteq(79, compress_frame_buffer(uts, dev, false));
  323. ut_assertok(check_copy_frame_buffer(uts, dev));
  324. vidconsole_putc_xy(con, 0, 0, ' ');
  325. - ut_asserteq(46, compress_frame_buffer(uts, dev));
  326. + ut_asserteq(46, compress_frame_buffer(uts, dev, false));
  327. ut_assertok(check_copy_frame_buffer(uts, dev));
  328. for (i = 0; i < 20; i++)
  329. vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i);
  330. - ut_asserteq(273, compress_frame_buffer(uts, dev));
  331. + ut_asserteq(273, compress_frame_buffer(uts, dev, false));
  332. ut_assertok(check_copy_frame_buffer(uts, dev));
  333. vidconsole_set_row(con, 0, WHITE);
  334. - ut_asserteq(46, compress_frame_buffer(uts, dev));
  335. + ut_asserteq(46, compress_frame_buffer(uts, dev, false));
  336. ut_assertok(check_copy_frame_buffer(uts, dev));
  337. for (i = 0; i < 20; i++)
  338. vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i);
  339. - ut_asserteq(273, compress_frame_buffer(uts, dev));
  340. + ut_asserteq(273, compress_frame_buffer(uts, dev, false));
  341. ut_assertok(check_copy_frame_buffer(uts, dev));
  342. return 0;
  343. @@ -209,30 +215,30 @@ static int dm_test_video_text_12x22(struct unit_test_state *uts)
  344. ut_assertok(video_get_nologo(uts, &dev));
  345. ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
  346. ut_assertok(vidconsole_select_font(con, "12x22", 0));
  347. - ut_asserteq(46, compress_frame_buffer(uts, dev));
  348. + ut_asserteq(46, compress_frame_buffer(uts, dev, false));
  349. ut_assertok(check_copy_frame_buffer(uts, dev));
  350. ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
  351. vidconsole_putc_xy(con, 0, 0, 'a');
  352. - ut_asserteq(89, compress_frame_buffer(uts, dev));
  353. + ut_asserteq(89, compress_frame_buffer(uts, dev, false));
  354. ut_assertok(check_copy_frame_buffer(uts, dev));
  355. vidconsole_putc_xy(con, 0, 0, ' ');
  356. - ut_asserteq(46, compress_frame_buffer(uts, dev));
  357. + ut_asserteq(46, compress_frame_buffer(uts, dev, false));
  358. ut_assertok(check_copy_frame_buffer(uts, dev));
  359. for (i = 0; i < 20; i++)
  360. vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i);
  361. - ut_asserteq(363, compress_frame_buffer(uts, dev));
  362. + ut_asserteq(363, compress_frame_buffer(uts, dev, false));
  363. ut_assertok(check_copy_frame_buffer(uts, dev));
  364. vidconsole_set_row(con, 0, WHITE);
  365. - ut_asserteq(46, compress_frame_buffer(uts, dev));
  366. + ut_asserteq(46, compress_frame_buffer(uts, dev, false));
  367. ut_assertok(check_copy_frame_buffer(uts, dev));
  368. for (i = 0; i < 20; i++)
  369. vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i);
  370. - ut_asserteq(363, compress_frame_buffer(uts, dev));
  371. + ut_asserteq(363, compress_frame_buffer(uts, dev, false));
  372. ut_assertok(check_copy_frame_buffer(uts, dev));
  373. return 0;
  374. @@ -250,7 +256,7 @@ static int dm_test_video_chars(struct unit_test_state *uts)
  375. ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
  376. ut_assertok(vidconsole_select_font(con, "8x16", 0));
  377. vidconsole_put_string(con, test_string);
  378. - ut_asserteq(466, compress_frame_buffer(uts, dev));
  379. + ut_asserteq(466, compress_frame_buffer(uts, dev, false));
  380. ut_assertok(check_copy_frame_buffer(uts, dev));
  381. return 0;
  382. @@ -272,23 +278,23 @@ static int dm_test_video_ansi(struct unit_test_state *uts)
  383. /* reference clear: */
  384. video_clear(con->parent);
  385. video_sync(con->parent, false);
  386. - ut_asserteq(46, compress_frame_buffer(uts, dev));
  387. + ut_asserteq(46, compress_frame_buffer(uts, dev, false));
  388. ut_assertok(check_copy_frame_buffer(uts, dev));
  389. /* test clear escape sequence: [2J */
  390. vidconsole_put_string(con, "A\tB\tC"ANSI_ESC"[2J");
  391. - ut_asserteq(46, compress_frame_buffer(uts, dev));
  392. + ut_asserteq(46, compress_frame_buffer(uts, dev, false));
  393. ut_assertok(check_copy_frame_buffer(uts, dev));
  394. /* test set-cursor: [%d;%df */
  395. vidconsole_put_string(con, "abc"ANSI_ESC"[2;2fab"ANSI_ESC"[4;4fcd");
  396. - ut_asserteq(143, compress_frame_buffer(uts, dev));
  397. + ut_asserteq(143, compress_frame_buffer(uts, dev, false));
  398. ut_assertok(check_copy_frame_buffer(uts, dev));
  399. /* test colors (30-37 fg color, 40-47 bg color) */
  400. vidconsole_put_string(con, ANSI_ESC"[30;41mfoo"); /* black on red */
  401. vidconsole_put_string(con, ANSI_ESC"[33;44mbar"); /* yellow on blue */
  402. - ut_asserteq(272, compress_frame_buffer(uts, dev));
  403. + ut_asserteq(272, compress_frame_buffer(uts, dev, false));
  404. ut_assertok(check_copy_frame_buffer(uts, dev));
  405. return 0;
  406. @@ -321,13 +327,13 @@ static int check_vidconsole_output(struct unit_test_state *uts, int rot,
  407. ut_assertok(video_get_nologo(uts, &dev));
  408. ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
  409. ut_assertok(vidconsole_select_font(con, "8x16", 0));
  410. - ut_asserteq(46, compress_frame_buffer(uts, dev));
  411. + ut_asserteq(46, compress_frame_buffer(uts, dev, false));
  412. ut_assertok(check_copy_frame_buffer(uts, dev));
  413. /* Check display wrap */
  414. for (i = 0; i < 120; i++)
  415. vidconsole_put_char(con, 'A' + i % 50);
  416. - ut_asserteq(wrap_size, compress_frame_buffer(uts, dev));
  417. + ut_asserteq(wrap_size, compress_frame_buffer(uts, dev, false));
  418. ut_assertok(check_copy_frame_buffer(uts, dev));
  419. /* Check display scrolling */
  420. @@ -335,13 +341,13 @@ static int check_vidconsole_output(struct unit_test_state *uts, int rot,
  421. vidconsole_put_char(con, 'A' + i % 50);
  422. vidconsole_put_char(con, '\n');
  423. }
  424. - ut_asserteq(scroll_size, compress_frame_buffer(uts, dev));
  425. + ut_asserteq(scroll_size, compress_frame_buffer(uts, dev, false));
  426. ut_assertok(check_copy_frame_buffer(uts, dev));
  427. /* If we scroll enough, the screen becomes blank again */
  428. for (i = 0; i < SCROLL_LINES; i++)
  429. vidconsole_put_char(con, '\n');
  430. - ut_asserteq(46, compress_frame_buffer(uts, dev));
  431. + ut_asserteq(46, compress_frame_buffer(uts, dev, false));
  432. ut_assertok(check_copy_frame_buffer(uts, dev));
  433. return 0;
  434. @@ -416,7 +422,7 @@ static int dm_test_video_bmp(struct unit_test_state *uts)
  435. ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
  436. ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
  437. - ut_asserteq(1368, compress_frame_buffer(uts, dev));
  438. + ut_asserteq(1368, compress_frame_buffer(uts, dev, false));
  439. ut_assertok(check_copy_frame_buffer(uts, dev));
  440. return 0;
  441. @@ -436,7 +442,7 @@ static int dm_test_video_bmp8(struct unit_test_state *uts)
  442. ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
  443. ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
  444. - ut_asserteq(1247, compress_frame_buffer(uts, dev));
  445. + ut_asserteq(1247, compress_frame_buffer(uts, dev, false));
  446. ut_assertok(check_copy_frame_buffer(uts, dev));
  447. return 0;
  448. @@ -460,7 +466,7 @@ static int dm_test_video_bmp16(struct unit_test_state *uts)
  449. &src_len));
  450. ut_assertok(video_bmp_display(dev, dst, 0, 0, false));
  451. - ut_asserteq(3700, compress_frame_buffer(uts, dev));
  452. + ut_asserteq(3700, compress_frame_buffer(uts, dev, false));
  453. ut_assertok(check_copy_frame_buffer(uts, dev));
  454. return 0;
  455. @@ -484,7 +490,7 @@ static int dm_test_video_bmp24(struct unit_test_state *uts)
  456. &src_len));
  457. ut_assertok(video_bmp_display(dev, dst, 0, 0, false));
  458. - ut_asserteq(3656, compress_frame_buffer(uts, dev));
  459. + ut_asserteq(3656, compress_frame_buffer(uts, dev, false));
  460. ut_assertok(check_copy_frame_buffer(uts, dev));
  461. return 0;
  462. @@ -508,7 +514,7 @@ static int dm_test_video_bmp24_32(struct unit_test_state *uts)
  463. &src_len));
  464. ut_assertok(video_bmp_display(dev, dst, 0, 0, false));
  465. - ut_asserteq(6827, compress_frame_buffer(uts, dev));
  466. + ut_asserteq(6827, compress_frame_buffer(uts, dev, false));
  467. ut_assertok(check_copy_frame_buffer(uts, dev));
  468. return 0;
  469. @@ -527,7 +533,7 @@ static int dm_test_video_bmp32(struct unit_test_state *uts)
  470. ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
  471. ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
  472. - ut_asserteq(2024, compress_frame_buffer(uts, dev));
  473. + ut_asserteq(2024, compress_frame_buffer(uts, dev, false));
  474. ut_assertok(check_copy_frame_buffer(uts, dev));
  475. return 0;
  476. @@ -544,7 +550,7 @@ static int dm_test_video_bmp_comp(struct unit_test_state *uts)
  477. ut_assertok(read_file(uts, "tools/logos/denx-comp.bmp", &addr));
  478. ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
  479. - ut_asserteq(1368, compress_frame_buffer(uts, dev));
  480. + ut_asserteq(1368, compress_frame_buffer(uts, dev, false));
  481. ut_assertok(check_copy_frame_buffer(uts, dev));
  482. return 0;
  483. @@ -564,7 +570,7 @@ static int dm_test_video_comp_bmp32(struct unit_test_state *uts)
  484. ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
  485. ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
  486. - ut_asserteq(2024, compress_frame_buffer(uts, dev));
  487. + ut_asserteq(2024, compress_frame_buffer(uts, dev, false));
  488. ut_assertok(check_copy_frame_buffer(uts, dev));
  489. return 0;
  490. @@ -584,7 +590,7 @@ static int dm_test_video_comp_bmp8(struct unit_test_state *uts)
  491. ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
  492. ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
  493. - ut_asserteq(1247, compress_frame_buffer(uts, dev));
  494. + ut_asserteq(1247, compress_frame_buffer(uts, dev, false));
  495. ut_assertok(check_copy_frame_buffer(uts, dev));
  496. return 0;
  497. @@ -600,7 +606,7 @@ static int dm_test_video_truetype(struct unit_test_state *uts)
  498. ut_assertok(video_get_nologo(uts, &dev));
  499. ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
  500. vidconsole_put_string(con, test_string);
  501. - ut_asserteq(12174, compress_frame_buffer(uts, dev));
  502. + ut_asserteq(12174, compress_frame_buffer(uts, dev, false));
  503. ut_assertok(check_copy_frame_buffer(uts, dev));
  504. return 0;
  505. @@ -622,7 +628,7 @@ static int dm_test_video_truetype_scroll(struct unit_test_state *uts)
  506. ut_assertok(video_get_nologo(uts, &dev));
  507. ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
  508. vidconsole_put_string(con, test_string);
  509. - ut_asserteq(34287, compress_frame_buffer(uts, dev));
  510. + ut_asserteq(34287, compress_frame_buffer(uts, dev, false));
  511. ut_assertok(check_copy_frame_buffer(uts, dev));
  512. return 0;
  513. @@ -644,7 +650,7 @@ static int dm_test_video_truetype_bs(struct unit_test_state *uts)
  514. ut_assertok(video_get_nologo(uts, &dev));
  515. ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
  516. vidconsole_put_string(con, test_string);
  517. - ut_asserteq(29471, compress_frame_buffer(uts, dev));
  518. + ut_asserteq(29471, compress_frame_buffer(uts, dev, false));
  519. ut_assertok(check_copy_frame_buffer(uts, dev));
  520. return 0;
  521. --
  522. 2.45.2
  523. From 173f97f38d1c6621acd9f24f8956c3a7d808cdd7 Mon Sep 17 00:00:00 2001
  524. From: Alper Nebi Yasak <alpernebiyasak@gmail.com>
  525. Date: Fri, 18 Aug 2023 17:31:27 +0300
  526. Subject: [PATCH 03/13] video: test: Test partial updates of hardware frame
  527. buffer
  528. With VIDEO_COPY enabled, only the modified parts of the frame buffer are
  529. intended to be copied to the hardware. Add a test that checks this, by
  530. overwriting contents we prepared without telling the video uclass and
  531. then checking if the overwritten contents have been redrawn on the next
  532. sync.
  533. Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
  534. Reviewed-by: Simon Glass <sjg@chromium.org>
  535. Link: https://lore.kernel.org/u-boot/20230821135111.3558478-4-alpernebiyasak@gmail.com/
  536. ---
  537. test/dm/video.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++
  538. 1 file changed, 54 insertions(+)
  539. diff --git a/test/dm/video.c b/test/dm/video.c
  540. index 50374cafc009..4798f2205a99 100644
  541. --- a/test/dm/video.c
  542. +++ b/test/dm/video.c
  543. @@ -656,3 +656,57 @@ static int dm_test_video_truetype_bs(struct unit_test_state *uts)
  544. return 0;
  545. }
  546. DM_TEST(dm_test_video_truetype_bs, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
  547. +
  548. +/* Test partial rendering onto hardware frame buffer */
  549. +static int dm_test_video_copy(struct unit_test_state *uts)
  550. +{
  551. + struct sandbox_sdl_plat *plat;
  552. + struct video_uc_plat *uc_plat;
  553. + struct udevice *dev, *con;
  554. + struct video_priv *priv;
  555. + const char *test_string = "\n\tCriticism may not be agreeable, but it is necessary.\t";
  556. + ulong addr;
  557. +
  558. + if (!IS_ENABLED(CONFIG_VIDEO_COPY))
  559. + return -EAGAIN;
  560. +
  561. + ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
  562. + ut_assertnonnull(dev);
  563. + uc_plat = dev_get_uclass_plat(dev);
  564. + uc_plat->hide_logo = true;
  565. + plat = dev_get_plat(dev);
  566. + plat->font_size = 32;
  567. + ut_assert(!device_active(dev));
  568. + ut_assertok(uclass_first_device_err(UCLASS_VIDEO, &dev));
  569. + ut_assertnonnull(dev);
  570. + priv = dev_get_uclass_priv(dev);
  571. +
  572. + ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
  573. + ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
  574. +
  575. + ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
  576. + vidconsole_put_string(con, "\n\n\n\n\n");
  577. + vidconsole_put_string(con, test_string);
  578. + vidconsole_put_string(con, test_string);
  579. +
  580. + ut_asserteq(6678, compress_frame_buffer(uts, dev, false));
  581. + ut_assertok(check_copy_frame_buffer(uts, dev));
  582. +
  583. + /*
  584. + * Secretly clear the hardware frame buffer, but in a different
  585. + * color (black) to see which parts will be overwritten.
  586. + */
  587. + memset(priv->copy_fb, 0, priv->fb_size);
  588. +
  589. + /*
  590. + * We should have the full content on the main buffer, but only
  591. + * the new content should have been copied to the copy buffer.
  592. + */
  593. + vidconsole_put_string(con, test_string);
  594. + vidconsole_put_string(con, test_string);
  595. + ut_asserteq(7589, compress_frame_buffer(uts, dev, false));
  596. + ut_asserteq(5278, compress_frame_buffer(uts, dev, true));
  597. +
  598. + return 0;
  599. +}
  600. +DM_TEST(dm_test_video_copy, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
  601. --
  602. 2.45.2
  603. From 11066af4f8d7a9c6b4729ce2647eb6251397423d Mon Sep 17 00:00:00 2001
  604. From: Alexander Graf <agraf@csgraf.de>
  605. Date: Fri, 10 Jun 2022 00:59:15 +0200
  606. Subject: [PATCH 04/13] dm: video: Add damage tracking API
  607. We are going to introduce image damage tracking to fasten up screen
  608. refresh on large displays. This patch adds damage tracking for up to
  609. one rectangle of the screen which is typically enough to hold blt or
  610. text print updates. Callers into this API and a reduced dcache flush
  611. code path will follow in later patches.
  612. Signed-off-by: Alexander Graf <agraf@csgraf.de>
  613. Reported-by: Da Xue <da@libre.computer>
  614. [Alper: Use xstart/yend, document new fields, return void from
  615. video_damage(), declare priv, drop headers, use IS_ENABLED()]
  616. Co-developed-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
  617. Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
  618. Link: https://lore.kernel.org/u-boot/20230821135111.3558478-5-alpernebiyasak@gmail.com/
  619. Reviewed-by: Simon Glass <sjg@chromium.org>
  620. ---
  621. drivers/video/Kconfig | 13 ++++++++++++
  622. drivers/video/video-uclass.c | 40 +++++++++++++++++++++++++++++++++---
  623. include/video.h | 40 ++++++++++++++++++++++++++++++++++--
  624. 3 files changed, 88 insertions(+), 5 deletions(-)
  625. diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
  626. index 7808ae7919e0..7815b590481e 100644
  627. --- a/drivers/video/Kconfig
  628. +++ b/drivers/video/Kconfig
  629. @@ -92,6 +92,19 @@ config VIDEO_COPY
  630. To use this, your video driver must set @copy_base in
  631. struct video_uc_plat.
  632. +config VIDEO_DAMAGE
  633. + bool "Enable damage tracking of frame buffer regions"
  634. + help
  635. + On some machines (most ARM), the display frame buffer resides in
  636. + RAM. To make the display controller pick up screen updates, we
  637. + have to flush frame buffer contents from CPU caches into RAM which
  638. + can be a slow operation.
  639. +
  640. + This feature adds damage tracking to collect information about regions
  641. + that received updates. When we want to sync, we then only flush
  642. + regions of the frame buffer that were modified before, speeding up
  643. + screen refreshes significantly.
  644. +
  645. config BACKLIGHT_PWM
  646. bool "Generic PWM based Backlight Driver"
  647. depends on BACKLIGHT && DM_PWM
  648. diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c
  649. index ff1382f4a43b..75ab5f5ba9d7 100644
  650. --- a/drivers/video/video-uclass.c
  651. +++ b/drivers/video/video-uclass.c
  652. @@ -346,9 +346,38 @@ void video_set_default_colors(struct udevice *dev, bool invert)
  653. priv->colour_bg = video_index_to_colour(priv, back);
  654. }
  655. +/* Notify about changes in the frame buffer */
  656. +#ifdef CONFIG_VIDEO_DAMAGE
  657. +void video_damage(struct udevice *vid, int x, int y, int width, int height)
  658. +{
  659. + struct video_priv *priv = dev_get_uclass_priv(vid);
  660. + int xend = x + width;
  661. + int yend = y + height;
  662. +
  663. + if (x > priv->xsize)
  664. + return;
  665. +
  666. + if (y > priv->ysize)
  667. + return;
  668. +
  669. + if (xend > priv->xsize)
  670. + xend = priv->xsize;
  671. +
  672. + if (yend > priv->ysize)
  673. + yend = priv->ysize;
  674. +
  675. + /* Span a rectangle across all old and new damage */
  676. + priv->damage.xstart = min(x, priv->damage.xstart);
  677. + priv->damage.ystart = min(y, priv->damage.ystart);
  678. + priv->damage.xend = max(xend, priv->damage.xend);
  679. + priv->damage.yend = max(yend, priv->damage.yend);
  680. +}
  681. +#endif
  682. +
  683. /* Flush video activity to the caches */
  684. int video_sync(struct udevice *vid, bool force)
  685. {
  686. + struct video_priv *priv = dev_get_uclass_priv(vid);
  687. struct video_ops *ops = video_get_ops(vid);
  688. int ret;
  689. @@ -364,15 +393,12 @@ int video_sync(struct udevice *vid, bool force)
  690. * out whether it exists? For now, ARM is safe.
  691. */
  692. #if defined(CONFIG_ARM) && !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
  693. - struct video_priv *priv = dev_get_uclass_priv(vid);
  694. -
  695. if (priv->flush_dcache) {
  696. flush_dcache_range((ulong)priv->fb,
  697. ALIGN((ulong)priv->fb + priv->fb_size,
  698. CONFIG_SYS_CACHELINE_SIZE));
  699. }
  700. #elif defined(CONFIG_VIDEO_SANDBOX_SDL)
  701. - struct video_priv *priv = dev_get_uclass_priv(vid);
  702. static ulong last_sync;
  703. if (force || get_timer(last_sync) > 100) {
  704. @@ -380,6 +406,14 @@ int video_sync(struct udevice *vid, bool force)
  705. last_sync = get_timer(0);
  706. }
  707. #endif
  708. +
  709. + if (IS_ENABLED(CONFIG_VIDEO_DAMAGE)) {
  710. + priv->damage.xstart = priv->xsize;
  711. + priv->damage.ystart = priv->ysize;
  712. + priv->damage.xend = 0;
  713. + priv->damage.yend = 0;
  714. + }
  715. +
  716. return 0;
  717. }
  718. diff --git a/include/video.h b/include/video.h
  719. index 4d8df9baaada..d2dabb66e9e6 100644
  720. --- a/include/video.h
  721. +++ b/include/video.h
  722. @@ -88,6 +88,11 @@ enum video_format {
  723. * @fb_size: Frame buffer size
  724. * @copy_fb: Copy of the frame buffer to keep up to date; see struct
  725. * video_uc_plat
  726. + * @damage: A bounding box of framebuffer regions updated since last sync
  727. + * @damage.xstart: X start position in pixels from the left
  728. + * @damage.ystart: Y start position in pixels from the top
  729. + * @damage.xend: X end position in pixels from the left
  730. + * @damage.xend: Y end position in pixels from the top
  731. * @line_length: Length of each frame buffer line, in bytes. This can be
  732. * set by the driver, but if not, the uclass will set it after
  733. * probing
  734. @@ -115,6 +120,12 @@ struct video_priv {
  735. void *fb;
  736. int fb_size;
  737. void *copy_fb;
  738. + struct {
  739. + int xstart;
  740. + int ystart;
  741. + int xend;
  742. + int yend;
  743. + } damage;
  744. int line_length;
  745. u32 colour_fg;
  746. u32 colour_bg;
  747. @@ -257,8 +268,9 @@ int video_fill_part(struct udevice *dev, int xstart, int ystart, int xend,
  748. * @return: 0 on success, error code otherwise
  749. *
  750. * Some frame buffers are cached or have a secondary frame buffer. This
  751. - * function syncs these up so that the current contents of the U-Boot frame
  752. - * buffer are displayed to the user.
  753. + * function syncs the damaged parts of them up so that the current contents
  754. + * of the U-Boot frame buffer are displayed to the user. It clears the damage
  755. + * buffer.
  756. */
  757. int video_sync(struct udevice *vid, bool force);
  758. @@ -378,6 +390,30 @@ static inline int video_sync_copy_all(struct udevice *dev)
  759. #endif
  760. +#ifdef CONFIG_VIDEO_DAMAGE
  761. +/**
  762. + * video_damage() - Notify the video subsystem about screen updates.
  763. + *
  764. + * @vid: Device to sync
  765. + * @x: Upper left X coordinate of the damaged rectangle
  766. + * @y: Upper left Y coordinate of the damaged rectangle
  767. + * @width: Width of the damaged rectangle
  768. + * @height: Height of the damaged rectangle
  769. + *
  770. + * Some frame buffers are cached or have a secondary frame buffer. This
  771. + * function notifies the video subsystem about rectangles that were updated
  772. + * within the frame buffer. They may only get written to the screen on the
  773. + * next call to video_sync().
  774. + */
  775. +void video_damage(struct udevice *vid, int x, int y, int width, int height);
  776. +#else
  777. +static inline void video_damage(struct udevice *vid, int x, int y, int width,
  778. + int height)
  779. +{
  780. + return;
  781. +}
  782. +#endif /* CONFIG_VIDEO_DAMAGE */
  783. +
  784. /**
  785. * video_is_active() - Test if one video device it active
  786. *
  787. --
  788. 2.45.2
  789. From 5613cd630801ccb329895f62c27b8690a2cbf74c Mon Sep 17 00:00:00 2001
  790. From: Alexander Graf <agraf@csgraf.de>
  791. Date: Fri, 10 Jun 2022 00:59:16 +0200
  792. Subject: [PATCH 05/13] dm: video: Add damage notification on display fills
  793. Let's report the video damage when we fill parts of the screen. This
  794. way we can later lazily flush only relevant regions to hardware.
  795. Signed-off-by: Alexander Graf <agraf@csgraf.de>
  796. Reported-by: Da Xue <da@libre.computer>
  797. [Alper: Move from video_clear() to video_fill(), video_fill_part()]
  798. Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
  799. Reviewed-by: Simon Glass <sjg@chromium.org>
  800. Link: https://lore.kernel.org/u-boot/20230821135111.3558478-6-alpernebiyasak@gmail.com/
  801. ---
  802. drivers/video/video-uclass.c | 4 ++++
  803. 1 file changed, 4 insertions(+)
  804. diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c
  805. index 75ab5f5ba9d7..ca348101817a 100644
  806. --- a/drivers/video/video-uclass.c
  807. +++ b/drivers/video/video-uclass.c
  808. @@ -195,6 +195,8 @@ int video_fill_part(struct udevice *dev, int xstart, int ystart, int xend,
  809. if (ret)
  810. return ret;
  811. + video_damage(dev, xstart, ystart, xend - xstart, yend - ystart);
  812. +
  813. return 0;
  814. }
  815. @@ -244,6 +246,8 @@ int video_fill(struct udevice *dev, u32 colour)
  816. if (ret)
  817. return ret;
  818. + video_damage(dev, 0, 0, priv->xsize, priv->ysize);
  819. +
  820. return video_sync(dev, false);
  821. }
  822. --
  823. 2.45.2
  824. From 4e29f9d2190f2ea390d5321192f5e71193d62f71 Mon Sep 17 00:00:00 2001
  825. From: Alexander Graf <agraf@csgraf.de>
  826. Date: Fri, 10 Jun 2022 00:59:17 +0200
  827. Subject: [PATCH 06/13] vidconsole: Add damage notifications to all vidconsole
  828. drivers
  829. Now that we have a damage tracking API, let's populate damage done by
  830. vidconsole drivers. We try to declare as little memory as damaged as
  831. possible.
  832. Signed-off-by: Alexander Graf <agraf@csgraf.de>
  833. Reported-by: Da Xue <da@libre.computer>
  834. [Alper: Rebase for met->baseline, fontdata->height/width, make rotated
  835. console_putc_xy() damages pass tests, edit patch message]
  836. Co-developed-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
  837. Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
  838. Link: https://lore.kernel.org/u-boot/20230821135111.3558478-7-alpernebiyasak@gmail.com/
  839. ---
  840. drivers/video/console_normal.c | 18 +++++++++++
  841. drivers/video/console_rotate.c | 54 ++++++++++++++++++++++++++++++++
  842. drivers/video/console_truetype.c | 21 +++++++++++++
  843. 3 files changed, 93 insertions(+)
  844. diff --git a/drivers/video/console_normal.c b/drivers/video/console_normal.c
  845. index 6f4194a18147..51ac8cc78e9d 100644
  846. --- a/drivers/video/console_normal.c
  847. +++ b/drivers/video/console_normal.c
  848. @@ -39,6 +39,12 @@ static int console_set_row(struct udevice *dev, uint row, int clr)
  849. if (ret)
  850. return ret;
  851. + video_damage(dev->parent,
  852. + 0,
  853. + fontdata->height * row,
  854. + vid_priv->xsize,
  855. + fontdata->height);
  856. +
  857. return 0;
  858. }
  859. @@ -60,6 +66,12 @@ static int console_move_rows(struct udevice *dev, uint rowdst,
  860. if (ret)
  861. return ret;
  862. + video_damage(dev->parent,
  863. + 0,
  864. + fontdata->height * rowdst,
  865. + vid_priv->xsize,
  866. + fontdata->height * count);
  867. +
  868. return 0;
  869. }
  870. @@ -91,6 +103,12 @@ static int console_putc_xy(struct udevice *dev, uint x_frac, uint y, int cp)
  871. if (ret)
  872. return ret;
  873. + video_damage(dev->parent,
  874. + x,
  875. + y,
  876. + fontdata->width,
  877. + fontdata->height);
  878. +
  879. ret = vidconsole_sync_copy(dev, start, line);
  880. if (ret)
  881. return ret;
  882. diff --git a/drivers/video/console_rotate.c b/drivers/video/console_rotate.c
  883. index dc9698362741..5c4a98f6cad0 100644
  884. --- a/drivers/video/console_rotate.c
  885. +++ b/drivers/video/console_rotate.c
  886. @@ -36,6 +36,12 @@ static int console_set_row_1(struct udevice *dev, uint row, int clr)
  887. if (ret)
  888. return ret;
  889. + video_damage(dev->parent,
  890. + vid_priv->xsize - ((row + 1) * fontdata->height),
  891. + 0,
  892. + fontdata->height,
  893. + vid_priv->ysize);
  894. +
  895. return 0;
  896. }
  897. @@ -64,6 +70,12 @@ static int console_move_rows_1(struct udevice *dev, uint rowdst, uint rowsrc,
  898. dst += vid_priv->line_length;
  899. }
  900. + video_damage(dev->parent,
  901. + vid_priv->xsize - ((rowdst + count) * fontdata->height),
  902. + 0,
  903. + count * fontdata->height,
  904. + vid_priv->ysize);
  905. +
  906. return 0;
  907. }
  908. @@ -97,6 +109,12 @@ static int console_putc_xy_1(struct udevice *dev, uint x_frac, uint y, int cp)
  909. if (ret)
  910. return ret;
  911. + video_damage(dev->parent,
  912. + vid_priv->xsize - y - fontdata->height,
  913. + linenum - 1,
  914. + fontdata->height,
  915. + fontdata->width);
  916. +
  917. return VID_TO_POS(fontdata->width);
  918. }
  919. @@ -122,6 +140,12 @@ static int console_set_row_2(struct udevice *dev, uint row, int clr)
  920. if (ret)
  921. return ret;
  922. + video_damage(dev->parent,
  923. + 0,
  924. + vid_priv->ysize - (row + 1) * fontdata->height,
  925. + vid_priv->xsize,
  926. + fontdata->height);
  927. +
  928. return 0;
  929. }
  930. @@ -143,6 +167,12 @@ static int console_move_rows_2(struct udevice *dev, uint rowdst, uint rowsrc,
  931. vidconsole_memmove(dev, dst, src,
  932. fontdata->height * vid_priv->line_length * count);
  933. + video_damage(dev->parent,
  934. + 0,
  935. + vid_priv->ysize - (rowdst + count) * fontdata->height,
  936. + vid_priv->xsize,
  937. + count * fontdata->height);
  938. +
  939. return 0;
  940. }
  941. @@ -176,6 +206,12 @@ static int console_putc_xy_2(struct udevice *dev, uint x_frac, uint y, int cp)
  942. if (ret)
  943. return ret;
  944. + video_damage(dev->parent,
  945. + x - fontdata->width + 1,
  946. + linenum - fontdata->height + 1,
  947. + fontdata->width,
  948. + fontdata->height);
  949. +
  950. return VID_TO_POS(fontdata->width);
  951. }
  952. @@ -200,6 +236,12 @@ static int console_set_row_3(struct udevice *dev, uint row, int clr)
  953. if (ret)
  954. return ret;
  955. + video_damage(dev->parent,
  956. + row * fontdata->height,
  957. + 0,
  958. + fontdata->height,
  959. + vid_priv->ysize);
  960. +
  961. return 0;
  962. }
  963. @@ -226,6 +268,12 @@ static int console_move_rows_3(struct udevice *dev, uint rowdst, uint rowsrc,
  964. dst += vid_priv->line_length;
  965. }
  966. + video_damage(dev->parent,
  967. + rowdst * fontdata->height,
  968. + 0,
  969. + count * fontdata->height,
  970. + vid_priv->ysize);
  971. +
  972. return 0;
  973. }
  974. @@ -258,6 +306,12 @@ static int console_putc_xy_3(struct udevice *dev, uint x_frac, uint y, int cp)
  975. if (ret)
  976. return ret;
  977. + video_damage(dev->parent,
  978. + y,
  979. + linenum - fontdata->width + 1,
  980. + fontdata->height,
  981. + fontdata->width);
  982. +
  983. return VID_TO_POS(fontdata->width);
  984. }
  985. diff --git a/drivers/video/console_truetype.c b/drivers/video/console_truetype.c
  986. index c435162d3f94..6a17f732fc26 100644
  987. --- a/drivers/video/console_truetype.c
  988. +++ b/drivers/video/console_truetype.c
  989. @@ -190,6 +190,7 @@ struct console_tt_store {
  990. static int console_truetype_set_row(struct udevice *dev, uint row, int clr)
  991. {
  992. struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
  993. + struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
  994. struct console_tt_priv *priv = dev_get_priv(dev);
  995. struct console_tt_metrics *met = priv->cur_met;
  996. void *end, *line;
  997. @@ -233,6 +234,12 @@ static int console_truetype_set_row(struct udevice *dev, uint row, int clr)
  998. if (ret)
  999. return ret;
  1000. + video_damage(dev->parent,
  1001. + 0,
  1002. + vc_priv->y_charsize * row,
  1003. + vid_priv->xsize,
  1004. + vc_priv->y_charsize);
  1005. +
  1006. return 0;
  1007. }
  1008. @@ -240,6 +247,7 @@ static int console_truetype_move_rows(struct udevice *dev, uint rowdst,
  1009. uint rowsrc, uint count)
  1010. {
  1011. struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
  1012. + struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
  1013. struct console_tt_priv *priv = dev_get_priv(dev);
  1014. struct console_tt_metrics *met = priv->cur_met;
  1015. void *dst;
  1016. @@ -258,6 +266,12 @@ static int console_truetype_move_rows(struct udevice *dev, uint rowdst,
  1017. for (i = 0; i < priv->pos_ptr; i++)
  1018. priv->pos[i].ypos -= diff;
  1019. + video_damage(dev->parent,
  1020. + 0,
  1021. + vc_priv->y_charsize * rowdst,
  1022. + vid_priv->xsize,
  1023. + vc_priv->y_charsize * count);
  1024. +
  1025. return 0;
  1026. }
  1027. @@ -418,6 +432,13 @@ static int console_truetype_putc_xy(struct udevice *dev, uint x, uint y,
  1028. line += vid_priv->line_length;
  1029. }
  1030. +
  1031. + video_damage(dev->parent,
  1032. + VID_TO_PIXEL(x) + xoff,
  1033. + y + met->baseline + yoff,
  1034. + width,
  1035. + height);
  1036. +
  1037. ret = vidconsole_sync_copy(dev, start, line);
  1038. if (ret)
  1039. return ret;
  1040. --
  1041. 2.45.2
  1042. From 11fa5d7c68878f629c8fff7dc28a76acaf1252ab Mon Sep 17 00:00:00 2001
  1043. From: Alper Nebi Yasak <alpernebiyasak@gmail.com>
  1044. Date: Fri, 18 Aug 2023 17:55:08 +0300
  1045. Subject: [PATCH 07/13] video: test: Test video damage tracking via vidconsole
  1046. With VIDEO_DAMAGE, the video uclass tracks updated regions of the frame
  1047. buffer in order to avoid unnecessary work during a video sync. Enable
  1048. the config in sandbox and add a test for it, by printing strings at a
  1049. few locations and checking the tracked region.
  1050. Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
  1051. Reviewed-by: Simon Glass <sjg@chromium.org>
  1052. Link: https://lore.kernel.org/u-boot/20230821135111.3558478-8-alpernebiyasak@gmail.com/
  1053. ---
  1054. configs/sandbox_defconfig | 1 +
  1055. test/dm/video.c | 56 +++++++++++++++++++++++++++++++++++++++
  1056. 2 files changed, 57 insertions(+)
  1057. diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
  1058. index da8c1976d7bd..6bc20ec34169 100644
  1059. --- a/configs/sandbox_defconfig
  1060. +++ b/configs/sandbox_defconfig
  1061. @@ -319,6 +319,7 @@ CONFIG_USB_ETH_CDC=y
  1062. CONFIG_VIDEO=y
  1063. CONFIG_VIDEO_FONT_SUN12X22=y
  1064. CONFIG_VIDEO_COPY=y
  1065. +CONFIG_VIDEO_DAMAGE=y
  1066. CONFIG_CONSOLE_ROTATION=y
  1067. CONFIG_CONSOLE_TRUETYPE=y
  1068. CONFIG_CONSOLE_TRUETYPE_CANTORAONE=y
  1069. diff --git a/test/dm/video.c b/test/dm/video.c
  1070. index 4798f2205a99..119c43153165 100644
  1071. --- a/test/dm/video.c
  1072. +++ b/test/dm/video.c
  1073. @@ -710,3 +710,59 @@ static int dm_test_video_copy(struct unit_test_state *uts)
  1074. return 0;
  1075. }
  1076. DM_TEST(dm_test_video_copy, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
  1077. +
  1078. +/* Test video damage tracking */
  1079. +static int dm_test_video_damage(struct unit_test_state *uts)
  1080. +{
  1081. + struct sandbox_sdl_plat *plat;
  1082. + struct udevice *dev, *con;
  1083. + struct video_priv *priv;
  1084. + const char *test_string_1 = "Criticism may not be agreeable, ";
  1085. + const char *test_string_2 = "but it is necessary.";
  1086. + const char *test_string_3 = "It fulfils the same function as pain in the human body.";
  1087. +
  1088. + if (!IS_ENABLED(CONFIG_VIDEO_DAMAGE))
  1089. + return -EAGAIN;
  1090. +
  1091. + ut_assertok(uclass_find_device(UCLASS_VIDEO, 0, &dev));
  1092. + ut_assert(!device_active(dev));
  1093. + plat = dev_get_plat(dev);
  1094. + plat->font_size = 32;
  1095. +
  1096. + ut_assertok(video_get_nologo(uts, &dev));
  1097. + ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
  1098. + priv = dev_get_uclass_priv(dev);
  1099. +
  1100. + vidconsole_position_cursor(con, 14, 10);
  1101. + vidconsole_put_string(con, test_string_2);
  1102. + ut_asserteq(449, priv->damage.xstart);
  1103. + ut_asserteq(325, priv->damage.ystart);
  1104. + ut_asserteq(661, priv->damage.xend);
  1105. + ut_asserteq(350, priv->damage.yend);
  1106. +
  1107. + vidconsole_position_cursor(con, 7, 5);
  1108. + vidconsole_put_string(con, test_string_1);
  1109. + ut_asserteq(225, priv->damage.xstart);
  1110. + ut_asserteq(164, priv->damage.ystart);
  1111. + ut_asserteq(661, priv->damage.xend);
  1112. + ut_asserteq(350, priv->damage.yend);
  1113. +
  1114. + vidconsole_position_cursor(con, 21, 15);
  1115. + vidconsole_put_string(con, test_string_3);
  1116. + ut_asserteq(225, priv->damage.xstart);
  1117. + ut_asserteq(164, priv->damage.ystart);
  1118. + ut_asserteq(1280, priv->damage.xend);
  1119. + ut_asserteq(510, priv->damage.yend);
  1120. +
  1121. + video_sync(dev, false);
  1122. + ut_asserteq(priv->xsize, priv->damage.xstart);
  1123. + ut_asserteq(priv->ysize, priv->damage.ystart);
  1124. + ut_asserteq(0, priv->damage.xend);
  1125. + ut_asserteq(0, priv->damage.yend);
  1126. +
  1127. + ut_asserteq(7339, compress_frame_buffer(uts, dev, false));
  1128. + ut_assertok(check_copy_frame_buffer(uts, dev));
  1129. +
  1130. + return 0;
  1131. +}
  1132. +DM_TEST(dm_test_video_damage, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
  1133. --
  1134. 2.45.2
  1135. From 80a32fe8f34466e6b86553018f47192a1fef3c6a Mon Sep 17 00:00:00 2001
  1136. From: Alexander Graf <agraf@csgraf.de>
  1137. Date: Fri, 10 Jun 2022 00:59:18 +0200
  1138. Subject: [PATCH 08/13] video: Add damage notification on bmp display
  1139. Let's report the video damage when we draw a bitmap on the screen. This
  1140. way we can later lazily flush only relevant regions to hardware.
  1141. Signed-off-by: Alexander Graf <agraf@csgraf.de>
  1142. Reported-by: Da Xue <da@libre.computer>
  1143. Reviewed-by: Simon Glass <sjg@chromium.org>
  1144. Link: https://lore.kernel.org/u-boot/20230821135111.3558478-9-alpernebiyasak@gmail.com/
  1145. ---
  1146. drivers/video/video_bmp.c | 2 ++
  1147. 1 file changed, 2 insertions(+)
  1148. diff --git a/drivers/video/video_bmp.c b/drivers/video/video_bmp.c
  1149. index ad512d99a1b9..78de95607924 100644
  1150. --- a/drivers/video/video_bmp.c
  1151. +++ b/drivers/video/video_bmp.c
  1152. @@ -459,6 +459,8 @@ int video_bmp_display(struct udevice *dev, ulong bmp_image, int x, int y,
  1153. break;
  1154. };
  1155. + video_damage(dev, x, y, width, height);
  1156. +
  1157. /* Find the position of the top left of the image in the framebuffer */
  1158. fb = (uchar *)(priv->fb + y * priv->line_length + x * bpix / 8);
  1159. ret = video_sync_copy(dev, start, fb);
  1160. --
  1161. 2.45.2
  1162. From 7afe761e51bfb0f24fd4547e8bec1826aaf2e6a0 Mon Sep 17 00:00:00 2001
  1163. From: Alexander Graf <agraf@csgraf.de>
  1164. Date: Fri, 10 Jun 2022 00:59:19 +0200
  1165. Subject: [PATCH 09/13] efi_loader: GOP: Add damage notification on BLT
  1166. Now that we have a damage tracking API, let's populate damage done by
  1167. UEFI payloads when they BLT data onto the screen.
  1168. Signed-off-by: Alexander Graf <agraf@csgraf.de>
  1169. Reported-by: Da Xue <da@libre.computer>
  1170. Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
  1171. [Alper: Add struct comment for new member]
  1172. Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
  1173. Reviewed-by: Simon Glass <sjg@chromium.org>
  1174. Link: https://lore.kernel.org/u-boot/20230821135111.3558478-10-alpernebiyasak@gmail.com/
  1175. ---
  1176. lib/efi_loader/efi_gop.c | 7 +++++++
  1177. 1 file changed, 7 insertions(+)
  1178. diff --git a/lib/efi_loader/efi_gop.c b/lib/efi_loader/efi_gop.c
  1179. index 41e12fa72460..1694e23dcc62 100644
  1180. --- a/lib/efi_loader/efi_gop.c
  1181. +++ b/lib/efi_loader/efi_gop.c
  1182. @@ -24,6 +24,7 @@ static const efi_guid_t efi_gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
  1183. * @ops: graphical output protocol interface
  1184. * @info: graphical output mode information
  1185. * @mode: graphical output mode
  1186. + * @vdev: backing video device
  1187. * @bpix: bits per pixel
  1188. * @fb: frame buffer
  1189. */
  1190. @@ -32,6 +33,7 @@ struct efi_gop_obj {
  1191. struct efi_gop ops;
  1192. struct efi_gop_mode_info info;
  1193. struct efi_gop_mode mode;
  1194. + struct udevice *vdev;
  1195. /* Fields we only have access to during init */
  1196. u32 bpix;
  1197. void *fb;
  1198. @@ -120,6 +122,7 @@ static __always_inline efi_status_t gop_blt_int(struct efi_gop *this,
  1199. u32 *fb32 = gopobj->fb;
  1200. u16 *fb16 = gopobj->fb;
  1201. struct efi_gop_pixel *buffer = __builtin_assume_aligned(bufferp, 4);
  1202. + bool blt_to_video = (operation != EFI_BLT_VIDEO_TO_BLT_BUFFER);
  1203. if (delta) {
  1204. /* Check for 4 byte alignment */
  1205. @@ -243,6 +246,9 @@ static __always_inline efi_status_t gop_blt_int(struct efi_gop *this,
  1206. dlineoff += dwidth;
  1207. }
  1208. + if (blt_to_video)
  1209. + video_damage(gopobj->vdev, dx, dy, width, height);
  1210. +
  1211. return EFI_SUCCESS;
  1212. }
  1213. @@ -549,6 +555,7 @@ efi_status_t efi_gop_register(void)
  1214. gopobj->info.pixels_per_scanline = col;
  1215. gopobj->bpix = bpix;
  1216. gopobj->fb = map_sysmem(fb_base, fb_size);
  1217. + gopobj->vdev = vdev;
  1218. return EFI_SUCCESS;
  1219. }
  1220. --
  1221. 2.45.2
  1222. From 134415d6cbe38f7ab630f978a602b6e15929feea Mon Sep 17 00:00:00 2001
  1223. From: Alexander Graf <agraf@csgraf.de>
  1224. Date: Fri, 10 Jun 2022 00:59:20 +0200
  1225. Subject: [PATCH 10/13] video: Only dcache flush damaged lines
  1226. Now that we have a damage area tells us which parts of the frame buffer
  1227. actually need updating, let's only dcache flush those on video_sync()
  1228. calls. With this optimization in place, frame buffer updates - especially
  1229. on large screen such as 4k displays - speed up significantly.
  1230. Signed-off-by: Alexander Graf <agraf@csgraf.de>
  1231. Reported-by: Da Xue <da@libre.computer>
  1232. [Alper: Use damage.xstart/yend, IS_ENABLED()]
  1233. Co-developed-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
  1234. Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
  1235. Link: https://lore.kernel.org/u-boot/20230821135111.3558478-11-alpernebiyasak@gmail.com/
  1236. ---
  1237. drivers/video/video-uclass.c | 43 +++++++++++++++++++++++++++++++-----
  1238. 1 file changed, 38 insertions(+), 5 deletions(-)
  1239. diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c
  1240. index ca348101817a..add7a85b20fe 100644
  1241. --- a/drivers/video/video-uclass.c
  1242. +++ b/drivers/video/video-uclass.c
  1243. @@ -378,6 +378,40 @@ void video_damage(struct udevice *vid, int x, int y, int width, int height)
  1244. }
  1245. #endif
  1246. +#if defined(CONFIG_ARM) && !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
  1247. +static void video_flush_dcache(struct udevice *vid, bool use_copy)
  1248. +{
  1249. + struct video_priv *priv = dev_get_uclass_priv(vid);
  1250. + ulong fb = use_copy ? (ulong)priv->copy_fb : (ulong)priv->fb;
  1251. +
  1252. + if (!priv->flush_dcache)
  1253. + return;
  1254. +
  1255. + if (!IS_ENABLED(CONFIG_VIDEO_DAMAGE)) {
  1256. + flush_dcache_range(fb, ALIGN(fb + priv->fb_size,
  1257. + CONFIG_SYS_CACHELINE_SIZE));
  1258. +
  1259. + return;
  1260. + }
  1261. +
  1262. + if (priv->damage.xend && priv->damage.yend) {
  1263. + int lstart = priv->damage.xstart * VNBYTES(priv->bpix);
  1264. + int lend = priv->damage.xend * VNBYTES(priv->bpix);
  1265. + int y;
  1266. +
  1267. + for (y = priv->damage.ystart; y < priv->damage.yend; y++) {
  1268. + ulong start = fb + (y * priv->line_length) + lstart;
  1269. + ulong end = start + lend - lstart;
  1270. +
  1271. + start = ALIGN_DOWN(start, CONFIG_SYS_CACHELINE_SIZE);
  1272. + end = ALIGN(end, CONFIG_SYS_CACHELINE_SIZE);
  1273. +
  1274. + flush_dcache_range(start, end);
  1275. + }
  1276. + }
  1277. +}
  1278. +#endif
  1279. +
  1280. /* Flush video activity to the caches */
  1281. int video_sync(struct udevice *vid, bool force)
  1282. {
  1283. @@ -397,11 +431,10 @@ int video_sync(struct udevice *vid, bool force)
  1284. * out whether it exists? For now, ARM is safe.
  1285. */
  1286. #if defined(CONFIG_ARM) && !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
  1287. - if (priv->flush_dcache) {
  1288. - flush_dcache_range((ulong)priv->fb,
  1289. - ALIGN((ulong)priv->fb + priv->fb_size,
  1290. - CONFIG_SYS_CACHELINE_SIZE));
  1291. - }
  1292. + video_flush_dcache(vid, false);
  1293. +
  1294. + if (IS_ENABLED(CONFIG_VIDEO_COPY))
  1295. + video_flush_dcache(vid, true);
  1296. #elif defined(CONFIG_VIDEO_SANDBOX_SDL)
  1297. static ulong last_sync;
  1298. --
  1299. 2.45.2
  1300. From d3f1653a87d51c5ecf187b19ecb60a2f740fb8e2 Mon Sep 17 00:00:00 2001
  1301. From: Alexander Graf <agraf@csgraf.de>
  1302. Date: Fri, 10 Jun 2022 00:59:21 +0200
  1303. Subject: [PATCH 11/13] video: Use VIDEO_DAMAGE for VIDEO_COPY
  1304. CONFIG_VIDEO_COPY implemented a range-based copying mechanism: If we
  1305. print a single character, it will always copy the full range of bytes
  1306. from the top left corner of the character to the lower right onto the
  1307. uncached frame buffer. This includes pretty much the full line contents
  1308. of the printed character.
  1309. Since we now have proper damage tracking, let's make use of that to reduce
  1310. the amount of data we need to copy. With this patch applied, we will only
  1311. copy the tiny rectangle surrounding characters when we print them,
  1312. speeding up the video console.
  1313. After this, changes to the main frame buffer are not immediately copied
  1314. to the copy frame buffer, but postponed until the next video device
  1315. sync. So issue an explicit sync before inspecting the copy frame buffer
  1316. contents for the video tests.
  1317. Signed-off-by: Alexander Graf <agraf@csgraf.de>
  1318. [Alper: Rebase for fontdata->height/w, fill_part(), fix memmove(dev),
  1319. drop from defconfig, use damage.xstart/yend, use IS_ENABLED(),
  1320. call video_sync() before copy_fb check, update video_copy test]
  1321. Co-developed-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
  1322. Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
  1323. Link: https://lore.kernel.org/u-boot/20230821135111.3558478-12-alpernebiyasak@gmail.com/
  1324. ---
  1325. configs/sandbox_defconfig | 1 -
  1326. drivers/video/Kconfig | 5 ++
  1327. drivers/video/console_normal.c | 13 +----
  1328. drivers/video/console_rotate.c | 44 +++-----------
  1329. drivers/video/console_truetype.c | 16 +-----
  1330. drivers/video/vidconsole-uclass.c | 16 ------
  1331. drivers/video/video-uclass.c | 96 ++++++++-----------------------
  1332. drivers/video/video_bmp.c | 7 ---
  1333. include/video.h | 37 ------------
  1334. include/video_console.h | 52 -----------------
  1335. test/dm/video.c | 3 +-
  1336. 11 files changed, 43 insertions(+), 247 deletions(-)
  1337. diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
  1338. index 6bc20ec34169..da8c1976d7bd 100644
  1339. --- a/configs/sandbox_defconfig
  1340. +++ b/configs/sandbox_defconfig
  1341. @@ -319,7 +319,6 @@ CONFIG_USB_ETH_CDC=y
  1342. CONFIG_VIDEO=y
  1343. CONFIG_VIDEO_FONT_SUN12X22=y
  1344. CONFIG_VIDEO_COPY=y
  1345. -CONFIG_VIDEO_DAMAGE=y
  1346. CONFIG_CONSOLE_ROTATION=y
  1347. CONFIG_CONSOLE_TRUETYPE=y
  1348. CONFIG_CONSOLE_TRUETYPE_CANTORAONE=y
  1349. diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
  1350. index 7815b590481e..88c6f8e68976 100644
  1351. --- a/drivers/video/Kconfig
  1352. +++ b/drivers/video/Kconfig
  1353. @@ -83,11 +83,14 @@ config VIDEO_PCI_DEFAULT_FB_SIZE
  1354. config VIDEO_COPY
  1355. bool "Enable copying the frame buffer to a hardware copy"
  1356. + select VIDEO_DAMAGE
  1357. help
  1358. On some machines (e.g. x86), reading from the frame buffer is very
  1359. slow because it is uncached. To improve performance, this feature
  1360. allows the frame buffer to be kept in cached memory (allocated by
  1361. U-Boot) and then copied to the hardware frame-buffer as needed.
  1362. + It uses the VIDEO_DAMAGE feature to keep track of regions to copy
  1363. + and will only copy actually touched regions.
  1364. To use this, your video driver must set @copy_base in
  1365. struct video_uc_plat.
  1366. @@ -105,6 +108,8 @@ config VIDEO_DAMAGE
  1367. regions of the frame buffer that were modified before, speeding up
  1368. screen refreshes significantly.
  1369. + It is also used by VIDEO_COPY to identify which regions changed.
  1370. +
  1371. config BACKLIGHT_PWM
  1372. bool "Generic PWM based Backlight Driver"
  1373. depends on BACKLIGHT && DM_PWM
  1374. diff --git a/drivers/video/console_normal.c b/drivers/video/console_normal.c
  1375. index 51ac8cc78e9d..07db613ac53c 100644
  1376. --- a/drivers/video/console_normal.c
  1377. +++ b/drivers/video/console_normal.c
  1378. @@ -35,10 +35,6 @@ static int console_set_row(struct udevice *dev, uint row, int clr)
  1379. fill_pixel_and_goto_next(&dst, clr, pbytes, pbytes);
  1380. end = dst;
  1381. - ret = vidconsole_sync_copy(dev, line, end);
  1382. - if (ret)
  1383. - return ret;
  1384. -
  1385. video_damage(dev->parent,
  1386. 0,
  1387. fontdata->height * row,
  1388. @@ -57,14 +53,11 @@ static int console_move_rows(struct udevice *dev, uint rowdst,
  1389. void *dst;
  1390. void *src;
  1391. int size;
  1392. - int ret;
  1393. dst = vid_priv->fb + rowdst * fontdata->height * vid_priv->line_length;
  1394. src = vid_priv->fb + rowsrc * fontdata->height * vid_priv->line_length;
  1395. size = fontdata->height * vid_priv->line_length * count;
  1396. - ret = vidconsole_memmove(dev, dst, src, size);
  1397. - if (ret)
  1398. - return ret;
  1399. + memmove(dst, src, size);
  1400. video_damage(dev->parent,
  1401. 0,
  1402. @@ -109,10 +102,6 @@ static int console_putc_xy(struct udevice *dev, uint x_frac, uint y, int cp)
  1403. fontdata->width,
  1404. fontdata->height);
  1405. - ret = vidconsole_sync_copy(dev, start, line);
  1406. - if (ret)
  1407. - return ret;
  1408. -
  1409. return VID_TO_POS(fontdata->width);
  1410. }
  1411. diff --git a/drivers/video/console_rotate.c b/drivers/video/console_rotate.c
  1412. index 5c4a98f6cad0..9f8e1b92770c 100644
  1413. --- a/drivers/video/console_rotate.c
  1414. +++ b/drivers/video/console_rotate.c
  1415. @@ -21,7 +21,6 @@ static int console_set_row_1(struct udevice *dev, uint row, int clr)
  1416. int pbytes = VNBYTES(vid_priv->bpix);
  1417. void *start, *dst, *line;
  1418. int i, j;
  1419. - int ret;
  1420. start = vid_priv->fb + vid_priv->line_length -
  1421. (row + 1) * fontdata->height * pbytes;
  1422. @@ -32,9 +31,6 @@ static int console_set_row_1(struct udevice *dev, uint row, int clr)
  1423. fill_pixel_and_goto_next(&dst, clr, pbytes, pbytes);
  1424. line += vid_priv->line_length;
  1425. }
  1426. - ret = vidconsole_sync_copy(dev, start, line);
  1427. - if (ret)
  1428. - return ret;
  1429. video_damage(dev->parent,
  1430. vid_priv->xsize - ((row + 1) * fontdata->height),
  1431. @@ -54,7 +50,7 @@ static int console_move_rows_1(struct udevice *dev, uint rowdst, uint rowsrc,
  1432. int pbytes = VNBYTES(vid_priv->bpix);
  1433. void *dst;
  1434. void *src;
  1435. - int j, ret;
  1436. + int j;
  1437. dst = vid_priv->fb + vid_priv->line_length -
  1438. (rowdst + count) * fontdata->height * pbytes;
  1439. @@ -62,10 +58,7 @@ static int console_move_rows_1(struct udevice *dev, uint rowdst, uint rowsrc,
  1440. (rowsrc + count) * fontdata->height * pbytes;
  1441. for (j = 0; j < vid_priv->ysize; j++) {
  1442. - ret = vidconsole_memmove(dev, dst, src,
  1443. - fontdata->height * pbytes * count);
  1444. - if (ret)
  1445. - return ret;
  1446. + memmove(dst, src, fontdata->height * pbytes * count);
  1447. src += vid_priv->line_length;
  1448. dst += vid_priv->line_length;
  1449. }
  1450. @@ -105,10 +98,6 @@ static int console_putc_xy_1(struct udevice *dev, uint x_frac, uint y, int cp)
  1451. return ret;
  1452. /* We draw backwards from 'start, so account for the first line */
  1453. - ret = vidconsole_sync_copy(dev, start - vid_priv->line_length, line);
  1454. - if (ret)
  1455. - return ret;
  1456. -
  1457. video_damage(dev->parent,
  1458. vid_priv->xsize - y - fontdata->height,
  1459. linenum - 1,
  1460. @@ -126,7 +115,7 @@ static int console_set_row_2(struct udevice *dev, uint row, int clr)
  1461. struct video_fontdata *fontdata = priv->fontdata;
  1462. void *start, *line, *dst, *end;
  1463. int pixels = fontdata->height * vid_priv->xsize;
  1464. - int i, ret;
  1465. + int i;
  1466. int pbytes = VNBYTES(vid_priv->bpix);
  1467. start = vid_priv->fb + vid_priv->ysize * vid_priv->line_length -
  1468. @@ -136,9 +125,6 @@ static int console_set_row_2(struct udevice *dev, uint row, int clr)
  1469. for (i = 0; i < pixels; i++)
  1470. fill_pixel_and_goto_next(&dst, clr, pbytes, pbytes);
  1471. end = dst;
  1472. - ret = vidconsole_sync_copy(dev, start, end);
  1473. - if (ret)
  1474. - return ret;
  1475. video_damage(dev->parent,
  1476. 0,
  1477. @@ -164,8 +150,7 @@ static int console_move_rows_2(struct udevice *dev, uint rowdst, uint rowsrc,
  1478. vid_priv->line_length;
  1479. src = end - (rowsrc + count) * fontdata->height *
  1480. vid_priv->line_length;
  1481. - vidconsole_memmove(dev, dst, src,
  1482. - fontdata->height * vid_priv->line_length * count);
  1483. + memmove(dst, src, fontdata->height * vid_priv->line_length * count);
  1484. video_damage(dev->parent,
  1485. 0,
  1486. @@ -201,11 +186,6 @@ static int console_putc_xy_2(struct udevice *dev, uint x_frac, uint y, int cp)
  1487. if (ret)
  1488. return ret;
  1489. - /* Add 4 bytes to allow for the first pixel writen */
  1490. - ret = vidconsole_sync_copy(dev, start + 4, line);
  1491. - if (ret)
  1492. - return ret;
  1493. -
  1494. video_damage(dev->parent,
  1495. x - fontdata->width + 1,
  1496. linenum - fontdata->height + 1,
  1497. @@ -222,7 +202,7 @@ static int console_set_row_3(struct udevice *dev, uint row, int clr)
  1498. struct video_fontdata *fontdata = priv->fontdata;
  1499. int pbytes = VNBYTES(vid_priv->bpix);
  1500. void *start, *dst, *line;
  1501. - int i, j, ret;
  1502. + int i, j;
  1503. start = vid_priv->fb + row * fontdata->height * pbytes;
  1504. line = start;
  1505. @@ -232,9 +212,6 @@ static int console_set_row_3(struct udevice *dev, uint row, int clr)
  1506. fill_pixel_and_goto_next(&dst, clr, pbytes, pbytes);
  1507. line += vid_priv->line_length;
  1508. }
  1509. - ret = vidconsole_sync_copy(dev, start, line);
  1510. - if (ret)
  1511. - return ret;
  1512. video_damage(dev->parent,
  1513. row * fontdata->height,
  1514. @@ -254,16 +231,13 @@ static int console_move_rows_3(struct udevice *dev, uint rowdst, uint rowsrc,
  1515. int pbytes = VNBYTES(vid_priv->bpix);
  1516. void *dst;
  1517. void *src;
  1518. - int j, ret;
  1519. + int j;
  1520. dst = vid_priv->fb + rowdst * fontdata->height * pbytes;
  1521. src = vid_priv->fb + rowsrc * fontdata->height * pbytes;
  1522. for (j = 0; j < vid_priv->ysize; j++) {
  1523. - ret = vidconsole_memmove(dev, dst, src,
  1524. - fontdata->height * pbytes * count);
  1525. - if (ret)
  1526. - return ret;
  1527. + memmove(dst, src, fontdata->height * pbytes * count);
  1528. src += vid_priv->line_length;
  1529. dst += vid_priv->line_length;
  1530. }
  1531. @@ -299,10 +273,6 @@ static int console_putc_xy_3(struct udevice *dev, uint x_frac, uint y, int cp)
  1532. line = start;
  1533. ret = fill_char_horizontally(pfont, &line, vid_priv, fontdata, NORMAL_DIRECTION);
  1534. - if (ret)
  1535. - return ret;
  1536. - /* Add a line to allow for the first pixels writen */
  1537. - ret = vidconsole_sync_copy(dev, start + vid_priv->line_length, line);
  1538. if (ret)
  1539. return ret;
  1540. diff --git a/drivers/video/console_truetype.c b/drivers/video/console_truetype.c
  1541. index 6a17f732fc26..58dcd8e050c3 100644
  1542. --- a/drivers/video/console_truetype.c
  1543. +++ b/drivers/video/console_truetype.c
  1544. @@ -194,7 +194,6 @@ static int console_truetype_set_row(struct udevice *dev, uint row, int clr)
  1545. struct console_tt_priv *priv = dev_get_priv(dev);
  1546. struct console_tt_metrics *met = priv->cur_met;
  1547. void *end, *line;
  1548. - int ret;
  1549. line = vid_priv->fb + row * met->font_size * vid_priv->line_length;
  1550. end = line + met->font_size * vid_priv->line_length;
  1551. @@ -230,9 +229,6 @@ static int console_truetype_set_row(struct udevice *dev, uint row, int clr)
  1552. default:
  1553. return -ENOSYS;
  1554. }
  1555. - ret = vidconsole_sync_copy(dev, line, end);
  1556. - if (ret)
  1557. - return ret;
  1558. video_damage(dev->parent,
  1559. 0,
  1560. @@ -252,14 +248,11 @@ static int console_truetype_move_rows(struct udevice *dev, uint rowdst,
  1561. struct console_tt_metrics *met = priv->cur_met;
  1562. void *dst;
  1563. void *src;
  1564. - int i, diff, ret;
  1565. + int i, diff;
  1566. dst = vid_priv->fb + rowdst * met->font_size * vid_priv->line_length;
  1567. src = vid_priv->fb + rowsrc * met->font_size * vid_priv->line_length;
  1568. - ret = vidconsole_memmove(dev, dst, src, met->font_size *
  1569. - vid_priv->line_length * count);
  1570. - if (ret)
  1571. - return ret;
  1572. + memmove(dst, src, met->font_size * vid_priv->line_length * count);
  1573. /* Scroll up our position history */
  1574. diff = (rowsrc - rowdst) * met->font_size;
  1575. @@ -292,7 +285,7 @@ static int console_truetype_putc_xy(struct udevice *dev, uint x, uint y,
  1576. u8 *bits, *data;
  1577. int advance;
  1578. void *start, *end, *line;
  1579. - int row, ret;
  1580. + int row;
  1581. /* First get some basic metrics about this character */
  1582. stbtt_GetCodepointHMetrics(font, cp, &advance, &lsb);
  1583. @@ -439,9 +432,6 @@ static int console_truetype_putc_xy(struct udevice *dev, uint x, uint y,
  1584. width,
  1585. height);
  1586. - ret = vidconsole_sync_copy(dev, start, line);
  1587. - if (ret)
  1588. - return ret;
  1589. free(data);
  1590. return width_frac;
  1591. diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c
  1592. index 80e7adf6a1a4..6dc5162804aa 100644
  1593. --- a/drivers/video/vidconsole-uclass.c
  1594. +++ b/drivers/video/vidconsole-uclass.c
  1595. @@ -759,22 +759,6 @@ UCLASS_DRIVER(vidconsole) = {
  1596. .per_device_auto = sizeof(struct vidconsole_priv),
  1597. };
  1598. -#ifdef CONFIG_VIDEO_COPY
  1599. -int vidconsole_sync_copy(struct udevice *dev, void *from, void *to)
  1600. -{
  1601. - struct udevice *vid = dev_get_parent(dev);
  1602. -
  1603. - return video_sync_copy(vid, from, to);
  1604. -}
  1605. -
  1606. -int vidconsole_memmove(struct udevice *dev, void *dst, const void *src,
  1607. - int size)
  1608. -{
  1609. - memmove(dst, src, size);
  1610. - return vidconsole_sync_copy(dev, dst, dst + size);
  1611. -}
  1612. -#endif
  1613. -
  1614. int vidconsole_clear_and_reset(struct udevice *dev)
  1615. {
  1616. int ret;
  1617. diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c
  1618. index add7a85b20fe..3b9b9fad0975 100644
  1619. --- a/drivers/video/video-uclass.c
  1620. +++ b/drivers/video/video-uclass.c
  1621. @@ -152,7 +152,7 @@ int video_fill_part(struct udevice *dev, int xstart, int ystart, int xend,
  1622. struct video_priv *priv = dev_get_uclass_priv(dev);
  1623. void *start, *line;
  1624. int pixels = xend - xstart;
  1625. - int row, i, ret;
  1626. + int row, i;
  1627. start = priv->fb + ystart * priv->line_length;
  1628. start += xstart * VNBYTES(priv->bpix);
  1629. @@ -191,9 +191,6 @@ int video_fill_part(struct udevice *dev, int xstart, int ystart, int xend,
  1630. }
  1631. line += priv->line_length;
  1632. }
  1633. - ret = video_sync_copy(dev, start, line);
  1634. - if (ret)
  1635. - return ret;
  1636. video_damage(dev, xstart, ystart, xend - xstart, yend - ystart);
  1637. @@ -217,7 +214,6 @@ int video_reserve_from_bloblist(struct video_handoff *ho)
  1638. int video_fill(struct udevice *dev, u32 colour)
  1639. {
  1640. struct video_priv *priv = dev_get_uclass_priv(dev);
  1641. - int ret;
  1642. switch (priv->bpix) {
  1643. case VIDEO_BPP16:
  1644. @@ -242,9 +238,6 @@ int video_fill(struct udevice *dev, u32 colour)
  1645. memset(priv->fb, colour, priv->fb_size);
  1646. break;
  1647. }
  1648. - ret = video_sync_copy(dev, priv->fb, priv->fb + priv->fb_size);
  1649. - if (ret)
  1650. - return ret;
  1651. video_damage(dev, 0, 0, priv->xsize, priv->ysize);
  1652. @@ -412,6 +405,27 @@ static void video_flush_dcache(struct udevice *vid, bool use_copy)
  1653. }
  1654. #endif
  1655. +static void video_flush_copy(struct udevice *vid)
  1656. +{
  1657. + struct video_priv *priv = dev_get_uclass_priv(vid);
  1658. +
  1659. + if (!priv->copy_fb)
  1660. + return;
  1661. +
  1662. + if (priv->damage.xend && priv->damage.yend) {
  1663. + int lstart = priv->damage.xstart * VNBYTES(priv->bpix);
  1664. + int lend = priv->damage.xend * VNBYTES(priv->bpix);
  1665. + int y;
  1666. +
  1667. + for (y = priv->damage.ystart; y < priv->damage.yend; y++) {
  1668. + ulong offset = (y * priv->line_length) + lstart;
  1669. + ulong len = lend - lstart;
  1670. +
  1671. + memcpy(priv->copy_fb + offset, priv->fb + offset, len);
  1672. + }
  1673. + }
  1674. +}
  1675. +
  1676. /* Flush video activity to the caches */
  1677. int video_sync(struct udevice *vid, bool force)
  1678. {
  1679. @@ -419,6 +433,9 @@ int video_sync(struct udevice *vid, bool force)
  1680. struct video_ops *ops = video_get_ops(vid);
  1681. int ret;
  1682. + if (IS_ENABLED(CONFIG_VIDEO_COPY))
  1683. + video_flush_copy(vid);
  1684. +
  1685. if (ops && ops->video_sync) {
  1686. ret = ops->video_sync(vid);
  1687. if (ret)
  1688. @@ -502,69 +519,6 @@ int video_get_ysize(struct udevice *dev)
  1689. return priv->ysize;
  1690. }
  1691. -#ifdef CONFIG_VIDEO_COPY
  1692. -int video_sync_copy(struct udevice *dev, void *from, void *to)
  1693. -{
  1694. - struct video_priv *priv = dev_get_uclass_priv(dev);
  1695. -
  1696. - if (priv->copy_fb) {
  1697. - long offset, size;
  1698. -
  1699. - /* Find the offset of the first byte to copy */
  1700. - if ((ulong)to > (ulong)from) {
  1701. - size = to - from;
  1702. - offset = from - priv->fb;
  1703. - } else {
  1704. - size = from - to;
  1705. - offset = to - priv->fb;
  1706. - }
  1707. -
  1708. - /*
  1709. - * Allow a bit of leeway for valid requests somewhere near the
  1710. - * frame buffer
  1711. - */
  1712. - if (offset < -priv->fb_size || offset > 2 * priv->fb_size) {
  1713. -#ifdef DEBUG
  1714. - char str[120];
  1715. -
  1716. - snprintf(str, sizeof(str),
  1717. - "[** FAULT sync_copy fb=%p, from=%p, to=%p, offset=%lx]",
  1718. - priv->fb, from, to, offset);
  1719. - console_puts_select_stderr(true, str);
  1720. -#endif
  1721. - return -EFAULT;
  1722. - }
  1723. -
  1724. - /*
  1725. - * Silently crop the memcpy. This allows callers to avoid doing
  1726. - * this themselves. It is common for the end pointer to go a
  1727. - * few lines after the end of the frame buffer, since most of
  1728. - * the update algorithms terminate a line after their last write
  1729. - */
  1730. - if (offset + size > priv->fb_size) {
  1731. - size = priv->fb_size - offset;
  1732. - } else if (offset < 0) {
  1733. - size += offset;
  1734. - offset = 0;
  1735. - }
  1736. -
  1737. - memcpy(priv->copy_fb + offset, priv->fb + offset, size);
  1738. - }
  1739. -
  1740. - return 0;
  1741. -}
  1742. -
  1743. -int video_sync_copy_all(struct udevice *dev)
  1744. -{
  1745. - struct video_priv *priv = dev_get_uclass_priv(dev);
  1746. -
  1747. - video_sync_copy(dev, priv->fb, priv->fb + priv->fb_size);
  1748. -
  1749. - return 0;
  1750. -}
  1751. -
  1752. -#endif
  1753. -
  1754. #define SPLASH_DECL(_name) \
  1755. extern u8 __splash_ ## _name ## _begin[]; \
  1756. extern u8 __splash_ ## _name ## _end[]
  1757. diff --git a/drivers/video/video_bmp.c b/drivers/video/video_bmp.c
  1758. index 78de95607924..1f267d45812c 100644
  1759. --- a/drivers/video/video_bmp.c
  1760. +++ b/drivers/video/video_bmp.c
  1761. @@ -267,7 +267,6 @@ int video_bmp_display(struct udevice *dev, ulong bmp_image, int x, int y,
  1762. enum video_format eformat;
  1763. struct bmp_color_table_entry *palette;
  1764. int hdr_size;
  1765. - int ret;
  1766. if (!bmp || !(bmp->header.signature[0] == 'B' &&
  1767. bmp->header.signature[1] == 'M')) {
  1768. @@ -461,11 +460,5 @@ int video_bmp_display(struct udevice *dev, ulong bmp_image, int x, int y,
  1769. video_damage(dev, x, y, width, height);
  1770. - /* Find the position of the top left of the image in the framebuffer */
  1771. - fb = (uchar *)(priv->fb + y * priv->line_length + x * bpix / 8);
  1772. - ret = video_sync_copy(dev, start, fb);
  1773. - if (ret)
  1774. - return log_ret(ret);
  1775. -
  1776. return video_sync(dev, false);
  1777. }
  1778. diff --git a/include/video.h b/include/video.h
  1779. index d2dabb66e9e6..44557457bf80 100644
  1780. --- a/include/video.h
  1781. +++ b/include/video.h
  1782. @@ -353,43 +353,6 @@ void video_set_default_colors(struct udevice *dev, bool invert);
  1783. */
  1784. int video_default_font_height(struct udevice *dev);
  1785. -#ifdef CONFIG_VIDEO_COPY
  1786. -/**
  1787. - * vidconsole_sync_copy() - Sync back to the copy framebuffer
  1788. - *
  1789. - * This ensures that the copy framebuffer has the same data as the framebuffer
  1790. - * for a particular region. It should be called after the framebuffer is updated
  1791. - *
  1792. - * @from and @to can be in either order. The region between them is synced.
  1793. - *
  1794. - * @dev: Vidconsole device being updated
  1795. - * @from: Start/end address within the framebuffer (->fb)
  1796. - * @to: Other address within the frame buffer
  1797. - * Return: 0 if OK, -EFAULT if the start address is before the start of the
  1798. - * frame buffer start
  1799. - */
  1800. -int video_sync_copy(struct udevice *dev, void *from, void *to);
  1801. -
  1802. -/**
  1803. - * video_sync_copy_all() - Sync the entire framebuffer to the copy
  1804. - *
  1805. - * @dev: Vidconsole device being updated
  1806. - * Return: 0 (always)
  1807. - */
  1808. -int video_sync_copy_all(struct udevice *dev);
  1809. -#else
  1810. -static inline int video_sync_copy(struct udevice *dev, void *from, void *to)
  1811. -{
  1812. - return 0;
  1813. -}
  1814. -
  1815. -static inline int video_sync_copy_all(struct udevice *dev)
  1816. -{
  1817. - return 0;
  1818. -}
  1819. -
  1820. -#endif
  1821. -
  1822. #ifdef CONFIG_VIDEO_DAMAGE
  1823. /**
  1824. * video_damage() - Notify the video subsystem about screen updates.
  1825. diff --git a/include/video_console.h b/include/video_console.h
  1826. index 8b5928dc5ebb..8806d10f946d 100644
  1827. --- a/include/video_console.h
  1828. +++ b/include/video_console.h
  1829. @@ -529,56 +529,4 @@ void vidconsole_list_fonts(struct udevice *dev);
  1830. */
  1831. int vidconsole_get_font_size(struct udevice *dev, const char **name, uint *sizep);
  1832. -#ifdef CONFIG_VIDEO_COPY
  1833. -/**
  1834. - * vidconsole_sync_copy() - Sync back to the copy framebuffer
  1835. - *
  1836. - * This ensures that the copy framebuffer has the same data as the framebuffer
  1837. - * for a particular region. It should be called after the framebuffer is updated
  1838. - *
  1839. - * @from and @to can be in either order. The region between them is synced.
  1840. - *
  1841. - * @dev: Vidconsole device being updated
  1842. - * @from: Start/end address within the framebuffer (->fb)
  1843. - * @to: Other address within the frame buffer
  1844. - * Return: 0 if OK, -EFAULT if the start address is before the start of the
  1845. - * frame buffer start
  1846. - */
  1847. -int vidconsole_sync_copy(struct udevice *dev, void *from, void *to);
  1848. -
  1849. -/**
  1850. - * vidconsole_memmove() - Perform a memmove() within the frame buffer
  1851. - *
  1852. - * This handles a memmove(), e.g. for scrolling. It also updates the copy
  1853. - * framebuffer.
  1854. - *
  1855. - * @dev: Vidconsole device being updated
  1856. - * @dst: Destination address within the framebuffer (->fb)
  1857. - * @src: Source address within the framebuffer (->fb)
  1858. - * @size: Number of bytes to transfer
  1859. - * Return: 0 if OK, -EFAULT if the start address is before the start of the
  1860. - * frame buffer start
  1861. - */
  1862. -int vidconsole_memmove(struct udevice *dev, void *dst, const void *src,
  1863. - int size);
  1864. -#else
  1865. -
  1866. -#include <string.h>
  1867. -
  1868. -static inline int vidconsole_sync_copy(struct udevice *dev, void *from,
  1869. - void *to)
  1870. -{
  1871. - return 0;
  1872. -}
  1873. -
  1874. -static inline int vidconsole_memmove(struct udevice *dev, void *dst,
  1875. - const void *src, int size)
  1876. -{
  1877. - memmove(dst, src, size);
  1878. -
  1879. - return 0;
  1880. -}
  1881. -
  1882. -#endif
  1883. -
  1884. #endif
  1885. diff --git a/test/dm/video.c b/test/dm/video.c
  1886. index 119c43153165..9b7bb51a3dd9 100644
  1887. --- a/test/dm/video.c
  1888. +++ b/test/dm/video.c
  1889. @@ -105,6 +105,7 @@ static int check_copy_frame_buffer(struct unit_test_state *uts,
  1890. if (!IS_ENABLED(CONFIG_VIDEO_COPY))
  1891. return 0;
  1892. + video_sync(dev, false);
  1893. ut_assertf(!memcmp(priv->fb, priv->copy_fb, priv->fb_size),
  1894. "Copy framebuffer does not match fb");
  1895. @@ -705,7 +706,7 @@ static int dm_test_video_copy(struct unit_test_state *uts)
  1896. vidconsole_put_string(con, test_string);
  1897. vidconsole_put_string(con, test_string);
  1898. ut_asserteq(7589, compress_frame_buffer(uts, dev, false));
  1899. - ut_asserteq(5278, compress_frame_buffer(uts, dev, true));
  1900. + ut_asserteq(4127, compress_frame_buffer(uts, dev, true));
  1901. return 0;
  1902. }
  1903. --
  1904. 2.45.2
  1905. From d0b64a4e493b665d7abafc185d88f533ebc27f2f Mon Sep 17 00:00:00 2001
  1906. From: Alexander Graf <agraf@csgraf.de>
  1907. Date: Tue, 3 Jan 2023 22:50:03 +0100
  1908. Subject: [PATCH 12/13] video: Always compile cache flushing code
  1909. The dcache flushing code path was conditional on ARM && !DCACHE config
  1910. options. However, dcaches exist on other platforms as well and may need
  1911. clearing if their driver requires it.
  1912. Simplify the compile logic and always enable the dcache flush logic in
  1913. the video core. That way, drivers can always rely on it to call the arch
  1914. specific callbacks.
  1915. This will increase code size for non-ARM platforms with CONFIG_VIDEO=y
  1916. slightly.
  1917. Reported-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
  1918. Signed-off-by: Alexander Graf <agraf@csgraf.de>
  1919. Reviewed-by: Simon Glass <sjg@chromium.org>
  1920. Link: https://lore.kernel.org/u-boot/20230821135111.3558478-13-alpernebiyasak@gmail.com/
  1921. ---
  1922. drivers/video/video-uclass.c | 12 +++++-------
  1923. 1 file changed, 5 insertions(+), 7 deletions(-)
  1924. diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c
  1925. index 3b9b9fad0975..f050ed1f67cb 100644
  1926. --- a/drivers/video/video-uclass.c
  1927. +++ b/drivers/video/video-uclass.c
  1928. @@ -377,6 +377,9 @@ static void video_flush_dcache(struct udevice *vid, bool use_copy)
  1929. struct video_priv *priv = dev_get_uclass_priv(vid);
  1930. ulong fb = use_copy ? (ulong)priv->copy_fb : (ulong)priv->fb;
  1931. + if (CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
  1932. + return;
  1933. +
  1934. if (!priv->flush_dcache)
  1935. return;
  1936. @@ -442,17 +445,12 @@ int video_sync(struct udevice *vid, bool force)
  1937. return ret;
  1938. }
  1939. - /*
  1940. - * flush_dcache_range() is declared in common.h but it seems that some
  1941. - * architectures do not actually implement it. Is there a way to find
  1942. - * out whether it exists? For now, ARM is safe.
  1943. - */
  1944. -#if defined(CONFIG_ARM) && !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
  1945. video_flush_dcache(vid, false);
  1946. if (IS_ENABLED(CONFIG_VIDEO_COPY))
  1947. video_flush_dcache(vid, true);
  1948. -#elif defined(CONFIG_VIDEO_SANDBOX_SDL)
  1949. +
  1950. +#if defined(CONFIG_VIDEO_SANDBOX_SDL)
  1951. static ulong last_sync;
  1952. if (force || get_timer(last_sync) > 100) {
  1953. --
  1954. 2.45.2
  1955. From e6b053a9d59d0b4ea0936edee5be2fadf0b8efc2 Mon Sep 17 00:00:00 2001
  1956. From: Alexander Graf <agraf@csgraf.de>
  1957. Date: Tue, 3 Jan 2023 22:50:04 +0100
  1958. Subject: [PATCH 13/13] video: Enable VIDEO_DAMAGE for drivers that need it
  1959. Some drivers call video_set_flush_dcache() to indicate that they want to
  1960. have the dcache flushed for the frame buffer. These drivers benefit from
  1961. our new video damage control, because we can reduce the amount of memory
  1962. that gets flushed significantly.
  1963. This patch enables video damage control for all device drivers that call
  1964. video_set_flush_dcache() to make sure they benefit from it.
  1965. Signed-off-by: Alexander Graf <agraf@csgraf.de>
  1966. [Alper: Add to VIDEO_TIDSS, imply instead of select]
  1967. Co-developed-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
  1968. Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
  1969. Reviewed-by: Simon Glass <sjg@chromium.org>
  1970. Link: https://lore.kernel.org/u-boot/20230821135111.3558478-14-alpernebiyasak@gmail.com/
  1971. ---
  1972. arch/arm/mach-sunxi/Kconfig | 1 +
  1973. drivers/video/Kconfig | 8 ++++++++
  1974. drivers/video/exynos/Kconfig | 1 +
  1975. drivers/video/imx/Kconfig | 1 +
  1976. drivers/video/meson/Kconfig | 1 +
  1977. drivers/video/rockchip/Kconfig | 1 +
  1978. drivers/video/stm32/Kconfig | 1 +
  1979. drivers/video/tegra20/Kconfig | 1 +
  1980. drivers/video/tidss/Kconfig | 1 +
  1981. 9 files changed, 16 insertions(+)
  1982. diff --git a/arch/arm/mach-sunxi/Kconfig b/arch/arm/mach-sunxi/Kconfig
  1983. index ddf9414b08e7..3c9745065bab 100644
  1984. --- a/arch/arm/mach-sunxi/Kconfig
  1985. +++ b/arch/arm/mach-sunxi/Kconfig
  1986. @@ -863,6 +863,7 @@ config VIDEO_SUNXI
  1987. depends on !SUNXI_GEN_NCAT2
  1988. select VIDEO
  1989. select DISPLAY
  1990. + imply VIDEO_DAMAGE
  1991. imply VIDEO_DT_SIMPLEFB
  1992. default y
  1993. ---help---
  1994. diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
  1995. index 88c6f8e68976..06d3ed8a736e 100644
  1996. --- a/drivers/video/Kconfig
  1997. +++ b/drivers/video/Kconfig
  1998. @@ -499,6 +499,7 @@ config VIDEO_LCD_ANX9804
  1999. config ATMEL_LCD
  2000. bool "Atmel LCD panel support"
  2001. + imply VIDEO_DAMAGE
  2002. depends on ARCH_AT91
  2003. config ATMEL_LCD_BGR555
  2004. @@ -508,6 +509,7 @@ config ATMEL_LCD_BGR555
  2005. config VIDEO_BCM2835
  2006. bool "Display support for BCM2835"
  2007. + imply VIDEO_DAMAGE
  2008. help
  2009. The graphics processor already sets up the display so this driver
  2010. simply checks the resolution and then sets up the frame buffer with
  2011. @@ -671,6 +673,7 @@ source "drivers/video/meson/Kconfig"
  2012. config VIDEO_MVEBU
  2013. bool "Armada XP LCD controller"
  2014. + imply VIDEO_DAMAGE
  2015. ---help---
  2016. Support for the LCD controller integrated in the Marvell
  2017. Armada XP SoC.
  2018. @@ -705,6 +708,7 @@ config NXP_TDA19988
  2019. config ATMEL_HLCD
  2020. bool "Enable ATMEL video support using HLCDC"
  2021. + imply VIDEO_DAMAGE
  2022. help
  2023. HLCDC supports video output to an attached LCD panel.
  2024. @@ -781,6 +785,7 @@ source "drivers/video/tidss/Kconfig"
  2025. config VIDEO_TEGRA124
  2026. bool "Enable video support on Tegra124"
  2027. + imply VIDEO_DAMAGE
  2028. help
  2029. Tegra124 supports many video output options including eDP and
  2030. HDMI. At present only eDP is supported by U-Boot. This option
  2031. @@ -795,6 +800,7 @@ source "drivers/video/imx/Kconfig"
  2032. config VIDEO_MXS
  2033. bool "Enable video support on i.MX28/i.MX6UL/i.MX7 SoCs"
  2034. + imply VIDEO_DAMAGE
  2035. help
  2036. Enable framebuffer driver for i.MX28/i.MX6UL/i.MX7 processors
  2037. @@ -857,6 +863,7 @@ config VIDEO_DW_MIPI_DSI
  2038. config VIDEO_SIMPLE
  2039. bool "Simple display driver for preconfigured display"
  2040. + imply VIDEO_DAMAGE
  2041. help
  2042. Enables a simple generic display driver which utilizes the
  2043. simple-framebuffer devicetree bindings.
  2044. @@ -875,6 +882,7 @@ config VIDEO_DT_SIMPLEFB
  2045. config VIDEO_MCDE_SIMPLE
  2046. bool "Simple driver for ST-Ericsson MCDE with preconfigured display"
  2047. + imply VIDEO_DAMAGE
  2048. help
  2049. Enables a simple display driver for ST-Ericsson MCDE
  2050. (Multichannel Display Engine), which reads the configuration from
  2051. diff --git a/drivers/video/exynos/Kconfig b/drivers/video/exynos/Kconfig
  2052. index 599d19d5ecc2..a2cf752aac03 100644
  2053. --- a/drivers/video/exynos/Kconfig
  2054. +++ b/drivers/video/exynos/Kconfig
  2055. @@ -12,6 +12,7 @@ config EXYNOS_DP
  2056. config EXYNOS_FB
  2057. bool "Exynos FIMD support"
  2058. + imply VIDEO_DAMAGE
  2059. config EXYNOS_MIPI_DSIM
  2060. bool "Exynos MIPI DSI support"
  2061. diff --git a/drivers/video/imx/Kconfig b/drivers/video/imx/Kconfig
  2062. index 34e8b640595b..5db3e5c0499e 100644
  2063. --- a/drivers/video/imx/Kconfig
  2064. +++ b/drivers/video/imx/Kconfig
  2065. @@ -2,6 +2,7 @@
  2066. config VIDEO_IPUV3
  2067. bool "i.MX IPUv3 Core video support"
  2068. depends on VIDEO && (MX5 || MX6)
  2069. + imply VIDEO_DAMAGE
  2070. help
  2071. This enables framebuffer driver for i.MX processors working
  2072. on the IPUv3(Image Processing Unit) internal graphic processor.
  2073. diff --git a/drivers/video/meson/Kconfig b/drivers/video/meson/Kconfig
  2074. index 3c2d72d019b8..fcf486ca0a3a 100644
  2075. --- a/drivers/video/meson/Kconfig
  2076. +++ b/drivers/video/meson/Kconfig
  2077. @@ -8,5 +8,6 @@ config VIDEO_MESON
  2078. bool "Enable Amlogic Meson video support"
  2079. depends on VIDEO
  2080. select DISPLAY
  2081. + imply VIDEO_DAMAGE
  2082. help
  2083. Enable Amlogic Meson Video Processing Unit video support.
  2084. diff --git a/drivers/video/rockchip/Kconfig b/drivers/video/rockchip/Kconfig
  2085. index 01804dcb1cc8..0f4550a29e38 100644
  2086. --- a/drivers/video/rockchip/Kconfig
  2087. +++ b/drivers/video/rockchip/Kconfig
  2088. @@ -11,6 +11,7 @@
  2089. menuconfig VIDEO_ROCKCHIP
  2090. bool "Enable Rockchip Video Support"
  2091. depends on VIDEO
  2092. + imply VIDEO_DAMAGE
  2093. help
  2094. Rockchip SoCs provide video output capabilities for High-Definition
  2095. Multimedia Interface (HDMI), Low-voltage Differential Signalling
  2096. diff --git a/drivers/video/stm32/Kconfig b/drivers/video/stm32/Kconfig
  2097. index 48066063e4c5..c354c402c288 100644
  2098. --- a/drivers/video/stm32/Kconfig
  2099. +++ b/drivers/video/stm32/Kconfig
  2100. @@ -8,6 +8,7 @@
  2101. menuconfig VIDEO_STM32
  2102. bool "Enable STM32 video support"
  2103. depends on VIDEO
  2104. + imply VIDEO_DAMAGE
  2105. help
  2106. STM32 supports many video output options including RGB and
  2107. DSI. This option enables these supports which can be used on
  2108. diff --git a/drivers/video/tegra20/Kconfig b/drivers/video/tegra20/Kconfig
  2109. index f5c4843e1191..2232b0b3ff53 100644
  2110. --- a/drivers/video/tegra20/Kconfig
  2111. +++ b/drivers/video/tegra20/Kconfig
  2112. @@ -1,6 +1,7 @@
  2113. config VIDEO_TEGRA20
  2114. bool "Enable Display Controller support on Tegra20 and Tegra 30"
  2115. depends on OF_CONTROL
  2116. + imply VIDEO_DAMAGE
  2117. help
  2118. T20/T30 support video output to an attached LCD panel as well as
  2119. other options such as HDMI. Only the LCD is supported in U-Boot.
  2120. diff --git a/drivers/video/tidss/Kconfig b/drivers/video/tidss/Kconfig
  2121. index 95086f3a5d66..3291b3ceb8d5 100644
  2122. --- a/drivers/video/tidss/Kconfig
  2123. +++ b/drivers/video/tidss/Kconfig
  2124. @@ -11,6 +11,7 @@
  2125. menuconfig VIDEO_TIDSS
  2126. bool "Enable TIDSS video support"
  2127. depends on VIDEO
  2128. + imply VIDEO_DAMAGE
  2129. help
  2130. TIDSS supports video output options LVDS and
  2131. DPI . This option enables these supports which can be used on
  2132. --
  2133. 2.45.2