Commit | Line | Data |
---|---|---|
479dcaea | 1 | /* |
ebb945a9 | 2 | * Copyright 2012 Red Hat Inc. |
479dcaea BS |
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. | |
479dcaea BS |
21 | */ |
22 | ||
ebb945a9 | 23 | #include <core/object.h> |
02a841d4 | 24 | #include <core/ramht.h> |
ebb945a9 BS |
25 | #include <core/math.h> |
26 | ||
27 | #include <subdev/bar.h> | |
479dcaea | 28 | |
dac79008 | 29 | static u32 |
ebb945a9 | 30 | nouveau_ramht_hash(struct nouveau_ramht *ramht, int chid, u32 handle) |
479dcaea | 31 | { |
dac79008 | 32 | u32 hash = 0; |
479dcaea | 33 | |
ebb945a9 | 34 | while (handle) { |
e05c5a31 BS |
35 | hash ^= (handle & ((1 << ramht->bits) - 1)); |
36 | handle >>= ramht->bits; | |
479dcaea BS |
37 | } |
38 | ||
ebb945a9 BS |
39 | hash ^= chid << (ramht->bits - 4); |
40 | hash = hash << 3; | |
479dcaea BS |
41 | return hash; |
42 | } | |
43 | ||
479dcaea | 44 | int |
ebb945a9 BS |
45 | nouveau_ramht_insert(struct nouveau_ramht *ramht, int chid, |
46 | u32 handle, u32 context) | |
479dcaea | 47 | { |
ebb945a9 BS |
48 | struct nouveau_bar *bar = nouveau_bar(ramht); |
49 | u32 co, ho; | |
dac79008 | 50 | |
ebb945a9 | 51 | co = ho = nouveau_ramht_hash(ramht, chid, handle); |
479dcaea | 52 | do { |
ebb945a9 | 53 | if (!nv_ro32(ramht, co + 4)) { |
a8eaebc6 | 54 | nv_wo32(ramht, co + 0, handle); |
ebb945a9 BS |
55 | nv_wo32(ramht, co + 4, context); |
56 | if (bar) | |
57 | bar->flush(bar); | |
58 | return co; | |
479dcaea | 59 | } |
479dcaea BS |
60 | |
61 | co += 8; | |
ebb945a9 | 62 | if (co >= nv_gpuobj(ramht)->size) |
479dcaea BS |
63 | co = 0; |
64 | } while (co != ho); | |
65 | ||
479dcaea BS |
66 | return -ENOMEM; |
67 | } | |
68 | ||
ebb945a9 BS |
69 | void |
70 | nouveau_ramht_remove(struct nouveau_ramht *ramht, int cookie) | |
dac79008 | 71 | { |
ebb945a9 BS |
72 | struct nouveau_bar *bar = nouveau_bar(ramht); |
73 | nv_wo32(ramht, cookie + 0, 0x00000000); | |
74 | nv_wo32(ramht, cookie + 4, 0x00000000); | |
75 | if (bar) | |
76 | bar->flush(bar); | |
dac79008 BS |
77 | } |
78 | ||
ebb945a9 BS |
79 | static struct nouveau_oclass |
80 | nouveau_ramht_oclass = { | |
81 | .handle = 0x0000abcd, | |
82 | .ofuncs = &(struct nouveau_ofuncs) { | |
83 | .ctor = NULL, | |
84 | .dtor = _nouveau_gpuobj_dtor, | |
85 | .init = _nouveau_gpuobj_init, | |
86 | .fini = _nouveau_gpuobj_fini, | |
87 | .rd32 = _nouveau_gpuobj_rd32, | |
88 | .wr32 = _nouveau_gpuobj_wr32, | |
89 | }, | |
90 | }; | |
a8eaebc6 BS |
91 | |
92 | int | |
ebb945a9 BS |
93 | nouveau_ramht_new(struct nouveau_object *parent, struct nouveau_object *pargpu, |
94 | u32 size, u32 align, struct nouveau_ramht **pramht) | |
a8eaebc6 BS |
95 | { |
96 | struct nouveau_ramht *ramht; | |
ebb945a9 | 97 | int ret; |
a8eaebc6 | 98 | |
ebb945a9 BS |
99 | ret = nouveau_gpuobj_create(parent, parent->engine ? |
100 | parent->engine : parent, /* <nv50 ramht */ | |
101 | &nouveau_ramht_oclass, 0, pargpu, size, | |
102 | align, NVOBJ_FLAG_ZERO_ALLOC, &ramht); | |
a8eaebc6 | 103 | *pramht = ramht; |
ebb945a9 BS |
104 | if (ret) |
105 | return ret; | |
a8eaebc6 | 106 | |
ebb945a9 BS |
107 | ramht->bits = log2i(nv_gpuobj(ramht)->size >> 3); |
108 | return 0; | |
479dcaea | 109 | } |