Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
nv50.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  * Authors: Ben Skeggs
23  */
24 
25 #include <subdev/instmem.h>
26 #include <subdev/fb.h>
27 
28 #include <core/mm.h>
29 
34 };
35 
38  struct nouveau_mem *mem;
39 };
40 
41 static int
42 nv50_instobj_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
43  struct nouveau_oclass *oclass, void *data, u32 size,
44  struct nouveau_object **pobject)
45 {
46  struct nouveau_fb *pfb = nouveau_fb(parent);
47  struct nv50_instobj_priv *node;
48  u32 align = (unsigned long)data;
49  int ret;
50 
51  size = max((size + 4095) & ~4095, (u32)4096);
52  align = max((align + 4095) & ~4095, (u32)4096);
53 
54  ret = nouveau_instobj_create(parent, engine, oclass, &node);
55  *pobject = nv_object(node);
56  if (ret)
57  return ret;
58 
59  ret = pfb->ram.get(pfb, size, align, 0, 0x800, &node->mem);
60  if (ret)
61  return ret;
62 
63  node->base.addr = node->mem->offset;
64  node->base.size = node->mem->size << 12;
65  node->mem->page_shift = 12;
66  return 0;
67 }
68 
69 static void
70 nv50_instobj_dtor(struct nouveau_object *object)
71 {
72  struct nv50_instobj_priv *node = (void *)object;
73  struct nouveau_fb *pfb = nouveau_fb(object);
74  pfb->ram.put(pfb, &node->mem);
76 }
77 
78 static u32
79 nv50_instobj_rd32(struct nouveau_object *object, u32 offset)
80 {
81  struct nv50_instmem_priv *priv = (void *)object->engine;
82  struct nv50_instobj_priv *node = (void *)object;
83  unsigned long flags;
84  u64 base = (node->mem->offset + offset) & 0xffffff00000ULL;
85  u64 addr = (node->mem->offset + offset) & 0x000000fffffULL;
86  u32 data;
87 
88  spin_lock_irqsave(&priv->lock, flags);
89  if (unlikely(priv->addr != base)) {
90  nv_wr32(priv, 0x001700, base >> 16);
91  priv->addr = base;
92  }
93  data = nv_rd32(priv, 0x700000 + addr);
94  spin_unlock_irqrestore(&priv->lock, flags);
95  return data;
96 }
97 
98 static void
99 nv50_instobj_wr32(struct nouveau_object *object, u32 offset, u32 data)
100 {
101  struct nv50_instmem_priv *priv = (void *)object->engine;
102  struct nv50_instobj_priv *node = (void *)object;
103  unsigned long flags;
104  u64 base = (node->mem->offset + offset) & 0xffffff00000ULL;
105  u64 addr = (node->mem->offset + offset) & 0x000000fffffULL;
106 
107  spin_lock_irqsave(&priv->lock, flags);
108  if (unlikely(priv->addr != base)) {
109  nv_wr32(priv, 0x001700, base >> 16);
110  priv->addr = base;
111  }
112  nv_wr32(priv, 0x700000 + addr, data);
113  spin_unlock_irqrestore(&priv->lock, flags);
114 }
115 
116 static struct nouveau_oclass
117 nv50_instobj_oclass = {
118  .ofuncs = &(struct nouveau_ofuncs) {
119  .ctor = nv50_instobj_ctor,
120  .dtor = nv50_instobj_dtor,
121  .init = _nouveau_instobj_init,
122  .fini = _nouveau_instobj_fini,
123  .rd32 = nv50_instobj_rd32,
124  .wr32 = nv50_instobj_wr32,
125  },
126 };
127 
128 static int
129 nv50_instmem_alloc(struct nouveau_instmem *imem, struct nouveau_object *parent,
130  u32 size, u32 align, struct nouveau_object **pobject)
131 {
132  struct nouveau_object *engine = nv_object(imem);
133  return nouveau_object_ctor(parent, engine, &nv50_instobj_oclass,
134  (void *)(unsigned long)align, size, pobject);
135 }
136 
137 static int
138 nv50_instmem_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
139  struct nouveau_oclass *oclass, void *data, u32 size,
140  struct nouveau_object **pobject)
141 {
142  struct nv50_instmem_priv *priv;
143  int ret;
144 
145  ret = nouveau_instmem_create(parent, engine, oclass, &priv);
146  *pobject = nv_object(priv);
147  if (ret)
148  return ret;
149 
150  spin_lock_init(&priv->lock);
151  priv->base.alloc = nv50_instmem_alloc;
152  return 0;
153 }
154 
155 static int
156 nv50_instmem_fini(struct nouveau_object *object, bool suspend)
157 {
158  struct nv50_instmem_priv *priv = (void *)object;
159  priv->addr = ~0ULL;
160  return nouveau_instmem_fini(&priv->base, suspend);
161 }
162 
163 struct nouveau_oclass
165  .handle = NV_SUBDEV(INSTMEM, 0x50),
166  .ofuncs = &(struct nouveau_ofuncs) {
167  .ctor = nv50_instmem_ctor,
168  .dtor = _nouveau_instmem_dtor,
169  .init = _nouveau_instmem_init,
170  .fini = nv50_instmem_fini,
171  },
172 };