Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright 2012 Red Hat Inc.
0003  *
0004  * Permission is hereby granted, free of charge, to any person obtaining a
0005  * copy of this software and associated documentation files (the "Software"),
0006  * to deal in the Software without restriction, including without limitation
0007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0008  * and/or sell copies of the Software, and to permit persons to whom the
0009  * Software is furnished to do so, subject to the following conditions:
0010  *
0011  * The above copyright notice and this permission notice shall be included in
0012  * all copies or substantial portions of the Software.
0013  *
0014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0017  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
0018  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0020  * OTHER DEALINGS IN THE SOFTWARE.
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 /* This version of the shadow function disobeys the ACPI spec and tries
0060  * to fetch in units of more than 4KiB at a time.  This is a LOT faster
0061  * on some systems, such as Lenovo W530.
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 /* Other systems, such as the one in fdo#55948, will report a success
0080  * but only return 4KiB of data.  The common bios fetching logic will
0081  * detect an invalid image, and fall back to this version of the read
0082  * function.
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 };