1 /* $NetBSD: nouveau_nvkm_subdev_bios_xpio.c,v 1.3 2021/12/18 23:45:38 riastradh Exp $ */
2
3 /*
4 * Copyright 2012 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
25 */
26 #include <sys/cdefs.h>
27 __KERNEL_RCSID(0, "$NetBSD: nouveau_nvkm_subdev_bios_xpio.c,v 1.3 2021/12/18 23:45:38 riastradh Exp $");
28
29 #include <subdev/bios.h>
30 #include <subdev/bios/gpio.h>
31 #include <subdev/bios/xpio.h>
32
33 static u16
dcb_xpiod_table(struct nvkm_bios * bios,u8 * ver,u8 * hdr,u8 * cnt,u8 * len)34 dcb_xpiod_table(struct nvkm_bios *bios, u8 *ver, u8 *hdr, u8 *cnt, u8 *len)
35 {
36 u16 data = dcb_gpio_table(bios, ver, hdr, cnt, len);
37 if (data && *ver >= 0x40 && *hdr >= 0x06) {
38 u16 xpio = nvbios_rd16(bios, data + 0x04);
39 if (xpio) {
40 *ver = nvbios_rd08(bios, data + 0x00);
41 *hdr = nvbios_rd08(bios, data + 0x01);
42 *cnt = nvbios_rd08(bios, data + 0x02);
43 *len = nvbios_rd08(bios, data + 0x03);
44 return xpio;
45 }
46 }
47 return 0x0000;
48 }
49
50 u16
dcb_xpio_table(struct nvkm_bios * bios,u8 idx,u8 * ver,u8 * hdr,u8 * cnt,u8 * len)51 dcb_xpio_table(struct nvkm_bios *bios, u8 idx,
52 u8 *ver, u8 *hdr, u8 *cnt, u8 *len)
53 {
54 u16 data = dcb_xpiod_table(bios, ver, hdr, cnt, len);
55 if (data && idx < *cnt) {
56 u16 xpio = nvbios_rd16(bios, data + *hdr + (idx * *len));
57 if (xpio) {
58 *ver = nvbios_rd08(bios, data + 0x00);
59 *hdr = nvbios_rd08(bios, data + 0x01);
60 *cnt = nvbios_rd08(bios, data + 0x02);
61 *len = nvbios_rd08(bios, data + 0x03);
62 return xpio;
63 }
64 }
65 return 0x0000;
66 }
67
68 u16
dcb_xpio_parse(struct nvkm_bios * bios,u8 idx,u8 * ver,u8 * hdr,u8 * cnt,u8 * len,struct nvbios_xpio * info)69 dcb_xpio_parse(struct nvkm_bios *bios, u8 idx,
70 u8 *ver, u8 *hdr, u8 *cnt, u8 *len, struct nvbios_xpio *info)
71 {
72 u16 data = dcb_xpio_table(bios, idx, ver, hdr, cnt, len);
73 if (data && *len >= 6) {
74 info->type = nvbios_rd08(bios, data + 0x04);
75 info->addr = nvbios_rd08(bios, data + 0x05);
76 info->flags = nvbios_rd08(bios, data + 0x06);
77 }
78 return 0x0000;
79 }
80