| 1 | /* $NetBSD: nouveau_subdev_bios_P0260.c,v 1.1.1.1 2014/08/06 12:36:28 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 |
| 25 | */ |
| 26 | |
| 27 | #include <sys/cdefs.h> |
| 28 | __KERNEL_RCSID(0, "$NetBSD: nouveau_subdev_bios_P0260.c,v 1.1.1.1 2014/08/06 12:36:28 riastradh Exp $" ); |
| 29 | |
| 30 | #include <subdev/bios.h> |
| 31 | #include <subdev/bios/bit.h> |
| 32 | #include <subdev/bios/ramcfg.h> |
| 33 | #include <subdev/bios/P0260.h> |
| 34 | |
| 35 | u32 |
| 36 | nvbios_P0260Te(struct nouveau_bios *bios, |
| 37 | u8 *ver, u8 *hdr, u8 *cnt, u8 *len, u8 *xnr, u8 *xsz) |
| 38 | { |
| 39 | struct bit_entry bit_P; |
| 40 | u32 data = 0x00000000; |
| 41 | |
| 42 | if (!bit_entry(bios, 'P', &bit_P)) { |
| 43 | if (bit_P.version == 2 && bit_P.length > 0x63) |
| 44 | data = nv_ro32(bios, bit_P.offset + 0x60); |
| 45 | if (data) { |
| 46 | *ver = nv_ro08(bios, data + 0); |
| 47 | switch (*ver) { |
| 48 | case 0x10: |
| 49 | *hdr = nv_ro08(bios, data + 1); |
| 50 | *cnt = nv_ro08(bios, data + 2); |
| 51 | *len = 4; |
| 52 | *xnr = nv_ro08(bios, data + 3); |
| 53 | *xsz = 4; |
| 54 | return data; |
| 55 | default: |
| 56 | break; |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | return 0x00000000; |
| 62 | } |
| 63 | |
| 64 | u32 |
| 65 | nvbios_P0260Ee(struct nouveau_bios *bios, int idx, u8 *ver, u8 *len) |
| 66 | { |
| 67 | u8 hdr, cnt, xnr, xsz; |
| 68 | u32 data = nvbios_P0260Te(bios, ver, &hdr, &cnt, len, &xnr, &xsz); |
| 69 | if (data && idx < cnt) |
| 70 | return data + hdr + (idx * *len); |
| 71 | return 0x00000000; |
| 72 | } |
| 73 | |
| 74 | u32 |
| 75 | nvbios_P0260Ep(struct nouveau_bios *bios, int idx, u8 *ver, u8 *len, |
| 76 | struct nvbios_P0260E *info) |
| 77 | { |
| 78 | u32 data = nvbios_P0260Ee(bios, idx, ver, len); |
| 79 | memset(info, 0x00, sizeof(*info)); |
| 80 | switch (!!data * *ver) { |
| 81 | case 0x10: |
| 82 | info->data = nv_ro32(bios, data); |
| 83 | return data; |
| 84 | default: |
| 85 | break; |
| 86 | } |
| 87 | return 0x00000000; |
| 88 | } |
| 89 | |
| 90 | u32 |
| 91 | nvbios_P0260Xe(struct nouveau_bios *bios, int idx, u8 *ver, u8 *xsz) |
| 92 | { |
| 93 | u8 hdr, cnt, len, xnr; |
| 94 | u32 data = nvbios_P0260Te(bios, ver, &hdr, &cnt, &len, &xnr, xsz); |
| 95 | if (data && idx < xnr) |
| 96 | return data + hdr + (cnt * len) + (idx * *xsz); |
| 97 | return 0x00000000; |
| 98 | } |
| 99 | |
| 100 | u32 |
| 101 | nvbios_P0260Xp(struct nouveau_bios *bios, int idx, u8 *ver, u8 *hdr, |
| 102 | struct nvbios_P0260X *info) |
| 103 | { |
| 104 | u32 data = nvbios_P0260Xe(bios, idx, ver, hdr); |
| 105 | memset(info, 0x00, sizeof(*info)); |
| 106 | switch (!!data * *ver) { |
| 107 | case 0x10: |
| 108 | info->data = nv_ro32(bios, data); |
| 109 | return data; |
| 110 | default: |
| 111 | break; |
| 112 | } |
| 113 | return 0x00000000; |
| 114 | } |
| 115 | |