Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ramht.c
Go to the documentation of this file.
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 #include <core/math.h>
26 
27 #include <subdev/bar.h>
28 
29 static u32
30 nouveau_ramht_hash(struct nouveau_ramht *ramht, int chid, u32 handle)
31 {
32  u32 hash = 0;
33 
34  while (handle) {
35  hash ^= (handle & ((1 << ramht->bits) - 1));
36  handle >>= ramht->bits;
37  }
38 
39  hash ^= chid << (ramht->bits - 4);
40  hash = hash << 3;
41  return hash;
42 }
43 
44 int
45 nouveau_ramht_insert(struct nouveau_ramht *ramht, int chid,
47 {
48  struct nouveau_bar *bar = nouveau_bar(ramht);
49  u32 co, ho;
50 
51  co = ho = nouveau_ramht_hash(ramht, chid, handle);
52  do {
53  if (!nv_ro32(ramht, co + 4)) {
54  nv_wo32(ramht, co + 0, handle);
55  nv_wo32(ramht, co + 4, context);
56  if (bar)
57  bar->flush(bar);
58  return co;
59  }
60 
61  co += 8;
62  if (co >= nv_gpuobj(ramht)->size)
63  co = 0;
64  } while (co != ho);
65 
66  return -ENOMEM;
67 }
68 
69 void
71 {
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);
77 }
78 
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 };
91 
92 int
93 nouveau_ramht_new(struct nouveau_object *parent, struct nouveau_object *pargpu,
94  u32 size, u32 align, struct nouveau_ramht **pramht)
95 {
96  struct nouveau_ramht *ramht;
97  int ret;
98 
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);
103  *pramht = ramht;
104  if (ret)
105  return ret;
106 
107  ramht->bits = log2i(nv_gpuobj(ramht)->size >> 3);
108  return 0;
109 }