aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLajos Molnar <molnar@ti.com>2010-07-08 03:26:44 -0400
committerPaolo Pisati <paolo.pisati@canonical.com>2012-08-17 04:18:59 -0400
commit410c55b47ea271f3c718b3897b65c847295e5839 (patch)
treec801c2dbe2edf1df4c3c39c49deab9d6ddaae922
parent0cbfc90be53e7b6c2701751e1531c125a3d73755 (diff)
TILER: Removed unused DMM macro definitions
Removed unneeded/unused macro definitions. Signed-off-by: Lajos Molnar <molnar@ti.com> Signed-off-by: David Sin <davidsin@ti.com> TILER: Removed redundant hardcoded TILER constants. tiler-geom.c now calculates most tiler-geometry related constants, and exposes them to other functions via a tiler_geom structure. Removed unused TILER calculation macros. Signed-off-by: Lajos Molnar <molnar@ti.com> Signed-off-by: David Sin <davidsin@ti.com> TILER: Removed unnecessary adjustment by TILFMT_8BIT Since TILFMT_8BIT is not 0, we don't need to adjust array access by tiler format. Signed-off-by: Lajos Molnar <molnar@ti.com> Signed-off-by: David Sin <davidsin@ti.com> TILER: Removed unused get_parent() API from TCM. Since TILER maintains a list of blocks within TCM areas, we do not use this method. Also, this method is only used when looking up blocks by ssptr, which is not used by MemMgr API-s. Originally, this method was provided to optimize this lookup. Signed-off-by: Lajos Molnar <molnar@ti.com> Signed-off-by: David Sin <davidsin@ti.com>
-rw-r--r--arch/arm/mach-omap2/include/mach/tiler.h20
-rw-r--r--drivers/media/video/tiler/_tiler.h16
-rw-r--r--drivers/media/video/tiler/tcm.h33
-rw-r--r--drivers/media/video/tiler/tcm/tcm-sita.c33
-rw-r--r--drivers/media/video/tiler/tiler-def.h144
-rw-r--r--drivers/media/video/tiler/tiler-geom.c281
-rw-r--r--drivers/media/video/tiler/tiler-main.c132
-rw-r--r--drivers/media/video/tiler/tiler-reserve.c44
8 files changed, 243 insertions, 460 deletions
diff --git a/arch/arm/mach-omap2/include/mach/tiler.h b/arch/arm/mach-omap2/include/mach/tiler.h
index 5d4d66547b4..7c62fe093a9 100644
--- a/arch/arm/mach-omap2/include/mach/tiler.h
+++ b/arch/arm/mach-omap2/include/mach/tiler.h
@@ -17,13 +17,6 @@
17#ifndef TILER_H 17#ifndef TILER_H
18#define TILER_H 18#define TILER_H
19 19
20#define TILER_PAGE 0x1000
21#define TILER_WIDTH 256
22#define TILER_HEIGHT 128
23#define TILER_BLOCK_WIDTH 64
24#define TILER_BLOCK_HEIGHT 64
25#define TILER_LENGTH (TILER_WIDTH * TILER_HEIGHT * TILER_PAGE)
26
27#define TILER_MAX_NUM_BLOCKS 16 20#define TILER_MAX_NUM_BLOCKS 16
28 21
29#include <linux/mm.h> 22#include <linux/mm.h>
@@ -114,9 +107,9 @@ struct tiler_buf_info {
114}; 107};
115 108
116struct tiler_view_orient { 109struct tiler_view_orient {
117 u8 rotate_90; 110 u32 x_invert;
118 u8 x_invert; 111 u32 y_invert;
119 u8 y_invert; 112 u32 rotate_90;
120}; 113};
121 114
122/** 115/**
@@ -310,12 +303,11 @@ s32 tiler_reservex_nv12(u32 n, u32 width, u32 height, u32 align, u32 offs,
310 303
311u32 tiler_reorient_addr(u32 tsptr, struct tiler_view_orient orient); 304u32 tiler_reorient_addr(u32 tsptr, struct tiler_view_orient orient);
312 305
313u32 tiler_get_natural_addr(void *sys_ptr); 306u32 tiler_offset_addr(u32 tsptr, u32 x, u32 y);
314 307
315u32 tiler_reorient_topleft(u32 tsptr, struct tiler_view_orient orient, 308u32 tiler_get_natural_addr(void *sys_ptr);
316 u32 width, u32 height);
317 309
318u32 tiler_stride(u32 tsptr); 310u32 tiler_topleft(u32 tsptr, u32 width, u32 height);
319 311
320void tiler_rotate_view(struct tiler_view_orient *orient, u32 rotation); 312void tiler_rotate_view(struct tiler_view_orient *orient, u32 rotation);
321 313
diff --git a/drivers/media/video/tiler/_tiler.h b/drivers/media/video/tiler/_tiler.h
index 149f3002730..ab6bfec8cf5 100644
--- a/drivers/media/video/tiler/_tiler.h
+++ b/drivers/media/video/tiler/_tiler.h
@@ -50,6 +50,15 @@ struct mem_info {
50 void *parent; /* area info for 2D, else group info */ 50 void *parent; /* area info for 2D, else group info */
51}; 51};
52 52
53struct tiler_geom {
54 u32 x_shft; /* unused X-bits (as part of bpp) */
55 u32 y_shft; /* unused Y-bits (as part of bpp) */
56 u32 bpp; /* bytes per pixel */
57 u32 slot_w; /* width of each slot (in pixels) */
58 u32 slot_h; /* height of each slot (in pixels) */
59 u32 bpp_m; /* modified bytes per pixel (=1 for page mode) */
60};
61
53struct tiler_ops { 62struct tiler_ops {
54 /* block operations */ 63 /* block operations */
55 s32 (*alloc) (enum tiler_fmt fmt, u32 width, u32 height, 64 s32 (*alloc) (enum tiler_fmt fmt, u32 width, u32 height,
@@ -97,10 +106,15 @@ struct tiler_ops {
97 void (*xy) (u32 tsptr, u32 *x, u32 *y); 106 void (*xy) (u32 tsptr, u32 *x, u32 *y);
98 u32 (*addr) (struct tiler_view_orient orient, enum tiler_fmt fmt, 107 u32 (*addr) (struct tiler_view_orient orient, enum tiler_fmt fmt,
99 u32 x, u32 y); 108 u32 x, u32 y);
109 const struct tiler_geom * (*geom) (enum tiler_fmt fmt);
100 110
101 /* additional info */ 111 /* additional info */
102 const struct file_operations *fops; 112 const struct file_operations *fops;
103 bool nv12_packed; 113
114 bool nv12_packed; /* whether NV12 is packed into same container */
115 u32 page; /* page size */
116 u32 width; /* container width */
117 u32 height; /* container height */
104}; 118};
105 119
106void tiler_iface_init(struct tiler_ops *tiler); 120void tiler_iface_init(struct tiler_ops *tiler);
diff --git a/drivers/media/video/tiler/tcm.h b/drivers/media/video/tiler/tcm.h
index 11201674fdc..ccd3ce4eaaa 100644
--- a/drivers/media/video/tiler/tcm.h
+++ b/drivers/media/video/tiler/tcm.h
@@ -49,8 +49,6 @@ struct tcm {
49 struct tcm_area *area); 49 struct tcm_area *area);
50 s32 (*reserve_1d)(struct tcm *tcm, u32 slots, struct tcm_area *area); 50 s32 (*reserve_1d)(struct tcm *tcm, u32 slots, struct tcm_area *area);
51 s32 (*free) (struct tcm *tcm, struct tcm_area *area); 51 s32 (*free) (struct tcm *tcm, struct tcm_area *area);
52 s32 (*get_parent)(struct tcm *tcm, struct tcm_pt *pt,
53 struct tcm_area *area);
54 void (*deinit) (struct tcm *tcm); 52 void (*deinit) (struct tcm *tcm);
55}; 53};
56 54
@@ -200,37 +198,6 @@ static inline s32 tcm_free(struct tcm_area *area)
200 return res; 198 return res;
201} 199}
202 200
203
204/**
205 * Retrieves the parent area (1D or 2D) for a given co-ordinate in the
206 * container.
207 *
208 * @author Ravi Ramachandra (3/1/2010)
209 *
210 * @param tcm Pointer to container manager.
211 * @param pt Pointer to the coordinates of a slot in the container.
212 * @param area Pointer to where the reserved area should be stored.
213 *
214 * @return 0 on success. Non-0 error code on failure. Also,
215 * the tcm field of the area will be set to NULL on
216 * failure. Some error codes: -ENODEV: invalid manager,
217 * -EINVAL: invalid area, -ENOENT: coordinate is not part of any
218 * active area.
219 */
220static inline s32 tcm_get_parent(struct tcm *tcm, struct tcm_pt *pt,
221 struct tcm_area *area)
222{
223 s32 res = (tcm == NULL ? -ENODEV :
224 area == NULL ? -EINVAL :
225 (pt->x >= tcm->width || pt->y >= tcm->height) ? -ENOENT :
226 tcm->get_parent(tcm, pt, area));
227
228 if (area)
229 area->tcm = res ? NULL : tcm;
230
231 return res;
232}
233
234/*============================================================================= 201/*=============================================================================
235 HELPER FUNCTION FOR ANY TILER CONTAINER MANAGER 202 HELPER FUNCTION FOR ANY TILER CONTAINER MANAGER
236=============================================================================*/ 203=============================================================================*/
diff --git a/drivers/media/video/tiler/tcm/tcm-sita.c b/drivers/media/video/tiler/tcm/tcm-sita.c
index 2ab5ac59ae2..ea6ceb8ecc9 100644
--- a/drivers/media/video/tiler/tcm/tcm-sita.c
+++ b/drivers/media/video/tiler/tcm/tcm-sita.c
@@ -45,8 +45,6 @@ static s32 sita_reserve_2d(struct tcm *tcm, u16 h, u16 w, u8 align,
45static s32 sita_reserve_1d(struct tcm *tcm, u32 slots, struct tcm_area 45static s32 sita_reserve_1d(struct tcm *tcm, u32 slots, struct tcm_area
46 *area); 46 *area);
47static s32 sita_free(struct tcm *tcm, struct tcm_area *to_be_removed_area); 47static s32 sita_free(struct tcm *tcm, struct tcm_area *to_be_removed_area);
48static s32 sita_get_parent(struct tcm *tcm, struct tcm_pt *pt,
49 struct tcm_area *area);
50static void sita_deinit(struct tcm *tcm); 48static void sita_deinit(struct tcm *tcm);
51 49
52/********************************************* 50/*********************************************
@@ -213,7 +211,6 @@ struct tcm *sita_init(u16 width, u16 height, struct tcm_pt *attr)
213 tcm->width = width; 211 tcm->width = width;
214 tcm->reserve_2d = sita_reserve_2d; 212 tcm->reserve_2d = sita_reserve_2d;
215 tcm->reserve_1d = sita_reserve_1d; 213 tcm->reserve_1d = sita_reserve_1d;
216 tcm->get_parent = sita_get_parent;
217 tcm->free = sita_free; 214 tcm->free = sita_free;
218 tcm->deinit = sita_deinit; 215 tcm->deinit = sita_deinit;
219 tcm->pvt = (void *)pvt; 216 tcm->pvt = (void *)pvt;
@@ -1296,36 +1293,6 @@ static s32 get_busy_neigh_stats(struct tcm *tcm, u16 width, u16 height,
1296 return 0; 1293 return 0;
1297} 1294}
1298 1295
1299/**
1300 @description: Retrieves the parent area of the page at p0.x, p0.y if
1301 occupied
1302 @input:co-ordinates of the page (p0.x, p0.y) whoes parent area
1303 is required
1304 @return 0 on success, non-0 error value on failure. On success
1305
1306 parent will contain co-ordinates (TL & BR corner) of the parent
1307 area
1308*/
1309static s32 sita_get_parent(struct tcm *tcm, struct tcm_pt *pt,
1310 struct tcm_area *parent)
1311{
1312 struct sita_pvt *pvt = (struct sita_pvt *)tcm->pvt;
1313 s32 res = 0;
1314
1315 mutex_lock(&(pvt->mtx));
1316
1317 if (pvt->map[pt->x][pt->y].busy) {
1318 *parent = pvt->map[pt->x][pt->y].parent;
1319 } else {
1320 memset(parent, 0, sizeof(*parent));
1321 res = -ENOENT;
1322 }
1323
1324 mutex_unlock(&(pvt->mtx));
1325
1326 return res;
1327}
1328
1329static s32 move_left(struct tcm *tcm, u16 x, u16 y, u32 num_pages, 1296static s32 move_left(struct tcm *tcm, u16 x, u16 y, u32 num_pages,
1330 u16 *xx, u16 *yy) 1297 u16 *xx, u16 *yy)
1331{ 1298{
diff --git a/drivers/media/video/tiler/tiler-def.h b/drivers/media/video/tiler/tiler-def.h
index facf497e31e..611b81dc60b 100644
--- a/drivers/media/video/tiler/tiler-def.h
+++ b/drivers/media/video/tiler/tiler-def.h
@@ -17,150 +17,10 @@
17#ifndef TILER_DEF_H 17#ifndef TILER_DEF_H
18#define TILER_DEF_H 18#define TILER_DEF_H
19 19
20#define ROUND_UP_2P(a, b) (((a) + (b) - 1) & ~((b) - 1))
21#define DIVIDE_UP(a, b) (((a) + (b) - 1) / (b))
22#define ROUND_UP(a, b) (DIVIDE_UP(a, b) * (b))
23#define MIN(a, b) ((a) < (b) ? (a) : (b)) 20#define MIN(a, b) ((a) < (b) ? (a) : (b))
24#define MAX(a, b) ((a) > (b) ? (a) : (b)) 21#define MAX(a, b) ((a) > (b) ? (a) : (b))
25 22
26#define TILER_ACC_MODE_SHIFT (27) 23#define TILER_FORMATS (TILFMT_MAX - TILFMT_MIN + 1)
27#define TILER_ACC_MODE_MASK (3) 24#define TILER_ALIAS_BASE 0x60000000u
28#define TILER_GET_ACC_MODE(x) ((enum tiler_fmt) (TILFMT_8BIT + \
29(((u32)x & (TILER_ACC_MODE_MASK<<TILER_ACC_MODE_SHIFT))>>TILER_ACC_MODE_SHIFT)))
30
31#define TILER_FORMATS 4
32
33#define TILER_ALIAS_BASE 0x60000000u
34#define TILVIEW_8BIT TILER_ALIAS_BASE
35#define TILVIEW_16BIT (TILVIEW_8BIT + 0x08000000u)
36#define TILVIEW_32BIT (TILVIEW_16BIT + 0x08000000u)
37#define TILVIEW_PAGE (TILVIEW_32BIT + 0x08000000u)
38#define TILVIEW_END (TILVIEW_PAGE + 0x08000000u)
39
40#define TILER_ACC_MODE_SHIFT (27)
41#define DMM_ACC_MODE_SHIFT (27)
42
43#define TIL_ALIAS_ADDR(x, access_mode)\
44((void *)(TILER_ALIAS_BASE | (u32)x | (access_mode << TILER_ACC_MODE_SHIFT)))
45
46#define TIL_ADDR(x, r, yi, xi, a)\
47((void *)((u32)x | (r << DMM_ROTATION_SHIFT) |\
48(yi << DMM_Y_INVERT_SHIFT) | (xi << DMM_X_INVERT_SHIFT) |\
49(a << DMM_ACC_MODE_SHIFT)))
50
51#define TILER_ALIAS_VIEW_CLEAR (~0xE0000000)
52
53#define DMM_X_INVERT_SHIFT (29)
54#define DMM_GET_X_INVERTED(x) ((((u32)x & (1<<DMM_X_INVERT_SHIFT)) > 0) ? 1 : 0)
55#define DMM_Y_INVERT_SHIFT (30)
56#define DMM_GET_Y_INVERTED(x) ((((u32)x & (1<<DMM_Y_INVERT_SHIFT)) > 0) ? 1 : 0)
57
58#define DMM_ROTATION_SHIFT (31)
59#define DMM_GET_ROTATED(x)\
60((((u32)x & ((u32)1<<DMM_ROTATION_SHIFT)) > 0) ? 1 : 0)
61
62#define DMM_ALIAS_VIEW_CLEAR (~0xE0000000)
63
64#define DMM_TILE_DIMM_X_MODE_8 (32)
65#define DMM_TILE_DIMM_Y_MODE_8 (32)
66
67#define DMM_TILE_DIMM_X_MODE_16 (32)
68#define DMM_TILE_DIMM_Y_MODE_16 (16)
69
70#define DMM_TILE_DIMM_X_MODE_32 (16)
71#define DMM_TILE_DIMM_Y_MODE_32 (16)
72
73#define DMM_PAGE_DIMM_X_MODE_8 (DMM_TILE_DIMM_X_MODE_8*2)
74#define DMM_PAGE_DIMM_Y_MODE_8 (DMM_TILE_DIMM_Y_MODE_8*2)
75
76#define DMM_PAGE_DIMM_X_MODE_16 (DMM_TILE_DIMM_X_MODE_16*2)
77#define DMM_PAGE_DIMM_Y_MODE_16 (DMM_TILE_DIMM_Y_MODE_16*2)
78
79#define DMM_PAGE_DIMM_X_MODE_32 (DMM_TILE_DIMM_X_MODE_32*2)
80#define DMM_PAGE_DIMM_Y_MODE_32 (DMM_TILE_DIMM_Y_MODE_32*2)
81
82#define DMM_HOR_X_ADDRSHIFT_8 (0)
83#define DMM_HOR_X_ADDRMASK_8 (0x3FFF)
84#define DMM_HOR_X_COOR_GET_8(x)\
85 (((unsigned long)x >> DMM_HOR_X_ADDRSHIFT_8) & DMM_HOR_X_ADDRMASK_8)
86#define DMM_HOR_X_PAGE_COOR_GET_8(x)\
87 (DMM_HOR_X_COOR_GET_8(x)/DMM_PAGE_DIMM_X_MODE_8)
88
89#define DMM_HOR_Y_ADDRSHIFT_8 (14)
90#define DMM_HOR_Y_ADDRMASK_8 (0x1FFF)
91#define DMM_HOR_Y_COOR_GET_8(x)\
92 (((unsigned long)x >> DMM_HOR_Y_ADDRSHIFT_8) & DMM_HOR_Y_ADDRMASK_8)
93#define DMM_HOR_Y_PAGE_COOR_GET_8(x)\
94 (DMM_HOR_Y_COOR_GET_8(x)/DMM_PAGE_DIMM_Y_MODE_8)
95
96#define DMM_HOR_X_ADDRSHIFT_16 (1)
97#define DMM_HOR_X_ADDRMASK_16 (0x7FFE)
98#define DMM_HOR_X_COOR_GET_16(x) (((unsigned long)x >> \
99 DMM_HOR_X_ADDRSHIFT_16) & DMM_HOR_X_ADDRMASK_16)
100#define DMM_HOR_X_PAGE_COOR_GET_16(x) (DMM_HOR_X_COOR_GET_16(x) / \
101 DMM_PAGE_DIMM_X_MODE_16)
102
103#define DMM_HOR_Y_ADDRSHIFT_16 (15)
104#define DMM_HOR_Y_ADDRMASK_16 (0xFFF)
105#define DMM_HOR_Y_COOR_GET_16(x) (((unsigned long)x >> \
106 DMM_HOR_Y_ADDRSHIFT_16) & DMM_HOR_Y_ADDRMASK_16)
107#define DMM_HOR_Y_PAGE_COOR_GET_16(x) (DMM_HOR_Y_COOR_GET_16(x) / \
108 DMM_PAGE_DIMM_Y_MODE_16)
109
110#define DMM_HOR_X_ADDRSHIFT_32 (2)
111#define DMM_HOR_X_ADDRMASK_32 (0x7FFC)
112#define DMM_HOR_X_COOR_GET_32(x) (((unsigned long)x >> \
113 DMM_HOR_X_ADDRSHIFT_32) & DMM_HOR_X_ADDRMASK_32)
114#define DMM_HOR_X_PAGE_COOR_GET_32(x) (DMM_HOR_X_COOR_GET_32(x) / \
115 DMM_PAGE_DIMM_X_MODE_32)
116
117#define DMM_HOR_Y_ADDRSHIFT_32 (15)
118#define DMM_HOR_Y_ADDRMASK_32 (0xFFF)
119#define DMM_HOR_Y_COOR_GET_32(x) (((unsigned long)x >> \
120 DMM_HOR_Y_ADDRSHIFT_32) & DMM_HOR_Y_ADDRMASK_32)
121#define DMM_HOR_Y_PAGE_COOR_GET_32(x) (DMM_HOR_Y_COOR_GET_32(x) / \
122 DMM_PAGE_DIMM_Y_MODE_32)
123
124#define DMM_VER_X_ADDRSHIFT_8 (14)
125#define DMM_VER_X_ADDRMASK_8 (0x1FFF)
126#define DMM_VER_X_COOR_GET_8(x)\
127 (((unsigned long)x >> DMM_VER_X_ADDRSHIFT_8) & DMM_VER_X_ADDRMASK_8)
128#define DMM_VER_X_PAGE_COOR_GET_8(x)\
129 (DMM_VER_X_COOR_GET_8(x)/DMM_PAGE_DIMM_X_MODE_8)
130
131#define DMM_VER_Y_ADDRSHIFT_8 (0)
132#define DMM_VER_Y_ADDRMASK_8 (0x3FFF)
133#define DMM_VER_Y_COOR_GET_8(x)\
134 (((unsigned long)x >> DMM_VER_Y_ADDRSHIFT_8) & DMM_VER_Y_ADDRMASK_8)
135#define DMM_VER_Y_PAGE_COOR_GET_8(x)\
136 (DMM_VER_Y_COOR_GET_8(x)/DMM_PAGE_DIMM_Y_MODE_8)
137
138#define DMM_VER_X_ADDRSHIFT_16 (14)
139#define DMM_VER_X_ADDRMASK_16 (0x1FFF)
140#define DMM_VER_X_COOR_GET_16(x) (((unsigned long)x >> \
141 DMM_VER_X_ADDRSHIFT_16) & DMM_VER_X_ADDRMASK_16)
142#define DMM_VER_X_PAGE_COOR_GET_16(x) (DMM_VER_X_COOR_GET_16(x) / \
143 DMM_PAGE_DIMM_X_MODE_16)
144
145#define DMM_VER_Y_ADDRSHIFT_16 (0)
146#define DMM_VER_Y_ADDRMASK_16 (0x3FFF)
147#define DMM_VER_Y_COOR_GET_16(x) (((unsigned long)x >> \
148 DMM_VER_Y_ADDRSHIFT_16) & DMM_VER_Y_ADDRMASK_16)
149#define DMM_VER_Y_PAGE_COOR_GET_16(x) (DMM_VER_Y_COOR_GET_16(x) / \
150 DMM_PAGE_DIMM_Y_MODE_16)
151
152#define DMM_VER_X_ADDRSHIFT_32 (15)
153#define DMM_VER_X_ADDRMASK_32 (0xFFF)
154#define DMM_VER_X_COOR_GET_32(x) (((unsigned long)x >> \
155 DMM_VER_X_ADDRSHIFT_32) & DMM_VER_X_ADDRMASK_32)
156#define DMM_VER_X_PAGE_COOR_GET_32(x) (DMM_VER_X_COOR_GET_32(x) / \
157 DMM_PAGE_DIMM_X_MODE_32)
158
159#define DMM_VER_Y_ADDRSHIFT_32 (0)
160#define DMM_VER_Y_ADDRMASK_32 (0x7FFF)
161#define DMM_VER_Y_COOR_GET_32(x) (((unsigned long)x >> \
162 DMM_VER_Y_ADDRSHIFT_32) & DMM_VER_Y_ADDRMASK_32)
163#define DMM_VER_Y_PAGE_COOR_GET_32(x) (DMM_VER_Y_COOR_GET_32(x) / \
164 DMM_PAGE_DIMM_Y_MODE_32)
165 25
166#endif 26#endif
diff --git a/drivers/media/video/tiler/tiler-geom.c b/drivers/media/video/tiler/tiler-geom.c
index 6258d75b926..ba6db872814 100644
--- a/drivers/media/video/tiler/tiler-geom.c
+++ b/drivers/media/video/tiler/tiler-geom.c
@@ -22,49 +22,64 @@
22#include "tcm.h" 22#include "tcm.h"
23#include "_tiler.h" 23#include "_tiler.h"
24 24
25#define DMM_SHIFT_PER_X_8 0 25#define SLOT_WIDTH_BITS 6
26#define DMM_SHIFT_PER_Y_8 0 26#define SLOT_HEIGHT_BITS 6
27#define DMM_SHIFT_PER_X_16 0 27
28#define DMM_SHIFT_PER_Y_16 1 28static struct tiler_geom geom[TILER_FORMATS] = {
29#define DMM_SHIFT_PER_X_32 1 29 {
30#define DMM_SHIFT_PER_Y_32 1 30 .x_shft = 0,
31#define DMM_SHIFT_PER_X_PAGE 6 31 .y_shft = 0,
32#define DMM_SHIFT_PER_Y_PAGE 6 32 },
33 33 {
34#define DMM_TILER_THE(NAME) (1 << DMM_TILER_##NAME##_BITS) 34 .x_shft = 0,
35#define DMM_TILER_THE_(N, NAME) (1 << DMM_TILER_##NAME##_BITS_(N)) 35 .y_shft = 1,
36 36 },
37#define DMM_TILER_CONT_WIDTH_BITS 14 37 {
38#define DMM_TILER_CONT_HEIGHT_BITS 13 38 .x_shft = 1,
39 39 .y_shft = 1,
40#define DMM_SHIFT_PER_P_(N) (DMM_SHIFT_PER_X_##N + DMM_SHIFT_PER_Y_##N) 40 },
41 41 {
42#define DMM_TILER_CONT_HEIGHT_BITS_(N) \ 42 .x_shft = SLOT_WIDTH_BITS,
43 (DMM_TILER_CONT_HEIGHT_BITS - DMM_SHIFT_PER_Y_##N) 43 .y_shft = SLOT_HEIGHT_BITS,
44#define DMM_TILER_CONT_WIDTH_BITS_(N) \ 44 },
45 (DMM_TILER_CONT_WIDTH_BITS - DMM_SHIFT_PER_X_##N) 45};
46 46
47#define DMM_TILER_MASK(bits) ((1 << (bits)) - 1) 47#define DMM_ROTATION_SHIFT 31
48 48#define DMM_Y_INVERT_SHIFT 30
49#define DMM_TILER_GET_OFFSET_(N, var) \ 49#define DMM_X_INVERT_SHIFT 29
50 ((((u32) var) & DMM_TILER_MASK(DMM_TILER_CONT_WIDTH_BITS + \ 50#define DMM_ACC_MODE_SHIFT 27
51 DMM_TILER_CONT_HEIGHT_BITS)) >> DMM_SHIFT_PER_P_(N)) 51#define DMM_ACC_MODE_MASK 3
52 52#define CONT_WIDTH_BITS 14
53#define DMM_TILER_GET_0_X_(N, var) \ 53#define CONT_HEIGHT_BITS 13
54 (DMM_TILER_GET_OFFSET_(N, var) & \ 54
55 DMM_TILER_MASK(DMM_TILER_CONT_WIDTH_BITS_(N))) 55#define TILER_PAGE (1 << (SLOT_WIDTH_BITS + SLOT_HEIGHT_BITS))
56#define DMM_TILER_GET_0_Y_(N, var) \ 56#define TILER_WIDTH (1 << (CONT_WIDTH_BITS - SLOT_WIDTH_BITS))
57 (DMM_TILER_GET_OFFSET_(N, var) >> DMM_TILER_CONT_WIDTH_BITS_(N)) 57#define TILER_HEIGHT (1 << (CONT_HEIGHT_BITS - SLOT_HEIGHT_BITS))
58#define DMM_TILER_GET_90_X_(N, var) \ 58
59 (DMM_TILER_GET_OFFSET_(N, var) & \ 59#define VIEW_SIZE (1u << (CONT_WIDTH_BITS + CONT_HEIGHT_BITS))
60 DMM_TILER_MASK(DMM_TILER_CONT_HEIGHT_BITS_(N))) 60#define VIEW_MASK (VIEW_SIZE - 1u)
61#define DMM_TILER_GET_90_Y_(N, var) \ 61
62 (DMM_TILER_GET_OFFSET_(N, var) >> DMM_TILER_CONT_HEIGHT_BITS_(N)) 62#define MASK(bits) ((1 << (bits)) - 1)
63 63
64#define DMM_TILER_STRIDE_0_(N) \ 64#define TILER_GET_ACC_MODE(x) ((enum tiler_fmt) \
65 (DMM_TILER_THE(CONT_WIDTH) << DMM_SHIFT_PER_Y_##N) 65 ((x >> DMM_ACC_MODE_SHIFT) & DMM_ACC_MODE_MASK))
66#define DMM_TILER_STRIDE_90_(N) \ 66#define DMM_IS_X_INVERTED(x) ((x >> DMM_X_INVERT_SHIFT) & 1)
67 (DMM_TILER_THE(CONT_HEIGHT) << DMM_SHIFT_PER_X_##N) 67#define DMM_IS_Y_INVERTED(x) ((x >> DMM_Y_INVERT_SHIFT) & 1)
68#define DMM_IS_ROTATED(x) ((x >> DMM_ROTATION_SHIFT) & 1)
69
70#define DMM_ALIAS_VIEW_CLEAR (~((1 << DMM_X_INVERT_SHIFT) | \
71 (1 << DMM_Y_INVERT_SHIFT) | (1 << DMM_ROTATION_SHIFT)))
72
73#define TILVIEW_8BIT TILER_ALIAS_BASE
74#define TILVIEW_16BIT (TILVIEW_8BIT + VIEW_SIZE)
75#define TILVIEW_32BIT (TILVIEW_16BIT + VIEW_SIZE)
76#define TILVIEW_PAGE (TILVIEW_32BIT + VIEW_SIZE)
77#define TILVIEW_END (TILVIEW_PAGE + VIEW_SIZE)
78
79#define TIL_ADDR(x, r, yi, xi, a)\
80 ((u32) x | (((r) ? 1 : 0) << DMM_ROTATION_SHIFT) | \
81 (((yi) ? 1 : 0) << DMM_Y_INVERT_SHIFT) | \
82 (((xi) ? 1 : 0) << DMM_X_INVERT_SHIFT) | ((a) << DMM_ACC_MODE_SHIFT))
68 83
69/* 84/*
70 * TILER Memory model query method 85 * TILER Memory model query method
@@ -78,24 +93,36 @@ bool is_tiler_addr(u32 phys)
78 * TILER block query method 93 * TILER block query method
79 */ 94 */
80 95
81static const u32 tiler_bpps[TILER_FORMATS] = { 1, 2, 4, 1 };
82static const u32 tiler_strides[TILER_FORMATS] = { 16384, 32768, 32768, 0 };
83
84u32 tiler_bpp(const struct tiler_block_t *b) 96u32 tiler_bpp(const struct tiler_block_t *b)
85{ 97{
86 enum tiler_fmt fmt = tiler_fmt(b->phys); 98 enum tiler_fmt fmt = tiler_fmt(b->phys);
87 BUG_ON(fmt == TILFMT_INVALID); 99 BUG_ON(fmt == TILFMT_INVALID);
88 100
89 return tiler_bpps[fmt - TILFMT_8BIT]; 101 /* return modified bpp */
102 return geom[fmt].bpp_m;
90} 103}
91EXPORT_SYMBOL(tiler_bpp); 104EXPORT_SYMBOL(tiler_bpp);
92 105
106static inline u32 tiler_stride(enum tiler_fmt fmt, bool rotated)
107{
108 if (fmt == TILFMT_PAGE)
109 return 0;
110
111 return rotated ?
112 1 << (CONT_HEIGHT_BITS + geom[fmt].x_shft) :
113 1 << (CONT_WIDTH_BITS + geom[fmt].y_shft);
114}
115
93u32 tiler_pstride(const struct tiler_block_t *b) 116u32 tiler_pstride(const struct tiler_block_t *b)
94{ 117{
95 enum tiler_fmt fmt = tiler_fmt(b->phys); 118 enum tiler_fmt fmt = tiler_fmt(b->phys);
96 BUG_ON(fmt == TILFMT_INVALID); 119 BUG_ON(fmt == TILFMT_INVALID);
97 120
98 return tiler_strides[fmt - TILFMT_8BIT] ? : tiler_vstride(b); 121 /* return the virtual stride for page mode */
122 if (fmt == TILFMT_PAGE)
123 return tiler_vstride(b);
124
125 return tiler_stride(fmt, 0);
99} 126}
100EXPORT_SYMBOL(tiler_pstride); 127EXPORT_SYMBOL(tiler_pstride);
101 128
@@ -108,6 +135,13 @@ enum tiler_fmt tiler_fmt(u32 phys)
108} 135}
109EXPORT_SYMBOL(tiler_fmt); 136EXPORT_SYMBOL(tiler_fmt);
110 137
138static const struct tiler_geom *get_geom(enum tiler_fmt fmt)
139{
140 if (fmt >= TILFMT_MIN && fmt <= TILFMT_MAX)
141 return geom + fmt;
142 return NULL;
143}
144
111static void tiler_get_natural_xy(u32 tsptr, u32 *x, u32 *y) 145static void tiler_get_natural_xy(u32 tsptr, u32 *x, u32 *y)
112{ 146{
113 u32 x_bits, y_bits, offset; 147 u32 x_bits, y_bits, offset;
@@ -115,42 +149,22 @@ static void tiler_get_natural_xy(u32 tsptr, u32 *x, u32 *y)
115 149
116 fmt = TILER_GET_ACC_MODE(tsptr); 150 fmt = TILER_GET_ACC_MODE(tsptr);
117 151
118 switch (fmt) { 152 x_bits = CONT_WIDTH_BITS - geom[fmt].x_shft;
119 case TILFMT_8BIT: 153 y_bits = CONT_HEIGHT_BITS - geom[fmt].y_shft;
120 x_bits = DMM_TILER_CONT_WIDTH_BITS_(8); 154 offset = (tsptr & VIEW_MASK) >> (geom[fmt].x_shft + geom[fmt].y_shft);
121 y_bits = DMM_TILER_CONT_HEIGHT_BITS_(8);
122 offset = DMM_TILER_GET_OFFSET_(8, tsptr);
123 break;
124 case TILFMT_16BIT:
125 x_bits = DMM_TILER_CONT_WIDTH_BITS_(16);
126 y_bits = DMM_TILER_CONT_HEIGHT_BITS_(16);
127 offset = DMM_TILER_GET_OFFSET_(16, tsptr);
128 break;
129 case TILFMT_32BIT:
130 x_bits = DMM_TILER_CONT_WIDTH_BITS_(32);
131 y_bits = DMM_TILER_CONT_HEIGHT_BITS_(32);
132 offset = DMM_TILER_GET_OFFSET_(32, tsptr);
133 break;
134 case TILFMT_PAGE:
135 default:
136 x_bits = DMM_TILER_CONT_WIDTH_BITS_(PAGE);
137 y_bits = DMM_TILER_CONT_HEIGHT_BITS_(PAGE);
138 offset = DMM_TILER_GET_OFFSET_(PAGE, tsptr);
139 break;
140 }
141 155
142 if (DMM_GET_ROTATED(tsptr)) { 156 if (DMM_IS_ROTATED(tsptr)) {
143 *x = offset >> y_bits; 157 *x = offset >> y_bits;
144 *y = offset & DMM_TILER_MASK(y_bits); 158 *y = offset & MASK(y_bits);
145 } else { 159 } else {
146 *x = offset & DMM_TILER_MASK(x_bits); 160 *x = offset & MASK(x_bits);
147 *y = offset >> x_bits; 161 *y = offset >> x_bits;
148 } 162 }
149 163
150 if (DMM_GET_X_INVERTED(tsptr)) 164 if (DMM_IS_X_INVERTED(tsptr))
151 *x ^= DMM_TILER_MASK(x_bits); 165 *x ^= MASK(x_bits);
152 if (DMM_GET_Y_INVERTED(tsptr)) 166 if (DMM_IS_Y_INVERTED(tsptr))
153 *y ^= DMM_TILER_MASK(y_bits); 167 *y ^= MASK(y_bits);
154} 168}
155 169
156static u32 tiler_get_address(struct tiler_view_orient orient, 170static u32 tiler_get_address(struct tiler_view_orient orient,
@@ -158,32 +172,12 @@ static u32 tiler_get_address(struct tiler_view_orient orient,
158{ 172{
159 u32 x_bits, y_bits, tmp, x_mask, y_mask, alignment; 173 u32 x_bits, y_bits, tmp, x_mask, y_mask, alignment;
160 174
161 switch (fmt) { 175 x_bits = CONT_WIDTH_BITS - geom[fmt].x_shft;
162 case TILFMT_8BIT: 176 y_bits = CONT_HEIGHT_BITS - geom[fmt].y_shft;
163 x_bits = DMM_TILER_CONT_WIDTH_BITS_(8); 177 alignment = geom[fmt].x_shft + geom[fmt].y_shft;
164 y_bits = DMM_TILER_CONT_HEIGHT_BITS_(8);
165 alignment = DMM_SHIFT_PER_P_(8);
166 break;
167 case TILFMT_16BIT:
168 x_bits = DMM_TILER_CONT_WIDTH_BITS_(16);
169 y_bits = DMM_TILER_CONT_HEIGHT_BITS_(16);
170 alignment = DMM_SHIFT_PER_P_(16);
171 break;
172 case TILFMT_32BIT:
173 x_bits = DMM_TILER_CONT_WIDTH_BITS_(32);
174 y_bits = DMM_TILER_CONT_HEIGHT_BITS_(32);
175 alignment = DMM_SHIFT_PER_P_(32);
176 break;
177 case TILFMT_PAGE:
178 default:
179 x_bits = DMM_TILER_CONT_WIDTH_BITS_(PAGE);
180 y_bits = DMM_TILER_CONT_HEIGHT_BITS_(PAGE);
181 alignment = DMM_SHIFT_PER_P_(PAGE);
182 break;
183 }
184 178
185 x_mask = DMM_TILER_MASK(x_bits); 179 x_mask = MASK(x_bits);
186 y_mask = DMM_TILER_MASK(y_bits); 180 y_mask = MASK(y_bits);
187 if (x < 0 || x > x_mask || y < 0 || y > y_mask) 181 if (x < 0 || x > x_mask || y < 0 || y > y_mask)
188 return 0; 182 return 0;
189 183
@@ -197,16 +191,8 @@ static u32 tiler_get_address(struct tiler_view_orient orient,
197 else 191 else
198 tmp = ((y << x_bits) + x); 192 tmp = ((y << x_bits) + x);
199 193
200 return (u32) 194 return TIL_ADDR((tmp << alignment), orient.rotate_90,
201 TIL_ADDR((tmp << alignment), (orient.rotate_90 ? 1 : 0), 195 orient.y_invert, orient.x_invert, fmt);
202 (orient.y_invert ? 1 : 0), (orient.x_invert ? 1 : 0),
203 fmt);
204}
205
206void tiler_geom_init(struct tiler_ops *tiler)
207{
208 tiler->xy = tiler_get_natural_xy;
209 tiler->addr = tiler_get_address;
210} 196}
211 197
212u32 tiler_reorient_addr(u32 tsptr, struct tiler_view_orient orient) 198u32 tiler_reorient_addr(u32 tsptr, struct tiler_view_orient orient)
@@ -224,51 +210,35 @@ u32 tiler_get_natural_addr(void *sys_ptr)
224} 210}
225EXPORT_SYMBOL(tiler_get_natural_addr); 211EXPORT_SYMBOL(tiler_get_natural_addr);
226 212
227u32 tiler_reorient_topleft(u32 tsptr, struct tiler_view_orient orient, 213u32 tiler_topleft(u32 tsptr, u32 width, u32 height)
228 u32 width, u32 height)
229{ 214{
230 enum tiler_fmt fmt;
231 u32 x, y; 215 u32 x, y;
232 216 enum tiler_fmt fmt = TILER_GET_ACC_MODE(tsptr);
233 fmt = TILER_GET_ACC_MODE(tsptr); 217 struct tiler_view_orient orient;
218 orient.x_invert = DMM_IS_X_INVERTED(tsptr);
219 orient.y_invert = DMM_IS_Y_INVERTED(tsptr);
220 orient.rotate_90 = DMM_IS_ROTATED(tsptr);
234 221
235 tiler_get_natural_xy(tsptr, &x, &y); 222 tiler_get_natural_xy(tsptr, &x, &y);
236 223
237 if (DMM_GET_X_INVERTED(tsptr)) 224 if (DMM_IS_X_INVERTED(tsptr))
238 x -= width - 1;
239 if (DMM_GET_Y_INVERTED(tsptr))
240 y -= height - 1;
241
242 if (orient.x_invert)
243 x += width - 1; 225 x += width - 1;
244 if (orient.y_invert) 226 if (DMM_IS_Y_INVERTED(tsptr))
245 y += height - 1; 227 y += height - 1;
246 228
229
247 return tiler_get_address(orient, fmt, x, y); 230 return tiler_get_address(orient, fmt, x, y);
248} 231}
249EXPORT_SYMBOL(tiler_reorient_topleft); 232EXPORT_SYMBOL(tiler_topleft);
250 233
251u32 tiler_stride(u32 tsptr) 234u32 tiler_offset_addr(u32 tsptr, u32 x, u32 y)
252{ 235{
253 enum tiler_fmt fmt; 236 enum tiler_fmt fmt = TILER_GET_ACC_MODE(tsptr);
237 bool rotated = DMM_IS_ROTATED(tsptr);
254 238
255 fmt = TILER_GET_ACC_MODE(tsptr); 239 return tsptr + x * geom[fmt].bpp_m + y * tiler_stride(fmt, rotated);
256
257 switch (fmt) {
258 case TILFMT_8BIT:
259 return DMM_GET_ROTATED(tsptr) ?
260 DMM_TILER_STRIDE_90_(8) : DMM_TILER_STRIDE_0_(8);
261 case TILFMT_16BIT:
262 return DMM_GET_ROTATED(tsptr) ?
263 DMM_TILER_STRIDE_90_(16) : DMM_TILER_STRIDE_0_(16);
264 case TILFMT_32BIT:
265 return DMM_GET_ROTATED(tsptr) ?
266 DMM_TILER_STRIDE_90_(32) : DMM_TILER_STRIDE_0_(32);
267 default:
268 return 0;
269 }
270} 240}
271EXPORT_SYMBOL(tiler_stride); 241EXPORT_SYMBOL(tiler_offset_addr);
272 242
273void tiler_rotate_view(struct tiler_view_orient *orient, u32 rotation) 243void tiler_rotate_view(struct tiler_view_orient *orient, u32 rotation)
274{ 244{
@@ -288,3 +258,26 @@ void tiler_rotate_view(struct tiler_view_orient *orient, u32 rotation)
288 } 258 }
289} 259}
290EXPORT_SYMBOL(tiler_rotate_view); 260EXPORT_SYMBOL(tiler_rotate_view);
261
262void tiler_geom_init(struct tiler_ops *tiler)
263{
264 struct tiler_geom *g;
265
266 tiler->xy = tiler_get_natural_xy;
267 tiler->addr = tiler_get_address;
268 tiler->geom = get_geom;
269
270 tiler->page = TILER_PAGE;
271 tiler->width = TILER_WIDTH;
272 tiler->height = TILER_HEIGHT;
273
274 /* calculate geometry */
275 for (g = geom; g < geom + TILER_FORMATS; g++) {
276 g->bpp_m = g->bpp = 1 << (g->x_shft + g->y_shft);
277 g->slot_w = 1 << (SLOT_WIDTH_BITS - g->x_shft);
278 g->slot_h = 1 << (SLOT_HEIGHT_BITS - g->y_shft);
279 }
280
281 /* set bpp_m = 1 for page mode as most applications deal in byte data */
282 geom[TILFMT_PAGE].bpp_m = 1;
283}
diff --git a/drivers/media/video/tiler/tiler-main.c b/drivers/media/video/tiler/tiler-main.c
index 7c6e4ca83f2..91e1c8540a0 100644
--- a/drivers/media/video/tiler/tiler-main.c
+++ b/drivers/media/video/tiler/tiler-main.c
@@ -78,13 +78,6 @@ static struct mutex mtx;
78static struct tcm *tcm[TILER_FORMATS]; 78static struct tcm *tcm[TILER_FORMATS];
79static struct tmm *tmm[TILER_FORMATS]; 79static struct tmm *tmm[TILER_FORMATS];
80 80
81#define TCM(fmt) tcm[(fmt) - TILFMT_8BIT]
82#define TCM_SS(ssptr) TCM(TILER_GET_ACC_MODE(ssptr))
83#define TCM_SET(fmt, i) tcm[(fmt) - TILFMT_8BIT] = i
84#define TMM(fmt) tmm[(fmt) - TILFMT_8BIT]
85#define TMM_SS(ssptr) TMM(TILER_GET_ACC_MODE(ssptr))
86#define TMM_SET(fmt, i) tmm[(fmt) - TILFMT_8BIT] = i
87
88/* 81/*
89 * TMM connectors 82 * TMM connectors
90 * ========================================================================== 83 * ==========================================================================
@@ -290,46 +283,33 @@ static s32 __analize_area(enum tiler_fmt fmt, u32 width, u32 height,
290 /* output: x_area, y_area, band, align, offs in slots */ 283 /* output: x_area, y_area, band, align, offs in slots */
291 284
292 /* slot width, height, and row size */ 285 /* slot width, height, and row size */
293 u32 slot_w, slot_h, slot_row, bpp, min_align; 286 u32 slot_row, min_align;
287 const struct tiler_geom *g;
294 288
295 /* align must be 2 power */ 289 /* align must be 2 power */
296 if (*align & (*align - 1)) 290 if (*align & (*align - 1))
297 return -1; 291 return -1;
298 292
299 switch (fmt) { 293 if (fmt == TILFMT_PAGE) {
300 case TILFMT_8BIT:
301 slot_w = DMM_PAGE_DIMM_X_MODE_8;
302 slot_h = DMM_PAGE_DIMM_Y_MODE_8;
303 bpp = 1;
304 break;
305 case TILFMT_16BIT:
306 slot_w = DMM_PAGE_DIMM_X_MODE_16;
307 slot_h = DMM_PAGE_DIMM_Y_MODE_16;
308 bpp = 2;
309 break;
310 case TILFMT_32BIT:
311 slot_w = DMM_PAGE_DIMM_X_MODE_32;
312 slot_h = DMM_PAGE_DIMM_Y_MODE_32;
313 bpp = 4;
314 break;
315 case TILFMT_PAGE:
316 /* adjust size to accomodate offset, only do page alignment */ 294 /* adjust size to accomodate offset, only do page alignment */
317 *align = PAGE_SIZE; 295 *align = PAGE_SIZE;
318 width += *offs & (PAGE_SIZE - 1); 296 width += *offs & (PAGE_SIZE - 1);
319 297
320 /* for 1D area keep the height (1), width is in tiler slots */ 298 /* for 1D area keep the height (1), width is in tiler slots */
321 *x_area = DIV_ROUND_UP(width, TILER_PAGE); 299 *x_area = DIV_ROUND_UP(width, tiler.page);
322 *y_area = *band = 1; 300 *y_area = *band = 1;
323 301
324 if (*x_area * *y_area > TILER_WIDTH * TILER_HEIGHT) 302 if (*x_area * *y_area > tiler.width * tiler.height)
325 return -1; 303 return -1;
326 return 0; 304 return 0;
327 default:
328 return -EINVAL;
329 } 305 }
330 306
307 g = tiler.geom(fmt);
308 if (!g)
309 return -EINVAL;
310
331 /* get the # of bytes per row in 1 slot */ 311 /* get the # of bytes per row in 1 slot */
332 slot_row = slot_w * bpp; 312 slot_row = g->slot_w * g->bpp;
333 313
334 /* how many slots are can be accessed via one physical page */ 314 /* how many slots are can be accessed via one physical page */
335 *band = PAGE_SIZE / slot_row; 315 *band = PAGE_SIZE / slot_row;
@@ -339,26 +319,26 @@ static s32 __analize_area(enum tiler_fmt fmt, u32 width, u32 height,
339 *align = ALIGN(*align ? : default_align, min_align); 319 *align = ALIGN(*align ? : default_align, min_align);
340 320
341 /* offset must be multiple of bpp */ 321 /* offset must be multiple of bpp */
342 if (*offs & (bpp - 1) || *offs >= *align) 322 if (*offs & (g->bpp - 1) || *offs >= *align)
343 return -EINVAL; 323 return -EINVAL;
344 324
345 /* round down the offset to the nearest slot size, and increase width 325 /* round down the offset to the nearest slot size, and increase width
346 to allow space for having the correct offset */ 326 to allow space for having the correct offset */
347 width += (*offs & (min_align - 1)) / bpp; 327 width += (*offs & (min_align - 1)) / g->bpp;
348 if (in_offs) 328 if (in_offs)
349 *in_offs = *offs & (min_align - 1); 329 *in_offs = *offs & (min_align - 1);
350 *offs &= ~(min_align - 1); 330 *offs &= ~(min_align - 1);
351 331
352 /* expand width to block size */ 332 /* expand width to block size */
353 width = ALIGN(width, min_align / bpp); 333 width = ALIGN(width, min_align / g->bpp);
354 334
355 /* adjust to slots */ 335 /* adjust to slots */
356 *x_area = DIV_ROUND_UP(width, slot_w); 336 *x_area = DIV_ROUND_UP(width, g->slot_w);
357 *y_area = DIV_ROUND_UP(height, slot_h); 337 *y_area = DIV_ROUND_UP(height, g->slot_h);
358 *align /= slot_row; 338 *align /= slot_row;
359 *offs /= slot_row; 339 *offs /= slot_row;
360 340
361 if (*x_area > TILER_WIDTH || *y_area > TILER_HEIGHT) 341 if (*x_area > tiler.width || *y_area > tiler.height)
362 return -1; 342 return -1;
363 return 0x0; 343 return 0x0;
364} 344}
@@ -496,7 +476,7 @@ static s32 lay_2d(enum tiler_fmt fmt, u16 n, u16 w, u16 h, u16 band,
496 /* calculate dimensions, band, offs and alignment in slots */ 476 /* calculate dimensions, band, offs and alignment in slots */
497 /* reserve an area */ 477 /* reserve an area */
498 ai = area_new_m(ALIGN(w_res + offs, max(band, align)), h, 478 ai = area_new_m(ALIGN(w_res + offs, max(band, align)), h,
499 max(band, align), TCM(fmt), gi); 479 max(band, align), tcm[fmt], gi);
500 if (!ai) 480 if (!ai)
501 return -ENOMEM; 481 return -ENOMEM;
502 482
@@ -525,13 +505,14 @@ static s32 lay_nv12(int n, u16 w, u16 w1, u16 h, struct gid_info *gi, u8 *p)
525{ 505{
526 u16 wh = (w1 + 1) >> 1, width, x0; 506 u16 wh = (w1 + 1) >> 1, width, x0;
527 int m; 507 int m;
508 int a = PAGE_SIZE / tiler.geom(TILFMT_8BIT)->slot_w;
528 509
529 struct mem_info *mi = NULL; 510 struct mem_info *mi = NULL;
530 struct area_info *ai = NULL; 511 struct area_info *ai = NULL;
531 struct list_head *pos; 512 struct list_head *pos;
532 513
533 /* reserve area */ 514 /* reserve area */
534 ai = area_new_m(w, h, 64, TILFMT_8BIT, gi); 515 ai = area_new_m(w, h, a, TILFMT_8BIT, gi);
535 if (!ai) 516 if (!ai)
536 return -ENOMEM; 517 return -ENOMEM;
537 518
@@ -582,8 +563,8 @@ static s32 _m_free(struct mem_info *mi)
582 } 563 }
583 kfree(mi->pg_ptr); 564 kfree(mi->pg_ptr);
584 } else if (mi->mem) { 565 } else if (mi->mem) {
585 tmm_free(TMM_SS(mi->blk.phys), mi->mem); 566 tmm_free(tmm[tiler_fmt(mi->blk.phys)], mi->mem);
586 clear_pat(TMM_SS(mi->blk.phys), &mi->area); 567 clear_pat(tmm[tiler_fmt(mi->blk.phys)], &mi->area);
587 } 568 }
588 569
589 /* safe deletion as list may not have been assigned */ 570 /* safe deletion as list may not have been assigned */
@@ -674,7 +655,7 @@ find_n_lock(u32 key, u32 id, struct gid_info *gi) {
674 /* is id is ssptr, we know if block is 1D or 2D by the address, 655 /* is id is ssptr, we know if block is 1D or 2D by the address,
675 so we optimize lookup */ 656 so we optimize lookup */
676 if (!ssptr_id || 657 if (!ssptr_id ||
677 TILER_GET_ACC_MODE(id) == TILFMT_PAGE) { 658 tiler_fmt(id) == TILFMT_PAGE) {
678 list_for_each_entry(mi, &gi->onedim, by_area) { 659 list_for_each_entry(mi, &gi->onedim, by_area) {
679 if (mi->blk.key == key && mi->blk.id == id) 660 if (mi->blk.key == key && mi->blk.id == id)
680 goto done; 661 goto done;
@@ -682,7 +663,7 @@ find_n_lock(u32 key, u32 id, struct gid_info *gi) {
682 } 663 }
683 664
684 if (!ssptr_id || 665 if (!ssptr_id ||
685 TILER_GET_ACC_MODE(id) != TILFMT_PAGE) { 666 tiler_fmt(id) != TILFMT_PAGE) {
686 list_for_each_entry(ai, &gi->areas, by_gid) { 667 list_for_each_entry(ai, &gi->areas, by_gid) {
687 list_for_each_entry(mi, &ai->blocks, by_area) { 668 list_for_each_entry(mi, &ai->blocks, by_area) {
688 if (mi->blk.key == key && 669 if (mi->blk.key == key &&
@@ -804,19 +785,22 @@ static struct mem_info *find_block_by_ssptr(u32 sys_addr)
804 struct tcm_pt pt; 785 struct tcm_pt pt;
805 u32 x, y; 786 u32 x, y;
806 enum tiler_fmt fmt; 787 enum tiler_fmt fmt;
788 const struct tiler_geom *g;
807 789
808 fmt = tiler_fmt(sys_addr); 790 fmt = tiler_fmt(sys_addr);
809 if (fmt == TILFMT_INVALID) 791 if (fmt == TILFMT_INVALID)
810 return NULL; 792 return NULL;
811 793
794 g = tiler.geom(fmt);
795
812 /* convert x & y pixel coordinates to slot coordinates */ 796 /* convert x & y pixel coordinates to slot coordinates */
813 tiler.xy(sys_addr, &x, &y); 797 tiler.xy(sys_addr, &x, &y);
814 pt.x = x / (fmt == TILFMT_PAGE ? 1 : fmt == TILFMT_32BIT ? 32 : 64); 798 pt.x = x / g->slot_w;
815 pt.y = y / (fmt == TILFMT_PAGE ? 1 : fmt == TILFMT_8BIT ? 64 : 32); 799 pt.y = y / g->slot_h;
816 800
817 mutex_lock(&mtx); 801 mutex_lock(&mtx);
818 list_for_each_entry(i, &blocks, global) { 802 list_for_each_entry(i, &blocks, global) {
819 if (tiler_fmt(i->blk.phys) == TILER_GET_ACC_MODE(sys_addr) && 803 if (tiler_fmt(i->blk.phys) == tiler_fmt(sys_addr) &&
820 tcm_is_in(pt, i->area)) { 804 tcm_is_in(pt, i->area)) {
821 i->refs++; 805 i->refs++;
822 goto found; 806 goto found;
@@ -833,7 +817,7 @@ found:
833static void fill_block_info(struct mem_info *i, struct tiler_block_info *blk) 817static void fill_block_info(struct mem_info *i, struct tiler_block_info *blk)
834{ 818{
835 blk->ptr = NULL; 819 blk->ptr = NULL;
836 blk->fmt = TILER_GET_ACC_MODE(i->blk.phys); 820 blk->fmt = tiler_fmt(i->blk.phys);
837 blk->ssptr = i->blk.phys; 821 blk->ssptr = i->blk.phys;
838 822
839 if (blk->fmt == TILFMT_PAGE) { 823 if (blk->fmt == TILFMT_PAGE) {
@@ -863,6 +847,7 @@ static struct mem_info *__get_area(enum tiler_fmt fmt, u32 width, u32 height,
863 u16 x, y, band, in_offs = 0; 847 u16 x, y, band, in_offs = 0;
864 struct mem_info *mi = NULL; 848 struct mem_info *mi = NULL;
865 struct tiler_view_orient orient = {0}; 849 struct tiler_view_orient orient = {0};
850 const struct tiler_geom *g = tiler.geom(fmt);
866 851
867 /* calculate dimensions, band, offs and alignment in slots */ 852 /* calculate dimensions, band, offs and alignment in slots */
868 if (__analize_area(fmt, width, height, &x, &y, &band, &align, &offs, 853 if (__analize_area(fmt, width, height, &x, &y, &band, &align, &offs,
@@ -876,7 +861,7 @@ static struct mem_info *__get_area(enum tiler_fmt fmt, u32 width, u32 height,
876 return NULL; 861 return NULL;
877 memset(mi, 0x0, sizeof(*mi)); 862 memset(mi, 0x0, sizeof(*mi));
878 863
879 if (tcm_reserve_1d(TCM(fmt), x * y, &mi->area)) { 864 if (tcm_reserve_1d(tcm[fmt], x * y, &mi->area)) {
880 kfree(mi); 865 kfree(mi);
881 return NULL; 866 return NULL;
882 } 867 }
@@ -885,7 +870,7 @@ static struct mem_info *__get_area(enum tiler_fmt fmt, u32 width, u32 height,
885 mi->parent = gi; 870 mi->parent = gi;
886 list_add(&mi->by_area, &gi->onedim); 871 list_add(&mi->by_area, &gi->onedim);
887 } else { 872 } else {
888 mi = get_2d_area(x, y, align, offs, band, gi, TCM(fmt)); 873 mi = get_2d_area(x, y, align, offs, band, gi, tcm[fmt]);
889 if (!mi) 874 if (!mi)
890 return NULL; 875 return NULL;
891 876
@@ -899,10 +884,7 @@ static struct mem_info *__get_area(enum tiler_fmt fmt, u32 width, u32 height,
899 mutex_unlock(&mtx); 884 mutex_unlock(&mtx);
900 885
901 mi->blk.phys = tiler.addr(orient, fmt, 886 mi->blk.phys = tiler.addr(orient, fmt,
902 mi->area.p0.x * (fmt == TILFMT_PAGE ? 1 : 887 mi->area.p0.x * g->slot_w, mi->area.p0.y * g->slot_h)
903 fmt == TILFMT_32BIT ? 32 : 64),
904 mi->area.p0.y * (fmt == TILFMT_PAGE ? 1 :
905 fmt == TILFMT_8BIT ? 64 : 32))
906 + TILER_ALIAS_BASE + in_offs; 888 + TILER_ALIAS_BASE + in_offs;
907 return mi; 889 return mi;
908} 890}
@@ -950,10 +932,10 @@ static s32 alloc_block(enum tiler_fmt fmt, u32 width, u32 height,
950 } 932 }
951 933
952 /* allocate and map if mapping is supported */ 934 /* allocate and map if mapping is supported */
953 if (tmm_can_map(TMM(fmt))) { 935 if (tmm_can_map(tmm[fmt])) {
954 mi->num_pg = tcm_sizeof(mi->area); 936 mi->num_pg = tcm_sizeof(mi->area);
955 937
956 mi->mem = tmm_get(TMM(fmt), mi->num_pg); 938 mi->mem = tmm_get(tmm[fmt], mi->num_pg);
957 if (!mi->mem) 939 if (!mi->mem)
958 goto cleanup; 940 goto cleanup;
959 941
@@ -961,7 +943,7 @@ static s32 alloc_block(enum tiler_fmt fmt, u32 width, u32 height,
961 wmb(); 943 wmb();
962 944
963 /* program PAT */ 945 /* program PAT */
964 if (refill_pat(TMM(fmt), &mi->area, mi->mem)) 946 if (refill_pat(tmm[fmt], &mi->area, mi->mem))
965 goto cleanup; 947 goto cleanup;
966 } 948 }
967 *info = mi; 949 *info = mi;
@@ -996,7 +978,7 @@ static s32 map_block(enum tiler_fmt fmt, u32 width, u32 height,
996 return -EPERM; 978 return -EPERM;
997 979
998 /* check if mapping is supported by tmm */ 980 /* check if mapping is supported by tmm */
999 if (!tmm_can_map(TMM(fmt))) 981 if (!tmm_can_map(tmm[fmt]))
1000 return -EPERM; 982 return -EPERM;
1001 983
1002 /* get group context */ 984 /* get group context */
@@ -1092,7 +1074,7 @@ static s32 map_block(enum tiler_fmt fmt, u32 width, u32 height,
1092 /* Ensure the data reaches to main memory before PAT refill */ 1074 /* Ensure the data reaches to main memory before PAT refill */
1093 wmb(); 1075 wmb();
1094 1076
1095 if (refill_pat(TMM(fmt), &mi->area, mem)) 1077 if (refill_pat(tmm[fmt], &mi->area, mem))
1096 goto fault; 1078 goto fault;
1097 1079
1098 res = 0; 1080 res = 0;
@@ -1150,23 +1132,23 @@ static s32 __init tiler_init(void)
1150 return -EINVAL; 1132 return -EINVAL;
1151 1133
1152 /* Allocate tiler container manager (we share 1 on OMAP4) */ 1134 /* Allocate tiler container manager (we share 1 on OMAP4) */
1153 div_pt.x = TILER_WIDTH; /* hardcoded default */ 1135 div_pt.x = tiler.width; /* hardcoded default */
1154 div_pt.y = (3 * TILER_HEIGHT) / 4; 1136 div_pt.y = (3 * tiler.height) / 4;
1155 sita = sita_init(TILER_WIDTH, TILER_HEIGHT, (void *)&div_pt); 1137 sita = sita_init(tiler.width, tiler.height, (void *)&div_pt);
1156 1138
1157 TCM_SET(TILFMT_8BIT, sita); 1139 tcm[TILFMT_8BIT] = sita;
1158 TCM_SET(TILFMT_16BIT, sita); 1140 tcm[TILFMT_16BIT] = sita;
1159 TCM_SET(TILFMT_32BIT, sita); 1141 tcm[TILFMT_32BIT] = sita;
1160 TCM_SET(TILFMT_PAGE, sita); 1142 tcm[TILFMT_PAGE] = sita;
1161 1143
1162 /* Allocate tiler memory manager (must have 1 unique TMM per TCM ) */ 1144 /* Allocate tiler memory manager (must have 1 unique TMM per TCM ) */
1163 tmm_pat = tmm_pat_init(0); 1145 tmm_pat = tmm_pat_init(0);
1164 TMM_SET(TILFMT_8BIT, tmm_pat); 1146 tmm[TILFMT_8BIT] = tmm_pat;
1165 TMM_SET(TILFMT_16BIT, tmm_pat); 1147 tmm[TILFMT_16BIT] = tmm_pat;
1166 TMM_SET(TILFMT_32BIT, tmm_pat); 1148 tmm[TILFMT_32BIT] = tmm_pat;
1167 TMM_SET(TILFMT_PAGE, tmm_pat); 1149 tmm[TILFMT_PAGE] = tmm_pat;
1168 1150
1169 tiler.nv12_packed = TCM(TILFMT_8BIT) == TCM(TILFMT_16BIT); 1151 tiler.nv12_packed = tcm[TILFMT_8BIT] == tcm[TILFMT_16BIT];
1170 1152
1171 tiler_device = kmalloc(sizeof(*tiler_device), GFP_KERNEL); 1153 tiler_device = kmalloc(sizeof(*tiler_device), GFP_KERNEL);
1172 if (!tiler_device || !sita || !tmm_pat) { 1154 if (!tiler_device || !sita || !tmm_pat) {
@@ -1237,16 +1219,16 @@ static void __exit tiler_exit(void)
1237 mutex_unlock(&mtx); 1219 mutex_unlock(&mtx);
1238 1220
1239 /* close containers only once */ 1221 /* close containers only once */
1240 for (i = TILFMT_8BIT; i <= TILFMT_MAX; i++) { 1222 for (i = TILFMT_MIN; i <= TILFMT_MAX; i++) {
1241 /* remove identical containers (tmm is unique per tcm) */ 1223 /* remove identical containers (tmm is unique per tcm) */
1242 for (j = i + 1; j <= TILFMT_MAX; j++) 1224 for (j = i + 1; j <= TILFMT_MAX; j++)
1243 if (TCM(i) == TCM(j)) { 1225 if (tcm[i] == tcm[j]) {
1244 TCM_SET(j, NULL); 1226 tcm[j] = NULL;
1245 TMM_SET(j, NULL); 1227 tmm[j] = NULL;
1246 } 1228 }
1247 1229
1248 tcm_deinit(TCM(i)); 1230 tcm_deinit(tcm[i]);
1249 tmm_deinit(TMM(i)); 1231 tmm_deinit(tmm[i]);
1250 } 1232 }
1251 1233
1252 mutex_destroy(&mtx); 1234 mutex_destroy(&mtx);
diff --git a/drivers/media/video/tiler/tiler-reserve.c b/drivers/media/video/tiler/tiler-reserve.c
index 1ca4cec82f8..fd3e1734f4b 100644
--- a/drivers/media/video/tiler/tiler-reserve.c
+++ b/drivers/media/video/tiler/tiler-reserve.c
@@ -22,6 +22,8 @@
22#include "_tiler.h" 22#include "_tiler.h"
23 23
24static struct tiler_ops *ops; 24static struct tiler_ops *ops;
25static int band_8; /* 8-bit band in slots */
26static int band_16; /* 16-bit band in slots */
25 27
26/* TILER is designed so that a (w * h) * 8bit area is twice as wide as a 28/* TILER is designed so that a (w * h) * 8bit area is twice as wide as a
27 (w/2 * h/2) * 16bit area. Since having pairs of such 8-bit and 16-bit 29 (w/2 * h/2) * 16bit area. Since having pairs of such 8-bit and 16-bit
@@ -60,7 +62,7 @@ static u32 tiler_best2pack(u16 o, u16 w, u16 e, u16 b, u16 *n, u16 *area)
60 * == align(o + (n-1) * e + w, b) - trim((o + (n-1) * e, b) for all n 62 * == align(o + (n-1) * e + w, b) - trim((o + (n-1) * e, b) for all n
61 */ 63 */
62 while (m < max_n && 64 while (m < max_n &&
63 o + m * e + w <= TILER_WIDTH && 65 o + m * e + w <= ops->width &&
64 stride == ALIGN(ar - o - m * e, b)) { 66 stride == ALIGN(ar - o - m * e, b)) {
65 /* get efficiency */ 67 /* get efficiency */
66 m++; 68 m++;
@@ -84,8 +86,8 @@ static u32 tiler_best2pack(u16 o, u16 w, u16 e, u16 b, u16 *n, u16 *area)
84/* assumptions: w > 0, o < a, 2 <= a */ 86/* assumptions: w > 0, o < a, 2 <= a */
85static u16 nv12_separate(u16 o, u16 w, u16 a, u16 n, u16 *area) 87static u16 nv12_separate(u16 o, u16 w, u16 a, u16 n, u16 *area)
86{ 88{
87 tiler_best2pack(o, w, ALIGN(w, a), 64, &n, area); 89 tiler_best2pack(o, w, ALIGN(w, a), band_8, &n, area);
88 tiler_best2pack(o / 2, (w + 1) / 2, ALIGN(w, a) / 2, 32, &n, area); 90 tiler_best2pack(o / 2, (w + 1) / 2, ALIGN(w, a) / 2, band_16, &n, area);
89 *area *= 3; 91 *area *= 3;
90 return n; 92 return n;
91} 93}
@@ -104,7 +106,7 @@ static u16 nv12_separate(u16 o, u16 w, u16 a, u16 n, u16 *area)
104static int nv12_A(u16 o, u16 w, u16 a, u16 *area, u16 n, u8 *p) 106static int nv12_A(u16 o, u16 w, u16 a, u16 *area, u16 n, u8 *p)
105{ 107{
106 u16 x = o, u, l, m = 0; 108 u16 x = o, u, l, m = 0;
107 *area = 64; 109 *area = band_8;
108 110
109 while (x + w < *area && m < n) { 111 while (x + w < *area && m < n) {
110 /* current 8bit upper bound (a) is next 8bit lower bound (B) */ 112 /* current 8bit upper bound (a) is next 8bit lower bound (B) */
@@ -149,7 +151,7 @@ static int nv12_B(u16 o, u16 w, u16 a, u16 *area, u16 n, u8 *p)
149 u16 o2 = o1 + (a >> 2); /* 2nd half offset */ 151 u16 o2 = o1 + (a >> 2); /* 2nd half offset */
150 u16 e2 = e1 + (a >> 2); /* 2nd half end offset */ 152 u16 e2 = e1 + (a >> 2); /* 2nd half end offset */
151 u16 m = 0; 153 u16 m = 0;
152 *area = 64; 154 *area = band_8;
153 155
154 /* ensure 16-bit blocks don't overlap 8-bit blocks */ 156 /* ensure 16-bit blocks don't overlap 8-bit blocks */
155 157
@@ -171,7 +173,7 @@ static int nv12_C(u16 o, u16 w, u16 a, u16 *area, u16 n, u8 *p)
171{ 173{
172 int m = 0; 174 int m = 0;
173 u16 o2, e = ALIGN(w, a), i = 0, j = 0; 175 u16 o2, e = ALIGN(w, a), i = 0, j = 0;
174 *area = 64; 176 *area = band_8;
175 o2 = *area - (a - (o + w) % a) % a; /* end of last possible block */ 177 o2 = *area - (a - (o + w) % a) % a; /* end of last possible block */
176 178
177 m = (min(o2 - 2 * o, 2 * o2 - o - *area) / 3 - w) / e + 1; 179 m = (min(o2 - 2 * o, 2 * o2 - o - *area) / 3 - w) / e + 1;
@@ -191,11 +193,11 @@ static int nv12_C(u16 o, u16 w, u16 a, u16 *area, u16 n, u8 *p)
191static int nv12_D(u16 o, u16 w, u16 a, u16 *area, u16 n, u8 *p) 193static int nv12_D(u16 o, u16 w, u16 a, u16 *area, u16 n, u8 *p)
192{ 194{
193 u16 o1, w1 = (w + 1) >> 1, d; 195 u16 o1, w1 = (w + 1) >> 1, d;
194 *area = ALIGN(o + w, 64); 196 *area = ALIGN(o + w, band_8);
195 197
196 for (d = 0; n > 0 && d + o + w <= *area; d += a) { 198 for (d = 0; n > 0 && d + o + w <= *area; d += a) {
197 /* fit 16-bit before 8-bit */ 199 /* fit 16-bit before 8-bit */
198 o1 = ((o + d) % 64) >> 1; 200 o1 = ((o + d) % band_8) >> 1;
199 if (o1 + w1 <= o + d) { 201 if (o1 + w1 <= o + d) {
200 *p++ = o + d; 202 *p++ = o + d;
201 *p++ = o1; 203 *p++ = o1;
@@ -203,7 +205,7 @@ static int nv12_D(u16 o, u16 w, u16 a, u16 *area, u16 n, u8 *p)
203 } 205 }
204 206
205 /* fit 16-bit after 8-bit */ 207 /* fit 16-bit after 8-bit */
206 o1 += ALIGN(d + o + w - o1, 32); 208 o1 += ALIGN(d + o + w - o1, band_16);
207 if (o1 + w1 <= *area) { 209 if (o1 + w1 <= *area) {
208 *p++ = o; 210 *p++ = o;
209 *p++ = o1; 211 *p++ = o1;
@@ -310,19 +312,21 @@ static u16 nv12_together(u16 o, u16 w, u16 a, u16 n, u16 *area, u8 *packing)
310static void reserve_nv12(u32 n, u32 width, u32 height, u32 align, u32 offs, 312static void reserve_nv12(u32 n, u32 width, u32 height, u32 align, u32 offs,
311 u32 gid, struct process_info *pi, bool can_together) 313 u32 gid, struct process_info *pi, bool can_together)
312{ 314{
313 /* adjust alignment to at least 128 bytes (16-bit slot width) */ 315 u16 w, h, band, a = align, o = offs, eff_w;
314 u16 w, h, band, a = MAX(128, align), o = offs, eff_w;
315 struct gid_info *gi; 316 struct gid_info *gi;
316 int res = 0, res2, i; 317 int res = 0, res2, i;
317 u16 n_t, n_s, area_t, area_s; 318 u16 n_t, n_s, area_t, area_s;
318 u8 packing[2 * 21]; 319 u8 packing[2 * 21];
319 struct list_head reserved = LIST_HEAD_INIT(reserved); 320 struct list_head reserved = LIST_HEAD_INIT(reserved);
320 321
322 /* adjust alignment to the largest slot width (128 bytes) */
323 a = MAX(PAGE_SIZE / MIN(band_8, band_16), a);
324
321 /* Check input parameters for correctness, and support */ 325 /* Check input parameters for correctness, and support */
322 if (!width || !height || !n || 326 if (!width || !height || !n ||
323 offs >= align || offs & 1 || 327 offs >= align || offs & 1 ||
324 align >= PAGE_SIZE || 328 align >= PAGE_SIZE ||
325 n > TILER_WIDTH * TILER_HEIGHT / 2) 329 n > ops->width * ops->height / 2)
326 return; 330 return;
327 331
328 /* calculate dimensions, band, offs and alignment in slots */ 332 /* calculate dimensions, band, offs and alignment in slots */
@@ -389,9 +393,10 @@ static void reserve_blocks(u32 n, enum tiler_fmt fmt, u32 width, u32 height,
389 u32 align, u32 offs, u32 gid, 393 u32 align, u32 offs, u32 gid,
390 struct process_info *pi) 394 struct process_info *pi)
391{ 395{
392 u32 til_width, bpp, bpt, res = 0, i; 396 u32 bpt, res = 0, i;
393 u16 o = offs, a = align, band, w, h, e, n_try; 397 u16 o = offs, a = align, band, w, h, e, n_try;
394 struct gid_info *gi; 398 struct gid_info *gi;
399 const struct tiler_geom *g;
395 400
396 /* Check input parameters for correctness, and support */ 401 /* Check input parameters for correctness, and support */
397 if (!width || !height || !n || 402 if (!width || !height || !n ||
@@ -400,14 +405,13 @@ static void reserve_blocks(u32 n, enum tiler_fmt fmt, u32 width, u32 height,
400 return; 405 return;
401 406
402 /* tiler page width in pixels, bytes per pixel, tiler page in bytes */ 407 /* tiler page width in pixels, bytes per pixel, tiler page in bytes */
403 til_width = fmt == TILFMT_32BIT ? 32 : 64; 408 g = ops->geom(fmt);
404 bpp = 1 << (fmt - TILFMT_8BIT); 409 bpt = g->slot_w * g->bpp;
405 bpt = til_width * bpp;
406 410
407 /* check offset. Also, if block is less than half the mapping window, 411 /* check offset. Also, if block is less than half the mapping window,
408 the default allocation is sufficient. Also check for basic area 412 the default allocation is sufficient. Also check for basic area
409 info. */ 413 info. */
410 if (width * bpp * 2 <= PAGE_SIZE || 414 if (width * g->bpp * 2 <= PAGE_SIZE ||
411 ops->analize(fmt, width, height, &w, &h, &band, &a, &o, NULL)) 415 ops->analize(fmt, width, height, &w, &h, &band, &a, &o, NULL))
412 return; 416 return;
413 417
@@ -421,7 +425,7 @@ static void reserve_blocks(u32 n, enum tiler_fmt fmt, u32 width, u32 height,
421 425
422 for (i = 0; i < n && res >= 0; i += res) { 426 for (i = 0; i < n && res >= 0; i += res) {
423 /* blocks to allocate in one area */ 427 /* blocks to allocate in one area */
424 n_try = MIN(n - i, TILER_WIDTH); 428 n_try = MIN(n - i, ops->width);
425 tiler_best2pack(offs, w, e, band, &n_try, NULL); 429 tiler_best2pack(offs, w, e, band, &n_try, NULL);
426 430
427 res = -1; 431 res = -1;
@@ -460,4 +464,8 @@ void tiler_reserve_init(struct tiler_ops *tiler)
460 ops->reserve_nv12 = reserve_nv12; 464 ops->reserve_nv12 = reserve_nv12;
461 ops->reserve = reserve_blocks; 465 ops->reserve = reserve_blocks;
462 ops->unreserve = unreserve_blocks; 466 ops->unreserve = unreserve_blocks;
467
468 band_8 = PAGE_SIZE / ops->geom(TILFMT_8BIT)->slot_w;
469 band_16 = PAGE_SIZE / ops->geom(TILFMT_16BIT)->slot_w
470 / ops->geom(TILFMT_16BIT)->bpp;
463} 471}