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