gf100.c 3.7 KB
Newer Older
1
/*
2
 * Copyright 2012 Red Hat Inc.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * 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 "gf100.h"
25
#include "ram.h"
26

27 28 29
#include <core/memory.h>
#include <core/option.h>

30 31
void
gf100_fb_intr(struct nvkm_fb *base)
32
{
33 34
	struct gf100_fb *fb = gf100_fb(base);
	struct nvkm_subdev *subdev = &fb->base.subdev;
35 36
	struct nvkm_device *device = subdev->device;
	u32 intr = nvkm_rd32(device, 0x000100);
B
Ben Skeggs 已提交
37
	if (intr & 0x08000000)
38
		nvkm_debug(subdev, "PFFB intr\n");
B
Ben Skeggs 已提交
39
	if (intr & 0x00002000)
40
		nvkm_debug(subdev, "PBFB intr\n");
41 42
}

43
int
44
gf100_fb_oneinit(struct nvkm_fb *base)
45
{
46 47
	struct gf100_fb *fb = gf100_fb(base);
	struct nvkm_device *device = fb->base.subdev.device;
48 49 50 51 52 53
	int ret, size = 0x1000;

	size = nvkm_longopt(device->cfgopt, "MmuDebugBufferSize", size);
	size = min(size, 0x1000);

	ret = nvkm_memory_new(device, NVKM_MEM_TARGET_INST, size, 0x1000,
54
			      true, &fb->base.mmu_rd);
55 56 57 58
	if (ret)
		return ret;

	ret = nvkm_memory_new(device, NVKM_MEM_TARGET_INST, size, 0x1000,
59
			      true, &fb->base.mmu_wr);
60 61 62
	if (ret)
		return ret;

63 64 65 66 67 68 69 70
	fb->r100c10_page = alloc_page(GFP_KERNEL | __GFP_ZERO);
	if (fb->r100c10_page) {
		fb->r100c10 = dma_map_page(device->dev, fb->r100c10_page, 0,
					   PAGE_SIZE, DMA_BIDIRECTIONAL);
		if (dma_mapping_error(device->dev, fb->r100c10))
			return -EFAULT;
	}

71 72 73
	return 0;
}

74
int
75 76 77 78
gf100_fb_init_page(struct nvkm_fb *fb)
{
	struct nvkm_device *device = fb->subdev.device;
	switch (fb->page) {
79 80
	case 16: nvkm_mask(device, 0x100c80, 0x00000001, 0x00000001); break;
	case 17: nvkm_mask(device, 0x100c80, 0x00000001, 0x00000000); break;
81
	default:
82
		return -EINVAL;
83
	}
84
	return 0;
85 86
}

87 88
void
gf100_fb_init(struct nvkm_fb *base)
89
{
90
	struct gf100_fb *fb = gf100_fb(base);
91
	struct nvkm_device *device = fb->base.subdev.device;
92

B
Ben Skeggs 已提交
93
	if (fb->r100c10_page)
94
		nvkm_wr32(device, 0x100c10, fb->r100c10 >> 8);
95 96
}

97 98
void *
gf100_fb_dtor(struct nvkm_fb *base)
99
{
100 101
	struct gf100_fb *fb = gf100_fb(base);
	struct nvkm_device *device = fb->base.subdev.device;
102

B
Ben Skeggs 已提交
103
	if (fb->r100c10_page) {
104
		dma_unmap_page(device->dev, fb->r100c10, PAGE_SIZE,
105
			       DMA_BIDIRECTIONAL);
B
Ben Skeggs 已提交
106
		__free_page(fb->r100c10_page);
107 108
	}

109
	return fb;
110 111
}

112
int
113 114
gf100_fb_new_(const struct nvkm_fb_func *func, struct nvkm_device *device,
	      int index, struct nvkm_fb **pfb)
115
{
B
Ben Skeggs 已提交
116
	struct gf100_fb *fb;
117

118 119 120 121
	if (!(fb = kzalloc(sizeof(*fb), GFP_KERNEL)))
		return -ENOMEM;
	nvkm_fb_ctor(func, device, index, &fb->base);
	*pfb = &fb->base;
122

123
	return 0;
124
}
125

126 127 128
static const struct nvkm_fb_func
gf100_fb = {
	.dtor = gf100_fb_dtor,
129
	.oneinit = gf100_fb_oneinit,
130
	.init = gf100_fb_init,
131
	.init_page = gf100_fb_init_page,
132
	.intr = gf100_fb_intr,
133
	.ram_new = gf100_ram_new,
134
	.default_bigpage = 17,
135 136 137 138 139 140 141
};

int
gf100_fb_new(struct nvkm_device *device, int index, struct nvkm_fb **pfb)
{
	return gf100_fb_new_(&gf100_fb, device, index, pfb);
}