9 * Compose two values, using a bitmask as decision value
10 * This is equivalent to (a & mask) | (b & ~mask)
13 static inline unsigned long
14 comp(unsigned long a
, unsigned long b
, unsigned long mask
)
16 return ((a
^ b
) & mask
) ^ b
;
20 * Create a pattern with the given pixel's color
23 #if BITS_PER_LONG == 64
24 static inline unsigned long
25 pixel_to_pat( u32 bpp
, u32 pixel
)
29 return 0xfffffffffffffffful
*pixel
;
31 return 0x5555555555555555ul
*pixel
;
33 return 0x1111111111111111ul
*pixel
;
35 return 0x0101010101010101ul
*pixel
;
37 return 0x1001001001001001ul
*pixel
;
39 return 0x0001000100010001ul
*pixel
;
41 return 0x0001000001000001ul
*pixel
;
43 return 0x0000000100000001ul
*pixel
;
45 WARN(1, "pixel_to_pat(): unsupported pixelformat %d\n", bpp
);
50 static inline unsigned long
51 pixel_to_pat( u32 bpp
, u32 pixel
)
55 return 0xfffffffful
*pixel
;
57 return 0x55555555ul
*pixel
;
59 return 0x11111111ul
*pixel
;
61 return 0x01010101ul
*pixel
;
63 return 0x01001001ul
*pixel
;
65 return 0x00010001ul
*pixel
;
67 return 0x01000001ul
*pixel
;
69 return 0x00000001ul
*pixel
;
71 WARN(1, "pixel_to_pat(): unsupported pixelformat %d\n", bpp
);
77 #ifdef CONFIG_FB_CFB_REV_PIXELS_IN_BYTE
78 #if BITS_PER_LONG == 64
79 #define REV_PIXELS_MASK1 0x5555555555555555ul
80 #define REV_PIXELS_MASK2 0x3333333333333333ul
81 #define REV_PIXELS_MASK4 0x0f0f0f0f0f0f0f0ful
83 #define REV_PIXELS_MASK1 0x55555555ul
84 #define REV_PIXELS_MASK2 0x33333333ul
85 #define REV_PIXELS_MASK4 0x0f0f0f0ful
88 static inline unsigned long fb_rev_pixels_in_long(unsigned long val
,
92 val
= comp(val
>> 1, val
<< 1, REV_PIXELS_MASK1
);
94 val
= comp(val
>> 2, val
<< 2, REV_PIXELS_MASK2
);
96 val
= comp(val
>> 4, val
<< 4, REV_PIXELS_MASK4
);
100 static inline u32
fb_shifted_pixels_mask_u32(struct fb_info
*p
, u32 index
,
106 mask
= FB_SHIFT_HIGH(p
, ~(u32
)0, index
);
108 mask
= 0xff << FB_LEFT_POS(p
, 8);
109 mask
= FB_SHIFT_LOW(p
, mask
, index
& (bswapmask
)) & mask
;
110 mask
= FB_SHIFT_HIGH(p
, mask
, index
& ~(bswapmask
));
111 #if defined(__i386__) || defined(__x86_64__)
112 /* Shift argument is limited to 0 - 31 on x86 based CPU's */
113 if(index
+ bswapmask
< 32)
115 mask
|= FB_SHIFT_HIGH(p
, ~(u32
)0,
116 (index
+ bswapmask
) & ~(bswapmask
));
121 static inline unsigned long fb_shifted_pixels_mask_long(struct fb_info
*p
,
128 mask
= FB_SHIFT_HIGH(p
, ~0UL, index
);
130 mask
= 0xff << FB_LEFT_POS(p
, 8);
131 mask
= FB_SHIFT_LOW(p
, mask
, index
& (bswapmask
)) & mask
;
132 mask
= FB_SHIFT_HIGH(p
, mask
, index
& ~(bswapmask
));
133 #if defined(__i386__) || defined(__x86_64__)
134 /* Shift argument is limited to 0 - 31 on x86 based CPU's */
135 if(index
+ bswapmask
< BITS_PER_LONG
)
137 mask
|= FB_SHIFT_HIGH(p
, ~0UL,
138 (index
+ bswapmask
) & ~(bswapmask
));
144 static inline u32
fb_compute_bswapmask(struct fb_info
*info
)
147 unsigned bpp
= info
->var
.bits_per_pixel
;
149 if ((bpp
< 8) && (info
->var
.nonstd
& FB_NONSTD_REV_PIX_IN_B
)) {
151 * Reversed order of pixel layout in bytes
152 * works only for 1, 2 and 4 bpp
154 bswapmask
= 7 - bpp
+ 1;
159 #else /* CONFIG_FB_CFB_REV_PIXELS_IN_BYTE */
161 static inline unsigned long fb_rev_pixels_in_long(unsigned long val
,
167 #define fb_shifted_pixels_mask_u32(p, i, b) FB_SHIFT_HIGH((p), ~(u32)0, (i))
168 #define fb_shifted_pixels_mask_long(p, i, b) FB_SHIFT_HIGH((p), ~0UL, (i))
169 #define fb_compute_bswapmask(...) 0
171 #endif /* CONFIG_FB_CFB_REV_PIXELS_IN_BYTE */
173 #define cpu_to_le_long _cpu_to_le_long(BITS_PER_LONG)
174 #define _cpu_to_le_long(x) __cpu_to_le_long(x)
175 #define __cpu_to_le_long(x) cpu_to_le##x
177 #define le_long_to_cpu _le_long_to_cpu(BITS_PER_LONG)
178 #define _le_long_to_cpu(x) __le_long_to_cpu(x)
179 #define __le_long_to_cpu(x) le##x##_to_cpu
181 static inline unsigned long rolx(unsigned long word
, unsigned int shift
, unsigned int x
)
183 return (word
<< shift
) | (word
>> (x
- shift
));
186 #endif /* FB_DRAW_H */