Ben Skeggs | 0a0dc8f | 2013-11-27 11:28:19 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 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 <bskeggs@redhat.com> |
| 23 | */ |
| 24 | |
| 25 | #include <subdev/bios.h> |
| 26 | #include <subdev/bios/bit.h> |
| 27 | #include <subdev/bios/ramcfg.h> |
Ben Skeggs | 15606cb | 2014-11-04 15:13:30 +1000 | [diff] [blame] | 28 | #include <subdev/bios/M0203.h> |
Ben Skeggs | 0a0dc8f | 2013-11-27 11:28:19 +1000 | [diff] [blame] | 29 | |
| 30 | static u8 |
Ben Skeggs | 0a8649f | 2014-03-19 00:55:02 +1000 | [diff] [blame] | 31 | nvbios_ramcfg_strap(struct nouveau_subdev *subdev) |
Ben Skeggs | 0a0dc8f | 2013-11-27 11:28:19 +1000 | [diff] [blame] | 32 | { |
Ben Skeggs | 0a8649f | 2014-03-19 00:55:02 +1000 | [diff] [blame] | 33 | return (nv_rd32(subdev, 0x101000) & 0x0000003c) >> 2; |
Ben Skeggs | 0a0dc8f | 2013-11-27 11:28:19 +1000 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | u8 |
| 37 | nvbios_ramcfg_count(struct nouveau_bios *bios) |
| 38 | { |
| 39 | struct bit_entry bit_M; |
| 40 | |
| 41 | if (!bit_entry(bios, 'M', &bit_M)) { |
| 42 | if (bit_M.version == 1 && bit_M.length >= 5) |
| 43 | return nv_ro08(bios, bit_M.offset + 2); |
| 44 | if (bit_M.version == 2 && bit_M.length >= 3) |
| 45 | return nv_ro08(bios, bit_M.offset + 0); |
| 46 | } |
| 47 | |
| 48 | return 0x00; |
| 49 | } |
| 50 | |
| 51 | u8 |
Ben Skeggs | 0a8649f | 2014-03-19 00:55:02 +1000 | [diff] [blame] | 52 | nvbios_ramcfg_index(struct nouveau_subdev *subdev) |
Ben Skeggs | 0a0dc8f | 2013-11-27 11:28:19 +1000 | [diff] [blame] | 53 | { |
Ben Skeggs | 0a8649f | 2014-03-19 00:55:02 +1000 | [diff] [blame] | 54 | struct nouveau_bios *bios = nouveau_bios(subdev); |
| 55 | u8 strap = nvbios_ramcfg_strap(subdev); |
Ben Skeggs | 0a0dc8f | 2013-11-27 11:28:19 +1000 | [diff] [blame] | 56 | u32 xlat = 0x00000000; |
| 57 | struct bit_entry bit_M; |
Ben Skeggs | 15606cb | 2014-11-04 15:13:30 +1000 | [diff] [blame] | 58 | struct nvbios_M0203E M0203E; |
| 59 | u8 ver, hdr; |
Ben Skeggs | 0a0dc8f | 2013-11-27 11:28:19 +1000 | [diff] [blame] | 60 | |
| 61 | if (!bit_entry(bios, 'M', &bit_M)) { |
| 62 | if (bit_M.version == 1 && bit_M.length >= 5) |
| 63 | xlat = nv_ro16(bios, bit_M.offset + 3); |
Ben Skeggs | 15606cb | 2014-11-04 15:13:30 +1000 | [diff] [blame] | 64 | if (bit_M.version == 2 && bit_M.length >= 3) { |
| 65 | /*XXX: is M ever shorter than this? |
| 66 | * if not - what is xlat used for now? |
| 67 | * also - sigh.. |
| 68 | */ |
| 69 | if (bit_M.length >= 7 && |
| 70 | nvbios_M0203Em(bios, strap, &ver, &hdr, &M0203E)) |
| 71 | return M0203E.group; |
Ben Skeggs | 0a0dc8f | 2013-11-27 11:28:19 +1000 | [diff] [blame] | 72 | xlat = nv_ro16(bios, bit_M.offset + 1); |
Ben Skeggs | 15606cb | 2014-11-04 15:13:30 +1000 | [diff] [blame] | 73 | } |
Ben Skeggs | 0a0dc8f | 2013-11-27 11:28:19 +1000 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | if (xlat) |
| 77 | strap = nv_ro08(bios, xlat + strap); |
| 78 | return strap; |
| 79 | } |