1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23#include "priv.h"
24
25struct priv {
26 struct nvkm_bios *bios;
27 u32 bar0;
28};
29
30static u32
31pramin_read(void *data, u32 offset, u32 length, struct nvkm_bios *bios)
32{
33 struct nvkm_device *device = bios->subdev.device;
34 u32 i;
35 if (offset + length <= 0x00100000) {
36 for (i = offset; i < offset + length; i += 4)
37 *(u32 *)&bios->data[i] = nvkm_rd32(device, 0x700000 + i);
38 return length;
39 }
40 return 0;
41}
42
43static void
44pramin_fini(void *data)
45{
46 struct priv *priv = data;
47 if (priv) {
48 struct nvkm_device *device = priv->bios->subdev.device;
49 nvkm_wr32(device, 0x001700, priv->bar0);
50 kfree(priv);
51 }
52}
53
54static void *
55pramin_init(struct nvkm_bios *bios, const char *name)
56{
57 struct nvkm_subdev *subdev = &bios->subdev;
58 struct nvkm_device *device = subdev->device;
59 struct priv *priv = NULL;
60 u64 addr = 0;
61
62
63 if (device->card_type < NV_50)
64 return NULL;
65
66
67 if (device->card_type >= GA100)
68 addr = device->chipset == 0x170;
69 else
70 if (device->card_type >= GM100)
71 addr = nvkm_rd32(device, 0x021c04);
72 else
73 if (device->card_type >= NV_C0)
74 addr = nvkm_rd32(device, 0x022500);
75 if (addr & 0x00000001) {
76 nvkm_debug(subdev, "... display disabled\n");
77 return ERR_PTR(-ENODEV);
78 }
79
80
81
82
83
84 if (device->card_type >= GV100)
85 addr = nvkm_rd32(device, 0x625f04);
86 else
87 addr = nvkm_rd32(device, 0x619f04);
88 if (!(addr & 0x00000008)) {
89 nvkm_debug(subdev, "... not enabled\n");
90 return ERR_PTR(-ENODEV);
91 }
92 if ( (addr & 0x00000003) != 1) {
93 nvkm_debug(subdev, "... not in vram\n");
94 return ERR_PTR(-ENODEV);
95 }
96
97
98 addr = (addr & 0xffffff00) << 8;
99 if (!addr) {
100 addr = (u64)nvkm_rd32(device, 0x001700) << 16;
101 addr += 0xf0000;
102 }
103
104
105 if (!(priv = kmalloc(sizeof(*priv), GFP_KERNEL))) {
106 nvkm_error(subdev, "... out of memory\n");
107 return ERR_PTR(-ENOMEM);
108 }
109
110 priv->bios = bios;
111 priv->bar0 = nvkm_rd32(device, 0x001700);
112 nvkm_wr32(device, 0x001700, addr >> 16);
113 return priv;
114}
115
116const struct nvbios_source
117nvbios_ramin = {
118 .name = "PRAMIN",
119 .init = pramin_init,
120 .fini = pramin_fini,
121 .read = pramin_read,
122 .rw = true,
123};
124