Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 94 lines (88 sloc) 2.993 kB
85bf736 @koriakin Add RAMHT bits.
koriakin authored
1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2010 PathScale Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 #include "drm.h"
28 #include "nouveau_drv.h"
29 #include "pscnv_ramht.h"
6a325d0 @koriakin vm: Move engine struct to pscnv_vm.h
koriakin authored
30 #include "pscnv_vm.h"
85bf736 @koriakin Add RAMHT bits.
koriakin authored
31
32 uint32_t pscnv_ramht_hash(struct pscnv_ramht *ramht, uint32_t handle) {
33 uint32_t hash = 0;
7e3f067 @koriakin ramht: Fix hash function
koriakin authored
34 while (handle) {
85bf736 @koriakin Add RAMHT bits.
koriakin authored
35 hash ^= handle & ((1 << ramht->bits) - 1);
36 handle >>= ramht->bits;
37 }
38 return hash;
39 }
40
41 int pscnv_ramht_insert(struct pscnv_ramht *ramht, uint32_t handle, uint32_t context) {
42 /* XXX: check if the object exists already... */
3375d31 @koriakin vram: Split to pscnv_vram and pscnv_mem, vo -> bo everywhere.
koriakin authored
43 struct drm_nouveau_private *dev_priv = ramht->bo->dev->dev_private;
85bf736 @koriakin Add RAMHT bits.
koriakin authored
44 uint32_t hash = pscnv_ramht_hash(ramht, handle);
45 uint32_t start = hash * 8;
46 uint32_t pos = start;
227d6d8 @koriakin vm, ramht: Use a module option for enabling debug.
koriakin authored
47 if (pscnv_ramht_debug >= 2)
3375d31 @koriakin vram: Split to pscnv_vram and pscnv_mem, vo -> bo everywhere.
koriakin authored
48 NV_INFO(ramht->bo->dev, "Handle %x hash %x\n", handle, hash);
85bf736 @koriakin Add RAMHT bits.
koriakin authored
49 spin_lock (&ramht->lock);
50 do {
3375d31 @koriakin vram: Split to pscnv_vram and pscnv_mem, vo -> bo everywhere.
koriakin authored
51 if (!nv_rv32(ramht->bo, ramht->offset + pos + 4)) {
52 nv_wv32(ramht->bo, ramht->offset + pos, handle);
53 nv_wv32(ramht->bo, ramht->offset + pos + 4, context);
54 dev_priv->vm->bar_flush(ramht->bo->dev);
85bf736 @koriakin Add RAMHT bits.
koriakin authored
55 spin_unlock (&ramht->lock);
227d6d8 @koriakin vm, ramht: Use a module option for enabling debug.
koriakin authored
56 if (pscnv_ramht_debug >= 1)
3375d31 @koriakin vram: Split to pscnv_vram and pscnv_mem, vo -> bo everywhere.
koriakin authored
57 NV_INFO(ramht->bo->dev, "Adding RAMHT entry for object %x at %x, context %x\n", handle, pos, context);
85bf736 @koriakin Add RAMHT bits.
koriakin authored
58 return 0;
59 }
60 pos += 8;
61 if (pos == 8 << ramht->bits)
62 pos = 0;
63 } while (pos != start);
64 spin_unlock (&ramht->lock);
3375d31 @koriakin vram: Split to pscnv_vram and pscnv_mem, vo -> bo everywhere.
koriakin authored
65 NV_ERROR(ramht->bo->dev, "No RAMHT space for object %x\n", handle);
85bf736 @koriakin Add RAMHT bits.
koriakin authored
66 return -ENOMEM;
67 }
59994c4 @koriakin ramht: Add find function.
koriakin authored
68
69 uint32_t pscnv_ramht_find(struct pscnv_ramht *ramht, uint32_t handle) {
70 /* XXX: do this properly. */
71 uint32_t hash = pscnv_ramht_hash(ramht, handle);
72 uint32_t start = hash * 8;
73 uint32_t pos = start;
74 uint32_t res;
227d6d8 @koriakin vm, ramht: Use a module option for enabling debug.
koriakin authored
75 if (pscnv_ramht_debug >= 2)
3375d31 @koriakin vram: Split to pscnv_vram and pscnv_mem, vo -> bo everywhere.
koriakin authored
76 NV_INFO(ramht->bo->dev, "Handle %x hash %x\n", handle, hash);
59994c4 @koriakin ramht: Add find function.
koriakin authored
77 spin_lock (&ramht->lock);
78 do {
3375d31 @koriakin vram: Split to pscnv_vram and pscnv_mem, vo -> bo everywhere.
koriakin authored
79 if (!nv_rv32(ramht->bo, ramht->offset + pos + 4))
59994c4 @koriakin ramht: Add find function.
koriakin authored
80 break;
3375d31 @koriakin vram: Split to pscnv_vram and pscnv_mem, vo -> bo everywhere.
koriakin authored
81 if (nv_rv32(ramht->bo, ramht->offset + pos) == handle) {
82 res = nv_rv32(ramht->bo, ramht->offset + pos + 4);
59994c4 @koriakin ramht: Add find function.
koriakin authored
83 spin_unlock (&ramht->lock);
84 return res;
85 }
86 pos += 8;
87 if (pos == 8 << ramht->bits)
88 pos = 0;
89 } while (pos != start);
90 spin_unlock (&ramht->lock);
3375d31 @koriakin vram: Split to pscnv_vram and pscnv_mem, vo -> bo everywhere.
koriakin authored
91 NV_ERROR(ramht->bo->dev, "RAMHT object %x not found\n", handle);
59994c4 @koriakin ramht: Add find function.
koriakin authored
92 return 0;
93 }
Something went wrong with that request. Please try again.