0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023 #include "priv.h"
0024
0025 static int
0026 acpi_read_bios(acpi_handle rom_handle, u8 *bios, u32 offset, u32 length)
0027 {
0028 #if defined(CONFIG_ACPI) && defined(CONFIG_X86)
0029 acpi_status status;
0030 union acpi_object rom_arg_elements[2], *obj;
0031 struct acpi_object_list rom_arg;
0032 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL};
0033
0034 rom_arg.count = 2;
0035 rom_arg.pointer = &rom_arg_elements[0];
0036
0037 rom_arg_elements[0].type = ACPI_TYPE_INTEGER;
0038 rom_arg_elements[0].integer.value = offset;
0039
0040 rom_arg_elements[1].type = ACPI_TYPE_INTEGER;
0041 rom_arg_elements[1].integer.value = length;
0042
0043 status = acpi_evaluate_object(rom_handle, NULL, &rom_arg, &buffer);
0044 if (ACPI_FAILURE(status)) {
0045 pr_info("failed to evaluate ROM got %s\n",
0046 acpi_format_exception(status));
0047 return -ENODEV;
0048 }
0049 obj = (union acpi_object *)buffer.pointer;
0050 length = min(length, obj->buffer.length);
0051 memcpy(bios+offset, obj->buffer.pointer, length);
0052 kfree(buffer.pointer);
0053 return length;
0054 #else
0055 return -EINVAL;
0056 #endif
0057 }
0058
0059
0060
0061
0062
0063 static u32
0064 acpi_read_fast(void *data, u32 offset, u32 length, struct nvkm_bios *bios)
0065 {
0066 u32 limit = (offset + length + 0xfff) & ~0xfff;
0067 u32 start = offset & ~0x00000fff;
0068 u32 fetch = limit - start;
0069
0070 if (nvbios_extend(bios, limit) >= 0) {
0071 int ret = acpi_read_bios(data, bios->data, start, fetch);
0072 if (ret == fetch)
0073 return fetch;
0074 }
0075
0076 return 0;
0077 }
0078
0079
0080
0081
0082
0083
0084 static u32
0085 acpi_read_slow(void *data, u32 offset, u32 length, struct nvkm_bios *bios)
0086 {
0087 u32 limit = (offset + length + 0xfff) & ~0xfff;
0088 u32 start = offset & ~0xfff;
0089 u32 fetch = 0;
0090
0091 if (nvbios_extend(bios, limit) >= 0) {
0092 while (start + fetch < limit) {
0093 int ret = acpi_read_bios(data, bios->data,
0094 start + fetch, 0x1000);
0095 if (ret != 0x1000)
0096 break;
0097 fetch += 0x1000;
0098 }
0099 }
0100
0101 return fetch;
0102 }
0103
0104 static void *
0105 acpi_init(struct nvkm_bios *bios, const char *name)
0106 {
0107 #if defined(CONFIG_ACPI) && defined(CONFIG_X86)
0108 acpi_status status;
0109 acpi_handle dhandle, rom_handle;
0110
0111 dhandle = ACPI_HANDLE(bios->subdev.device->dev);
0112 if (!dhandle)
0113 return ERR_PTR(-ENODEV);
0114
0115 status = acpi_get_handle(dhandle, "_ROM", &rom_handle);
0116 if (ACPI_FAILURE(status))
0117 return ERR_PTR(-ENODEV);
0118
0119 return rom_handle;
0120 #else
0121 return ERR_PTR(-ENODEV);
0122 #endif
0123 }
0124
0125 const struct nvbios_source
0126 nvbios_acpi_fast = {
0127 .name = "ACPI",
0128 .init = acpi_init,
0129 .read = acpi_read_fast,
0130 .rw = false,
0131 .require_checksum = true,
0132 };
0133
0134 const struct nvbios_source
0135 nvbios_acpi_slow = {
0136 .name = "ACPI",
0137 .init = acpi_init,
0138 .read = acpi_read_slow,
0139 .rw = false,
0140 };