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 #define mcp77_ram(p) container_of((p), struct mcp77_ram, base)
0025 #include "ram.h"
0026 
0027 struct mcp77_ram {
0028     struct nvkm_ram base;
0029     u64 poller_base;
0030 };
0031 
0032 static int
0033 mcp77_ram_init(struct nvkm_ram *base)
0034 {
0035     struct mcp77_ram *ram = mcp77_ram(base);
0036     struct nvkm_device *device = ram->base.fb->subdev.device;
0037     u32 dniso  = ((ram->base.size - (ram->poller_base + 0x00)) >> 5) - 1;
0038     u32 hostnb = ((ram->base.size - (ram->poller_base + 0x20)) >> 5) - 1;
0039     u32 flush  = ((ram->base.size - (ram->poller_base + 0x40)) >> 5) - 1;
0040 
0041     /* Enable NISO poller for various clients and set their associated
0042      * read address, only for MCP77/78 and MCP79/7A. (fd#27501)
0043      */
0044     nvkm_wr32(device, 0x100c18, dniso);
0045     nvkm_mask(device, 0x100c14, 0x00000000, 0x00000001);
0046     nvkm_wr32(device, 0x100c1c, hostnb);
0047     nvkm_mask(device, 0x100c14, 0x00000000, 0x00000002);
0048     nvkm_wr32(device, 0x100c24, flush);
0049     nvkm_mask(device, 0x100c14, 0x00000000, 0x00010000);
0050     return 0;
0051 }
0052 
0053 static const struct nvkm_ram_func
0054 mcp77_ram_func = {
0055     .init = mcp77_ram_init,
0056 };
0057 
0058 int
0059 mcp77_ram_new(struct nvkm_fb *fb, struct nvkm_ram **pram)
0060 {
0061     struct nvkm_device *device = fb->subdev.device;
0062     u32 rsvd_head = ( 256 * 1024); /* vga memory */
0063     u32 rsvd_tail = (1024 * 1024) + 0x1000; /* vbios etc + poller mem */
0064     u64 base = (u64)nvkm_rd32(device, 0x100e10) << 12;
0065     u64 size = (u64)nvkm_rd32(device, 0x100e14) << 12;
0066     struct mcp77_ram *ram;
0067     int ret;
0068 
0069     if (!(ram = kzalloc(sizeof(*ram), GFP_KERNEL)))
0070         return -ENOMEM;
0071     *pram = &ram->base;
0072 
0073     ret = nvkm_ram_ctor(&mcp77_ram_func, fb, NVKM_RAM_TYPE_STOLEN,
0074                 size, &ram->base);
0075     if (ret)
0076         return ret;
0077 
0078     ram->poller_base = size - rsvd_tail;
0079     ram->base.stolen = base;
0080     nvkm_mm_fini(&ram->base.vram);
0081 
0082     return nvkm_mm_init(&ram->base.vram, NVKM_RAM_MM_NORMAL,
0083                 rsvd_head >> NVKM_RAM_MM_SHIFT,
0084                 (size - rsvd_head - rsvd_tail) >>
0085                 NVKM_RAM_MM_SHIFT, 1);
0086 }