2
* Copyright © 2012 Intel 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 (including the next
12
* paragraph) shall be included in all copies or substantial portions of the
15
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24
* Ben Widawsky <ben@bwidawsk.net>
29
* Negative test cases:
30
* test we can't submit contexts to unsupported rings
43
#include <sys/ioctl.h>
50
struct local_drm_i915_gem_context_create {
55
#define CONTEXT_CREATE_IOCTL DRM_IOWR(DRM_COMMAND_BASE + 0x2d, struct local_drm_i915_gem_context_create)
57
static uint32_t context_create(int fd)
59
struct local_drm_i915_gem_context_create create;
62
ret = drmIoctl(fd, CONTEXT_CREATE_IOCTL, &create);
63
if (ret == -1 && (errno == ENODEV || errno == EINVAL)) {
72
/* Copied from gem_exec_nop.c */
73
static int exec(int fd, uint32_t handle, int ring, int ctx_id)
75
struct drm_i915_gem_execbuffer2 execbuf;
76
struct drm_i915_gem_exec_object2 gem_exec;
79
gem_exec.handle = handle;
80
gem_exec.relocation_count = 0;
81
gem_exec.relocs_ptr = 0;
82
gem_exec.alignment = 0;
88
execbuf.buffers_ptr = (uintptr_t)&gem_exec;
89
execbuf.buffer_count = 1;
90
execbuf.batch_start_offset = 0;
91
execbuf.batch_len = 8;
92
execbuf.cliprects_ptr = 0;
93
execbuf.num_cliprects = 0;
97
i915_execbuffer2_set_context_id(execbuf, ctx_id);
100
ret = drmIoctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2,
102
gem_sync(fd, handle);
107
#define MI_BATCH_BUFFER_END (0xA<<23)
108
int main(int argc, char *argv[])
111
uint32_t batch[2] = {MI_BATCH_BUFFER_END};
116
ctx_id = context_create(fd);
118
handle = gem_create(fd, 4096);
119
gem_write(fd, handle, 0, batch, sizeof(batch));
120
assert(exec(fd, handle, I915_EXEC_RENDER, ctx_id) == 0);
121
assert(exec(fd, handle, I915_EXEC_BSD, ctx_id) != 0);
122
assert(exec(fd, handle, I915_EXEC_BLT, ctx_id) != 0);