xref: /linux/drivers/gpu/drm/nouveau/nvkm/subdev/fb/rammcp77.c (revision 664b0bae0b87f69bc9deb098f5e0158b9cf18e04)
1639c308eSBen Skeggs /*
2639c308eSBen Skeggs  * Copyright 2013 Red Hat Inc.
3639c308eSBen Skeggs  *
4639c308eSBen Skeggs  * Permission is hereby granted, free of charge, to any person obtaining a
5639c308eSBen Skeggs  * copy of this software and associated documentation files (the "Software"),
6639c308eSBen Skeggs  * to deal in the Software without restriction, including without limitation
7639c308eSBen Skeggs  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8639c308eSBen Skeggs  * and/or sell copies of the Software, and to permit persons to whom the
9639c308eSBen Skeggs  * Software is furnished to do so, subject to the following conditions:
10639c308eSBen Skeggs  *
11639c308eSBen Skeggs  * The above copyright notice and this permission notice shall be included in
12639c308eSBen Skeggs  * all copies or substantial portions of the Software.
13639c308eSBen Skeggs  *
14639c308eSBen Skeggs  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15639c308eSBen Skeggs  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16639c308eSBen Skeggs  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17639c308eSBen Skeggs  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18639c308eSBen Skeggs  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19639c308eSBen Skeggs  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20639c308eSBen Skeggs  * OTHER DEALINGS IN THE SOFTWARE.
21639c308eSBen Skeggs  *
22639c308eSBen Skeggs  * Authors: Ben Skeggs
23639c308eSBen Skeggs  */
24d36a99d2SBen Skeggs #define mcp77_ram(p) container_of((p), struct mcp77_ram, base)
25d36a99d2SBen Skeggs #include "ram.h"
26639c308eSBen Skeggs 
27b1e4553cSBen Skeggs struct mcp77_ram {
28639c308eSBen Skeggs 	struct nvkm_ram base;
29639c308eSBen Skeggs 	u64 poller_base;
30639c308eSBen Skeggs };
31639c308eSBen Skeggs 
32639c308eSBen Skeggs static int
mcp77_ram_init(struct nvkm_ram * base)33d36a99d2SBen Skeggs mcp77_ram_init(struct nvkm_ram *base)
34639c308eSBen Skeggs {
35d36a99d2SBen Skeggs 	struct mcp77_ram *ram = mcp77_ram(base);
36d36a99d2SBen Skeggs 	struct nvkm_device *device = ram->base.fb->subdev.device;
37d36a99d2SBen Skeggs 	u32 dniso  = ((ram->base.size - (ram->poller_base + 0x00)) >> 5) - 1;
38d36a99d2SBen Skeggs 	u32 hostnb = ((ram->base.size - (ram->poller_base + 0x20)) >> 5) - 1;
39d36a99d2SBen Skeggs 	u32 flush  = ((ram->base.size - (ram->poller_base + 0x40)) >> 5) - 1;
40639c308eSBen Skeggs 
41639c308eSBen Skeggs 	/* Enable NISO poller for various clients and set their associated
4208796832SIlia Mirkin 	 * read address, only for MCP77/78 and MCP79/7A. (fd#27501)
43639c308eSBen Skeggs 	 */
446758745bSBen Skeggs 	nvkm_wr32(device, 0x100c18, dniso);
456758745bSBen Skeggs 	nvkm_mask(device, 0x100c14, 0x00000000, 0x00000001);
466758745bSBen Skeggs 	nvkm_wr32(device, 0x100c1c, hostnb);
476758745bSBen Skeggs 	nvkm_mask(device, 0x100c14, 0x00000000, 0x00000002);
486758745bSBen Skeggs 	nvkm_wr32(device, 0x100c24, flush);
496758745bSBen Skeggs 	nvkm_mask(device, 0x100c14, 0x00000000, 0x00010000);
50639c308eSBen Skeggs 	return 0;
51639c308eSBen Skeggs }
52639c308eSBen Skeggs 
53d36a99d2SBen Skeggs static const struct nvkm_ram_func
54d36a99d2SBen Skeggs mcp77_ram_func = {
55639c308eSBen Skeggs 	.init = mcp77_ram_init,
56639c308eSBen Skeggs };
57d36a99d2SBen Skeggs 
58d36a99d2SBen Skeggs int
mcp77_ram_new(struct nvkm_fb * fb,struct nvkm_ram ** pram)59d36a99d2SBen Skeggs mcp77_ram_new(struct nvkm_fb *fb, struct nvkm_ram **pram)
60d36a99d2SBen Skeggs {
61d36a99d2SBen Skeggs 	struct nvkm_device *device = fb->subdev.device;
62d36a99d2SBen Skeggs 	u32 rsvd_head = ( 256 * 1024); /* vga memory */
63d36a99d2SBen Skeggs 	u32 rsvd_tail = (1024 * 1024) + 0x1000; /* vbios etc + poller mem */
64d36a99d2SBen Skeggs 	u64 base = (u64)nvkm_rd32(device, 0x100e10) << 12;
65d36a99d2SBen Skeggs 	u64 size = (u64)nvkm_rd32(device, 0x100e14) << 12;
66d36a99d2SBen Skeggs 	struct mcp77_ram *ram;
67d36a99d2SBen Skeggs 	int ret;
68d36a99d2SBen Skeggs 
69d36a99d2SBen Skeggs 	if (!(ram = kzalloc(sizeof(*ram), GFP_KERNEL)))
70d36a99d2SBen Skeggs 		return -ENOMEM;
71d36a99d2SBen Skeggs 	*pram = &ram->base;
72d36a99d2SBen Skeggs 
73d36a99d2SBen Skeggs 	ret = nvkm_ram_ctor(&mcp77_ram_func, fb, NVKM_RAM_TYPE_STOLEN,
74*af793b8cSBen Skeggs 			    size, &ram->base);
75d36a99d2SBen Skeggs 	if (ret)
76d36a99d2SBen Skeggs 		return ret;
77d36a99d2SBen Skeggs 
78d36a99d2SBen Skeggs 	ram->poller_base = size - rsvd_tail;
79d36a99d2SBen Skeggs 	ram->base.stolen = base;
80d36a99d2SBen Skeggs 	nvkm_mm_fini(&ram->base.vram);
81d36a99d2SBen Skeggs 
824d058fabSBen Skeggs 	return nvkm_mm_init(&ram->base.vram, NVKM_RAM_MM_NORMAL,
834d058fabSBen Skeggs 			    rsvd_head >> NVKM_RAM_MM_SHIFT,
84d36a99d2SBen Skeggs 			    (size - rsvd_head - rsvd_tail) >>
85d36a99d2SBen Skeggs 			    NVKM_RAM_MM_SHIFT, 1);
86d36a99d2SBen Skeggs }
87