1ba4c063dSBen Skeggs /*
2ba4c063dSBen Skeggs * Copyright 2017 Red Hat Inc.
3ba4c063dSBen Skeggs *
4ba4c063dSBen Skeggs * Permission is hereby granted, free of charge, to any person obtaining a
5ba4c063dSBen Skeggs * copy of this software and associated documentation files (the "Software"),
6ba4c063dSBen Skeggs * to deal in the Software without restriction, including without limitation
7ba4c063dSBen Skeggs * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8ba4c063dSBen Skeggs * and/or sell copies of the Software, and to permit persons to whom the
9ba4c063dSBen Skeggs * Software is furnished to do so, subject to the following conditions:
10ba4c063dSBen Skeggs *
11ba4c063dSBen Skeggs * The above copyright notice and this permission notice shall be included in
12ba4c063dSBen Skeggs * all copies or substantial portions of the Software.
13ba4c063dSBen Skeggs *
14ba4c063dSBen Skeggs * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15ba4c063dSBen Skeggs * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16ba4c063dSBen Skeggs * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17ba4c063dSBen Skeggs * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18ba4c063dSBen Skeggs * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19ba4c063dSBen Skeggs * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20ba4c063dSBen Skeggs * OTHER DEALINGS IN THE SOFTWARE.
21ba4c063dSBen Skeggs *
22ba4c063dSBen Skeggs * Authors: Ben Skeggs <bskeggs@redhat.com>
23ba4c063dSBen Skeggs */
24ba4c063dSBen Skeggs #include "ram.h"
25ba4c063dSBen Skeggs
2697e5268dSBen Skeggs u32
gm200_ram_probe_fbp_amount(const struct nvkm_ram_func * func,u32 fbpao,struct nvkm_device * device,int fbp,int * pltcs)2797e5268dSBen Skeggs gm200_ram_probe_fbp_amount(const struct nvkm_ram_func *func, u32 fbpao,
2897e5268dSBen Skeggs struct nvkm_device *device, int fbp, int *pltcs)
2997e5268dSBen Skeggs {
3097e5268dSBen Skeggs u32 ltcs = nvkm_rd32(device, 0x022450);
3197e5268dSBen Skeggs u32 fbpas = nvkm_rd32(device, 0x022458);
3297e5268dSBen Skeggs u32 fbpa = fbp * fbpas;
3397e5268dSBen Skeggs u32 size = 0;
3497e5268dSBen Skeggs if (!(nvkm_rd32(device, 0x021d38) & BIT(fbp))) {
3597e5268dSBen Skeggs u32 ltco = nvkm_rd32(device, 0x021d70 + (fbp * 4));
3697e5268dSBen Skeggs u32 ltcm = ~ltco & ((1 << ltcs) - 1);
3797e5268dSBen Skeggs
3897e5268dSBen Skeggs while (fbpas--) {
3997e5268dSBen Skeggs if (!(fbpao & (1 << fbpa)))
4097e5268dSBen Skeggs size += func->probe_fbpa_amount(device, fbpa);
4197e5268dSBen Skeggs fbpa++;
4297e5268dSBen Skeggs }
4397e5268dSBen Skeggs
4497e5268dSBen Skeggs *pltcs = hweight32(ltcm);
4597e5268dSBen Skeggs }
4697e5268dSBen Skeggs return size;
4797e5268dSBen Skeggs }
4897e5268dSBen Skeggs
49ba4c063dSBen Skeggs static const struct nvkm_ram_func
50ba4c063dSBen Skeggs gm200_ram = {
51*2cf3c8bcSWambui Karuga .upper = 0x1000000000ULL,
5297e5268dSBen Skeggs .probe_fbp = gm107_ram_probe_fbp,
5397e5268dSBen Skeggs .probe_fbp_amount = gm200_ram_probe_fbp_amount,
5497e5268dSBen Skeggs .probe_fbpa_amount = gf100_ram_probe_fbpa_amount,
55ba4c063dSBen Skeggs .dtor = gk104_ram_dtor,
56ba4c063dSBen Skeggs .init = gk104_ram_init,
57ba4c063dSBen Skeggs .calc = gk104_ram_calc,
58ba4c063dSBen Skeggs .prog = gk104_ram_prog,
59ba4c063dSBen Skeggs .tidy = gk104_ram_tidy,
60ba4c063dSBen Skeggs };
61ba4c063dSBen Skeggs
62ba4c063dSBen Skeggs int
gm200_ram_new(struct nvkm_fb * fb,struct nvkm_ram ** pram)63ba4c063dSBen Skeggs gm200_ram_new(struct nvkm_fb *fb, struct nvkm_ram **pram)
64ba4c063dSBen Skeggs {
6597e5268dSBen Skeggs return gk104_ram_new_(&gm200_ram, fb, pram);
66ba4c063dSBen Skeggs }
67