Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright 2012 Nouveau Community
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: Martin Peres
0023  */
0024 #include <subdev/bios.h>
0025 #include <subdev/bios/dcb.h>
0026 #include <subdev/bios/extdev.h>
0027 
0028 static u16
0029 extdev_table(struct nvkm_bios *bios, u8 *ver, u8 *hdr, u8 *len, u8 *cnt)
0030 {
0031     u8  dcb_ver, dcb_hdr, dcb_cnt, dcb_len;
0032     u16 dcb, extdev = 0;
0033 
0034     dcb = dcb_table(bios, &dcb_ver, &dcb_hdr, &dcb_cnt, &dcb_len);
0035     if (!dcb || (dcb_ver != 0x30 && dcb_ver != 0x40 && dcb_ver != 0x41))
0036         return 0x0000;
0037 
0038     extdev = nvbios_rd16(bios, dcb + 18);
0039     if (!extdev)
0040         return 0x0000;
0041 
0042     *ver = nvbios_rd08(bios, extdev + 0);
0043     *hdr = nvbios_rd08(bios, extdev + 1);
0044     *cnt = nvbios_rd08(bios, extdev + 2);
0045     *len = nvbios_rd08(bios, extdev + 3);
0046     return extdev + *hdr;
0047 }
0048 
0049 bool
0050 nvbios_extdev_skip_probe(struct nvkm_bios *bios)
0051 {
0052     u8  ver, hdr, len, cnt;
0053     u16 data = extdev_table(bios, &ver, &hdr, &len, &cnt);
0054     if (data && ver == 0x40 && hdr >= 5) {
0055         u8 flags = nvbios_rd08(bios, data - hdr + 4);
0056         if (flags & 1)
0057             return true;
0058     }
0059     return false;
0060 }
0061 
0062 static u16
0063 nvbios_extdev_entry(struct nvkm_bios *bios, int idx, u8 *ver, u8 *len)
0064 {
0065     u8 hdr, cnt;
0066     u16 extdev = extdev_table(bios, ver, &hdr, len, &cnt);
0067     if (extdev && idx < cnt)
0068         return extdev + idx * *len;
0069     return 0x0000;
0070 }
0071 
0072 static void
0073 extdev_parse_entry(struct nvkm_bios *bios, u16 offset,
0074            struct nvbios_extdev_func *entry)
0075 {
0076     entry->type = nvbios_rd08(bios, offset + 0);
0077     entry->addr = nvbios_rd08(bios, offset + 1);
0078     entry->bus = (nvbios_rd08(bios, offset + 2) >> 4) & 1;
0079 }
0080 
0081 int
0082 nvbios_extdev_parse(struct nvkm_bios *bios, int idx,
0083             struct nvbios_extdev_func *func)
0084 {
0085     u8 ver, len;
0086     u16 entry;
0087 
0088     if (!(entry = nvbios_extdev_entry(bios, idx, &ver, &len)))
0089         return -EINVAL;
0090 
0091     extdev_parse_entry(bios, entry, func);
0092     return 0;
0093 }
0094 
0095 int
0096 nvbios_extdev_find(struct nvkm_bios *bios, enum nvbios_extdev_type type,
0097            struct nvbios_extdev_func *func)
0098 {
0099     u8 ver, len, i;
0100     u16 entry;
0101 
0102     i = 0;
0103     while ((entry = nvbios_extdev_entry(bios, i++, &ver, &len))) {
0104         extdev_parse_entry(bios, entry, func);
0105         if (func->type == type)
0106             return 0;
0107     }
0108 
0109     return -EINVAL;
0110 }