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