LCOV - code coverage report
Current view: top level - drivers/gpu/drm/tests - drm_format_helper_test.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 354 354 100.0 %
Date: 2023-07-19 18:55:55 Functions: 27 27 100.0 %

          Line data    Source code
       1             : // SPDX-License-Identifier: GPL-2.0+
       2             : 
       3             : #include <kunit/test.h>
       4             : 
       5             : #include <drm/drm_device.h>
       6             : #include <drm/drm_drv.h>
       7             : #include <drm/drm_file.h>
       8             : #include <drm/drm_format_helper.h>
       9             : #include <drm/drm_fourcc.h>
      10             : #include <drm/drm_framebuffer.h>
      11             : #include <drm/drm_gem_framebuffer_helper.h>
      12             : #include <drm/drm_mode.h>
      13             : #include <drm/drm_print.h>
      14             : #include <drm/drm_rect.h>
      15             : #include <drm/drm_kunit_helpers.h>
      16             : 
      17             : #include "../drm_crtc_internal.h"
      18             : 
      19             : #define TEST_BUF_SIZE 50
      20             : 
      21             : #define TEST_USE_DEFAULT_PITCH 0
      22             : 
      23             : struct convert_to_gray8_result {
      24             :         unsigned int dst_pitch;
      25             :         const u8 expected[TEST_BUF_SIZE];
      26             : };
      27             : 
      28             : struct convert_to_rgb332_result {
      29             :         unsigned int dst_pitch;
      30             :         const u8 expected[TEST_BUF_SIZE];
      31             : };
      32             : 
      33             : struct convert_to_rgb565_result {
      34             :         unsigned int dst_pitch;
      35             :         const u16 expected[TEST_BUF_SIZE];
      36             :         const u16 expected_swab[TEST_BUF_SIZE];
      37             : };
      38             : 
      39             : struct convert_to_xrgb1555_result {
      40             :         unsigned int dst_pitch;
      41             :         const u16 expected[TEST_BUF_SIZE];
      42             : };
      43             : 
      44             : struct convert_to_argb1555_result {
      45             :         unsigned int dst_pitch;
      46             :         const u16 expected[TEST_BUF_SIZE];
      47             : };
      48             : 
      49             : struct convert_to_rgba5551_result {
      50             :         unsigned int dst_pitch;
      51             :         const u16 expected[TEST_BUF_SIZE];
      52             : };
      53             : 
      54             : struct convert_to_rgb888_result {
      55             :         unsigned int dst_pitch;
      56             :         const u8 expected[TEST_BUF_SIZE];
      57             : };
      58             : 
      59             : struct convert_to_argb8888_result {
      60             :         unsigned int dst_pitch;
      61             :         const u32 expected[TEST_BUF_SIZE];
      62             : };
      63             : 
      64             : struct convert_to_xrgb2101010_result {
      65             :         unsigned int dst_pitch;
      66             :         const u32 expected[TEST_BUF_SIZE];
      67             : };
      68             : 
      69             : struct convert_to_argb2101010_result {
      70             :         unsigned int dst_pitch;
      71             :         const u32 expected[TEST_BUF_SIZE];
      72             : };
      73             : 
      74             : struct convert_to_mono_result {
      75             :         unsigned int dst_pitch;
      76             :         const u8 expected[TEST_BUF_SIZE];
      77             : };
      78             : 
      79             : struct fb_swab_result {
      80             :         unsigned int dst_pitch;
      81             :         const u32 expected[TEST_BUF_SIZE];
      82             : };
      83             : 
      84             : struct convert_xrgb8888_case {
      85             :         const char *name;
      86             :         unsigned int pitch;
      87             :         struct drm_rect clip;
      88             :         const u32 xrgb8888[TEST_BUF_SIZE];
      89             :         struct convert_to_gray8_result gray8_result;
      90             :         struct convert_to_rgb332_result rgb332_result;
      91             :         struct convert_to_rgb565_result rgb565_result;
      92             :         struct convert_to_xrgb1555_result xrgb1555_result;
      93             :         struct convert_to_argb1555_result argb1555_result;
      94             :         struct convert_to_rgba5551_result rgba5551_result;
      95             :         struct convert_to_rgb888_result rgb888_result;
      96             :         struct convert_to_argb8888_result argb8888_result;
      97             :         struct convert_to_xrgb2101010_result xrgb2101010_result;
      98             :         struct convert_to_argb2101010_result argb2101010_result;
      99             :         struct convert_to_mono_result mono_result;
     100             :         struct fb_swab_result swab_result;
     101             : };
     102             : 
     103             : static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
     104             :         {
     105             :                 .name = "single_pixel_source_buffer",
     106             :                 .pitch = 1 * 4,
     107             :                 .clip = DRM_RECT_INIT(0, 0, 1, 1),
     108             :                 .xrgb8888 = { 0x01FF0000 },
     109             :                 .gray8_result = {
     110             :                         .dst_pitch = TEST_USE_DEFAULT_PITCH,
     111             :                         .expected = { 0x4C },
     112             :                 },
     113             :                 .rgb332_result = {
     114             :                         .dst_pitch = TEST_USE_DEFAULT_PITCH,
     115             :                         .expected = { 0xE0 },
     116             :                 },
     117             :                 .rgb565_result = {
     118             :                         .dst_pitch = TEST_USE_DEFAULT_PITCH,
     119             :                         .expected = { 0xF800 },
     120             :                         .expected_swab = { 0x00F8 },
     121             :                 },
     122             :                 .xrgb1555_result = {
     123             :                         .dst_pitch = TEST_USE_DEFAULT_PITCH,
     124             :                         .expected = { 0x7C00 },
     125             :                 },
     126             :                 .argb1555_result = {
     127             :                         .dst_pitch = TEST_USE_DEFAULT_PITCH,
     128             :                         .expected = { 0xFC00 },
     129             :                 },
     130             :                 .rgba5551_result = {
     131             :                         .dst_pitch = TEST_USE_DEFAULT_PITCH,
     132             :                         .expected = { 0xF801 },
     133             :                 },
     134             :                 .rgb888_result = {
     135             :                         .dst_pitch = TEST_USE_DEFAULT_PITCH,
     136             :                         .expected = { 0x00, 0x00, 0xFF },
     137             :                 },
     138             :                 .argb8888_result = {
     139             :                         .dst_pitch = TEST_USE_DEFAULT_PITCH,
     140             :                         .expected = { 0xFFFF0000 },
     141             :                 },
     142             :                 .xrgb2101010_result = {
     143             :                         .dst_pitch = TEST_USE_DEFAULT_PITCH,
     144             :                         .expected = { 0x3FF00000 },
     145             :                 },
     146             :                 .argb2101010_result = {
     147             :                         .dst_pitch = TEST_USE_DEFAULT_PITCH,
     148             :                         .expected = { 0xFFF00000 },
     149             :                 },
     150             :                 .mono_result = {
     151             :                         .dst_pitch =  TEST_USE_DEFAULT_PITCH,
     152             :                         .expected = { 0b0 },
     153             :                 },
     154             :                 .swab_result = {
     155             :                         .dst_pitch =  TEST_USE_DEFAULT_PITCH,
     156             :                         .expected = { 0x0000FF01 },
     157             :                 },
     158             :         },
     159             :         {
     160             :                 .name = "single_pixel_clip_rectangle",
     161             :                 .pitch = 2 * 4,
     162             :                 .clip = DRM_RECT_INIT(1, 1, 1, 1),
     163             :                 .xrgb8888 = {
     164             :                         0x00000000, 0x00000000,
     165             :                         0x00000000, 0x10FF0000,
     166             :                 },
     167             :                 .gray8_result = {
     168             :                         .dst_pitch = TEST_USE_DEFAULT_PITCH,
     169             :                         .expected = { 0x4C },
     170             :                 },
     171             :                 .rgb332_result = {
     172             :                         .dst_pitch = TEST_USE_DEFAULT_PITCH,
     173             :                         .expected = { 0xE0 },
     174             :                 },
     175             :                 .rgb565_result = {
     176             :                         .dst_pitch = TEST_USE_DEFAULT_PITCH,
     177             :                         .expected = { 0xF800 },
     178             :                         .expected_swab = { 0x00F8 },
     179             :                 },
     180             :                 .xrgb1555_result = {
     181             :                         .dst_pitch = TEST_USE_DEFAULT_PITCH,
     182             :                         .expected = { 0x7C00 },
     183             :                 },
     184             :                 .argb1555_result = {
     185             :                         .dst_pitch = TEST_USE_DEFAULT_PITCH,
     186             :                         .expected = { 0xFC00 },
     187             :                 },
     188             :                 .rgba5551_result = {
     189             :                         .dst_pitch = TEST_USE_DEFAULT_PITCH,
     190             :                         .expected = { 0xF801 },
     191             :                 },
     192             :                 .rgb888_result = {
     193             :                         .dst_pitch = TEST_USE_DEFAULT_PITCH,
     194             :                         .expected = { 0x00, 0x00, 0xFF },
     195             :                 },
     196             :                 .argb8888_result = {
     197             :                         .dst_pitch = TEST_USE_DEFAULT_PITCH,
     198             :                         .expected = { 0xFFFF0000 },
     199             :                 },
     200             :                 .xrgb2101010_result = {
     201             :                         .dst_pitch = TEST_USE_DEFAULT_PITCH,
     202             :                         .expected = { 0x3FF00000 },
     203             :                 },
     204             :                 .argb2101010_result = {
     205             :                         .dst_pitch = TEST_USE_DEFAULT_PITCH,
     206             :                         .expected = { 0xFFF00000 },
     207             :                 },
     208             :                 .mono_result = {
     209             :                         .dst_pitch = TEST_USE_DEFAULT_PITCH,
     210             :                         .expected = { 0b0 },
     211             :                 },
     212             :                 .swab_result = {
     213             :                         .dst_pitch =  TEST_USE_DEFAULT_PITCH,
     214             :                         .expected = { 0x0000FF10 },
     215             :                 },
     216             :         },
     217             :         {
     218             :                 /* Well known colors: White, black, red, green, blue, magenta,
     219             :                  * yellow and cyan. Different values for the X in XRGB8888 to
     220             :                  * make sure it is ignored. Partial clip area.
     221             :                  */
     222             :                 .name = "well_known_colors",
     223             :                 .pitch = 4 * 4,
     224             :                 .clip = DRM_RECT_INIT(1, 1, 2, 4),
     225             :                 .xrgb8888 = {
     226             :                         0x00000000, 0x00000000, 0x00000000, 0x00000000,
     227             :                         0x00000000, 0x11FFFFFF, 0x22000000, 0x00000000,
     228             :                         0x00000000, 0x33FF0000, 0x4400FF00, 0x00000000,
     229             :                         0x00000000, 0x550000FF, 0x66FF00FF, 0x00000000,
     230             :                         0x00000000, 0x77FFFF00, 0x8800FFFF, 0x00000000,
     231             :                 },
     232             :                 .gray8_result = {
     233             :                         .dst_pitch = TEST_USE_DEFAULT_PITCH,
     234             :                         .expected = {
     235             :                                 0xFF, 0x00,
     236             :                                 0x4C, 0x99,
     237             :                                 0x19, 0x66,
     238             :                                 0xE5, 0xB2,
     239             :                         },
     240             :                 },
     241             :                 .rgb332_result = {
     242             :                         .dst_pitch = TEST_USE_DEFAULT_PITCH,
     243             :                         .expected = {
     244             :                                 0xFF, 0x00,
     245             :                                 0xE0, 0x1C,
     246             :                                 0x03, 0xE3,
     247             :                                 0xFC, 0x1F,
     248             :                         },
     249             :                 },
     250             :                 .rgb565_result = {
     251             :                         .dst_pitch = TEST_USE_DEFAULT_PITCH,
     252             :                         .expected = {
     253             :                                 0xFFFF, 0x0000,
     254             :                                 0xF800, 0x07E0,
     255             :                                 0x001F, 0xF81F,
     256             :                                 0xFFE0, 0x07FF,
     257             :                         },
     258             :                         .expected_swab = {
     259             :                                 0xFFFF, 0x0000,
     260             :                                 0x00F8, 0xE007,
     261             :                                 0x1F00, 0x1FF8,
     262             :                                 0xE0FF, 0xFF07,
     263             :                         },
     264             :                 },
     265             :                 .xrgb1555_result = {
     266             :                         .dst_pitch = TEST_USE_DEFAULT_PITCH,
     267             :                         .expected = {
     268             :                                 0x7FFF, 0x0000,
     269             :                                 0x7C00, 0x03E0,
     270             :                                 0x001F, 0x7C1F,
     271             :                                 0x7FE0, 0x03FF,
     272             :                         },
     273             :                 },
     274             :                 .argb1555_result = {
     275             :                         .dst_pitch = TEST_USE_DEFAULT_PITCH,
     276             :                         .expected = {
     277             :                                 0xFFFF, 0x8000,
     278             :                                 0xFC00, 0x83E0,
     279             :                                 0x801F, 0xFC1F,
     280             :                                 0xFFE0, 0x83FF,
     281             :                         },
     282             :                 },
     283             :                 .rgba5551_result = {
     284             :                         .dst_pitch = TEST_USE_DEFAULT_PITCH,
     285             :                         .expected = {
     286             :                                 0xFFFF, 0x0001,
     287             :                                 0xF801, 0x07C1,
     288             :                                 0x003F, 0xF83F,
     289             :                                 0xFFC1, 0x07FF,
     290             :                         },
     291             :                 },
     292             :                 .rgb888_result = {
     293             :                         .dst_pitch = TEST_USE_DEFAULT_PITCH,
     294             :                         .expected = {
     295             :                                 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00,
     296             :                                 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00,
     297             :                                 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF,
     298             :                                 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00,
     299             :                         },
     300             :                 },
     301             :                 .argb8888_result = {
     302             :                         .dst_pitch = TEST_USE_DEFAULT_PITCH,
     303             :                         .expected = {
     304             :                                 0xFFFFFFFF, 0xFF000000,
     305             :                                 0xFFFF0000, 0xFF00FF00,
     306             :                                 0xFF0000FF, 0xFFFF00FF,
     307             :                                 0xFFFFFF00, 0xFF00FFFF,
     308             :                         },
     309             :                 },
     310             :                 .xrgb2101010_result = {
     311             :                         .dst_pitch = TEST_USE_DEFAULT_PITCH,
     312             :                         .expected = {
     313             :                                 0x3FFFFFFF, 0x00000000,
     314             :                                 0x3FF00000, 0x000FFC00,
     315             :                                 0x000003FF, 0x3FF003FF,
     316             :                                 0x3FFFFC00, 0x000FFFFF,
     317             :                         },
     318             :                 },
     319             :                 .argb2101010_result = {
     320             :                         .dst_pitch = TEST_USE_DEFAULT_PITCH,
     321             :                         .expected = {
     322             :                                 0xFFFFFFFF, 0xC0000000,
     323             :                                 0xFFF00000, 0xC00FFC00,
     324             :                                 0xC00003FF, 0xFFF003FF,
     325             :                                 0xFFFFFC00, 0xC00FFFFF,
     326             :                         },
     327             :                 },
     328             :                 .mono_result = {
     329             :                         .dst_pitch =  TEST_USE_DEFAULT_PITCH,
     330             :                         .expected = {
     331             :                                 0b01,
     332             :                                 0b10,
     333             :                                 0b00,
     334             :                                 0b11,
     335             :                         },
     336             :                 },
     337             :                 .swab_result = {
     338             :                         .dst_pitch =  TEST_USE_DEFAULT_PITCH,
     339             :                         .expected = {
     340             :                                 0xFFFFFF11, 0x00000022,
     341             :                                 0x0000FF33, 0x00FF0044,
     342             :                                 0xFF000055, 0xFF00FF66,
     343             :                                 0x00FFFF77, 0xFFFF0088,
     344             :                         },
     345             :                 },
     346             :         },
     347             :         {
     348             :                 /* Randomly picked colors. Full buffer within the clip area. */
     349             :                 .name = "destination_pitch",
     350             :                 .pitch = 3 * 4,
     351             :                 .clip = DRM_RECT_INIT(0, 0, 3, 3),
     352             :                 .xrgb8888 = {
     353             :                         0xA10E449C, 0xB1114D05, 0xC1A8F303,
     354             :                         0xD16CF073, 0xA20E449C, 0xB2114D05,
     355             :                         0xC2A80303, 0xD26CF073, 0xA30E449C,
     356             :                 },
     357             :                 .gray8_result = {
     358             :                         .dst_pitch = 5,
     359             :                         .expected = {
     360             :                                 0x3C, 0x33, 0xC4, 0x00, 0x00,
     361             :                                 0xBB, 0x3C, 0x33, 0x00, 0x00,
     362             :                                 0x34, 0xBB, 0x3C, 0x00, 0x00,
     363             :                         },
     364             :                 },
     365             :                 .rgb332_result = {
     366             :                         .dst_pitch = 5,
     367             :                         .expected = {
     368             :                                 0x0A, 0x08, 0xBC, 0x00, 0x00,
     369             :                                 0x7D, 0x0A, 0x08, 0x00, 0x00,
     370             :                                 0xA0, 0x7D, 0x0A, 0x00, 0x00,
     371             :                         },
     372             :                 },
     373             :                 .rgb565_result = {
     374             :                         .dst_pitch = 10,
     375             :                         .expected = {
     376             :                                 0x0A33, 0x1260, 0xAF80, 0x0000, 0x0000,
     377             :                                 0x6F8E, 0x0A33, 0x1260, 0x0000, 0x0000,
     378             :                                 0xA800, 0x6F8E, 0x0A33, 0x0000, 0x0000,
     379             :                         },
     380             :                         .expected_swab = {
     381             :                                 0x330A, 0x6012, 0x80AF, 0x0000, 0x0000,
     382             :                                 0x8E6F, 0x330A, 0x6012, 0x0000, 0x0000,
     383             :                                 0x00A8, 0x8E6F, 0x330A, 0x0000, 0x0000,
     384             :                         },
     385             :                 },
     386             :                 .xrgb1555_result = {
     387             :                         .dst_pitch = 10,
     388             :                         .expected = {
     389             :                                 0x0513, 0x0920, 0x57C0, 0x0000, 0x0000,
     390             :                                 0x37CE, 0x0513, 0x0920, 0x0000, 0x0000,
     391             :                                 0x5400, 0x37CE, 0x0513, 0x0000, 0x0000,
     392             :                         },
     393             :                 },
     394             :                 .argb1555_result = {
     395             :                         .dst_pitch = 10,
     396             :                         .expected = {
     397             :                                 0x8513, 0x8920, 0xD7C0, 0x0000, 0x0000,
     398             :                                 0xB7CE, 0x8513, 0x8920, 0x0000, 0x0000,
     399             :                                 0xD400, 0xB7CE, 0x8513, 0x0000, 0x0000,
     400             :                         },
     401             :                 },
     402             :                 .rgba5551_result = {
     403             :                         .dst_pitch = 10,
     404             :                         .expected = {
     405             :                                 0x0A27, 0x1241, 0xAF81, 0x0000, 0x0000,
     406             :                                 0x6F9D, 0x0A27, 0x1241, 0x0000, 0x0000,
     407             :                                 0xA801, 0x6F9D, 0x0A27, 0x0000, 0x0000,
     408             :                         },
     409             :                 },
     410             :                 .rgb888_result = {
     411             :                         .dst_pitch = 15,
     412             :                         .expected = {
     413             :                                 0x9C, 0x44, 0x0E, 0x05, 0x4D, 0x11, 0x03, 0xF3, 0xA8,
     414             :                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     415             :                                 0x73, 0xF0, 0x6C, 0x9C, 0x44, 0x0E, 0x05, 0x4D, 0x11,
     416             :                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     417             :                                 0x03, 0x03, 0xA8, 0x73, 0xF0, 0x6C, 0x9C, 0x44, 0x0E,
     418             :                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     419             :                         },
     420             :                 },
     421             :                 .argb8888_result = {
     422             :                         .dst_pitch = 20,
     423             :                         .expected = {
     424             :                                 0xFF0E449C, 0xFF114D05, 0xFFA8F303, 0x00000000, 0x00000000,
     425             :                                 0xFF6CF073, 0xFF0E449C, 0xFF114D05, 0x00000000, 0x00000000,
     426             :                                 0xFFA80303, 0xFF6CF073, 0xFF0E449C, 0x00000000, 0x00000000,
     427             :                         },
     428             :                 },
     429             :                 .xrgb2101010_result = {
     430             :                         .dst_pitch = 20,
     431             :                         .expected = {
     432             :                                 0x03844672, 0x0444D414, 0x2A2F3C0C, 0x00000000, 0x00000000,
     433             :                                 0x1B1F0DCD, 0x03844672, 0x0444D414, 0x00000000, 0x00000000,
     434             :                                 0x2A20300C, 0x1B1F0DCD, 0x03844672, 0x00000000, 0x00000000,
     435             :                         },
     436             :                 },
     437             :                 .argb2101010_result = {
     438             :                         .dst_pitch = 20,
     439             :                         .expected = {
     440             :                                 0xC3844672, 0xC444D414, 0xEA2F3C0C, 0x00000000, 0x00000000,
     441             :                                 0xDB1F0DCD, 0xC3844672, 0xC444D414, 0x00000000, 0x00000000,
     442             :                                 0xEA20300C, 0xDB1F0DCD, 0xC3844672, 0x00000000, 0x00000000,
     443             :                         },
     444             :                 },
     445             :                 .mono_result = {
     446             :                         .dst_pitch = 2,
     447             :                         .expected = {
     448             :                                 0b100, 0b000,
     449             :                                 0b001, 0b000,
     450             :                                 0b010, 0b000,
     451             :                         },
     452             :                 },
     453             :                 .swab_result = {
     454             :                         .dst_pitch =  20,
     455             :                         .expected = {
     456             :                                 0x9C440EA1, 0x054D11B1, 0x03F3A8C1, 0x00000000, 0x00000000,
     457             :                                 0x73F06CD1, 0x9C440EA2, 0x054D11B2, 0x00000000, 0x00000000,
     458             :                                 0x0303A8C2, 0x73F06CD2, 0x9C440EA3, 0x00000000, 0x00000000,
     459             :                         },
     460             :                 },
     461             :         },
     462             : };
     463             : 
     464             : /*
     465             :  * conversion_buf_size - Return the destination buffer size required to convert
     466             :  * between formats.
     467             :  * @dst_format: destination buffer pixel format (DRM_FORMAT_*)
     468             :  * @dst_pitch: Number of bytes between two consecutive scanlines within dst
     469             :  * @clip: Clip rectangle area to convert
     470             :  *
     471             :  * Returns:
     472             :  * The size of the destination buffer or negative value on error.
     473             :  */
     474          72 : static size_t conversion_buf_size(u32 dst_format, unsigned int dst_pitch,
     475             :                                   const struct drm_rect *clip, int plane)
     476             : {
     477          72 :         const struct drm_format_info *dst_fi = drm_format_info(dst_format);
     478             : 
     479          72 :         if (!dst_fi)
     480             :                 return -EINVAL;
     481             : 
     482          72 :         if (!dst_pitch)
     483         108 :                 dst_pitch = drm_format_info_min_pitch(dst_fi, plane, drm_rect_width(clip));
     484             : 
     485         144 :         return dst_pitch * drm_rect_height(clip);
     486             : }
     487             : 
     488          20 : static u16 *le16buf_to_cpu(struct kunit *test, const __le16 *buf, size_t buf_size)
     489             : {
     490          20 :         u16 *dst = NULL;
     491             :         int n;
     492             : 
     493          40 :         dst = kunit_kzalloc(test, sizeof(*dst) * buf_size, GFP_KERNEL);
     494          20 :         if (!dst)
     495             :                 return NULL;
     496             : 
     497         125 :         for (n = 0; n < buf_size; n++)
     498         125 :                 dst[n] = le16_to_cpu(buf[n]);
     499             : 
     500             :         return dst;
     501             : }
     502             : 
     503          12 : static u32 *le32buf_to_cpu(struct kunit *test, const __le32 *buf, size_t buf_size)
     504             : {
     505          12 :         u32 *dst = NULL;
     506             :         int n;
     507             : 
     508          24 :         dst = kunit_kzalloc(test, sizeof(*dst) * buf_size, GFP_KERNEL);
     509          12 :         if (!dst)
     510             :                 return NULL;
     511             : 
     512          75 :         for (n = 0; n < buf_size; n++)
     513          75 :                 dst[n] = le32_to_cpu((__force __le32)buf[n]);
     514             : 
     515             :         return dst;
     516             : }
     517             : 
     518          48 : static __le32 *cpubuf_to_le32(struct kunit *test, const u32 *buf, size_t buf_size)
     519             : {
     520          48 :         __le32 *dst = NULL;
     521             :         int n;
     522             : 
     523          96 :         dst = kunit_kzalloc(test, sizeof(*dst) * buf_size, GFP_KERNEL);
     524          48 :         if (!dst)
     525             :                 return NULL;
     526             : 
     527        2400 :         for (n = 0; n < buf_size; n++)
     528        2400 :                 dst[n] = cpu_to_le32(buf[n]);
     529             : 
     530             :         return dst;
     531             : }
     532          48 : static void convert_xrgb8888_case_desc(struct convert_xrgb8888_case *t,
     533             :                                        char *desc)
     534             : {
     535          48 :         strscpy(desc, t->name, KUNIT_PARAM_DESC_SIZE);
     536          48 : }
     537             : 
     538          60 : KUNIT_ARRAY_PARAM(convert_xrgb8888, convert_xrgb8888_cases,
     539             :                   convert_xrgb8888_case_desc);
     540             : 
     541           4 : static void drm_test_fb_xrgb8888_to_gray8(struct kunit *test)
     542             : {
     543           4 :         const struct convert_xrgb8888_case *params = test->param_value;
     544           4 :         const struct convert_to_gray8_result *result = &params->gray8_result;
     545             :         size_t dst_size;
     546           4 :         u8 *buf = NULL;
     547           4 :         __le32 *xrgb8888 = NULL;
     548             :         struct iosys_map dst, src;
     549             : 
     550          12 :         struct drm_framebuffer fb = {
     551           4 :                 .format = drm_format_info(DRM_FORMAT_XRGB8888),
     552           4 :                 .pitches = { params->pitch, 0, 0 },
     553             :         };
     554             : 
     555           4 :         dst_size = conversion_buf_size(DRM_FORMAT_R8, result->dst_pitch,
     556             :                                        &params->clip, 0);
     557           4 :         KUNIT_ASSERT_GT(test, dst_size, 0);
     558             : 
     559           4 :         buf = kunit_kzalloc(test, dst_size, GFP_KERNEL);
     560           8 :         KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
     561           4 :         iosys_map_set_vaddr(&dst, buf);
     562             : 
     563           4 :         xrgb8888 = cpubuf_to_le32(test, params->xrgb8888, TEST_BUF_SIZE);
     564           8 :         KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb8888);
     565           4 :         iosys_map_set_vaddr(&src, xrgb8888);
     566             : 
     567           4 :         if (result->dst_pitch == TEST_USE_DEFAULT_PITCH)
     568           3 :                 drm_fb_xrgb8888_to_gray8(&dst, NULL, &src, &fb, &params->clip);
     569             :         else
     570           1 :                 drm_fb_xrgb8888_to_gray8(&dst, &result->dst_pitch, &src, &fb, &params->clip);
     571           4 :         KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
     572           4 : }
     573             : 
     574           4 : static void drm_test_fb_xrgb8888_to_rgb332(struct kunit *test)
     575             : {
     576           4 :         const struct convert_xrgb8888_case *params = test->param_value;
     577           4 :         const struct convert_to_rgb332_result *result = &params->rgb332_result;
     578             :         size_t dst_size;
     579           4 :         u8 *buf = NULL;
     580           4 :         __le32 *xrgb8888 = NULL;
     581             :         struct iosys_map dst, src;
     582             : 
     583          12 :         struct drm_framebuffer fb = {
     584           4 :                 .format = drm_format_info(DRM_FORMAT_XRGB8888),
     585           4 :                 .pitches = { params->pitch, 0, 0 },
     586             :         };
     587             : 
     588           4 :         dst_size = conversion_buf_size(DRM_FORMAT_RGB332, result->dst_pitch,
     589             :                                        &params->clip, 0);
     590           4 :         KUNIT_ASSERT_GT(test, dst_size, 0);
     591             : 
     592           4 :         buf = kunit_kzalloc(test, dst_size, GFP_KERNEL);
     593           8 :         KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
     594           4 :         iosys_map_set_vaddr(&dst, buf);
     595             : 
     596           4 :         xrgb8888 = cpubuf_to_le32(test, params->xrgb8888, TEST_BUF_SIZE);
     597           8 :         KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb8888);
     598           4 :         iosys_map_set_vaddr(&src, xrgb8888);
     599             : 
     600           4 :         if (result->dst_pitch == TEST_USE_DEFAULT_PITCH)
     601           3 :                 drm_fb_xrgb8888_to_rgb332(&dst, NULL, &src, &fb, &params->clip);
     602             :         else
     603           1 :                 drm_fb_xrgb8888_to_rgb332(&dst, &result->dst_pitch, &src, &fb, &params->clip);
     604           4 :         KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
     605           4 : }
     606             : 
     607           4 : static void drm_test_fb_xrgb8888_to_rgb565(struct kunit *test)
     608             : {
     609           4 :         const struct convert_xrgb8888_case *params = test->param_value;
     610           4 :         const struct convert_to_rgb565_result *result = &params->rgb565_result;
     611             :         size_t dst_size;
     612           4 :         u16 *buf = NULL;
     613           4 :         __le32 *xrgb8888 = NULL;
     614             :         struct iosys_map dst, src;
     615             : 
     616          12 :         struct drm_framebuffer fb = {
     617           4 :                 .format = drm_format_info(DRM_FORMAT_XRGB8888),
     618           4 :                 .pitches = { params->pitch, 0, 0 },
     619             :         };
     620             : 
     621           4 :         dst_size = conversion_buf_size(DRM_FORMAT_RGB565, result->dst_pitch,
     622             :                                        &params->clip, 0);
     623           4 :         KUNIT_ASSERT_GT(test, dst_size, 0);
     624             : 
     625           4 :         buf = kunit_kzalloc(test, dst_size, GFP_KERNEL);
     626           8 :         KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
     627           4 :         iosys_map_set_vaddr(&dst, buf);
     628             : 
     629           4 :         xrgb8888 = cpubuf_to_le32(test, params->xrgb8888, TEST_BUF_SIZE);
     630           8 :         KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb8888);
     631           4 :         iosys_map_set_vaddr(&src, xrgb8888);
     632             : 
     633           4 :         if (result->dst_pitch == TEST_USE_DEFAULT_PITCH)
     634           3 :                 drm_fb_xrgb8888_to_rgb565(&dst, NULL, &src, &fb, &params->clip, false);
     635             :         else
     636           1 :                 drm_fb_xrgb8888_to_rgb565(&dst, &result->dst_pitch, &src, &fb, &params->clip,
     637             :                                           false);
     638           4 :         buf = le16buf_to_cpu(test, (__force const __le16 *)buf, dst_size / sizeof(__le16));
     639           4 :         KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
     640             : 
     641           4 :         buf = dst.vaddr; /* restore original value of buf */
     642           4 :         if (result->dst_pitch == TEST_USE_DEFAULT_PITCH)
     643           3 :                 drm_fb_xrgb8888_to_rgb565(&dst, NULL, &src, &fb, &params->clip, true);
     644             :         else
     645           1 :                 drm_fb_xrgb8888_to_rgb565(&dst, &result->dst_pitch, &src, &fb, &params->clip, true);
     646           4 :         buf = le16buf_to_cpu(test, (__force const __le16 *)buf, dst_size / sizeof(__le16));
     647           4 :         KUNIT_EXPECT_MEMEQ(test, buf, result->expected_swab, dst_size);
     648           4 : }
     649             : 
     650           4 : static void drm_test_fb_xrgb8888_to_xrgb1555(struct kunit *test)
     651             : {
     652           4 :         const struct convert_xrgb8888_case *params = test->param_value;
     653           4 :         const struct convert_to_xrgb1555_result *result = &params->xrgb1555_result;
     654             :         size_t dst_size;
     655           4 :         u16 *buf = NULL;
     656           4 :         __le32 *xrgb8888 = NULL;
     657             :         struct iosys_map dst, src;
     658             : 
     659          12 :         struct drm_framebuffer fb = {
     660           4 :                 .format = drm_format_info(DRM_FORMAT_XRGB8888),
     661           4 :                 .pitches = { params->pitch, 0, 0 },
     662             :         };
     663             : 
     664           4 :         dst_size = conversion_buf_size(DRM_FORMAT_XRGB1555, result->dst_pitch,
     665             :                                        &params->clip, 0);
     666           4 :         KUNIT_ASSERT_GT(test, dst_size, 0);
     667             : 
     668           4 :         buf = kunit_kzalloc(test, dst_size, GFP_KERNEL);
     669           8 :         KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
     670           4 :         iosys_map_set_vaddr(&dst, buf);
     671             : 
     672           4 :         xrgb8888 = cpubuf_to_le32(test, params->xrgb8888, TEST_BUF_SIZE);
     673           8 :         KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb8888);
     674           4 :         iosys_map_set_vaddr(&src, xrgb8888);
     675             : 
     676           4 :         if (result->dst_pitch == TEST_USE_DEFAULT_PITCH)
     677           3 :                 drm_fb_xrgb8888_to_xrgb1555(&dst, NULL, &src, &fb, &params->clip);
     678             :         else
     679           1 :                 drm_fb_xrgb8888_to_xrgb1555(&dst, &result->dst_pitch, &src, &fb, &params->clip);
     680           4 :         buf = le16buf_to_cpu(test, (__force const __le16 *)buf, dst_size / sizeof(__le16));
     681           4 :         KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
     682           4 : }
     683             : 
     684           4 : static void drm_test_fb_xrgb8888_to_argb1555(struct kunit *test)
     685             : {
     686           4 :         const struct convert_xrgb8888_case *params = test->param_value;
     687           4 :         const struct convert_to_argb1555_result *result = &params->argb1555_result;
     688             :         size_t dst_size;
     689           4 :         u16 *buf = NULL;
     690           4 :         __le32 *xrgb8888 = NULL;
     691             :         struct iosys_map dst, src;
     692             : 
     693          12 :         struct drm_framebuffer fb = {
     694           4 :                 .format = drm_format_info(DRM_FORMAT_XRGB8888),
     695           4 :                 .pitches = { params->pitch, 0, 0 },
     696             :         };
     697             : 
     698           4 :         dst_size = conversion_buf_size(DRM_FORMAT_ARGB1555, result->dst_pitch,
     699             :                                        &params->clip, 0);
     700           4 :         KUNIT_ASSERT_GT(test, dst_size, 0);
     701             : 
     702           4 :         buf = kunit_kzalloc(test, dst_size, GFP_KERNEL);
     703           8 :         KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
     704           4 :         iosys_map_set_vaddr(&dst, buf);
     705             : 
     706           4 :         xrgb8888 = cpubuf_to_le32(test, params->xrgb8888, TEST_BUF_SIZE);
     707           8 :         KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb8888);
     708           4 :         iosys_map_set_vaddr(&src, xrgb8888);
     709             : 
     710           4 :         if (result->dst_pitch == TEST_USE_DEFAULT_PITCH)
     711           3 :                 drm_fb_xrgb8888_to_argb1555(&dst, NULL, &src, &fb, &params->clip);
     712             :         else
     713           1 :                 drm_fb_xrgb8888_to_argb1555(&dst, &result->dst_pitch, &src, &fb, &params->clip);
     714           4 :         buf = le16buf_to_cpu(test, (__force const __le16 *)buf, dst_size / sizeof(__le16));
     715           4 :         KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
     716           4 : }
     717             : 
     718           4 : static void drm_test_fb_xrgb8888_to_rgba5551(struct kunit *test)
     719             : {
     720           4 :         const struct convert_xrgb8888_case *params = test->param_value;
     721           4 :         const struct convert_to_rgba5551_result *result = &params->rgba5551_result;
     722             :         size_t dst_size;
     723           4 :         u16 *buf = NULL;
     724           4 :         __le32 *xrgb8888 = NULL;
     725             :         struct iosys_map dst, src;
     726             : 
     727          12 :         struct drm_framebuffer fb = {
     728           4 :                 .format = drm_format_info(DRM_FORMAT_XRGB8888),
     729           4 :                 .pitches = { params->pitch, 0, 0 },
     730             :         };
     731             : 
     732           4 :         dst_size = conversion_buf_size(DRM_FORMAT_RGBA5551, result->dst_pitch,
     733             :                                        &params->clip, 0);
     734           4 :         KUNIT_ASSERT_GT(test, dst_size, 0);
     735             : 
     736           4 :         buf = kunit_kzalloc(test, dst_size, GFP_KERNEL);
     737           8 :         KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
     738           4 :         iosys_map_set_vaddr(&dst, buf);
     739             : 
     740           4 :         xrgb8888 = cpubuf_to_le32(test, params->xrgb8888, TEST_BUF_SIZE);
     741           8 :         KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb8888);
     742           4 :         iosys_map_set_vaddr(&src, xrgb8888);
     743             : 
     744           4 :         if (result->dst_pitch == TEST_USE_DEFAULT_PITCH)
     745           3 :                 drm_fb_xrgb8888_to_rgba5551(&dst, &result->dst_pitch, &src, &fb, &params->clip);
     746             :         else
     747           1 :                 drm_fb_xrgb8888_to_rgba5551(&dst, &result->dst_pitch, &src, &fb, &params->clip);
     748           4 :         buf = le16buf_to_cpu(test, (__force const __le16 *)buf, dst_size / sizeof(__le16));
     749           4 :         KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
     750           4 : }
     751             : 
     752           4 : static void drm_test_fb_xrgb8888_to_rgb888(struct kunit *test)
     753             : {
     754           4 :         const struct convert_xrgb8888_case *params = test->param_value;
     755           4 :         const struct convert_to_rgb888_result *result = &params->rgb888_result;
     756             :         size_t dst_size;
     757           4 :         u8 *buf = NULL;
     758           4 :         __le32 *xrgb8888 = NULL;
     759             :         struct iosys_map dst, src;
     760             : 
     761          12 :         struct drm_framebuffer fb = {
     762           4 :                 .format = drm_format_info(DRM_FORMAT_XRGB8888),
     763           4 :                 .pitches = { params->pitch, 0, 0 },
     764             :         };
     765             : 
     766           4 :         dst_size = conversion_buf_size(DRM_FORMAT_RGB888, result->dst_pitch,
     767             :                                        &params->clip, 0);
     768           4 :         KUNIT_ASSERT_GT(test, dst_size, 0);
     769             : 
     770           4 :         buf = kunit_kzalloc(test, dst_size, GFP_KERNEL);
     771           8 :         KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
     772           4 :         iosys_map_set_vaddr(&dst, buf);
     773             : 
     774           4 :         xrgb8888 = cpubuf_to_le32(test, params->xrgb8888, TEST_BUF_SIZE);
     775           8 :         KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb8888);
     776           4 :         iosys_map_set_vaddr(&src, xrgb8888);
     777             : 
     778             :         /*
     779             :          * RGB888 expected results are already in little-endian
     780             :          * order, so there's no need to convert the test output.
     781             :          */
     782           4 :         if (result->dst_pitch == TEST_USE_DEFAULT_PITCH)
     783           3 :                 drm_fb_xrgb8888_to_rgb888(&dst, NULL, &src, &fb, &params->clip);
     784             :         else
     785           1 :                 drm_fb_xrgb8888_to_rgb888(&dst, &result->dst_pitch, &src, &fb, &params->clip);
     786             : 
     787           4 :         KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
     788           4 : }
     789             : 
     790           4 : static void drm_test_fb_xrgb8888_to_argb8888(struct kunit *test)
     791             : {
     792           4 :         const struct convert_xrgb8888_case *params = test->param_value;
     793           4 :         const struct convert_to_argb8888_result *result = &params->argb8888_result;
     794             :         size_t dst_size;
     795           4 :         u32 *buf = NULL;
     796           4 :         __le32 *xrgb8888 = NULL;
     797             :         struct iosys_map dst, src;
     798             : 
     799          12 :         struct drm_framebuffer fb = {
     800           4 :                 .format = drm_format_info(DRM_FORMAT_XRGB8888),
     801           4 :                 .pitches = { params->pitch, 0, 0 },
     802             :         };
     803             : 
     804           4 :         dst_size = conversion_buf_size(DRM_FORMAT_ARGB8888,
     805             :                                        result->dst_pitch, &params->clip, 0);
     806           4 :         KUNIT_ASSERT_GT(test, dst_size, 0);
     807             : 
     808           4 :         buf = kunit_kzalloc(test, dst_size, GFP_KERNEL);
     809           8 :         KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
     810           4 :         iosys_map_set_vaddr(&dst, buf);
     811             : 
     812           4 :         xrgb8888 = cpubuf_to_le32(test, params->xrgb8888, TEST_BUF_SIZE);
     813           8 :         KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb8888);
     814           4 :         iosys_map_set_vaddr(&src, xrgb8888);
     815             : 
     816           4 :         if (result->dst_pitch == TEST_USE_DEFAULT_PITCH)
     817           3 :                 drm_fb_xrgb8888_to_argb8888(&dst, NULL, &src, &fb, &params->clip);
     818             :         else
     819           1 :                 drm_fb_xrgb8888_to_argb8888(&dst, &result->dst_pitch, &src, &fb, &params->clip);
     820             : 
     821           4 :         buf = le32buf_to_cpu(test, (__force const __le32 *)buf, dst_size / sizeof(u32));
     822           4 :         KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
     823           4 : }
     824             : 
     825           4 : static void drm_test_fb_xrgb8888_to_xrgb2101010(struct kunit *test)
     826             : {
     827           4 :         const struct convert_xrgb8888_case *params = test->param_value;
     828           4 :         const struct convert_to_xrgb2101010_result *result = &params->xrgb2101010_result;
     829             :         size_t dst_size;
     830           4 :         u32 *buf = NULL;
     831           4 :         __le32 *xrgb8888 = NULL;
     832             :         struct iosys_map dst, src;
     833             : 
     834          12 :         struct drm_framebuffer fb = {
     835           4 :                 .format = drm_format_info(DRM_FORMAT_XRGB8888),
     836           4 :                 .pitches = { params->pitch, 0, 0 },
     837             :         };
     838             : 
     839           4 :         dst_size = conversion_buf_size(DRM_FORMAT_XRGB2101010,
     840             :                                        result->dst_pitch, &params->clip, 0);
     841           4 :         KUNIT_ASSERT_GT(test, dst_size, 0);
     842             : 
     843           4 :         buf = kunit_kzalloc(test, dst_size, GFP_KERNEL);
     844           8 :         KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
     845           4 :         iosys_map_set_vaddr(&dst, buf);
     846             : 
     847           4 :         xrgb8888 = cpubuf_to_le32(test, params->xrgb8888, TEST_BUF_SIZE);
     848           8 :         KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb8888);
     849           4 :         iosys_map_set_vaddr(&src, xrgb8888);
     850             : 
     851           4 :         if (result->dst_pitch == TEST_USE_DEFAULT_PITCH)
     852           3 :                 drm_fb_xrgb8888_to_xrgb2101010(&dst, NULL, &src, &fb, &params->clip);
     853             :         else
     854           1 :                 drm_fb_xrgb8888_to_xrgb2101010(&dst, &result->dst_pitch, &src, &fb, &params->clip);
     855           4 :         buf = le32buf_to_cpu(test, buf, dst_size / sizeof(u32));
     856           4 :         KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
     857           4 : }
     858             : 
     859           4 : static void drm_test_fb_xrgb8888_to_argb2101010(struct kunit *test)
     860             : {
     861           4 :         const struct convert_xrgb8888_case *params = test->param_value;
     862           4 :         const struct convert_to_argb2101010_result *result = &params->argb2101010_result;
     863             :         size_t dst_size;
     864           4 :         u32 *buf = NULL;
     865           4 :         __le32 *xrgb8888 = NULL;
     866             :         struct iosys_map dst, src;
     867             : 
     868          12 :         struct drm_framebuffer fb = {
     869           4 :                 .format = drm_format_info(DRM_FORMAT_XRGB8888),
     870           4 :                 .pitches = { params->pitch, 0, 0 },
     871             :         };
     872             : 
     873           4 :         dst_size = conversion_buf_size(DRM_FORMAT_ARGB2101010,
     874             :                                        result->dst_pitch, &params->clip, 0);
     875           4 :         KUNIT_ASSERT_GT(test, dst_size, 0);
     876             : 
     877           4 :         buf = kunit_kzalloc(test, dst_size, GFP_KERNEL);
     878           8 :         KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
     879           4 :         iosys_map_set_vaddr(&dst, buf);
     880             : 
     881           4 :         xrgb8888 = cpubuf_to_le32(test, params->xrgb8888, TEST_BUF_SIZE);
     882           8 :         KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb8888);
     883           4 :         iosys_map_set_vaddr(&src, xrgb8888);
     884             : 
     885           4 :         if (result->dst_pitch == TEST_USE_DEFAULT_PITCH)
     886           3 :                 drm_fb_xrgb8888_to_argb2101010(&dst, NULL, &src, &fb, &params->clip);
     887             :         else
     888           1 :                 drm_fb_xrgb8888_to_argb2101010(&dst, &result->dst_pitch, &src, &fb, &params->clip);
     889             : 
     890           4 :         buf = le32buf_to_cpu(test, (__force const __le32 *)buf, dst_size / sizeof(u32));
     891           4 :         KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
     892           4 : }
     893             : 
     894           4 : static void drm_test_fb_xrgb8888_to_mono(struct kunit *test)
     895             : {
     896           4 :         const struct convert_xrgb8888_case *params = test->param_value;
     897           4 :         const struct convert_to_mono_result *result = &params->mono_result;
     898             :         size_t dst_size;
     899           4 :         u8 *buf = NULL;
     900           4 :         __le32 *xrgb8888 = NULL;
     901             :         struct iosys_map dst, src;
     902             : 
     903          12 :         struct drm_framebuffer fb = {
     904           4 :                 .format = drm_format_info(DRM_FORMAT_XRGB8888),
     905           4 :                 .pitches = { params->pitch, 0, 0 },
     906             :         };
     907             : 
     908           4 :         dst_size = conversion_buf_size(DRM_FORMAT_C1, result->dst_pitch, &params->clip, 0);
     909             : 
     910           4 :         KUNIT_ASSERT_GT(test, dst_size, 0);
     911             : 
     912           4 :         buf = kunit_kzalloc(test, dst_size, GFP_KERNEL);
     913           8 :         KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
     914           4 :         iosys_map_set_vaddr(&dst, buf);
     915             : 
     916           4 :         xrgb8888 = cpubuf_to_le32(test, params->xrgb8888, TEST_BUF_SIZE);
     917           8 :         KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb8888);
     918           4 :         iosys_map_set_vaddr(&src, xrgb8888);
     919             : 
     920           4 :         if (result->dst_pitch == TEST_USE_DEFAULT_PITCH)
     921           3 :                 drm_fb_xrgb8888_to_mono(&dst, NULL, &src, &fb, &params->clip);
     922             :         else
     923           1 :                 drm_fb_xrgb8888_to_mono(&dst, &result->dst_pitch, &src, &fb, &params->clip);
     924           4 :         KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
     925           4 : }
     926             : 
     927           4 : static void drm_test_fb_swab(struct kunit *test)
     928             : {
     929           4 :         const struct convert_xrgb8888_case *params = test->param_value;
     930           4 :         const struct fb_swab_result *result = &params->swab_result;
     931             :         size_t dst_size;
     932           4 :         u8 *buf = NULL;
     933           4 :         __le32 *xrgb8888 = NULL;
     934             :         struct iosys_map dst, src;
     935             : 
     936          12 :         struct drm_framebuffer fb = {
     937           4 :                 .format = drm_format_info(DRM_FORMAT_XRGB8888),
     938           4 :                 .pitches = { params->pitch, 0, 0 },
     939             :         };
     940             : 
     941           4 :         dst_size = conversion_buf_size(DRM_FORMAT_XRGB8888, result->dst_pitch, &params->clip, 0);
     942             : 
     943           4 :         KUNIT_ASSERT_GT(test, dst_size, 0);
     944             : 
     945           4 :         buf = kunit_kzalloc(test, dst_size, GFP_KERNEL);
     946           8 :         KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
     947           4 :         iosys_map_set_vaddr(&dst, buf);
     948             : 
     949           4 :         xrgb8888 = cpubuf_to_le32(test, params->xrgb8888, TEST_BUF_SIZE);
     950           8 :         KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb8888);
     951           4 :         iosys_map_set_vaddr(&src, xrgb8888);
     952             : 
     953           4 :         if (result->dst_pitch == TEST_USE_DEFAULT_PITCH)
     954           3 :                 drm_fb_swab(&dst, NULL, &src, &fb, &params->clip, false);
     955             :         else
     956           1 :                 drm_fb_swab(&dst, &result->dst_pitch, &src, &fb, &params->clip, false);
     957           4 :         KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
     958           4 : }
     959             : 
     960             : struct clip_offset_case {
     961             :         const char *name;
     962             :         unsigned int pitch;
     963             :         u32 format;
     964             :         struct drm_rect clip;
     965             :         unsigned int expected_offset;
     966             : };
     967             : 
     968             : static struct clip_offset_case clip_offset_cases[] = {
     969             :         {
     970             :                 .name = "pass through",
     971             :                 .pitch = TEST_USE_DEFAULT_PITCH,
     972             :                 .format = DRM_FORMAT_XRGB8888,
     973             :                 .clip = DRM_RECT_INIT(0, 0, 3, 3),
     974             :                 .expected_offset = 0
     975             :         },
     976             :         {
     977             :                 .name = "horizontal offset",
     978             :                 .pitch = TEST_USE_DEFAULT_PITCH,
     979             :                 .format = DRM_FORMAT_XRGB8888,
     980             :                 .clip = DRM_RECT_INIT(1, 0, 3, 3),
     981             :                 .expected_offset = 4,
     982             :         },
     983             :         {
     984             :                 .name = "vertical offset",
     985             :                 .pitch = TEST_USE_DEFAULT_PITCH,
     986             :                 .format = DRM_FORMAT_XRGB8888,
     987             :                 .clip = DRM_RECT_INIT(0, 1, 3, 3),
     988             :                 .expected_offset = 12,
     989             :         },
     990             :         {
     991             :                 .name = "horizontal and vertical offset",
     992             :                 .pitch = TEST_USE_DEFAULT_PITCH,
     993             :                 .format = DRM_FORMAT_XRGB8888,
     994             :                 .clip = DRM_RECT_INIT(1, 1, 3, 3),
     995             :                 .expected_offset = 16,
     996             :         },
     997             :         {
     998             :                 .name = "horizontal offset (custom pitch)",
     999             :                 .pitch = 20,
    1000             :                 .format = DRM_FORMAT_XRGB8888,
    1001             :                 .clip = DRM_RECT_INIT(1, 0, 3, 3),
    1002             :                 .expected_offset = 4,
    1003             :         },
    1004             :         {
    1005             :                 .name = "vertical offset (custom pitch)",
    1006             :                 .pitch = 20,
    1007             :                 .format = DRM_FORMAT_XRGB8888,
    1008             :                 .clip = DRM_RECT_INIT(0, 1, 3, 3),
    1009             :                 .expected_offset = 20,
    1010             :         },
    1011             :         {
    1012             :                 .name = "horizontal and vertical offset (custom pitch)",
    1013             :                 .pitch = 20,
    1014             :                 .format = DRM_FORMAT_XRGB8888,
    1015             :                 .clip = DRM_RECT_INIT(1, 1, 3, 3),
    1016             :                 .expected_offset = 24,
    1017             :         },
    1018             : };
    1019             : 
    1020           7 : static void clip_offset_case_desc(struct clip_offset_case *t, char *desc)
    1021             : {
    1022           7 :         strscpy(desc, t->name, KUNIT_PARAM_DESC_SIZE);
    1023           7 : }
    1024             : 
    1025           8 : KUNIT_ARRAY_PARAM(clip_offset, clip_offset_cases, clip_offset_case_desc);
    1026             : 
    1027           7 : static void drm_test_fb_clip_offset(struct kunit *test)
    1028             : {
    1029           7 :         const struct clip_offset_case *params = test->param_value;
    1030           7 :         const struct drm_format_info *format_info = drm_format_info(params->format);
    1031             : 
    1032           7 :         unsigned int offset = -1;
    1033             : 
    1034           7 :         unsigned int pitch = params->pitch;
    1035             : 
    1036           7 :         if (pitch == TEST_USE_DEFAULT_PITCH)
    1037           4 :                 pitch = drm_format_info_min_pitch(format_info, 0,
    1038           4 :                                                   drm_rect_width(&params->clip));
    1039             : 
    1040             :         /* Assure that the pitch is not zero, because this will inevitable cause the
    1041             :          * wrong expected result
    1042             :          */
    1043           7 :         KUNIT_ASSERT_NE(test, pitch, 0);
    1044             : 
    1045           7 :         offset = drm_fb_clip_offset(pitch, format_info, &params->clip);
    1046             : 
    1047           7 :         KUNIT_EXPECT_EQ(test, offset, params->expected_offset);
    1048           7 : }
    1049             : 
    1050             : struct fb_memcpy_result {
    1051             :         unsigned int dst_pitches[DRM_FORMAT_MAX_PLANES];
    1052             :         const u32 expected[DRM_FORMAT_MAX_PLANES][TEST_BUF_SIZE];
    1053             : };
    1054             : 
    1055             : struct multi_plane_op_case {
    1056             :         const char *name;
    1057             :         u32 format;
    1058             :         struct drm_rect clip;
    1059             :         unsigned int src_pitches[DRM_FORMAT_MAX_PLANES];
    1060             :         const u32 src[DRM_FORMAT_MAX_PLANES][TEST_BUF_SIZE];
    1061             :         struct fb_memcpy_result memcpy_result;
    1062             : };
    1063             : 
    1064             : static struct multi_plane_op_case multi_plane_op_cases[] = {
    1065             :         {
    1066             :                 .name = "single_pixel_source_buffer",
    1067             :                 .format = DRM_FORMAT_XRGB8888,
    1068             :                 .clip = DRM_RECT_INIT(0, 0, 1, 1),
    1069             :                 .src_pitches = { 1 * 4 },
    1070             :                 .src = {{ 0x01020304 }},
    1071             :                 .memcpy_result = {
    1072             :                         .dst_pitches = { TEST_USE_DEFAULT_PITCH },
    1073             :                         .expected = {{ 0x01020304 }},
    1074             :                 }
    1075             :         },
    1076             :         {
    1077             :                 .name = "single_pixel_source_buffer",
    1078             :                 .format = DRM_FORMAT_XRGB8888_A8,
    1079             :                 .clip = DRM_RECT_INIT(0, 0, 1, 1),
    1080             :                 .src_pitches = { 1 * 4, 1 },
    1081             :                 .src = {
    1082             :                         { 0x01020304 },
    1083             :                         { 0xFFFFFF01 },
    1084             :                 },
    1085             :                 .memcpy_result = {
    1086             :                         .dst_pitches = { TEST_USE_DEFAULT_PITCH },
    1087             :                         .expected = {
    1088             :                                 { 0x01020304 },
    1089             :                                 { 0x00000001 },
    1090             :                         },
    1091             :                 },
    1092             :         },
    1093             :         {
    1094             :                 .name = "single_pixel_source_buffer",
    1095             :                 .format = DRM_FORMAT_YUV444,
    1096             :                 .clip = DRM_RECT_INIT(0, 0, 1, 1),
    1097             :                 .src_pitches = { 1, 1, 1 },
    1098             :                 .src = {
    1099             :                         { 0xFFFFFF01 },
    1100             :                         { 0xFFFFFF01 },
    1101             :                         { 0xFFFFFF01 },
    1102             :                 },
    1103             :                 .memcpy_result = {
    1104             :                         .dst_pitches = { TEST_USE_DEFAULT_PITCH },
    1105             :                         .expected = {
    1106             :                                 { 0x00000001 },
    1107             :                                 { 0x00000001 },
    1108             :                                 { 0x00000001 },
    1109             :                         },
    1110             :                 },
    1111             :         },
    1112             :         {
    1113             :                 .name = "single_pixel_clip_rectangle",
    1114             :                 .format = DRM_FORMAT_XBGR8888,
    1115             :                 .clip = DRM_RECT_INIT(1, 1, 1, 1),
    1116             :                 .src_pitches = { 2 * 4 },
    1117             :                 .src = {
    1118             :                         {
    1119             :                                 0x00000000, 0x00000000,
    1120             :                                 0x00000000, 0x01020304,
    1121             :                         },
    1122             :                 },
    1123             :                 .memcpy_result = {
    1124             :                         .dst_pitches = { TEST_USE_DEFAULT_PITCH },
    1125             :                         .expected = {
    1126             :                                 { 0x01020304 },
    1127             :                         },
    1128             :                 },
    1129             :         },
    1130             :         {
    1131             :                 .name = "single_pixel_clip_rectangle",
    1132             :                 .format = DRM_FORMAT_XRGB8888_A8,
    1133             :                 .clip = DRM_RECT_INIT(1, 1, 1, 1),
    1134             :                 .src_pitches = { 2 * 4 , 2 * 1 },
    1135             :                 .src = {
    1136             :                         {
    1137             :                                 0x00000000, 0x00000000,
    1138             :                                 0x00000000, 0x01020304,
    1139             :                         },
    1140             :                         { 0x01000000 },
    1141             :                 },
    1142             :                 .memcpy_result = {
    1143             :                         .dst_pitches = { TEST_USE_DEFAULT_PITCH },
    1144             :                         .expected = {
    1145             :                                 { 0x01020304 },
    1146             :                                 { 0x00000001 },
    1147             :                         },
    1148             :                 },
    1149             :         },
    1150             :         {
    1151             :                 .name = "single_pixel_clip_rectangle",
    1152             :                 .format = DRM_FORMAT_YUV444,
    1153             :                 .clip = DRM_RECT_INIT(1, 1, 1, 1),
    1154             :                 .src_pitches = { 2 * 1 , 2 * 1 , 2 * 1 },
    1155             :                 .src = {
    1156             :                         { 0x01000000 },
    1157             :                         { 0x01000000 },
    1158             :                         { 0x01000000 },
    1159             :                 },
    1160             :                 .memcpy_result = {
    1161             :                         .dst_pitches = { TEST_USE_DEFAULT_PITCH },
    1162             :                         .expected = {
    1163             :                                 { 0x00000001 },
    1164             :                                 { 0x00000001 },
    1165             :                                 { 0x00000001 },
    1166             :                         },
    1167             :                 },
    1168             :         },
    1169             :         {
    1170             :                 .name = "well_known_colors",
    1171             :                 .format = DRM_FORMAT_XBGR8888,
    1172             :                 .clip = DRM_RECT_INIT(1, 1, 2, 4),
    1173             :                 .src_pitches = { 4 * 4 },
    1174             :                 .src = {
    1175             :                         {
    1176             :                                 0x00000000, 0x00000000, 0x00000000, 0x00000000,
    1177             :                                 0x00000000, 0x11FFFFFF, 0x22000000, 0x00000000,
    1178             :                                 0x00000000, 0x33FF0000, 0x4400FF00, 0x00000000,
    1179             :                                 0x00000000, 0x550000FF, 0x66FF00FF, 0x00000000,
    1180             :                                 0x00000000, 0x77FFFF00, 0x8800FFFF, 0x00000000,
    1181             :                         },
    1182             :                 },
    1183             :                 .memcpy_result = {
    1184             :                         .dst_pitches = { TEST_USE_DEFAULT_PITCH },
    1185             :                         .expected = {
    1186             :                                 {
    1187             :                                         0x11FFFFFF, 0x22000000,
    1188             :                                         0x33FF0000, 0x4400FF00,
    1189             :                                         0x550000FF, 0x66FF00FF,
    1190             :                                         0x77FFFF00, 0x8800FFFF,
    1191             :                                 },
    1192             :                         },
    1193             :                 },
    1194             :         },
    1195             :         {
    1196             :                 .name = "well_known_colors",
    1197             :                 .format = DRM_FORMAT_XRGB8888_A8,
    1198             :                 .clip = DRM_RECT_INIT(1, 1, 2, 4),
    1199             :                 .src_pitches = { 4 * 4 , 4 * 1 },
    1200             :                 .src = {
    1201             :                         {
    1202             :                                 0x00000000, 0x00000000, 0x00000000, 0x00000000,
    1203             :                                 0x00000000, 0xFFFFFFFF, 0xFF000000, 0x00000000,
    1204             :                                 0x00000000, 0xFFFF0000, 0xFF00FF00, 0x00000000,
    1205             :                                 0x00000000, 0xFF0000FF, 0xFFFF00FF, 0x00000000,
    1206             :                                 0x00000000, 0xFFFFFF00, 0xFF00FFFF, 0x00000000,
    1207             :                         },
    1208             :                         {
    1209             :                                 0x00000000,
    1210             :                                 0x00221100,
    1211             :                                 0x00443300,
    1212             :                                 0x00665500,
    1213             :                                 0x00887700,
    1214             :                         },
    1215             :                 },
    1216             :                 .memcpy_result = {
    1217             :                         .dst_pitches = { TEST_USE_DEFAULT_PITCH },
    1218             :                         .expected = {
    1219             :                                 {
    1220             :                                         0xFFFFFFFF, 0xFF000000,
    1221             :                                         0xFFFF0000, 0xFF00FF00,
    1222             :                                         0xFF0000FF, 0xFFFF00FF,
    1223             :                                         0xFFFFFF00, 0xFF00FFFF,
    1224             :                                 },
    1225             :                                 {
    1226             :                                         0x44332211,
    1227             :                                         0x88776655,
    1228             :                                 },
    1229             :                         },
    1230             :                 },
    1231             :         },
    1232             :         {
    1233             :                 .name = "well_known_colors",
    1234             :                 .format = DRM_FORMAT_YUV444,
    1235             :                 .clip = DRM_RECT_INIT(1, 1, 2, 4),
    1236             :                 .src_pitches = { 4 * 1 , 4 * 1 , 4 * 1 },
    1237             :                 .src = {
    1238             :                         {
    1239             :                                 0x00000000,
    1240             :                                 0x0000FF00,
    1241             :                                 0x00954C00,
    1242             :                                 0x00691D00,
    1243             :                                 0x00B2E100,
    1244             :                         },
    1245             :                         {
    1246             :                                 0x00000000,
    1247             :                                 0x00000000,
    1248             :                                 0x00BEDE00,
    1249             :                                 0x00436500,
    1250             :                                 0x00229B00,
    1251             :                         },
    1252             :                         {
    1253             :                                 0x00000000,
    1254             :                                 0x00000000,
    1255             :                                 0x007E9C00,
    1256             :                                 0x0083E700,
    1257             :                                 0x00641A00,
    1258             :                         },
    1259             :                 },
    1260             :                 .memcpy_result = {
    1261             :                         .dst_pitches = { TEST_USE_DEFAULT_PITCH },
    1262             :                         .expected = {
    1263             :                                 {
    1264             :                                         0x954C00FF,
    1265             :                                         0xB2E1691D,
    1266             :                                 },
    1267             :                                 {
    1268             :                                         0xBEDE0000,
    1269             :                                         0x229B4365,
    1270             :                                 },
    1271             :                                 {
    1272             :                                         0x7E9C0000,
    1273             :                                         0x641A83E7,
    1274             :                                 },
    1275             :                         },
    1276             :                 },
    1277             :         },
    1278             :         {
    1279             :                 .name = "destination_pitch",
    1280             :                 .format = DRM_FORMAT_XBGR8888,
    1281             :                 .clip = DRM_RECT_INIT(0, 0, 3, 3),
    1282             :                 .src_pitches = { 3 * 4 },
    1283             :                 .src = {
    1284             :                         {
    1285             :                                 0xA10E449C, 0xB1114D05, 0xC1A8F303,
    1286             :                                 0xD16CF073, 0xA20E449C, 0xB2114D05,
    1287             :                                 0xC2A80303, 0xD26CF073, 0xA30E449C,
    1288             :                         },
    1289             :                 },
    1290             :                 .memcpy_result = {
    1291             :                         .dst_pitches = { 5 * 4 },
    1292             :                         .expected = {
    1293             :                                 {
    1294             :                                         0xA10E449C, 0xB1114D05, 0xC1A8F303, 0x00000000, 0x00000000,
    1295             :                                         0xD16CF073, 0xA20E449C, 0xB2114D05, 0x00000000, 0x00000000,
    1296             :                                         0xC2A80303, 0xD26CF073, 0xA30E449C, 0x00000000, 0x00000000,
    1297             :                                 },
    1298             :                         },
    1299             :                 },
    1300             :         },
    1301             :         {
    1302             :                 .name = "destination_pitch",
    1303             :                 .format = DRM_FORMAT_XRGB8888_A8,
    1304             :                 .clip = DRM_RECT_INIT(0, 0, 3, 3),
    1305             :                 .src_pitches = { 3 * 4 , 3 * 1 },
    1306             :                 .src = {
    1307             :                         {
    1308             :                                 0xFF0E449C, 0xFF114D05, 0xFFA8F303,
    1309             :                                 0xFF6CF073, 0xFF0E449C, 0xFF114D05,
    1310             :                                 0xFFA80303, 0xFF6CF073, 0xFF0E449C,
    1311             :                         },
    1312             :                         {
    1313             :                                 0xB2C1B1A1,
    1314             :                                 0xD2A3D1A2,
    1315             :                                 0xFFFFFFC2,
    1316             :                         },
    1317             :                 },
    1318             :                 .memcpy_result = {
    1319             :                         .dst_pitches = { 5 * 4, 5 * 1 },
    1320             :                         .expected = {
    1321             :                                 {
    1322             :                                         0xFF0E449C, 0xFF114D05, 0xFFA8F303, 0x00000000, 0x00000000,
    1323             :                                         0xFF6CF073, 0xFF0E449C, 0xFF114D05, 0x00000000, 0x00000000,
    1324             :                                         0xFFA80303, 0xFF6CF073, 0xFF0E449C, 0x00000000, 0x00000000,
    1325             :                                 },
    1326             :                                 {
    1327             :                                         0x00C1B1A1,
    1328             :                                         0xD1A2B200,
    1329             :                                         0xD2A30000,
    1330             :                                         0xFF0000C2,
    1331             :                                 },
    1332             :                         },
    1333             :                 },
    1334             :         },
    1335             :         {
    1336             :                 .name = "destination_pitch",
    1337             :                 .format = DRM_FORMAT_YUV444,
    1338             :                 .clip = DRM_RECT_INIT(0, 0, 3, 3),
    1339             :                 .src_pitches = { 3 * 1 , 3 * 1 , 3 * 1 },
    1340             :                 .src = {
    1341             :                         {
    1342             :                                 0xBAC1323D,
    1343             :                                 0xBA34323D,
    1344             :                                 0xFFFFFF3D,
    1345             :                         },
    1346             :                         {
    1347             :                                 0xE1ABEC2A,
    1348             :                                 0xE1EAEC2A,
    1349             :                                 0xFFFFFF2A,
    1350             :                         },
    1351             :                         {
    1352             :                                 0xBCEBE4D7,
    1353             :                                 0xBC65E4D7,
    1354             :                                 0xFFFFFFD7,
    1355             :                         },
    1356             :                 },
    1357             :                 .memcpy_result = {
    1358             :                         .dst_pitches = { 5 * 1 , 5 * 1 , 5 * 1 },
    1359             :                         .expected = {
    1360             :                                 {
    1361             :                                         0x00C1323D,
    1362             :                                         0x323DBA00,
    1363             :                                         0xBA340000,
    1364             :                                         0xFF00003D,
    1365             :                                 },
    1366             :                                 { 
    1367             :                                         0x00ABEC2A,
    1368             :                                         0xEC2AE100,
    1369             :                                         0xE1EA0000,
    1370             :                                         0xFF00002A,
    1371             :                                 },
    1372             :                                 { 
    1373             :                                         0x00EBE4D7,
    1374             :                                         0xE4D7BC00,
    1375             :                                         0xBC650000,
    1376             :                                         0xFF0000D7,
    1377             :                                 },
    1378             :                         },
    1379             :                 },
    1380             :         },
    1381             : };
    1382             : 
    1383          12 : static void multi_plane_op_case_desc(struct multi_plane_op_case *t, char *desc)
    1384             : {
    1385          12 :         snprintf(desc, KUNIT_PARAM_DESC_SIZE, "%s: %p4cc", t->name, &t->format);
    1386          12 : }
    1387             : 
    1388          13 : KUNIT_ARRAY_PARAM(multi_plane_op, multi_plane_op_cases, multi_plane_op_case_desc);
    1389             : 
    1390          12 : static void drm_test_fb_memcpy(struct kunit *test)
    1391             : {
    1392          12 :         const struct multi_plane_op_case *params = test->param_value;
    1393          12 :         const struct fb_memcpy_result *result = &params->memcpy_result;
    1394          12 :         size_t dst_size[DRM_FORMAT_MAX_PLANES] = { 0 };
    1395          12 :         u32 *buf[DRM_FORMAT_MAX_PLANES] = { 0 };
    1396          12 :         u32 src_cp[DRM_FORMAT_MAX_PLANES][TEST_BUF_SIZE] = { 0 };
    1397             :         struct iosys_map dst[DRM_FORMAT_MAX_PLANES];
    1398             :         struct iosys_map src[DRM_FORMAT_MAX_PLANES];
    1399             : 
    1400          24 :         struct drm_framebuffer fb = {
    1401          12 :                 .format = drm_format_info(params->format),
    1402             :         };
    1403             : 
    1404          12 :         memcpy(fb.pitches, params->src_pitches, DRM_FORMAT_MAX_PLANES * sizeof(int));
    1405             : 
    1406          36 :         for (size_t i = 0; i < fb.format->num_planes; i++) {
    1407          24 :                 dst_size[i] = conversion_buf_size(params->format, result->dst_pitches[i],
    1408             :                                                   &params->clip, i);
    1409          24 :                 KUNIT_ASSERT_GT(test, dst_size[i], 0);
    1410             : 
    1411          24 :                 printk("dst_size[%zu] = %zu\n", i, dst_size[i]);
    1412             : 
    1413          48 :                 buf[i] = kunit_kzalloc(test, dst_size[i], GFP_KERNEL);
    1414          48 :                 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf[i]);
    1415          48 :                 iosys_map_set_vaddr(&dst[i], buf[i]);
    1416             : 
    1417          24 :                 memcpy(src_cp[i], params->src[i], TEST_BUF_SIZE * sizeof(u32));
    1418          48 :                 iosys_map_set_vaddr(&src[i], src_cp[i]);
    1419             :         }
    1420             : 
    1421          12 :         if (result->dst_pitches[0] == TEST_USE_DEFAULT_PITCH)
    1422           9 :                 drm_fb_memcpy(dst, NULL, src, &fb, &params->clip);
    1423             :         else
    1424           3 :                 drm_fb_memcpy(dst, result->dst_pitches, src, &fb, &params->clip);
    1425             : 
    1426             : 
    1427          24 :         for (size_t i = 0; i < fb.format->num_planes; i++) {
    1428          24 :                 KUNIT_EXPECT_MEMEQ_MSG(test, buf[i], result->expected[i], dst_size[i],
    1429             :                                        "Failed expectation on plane %zu", i);
    1430             :         }
    1431          12 : }
    1432             : 
    1433             : struct fb_build_fourcc_list_case {
    1434             :         const char *name;
    1435             :         u32 native_fourccs[TEST_BUF_SIZE];
    1436             :         u32 expected[TEST_BUF_SIZE];
    1437             : };
    1438             : 
    1439             : struct fb_build_fourcc_list_case fb_build_fourcc_list_cases[] = {
    1440             :         {
    1441             :                 .name = "no native formats",
    1442             :                 .native_fourccs = { },
    1443             :                 .expected = { DRM_FORMAT_XRGB8888 },
    1444             :         },
    1445             :         {
    1446             :                 .name = "XRGB8888 as native format",
    1447             :                 .native_fourccs = { DRM_FORMAT_XRGB8888 },
    1448             :                 .expected = { DRM_FORMAT_XRGB8888 },
    1449             :         },
    1450             :         {
    1451             :                 .name = "remove duplicates",
    1452             :                 .native_fourccs = {
    1453             :                         DRM_FORMAT_XRGB8888,
    1454             :                         DRM_FORMAT_XRGB8888,
    1455             :                         DRM_FORMAT_RGB888,
    1456             :                         DRM_FORMAT_RGB888,
    1457             :                         DRM_FORMAT_RGB888,
    1458             :                         DRM_FORMAT_XRGB8888,
    1459             :                         DRM_FORMAT_RGB888,
    1460             :                         DRM_FORMAT_RGB565,
    1461             :                         DRM_FORMAT_RGB888,
    1462             :                         DRM_FORMAT_XRGB8888,
    1463             :                         DRM_FORMAT_RGB565,
    1464             :                         DRM_FORMAT_RGB565,
    1465             :                         DRM_FORMAT_XRGB8888,
    1466             :                 },
    1467             :                 .expected = {
    1468             :                         DRM_FORMAT_XRGB8888,
    1469             :                         DRM_FORMAT_RGB888,
    1470             :                         DRM_FORMAT_RGB565,
    1471             :                 },
    1472             :         },
    1473             :         {
    1474             :                 .name = "convert alpha formats",
    1475             :                 .native_fourccs = {
    1476             :                         DRM_FORMAT_ARGB1555,
    1477             :                         DRM_FORMAT_ABGR1555,
    1478             :                         DRM_FORMAT_RGBA5551,
    1479             :                         DRM_FORMAT_BGRA5551,
    1480             :                         DRM_FORMAT_ARGB8888,
    1481             :                         DRM_FORMAT_ABGR8888,
    1482             :                         DRM_FORMAT_RGBA8888,
    1483             :                         DRM_FORMAT_BGRA8888,
    1484             :                         DRM_FORMAT_ARGB2101010,
    1485             :                         DRM_FORMAT_ABGR2101010,
    1486             :                         DRM_FORMAT_RGBA1010102,
    1487             :                         DRM_FORMAT_BGRA1010102,
    1488             :                 },
    1489             :                 .expected = {
    1490             :                         DRM_FORMAT_XRGB1555,
    1491             :                         DRM_FORMAT_XBGR1555,
    1492             :                         DRM_FORMAT_RGBX5551,
    1493             :                         DRM_FORMAT_BGRX5551,
    1494             :                         DRM_FORMAT_XRGB8888,
    1495             :                         DRM_FORMAT_XBGR8888,
    1496             :                         DRM_FORMAT_RGBX8888,
    1497             :                         DRM_FORMAT_BGRX8888,
    1498             :                         DRM_FORMAT_XRGB2101010,
    1499             :                         DRM_FORMAT_XBGR2101010,
    1500             :                         DRM_FORMAT_RGBX1010102,
    1501             :                         DRM_FORMAT_BGRX1010102,
    1502             :                 },
    1503             :         },
    1504             :         {
    1505             :                 .name = "random formats",
    1506             :                 .native_fourccs = {
    1507             :                         DRM_FORMAT_Y212,
    1508             :                         DRM_FORMAT_ARGB1555,
    1509             :                         DRM_FORMAT_ABGR16161616F,
    1510             :                         DRM_FORMAT_C8,
    1511             :                         DRM_FORMAT_BGR888,
    1512             :                         DRM_FORMAT_XRGB1555,
    1513             :                         DRM_FORMAT_RGBA5551,
    1514             :                         DRM_FORMAT_BGR565_A8,
    1515             :                         DRM_FORMAT_R10,
    1516             :                         DRM_FORMAT_XYUV8888,
    1517             :                 },
    1518             :                 .expected = {
    1519             :                         DRM_FORMAT_Y212,
    1520             :                         DRM_FORMAT_XRGB1555,
    1521             :                         DRM_FORMAT_ABGR16161616F,
    1522             :                         DRM_FORMAT_C8,
    1523             :                         DRM_FORMAT_BGR888,
    1524             :                         DRM_FORMAT_RGBX5551,
    1525             :                         DRM_FORMAT_BGR565_A8,
    1526             :                         DRM_FORMAT_R10,
    1527             :                         DRM_FORMAT_XYUV8888,
    1528             :                         DRM_FORMAT_XRGB8888,
    1529             :                 },
    1530             :         },
    1531             : };
    1532             : 
    1533           5 : static void fb_build_fourcc_list_case_desc(struct fb_build_fourcc_list_case *t, char *desc)
    1534             : {
    1535           5 :         strscpy(desc, t->name, KUNIT_PARAM_DESC_SIZE);
    1536           5 : }
    1537             : 
    1538           6 : KUNIT_ARRAY_PARAM(fb_build_fourcc_list, fb_build_fourcc_list_cases, fb_build_fourcc_list_case_desc);
    1539             : 
    1540             : static size_t get_nfourccs(const u32 *fourccs)
    1541             : {
    1542             :         size_t i;
    1543             : 
    1544          32 :         for (i = 0; i < TEST_BUF_SIZE && fourccs[i]; ++i)
    1545             :                 ;
    1546             : 
    1547             :         return i;
    1548             : }
    1549             : 
    1550           5 : static void drm_test_fb_build_fourcc_list(struct kunit *test)
    1551             : {
    1552           5 :         const struct fb_build_fourcc_list_case *params = test->param_value;
    1553             :         u32 fourccs_out[TEST_BUF_SIZE];
    1554             :         size_t nfourccs_out;
    1555             :         struct drm_device *drm;
    1556             :         struct device *dev;
    1557             : 
    1558           5 :         dev = drm_kunit_helper_alloc_device(test);
    1559          10 :         KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
    1560             : 
    1561           5 :         drm = __drm_kunit_helper_alloc_drm_device(test, dev, sizeof(*drm), 0, DRIVER_MODESET);
    1562          10 :         KUNIT_ASSERT_NOT_ERR_OR_NULL(test, drm);
    1563             : 
    1564           5 :         nfourccs_out = drm_fb_build_fourcc_list(drm, params->native_fourccs,
    1565           5 :                                                 get_nfourccs(params->native_fourccs),
    1566             :                                                 fourccs_out, TEST_BUF_SIZE);
    1567             : 
    1568           5 :         drm_kunit_helper_free_device(test, dev);
    1569          10 :         KUNIT_EXPECT_EQ(test, nfourccs_out, get_nfourccs(params->expected));
    1570           5 :         KUNIT_EXPECT_MEMEQ(test, fourccs_out, params->expected, nfourccs_out);
    1571           5 : }
    1572             : 
    1573             : static struct kunit_case drm_format_helper_test_cases[] = {
    1574             :         KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_gray8, convert_xrgb8888_gen_params),
    1575             :         KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_rgb332, convert_xrgb8888_gen_params),
    1576             :         KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_rgb565, convert_xrgb8888_gen_params),
    1577             :         KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_xrgb1555, convert_xrgb8888_gen_params),
    1578             :         KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_argb1555, convert_xrgb8888_gen_params),
    1579             :         KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_rgba5551, convert_xrgb8888_gen_params),
    1580             :         KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_rgb888, convert_xrgb8888_gen_params),
    1581             :         KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_argb8888, convert_xrgb8888_gen_params),
    1582             :         KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_xrgb2101010, convert_xrgb8888_gen_params),
    1583             :         KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_argb2101010, convert_xrgb8888_gen_params),
    1584             :         KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_mono, convert_xrgb8888_gen_params),
    1585             :         KUNIT_CASE_PARAM(drm_test_fb_swab, convert_xrgb8888_gen_params),
    1586             :         KUNIT_CASE_PARAM(drm_test_fb_clip_offset, clip_offset_gen_params),
    1587             :         KUNIT_CASE_PARAM(drm_test_fb_memcpy, multi_plane_op_gen_params),
    1588             :         KUNIT_CASE_PARAM(drm_test_fb_build_fourcc_list, fb_build_fourcc_list_gen_params),
    1589             :         {}
    1590             : };
    1591             : 
    1592             : static struct kunit_suite drm_format_helper_test_suite = {
    1593             :         .name = "drm_format_helper_test",
    1594             :         .test_cases = drm_format_helper_test_cases,
    1595             : };
    1596             : 
    1597             : kunit_test_suite(drm_format_helper_test_suite);
    1598             : 
    1599             : MODULE_DESCRIPTION("KUnit tests for the drm_format_helper APIs");
    1600             : MODULE_LICENSE("GPL");
    1601             : MODULE_AUTHOR("José Expósito <jose.exposito89@gmail.com>");

Generated by: LCOV version 1.14