summaryrefslogtreecommitdiff
path: root/src/host1x.h
blob: 27d3839da5e68939456b5004e117cad39d013e4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*
 * Copyright (c) 2012, 2013 Erik Faye-Lund
 * Copyright (c) 2013 Avionic Design GmbH
 * Copyright (c) 2013 Thierry Reding
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

#ifndef HOST1X_H
#define HOST1X_H

#define FLOAT_TO_FIXED_6_12(fp) \
    (((int32_t) (fp * 4096.0f + 0.5f)) & ((1 << 18) - 1))

#define FLOAT_TO_FIXED_s2_7(fp) \
    (((fp < 0.0f) << 9) | (((int32_t) (fabs(fp) * 128.0f)) & ((1 << 9) - 1)))

#define FLOAT_TO_FIXED_s1_7(fp) \
    (((fp < 0.0f) << 8) | (((int32_t) (fabs(fp) * 128.0f)) & ((1 << 8) - 1)))

#define FLOAT_TO_FIXED_0_8(fp) \
    (((int32_t) (fp * 256.0f + 0.5f)) & ((1 << 8) - 1))

#define HOST1X_OPCODE_SETCL(offset, classid, mask) \
    ((0x0 << 28) | (((offset) & 0xfff) << 16) | (((classid) & 0x3ff) << 6) | ((mask) & 0x3f))
#define HOST1X_OPCODE_INCR(offset, count) \
    ((0x1 << 28) | (((offset) & 0xfff) << 16) | ((count) & 0xffff))
#define HOST1X_OPCODE_NONINCR(offset, count) \
    ((0x2 << 28) | (((offset) & 0xfff) << 16) | ((count) & 0xffff))
#define HOST1X_OPCODE_MASK(offset, mask) \
    ((0x3 << 28) | (((offset) & 0xfff) << 16) | ((mask) & 0xffff))
#define HOST1X_OPCODE_IMM(offset, data) \
    ((0x4 << 28) | (((offset) & 0xfff) << 16) | ((data) & 0xffff))
#define HOST1X_OPCODE_EXTEND(subop, value) \
    ((0xe << 28) | (((subop) & 0xf) << 24) | ((value) & 0xffffff))

#define HOST1X_CLASS_GR2D       0x51
#define HOST1X_CLASS_GR2D_SB    0x52

