Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright 2013 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  * Authors: Ben Skeggs
0023  */
0024 #include "ram.h"
0025 
0026 #include <subdev/bios.h>
0027 #include <subdev/bios/init.h>
0028 #include <subdev/bios/rammap.h>
0029 
0030 static int
0031 gp100_ram_init(struct nvkm_ram *ram)
0032 {
0033     struct nvkm_subdev *subdev = &ram->fb->subdev;
0034     struct nvkm_device *device = subdev->device;
0035     struct nvkm_bios *bios = device->bios;
0036     u8  ver, hdr, cnt, len, snr, ssz;
0037     u32 data;
0038     int i;
0039 
0040     /* run a bunch of tables from rammap table.  there's actually
0041      * individual pointers for each rammap entry too, but, nvidia
0042      * seem to just run the last two entries' scripts early on in
0043      * their init, and never again.. we'll just run 'em all once
0044      * for now.
0045      *
0046      * i strongly suspect that each script is for a separate mode
0047      * (likely selected by 0x9a065c's lower bits?), and the
0048      * binary driver skips the one that's already been setup by
0049      * the init tables.
0050      */
0051     data = nvbios_rammapTe(bios, &ver, &hdr, &cnt, &len, &snr, &ssz);
0052     if (!data || hdr < 0x15)
0053         return -EINVAL;
0054 
0055     cnt  = nvbios_rd08(bios, data + 0x14); /* guess at count */
0056     data = nvbios_rd32(bios, data + 0x10); /* guess u32... */
0057     if (cnt) {
0058         u32 save = nvkm_rd32(device, 0x9a065c) & 0x000000f0;
0059         for (i = 0; i < cnt; i++, data += 4) {
0060             if (i != save >> 4) {
0061                 nvkm_mask(device, 0x9a065c, 0x000000f0, i << 4);
0062                 nvbios_init(subdev, nvbios_rd32(bios, data));
0063             }
0064         }
0065         nvkm_mask(device, 0x9a065c, 0x000000f0, save);
0066     }
0067 
0068     nvkm_mask(device, 0x9a0584, 0x11000000, 0x00000000);
0069     nvkm_wr32(device, 0x10ecc0, 0xffffffff);
0070     nvkm_mask(device, 0x9a0160, 0x00000010, 0x00000010);
0071     return 0;
0072 }
0073 
0074 static u32
0075 gp100_ram_probe_fbpa(struct nvkm_device *device, int fbpa)
0076 {
0077     return nvkm_rd32(device, 0x90020c + (fbpa * 0x4000));
0078 }
0079 
0080 static const struct nvkm_ram_func
0081 gp100_ram = {
0082     .upper = 0x1000000000ULL,
0083     .probe_fbp = gm107_ram_probe_fbp,
0084     .probe_fbp_amount = gm200_ram_probe_fbp_amount,
0085     .probe_fbpa_amount = gp100_ram_probe_fbpa,
0086     .init = gp100_ram_init,
0087 };
0088 
0089 int
0090 gp100_ram_new(struct nvkm_fb *fb, struct nvkm_ram **pram)
0091 {
0092     struct nvkm_ram *ram;
0093 
0094     if (!(ram = *pram = kzalloc(sizeof(*ram), GFP_KERNEL)))
0095         return -ENOMEM;
0096 
0097     return gf100_ram_ctor(&gp100_ram, fb, ram);
0098 
0099 }