1 /* 2 * Copyright 2012 Red Hat Inc. 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 * OTHER DEALINGS IN THE SOFTWARE. 21 * 22 * Authors: Ben Skeggs 23 */ 24 #include "priv.h" 25 #include "ram.h" 26 27 #include <subdev/bios.h> 28 #include <subdev/bios/M0203.h> 29 30 int 31 nvkm_fb_bios_memtype(struct nvkm_bios *bios) 32 { 33 struct nvkm_subdev *subdev = &bios->subdev; 34 struct nvkm_device *device = subdev->device; 35 const u8 ramcfg = (nvkm_rd32(device, 0x101000) & 0x0000003c) >> 2; 36 struct nvbios_M0203E M0203E; 37 u8 ver, hdr; 38 39 if (nvbios_M0203Em(bios, ramcfg, &ver, &hdr, &M0203E)) { 40 switch (M0203E.type) { 41 case M0203E_TYPE_DDR2 : return NVKM_RAM_TYPE_DDR2; 42 case M0203E_TYPE_DDR3 : return NVKM_RAM_TYPE_DDR3; 43 case M0203E_TYPE_GDDR3: return NVKM_RAM_TYPE_GDDR3; 44 case M0203E_TYPE_GDDR5: return NVKM_RAM_TYPE_GDDR5; 45 default: 46 nvkm_warn(subdev, "M0203E type %02x\n", M0203E.type); 47 return NVKM_RAM_TYPE_UNKNOWN; 48 } 49 } 50 51 nvkm_warn(subdev, "M0203E not matched!\n"); 52 return NVKM_RAM_TYPE_UNKNOWN; 53 } 54 55 int 56 _nvkm_fb_fini(struct nvkm_object *object, bool suspend) 57 { 58 struct nvkm_fb *fb = (void *)object; 59 return nvkm_subdev_fini_old(&fb->subdev, suspend); 60 } 61 62 int 63 _nvkm_fb_init(struct nvkm_object *object) 64 { 65 struct nvkm_fb *fb = (void *)object; 66 int ret, i; 67 68 ret = nvkm_subdev_init_old(&fb->subdev); 69 if (ret) 70 return ret; 71 72 if (fb->ram) 73 nvkm_ram_init(fb->ram); 74 75 for (i = 0; i < fb->tile.regions; i++) 76 fb->tile.prog(fb, i, &fb->tile.region[i]); 77 78 return 0; 79 } 80 81 void 82 _nvkm_fb_dtor(struct nvkm_object *object) 83 { 84 struct nvkm_fb *fb = (void *)object; 85 int i; 86 87 for (i = 0; i < fb->tile.regions; i++) 88 fb->tile.fini(fb, i, &fb->tile.region[i]); 89 90 nvkm_ram_del(&fb->ram); 91 nvkm_subdev_destroy(&fb->subdev); 92 } 93 94 int 95 nvkm_fb_create_(struct nvkm_object *parent, struct nvkm_object *engine, 96 struct nvkm_oclass *oclass, int length, void **pobject) 97 { 98 struct nvkm_fb_impl *impl = (void *)oclass; 99 struct nvkm_fb *fb; 100 int ret; 101 102 ret = nvkm_subdev_create_(parent, engine, oclass, 0, "PFB", "fb", 103 length, pobject); 104 fb = *pobject; 105 if (ret) 106 return ret; 107 108 fb->memtype_valid = impl->memtype; 109 110 if (!impl->ram_new) 111 return 0; 112 113 ret = impl->ram_new(fb, &fb->ram); 114 if (ret) { 115 nvkm_error(&fb->subdev, "vram init failed, %d\n", ret); 116 return ret; 117 } 118 119 return 0; 120 } 121