ARM: pmu: add support for interrupt-affinity property
[linux/fpc-iii.git] / drivers / gpu / drm / nouveau / nvkm / subdev / bios / extdev.c
bloba8503a1854c44f5483286588eac37bcfe21c424a
1 /*
2 * Copyright 2012 Nouveau Community
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.
22 * Authors: Martin Peres
24 #include <subdev/bios.h>
25 #include <subdev/bios/dcb.h>
26 #include <subdev/bios/extdev.h>
28 static u16
29 extdev_table(struct nvkm_bios *bios, u8 *ver, u8 *hdr, u8 *len, u8 *cnt)
31 u8 dcb_ver, dcb_hdr, dcb_cnt, dcb_len;
32 u16 dcb, extdev = 0;
34 dcb = dcb_table(bios, &dcb_ver, &dcb_hdr, &dcb_cnt, &dcb_len);
35 if (!dcb || (dcb_ver != 0x30 && dcb_ver != 0x40))
36 return 0x0000;
38 extdev = nv_ro16(bios, dcb + 18);
39 if (!extdev)
40 return 0x0000;
42 *ver = nv_ro08(bios, extdev + 0);
43 *hdr = nv_ro08(bios, extdev + 1);
44 *cnt = nv_ro08(bios, extdev + 2);
45 *len = nv_ro08(bios, extdev + 3);
46 return extdev + *hdr;
49 static u16
50 nvbios_extdev_entry(struct nvkm_bios *bios, int idx, u8 *ver, u8 *len)
52 u8 hdr, cnt;
53 u16 extdev = extdev_table(bios, ver, &hdr, len, &cnt);
54 if (extdev && idx < cnt)
55 return extdev + idx * *len;
56 return 0x0000;
59 static void
60 extdev_parse_entry(struct nvkm_bios *bios, u16 offset,
61 struct nvbios_extdev_func *entry)
63 entry->type = nv_ro08(bios, offset + 0);
64 entry->addr = nv_ro08(bios, offset + 1);
65 entry->bus = (nv_ro08(bios, offset + 2) >> 4) & 1;
68 int
69 nvbios_extdev_parse(struct nvkm_bios *bios, int idx,
70 struct nvbios_extdev_func *func)
72 u8 ver, len;
73 u16 entry;
75 if (!(entry = nvbios_extdev_entry(bios, idx, &ver, &len)))
76 return -EINVAL;
78 extdev_parse_entry(bios, entry, func);
79 return 0;
82 int
83 nvbios_extdev_find(struct nvkm_bios *bios, enum nvbios_extdev_type type,
84 struct nvbios_extdev_func *func)
86 u8 ver, len, i;
87 u16 entry;
89 i = 0;
90 while ((entry = nvbios_extdev_entry(bios, i++, &ver, &len))) {
91 extdev_parse_entry(bios, entry, func);
92 if (func->type == type)
93 return 0;
96 return -EINVAL;