17ff51f82SBen Skeggs /*
27ff51f82SBen Skeggs * Copyright 2013 Red Hat Inc.
37ff51f82SBen Skeggs *
47ff51f82SBen Skeggs * Permission is hereby granted, free of charge, to any person obtaining a
57ff51f82SBen Skeggs * copy of this software and associated documentation files (the "Software"),
67ff51f82SBen Skeggs * to deal in the Software without restriction, including without limitation
77ff51f82SBen Skeggs * the rights to use, copy, modify, merge, publish, distribute, sublicense,
87ff51f82SBen Skeggs * and/or sell copies of the Software, and to permit persons to whom the
97ff51f82SBen Skeggs * Software is furnished to do so, subject to the following conditions:
107ff51f82SBen Skeggs *
117ff51f82SBen Skeggs * The above copyright notice and this permission notice shall be included in
127ff51f82SBen Skeggs * all copies or substantial portions of the Software.
137ff51f82SBen Skeggs *
147ff51f82SBen Skeggs * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
157ff51f82SBen Skeggs * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
167ff51f82SBen Skeggs * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
177ff51f82SBen Skeggs * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
187ff51f82SBen Skeggs * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
197ff51f82SBen Skeggs * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
207ff51f82SBen Skeggs * OTHER DEALINGS IN THE SOFTWARE.
217ff51f82SBen Skeggs *
227ff51f82SBen Skeggs * Authors: Ben Skeggs
237ff51f82SBen Skeggs */
247ff51f82SBen Skeggs #include "ram.h"
257ff51f82SBen Skeggs
267ff51f82SBen Skeggs #include <subdev/bios.h>
277ff51f82SBen Skeggs #include <subdev/bios/init.h>
287ff51f82SBen Skeggs #include <subdev/bios/rammap.h>
297ff51f82SBen Skeggs
30*def80cdbSBen Skeggs int
gp100_ram_init(struct nvkm_ram * ram)317ff51f82SBen Skeggs gp100_ram_init(struct nvkm_ram *ram)
327ff51f82SBen Skeggs {
337ff51f82SBen Skeggs struct nvkm_subdev *subdev = &ram->fb->subdev;
347ff51f82SBen Skeggs struct nvkm_device *device = subdev->device;
357ff51f82SBen Skeggs struct nvkm_bios *bios = device->bios;
367ff51f82SBen Skeggs u8 ver, hdr, cnt, len, snr, ssz;
377ff51f82SBen Skeggs u32 data;
387ff51f82SBen Skeggs int i;
397ff51f82SBen Skeggs
407ff51f82SBen Skeggs /* run a bunch of tables from rammap table. there's actually
417ff51f82SBen Skeggs * individual pointers for each rammap entry too, but, nvidia
427ff51f82SBen Skeggs * seem to just run the last two entries' scripts early on in
437ff51f82SBen Skeggs * their init, and never again.. we'll just run 'em all once
447ff51f82SBen Skeggs * for now.
457ff51f82SBen Skeggs *
467ff51f82SBen Skeggs * i strongly suspect that each script is for a separate mode
477ff51f82SBen Skeggs * (likely selected by 0x9a065c's lower bits?), and the
487ff51f82SBen Skeggs * binary driver skips the one that's already been setup by
497ff51f82SBen Skeggs * the init tables.
507ff51f82SBen Skeggs */
517ff51f82SBen Skeggs data = nvbios_rammapTe(bios, &ver, &hdr, &cnt, &len, &snr, &ssz);
527ff51f82SBen Skeggs if (!data || hdr < 0x15)
537ff51f82SBen Skeggs return -EINVAL;
547ff51f82SBen Skeggs
557ff51f82SBen Skeggs cnt = nvbios_rd08(bios, data + 0x14); /* guess at count */
567ff51f82SBen Skeggs data = nvbios_rd32(bios, data + 0x10); /* guess u32... */
577ff51f82SBen Skeggs if (cnt) {
587ff51f82SBen Skeggs u32 save = nvkm_rd32(device, 0x9a065c) & 0x000000f0;
597ff51f82SBen Skeggs for (i = 0; i < cnt; i++, data += 4) {
607ff51f82SBen Skeggs if (i != save >> 4) {
617ff51f82SBen Skeggs nvkm_mask(device, 0x9a065c, 0x000000f0, i << 4);
624fdc6ba3SBen Skeggs nvbios_init(subdev, nvbios_rd32(bios, data));
637ff51f82SBen Skeggs }
647ff51f82SBen Skeggs }
657ff51f82SBen Skeggs nvkm_mask(device, 0x9a065c, 0x000000f0, save);
667ff51f82SBen Skeggs }
677ff51f82SBen Skeggs
687ff51f82SBen Skeggs nvkm_mask(device, 0x9a0584, 0x11000000, 0x00000000);
697ff51f82SBen Skeggs nvkm_wr32(device, 0x10ecc0, 0xffffffff);
707ff51f82SBen Skeggs nvkm_mask(device, 0x9a0160, 0x00000010, 0x00000010);
717ff51f82SBen Skeggs return 0;
727ff51f82SBen Skeggs }
737ff51f82SBen Skeggs
7497e5268dSBen Skeggs static u32
gp100_ram_probe_fbpa(struct nvkm_device * device,int fbpa)7597e5268dSBen Skeggs gp100_ram_probe_fbpa(struct nvkm_device *device, int fbpa)
7697e5268dSBen Skeggs {
7797e5268dSBen Skeggs return nvkm_rd32(device, 0x90020c + (fbpa * 0x4000));
7897e5268dSBen Skeggs }
7997e5268dSBen Skeggs
807ff51f82SBen Skeggs static const struct nvkm_ram_func
8197e5268dSBen Skeggs gp100_ram = {
822cf3c8bcSWambui Karuga .upper = 0x1000000000ULL,
8397e5268dSBen Skeggs .probe_fbp = gm107_ram_probe_fbp,
8497e5268dSBen Skeggs .probe_fbp_amount = gm200_ram_probe_fbp_amount,
8597e5268dSBen Skeggs .probe_fbpa_amount = gp100_ram_probe_fbpa,
867ff51f82SBen Skeggs .init = gp100_ram_init,
877ff51f82SBen Skeggs };
887ff51f82SBen Skeggs
897ff51f82SBen Skeggs int
gp100_ram_new(struct nvkm_fb * fb,struct nvkm_ram ** pram)907ff51f82SBen Skeggs gp100_ram_new(struct nvkm_fb *fb, struct nvkm_ram **pram)
917ff51f82SBen Skeggs {
927ff51f82SBen Skeggs struct nvkm_ram *ram;
937ff51f82SBen Skeggs
9497e5268dSBen Skeggs if (!(ram = *pram = kzalloc(sizeof(*ram), GFP_KERNEL)))
9597e5268dSBen Skeggs return -ENOMEM;
967ff51f82SBen Skeggs
9797e5268dSBen Skeggs return gf100_ram_ctor(&gp100_ram, fb, ram);
987ff51f82SBen Skeggs
997ff51f82SBen Skeggs }
100