summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/nouveau/nvkm/subdev/fb/base.c
blob: d435bd155684f19ab391bb42e7ee234da45c408b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
 * 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
 */
#include "priv.h"
#include "ram.h"

#include <subdev/bios.h>
#include <subdev/bios/M0203.h>

int
nvkm_fb_bios_memtype(struct nvkm_bios *bios)
{
	struct nvkm_subdev *subdev = &bios->subdev;
	struct nvkm_device *device = subdev->device;
	const u8 ramcfg = (nvkm_rd32(device, 0x101000) & 0x0000003c) >> 2;
	struct nvbios_M0203E M0203E;
	u8 ver, hdr;

	if (nvbios_M0203Em(bios, ramcfg, &ver, &hdr, &M0203E)) {
		switch (M0203E.type) {
		case M0203E_TYPE_DDR2 : return NVKM_RAM_TYPE_DDR2;
		case M0203E_TYPE_DDR3 : return NVKM_RAM_TYPE_DDR3;
		case M0203E_TYPE_GDDR3: return NVKM_RAM_TYPE_GDDR3;
		case M0203E_TYPE_GDDR5: return NVKM_RAM_TYPE_GDDR5;
		default:
			nvkm_warn(subdev, "M0203E type %02x\n", M0203E.type);
			return NVKM_RAM_TYPE_UNKNOWN;
		}
	}

	nvkm_warn(subdev, "M0203E not matched!\n");
	return NVKM_RAM_TYPE_UNKNOWN;
}

int
_nvkm_fb_fini(struct nvkm_object *object, bool suspend)
{
	struct nvkm_fb *fb = (void *)object;
	return nvkm_subdev_fini_old(&fb->subdev, suspend);
}

int
_nvkm_fb_init(struct nvkm_object *object)
{
	struct nvkm_fb *fb = (void *)object;
	int ret, i;

	ret = nvkm_subdev_init_old(&fb->subdev);
	if (ret)
		return ret;

	if (fb->ram)
		nvkm_ram_init(fb->ram);

	for (i = 0; i < fb->tile.regions; i++)
		fb->tile.prog(fb, i, &fb->tile.region[i]);

	return 0;
}

void
_nvkm_fb_dtor(struct nvkm_object *object)
{
	struct nvkm_fb *fb = (void *)object;
	int i;

	for (i = 0; i < fb->tile.regions; i++)
		fb->tile.fini(fb, i, &fb->tile.region[i]);

	nvkm_ram_del(&fb->ram);
	nvkm_subdev_destroy(&fb->subdev);
}

int
nvkm_fb_create_(struct nvkm_object *parent, struct nvkm_object *engine,
		struct nvkm_oclass *oclass, int length, void **pobject)
{
	struct nvkm_fb_impl *impl = (void *)oclass;
	struct nvkm_fb *fb;
	int ret;

	ret = nvkm_subdev_create_(parent, engine, oclass, 0, "PFB", "fb",
				  length, pobject);
	fb = *pobject;
	if (ret)
		return ret;

	fb->memtype_valid = impl->memtype;

	if (!impl->ram_new)
		return 0;

	ret = impl->ram_new(fb, &fb->ram);
	if (ret) {
		nvkm_error(&fb->subdev, "vram init failed, %d\n", ret);
		return ret;
	}

	return 0;
}
OpenPOWER on IntegriCloud