Commit | Line | Data |
---|---|---|
f64122c1 DA |
1 | /* |
2 | * Copyright 2013 Red Hat Inc. | |
3 | * | |
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: | |
10 | * | |
11 | * The above copyright notice and this permission notice shall be included in | |
12 | * all copies or substantial portions of the Software. | |
13 | * | |
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. | |
21 | * | |
22 | * Authors: Dave Airlie | |
23 | * Alon Levy | |
24 | */ | |
25 | ||
26 | ||
27 | #include "qxl_drv.h" | |
28 | ||
29 | /* QXL fencing- | |
30 | ||
31 | When we submit operations to the GPU we pass a release reference to the GPU | |
32 | with them, the release reference is then added to the release ring when | |
33 | the GPU is finished with that particular operation and has removed it from | |
34 | its tree. | |
35 | ||
36 | So we have can have multiple outstanding non linear fences per object. | |
37 | ||
38 | From a TTM POV we only care if the object has any outstanding releases on | |
39 | it. | |
40 | ||
41 | we wait until all outstanding releases are processeed. | |
42 | ||
43 | sync object is just a list of release ids that represent that fence on | |
44 | that buffer. | |
45 | ||
46 | we just add new releases onto the sync object attached to the object. | |
47 | ||
48 | This currently uses a radix tree to store the list of release ids. | |
49 | ||
50 | For some reason every so often qxl hw fails to release, things go wrong. | |
51 | */ | |
8002db63 DA |
52 | /* must be called with the fence lock held */ |
53 | void qxl_fence_add_release_locked(struct qxl_fence *qfence, uint32_t rel_id) | |
f64122c1 | 54 | { |
f64122c1 DA |
55 | radix_tree_insert(&qfence->tree, rel_id, qfence); |
56 | qfence->num_active_releases++; | |
f64122c1 DA |
57 | } |
58 | ||
59 | int qxl_fence_remove_release(struct qxl_fence *qfence, uint32_t rel_id) | |
60 | { | |
61 | void *ret; | |
62 | int retval = 0; | |
63 | struct qxl_bo *bo = container_of(qfence, struct qxl_bo, fence); | |
64 | ||
65 | spin_lock(&bo->tbo.bdev->fence_lock); | |
66 | ||
67 | ret = radix_tree_delete(&qfence->tree, rel_id); | |
68 | if (ret == qfence) | |
69 | qfence->num_active_releases--; | |
70 | else { | |
71 | DRM_DEBUG("didn't find fence in radix tree for %d\n", rel_id); | |
72 | retval = -ENOENT; | |
73 | } | |
74 | spin_unlock(&bo->tbo.bdev->fence_lock); | |
75 | return retval; | |
76 | } | |
77 | ||
78 | ||
79 | int qxl_fence_init(struct qxl_device *qdev, struct qxl_fence *qfence) | |
80 | { | |
81 | qfence->qdev = qdev; | |
82 | qfence->num_active_releases = 0; | |
83 | INIT_RADIX_TREE(&qfence->tree, GFP_ATOMIC); | |
84 | return 0; | |
85 | } | |
86 | ||
87 | void qxl_fence_fini(struct qxl_fence *qfence) | |
88 | { | |
89 | kfree(qfence->release_ids); | |
90 | qfence->num_active_releases = 0; | |
91 | } |