Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
dp.c
Go to the documentation of this file.
1 /*
2  * Copyright 2012 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
23  */
24 
25 
26 #include "subdev/bios.h"
27 #include "subdev/bios/bit.h"
28 #include "subdev/bios/dcb.h"
29 #include "subdev/bios/dp.h"
30 
31 u16
32 dp_table(struct nouveau_bios *bios, u8 *ver, u8 *hdr, u8 *cnt, u8 *len)
33 {
34  struct bit_entry bit_d;
35 
36  if (!bit_entry(bios, 'd', &bit_d)) {
37  if (bit_d.version == 1) {
38  u16 data = nv_ro16(bios, bit_d.offset);
39  if (data) {
40  *ver = nv_ro08(bios, data + 0);
41  *hdr = nv_ro08(bios, data + 1);
42  *len = nv_ro08(bios, data + 2);
43  *cnt = nv_ro08(bios, data + 3);
44  return data;
45  }
46  }
47  }
48 
49  return 0x0000;
50 }
51 
52 u16
53 dp_outp(struct nouveau_bios *bios, u8 idx, u8 *ver, u8 *len)
54 {
55  u8 hdr, cnt;
56  u16 table = dp_table(bios, ver, &hdr, &cnt, len);
57  if (table && idx < cnt)
58  return nv_ro16(bios, table + hdr + (idx * *len));
59  return 0xffff;
60 }
61 
62 u16
64  u8 *ver, u8 *len)
65 {
66  u8 idx = 0;
67  u16 data;
68  while ((data = dp_outp(bios, idx++, ver, len)) != 0xffff) {
69  if (data) {
70  u32 hash = nv_ro32(bios, data);
71  if (dcb_hash_match(outp, hash))
72  return data;
73  }
74  }
75  return 0x0000;
76 }