gf100.c 3.9 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
extern const u8 gf100_pte_storage_type_map[256];
31

32
bool
B
Ben Skeggs 已提交
33
gf100_fb_memtype_valid(struct nvkm_fb *fb, u32 tile_flags)
34
{
35
	u8 memtype = (tile_flags & 0x0000ff00) >> 8;
36
	return likely((gf100_pte_storage_type_map[memtype] != 0xff));
37
}
38

39 40
void
gf100_fb_intr(struct nvkm_fb *base)
41
{
42 43
	struct gf100_fb *fb = gf100_fb(base);
	struct nvkm_subdev *subdev = &fb->base.subdev;
44 45
	struct nvkm_device *device = subdev->device;
	u32 intr = nvkm_rd32(device, 0x000100);
B
Ben Skeggs 已提交
46
	if (intr & 0x08000000)
47
		nvkm_debug(subdev, "PFFB intr\n");
B
Ben Skeggs 已提交
48
	if (intr & 0x00002000)
49
		nvkm_debug(subdev, "PBFB intr\n");
50 51
}

52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
int
gf100_fb_oneinit(struct nvkm_fb *fb)
{
	struct nvkm_device *device = fb->subdev.device;
	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,
			      false, &fb->mmu_rd);
	if (ret)
		return ret;

	ret = nvkm_memory_new(device, NVKM_MEM_TARGET_INST, size, 0x1000,
			      false, &fb->mmu_wr);
	if (ret)
		return ret;

	return 0;
}

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

90 91
void
gf100_fb_init(struct nvkm_fb *base)
92
{
93
	struct gf100_fb *fb = gf100_fb(base);
94
	struct nvkm_device *device = fb->base.subdev.device;
95

B
Ben Skeggs 已提交
96
	if (fb->r100c10_page)
97
		nvkm_wr32(device, 0x100c10, fb->r100c10 >> 8);
98 99
}

100 101
void *
gf100_fb_dtor(struct nvkm_fb *base)
102
{
103 104
	struct gf100_fb *fb = gf100_fb(base);
	struct nvkm_device *device = fb->base.subdev.device;
105

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

112
	return fb;
113 114
}

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

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

B
Ben Skeggs 已提交
126 127
	fb->r100c10_page = alloc_page(GFP_KERNEL | __GFP_ZERO);
	if (fb->r100c10_page) {
128 129 130
		fb->r100c10 = dma_map_page(device->dev, fb->r100c10_page, 0,
					   PAGE_SIZE, DMA_BIDIRECTIONAL);
		if (dma_mapping_error(device->dev, fb->r100c10))
131 132
			return -EFAULT;
	}
133

134
	return 0;
135
}
136

137 138 139
static const struct nvkm_fb_func
gf100_fb = {
	.dtor = gf100_fb_dtor,
140
	.oneinit = gf100_fb_oneinit,
141
	.init = gf100_fb_init,
142
	.init_page = gf100_fb_init_page,
143
	.intr = gf100_fb_intr,
144
	.ram_new = gf100_ram_new,
145 146 147 148 149 150 151 152
	.memtype_valid = gf100_fb_memtype_valid,
};

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