xref: /linux/drivers/gpu/drm/nouveau/dispnv50/tile.h (revision 7f4f3b14e8079ecde096bd734af10e30d40c27b7)
1 /* SPDX-License-Identifier: MIT */
2 #ifndef __NV50_TILE_H__
3 #define __NV50_TILE_H__
4 
5 #include <linux/types.h>
6 #include <linux/math.h>
7 
8 /*
9  * Tiling parameters for NV50+.
10  * GOB = Group of bytes, the main unit for tiling blocks.
11  * Tiling blocks are a power of 2 number of GOB.
12  * All GOBs and blocks have the same width: 64 bytes (so 16 pixels in 32bits).
13  * tile_mode is the log2 of the number of GOB per block.
14  */
15 
16 #define NV_TILE_GOB_HEIGHT_TESLA 4	/* 4 x 64 bytes = 256 bytes for a GOB on Tesla*/
17 #define NV_TILE_GOB_HEIGHT 8		/* 8 x 64 bytes = 512 bytes for a GOB on Fermi and later */
18 #define NV_TILE_GOB_WIDTH_BYTES 64
19 
20 /* Number of blocks to cover the width of the framebuffer */
21 static inline u32 nouveau_get_width_in_blocks(u32 stride)
22 {
23 	return DIV_ROUND_UP(stride, NV_TILE_GOB_WIDTH_BYTES);
24 }
25 
26 /* Return the height in pixel of one GOB */
27 static inline u32 nouveau_get_gob_height(u16 family)
28 {
29 	if (family == NV_DEVICE_INFO_V0_TESLA)
30 		return NV_TILE_GOB_HEIGHT_TESLA;
31 	else
32 		return NV_TILE_GOB_HEIGHT;
33 }
34 
35 /* Number of blocks to cover the heigth of the framebuffer */
36 static inline u32 nouveau_get_height_in_blocks(u32 height, u32 gobs_in_block, u16 family)
37 {
38 	return DIV_ROUND_UP(height, nouveau_get_gob_height(family) * gobs_in_block);
39 }
40 
41 /* Return the GOB size in bytes */
42 static inline u32 nouveau_get_gob_size(u16 family)
43 {
44 	return nouveau_get_gob_height(family) * NV_TILE_GOB_WIDTH_BYTES;
45 }
46 
47 /* Return the number of GOB in a block */
48 static inline int nouveau_get_gobs_in_block(u32 tile_mode, u16 chipset)
49 {
50 	if (chipset >= 0xc0)
51 		return 1 << (tile_mode >> 4);
52 	return 1 << tile_mode;
53 }
54 
55 /* Return true if tile_mode is invalid */
56 static inline bool nouveau_check_tile_mode(u32 tile_mode, u16 chipset)
57 {
58 	if (chipset >= 0xc0)
59 		return (tile_mode & 0xfffff0f);
60 	return (tile_mode & 0xfffffff0);
61 }
62 
63 #endif
64