Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright 2012 Red Hat Inc.
0003  *
0004  * Permission is hereby granted, free of charge, to any person obtaining a
0005  * copy of this software and associated documentation files (the "Software"),
0006  * to deal in the Software without restriction, including without limitation
0007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0008  * and/or sell copies of the Software, and to permit persons to whom the
0009  * Software is furnished to do so, subject to the following conditions:
0010  *
0011  * The above copyright notice and this permission notice shall be included in
0012  * all copies or substantial portions of the Software.
0013  *
0014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0017  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
0018  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0020  * OTHER DEALINGS IN THE SOFTWARE.
0021  *
0022  * Authors: Ben Skeggs
0023  */
0024 #include <subdev/bios.h>
0025 #include <subdev/bios/bit.h>
0026 #include <subdev/bios/disp.h>
0027 
0028 u16
0029 nvbios_disp_table(struct nvkm_bios *bios,
0030           u8 *ver, u8 *hdr, u8 *cnt, u8 *len, u8 *sub)
0031 {
0032     struct bit_entry U;
0033 
0034     if (!bit_entry(bios, 'U', &U)) {
0035         if (U.version == 1) {
0036             u16 data = nvbios_rd16(bios, U.offset);
0037             if (data) {
0038                 *ver = nvbios_rd08(bios, data + 0x00);
0039                 switch (*ver) {
0040                 case 0x20:
0041                 case 0x21:
0042                 case 0x22:
0043                     *hdr = nvbios_rd08(bios, data + 0x01);
0044                     *len = nvbios_rd08(bios, data + 0x02);
0045                     *cnt = nvbios_rd08(bios, data + 0x03);
0046                     *sub = nvbios_rd08(bios, data + 0x04);
0047                     return data;
0048                 default:
0049                     break;
0050                 }
0051             }
0052         }
0053     }
0054 
0055     return 0x0000;
0056 }
0057 
0058 u16
0059 nvbios_disp_entry(struct nvkm_bios *bios, u8 idx, u8 *ver, u8 *len, u8 *sub)
0060 {
0061     u8  hdr, cnt;
0062     u16 data = nvbios_disp_table(bios, ver, &hdr, &cnt, len, sub);
0063     if (data && idx < cnt)
0064         return data + hdr + (idx * *len);
0065     *ver = 0x00;
0066     return 0x0000;
0067 }
0068 
0069 u16
0070 nvbios_disp_parse(struct nvkm_bios *bios, u8 idx, u8 *ver, u8 *len, u8 *sub,
0071           struct nvbios_disp *info)
0072 {
0073     u16 data = nvbios_disp_entry(bios, idx, ver, len, sub);
0074     if (data && *len >= 2) {
0075         info->data = nvbios_rd16(bios, data + 0);
0076         return data;
0077     }
0078     return 0x0000;
0079 }
0080 
0081 u16
0082 nvbios_outp_entry(struct nvkm_bios *bios, u8 idx,
0083           u8 *ver, u8 *hdr, u8 *cnt, u8 *len)
0084 {
0085     struct nvbios_disp info;
0086     u16 data = nvbios_disp_parse(bios, idx, ver, len, hdr, &info);
0087     if (data) {
0088         *cnt = nvbios_rd08(bios, info.data + 0x05);
0089         *len = 0x06;
0090         data = info.data;
0091     }
0092     return data;
0093 }
0094 
0095 u16
0096 nvbios_outp_parse(struct nvkm_bios *bios, u8 idx,
0097           u8 *ver, u8 *hdr, u8 *cnt, u8 *len, struct nvbios_outp *info)
0098 {
0099     u16 data = nvbios_outp_entry(bios, idx, ver, hdr, cnt, len);
0100     if (data && *hdr >= 0x0a) {
0101         info->type      = nvbios_rd16(bios, data + 0x00);
0102         info->mask      = nvbios_rd32(bios, data + 0x02);
0103         if (*ver <= 0x20) /* match any link */
0104             info->mask |= 0x00c0;
0105         info->script[0] = nvbios_rd16(bios, data + 0x06);
0106         info->script[1] = nvbios_rd16(bios, data + 0x08);
0107         info->script[2] = 0x0000;
0108         if (*hdr >= 0x0c)
0109             info->script[2] = nvbios_rd16(bios, data + 0x0a);
0110         return data;
0111     }
0112     return 0x0000;
0113 }
0114 
0115 u16
0116 nvbios_outp_match(struct nvkm_bios *bios, u16 type, u16 mask,
0117           u8 *ver, u8 *hdr, u8 *cnt, u8 *len, struct nvbios_outp *info)
0118 {
0119     u16 data, idx = 0;
0120     while ((data = nvbios_outp_parse(bios, idx++, ver, hdr, cnt, len, info)) || *ver) {
0121         if (data && info->type == type) {
0122             if ((info->mask & mask) == mask)
0123                 break;
0124         }
0125     }
0126     return data;
0127 }
0128 
0129 u16
0130 nvbios_ocfg_entry(struct nvkm_bios *bios, u16 outp, u8 idx,
0131           u8 *ver, u8 *hdr, u8 *cnt, u8 *len)
0132 {
0133     if (idx < *cnt)
0134         return outp + *hdr + (idx * *len);
0135     return 0x0000;
0136 }
0137 
0138 u16
0139 nvbios_ocfg_parse(struct nvkm_bios *bios, u16 outp, u8 idx,
0140           u8 *ver, u8 *hdr, u8 *cnt, u8 *len, struct nvbios_ocfg *info)
0141 {
0142     u16 data = nvbios_ocfg_entry(bios, outp, idx, ver, hdr, cnt, len);
0143     if (data) {
0144         info->proto     = nvbios_rd08(bios, data + 0x00);
0145         info->flags     = nvbios_rd16(bios, data + 0x01);
0146         info->clkcmp[0] = nvbios_rd16(bios, data + 0x02);
0147         info->clkcmp[1] = nvbios_rd16(bios, data + 0x04);
0148     }
0149     return data;
0150 }
0151 
0152 u16
0153 nvbios_ocfg_match(struct nvkm_bios *bios, u16 outp, u8 proto, u8 flags,
0154           u8 *ver, u8 *hdr, u8 *cnt, u8 *len, struct nvbios_ocfg *info)
0155 {
0156     u16 data, idx = 0;
0157     while ((data = nvbios_ocfg_parse(bios, outp, idx++, ver, hdr, cnt, len, info))) {
0158         if ((info->proto == proto || info->proto == 0xff) &&
0159             (info->flags == flags))
0160             break;
0161     }
0162     return data;
0163 }
0164 
0165 u16
0166 nvbios_oclk_match(struct nvkm_bios *bios, u16 cmp, u32 khz)
0167 {
0168     while (cmp) {
0169         if (khz / 10 >= nvbios_rd16(bios, cmp + 0x00))
0170             return  nvbios_rd16(bios, cmp + 0x02);
0171         cmp += 0x04;
0172     }
0173     return 0x0000;
0174 }