1 /* $NetBSD: nouveau_nvkm_subdev_bios_pcir.c,v 1.3 2021/12/18 23:45:38 riastradh Exp $ */
2
3 /*
4 * Copyright 2014 Red Hat Inc.
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: Ben Skeggs <bskeggs@redhat.com>
25 */
26 #include <sys/cdefs.h>
27 __KERNEL_RCSID(0, "$NetBSD: nouveau_nvkm_subdev_bios_pcir.c,v 1.3 2021/12/18 23:45:38 riastradh Exp $");
28
29 #include <subdev/bios.h>
30 #include <subdev/bios/pcir.h>
31
32 u32
nvbios_pcirTe(struct nvkm_bios * bios,u32 base,u8 * ver,u16 * hdr)33 nvbios_pcirTe(struct nvkm_bios *bios, u32 base, u8 *ver, u16 *hdr)
34 {
35 u32 data = nvbios_rd16(bios, base + 0x18);
36 if (data) {
37 data += base;
38 switch (nvbios_rd32(bios, data + 0x00)) {
39 case 0x52494350: /* PCIR */
40 case 0x53494752: /* RGIS */
41 case 0x5344504e: /* NPDS */
42 *hdr = nvbios_rd16(bios, data + 0x0a);
43 *ver = nvbios_rd08(bios, data + 0x0c);
44 break;
45 default:
46 nvkm_debug(&bios->subdev,
47 "%08x: PCIR signature (%08x) unknown\n",
48 data, nvbios_rd32(bios, data + 0x00));
49 data = 0;
50 break;
51 }
52 }
53 return data;
54 }
55
56 u32
nvbios_pcirTp(struct nvkm_bios * bios,u32 base,u8 * ver,u16 * hdr,struct nvbios_pcirT * info)57 nvbios_pcirTp(struct nvkm_bios *bios, u32 base, u8 *ver, u16 *hdr,
58 struct nvbios_pcirT *info)
59 {
60 u32 data = nvbios_pcirTe(bios, base, ver, hdr);
61 memset(info, 0x00, sizeof(*info));
62 if (data) {
63 info->vendor_id = nvbios_rd16(bios, data + 0x04);
64 info->device_id = nvbios_rd16(bios, data + 0x06);
65 info->class_code[0] = nvbios_rd08(bios, data + 0x0d);
66 info->class_code[1] = nvbios_rd08(bios, data + 0x0e);
67 info->class_code[2] = nvbios_rd08(bios, data + 0x0f);
68 info->image_size = nvbios_rd16(bios, data + 0x10) * 512;
69 info->image_rev = nvbios_rd16(bios, data + 0x12);
70 info->image_type = nvbios_rd08(bios, data + 0x14);
71 info->last = nvbios_rd08(bios, data + 0x15) & 0x80;
72 }
73 return data;
74 }
75