1c39f472eSBen Skeggs /* 2c39f472eSBen Skeggs * Copyright 2012 Red Hat Inc. 3c39f472eSBen Skeggs * 4c39f472eSBen Skeggs * Permission is hereby granted, free of charge, to any person obtaining a 5c39f472eSBen Skeggs * copy of this software and associated documentation files (the "Software"), 6c39f472eSBen Skeggs * to deal in the Software without restriction, including without limitation 7c39f472eSBen Skeggs * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8c39f472eSBen Skeggs * and/or sell copies of the Software, and to permit persons to whom the 9c39f472eSBen Skeggs * Software is furnished to do so, subject to the following conditions: 10c39f472eSBen Skeggs * 11c39f472eSBen Skeggs * The above copyright notice and this permission notice shall be included in 12c39f472eSBen Skeggs * all copies or substantial portions of the Software. 13c39f472eSBen Skeggs * 14c39f472eSBen Skeggs * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15c39f472eSBen Skeggs * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16c39f472eSBen Skeggs * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17c39f472eSBen Skeggs * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18c39f472eSBen Skeggs * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19c39f472eSBen Skeggs * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20c39f472eSBen Skeggs * OTHER DEALINGS IN THE SOFTWARE. 21c39f472eSBen Skeggs * 22c39f472eSBen Skeggs * Authors: Ben Skeggs 23c39f472eSBen Skeggs */ 24c39f472eSBen Skeggs #include "nv04.h" 25639c308eSBen Skeggs #include "regsnv04.h" 26c39f472eSBen Skeggs 27c39f472eSBen Skeggs bool 28b1e4553cSBen Skeggs nv04_fb_memtype_valid(struct nvkm_fb *fb, u32 tile_flags) 29c39f472eSBen Skeggs { 30c39f472eSBen Skeggs if (!(tile_flags & 0xff00)) 31c39f472eSBen Skeggs return true; 32c39f472eSBen Skeggs 33c39f472eSBen Skeggs return false; 34c39f472eSBen Skeggs } 35c39f472eSBen Skeggs 36c39f472eSBen Skeggs static int 37639c308eSBen Skeggs nv04_fb_init(struct nvkm_object *object) 38c39f472eSBen Skeggs { 39b1e4553cSBen Skeggs struct nvkm_fb *fb = (void *)object; 40c39f472eSBen Skeggs int ret; 41c39f472eSBen Skeggs 42b1e4553cSBen Skeggs ret = nvkm_fb_init(fb); 43c39f472eSBen Skeggs if (ret) 44c39f472eSBen Skeggs return ret; 45c39f472eSBen Skeggs 46c39f472eSBen Skeggs /* This is what the DDX did for NV_ARCH_04, but a mmio-trace shows 47c39f472eSBen Skeggs * nvidia reading PFB_CFG_0, then writing back its original value. 48c39f472eSBen Skeggs * (which was 0x701114 in this case) 49c39f472eSBen Skeggs */ 50b1e4553cSBen Skeggs nv_wr32(fb, NV04_PFB_CFG0, 0x1114); 51c39f472eSBen Skeggs return 0; 52c39f472eSBen Skeggs } 53c39f472eSBen Skeggs 54c39f472eSBen Skeggs int 55639c308eSBen Skeggs nv04_fb_ctor(struct nvkm_object *parent, struct nvkm_object *engine, 56639c308eSBen Skeggs struct nvkm_oclass *oclass, void *data, u32 size, 57639c308eSBen Skeggs struct nvkm_object **pobject) 58c39f472eSBen Skeggs { 59c39f472eSBen Skeggs struct nv04_fb_impl *impl = (void *)oclass; 60b1e4553cSBen Skeggs struct nvkm_fb *fb; 61c39f472eSBen Skeggs int ret; 62c39f472eSBen Skeggs 63b1e4553cSBen Skeggs ret = nvkm_fb_create(parent, engine, oclass, &fb); 64b1e4553cSBen Skeggs *pobject = nv_object(fb); 65c39f472eSBen Skeggs if (ret) 66c39f472eSBen Skeggs return ret; 67c39f472eSBen Skeggs 68b1e4553cSBen Skeggs fb->tile.regions = impl->tile.regions; 69b1e4553cSBen Skeggs fb->tile.init = impl->tile.init; 70b1e4553cSBen Skeggs fb->tile.comp = impl->tile.comp; 71b1e4553cSBen Skeggs fb->tile.fini = impl->tile.fini; 72b1e4553cSBen Skeggs fb->tile.prog = impl->tile.prog; 73c39f472eSBen Skeggs return 0; 74c39f472eSBen Skeggs } 75c39f472eSBen Skeggs 76639c308eSBen Skeggs struct nvkm_oclass * 77c39f472eSBen Skeggs nv04_fb_oclass = &(struct nv04_fb_impl) { 78c39f472eSBen Skeggs .base.base.handle = NV_SUBDEV(FB, 0x04), 79639c308eSBen Skeggs .base.base.ofuncs = &(struct nvkm_ofuncs) { 80c39f472eSBen Skeggs .ctor = nv04_fb_ctor, 81639c308eSBen Skeggs .dtor = _nvkm_fb_dtor, 82c39f472eSBen Skeggs .init = nv04_fb_init, 83639c308eSBen Skeggs .fini = _nvkm_fb_fini, 84c39f472eSBen Skeggs }, 85c39f472eSBen Skeggs .base.memtype = nv04_fb_memtype_valid, 86c39f472eSBen Skeggs .base.ram = &nv04_ram_oclass, 87c39f472eSBen Skeggs }.base.base; 88