]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/gpu/drm/nouveau/core/core/ramht.c
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/iwlwifi/iwlwif...
[karo-tx-linux.git] / drivers / gpu / drm / nouveau / core / core / ramht.c
1 /*
2  * Copyright 2012 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
23 #include <core/object.h>
24 #include <core/ramht.h>
25
26 #include <subdev/bar.h>
27
28 static u32
29 nouveau_ramht_hash(struct nouveau_ramht *ramht, int chid, u32 handle)
30 {
31         u32 hash = 0;
32
33         while (handle) {
34                 hash ^= (handle & ((1 << ramht->bits) - 1));
35                 handle >>= ramht->bits;
36         }
37
38         hash ^= chid << (ramht->bits - 4);
39         hash  = hash << 3;
40         return hash;
41 }
42
43 int
44 nouveau_ramht_insert(struct nouveau_ramht *ramht, int chid,
45                      u32 handle, u32 context)
46 {
47         struct nouveau_bar *bar = nouveau_bar(ramht);
48         u32 co, ho;
49
50         co = ho = nouveau_ramht_hash(ramht, chid, handle);
51         do {
52                 if (!nv_ro32(ramht, co + 4)) {
53                         nv_wo32(ramht, co + 0, handle);
54                         nv_wo32(ramht, co + 4, context);
55                         if (bar)
56                                 bar->flush(bar);
57                         return co;
58                 }
59
60                 co += 8;
61                 if (co >= nv_gpuobj(ramht)->size)
62                         co = 0;
63         } while (co != ho);
64
65         return -ENOMEM;
66 }
67
68 void
69 nouveau_ramht_remove(struct nouveau_ramht *ramht, int cookie)
70 {
71         struct nouveau_bar *bar = nouveau_bar(ramht);
72         nv_wo32(ramht, cookie + 0, 0x00000000);
73         nv_wo32(ramht, cookie + 4, 0x00000000);
74         if (bar)
75                 bar->flush(bar);
76 }
77
78 static struct nouveau_oclass
79 nouveau_ramht_oclass = {
80         .handle = 0x0000abcd,
81         .ofuncs = &(struct nouveau_ofuncs) {
82                 .ctor = NULL,
83                 .dtor = _nouveau_gpuobj_dtor,
84                 .init = _nouveau_gpuobj_init,
85                 .fini = _nouveau_gpuobj_fini,
86                 .rd32 = _nouveau_gpuobj_rd32,
87                 .wr32 = _nouveau_gpuobj_wr32,
88         },
89 };
90
91 int
92 nouveau_ramht_new(struct nouveau_object *parent, struct nouveau_object *pargpu,
93                   u32 size, u32 align, struct nouveau_ramht **pramht)
94 {
95         struct nouveau_ramht *ramht;
96         int ret;
97
98         ret = nouveau_gpuobj_create(parent, parent->engine ?
99                                     parent->engine : parent, /* <nv50 ramht */
100                                     &nouveau_ramht_oclass, 0, pargpu, size,
101                                     align, NVOBJ_FLAG_ZERO_ALLOC, &ramht);
102         *pramht = ramht;
103         if (ret)
104                 return ret;
105
106         ramht->bits = order_base_2(nv_gpuobj(ramht)->size >> 3);
107         return 0;
108 }