21
#include "etnaviv_compat.h"
22
#include "etnaviv_cmdbuf.h"
23
#include "etnaviv_drv.h"
24
#include "etnaviv_gpu.h"
25
#include "etnaviv_gem.h"
26
#include "etnaviv_drm.h"
28
#include <embox_drm/drm_gem.h>
30
#define BO_INVALID_FLAGS ~(ETNA_SUBMIT_BO_READ | ETNA_SUBMIT_BO_WRITE)
32
#define BO_LOCKED 0x4000
33
#define BO_PINNED 0x2000
35
static struct etnaviv_gem_submit *submit_create(struct drm_device *dev,
36
struct etnaviv_gpu *gpu, size_t nr) {
39
static struct etnaviv_gem_submit submit;
40
memset(&submit, 0, sizeof(submit));
47
static int submit_lookup_objects(struct etnaviv_gem_submit *submit,
48
struct drm_file *file, struct drm_etnaviv_gem_submit_bo *submit_bos,
50
struct drm_etnaviv_gem_submit_bo *bo;
54
for (i = 0, bo = submit_bos; i < nr_bos; i++, bo++) {
55
struct drm_gem_object *obj;
57
if (bo->flags & BO_INVALID_FLAGS) {
58
DRM_ERROR("invalid flags: %x\n", bo->flags);
63
submit->bos[i].flags = bo->flags;
68
obj = idr_find(&file->object_idr, bo->handle);
70
DRM_ERROR("invalid handle %u at index %u\n",
80
submit->bos[i].obj = to_etnaviv_bo(obj);
89
static int submit_pin_objects(struct etnaviv_gem_submit *submit) {
92
for (i = 0; i < submit->nr_bos; i++) {
93
struct etnaviv_gem_object *etnaviv_obj = submit->bos[i].obj;
94
struct etnaviv_vram_mapping *mapping;
96
mapping = etnaviv_gem_mapping_get(&etnaviv_obj->base,
98
log_debug("map for %d is %p\n", i, mapping);
99
submit->bos[i].flags |= BO_PINNED;
100
submit->bos[i].mapping = mapping;
106
static int submit_bo(struct etnaviv_gem_submit *submit, uint32_t idx,
107
struct etnaviv_gem_submit_bo **bo) {
108
if (idx >= submit->nr_bos) {
109
DRM_ERROR("invalid buffer index: %u (out of %u)\n",
110
idx, submit->nr_bos);
111
submit->nr_bos = idx;
116
*bo = &submit->bos[idx];
122
static int submit_reloc(struct etnaviv_gem_submit *submit, void *stream,
123
uint32_t size, const struct drm_etnaviv_gem_submit_reloc *relocs,
126
uint32_t i, last_offset = 0;
127
uint32_t *ptr = stream;
130
for (i = 0; i < nr_relocs; i++) {
131
const struct drm_etnaviv_gem_submit_reloc *r = relocs + i;
132
struct etnaviv_gem_submit_bo *bo;
135
if (r->submit_offset % 4) {
136
DRM_ERROR("non-aligned reloc offset: %u\n",
142
off = r->submit_offset / 4;
144
if ((off >= size ) ||
145
(off < last_offset)) {
146
DRM_ERROR("invalid offset %u at reloc %u\n", off, i);
150
ret = submit_bo(submit, r->reloc_idx, &bo);
154
if (r->reloc_offset >= bo->obj->base.size - sizeof(*ptr)) {
155
DRM_ERROR("relocation %u outside object", i);
158
ptr[off] = bo->mapping->iova + (uint32_t) r->reloc_offset;
166
extern void etnaviv_buffer_dump(struct etnaviv_gpu *gpu,
167
struct etnaviv_cmdbuf *buf, uint32_t off, uint32_t len);
169
int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data, struct drm_file *file) {
170
struct etnaviv_drm_private *priv = dev->dev_private;
171
struct drm_etnaviv_gem_submit *args = data;
172
struct drm_etnaviv_gem_submit_reloc *relocs;
173
struct drm_etnaviv_gem_submit_bo *bos;
174
struct etnaviv_gem_submit *submit;
175
struct etnaviv_cmdbuf *cmdbuf;
176
struct etnaviv_gpu *gpu;
180
log_debug("Pipe is %d", args->pipe);
182
if (args->pipe >= ETNA_MAX_PIPES) {
186
gpu = priv->gpu[args->pipe];
191
if (args->stream_size % 4) {
192
log_error("non-aligned cmdstream buffer size: %u",
197
if (args->exec_state != ETNA_PIPE_3D &&
198
args->exec_state != ETNA_PIPE_2D &&
199
args->exec_state != ETNA_PIPE_VG) {
200
DRM_ERROR("invalid exec_state: 0x%x", args->exec_state);
208
bos = (void *) (uint32_t) args->bos;
209
relocs = (void *) (uint32_t) args->relocs;
210
cmdbuf = etnaviv_cmdbuf_new(gpu->cmdbuf_suballoc,
211
ALIGN(args->stream_size, 8) + 8,
214
log_error("smth is null bos %p relocs %p cmdbuf %p", bos, relocs, cmdbuf);
218
cmdbuf->exec_state = args->exec_state * 0;
219
cmdbuf->ctx = file->driver_priv;
221
stream = (void *) (int) args->stream;
222
submit = submit_create(dev, gpu, args->nr_bos);
230
if ((ret = submit_lookup_objects(submit, file, bos, args->nr_bos))) {
235
memcpy(cmdbuf->vaddr, stream, args->stream_size);
236
cmdbuf->user_size = ALIGN(args->stream_size, 8);
238
etnaviv_buffer_dump(gpu, cmdbuf, 0, cmdbuf->user_size);
240
if (!etnaviv_cmd_validate_one(gpu, stream, args->stream_size / 4,
241
relocs, args->nr_relocs)) {
245
if ((ret = submit_pin_objects(submit))) {
246
log_error("submit_pit_objects failed with %d", ret);
251
ret = submit_reloc(submit, stream, args->stream_size / 4,
252
relocs, args->nr_relocs);
254
log_error("submit_reloc fail");
259
memcpy(cmdbuf->vaddr, stream, args->stream_size);
260
cmdbuf->user_size = ALIGN(args->stream_size, 8);
262
return etnaviv_gpu_submit(gpu, submit, cmdbuf);