nv04.c 5.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * Copyright 2012 Red Hat Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 * Authors: Ben Skeggs
 */
24
#include "nv04.h"
25

26 27
#include <core/ramht.h>

28 29 30 31 32
/******************************************************************************
 * instmem object implementation
 *****************************************************************************/

static u32
33
nv04_instobj_rd32(struct nvkm_object *object, u64 addr)
34
{
B
Ben Skeggs 已提交
35 36 37
	struct nv04_instmem *imem = (void *)nvkm_instmem(object);
	struct nv04_instobj *node = (void *)object;
	return nv_ro32(imem, node->mem->offset + addr);
38 39 40
}

static void
41
nv04_instobj_wr32(struct nvkm_object *object, u64 addr, u32 data)
42
{
B
Ben Skeggs 已提交
43 44 45
	struct nv04_instmem *imem = (void *)nvkm_instmem(object);
	struct nv04_instobj *node = (void *)object;
	nv_wo32(imem, node->mem->offset + addr, data);
46 47 48
}

static void
49
nv04_instobj_dtor(struct nvkm_object *object)
50
{
B
Ben Skeggs 已提交
51 52 53 54 55
	struct nv04_instmem *imem = (void *)nvkm_instmem(object);
	struct nv04_instobj *node = (void *)object;
	mutex_lock(&imem->base.subdev.mutex);
	nvkm_mm_free(&imem->heap, &node->mem);
	mutex_unlock(&imem->base.subdev.mutex);
56
	nvkm_instobj_destroy(&node->base);
57 58
}

59
static int
60 61 62
nv04_instobj_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
		  struct nvkm_oclass *oclass, void *data, u32 size,
		  struct nvkm_object **pobject)
63
{
B
Ben Skeggs 已提交
64 65
	struct nv04_instmem *imem = (void *)nvkm_instmem(parent);
	struct nv04_instobj *node;
66
	struct nvkm_instobj_args *args = data;
67
	int ret;
68

69 70
	if (!args->align)
		args->align = 1;
71

72
	ret = nvkm_instobj_create(parent, engine, oclass, &node);
73 74 75 76
	*pobject = nv_object(node);
	if (ret)
		return ret;

B
Ben Skeggs 已提交
77 78
	mutex_lock(&imem->base.subdev.mutex);
	ret = nvkm_mm_head(&imem->heap, 0, 1, args->size, args->size,
79
			   args->align, &node->mem);
B
Ben Skeggs 已提交
80
	mutex_unlock(&imem->base.subdev.mutex);
81 82 83 84 85 86 87 88
	if (ret)
		return ret;

	node->base.addr = node->mem->offset;
	node->base.size = node->mem->length;
	return 0;
}

89
struct nvkm_instobj_impl
90
nv04_instobj_oclass = {
91
	.base.ofuncs = &(struct nvkm_ofuncs) {
92 93
		.ctor = nv04_instobj_ctor,
		.dtor = nv04_instobj_dtor,
94 95
		.init = _nvkm_instobj_init,
		.fini = _nvkm_instobj_fini,
96 97 98 99 100
		.rd32 = nv04_instobj_rd32,
		.wr32 = nv04_instobj_wr32,
	},
};

101 102 103 104 105
/******************************************************************************
 * instmem subdev implementation
 *****************************************************************************/

static u32
106
nv04_instmem_rd32(struct nvkm_object *object, u64 addr)
107
{
108 109
	return nv_rd32(object, 0x700000 + addr);
}
110

111
static void
112
nv04_instmem_wr32(struct nvkm_object *object, u64 addr, u32 data)
113 114 115
{
	return nv_wr32(object, 0x700000 + addr, data);
}
116

117
void
118
nv04_instmem_dtor(struct nvkm_object *object)
119
{
B
Ben Skeggs 已提交
120 121 122 123 124 125 126 127 128
	struct nv04_instmem *imem = (void *)object;
	nvkm_gpuobj_ref(NULL, &imem->ramfc);
	nvkm_gpuobj_ref(NULL, &imem->ramro);
	nvkm_ramht_ref(NULL, &imem->ramht);
	nvkm_gpuobj_ref(NULL, &imem->vbios);
	nvkm_mm_fini(&imem->heap);
	if (imem->iomem)
		iounmap(imem->iomem);
	nvkm_instmem_destroy(&imem->base);
129
}
130

131
static int
132 133 134
nv04_instmem_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
		  struct nvkm_oclass *oclass, void *data, u32 size,
		  struct nvkm_object **pobject)
135
{
B
Ben Skeggs 已提交
136
	struct nv04_instmem *imem;
137
	int ret;
138

B
Ben Skeggs 已提交
139 140
	ret = nvkm_instmem_create(parent, engine, oclass, &imem);
	*pobject = nv_object(imem);
141 142 143
	if (ret)
		return ret;

144
	/* PRAMIN aperture maps over the end of VRAM, reserve it */
B
Ben Skeggs 已提交
145
	imem->base.reserved = 512 * 1024;
146

B
Ben Skeggs 已提交
147
	ret = nvkm_mm_init(&imem->heap, 0, imem->base.reserved, 1);
148 149 150
	if (ret)
		return ret;

151
	/* 0x00000-0x10000: reserve for probable vbios image */
B
Ben Skeggs 已提交
152 153
	ret = nvkm_gpuobj_new(nv_object(imem), NULL, 0x10000, 0, 0,
			      &imem->vbios);
154 155 156
	if (ret)
		return ret;

157
	/* 0x10000-0x18000: reserve for RAMHT */
B
Ben Skeggs 已提交
158
	ret = nvkm_ramht_new(nv_object(imem), NULL, 0x08000, 0, &imem->ramht);
159 160 161
	if (ret)
		return ret;

162
	/* 0x18000-0x18800: reserve for RAMFC (enough for 32 nv30 channels) */
B
Ben Skeggs 已提交
163 164
	ret = nvkm_gpuobj_new(nv_object(imem), NULL, 0x00800, 0,
			      NVOBJ_FLAG_ZERO_ALLOC, &imem->ramfc);
165 166
	if (ret)
		return ret;
167

168
	/* 0x18800-0x18a00: reserve for RAMRO */
B
Ben Skeggs 已提交
169 170
	ret = nvkm_gpuobj_new(nv_object(imem), NULL, 0x00200, 0, 0,
			      &imem->ramro);
171
	if (ret)
172
		return ret;
173

174
	return 0;
175 176
}

177 178
struct nvkm_oclass *
nv04_instmem_oclass = &(struct nvkm_instmem_impl) {
179
	.base.handle = NV_SUBDEV(INSTMEM, 0x04),
180
	.base.ofuncs = &(struct nvkm_ofuncs) {
181 182
		.ctor = nv04_instmem_ctor,
		.dtor = nv04_instmem_dtor,
183 184
		.init = _nvkm_instmem_init,
		.fini = _nvkm_instmem_fini,
185 186 187
		.rd32 = nv04_instmem_rd32,
		.wr32 = nv04_instmem_wr32,
	},
188
	.instobj = &nv04_instobj_oclass.base,
189
}.base;