2 * Copyright 2014 Red Hat Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
24 #include <subdev/bios.h>
25 #include <subdev/bios/bit.h>
26 #include <subdev/bios/M0203.h>
29 nvbios_M0203Te(struct nvkm_bios
*bios
, u8
*ver
, u8
*hdr
, u8
*cnt
, u8
*len
)
31 struct bit_entry bit_M
;
32 u32 data
= 0x00000000;
34 if (!bit_entry(bios
, 'M', &bit_M
)) {
35 if (bit_M
.version
== 2 && bit_M
.length
> 0x04)
36 data
= nv_ro16(bios
, bit_M
.offset
+ 0x03);
38 *ver
= nv_ro08(bios
, data
+ 0x00);
41 *hdr
= nv_ro08(bios
, data
+ 0x01);
42 *len
= nv_ro08(bios
, data
+ 0x02);
43 *cnt
= nv_ro08(bios
, data
+ 0x03);
55 nvbios_M0203Tp(struct nvkm_bios
*bios
, u8
*ver
, u8
*hdr
, u8
*cnt
, u8
*len
,
56 struct nvbios_M0203T
*info
)
58 u32 data
= nvbios_M0203Te(bios
, ver
, hdr
, cnt
, len
);
59 memset(info
, 0x00, sizeof(*info
));
60 switch (!!data
* *ver
) {
62 info
->type
= nv_ro08(bios
, data
+ 0x04);
63 info
->pointer
= nv_ro16(bios
, data
+ 0x05);
72 nvbios_M0203Ee(struct nvkm_bios
*bios
, int idx
, u8
*ver
, u8
*hdr
)
75 u32 data
= nvbios_M0203Te(bios
, ver
, hdr
, &cnt
, &len
);
76 if (data
&& idx
< cnt
) {
77 data
= data
+ *hdr
+ idx
* len
;
85 nvbios_M0203Ep(struct nvkm_bios
*bios
, int idx
, u8
*ver
, u8
*hdr
,
86 struct nvbios_M0203E
*info
)
88 u32 data
= nvbios_M0203Ee(bios
, idx
, ver
, hdr
);
89 memset(info
, 0x00, sizeof(*info
));
90 switch (!!data
* *ver
) {
92 info
->type
= (nv_ro08(bios
, data
+ 0x00) & 0x0f) >> 0;
93 info
->strap
= (nv_ro08(bios
, data
+ 0x00) & 0xf0) >> 4;
94 info
->group
= (nv_ro08(bios
, data
+ 0x01) & 0x0f) >> 0;
103 nvbios_M0203Em(struct nvkm_bios
*bios
, u8 ramcfg
, u8
*ver
, u8
*hdr
,
104 struct nvbios_M0203E
*info
)
106 struct nvbios_M0203T M0203T
;
107 u8 cnt
, len
, idx
= 0xff;
110 if (!nvbios_M0203Tp(bios
, ver
, hdr
, &cnt
, &len
, &M0203T
)) {
111 nv_warn(bios
, "M0203T not found\n");
115 while ((data
= nvbios_M0203Ep(bios
, ++idx
, ver
, hdr
, info
))) {
116 switch (M0203T
.type
) {
117 case M0203T_TYPE_RAMCFG
:
118 if (info
->strap
!= ramcfg
)
122 nv_warn(bios
, "M0203T type %02x\n", M0203T
.type
);