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.
25 #include <subdev/fb.h>
30 struct nv50_instmem_priv {
31 struct nouveau_instmem base;
36 struct nv50_instobj_priv {
37 struct nouveau_instobj base;
38 struct nouveau_mem *mem;
41 /******************************************************************************
42 * instmem object implementation
43 *****************************************************************************/
46 nv50_instobj_rd32(struct nouveau_object *object, u64 offset)
48 struct nv50_instmem_priv *priv = (void *)object->engine;
49 struct nv50_instobj_priv *node = (void *)object;
51 u64 base = (node->mem->offset + offset) & 0xffffff00000ULL;
52 u64 addr = (node->mem->offset + offset) & 0x000000fffffULL;
55 spin_lock_irqsave(&priv->lock, flags);
56 if (unlikely(priv->addr != base)) {
57 nv_wr32(priv, 0x001700, base >> 16);
60 data = nv_rd32(priv, 0x700000 + addr);
61 spin_unlock_irqrestore(&priv->lock, flags);
66 nv50_instobj_wr32(struct nouveau_object *object, u64 offset, u32 data)
68 struct nv50_instmem_priv *priv = (void *)object->engine;
69 struct nv50_instobj_priv *node = (void *)object;
71 u64 base = (node->mem->offset + offset) & 0xffffff00000ULL;
72 u64 addr = (node->mem->offset + offset) & 0x000000fffffULL;
74 spin_lock_irqsave(&priv->lock, flags);
75 if (unlikely(priv->addr != base)) {
76 nv_wr32(priv, 0x001700, base >> 16);
79 nv_wr32(priv, 0x700000 + addr, data);
80 spin_unlock_irqrestore(&priv->lock, flags);
84 nv50_instobj_dtor(struct nouveau_object *object)
86 struct nv50_instobj_priv *node = (void *)object;
87 struct nouveau_fb *pfb = nouveau_fb(object);
88 pfb->ram->put(pfb, &node->mem);
89 nouveau_instobj_destroy(&node->base);
93 nv50_instobj_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
94 struct nouveau_oclass *oclass, void *data, u32 size,
95 struct nouveau_object **pobject)
97 struct nouveau_fb *pfb = nouveau_fb(parent);
98 struct nouveau_instobj_args *args = data;
99 struct nv50_instobj_priv *node;
102 args->size = max((args->size + 4095) & ~4095, (u32)4096);
103 args->align = max((args->align + 4095) & ~4095, (u32)4096);
105 ret = nouveau_instobj_create(parent, engine, oclass, &node);
106 *pobject = nv_object(node);
110 ret = pfb->ram->get(pfb, args->size, args->align, 0, 0x800, &node->mem);
114 node->base.addr = node->mem->offset;
115 node->base.size = node->mem->size << 12;
116 node->mem->page_shift = 12;
120 static struct nouveau_instobj_impl
121 nv50_instobj_oclass = {
122 .base.ofuncs = &(struct nouveau_ofuncs) {
123 .ctor = nv50_instobj_ctor,
124 .dtor = nv50_instobj_dtor,
125 .init = _nouveau_instobj_init,
126 .fini = _nouveau_instobj_fini,
127 .rd32 = nv50_instobj_rd32,
128 .wr32 = nv50_instobj_wr32,
132 /******************************************************************************
133 * instmem subdev implementation
134 *****************************************************************************/
137 nv50_instmem_fini(struct nouveau_object *object, bool suspend)
139 struct nv50_instmem_priv *priv = (void *)object;
141 return nouveau_instmem_fini(&priv->base, suspend);
145 nv50_instmem_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
146 struct nouveau_oclass *oclass, void *data, u32 size,
147 struct nouveau_object **pobject)
149 struct nv50_instmem_priv *priv;
152 ret = nouveau_instmem_create(parent, engine, oclass, &priv);
153 *pobject = nv_object(priv);
157 spin_lock_init(&priv->lock);
161 struct nouveau_oclass *
162 nv50_instmem_oclass = &(struct nouveau_instmem_impl) {
163 .base.handle = NV_SUBDEV(INSTMEM, 0x50),
164 .base.ofuncs = &(struct nouveau_ofuncs) {
165 .ctor = nv50_instmem_ctor,
166 .dtor = _nouveau_instmem_dtor,
167 .init = _nouveau_instmem_init,
168 .fini = nv50_instmem_fini,
170 .instobj = &nv50_instobj_oclass.base,