| 1 | /* $NetBSD: nouveau_subdev_bios_ramcfg.c,v 1.1.1.1 2014/08/06 12:36:29 riastradh Exp $ */ |
| 2 | |
| 3 | /* |
| 4 | * Copyright 2013 Red Hat Inc. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in |
| 14 | * all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 20 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 21 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 22 | * OTHER DEALINGS IN THE SOFTWARE. |
| 23 | * |
| 24 | * Authors: Ben Skeggs <bskeggs@redhat.com> |
| 25 | */ |
| 26 | |
| 27 | #include <sys/cdefs.h> |
| 28 | __KERNEL_RCSID(0, "$NetBSD: nouveau_subdev_bios_ramcfg.c,v 1.1.1.1 2014/08/06 12:36:29 riastradh Exp $" ); |
| 29 | |
| 30 | #include <subdev/bios.h> |
| 31 | #include <subdev/bios/bit.h> |
| 32 | #include <subdev/bios/ramcfg.h> |
| 33 | |
| 34 | static u8 |
| 35 | nvbios_ramcfg_strap(struct nouveau_subdev *subdev) |
| 36 | { |
| 37 | return (nv_rd32(subdev, 0x101000) & 0x0000003c) >> 2; |
| 38 | } |
| 39 | |
| 40 | u8 |
| 41 | nvbios_ramcfg_count(struct nouveau_bios *bios) |
| 42 | { |
| 43 | struct bit_entry bit_M; |
| 44 | |
| 45 | if (!bit_entry(bios, 'M', &bit_M)) { |
| 46 | if (bit_M.version == 1 && bit_M.length >= 5) |
| 47 | return nv_ro08(bios, bit_M.offset + 2); |
| 48 | if (bit_M.version == 2 && bit_M.length >= 3) |
| 49 | return nv_ro08(bios, bit_M.offset + 0); |
| 50 | } |
| 51 | |
| 52 | return 0x00; |
| 53 | } |
| 54 | |
| 55 | u8 |
| 56 | nvbios_ramcfg_index(struct nouveau_subdev *subdev) |
| 57 | { |
| 58 | struct nouveau_bios *bios = nouveau_bios(subdev); |
| 59 | u8 strap = nvbios_ramcfg_strap(subdev); |
| 60 | u32 xlat = 0x00000000; |
| 61 | struct bit_entry bit_M; |
| 62 | |
| 63 | if (!bit_entry(bios, 'M', &bit_M)) { |
| 64 | if (bit_M.version == 1 && bit_M.length >= 5) |
| 65 | xlat = nv_ro16(bios, bit_M.offset + 3); |
| 66 | if (bit_M.version == 2 && bit_M.length >= 3) |
| 67 | xlat = nv_ro16(bios, bit_M.offset + 1); |
| 68 | } |
| 69 | |
| 70 | if (xlat) |
| 71 | strap = nv_ro08(bios, xlat + strap); |
| 72 | return strap; |
| 73 | } |
| 74 | |