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

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