2 * Copyright 2012 Red Hat Inc.
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.
25 #include <core/device.h>
27 #if defined(CONFIG_ACPI) && defined(CONFIG_X86)
28 int nouveau_acpi_get_bios_chunk(uint8_t *bios, int offset, int len);
29 bool nouveau_acpi_rom_supported(struct pci_dev *pdev);
32 nouveau_acpi_rom_supported(struct pci_dev *pdev)
38 nouveau_acpi_get_bios_chunk(uint8_t *bios, int offset, int len)
44 /* This version of the shadow function disobeys the ACPI spec and tries
45 * to fetch in units of more than 4KiB at a time. This is a LOT faster
46 * on some systems, such as Lenovo W530.
49 acpi_read_fast(void *data, u32 offset, u32 length, struct nvkm_bios *bios)
51 u32 limit = (offset + length + 0xfff) & ~0xfff;
52 u32 start = offset & ~0x00000fff;
53 u32 fetch = limit - start;
55 if (nvbios_extend(bios, limit) > 0) {
56 int ret = nouveau_acpi_get_bios_chunk(bios->data, start, fetch);
64 /* Other systems, such as the one in fdo#55948, will report a success
65 * but only return 4KiB of data. The common bios fetching logic will
66 * detect an invalid image, and fall back to this version of the read
70 acpi_read_slow(void *data, u32 offset, u32 length, struct nvkm_bios *bios)
72 u32 limit = (offset + length + 0xfff) & ~0xfff;
73 u32 start = offset & ~0xfff;
76 if (nvbios_extend(bios, limit) > 0) {
77 while (start + fetch < limit) {
78 int ret = nouveau_acpi_get_bios_chunk(bios->data,
91 acpi_init(struct nvkm_bios *bios, const char *name)
93 if (!nouveau_acpi_rom_supported(nv_device(bios)->pdev))
94 return ERR_PTR(-ENODEV);
98 const struct nvbios_source
102 .read = acpi_read_fast,
106 const struct nvbios_source
110 .read = acpi_read_slow,