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
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
void
gf100_fb_init(struct nvkm_fb *base)
76
{
77
	struct gf100_fb *fb = gf100_fb(base);
78
	struct nvkm_device *device = fb->base.subdev.device;
79

B
Ben Skeggs 已提交
80
	if (fb->r100c10_page)
81
		nvkm_wr32(device, 0x100c10, fb->r100c10 >> 8);
82

83
	nvkm_mask(device, 0x100c80, 0x00000001, 0x00000000); /* 128KiB lpg */
84 85
}

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

B
Ben Skeggs 已提交
92
	if (fb->r100c10_page) {
93
		dma_unmap_page(device->dev, fb->r100c10, PAGE_SIZE,
94
			       DMA_BIDIRECTIONAL);
B
Ben Skeggs 已提交
95
		__free_page(fb->r100c10_page);
96 97
	}

98
	return fb;
99 100
}

101
int
102 103
gf100_fb_new_(const struct nvkm_fb_func *func, struct nvkm_device *device,
	      int index, struct nvkm_fb **pfb)
104
{
B
Ben Skeggs 已提交
105
	struct gf100_fb *fb;
106

107 108 109 110
	if (!(fb = kzalloc(sizeof(*fb), GFP_KERNEL)))
		return -ENOMEM;
	nvkm_fb_ctor(func, device, index, &fb->base);
	*pfb = &fb->base;
111

B
Ben Skeggs 已提交
112 113
	fb->r100c10_page = alloc_page(GFP_KERNEL | __GFP_ZERO);
	if (fb->r100c10_page) {
114 115 116
		fb->r100c10 = dma_map_page(device->dev, fb->r100c10_page, 0,
					   PAGE_SIZE, DMA_BIDIRECTIONAL);
		if (dma_mapping_error(device->dev, fb->r100c10))
117 118
			return -EFAULT;
	}
119

120
	return 0;
121
}
122

123 124 125
static const struct nvkm_fb_func
gf100_fb = {
	.dtor = gf100_fb_dtor,
126
	.oneinit = gf100_fb_oneinit,
127 128
	.init = gf100_fb_init,
	.intr = gf100_fb_intr,
129
	.ram_new = gf100_ram_new,
130 131 132 133 134 135 136 137
	.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);
}