Ben Skeggs | 861d210 | 2012-07-11 19:05:01 +1000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2010 Francisco Jerez. |
| 3 | * All Rights Reserved. |
| 4 | * |
| 5 | * Permission is hereby granted, free of charge, to any person obtaining |
| 6 | * a copy of this software and associated documentation files (the |
| 7 | * "Software"), to deal in the Software without restriction, including |
| 8 | * without limitation the rights to use, copy, modify, merge, publish, |
| 9 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 10 | * permit persons to whom the Software is furnished to do so, subject to |
| 11 | * the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice (including the |
| 14 | * next paragraph) shall be included in all copies or substantial |
| 15 | * portions of the Software. |
| 16 | * |
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 20 | * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE |
| 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 24 | * |
| 25 | */ |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 26 | |
Ben Skeggs | 861d210 | 2012-07-11 19:05:01 +1000 | [diff] [blame^] | 27 | #include <subdev/fb.h> |
| 28 | |
| 29 | struct nv40_fb_priv { |
| 30 | struct nouveau_fb base; |
| 31 | }; |
| 32 | |
| 33 | static inline int |
| 34 | nv44_graph_class(struct nouveau_device *device) |
Francisco Jerez | 0d87c10 | 2009-12-16 12:12:27 +0100 | [diff] [blame] | 35 | { |
Ben Skeggs | 861d210 | 2012-07-11 19:05:01 +1000 | [diff] [blame^] | 36 | if ((device->chipset & 0xf0) == 0x60) |
| 37 | return 1; |
Francisco Jerez | 0d87c10 | 2009-12-16 12:12:27 +0100 | [diff] [blame] | 38 | |
Ben Skeggs | 861d210 | 2012-07-11 19:05:01 +1000 | [diff] [blame^] | 39 | return !(0x0baf & (1 << (device->chipset & 0x0f))); |
Francisco Jerez | 0d87c10 | 2009-12-16 12:12:27 +0100 | [diff] [blame] | 40 | } |
| 41 | |
Ben Skeggs | 7948758 | 2011-01-11 14:52:40 +1000 | [diff] [blame] | 42 | static void |
Ben Skeggs | 861d210 | 2012-07-11 19:05:01 +1000 | [diff] [blame^] | 43 | nv40_fb_tile_prog(struct nouveau_fb *pfb, int i, struct nouveau_fb_tile *tile) |
Ben Skeggs | 7948758 | 2011-01-11 14:52:40 +1000 | [diff] [blame] | 44 | { |
Ben Skeggs | 861d210 | 2012-07-11 19:05:01 +1000 | [diff] [blame^] | 45 | nv_wr32(pfb, 0x100604 + (i * 0x10), tile->limit); |
| 46 | nv_wr32(pfb, 0x100608 + (i * 0x10), tile->pitch); |
| 47 | nv_wr32(pfb, 0x100600 + (i * 0x10), tile->addr); |
| 48 | } |
Ben Skeggs | 7948758 | 2011-01-11 14:52:40 +1000 | [diff] [blame] | 49 | |
Ben Skeggs | 861d210 | 2012-07-11 19:05:01 +1000 | [diff] [blame^] | 50 | static void |
| 51 | nv40_fb_init_gart(struct nv40_fb_priv *priv) |
| 52 | { |
| 53 | #if 0 |
| 54 | struct nouveau_gpuobj *gart = ndev->gart_info.sg_ctxdma; |
| 55 | |
| 56 | if (ndev->gart_info.type != NOUVEAU_GART_HW) { |
| 57 | #endif |
| 58 | nv_wr32(priv, 0x100800, 0x00000001); |
| 59 | #if 0 |
Ben Skeggs | 7948758 | 2011-01-11 14:52:40 +1000 | [diff] [blame] | 60 | return; |
| 61 | } |
| 62 | |
Ben Skeggs | 861d210 | 2012-07-11 19:05:01 +1000 | [diff] [blame^] | 63 | nv_wr32(ndev, 0x100800, gart->pinst | 0x00000002); |
| 64 | nv_mask(ndev, 0x10008c, 0x00000100, 0x00000100); |
| 65 | nv_wr32(ndev, 0x100820, 0x00000000); |
| 66 | #endif |
Ben Skeggs | 7948758 | 2011-01-11 14:52:40 +1000 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | static void |
Ben Skeggs | 861d210 | 2012-07-11 19:05:01 +1000 | [diff] [blame^] | 70 | nv44_fb_init_gart(struct nv40_fb_priv *priv) |
Ben Skeggs | 7948758 | 2011-01-11 14:52:40 +1000 | [diff] [blame] | 71 | { |
Ben Skeggs | 861d210 | 2012-07-11 19:05:01 +1000 | [diff] [blame^] | 72 | #if 0 |
| 73 | struct nouveau_gpuobj *gart = ndev->gart_info.sg_ctxdma; |
Ben Skeggs | 7948758 | 2011-01-11 14:52:40 +1000 | [diff] [blame] | 74 | u32 vinst; |
| 75 | |
Ben Skeggs | 861d210 | 2012-07-11 19:05:01 +1000 | [diff] [blame^] | 76 | if (ndev->gart_info.type != NOUVEAU_GART_HW) { |
| 77 | #endif |
| 78 | nv_wr32(priv, 0x100850, 0x80000000); |
| 79 | nv_wr32(priv, 0x100800, 0x00000001); |
| 80 | #if 0 |
Ben Skeggs | 7948758 | 2011-01-11 14:52:40 +1000 | [diff] [blame] | 81 | return; |
| 82 | } |
| 83 | |
| 84 | /* calculate vram address of this PRAMIN block, object |
| 85 | * must be allocated on 512KiB alignment, and not exceed |
| 86 | * a total size of 512KiB for this to work correctly |
| 87 | */ |
Ben Skeggs | 861d210 | 2012-07-11 19:05:01 +1000 | [diff] [blame^] | 88 | vinst = nv_rd32(ndev, 0x10020c); |
Ben Skeggs | 7948758 | 2011-01-11 14:52:40 +1000 | [diff] [blame] | 89 | vinst -= ((gart->pinst >> 19) + 1) << 19; |
| 90 | |
Ben Skeggs | 861d210 | 2012-07-11 19:05:01 +1000 | [diff] [blame^] | 91 | nv_wr32(ndev, 0x100850, 0x80000000); |
| 92 | nv_wr32(ndev, 0x100818, ndev->gart_info.dummy.addr); |
Ben Skeggs | 7948758 | 2011-01-11 14:52:40 +1000 | [diff] [blame] | 93 | |
Ben Skeggs | 861d210 | 2012-07-11 19:05:01 +1000 | [diff] [blame^] | 94 | nv_wr32(ndev, 0x100804, ndev->gart_info.aper_size); |
| 95 | nv_wr32(ndev, 0x100850, 0x00008000); |
| 96 | nv_mask(ndev, 0x10008c, 0x00000200, 0x00000200); |
| 97 | nv_wr32(ndev, 0x100820, 0x00000000); |
| 98 | nv_wr32(ndev, 0x10082c, 0x00000001); |
| 99 | nv_wr32(ndev, 0x100800, vinst | 0x00000010); |
| 100 | #endif |
Ben Skeggs | 7948758 | 2011-01-11 14:52:40 +1000 | [diff] [blame] | 101 | } |
| 102 | |
Ben Skeggs | 861d210 | 2012-07-11 19:05:01 +1000 | [diff] [blame^] | 103 | static int |
| 104 | nv40_fb_init(struct nouveau_object *object) |
Ben Skeggs | ff92a6c | 2011-12-12 23:03:14 +1000 | [diff] [blame] | 105 | { |
Ben Skeggs | 861d210 | 2012-07-11 19:05:01 +1000 | [diff] [blame^] | 106 | struct nv40_fb_priv *priv = (void *)object; |
| 107 | int ret; |
| 108 | |
| 109 | ret = nouveau_fb_init(&priv->base); |
| 110 | if (ret) |
| 111 | return ret; |
| 112 | |
| 113 | switch (nv_device(priv)->chipset) { |
| 114 | case 0x40: |
| 115 | case 0x45: |
| 116 | nv_mask(priv, 0x10033c, 0x00008000, 0x00000000); |
| 117 | break; |
| 118 | default: |
| 119 | if (nv44_graph_class(nv_device(priv))) |
| 120 | nv44_fb_init_gart(priv); |
| 121 | else |
| 122 | nv40_fb_init_gart(priv); |
| 123 | break; |
| 124 | } |
| 125 | |
| 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | static int |
| 130 | nv40_fb_ctor(struct nouveau_object *parent, struct nouveau_object *engine, |
| 131 | struct nouveau_oclass *oclass, void *data, u32 size, |
| 132 | struct nouveau_object **pobject) |
| 133 | { |
| 134 | struct nouveau_device *device = nv_device(parent); |
| 135 | struct nv40_fb_priv *priv; |
| 136 | int ret; |
| 137 | |
| 138 | ret = nouveau_fb_create(parent, engine, oclass, &priv); |
| 139 | *pobject = nv_object(priv); |
| 140 | if (ret) |
| 141 | return ret; |
Ben Skeggs | ff92a6c | 2011-12-12 23:03:14 +1000 | [diff] [blame] | 142 | |
| 143 | /* 0x001218 is actually present on a few other NV4X I looked at, |
| 144 | * and even contains sane values matching 0x100474. From looking |
| 145 | * at various vbios images however, this isn't the case everywhere. |
| 146 | * So, I chose to use the same regs I've seen NVIDIA reading around |
| 147 | * the memory detection, hopefully that'll get us the right numbers |
| 148 | */ |
Ben Skeggs | 861d210 | 2012-07-11 19:05:01 +1000 | [diff] [blame^] | 149 | if (device->chipset == 0x40) { |
| 150 | u32 pbus1218 = nv_rd32(priv, 0x001218); |
Ben Skeggs | ff92a6c | 2011-12-12 23:03:14 +1000 | [diff] [blame] | 151 | switch (pbus1218 & 0x00000300) { |
Ben Skeggs | 861d210 | 2012-07-11 19:05:01 +1000 | [diff] [blame^] | 152 | case 0x00000000: priv->base.ram.type = NV_MEM_TYPE_SDRAM; break; |
| 153 | case 0x00000100: priv->base.ram.type = NV_MEM_TYPE_DDR1; break; |
| 154 | case 0x00000200: priv->base.ram.type = NV_MEM_TYPE_GDDR3; break; |
| 155 | case 0x00000300: priv->base.ram.type = NV_MEM_TYPE_DDR2; break; |
Ben Skeggs | ff92a6c | 2011-12-12 23:03:14 +1000 | [diff] [blame] | 156 | } |
| 157 | } else |
Ben Skeggs | 861d210 | 2012-07-11 19:05:01 +1000 | [diff] [blame^] | 158 | if (device->chipset == 0x49 || device->chipset == 0x4b) { |
| 159 | u32 pfb914 = nv_rd32(priv, 0x100914); |
Ben Skeggs | ff92a6c | 2011-12-12 23:03:14 +1000 | [diff] [blame] | 160 | switch (pfb914 & 0x00000003) { |
Ben Skeggs | 861d210 | 2012-07-11 19:05:01 +1000 | [diff] [blame^] | 161 | case 0x00000000: priv->base.ram.type = NV_MEM_TYPE_DDR1; break; |
| 162 | case 0x00000001: priv->base.ram.type = NV_MEM_TYPE_DDR2; break; |
| 163 | case 0x00000002: priv->base.ram.type = NV_MEM_TYPE_GDDR3; break; |
Ben Skeggs | ff92a6c | 2011-12-12 23:03:14 +1000 | [diff] [blame] | 164 | case 0x00000003: break; |
| 165 | } |
| 166 | } else |
Ben Skeggs | 861d210 | 2012-07-11 19:05:01 +1000 | [diff] [blame^] | 167 | if (device->chipset != 0x4e) { |
| 168 | u32 pfb474 = nv_rd32(priv, 0x100474); |
Ben Skeggs | ff92a6c | 2011-12-12 23:03:14 +1000 | [diff] [blame] | 169 | if (pfb474 & 0x00000004) |
Ben Skeggs | 861d210 | 2012-07-11 19:05:01 +1000 | [diff] [blame^] | 170 | priv->base.ram.type = NV_MEM_TYPE_GDDR3; |
Ben Skeggs | ff92a6c | 2011-12-12 23:03:14 +1000 | [diff] [blame] | 171 | if (pfb474 & 0x00000002) |
Ben Skeggs | 861d210 | 2012-07-11 19:05:01 +1000 | [diff] [blame^] | 172 | priv->base.ram.type = NV_MEM_TYPE_DDR2; |
Ben Skeggs | ff92a6c | 2011-12-12 23:03:14 +1000 | [diff] [blame] | 173 | if (pfb474 & 0x00000001) |
Ben Skeggs | 861d210 | 2012-07-11 19:05:01 +1000 | [diff] [blame^] | 174 | priv->base.ram.type = NV_MEM_TYPE_DDR1; |
Ben Skeggs | ff92a6c | 2011-12-12 23:03:14 +1000 | [diff] [blame] | 175 | } else { |
Ben Skeggs | 861d210 | 2012-07-11 19:05:01 +1000 | [diff] [blame^] | 176 | priv->base.ram.type = NV_MEM_TYPE_STOLEN; |
Ben Skeggs | ff92a6c | 2011-12-12 23:03:14 +1000 | [diff] [blame] | 177 | } |
| 178 | |
Ben Skeggs | 861d210 | 2012-07-11 19:05:01 +1000 | [diff] [blame^] | 179 | priv->base.ram.size = nv_rd32(priv, 0x10020c) & 0xff000000; |
Ben Skeggs | ff92a6c | 2011-12-12 23:03:14 +1000 | [diff] [blame] | 180 | |
Ben Skeggs | 861d210 | 2012-07-11 19:05:01 +1000 | [diff] [blame^] | 181 | priv->base.memtype_valid = nv04_fb_memtype_valid; |
| 182 | switch (device->chipset) { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 183 | case 0x40: |
| 184 | case 0x45: |
Ben Skeggs | 861d210 | 2012-07-11 19:05:01 +1000 | [diff] [blame^] | 185 | priv->base.tile.regions = 8; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 186 | break; |
Ben Skeggs | 861d210 | 2012-07-11 19:05:01 +1000 | [diff] [blame^] | 187 | case 0x46: |
| 188 | case 0x47: |
| 189 | case 0x49: |
| 190 | case 0x4b: |
| 191 | case 0x4c: |
| 192 | priv->base.tile.regions = 15; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 193 | break; |
| 194 | default: |
Ben Skeggs | 861d210 | 2012-07-11 19:05:01 +1000 | [diff] [blame^] | 195 | priv->base.tile.regions = 12; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 196 | break; |
| 197 | } |
Ben Skeggs | 861d210 | 2012-07-11 19:05:01 +1000 | [diff] [blame^] | 198 | priv->base.tile.init = nv30_fb_tile_init; |
| 199 | priv->base.tile.fini = nv30_fb_tile_fini; |
| 200 | if (device->chipset == 0x40) |
| 201 | priv->base.tile.prog = nv10_fb_tile_prog; |
| 202 | else |
| 203 | priv->base.tile.prog = nv40_fb_tile_prog; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 204 | |
Ben Skeggs | 861d210 | 2012-07-11 19:05:01 +1000 | [diff] [blame^] | 205 | return nouveau_fb_created(&priv->base); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 206 | } |
| 207 | |
Ben Skeggs | 861d210 | 2012-07-11 19:05:01 +1000 | [diff] [blame^] | 208 | |
| 209 | struct nouveau_oclass |
| 210 | nv40_fb_oclass = { |
| 211 | .handle = NV_SUBDEV(FB, 0x40), |
| 212 | .ofuncs = &(struct nouveau_ofuncs) { |
| 213 | .ctor = nv40_fb_ctor, |
| 214 | .dtor = _nouveau_fb_dtor, |
| 215 | .init = nv40_fb_init, |
| 216 | .fini = _nouveau_fb_fini, |
| 217 | }, |
| 218 | }; |