#define host1x_error(fmt, args...) \
    fprintf(stderr, "ERROR: %s: %d: " fmt, __func__, __LINE__, ##args)

#define PIX_BUF_FMT(id, bpp, planes_nb) \
    ((planes_nb) << 16 | (id) << 8 | (bpp))

#define PIX_BUF_FORMAT_BITS(f) \
    ((f) & 0xff)

#define PIX_BUF_FORMAT_BYTES(f) \
    (PIX_BUF_FORMAT_BITS(f) >> 3)

#define PIX_BUF_FORMAT_PLANES_NB(f) \
    (((f) >> 16) & 3)

enum pixel_format {
    PIX_BUF_FMT_A8            = PIX_BUF_FMT(0, 8, 1),
    PIX_BUF_FMT_L8            = PIX_BUF_FMT(1, 8, 1),
    PIX_BUF_FMT_S8            = PIX_BUF_FMT(2, 8, 1),
    PIX_BUF_FMT_LA88          = PIX_BUF_FMT(3, 16, 1),
    PIX_BUF_FMT_RGB565        = PIX_BUF_FMT(4, 16, 1),
    PIX_BUF_FMT_RGBA5551      = PIX_BUF_FMT(5, 16, 1),
    PIX_BUF_FMT_RGBA4444      = PIX_BUF_FMT(6, 16, 1),
    PIX_BUF_FMT_D16_LINEAR    = PIX_BUF_FMT(7, 16, 1),
    PIX_BUF_FMT_D16_NONLINEAR = PIX_BUF_FMT(8, 16, 1),
    PIX_BUF_FMT_RGBA8888      = PIX_BUF_FMT(9, 32, 1),
    PIX_BUF_FMT_RGBA_FP32     = PIX_BUF_FMT(10, 32, 1),
    PIX_BUF_FMT_ARGB8888      = PIX_BUF_FMT(11, 32, 1),
    PIX_BUF_FMT_ABGR8888      = PIX_BUF_FMT(12, 32, 1),
    PIX_BUF_FMT_YV12          = PIX_BUF_FMT(13, 8, 3),
};

enum layout_format {
    PIX_BUF_LAYOUT_LINEAR,
    PIX_BUF_LAYOUT_TILED_16x16,
};

struct host1x_csc_params {
    uint32_t yos, cvr, cub;
    uint32_t cyx, cur, cug;
    uint32_t cvb, cvg;
};

extern struct host1x_csc_params csc_rgb_default;

struct host1x_pixelbuffer {
    union {
        struct drm_tegra_bo *bo;
        struct drm_tegra_bo *bos[3];
    };
    enum pixel_format format;
    enum layout_format layout;
    unsigned width;
    unsigned height;
    unsigned pitch;
    unsigned pitch_uv;
    uint32_t guard_offset[3];
    uint32_t bo_offset[3];
    bool guard_enabled;
};

#define PIXBUF_GUARD_AREA_SIZE    0x4000

struct host1x_pixelbuffer *host1x_pixelbuffer_create(struct drm_tegra *drm,
                                                     unsigned width,
                                                     unsigned height,
                                                     unsigned pitch,
                                                     unsigned pitch_uv,
                                                     enum pixel_format format,
                                                     enum layout_format layout);

struct host1x_pixelbuffer *host1x_pixelbuffer_wrap(struct drm_tegra_bo **bos,
                                                   unsigned width,
                                                   unsigned height,
                                                   unsigned pitch,
                                                   unsigned pitch_uv,
                                                   enum pixel_format format,
                                                   enum layout_format layout);

void host1x_pixelbuffer_free(struct host1x_pixelbuffer *pixbuf);

int host1x_pixelbuffer_load_data(struct drm_tegra *drm,
                                 struct tegra_stream *stream,
                                 struct host1x_pixelbuffer *pixbuf,
                                 void *data,
                                 unsigned data_pitch,
                                 unsigned long data_size,
                                 enum pixel_format data_format,
                                 enum layout_format data_layout);

int host1x_pixelbuffer_setup_guard(struct host1x_pixelbuffer *pixbuf);

int host1x_pixelbuffer_check_guard(struct host1x_pixelbuffer *pixbuf);

void host1x_pixelbuffer_disable_bo_guard(void);

int host1x_gr2d_clear(struct tegra_stream *stream,
                      struct host1x_pixelbuffer *pixbuf,
                      uint32_t color);

int host1x_gr2d_clear_rect(struct tegra_stream *stream,
                           struct host1x_pixelbuffer *pixbuf,
                           uint32_t color,
                           unsigned x, unsigned y,
                           unsigned width, unsigned height);

int host1x_gr2d_clear_rect_clipped(struct tegra_stream *stream,
                                   struct host1x_pixelbuffer *pixbuf,
                                   uint32_t color,
                                   unsigned x, unsigned y,
                                   unsigned width, unsigned height,
                                   unsigned clip_x0, unsigned clip_y0,
                                   unsigned clip_x1, unsigned clip_y1,
                                   bool draw_outside);

int host1x_gr2d_blit(struct tegra_stream *stream,
                     struct host1x_pixelbuffer *src,
                     struct host1x_pixelbuffer *dst,
                     unsigned int sx, unsigned int sy,
                     unsigned int dx, unsigned int dy,
                     unsigned int width, int height);

int host1x_gr2d_surface_blit(struct tegra_stream *stream,
                             struct host1x_pixelbuffer *src,
                             struct host1x_pixelbuffer *dst,
                             struct host1x_csc_params *csc,
                             unsigned int sx, unsigned int sy,
                             unsigned int src_width, unsigned int src_height,
                             unsigned int dx, unsigned int dy,
                             unsigned int dst_width, int dst_height);
#endif