]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/omapdrm/omap_dmm_tiler.h
55ab284b075bad351ddfde83b3f0e26765b153b9
[karo-tx-linux.git] / drivers / staging / omapdrm / omap_dmm_tiler.h
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 <plat/cpu.h>
20 #include "omap_drv.h"
21 #include "tcm.h"
22
23 enum tiler_fmt {
24         TILFMT_8BIT = 0,
25         TILFMT_16BIT,
26         TILFMT_32BIT,
27         TILFMT_PAGE,
28         TILFMT_NFORMATS
29 };
30
31 struct pat_area {
32         u32 x0:8;
33         u32 y0:8;
34         u32 x1:8;
35         u32 y1:8;
36 };
37
38 struct tiler_block {
39         struct list_head alloc_node;    /* node for global block list */
40         struct tcm_area area;           /* area */
41         enum tiler_fmt fmt;             /* format */
42 };
43
44 /* bits representing the same slot in DMM-TILER hw-block */
45 #define SLOT_WIDTH_BITS         6
46 #define SLOT_HEIGHT_BITS        6
47
48 /* bits reserved to describe coordinates in DMM-TILER hw-block */
49 #define CONT_WIDTH_BITS         14
50 #define CONT_HEIGHT_BITS        13
51
52 /* calculated constants */
53 #define TILER_PAGE              (1 << (SLOT_WIDTH_BITS + SLOT_HEIGHT_BITS))
54 #define TILER_WIDTH             (1 << (CONT_WIDTH_BITS - SLOT_WIDTH_BITS))
55 #define TILER_HEIGHT            (1 << (CONT_HEIGHT_BITS - SLOT_HEIGHT_BITS))
56
57 /* tiler space addressing bitfields */
58 #define MASK_XY_FLIP            (1 << 31)
59 #define MASK_Y_INVERT           (1 << 30)
60 #define MASK_X_INVERT           (1 << 29)
61 #define SHIFT_ACC_MODE          27
62 #define MASK_ACC_MODE           3
63
64 #define MASK(bits) ((1 << (bits)) - 1)
65
66 #define TILVIEW_8BIT    0x60000000u
67 #define TILVIEW_16BIT   (TILVIEW_8BIT  + VIEW_SIZE)
68 #define TILVIEW_32BIT   (TILVIEW_16BIT + VIEW_SIZE)
69 #define TILVIEW_PAGE    (TILVIEW_32BIT + VIEW_SIZE)
70 #define TILVIEW_END     (TILVIEW_PAGE  + VIEW_SIZE)
71
72 /* create tsptr by adding view orientation and access mode */
73 #define TIL_ADDR(x, orient, a)\
74         ((u32) (x) | (orient) | ((a) << SHIFT_ACC_MODE))
75
76 /* externally accessible functions */
77 int omap_dmm_init(struct drm_device *dev);
78 int omap_dmm_remove(void);
79
80 #ifdef CONFIG_DEBUG_FS
81 int tiler_map_show(struct seq_file *s, void *arg);
82 #endif
83
84 /* pin/unpin */
85 int tiler_pin(struct tiler_block *block, struct page **pages,
86                 uint32_t npages, uint32_t roll, bool wait);
87 int tiler_unpin(struct tiler_block *block);
88
89 /* reserve/release */
90 struct tiler_block *tiler_reserve_2d(enum tiler_fmt fmt, uint16_t w, uint16_t h,
91                                 uint16_t align);
92 struct tiler_block *tiler_reserve_1d(size_t size);
93 int tiler_release(struct tiler_block *block);
94
95 /* utilities */
96 dma_addr_t tiler_ssptr(struct tiler_block *block);
97 uint32_t tiler_stride(enum tiler_fmt fmt);
98 size_t tiler_size(enum tiler_fmt fmt, uint16_t w, uint16_t h);
99 size_t tiler_vsize(enum tiler_fmt fmt, uint16_t w, uint16_t h);
100 void tiler_align(enum tiler_fmt fmt, uint16_t *w, uint16_t *h);
101
102
103 /* GEM bo flags -> tiler fmt */
104 static inline enum tiler_fmt gem2fmt(uint32_t flags)
105 {
106         switch (flags & OMAP_BO_TILED) {
107         case OMAP_BO_TILED_8:
108                 return TILFMT_8BIT;
109         case OMAP_BO_TILED_16:
110                 return TILFMT_16BIT;
111         case OMAP_BO_TILED_32:
112                 return TILFMT_32BIT;
113         default:
114                 return TILFMT_PAGE;
115         }
116 }
117
118 static inline bool validfmt(enum tiler_fmt fmt)
119 {
120         switch (fmt) {
121         case TILFMT_8BIT:
122         case TILFMT_16BIT:
123         case TILFMT_32BIT:
124         case TILFMT_PAGE:
125                 return true;
126         default:
127                 return false;
128         }
129 }
130
131 struct omap_dmm_platform_data {
132         void __iomem *base;
133         int irq;
134 };
135
136 static inline int dmm_is_available(void)
137 {
138         return cpu_is_omap44xx();
139 }
140
141 #endif