Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright 2012 Red Hat Inc.
0003  *
0004  * Permission is hereby granted, free of charge, to any person obtaining a
0005  * copy of this software and associated documentation files (the "Software"),
0006  * to deal in the Software without restriction, including without limitation
0007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0008  * and/or sell copies of the Software, and to permit persons to whom the
0009  * Software is furnished to do so, subject to the following conditions:
0010  *
0011  * The above copyright notice and this permission notice shall be included in
0012  * all copies or substantial portions of the Software.
0013  *
0014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0017  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
0018  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0020  * OTHER DEALINGS IN THE SOFTWARE.
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     /* PRAMIN always potentially available prior to nv50 */
0063     if (device->card_type < NV_50)
0064         return NULL;
0065 
0066     /* we can't get the bios image pointer without PDISP */
0067     if (device->card_type >= GA100)
0068         addr = device->chipset == 0x170; /*XXX: find the fuse reg for this */
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     /* check that the window is enabled and in vram, particularly
0081      * important as we don't want to be touching vram on an
0082      * uninitialised board
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     /* some alternate method inherited from xf86-video-nv... */
0098     addr = (addr & 0xffffff00) << 8;
0099     if (!addr) {
0100         addr  = (u64)nvkm_rd32(device, 0x001700) << 16;
0101         addr += 0xf0000;
0102     }
0103 
0104     /* modify bar0 PRAMIN window to cover the bios image */
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 };