1 /* SPDX-License-Identifier: GPL-2.0 */
10 * Compose two values, using a bitmask as decision value
11 * This is equivalent to (a & mask) | (b & ~mask)
14 static inline unsigned long
15 comp(unsigned long a
, unsigned long b
, unsigned long mask
)
17 return ((a
^ b
) & mask
) ^ b
;
21 * Create a pattern with the given pixel's color
24 #if BITS_PER_LONG == 64
25 static inline unsigned long
26 pixel_to_pat( u32 bpp
, u32 pixel
)
30 return 0xfffffffffffffffful
*pixel
;
32 return 0x5555555555555555ul
*pixel
;
34 return 0x1111111111111111ul
*pixel
;
36 return 0x0101010101010101ul
*pixel
;
38 return 0x1001001001001001ul
*pixel
;
40 return 0x0001000100010001ul
*pixel
;
42 return 0x0001000001000001ul
*pixel
;
44 return 0x0000000100000001ul
*pixel
;
46 WARN(1, "pixel_to_pat(): unsupported pixelformat %d\n", bpp
);
51 static inline unsigned long
52 pixel_to_pat( u32 bpp
, u32 pixel
)
56 return 0xfffffffful
*pixel
;
58 return 0x55555555ul
*pixel
;
60 return 0x11111111ul
*pixel
;
62 return 0x01010101ul
*pixel
;
64 return 0x01001001ul
*pixel
;
66 return 0x00010001ul
*pixel
;
68 return 0x01000001ul
*pixel
;
70 return 0x00000001ul
*pixel
;
72 WARN(1, "pixel_to_pat(): unsupported pixelformat %d\n", bpp
);
78 #ifdef CONFIG_FB_CFB_REV_PIXELS_IN_BYTE
79 #if BITS_PER_LONG == 64
80 #define REV_PIXELS_MASK1 0x5555555555555555ul
81 #define REV_PIXELS_MASK2 0x3333333333333333ul
82 #define REV_PIXELS_MASK4 0x0f0f0f0f0f0f0f0ful
84 #define REV_PIXELS_MASK1 0x55555555ul
85 #define REV_PIXELS_MASK2 0x33333333ul
86 #define REV_PIXELS_MASK4 0x0f0f0f0ful
89 static inline unsigned long fb_rev_pixels_in_long(unsigned long val
,
93 val
= comp(val
>> 1, val
<< 1, REV_PIXELS_MASK1
);
95 val
= comp(val
>> 2, val
<< 2, REV_PIXELS_MASK2
);
97 val
= comp(val
>> 4, val
<< 4, REV_PIXELS_MASK4
);
101 static inline u32
fb_shifted_pixels_mask_u32(struct fb_info
*p
, u32 index
,
107 mask
= FB_SHIFT_HIGH(p
, ~(u32
)0, index
);
109 mask
= 0xff << FB_LEFT_POS(p
, 8);
110 mask
= FB_SHIFT_LOW(p
, mask
, index
& (bswapmask
)) & mask
;
111 mask
= FB_SHIFT_HIGH(p
, mask
, index
& ~(bswapmask
));
112 #if defined(__i386__) || defined(__x86_64__)
113 /* Shift argument is limited to 0 - 31 on x86 based CPU's */
114 if(index
+ bswapmask
< 32)
116 mask
|= FB_SHIFT_HIGH(p
, ~(u32
)0,
117 (index
+ bswapmask
) & ~(bswapmask
));
122 static inline unsigned long fb_shifted_pixels_mask_long(struct fb_info
*p
,
129 mask
= FB_SHIFT_HIGH(p
, ~0UL, index
);
131 mask
= 0xff << FB_LEFT_POS(p
, 8);
132 mask
= FB_SHIFT_LOW(p
, mask
, index
& (bswapmask
)) & mask
;
133 mask
= FB_SHIFT_HIGH(p
, mask
, index
& ~(bswapmask
));
134 #if defined(__i386__) || defined(__x86_64__)
135 /* Shift argument is limited to 0 - 31 on x86 based CPU's */
136 if(index
+ bswapmask
< BITS_PER_LONG
)
138 mask
|= FB_SHIFT_HIGH(p
, ~0UL,
139 (index
+ bswapmask
) & ~(bswapmask
));
145 static inline u32
fb_compute_bswapmask(struct fb_info
*info
)
148 unsigned bpp
= info
->var
.bits_per_pixel
;
150 if ((bpp
< 8) && (info
->var
.nonstd
& FB_NONSTD_REV_PIX_IN_B
)) {
152 * Reversed order of pixel layout in bytes
153 * works only for 1, 2 and 4 bpp
155 bswapmask
= 7 - bpp
+ 1;
160 #else /* CONFIG_FB_CFB_REV_PIXELS_IN_BYTE */
162 static inline unsigned long fb_rev_pixels_in_long(unsigned long val
,
168 #define fb_shifted_pixels_mask_u32(p, i, b) FB_SHIFT_HIGH((p), ~(u32)0, (i))
169 #define fb_shifted_pixels_mask_long(p, i, b) FB_SHIFT_HIGH((p), ~0UL, (i))
170 #define fb_compute_bswapmask(...) 0
172 #endif /* CONFIG_FB_CFB_REV_PIXELS_IN_BYTE */
174 #define cpu_to_le_long _cpu_to_le_long(BITS_PER_LONG)
175 #define _cpu_to_le_long(x) __cpu_to_le_long(x)
176 #define __cpu_to_le_long(x) cpu_to_le##x
178 #define le_long_to_cpu _le_long_to_cpu(BITS_PER_LONG)
179 #define _le_long_to_cpu(x) __le_long_to_cpu(x)
180 #define __le_long_to_cpu(x) le##x##_to_cpu
182 static inline unsigned long rolx(unsigned long word
, unsigned int shift
, unsigned int x
)
184 return (word
<< shift
) | (word
>> (x
- shift
));
187 #endif /* FB_DRAW_H */