1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23#include "priv.h"
24
25#if defined(CONFIG_ACPI) && defined(CONFIG_X86)
26int nouveau_acpi_get_bios_chunk(uint8_t *bios, int offset, int len);
27bool nouveau_acpi_rom_supported(struct device *);
28#else
29static inline bool
30nouveau_acpi_rom_supported(struct device *dev)
31{
32 return false;
33}
34
35static inline int
36nouveau_acpi_get_bios_chunk(uint8_t *bios, int offset, int len)
37{
38 return -EINVAL;
39}
40#endif
41
42
43
44
45
46static u32
47acpi_read_fast(void *data, u32 offset, u32 length, struct nvkm_bios *bios)
48{
49 u32 limit = (offset + length + 0xfff) & ~0xfff;
50 u32 start = offset & ~0x00000fff;
51 u32 fetch = limit - start;
52
53 if (nvbios_extend(bios, limit) >= 0) {
54 int ret = nouveau_acpi_get_bios_chunk(bios->data, start, fetch);
55 if (ret == fetch)
56 return fetch;
57 }
58
59 return 0;
60}
61
62
63
64
65
66
67static u32
68acpi_read_slow(void *data, u32 offset, u32 length, struct nvkm_bios *bios)
69{
70 u32 limit = (offset + length + 0xfff) & ~0xfff;
71 u32 start = offset & ~0xfff;
72 u32 fetch = 0;
73
74 if (nvbios_extend(bios, limit) >= 0) {
75 while (start + fetch < limit) {
76 int ret = nouveau_acpi_get_bios_chunk(bios->data,
77 start + fetch,
78 0x1000);
79 if (ret != 0x1000)
80 break;
81 fetch += 0x1000;
82 }
83 }
84
85 return fetch;
86}
87
88static void *
89acpi_init(struct nvkm_bios *bios, const char *name)
90{
91 if (!nouveau_acpi_rom_supported(bios->subdev.device->dev))
92 return ERR_PTR(-ENODEV);
93 return NULL;
94}
95
96const struct nvbios_source
97nvbios_acpi_fast = {
98 .name = "ACPI",
99 .init = acpi_init,
100 .read = acpi_read_fast,
101 .rw = false,
102 .require_checksum = true,
103};
104
105const struct nvbios_source
106nvbios_acpi_slow = {
107 .name = "ACPI",
108 .init = acpi_init,
109 .read = acpi_read_slow,
110 .rw = false,
111};
112