drm/nouveau/bar: namespace + nvidia gpu names (no binary change)
[deliverable/linux.git] / drivers / gpu / drm / nouveau / nvkm / subdev / bios / pmu.c
CommitLineData
50e216d6
BS
1/*
2 * Copyright 2014 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 <bskeggs@redhat.com>
23 */
24
25#include <subdev/bios.h>
26#include <subdev/bios/bit.h>
27#include <subdev/bios/image.h>
28#include <subdev/bios/pmu.h>
29
30static u32
31weirdo_pointer(struct nouveau_bios *bios, u32 data)
32{
33 struct nvbios_image image;
34 int idx = 0;
35 if (nvbios_image(bios, idx++, &image)) {
36 data -= image.size;
37 while (nvbios_image(bios, idx++, &image)) {
38 if (image.type == 0xe0)
39 return image.base + data;
40 }
41 }
42 return 0;
43}
44
45u32
46nvbios_pmuTe(struct nouveau_bios *bios, u8 *ver, u8 *hdr, u8 *cnt, u8 *len)
47{
48 struct bit_entry bit_p;
49 u32 data = 0;
50
51 if (!bit_entry(bios, 'p', &bit_p)) {
52 if (bit_p.version == 2 && bit_p.length >= 4)
53 data = nv_ro32(bios, bit_p.offset + 0x00);
54 if ((data = weirdo_pointer(bios, data))) {
55 *ver = nv_ro08(bios, data + 0x00); /* maybe? */
56 *hdr = nv_ro08(bios, data + 0x01);
57 *len = nv_ro08(bios, data + 0x02);
58 *cnt = nv_ro08(bios, data + 0x03);
59 }
60 }
61
62 return data;
63}
64
65u32
66nvbios_pmuTp(struct nouveau_bios *bios, u8 *ver, u8 *hdr, u8 *cnt, u8 *len,
67 struct nvbios_pmuT *info)
68{
69 u32 data = nvbios_pmuTe(bios, ver, hdr, cnt, len);
70 memset(info, 0x00, sizeof(*info));
71 switch (!!data * *ver) {
72 default:
73 break;
74 }
75 return data;
76}
77
78u32
79nvbios_pmuEe(struct nouveau_bios *bios, int idx, u8 *ver, u8 *hdr)
80{
81 u8 cnt, len;
82 u32 data = nvbios_pmuTe(bios, ver, hdr, &cnt, &len);
83 if (data && idx < cnt) {
84 data = data + *hdr + (idx * len);
85 *hdr = len;
86 return data;
87 }
88 return 0;
89}
90
91u32
92nvbios_pmuEp(struct nouveau_bios *bios, int idx, u8 *ver, u8 *hdr,
93 struct nvbios_pmuE *info)
94{
95 u32 data = nvbios_pmuEe(bios, idx, ver, hdr);
96 memset(info, 0x00, sizeof(*info));
97 switch (!!data * *ver) {
98 default:
99 info->type = nv_ro08(bios, data + 0x00);
100 info->data = nv_ro32(bios, data + 0x02);
101 break;
102 }
103 return data;
104}
105
106bool
107nvbios_pmuRm(struct nouveau_bios *bios, u8 type, struct nvbios_pmuR *info)
108{
109 struct nvbios_pmuE pmuE;
110 u8 ver, hdr, idx = 0;
111 u32 data;
112 memset(info, 0x00, sizeof(*info));
113 while ((data = nvbios_pmuEp(bios, idx++, &ver, &hdr, &pmuE))) {
114 if ( pmuE.type == type &&
115 (data = weirdo_pointer(bios, pmuE.data))) {
116 info->init_addr_pmu = nv_ro32(bios, data + 0x08);
117 info->args_addr_pmu = nv_ro32(bios, data + 0x0c);
118 info->boot_addr = data + 0x30;
119 info->boot_addr_pmu = nv_ro32(bios, data + 0x10) +
120 nv_ro32(bios, data + 0x18);
121 info->boot_size = nv_ro32(bios, data + 0x1c) -
122 nv_ro32(bios, data + 0x18);
123 info->code_addr = info->boot_addr + info->boot_size;
124 info->code_addr_pmu = info->boot_addr_pmu +
125 info->boot_size;
126 info->code_size = nv_ro32(bios, data + 0x20);
127 info->data_addr = data + 0x30 +
128 nv_ro32(bios, data + 0x24);
129 info->data_addr_pmu = nv_ro32(bios, data + 0x28);
130 info->data_size = nv_ro32(bios, data + 0x2c);
131 return true;
132 }
133 }
134 return false;
135}
This page took 0.051546 seconds and 5 git commands to generate.