• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2012 Nouveau Community
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: Martin Peres
23  */
24 
25 #include <subdev/bios.h>
26 #include <subdev/bios/bit.h>
27 #include <subdev/bios/vmap.h>
28 
29 u16
nvbios_vmap_table(struct nouveau_bios * bios,u8 * ver,u8 * hdr,u8 * cnt,u8 * len)30 nvbios_vmap_table(struct nouveau_bios *bios, u8 *ver, u8 *hdr, u8 *cnt, u8 *len)
31 {
32 	struct bit_entry bit_P;
33 	u16 vmap = 0x0000;
34 
35 	if (!bit_entry(bios, 'P', &bit_P)) {
36 		if (bit_P.version == 2) {
37 			vmap = nv_ro16(bios, bit_P.offset + 0x20);
38 			if (vmap) {
39 				*ver = nv_ro08(bios, vmap + 0);
40 				switch (*ver) {
41 				case 0x10:
42 				case 0x20:
43 					*hdr = nv_ro08(bios, vmap + 1);
44 					*cnt = nv_ro08(bios, vmap + 3);
45 					*len = nv_ro08(bios, vmap + 2);
46 					return vmap;
47 				default:
48 					break;
49 				}
50 			}
51 		}
52 	}
53 
54 	return 0x0000;
55 }
56 
57 u16
nvbios_vmap_parse(struct nouveau_bios * bios,u8 * ver,u8 * hdr,u8 * cnt,u8 * len,struct nvbios_vmap * info)58 nvbios_vmap_parse(struct nouveau_bios *bios, u8 *ver, u8 *hdr, u8 *cnt, u8 *len,
59 		  struct nvbios_vmap *info)
60 {
61 	u16 vmap = nvbios_vmap_table(bios, ver, hdr, cnt, len);
62 	memset(info, 0x00, sizeof(*info));
63 	switch (!!vmap * *ver) {
64 	case 0x10:
65 	case 0x20:
66 		break;
67 	}
68 	return vmap;
69 }
70 
71 u16
nvbios_vmap_entry(struct nouveau_bios * bios,int idx,u8 * ver,u8 * len)72 nvbios_vmap_entry(struct nouveau_bios *bios, int idx, u8 *ver, u8 *len)
73 {
74 	u8  hdr, cnt;
75 	u16 vmap = nvbios_vmap_table(bios, ver, &hdr, &cnt, len);
76 	if (vmap && idx < cnt) {
77 		vmap = vmap + hdr + (idx * *len);
78 		return vmap;
79 	}
80 	return 0x0000;
81 }
82 
83 u16
nvbios_vmap_entry_parse(struct nouveau_bios * bios,int idx,u8 * ver,u8 * len,struct nvbios_vmap_entry * info)84 nvbios_vmap_entry_parse(struct nouveau_bios *bios, int idx, u8 *ver, u8 *len,
85 			struct nvbios_vmap_entry *info)
86 {
87 	u16 vmap = nvbios_vmap_entry(bios, idx, ver, len);
88 	memset(info, 0x00, sizeof(*info));
89 	switch (!!vmap * *ver) {
90 	case 0x10:
91 		info->link   = 0xff;
92 		info->min    = nv_ro32(bios, vmap + 0x00);
93 		info->max    = nv_ro32(bios, vmap + 0x04);
94 		info->arg[0] = nv_ro32(bios, vmap + 0x08);
95 		info->arg[1] = nv_ro32(bios, vmap + 0x0c);
96 		info->arg[2] = nv_ro32(bios, vmap + 0x10);
97 		break;
98 	case 0x20:
99 		info->unk0   = nv_ro08(bios, vmap + 0x00);
100 		info->link   = nv_ro08(bios, vmap + 0x01);
101 		info->min    = nv_ro32(bios, vmap + 0x02);
102 		info->max    = nv_ro32(bios, vmap + 0x06);
103 		info->arg[0] = nv_ro32(bios, vmap + 0x0a);
104 		info->arg[1] = nv_ro32(bios, vmap + 0x0e);
105 		info->arg[2] = nv_ro32(bios, vmap + 0x12);
106 		info->arg[3] = nv_ro32(bios, vmap + 0x16);
107 		info->arg[4] = nv_ro32(bios, vmap + 0x1a);
108 		info->arg[5] = nv_ro32(bios, vmap + 0x1e);
109 		break;
110 	}
111 	return vmap;
112 }
113