2 * Copyright 2012 Red Hat Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
23 #include <core/object.h>
24 #include <core/ramht.h>
25 #include <core/math.h>
27 #include <subdev/bar.h>
30 nouveau_ramht_hash(struct nouveau_ramht *ramht, int chid, u32 handle)
35 hash ^= (handle & ((1 << ramht->bits) - 1));
36 handle >>= ramht->bits;
39 hash ^= chid << (ramht->bits - 4);
45 nouveau_ramht_insert(struct nouveau_ramht *ramht, int chid,
46 u32 handle, u32 context)
48 struct nouveau_bar *bar = nouveau_bar(ramht);
51 co = ho = nouveau_ramht_hash(ramht, chid, handle);
53 if (!nv_ro32(ramht, co + 4)) {
54 nv_wo32(ramht, co + 0, handle);
55 nv_wo32(ramht, co + 4, context);
62 if (co >= nv_gpuobj(ramht)->size)
70 nouveau_ramht_remove(struct nouveau_ramht *ramht, int cookie)
72 struct nouveau_bar *bar = nouveau_bar(ramht);
73 nv_wo32(ramht, cookie + 0, 0x00000000);
74 nv_wo32(ramht, cookie + 4, 0x00000000);
79 static struct nouveau_oclass
80 nouveau_ramht_oclass = {
82 .ofuncs = &(struct nouveau_ofuncs) {
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,
93 nouveau_ramht_new(struct nouveau_object *parent, struct nouveau_object *pargpu,
94 u32 size, u32 align, struct nouveau_ramht **pramht)
96 struct nouveau_ramht *ramht;
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);
107 ramht->bits = log2i(nv_gpuobj(ramht)->size >> 3);