xref: /linux/drivers/gpu/drm/nouveau/nvkm/subdev/fb/gf100.c (revision 7f5f518fd70b1b72ca4cf8249ca3306846383ed4)
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 #include "gf100.h"
25 
26 extern const u8 gf100_pte_storage_type_map[256];
27 
28 bool
29 gf100_fb_memtype_valid(struct nvkm_fb *fb, u32 tile_flags)
30 {
31 	u8 memtype = (tile_flags & 0x0000ff00) >> 8;
32 	return likely((gf100_pte_storage_type_map[memtype] != 0xff));
33 }
34 
35 static void
36 gf100_fb_intr(struct nvkm_subdev *subdev)
37 {
38 	struct nvkm_device *device = subdev->device;
39 	u32 intr = nvkm_rd32(device, 0x000100);
40 	if (intr & 0x08000000)
41 		nvkm_debug(subdev, "PFFB intr\n");
42 	if (intr & 0x00002000)
43 		nvkm_debug(subdev, "PBFB intr\n");
44 }
45 
46 int
47 gf100_fb_init(struct nvkm_object *object)
48 {
49 	struct gf100_fb *fb = (void *)object;
50 	struct nvkm_device *device = fb->base.subdev.device;
51 	int ret;
52 
53 	ret = nvkm_fb_init(&fb->base);
54 	if (ret)
55 		return ret;
56 
57 	if (fb->r100c10_page)
58 		nvkm_wr32(device, 0x100c10, fb->r100c10 >> 8);
59 
60 	nvkm_mask(device, 0x100c80, 0x00000001, 0x00000000); /* 128KiB lpg */
61 	return 0;
62 }
63 
64 void
65 gf100_fb_dtor(struct nvkm_object *object)
66 {
67 	struct nvkm_device *device = nv_device(object);
68 	struct gf100_fb *fb = (void *)object;
69 
70 	if (fb->r100c10_page) {
71 		dma_unmap_page(nv_device_base(device), fb->r100c10, PAGE_SIZE,
72 			       DMA_BIDIRECTIONAL);
73 		__free_page(fb->r100c10_page);
74 	}
75 
76 	nvkm_fb_destroy(&fb->base);
77 }
78 
79 int
80 gf100_fb_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
81 	      struct nvkm_oclass *oclass, void *data, u32 size,
82 	      struct nvkm_object **pobject)
83 {
84 	struct nvkm_device *device = nv_device(parent);
85 	struct gf100_fb *fb;
86 	int ret;
87 
88 	ret = nvkm_fb_create(parent, engine, oclass, &fb);
89 	*pobject = nv_object(fb);
90 	if (ret)
91 		return ret;
92 
93 	fb->r100c10_page = alloc_page(GFP_KERNEL | __GFP_ZERO);
94 	if (fb->r100c10_page) {
95 		fb->r100c10 = dma_map_page(nv_device_base(device),
96 					     fb->r100c10_page, 0, PAGE_SIZE,
97 					     DMA_BIDIRECTIONAL);
98 		if (dma_mapping_error(nv_device_base(device), fb->r100c10))
99 			return -EFAULT;
100 	}
101 
102 	nv_subdev(fb)->intr = gf100_fb_intr;
103 	return 0;
104 }
105 
106 struct nvkm_oclass *
107 gf100_fb_oclass = &(struct nvkm_fb_impl) {
108 	.base.handle = NV_SUBDEV(FB, 0xc0),
109 	.base.ofuncs = &(struct nvkm_ofuncs) {
110 		.ctor = gf100_fb_ctor,
111 		.dtor = gf100_fb_dtor,
112 		.init = gf100_fb_init,
113 		.fini = _nvkm_fb_fini,
114 	},
115 	.memtype = gf100_fb_memtype_valid,
116 	.ram = &gf100_ram_oclass,
117 }.base;
118