2 * Copyright © 2014 NVIDIA Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
30 #include "drm-test-tegra.h"
33 int drm_tegra_gr2d_open(struct drm_tegra
*drm
, struct drm_tegra_gr2d
**gr2dp
)
35 struct drm_tegra_gr2d
*gr2d
;
38 gr2d
= calloc(1, sizeof(*gr2d
));
44 err
= drm_tegra_channel_open(drm
, DRM_TEGRA_GR2D
, &gr2d
->channel
);
55 int drm_tegra_gr2d_close(struct drm_tegra_gr2d
*gr2d
)
60 drm_tegra_channel_close(gr2d
->channel
);
66 int drm_tegra_gr2d_fill(struct drm_tegra_gr2d
*gr2d
, struct drm_framebuffer
*fb
,
67 unsigned int x
, unsigned int y
, unsigned int width
,
68 unsigned int height
, uint32_t color
)
70 struct drm_tegra_bo
*fbo
= fb
->data
;
71 struct drm_tegra_pushbuf
*pushbuf
;
72 struct drm_tegra_mapping
*map
;
73 struct drm_tegra_job
*job
;
77 err
= drm_tegra_job_new(gr2d
->channel
, &job
);
81 err
= drm_tegra_channel_map(gr2d
->channel
, fbo
, 0, &map
);
85 err
= drm_tegra_job_get_pushbuf(job
, &pushbuf
);
89 err
= drm_tegra_pushbuf_begin(pushbuf
, 32, &ptr
);
93 *ptr
++ = HOST1X_OPCODE_SETCL(0, HOST1X_CLASS_GR2D
, 0);
95 *ptr
++ = HOST1X_OPCODE_MASK(0x9, 0x9);
99 *ptr
++ = HOST1X_OPCODE_MASK(0x1e, 0x7);
101 *ptr
++ = (2 << 16) | (1 << 6) | (1 << 2);
104 *ptr
++ = HOST1X_OPCODE_MASK(0x2b, 0x9);
106 /* relocate destination buffer */
107 err
= drm_tegra_pushbuf_relocate(pushbuf
, &ptr
, map
, 0, 0, 0);
109 fprintf(stderr
, "failed to relocate buffer object: %d\n", err
);
115 *ptr
++ = HOST1X_OPCODE_NONINCR(0x35, 1);
118 *ptr
++ = HOST1X_OPCODE_NONINCR(0x46, 1);
121 *ptr
++ = HOST1X_OPCODE_MASK(0x38, 0x5);
122 *ptr
++ = height
<< 16 | width
;
123 *ptr
++ = y
<< 16 | x
;
125 err
= drm_tegra_pushbuf_end(pushbuf
, ptr
);
127 fprintf(stderr
, "failed to update push buffer: %d\n", -err
);
131 err
= drm_tegra_job_submit(job
, NULL
);
133 fprintf(stderr
, "failed to submit job: %d\n", err
);
137 err
= drm_tegra_job_wait(job
, 0);
139 fprintf(stderr
, "failed to wait for fence: %d\n", err
);
143 drm_tegra_channel_unmap(map
);
144 drm_tegra_job_free(job
);