2 * Copyright 2012 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.
26 #include <subdev/bios.h>
27 #include <subdev/bios/bmp.h>
28 #include <subdev/bios/bit.h>
31 nvbios_checksum(const u8
*data
, int size
)
40 nvbios_findstr(const u8
*data
, int size
, const char *str
, int len
)
44 for (i
= 0; i
<= (size
- len
); i
++) {
45 for (j
= 0; j
< len
; j
++)
46 if ((char)data
[i
+ j
] != str
[j
])
56 nvbios_memcmp(struct nvkm_bios
*bios
, u32 addr
, const char *str
, u32 len
)
61 c1
= nvbios_rd08(bios
, addr
++);
70 nvbios_extend(struct nvkm_bios
*bios
, u32 length
)
72 if (bios
->size
< length
) {
73 u8
*prev
= bios
->data
;
74 if (!(bios
->data
= kmalloc(length
, GFP_KERNEL
))) {
78 memcpy(bios
->data
, prev
, bios
->size
);
87 nvkm_bios_dtor(struct nvkm_subdev
*subdev
)
89 struct nvkm_bios
*bios
= nvkm_bios(subdev
);
94 static const struct nvkm_subdev_func
96 .dtor
= nvkm_bios_dtor
,
100 nvkm_bios_new(struct nvkm_device
*device
, int index
, struct nvkm_bios
**pbios
)
102 struct nvkm_bios
*bios
;
103 struct bit_entry bit_i
;
106 if (!(bios
= *pbios
= kzalloc(sizeof(*bios
), GFP_KERNEL
)))
108 nvkm_subdev_ctor(&nvkm_bios
, device
, index
, 0, &bios
->subdev
);
110 ret
= nvbios_shadow(bios
);
114 /* detect type of vbios we're dealing with */
115 bios
->bmp_offset
= nvbios_findstr(bios
->data
, bios
->size
,
116 "\xff\x7f""NV\0", 5);
117 if (bios
->bmp_offset
) {
118 nvkm_debug(&bios
->subdev
, "BMP version %x.%x\n",
119 bmp_version(bios
) >> 8,
120 bmp_version(bios
) & 0xff);
123 bios
->bit_offset
= nvbios_findstr(bios
->data
, bios
->size
,
125 if (bios
->bit_offset
)
126 nvkm_debug(&bios
->subdev
, "BIT signature found\n");
128 /* determine the vbios version number */
129 if (!bit_entry(bios
, 'i', &bit_i
) && bit_i
.length
>= 4) {
130 bios
->version
.major
= nvbios_rd08(bios
, bit_i
.offset
+ 3);
131 bios
->version
.chip
= nvbios_rd08(bios
, bit_i
.offset
+ 2);
132 bios
->version
.minor
= nvbios_rd08(bios
, bit_i
.offset
+ 1);
133 bios
->version
.micro
= nvbios_rd08(bios
, bit_i
.offset
+ 0);
134 bios
->version
.patch
= nvbios_rd08(bios
, bit_i
.offset
+ 4);
136 if (bmp_version(bios
)) {
137 bios
->version
.major
= nvbios_rd08(bios
, bios
->bmp_offset
+ 13);
138 bios
->version
.chip
= nvbios_rd08(bios
, bios
->bmp_offset
+ 12);
139 bios
->version
.minor
= nvbios_rd08(bios
, bios
->bmp_offset
+ 11);
140 bios
->version
.micro
= nvbios_rd08(bios
, bios
->bmp_offset
+ 10);
143 nvkm_info(&bios
->subdev
, "version %02x.%02x.%02x.%02x.%02x\n",
144 bios
->version
.major
, bios
->version
.chip
,
145 bios
->version
.minor
, bios
->version
.micro
, bios
->version
.patch
);