• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/fb.h>
26 
27 #include "nv04.h"
28 
29 static int
nv04_instobj_ctor(struct nouveau_object * parent,struct nouveau_object * engine,struct nouveau_oclass * oclass,void * data,u32 size,struct nouveau_object ** pobject)30 nv04_instobj_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
31 		  struct nouveau_oclass *oclass, void *data, u32 size,
32 		  struct nouveau_object **pobject)
33 {
34 	struct nv04_instmem_priv *priv = (void *)engine;
35 	struct nv04_instobj_priv *node;
36 	int ret, align;
37 
38 	align = (unsigned long)data;
39 	if (!align)
40 		align = 1;
41 
42 	ret = nouveau_instobj_create(parent, engine, oclass, &node);
43 	*pobject = nv_object(node);
44 	if (ret)
45 		return ret;
46 
47 	ret = nouveau_mm_head(&priv->heap, 1, size, size, align, &node->mem);
48 	if (ret)
49 		return ret;
50 
51 	node->base.addr = node->mem->offset;
52 	node->base.size = node->mem->length;
53 	return 0;
54 }
55 
56 static void
nv04_instobj_dtor(struct nouveau_object * object)57 nv04_instobj_dtor(struct nouveau_object *object)
58 {
59 	struct nv04_instmem_priv *priv = (void *)object->engine;
60 	struct nv04_instobj_priv *node = (void *)object;
61 	nouveau_mm_free(&priv->heap, &node->mem);
62 	nouveau_instobj_destroy(&node->base);
63 }
64 
65 static u32
nv04_instobj_rd32(struct nouveau_object * object,u64 addr)66 nv04_instobj_rd32(struct nouveau_object *object, u64 addr)
67 {
68 	struct nv04_instobj_priv *node = (void *)object;
69 	return nv_ro32(object->engine, node->mem->offset + addr);
70 }
71 
72 static void
nv04_instobj_wr32(struct nouveau_object * object,u64 addr,u32 data)73 nv04_instobj_wr32(struct nouveau_object *object, u64 addr, u32 data)
74 {
75 	struct nv04_instobj_priv *node = (void *)object;
76 	nv_wo32(object->engine, node->mem->offset + addr, data);
77 }
78 
79 static struct nouveau_oclass
80 nv04_instobj_oclass = {
81 	.ofuncs = &(struct nouveau_ofuncs) {
82 		.ctor = nv04_instobj_ctor,
83 		.dtor = nv04_instobj_dtor,
84 		.init = _nouveau_instobj_init,
85 		.fini = _nouveau_instobj_fini,
86 		.rd32 = nv04_instobj_rd32,
87 		.wr32 = nv04_instobj_wr32,
88 	},
89 };
90 
91 int
nv04_instmem_alloc(struct nouveau_instmem * imem,struct nouveau_object * parent,u32 size,u32 align,struct nouveau_object ** pobject)92 nv04_instmem_alloc(struct nouveau_instmem *imem, struct nouveau_object *parent,
93 		   u32 size, u32 align, struct nouveau_object **pobject)
94 {
95 	struct nouveau_object *engine = nv_object(imem);
96 	int ret;
97 
98 	ret = nouveau_object_ctor(parent, engine, &nv04_instobj_oclass,
99 				  (void *)(unsigned long)align, size, pobject);
100 	if (ret)
101 		return ret;
102 
103 	return 0;
104 }
105 
106 static int
nv04_instmem_ctor(struct nouveau_object * parent,struct nouveau_object * engine,struct nouveau_oclass * oclass,void * data,u32 size,struct nouveau_object ** pobject)107 nv04_instmem_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
108 		  struct nouveau_oclass *oclass, void *data, u32 size,
109 		  struct nouveau_object **pobject)
110 {
111 	struct nv04_instmem_priv *priv;
112 	int ret;
113 
114 	ret = nouveau_instmem_create(parent, engine, oclass, &priv);
115 	*pobject = nv_object(priv);
116 	if (ret)
117 		return ret;
118 
119 	/* PRAMIN aperture maps over the end of VRAM, reserve it */
120 	priv->base.reserved = 512 * 1024;
121 	priv->base.alloc    = nv04_instmem_alloc;
122 
123 	ret = nouveau_mm_init(&priv->heap, 0, priv->base.reserved, 1);
124 	if (ret)
125 		return ret;
126 
127 	/* 0x00000-0x10000: reserve for probable vbios image */
128 	ret = nouveau_gpuobj_new(nv_object(priv), NULL, 0x10000, 0, 0,
129 				&priv->vbios);
130 	if (ret)
131 		return ret;
132 
133 	/* 0x10000-0x18000: reserve for RAMHT */
134 	ret = nouveau_ramht_new(nv_object(priv), NULL, 0x08000, 0, &priv->ramht);
135 	if (ret)
136 		return ret;
137 
138 	/* 0x18000-0x18800: reserve for RAMFC (enough for 32 nv30 channels) */
139 	ret = nouveau_gpuobj_new(nv_object(priv), NULL, 0x00800, 0,
140 				 NVOBJ_FLAG_ZERO_ALLOC, &priv->ramfc);
141 	if (ret)
142 		return ret;
143 
144 	/* 0x18800-0x18a00: reserve for RAMRO */
145 	ret = nouveau_gpuobj_new(nv_object(priv), NULL, 0x00200, 0, 0,
146 				&priv->ramro);
147 	if (ret)
148 		return ret;
149 
150 	return 0;
151 }
152 
153 void
nv04_instmem_dtor(struct nouveau_object * object)154 nv04_instmem_dtor(struct nouveau_object *object)
155 {
156 	struct nv04_instmem_priv *priv = (void *)object;
157 	nouveau_gpuobj_ref(NULL, &priv->ramfc);
158 	nouveau_gpuobj_ref(NULL, &priv->ramro);
159 	nouveau_ramht_ref(NULL, &priv->ramht);
160 	nouveau_gpuobj_ref(NULL, &priv->vbios);
161 	nouveau_mm_fini(&priv->heap);
162 	if (priv->iomem)
163 		iounmap(priv->iomem);
164 	nouveau_instmem_destroy(&priv->base);
165 }
166 
167 static u32
nv04_instmem_rd32(struct nouveau_object * object,u64 addr)168 nv04_instmem_rd32(struct nouveau_object *object, u64 addr)
169 {
170 	return nv_rd32(object, 0x700000 + addr);
171 }
172 
173 static void
nv04_instmem_wr32(struct nouveau_object * object,u64 addr,u32 data)174 nv04_instmem_wr32(struct nouveau_object *object, u64 addr, u32 data)
175 {
176 	return nv_wr32(object, 0x700000 + addr, data);
177 }
178 
179 struct nouveau_oclass
180 nv04_instmem_oclass = {
181 	.handle = NV_SUBDEV(INSTMEM, 0x04),
182 	.ofuncs = &(struct nouveau_ofuncs) {
183 		.ctor = nv04_instmem_ctor,
184 		.dtor = nv04_instmem_dtor,
185 		.init = _nouveau_instmem_init,
186 		.fini = _nouveau_instmem_fini,
187 		.rd32 = nv04_instmem_rd32,
188 		.wr32 = nv04_instmem_wr32,
189 	},
190 };
191