1 /*
2  *
3  * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
4  * Author: Rob Clark <rob@ti.com>
5  *         Andy Gross <andy.gross@ti.com>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation version 2.
10  *
11  * This program is distributed "as is" WITHOUT ANY WARRANTY of any
12  * kind, whether express or implied; without even the implied warranty
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  */
16 #ifndef OMAP_DMM_TILER_H
17 #define OMAP_DMM_TILER_H
18 
19 #include "omap_drv.h"
20 #include "tcm.h"
21 
22 enum tiler_fmt {
23 	TILFMT_8BIT = 0,
24 	TILFMT_16BIT,
25 	TILFMT_32BIT,
26 	TILFMT_PAGE,
27 	TILFMT_NFORMATS
28 };
29 
30 struct pat_area {
31 	u32 x0:8;
32 	u32 y0:8;
33 	u32 x1:8;
34 	u32 y1:8;
35 };
36 
37 struct tiler_block {
38 	struct list_head alloc_node;	/* node for global block list */
39 	struct tcm_area area;		/* area */
40 	enum tiler_fmt fmt;		/* format */
41 };
42 
43 /* bits representing the same slot in DMM-TILER hw-block */
44 #define SLOT_WIDTH_BITS         6
45 #define SLOT_HEIGHT_BITS        6
46 
47 /* bits reserved to describe coordinates in DMM-TILER hw-block */
48 #define CONT_WIDTH_BITS         14
49 #define CONT_HEIGHT_BITS        13
50 
51 /* calculated constants */
52 #define TILER_PAGE              (1 << (SLOT_WIDTH_BITS + SLOT_HEIGHT_BITS))
53 #define TILER_WIDTH             (1 << (CONT_WIDTH_BITS - SLOT_WIDTH_BITS))
54 #define TILER_HEIGHT            (1 << (CONT_HEIGHT_BITS - SLOT_HEIGHT_BITS))
55 
56 /* tiler space addressing bitfields */
57 #define MASK_XY_FLIP		(1 << 31)
58 #define MASK_Y_INVERT		(1 << 30)
59 #define MASK_X_INVERT		(1 << 29)
60 #define SHIFT_ACC_MODE		27
61 #define MASK_ACC_MODE		3
62 
63 #define MASK(bits) ((1 << (bits)) - 1)
64 
65 #define TILVIEW_8BIT    0x60000000u
66 #define TILVIEW_16BIT   (TILVIEW_8BIT  + VIEW_SIZE)
67 #define TILVIEW_32BIT   (TILVIEW_16BIT + VIEW_SIZE)
68 #define TILVIEW_PAGE    (TILVIEW_32BIT + VIEW_SIZE)
69 #define TILVIEW_END     (TILVIEW_PAGE  + VIEW_SIZE)
70 
71 /* create tsptr by adding view orientation and access mode */
72 #define TIL_ADDR(x, orient, a)\
73 	((u32) (x) | (orient) | ((a) << SHIFT_ACC_MODE))
74 
75 /* externally accessible functions */
76 int omap_dmm_init(struct drm_device *dev);
77 int omap_dmm_remove(void);
78 
79 #ifdef CONFIG_DEBUG_FS
80 int tiler_map_show(struct seq_file *s, void *arg);
81 #endif
82 
83 /* pin/unpin */
84 int tiler_pin(struct tiler_block *block, struct page **pages,
85 		uint32_t npages, uint32_t roll, bool wait);
86 int tiler_unpin(struct tiler_block *block);
87 
88 /* reserve/release */
89 struct tiler_block *tiler_reserve_2d(enum tiler_fmt fmt, uint16_t w, uint16_t h,
90 				uint16_t align);
91 struct tiler_block *tiler_reserve_1d(size_t size);
92 int tiler_release(struct tiler_block *block);
93 
94 /* utilities */
95 dma_addr_t tiler_ssptr(struct tiler_block *block);
96 uint32_t tiler_stride(enum tiler_fmt fmt);
97 size_t tiler_size(enum tiler_fmt fmt, uint16_t w, uint16_t h);
98 size_t tiler_vsize(enum tiler_fmt fmt, uint16_t w, uint16_t h);
99 void tiler_align(enum tiler_fmt fmt, uint16_t *w, uint16_t *h);
100 
101 
102 /* GEM bo flags -> tiler fmt */
gem2fmt(uint32_t flags)103 static inline enum tiler_fmt gem2fmt(uint32_t flags)
104 {
105 	switch (flags & OMAP_BO_TILED) {
106 	case OMAP_BO_TILED_8:
107 		return TILFMT_8BIT;
108 	case OMAP_BO_TILED_16:
109 		return TILFMT_16BIT;
110 	case OMAP_BO_TILED_32:
111 		return TILFMT_32BIT;
112 	default:
113 		return TILFMT_PAGE;
114 	}
115 }
116 
validfmt(enum tiler_fmt fmt)117 static inline bool validfmt(enum tiler_fmt fmt)
118 {
119 	switch (fmt) {
120 	case TILFMT_8BIT:
121 	case TILFMT_16BIT:
122 	case TILFMT_32BIT:
123 	case TILFMT_PAGE:
124 		return true;
125 	default:
126 		return false;
127 	}
128 }
129 
130 struct omap_dmm_platform_data {
131 	void __iomem *base;
132 	int irq;
133 };
134 
135 #endif
136