Loading...
Note: File does not exist in v6.9.4.
1// SPDX-License-Identifier: MIT
2/*
3 * Copyright © 2019 Intel Corporation
4 */
5
6#include "i915_active.h"
7#include "intel_context.h"
8#include "intel_context_param.h"
9#include "intel_ring.h"
10
11int intel_context_set_ring_size(struct intel_context *ce, long sz)
12{
13 int err;
14
15 if (intel_context_lock_pinned(ce))
16 return -EINTR;
17
18 err = i915_active_wait(&ce->active);
19 if (err < 0)
20 goto unlock;
21
22 if (intel_context_is_pinned(ce)) {
23 err = -EBUSY; /* In active use, come back later! */
24 goto unlock;
25 }
26
27 if (test_bit(CONTEXT_ALLOC_BIT, &ce->flags)) {
28 struct intel_ring *ring;
29
30 /* Replace the existing ringbuffer */
31 ring = intel_engine_create_ring(ce->engine, sz);
32 if (IS_ERR(ring)) {
33 err = PTR_ERR(ring);
34 goto unlock;
35 }
36
37 intel_ring_put(ce->ring);
38 ce->ring = ring;
39
40 /* Context image will be updated on next pin */
41 } else {
42 ce->ring = __intel_context_ring_size(sz);
43 }
44
45unlock:
46 intel_context_unlock_pinned(ce);
47 return err;
48}
49
50long intel_context_get_ring_size(struct intel_context *ce)
51{
52 long sz = (unsigned long)READ_ONCE(ce->ring);
53
54 if (test_bit(CONTEXT_ALLOC_BIT, &ce->flags)) {
55 if (intel_context_lock_pinned(ce))
56 return -EINTR;
57
58 sz = ce->ring->size;
59 intel_context_unlock_pinned(ce);
60 }
61
62 return sz;
63}