0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023 #include "priv.h"
0024
0025 struct priv {
0026 struct nvkm_bios *bios;
0027 u32 bar0;
0028 };
0029
0030 static u32
0031 pramin_read(void *data, u32 offset, u32 length, struct nvkm_bios *bios)
0032 {
0033 struct nvkm_device *device = bios->subdev.device;
0034 u32 i;
0035 if (offset + length <= 0x00100000) {
0036 for (i = offset; i < offset + length; i += 4)
0037 *(u32 *)&bios->data[i] = nvkm_rd32(device, 0x700000 + i);
0038 return length;
0039 }
0040 return 0;
0041 }
0042
0043 static void
0044 pramin_fini(void *data)
0045 {
0046 struct priv *priv = data;
0047 if (priv) {
0048 struct nvkm_device *device = priv->bios->subdev.device;
0049 nvkm_wr32(device, 0x001700, priv->bar0);
0050 kfree(priv);
0051 }
0052 }
0053
0054 static void *
0055 pramin_init(struct nvkm_bios *bios, const char *name)
0056 {
0057 struct nvkm_subdev *subdev = &bios->subdev;
0058 struct nvkm_device *device = subdev->device;
0059 struct priv *priv = NULL;
0060 u64 addr = 0;
0061
0062
0063 if (device->card_type < NV_50)
0064 return NULL;
0065
0066
0067 if (device->card_type >= GA100)
0068 addr = device->chipset == 0x170;
0069 else
0070 if (device->card_type >= GM100)
0071 addr = nvkm_rd32(device, 0x021c04);
0072 else
0073 if (device->card_type >= NV_C0)
0074 addr = nvkm_rd32(device, 0x022500);
0075 if (addr & 0x00000001) {
0076 nvkm_debug(subdev, "... display disabled\n");
0077 return ERR_PTR(-ENODEV);
0078 }
0079
0080
0081
0082
0083
0084 if (device->card_type >= GV100)
0085 addr = nvkm_rd32(device, 0x625f04);
0086 else
0087 addr = nvkm_rd32(device, 0x619f04);
0088 if (!(addr & 0x00000008)) {
0089 nvkm_debug(subdev, "... not enabled\n");
0090 return ERR_PTR(-ENODEV);
0091 }
0092 if ( (addr & 0x00000003) != 1) {
0093 nvkm_debug(subdev, "... not in vram\n");
0094 return ERR_PTR(-ENODEV);
0095 }
0096
0097
0098 addr = (addr & 0xffffff00) << 8;
0099 if (!addr) {
0100 addr = (u64)nvkm_rd32(device, 0x001700) << 16;
0101 addr += 0xf0000;
0102 }
0103
0104
0105 if (!(priv = kmalloc(sizeof(*priv), GFP_KERNEL))) {
0106 nvkm_error(subdev, "... out of memory\n");
0107 return ERR_PTR(-ENOMEM);
0108 }
0109
0110 priv->bios = bios;
0111 priv->bar0 = nvkm_rd32(device, 0x001700);
0112 nvkm_wr32(device, 0x001700, addr >> 16);
0113 return priv;
0114 }
0115
0116 const struct nvbios_source
0117 nvbios_ramin = {
0118 .name = "PRAMIN",
0119 .init = pramin_init,
0120 .fini = pramin_fini,
0121 .read = pramin_read,
0122 .rw = true,
0123 };