1c39f472eSBen Skeggs /*
2c39f472eSBen Skeggs * Copyright 2014 Red Hat Inc.
3c39f472eSBen Skeggs *
4c39f472eSBen Skeggs * Permission is hereby granted, free of charge, to any person obtaining a
5c39f472eSBen Skeggs * copy of this software and associated documentation files (the "Software"),
6c39f472eSBen Skeggs * to deal in the Software without restriction, including without limitation
7c39f472eSBen Skeggs * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8c39f472eSBen Skeggs * and/or sell copies of the Software, and to permit persons to whom the
9c39f472eSBen Skeggs * Software is furnished to do so, subject to the following conditions:
10c39f472eSBen Skeggs *
11c39f472eSBen Skeggs * The above copyright notice and this permission notice shall be included in
12c39f472eSBen Skeggs * all copies or substantial portions of the Software.
13c39f472eSBen Skeggs *
14c39f472eSBen Skeggs * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15c39f472eSBen Skeggs * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16c39f472eSBen Skeggs * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17c39f472eSBen Skeggs * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18c39f472eSBen Skeggs * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19c39f472eSBen Skeggs * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20c39f472eSBen Skeggs * OTHER DEALINGS IN THE SOFTWARE.
21c39f472eSBen Skeggs *
22c39f472eSBen Skeggs * Authors: Ben Skeggs <bskeggs@redhat.com>
23c39f472eSBen Skeggs */
24c39f472eSBen Skeggs #include <subdev/bios.h>
25c39f472eSBen Skeggs #include <subdev/bios/npde.h>
26c39f472eSBen Skeggs #include <subdev/bios/pcir.h>
27c39f472eSBen Skeggs
28c39f472eSBen Skeggs u32
nvbios_npdeTe(struct nvkm_bios * bios,u32 base)29d390b480SBen Skeggs nvbios_npdeTe(struct nvkm_bios *bios, u32 base)
30c39f472eSBen Skeggs {
31c39f472eSBen Skeggs struct nvbios_pcirT pcir;
32c39f472eSBen Skeggs u8 ver; u16 hdr;
33c39f472eSBen Skeggs u32 data = nvbios_pcirTp(bios, base, &ver, &hdr, &pcir);
34c39f472eSBen Skeggs if (data = (data + hdr + 0x0f) & ~0x0f, data) {
35*7f5f518fSBen Skeggs switch (nvbios_rd32(bios, data + 0x00)) {
36c39f472eSBen Skeggs case 0x4544504e: /* NPDE */
37c39f472eSBen Skeggs break;
38c39f472eSBen Skeggs default:
3960b29d20SBen Skeggs nvkm_debug(&bios->subdev,
4060b29d20SBen Skeggs "%08x: NPDE signature (%08x) unknown\n",
41*7f5f518fSBen Skeggs data, nvbios_rd32(bios, data + 0x00));
42c39f472eSBen Skeggs data = 0;
43c39f472eSBen Skeggs break;
44c39f472eSBen Skeggs }
45c39f472eSBen Skeggs }
46c39f472eSBen Skeggs return data;
47c39f472eSBen Skeggs }
48c39f472eSBen Skeggs
49c39f472eSBen Skeggs u32
nvbios_npdeTp(struct nvkm_bios * bios,u32 base,struct nvbios_npdeT * info)50d390b480SBen Skeggs nvbios_npdeTp(struct nvkm_bios *bios, u32 base, struct nvbios_npdeT *info)
51c39f472eSBen Skeggs {
52c39f472eSBen Skeggs u32 data = nvbios_npdeTe(bios, base);
53c39f472eSBen Skeggs memset(info, 0x00, sizeof(*info));
54c39f472eSBen Skeggs if (data) {
55*7f5f518fSBen Skeggs info->image_size = nvbios_rd16(bios, data + 0x08) * 512;
56*7f5f518fSBen Skeggs info->last = nvbios_rd08(bios, data + 0x0a) & 0x80;
57c39f472eSBen Skeggs }
58c39f472eSBen Skeggs return data;
59c39f472eSBen Skeggs }
60