| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: drm_vma_manager.c,v 1.1 2014/07/16 20:56:25 riastradh Exp $ */ | | 1 | /* $NetBSD: drm_vma_manager.c,v 1.2 2015/03/02 17:34:23 riastradh Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2014 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2014 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Taylor R. Campbell. | | 8 | * by Taylor R. Campbell. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -20,27 +20,27 @@ | | | @@ -20,27 +20,27 @@ |
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | * POSSIBILITY OF SUCH DAMAGE. | | 29 | * POSSIBILITY OF SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | #include <sys/cdefs.h> | | 32 | #include <sys/cdefs.h> |
33 | __KERNEL_RCSID(0, "$NetBSD: drm_vma_manager.c,v 1.1 2014/07/16 20:56:25 riastradh Exp $"); | | 33 | __KERNEL_RCSID(0, "$NetBSD: drm_vma_manager.c,v 1.2 2015/03/02 17:34:23 riastradh Exp $"); |
34 | | | 34 | |
35 | #include <sys/kmem.h> | | 35 | #include <sys/kmem.h> |
36 | #include <sys/rbtree.h> | | 36 | #include <sys/rbtree.h> |
37 | #include <sys/vmem.h> | | 37 | #include <sys/vmem.h> |
38 | | | 38 | |
39 | #include <drm/drm_vma_manager.h> | | 39 | #include <drm/drm_vma_manager.h> |
40 | | | 40 | |
41 | static int | | 41 | static int |
42 | drm_vma_node_compare(void *cookie __unused, const void *va, const void *vb) | | 42 | drm_vma_node_compare(void *cookie __unused, const void *va, const void *vb) |
43 | { | | 43 | { |
44 | const struct drm_vma_offset_node *const na = va; | | 44 | const struct drm_vma_offset_node *const na = va; |
45 | const struct drm_vma_offset_node *const nb = vb; | | 45 | const struct drm_vma_offset_node *const nb = vb; |
46 | | | 46 | |
| @@ -154,31 +154,34 @@ drm_vma_node_destroy(struct drm_vma_offs | | | @@ -154,31 +154,34 @@ drm_vma_node_destroy(struct drm_vma_offs |
154 | int | | 154 | int |
155 | drm_vma_offset_add(struct drm_vma_offset_manager *mgr, | | 155 | drm_vma_offset_add(struct drm_vma_offset_manager *mgr, |
156 | struct drm_vma_offset_node *node, unsigned long npages) | | 156 | struct drm_vma_offset_node *node, unsigned long npages) |
157 | { | | 157 | { |
158 | vmem_size_t startpage; | | 158 | vmem_size_t startpage; |
159 | struct drm_vma_offset_node *collision __diagused; | | 159 | struct drm_vma_offset_node *collision __diagused; |
160 | int error; | | 160 | int error; |
161 | | | 161 | |
162 | KASSERT(npages != 0); | | 162 | KASSERT(npages != 0); |
163 | | | 163 | |
164 | if (0 < node->von_npages) | | 164 | if (0 < node->von_npages) |
165 | return 0; | | 165 | return 0; |
166 | | | 166 | |
167 | error = vmem_alloc(mgr->vom_vmem, npages, VM_SLEEP|VM_BESTFIT, | | 167 | error = vmem_alloc(mgr->vom_vmem, npages, VM_NOSLEEP|VM_BESTFIT, |
168 | &startpage); | | 168 | &startpage); |
169 | if (error) | | 169 | if (error) { |
| | | 170 | if (error == ENOMEM) |
| | | 171 | error = ENOSPC; |
170 | /* XXX errno NetBSD->Linux */ | | 172 | /* XXX errno NetBSD->Linux */ |
171 | return -error; | | 173 | return -error; |
| | | 174 | } |
172 | | | 175 | |
173 | node->von_startpage = startpage; | | 176 | node->von_startpage = startpage; |
174 | node->von_npages = npages; | | 177 | node->von_npages = npages; |
175 | | | 178 | |
176 | rw_enter(&node->von_lock, RW_WRITER); | | 179 | rw_enter(&node->von_lock, RW_WRITER); |
177 | collision = rb_tree_insert_node(&mgr->vom_nodes, node); | | 180 | collision = rb_tree_insert_node(&mgr->vom_nodes, node); |
178 | KASSERT(collision == node); | | 181 | KASSERT(collision == node); |
179 | rw_exit(&node->von_lock); | | 182 | rw_exit(&node->von_lock); |
180 | | | 183 | |
181 | return 0; | | 184 | return 0; |
182 | } | | 185 | } |
183 | | | 186 | |
184 | void | | 187 | void |