forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-11 04dd17822334871b23ea2862f7798fb0e0007777
kernel/drivers/gpu/drm/nouveau/nvkm/subdev/bios/shadowacpi.c
....@@ -22,22 +22,39 @@
2222 */
2323 #include "priv.h"
2424
25
+static int
26
+acpi_read_bios(acpi_handle rom_handle, u8 *bios, u32 offset, u32 length)
27
+{
2528 #if defined(CONFIG_ACPI) && defined(CONFIG_X86)
26
-int nouveau_acpi_get_bios_chunk(uint8_t *bios, int offset, int len);
27
-bool nouveau_acpi_rom_supported(struct device *);
28
-#else
29
-static inline bool
30
-nouveau_acpi_rom_supported(struct device *dev)
31
-{
32
- return false;
33
-}
29
+ acpi_status status;
30
+ union acpi_object rom_arg_elements[2], *obj;
31
+ struct acpi_object_list rom_arg;
32
+ struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL};
3433
35
-static inline int
36
-nouveau_acpi_get_bios_chunk(uint8_t *bios, int offset, int len)
37
-{
34
+ rom_arg.count = 2;
35
+ rom_arg.pointer = &rom_arg_elements[0];
36
+
37
+ rom_arg_elements[0].type = ACPI_TYPE_INTEGER;
38
+ rom_arg_elements[0].integer.value = offset;
39
+
40
+ rom_arg_elements[1].type = ACPI_TYPE_INTEGER;
41
+ rom_arg_elements[1].integer.value = length;
42
+
43
+ status = acpi_evaluate_object(rom_handle, NULL, &rom_arg, &buffer);
44
+ if (ACPI_FAILURE(status)) {
45
+ pr_info("failed to evaluate ROM got %s\n",
46
+ acpi_format_exception(status));
47
+ return -ENODEV;
48
+ }
49
+ obj = (union acpi_object *)buffer.pointer;
50
+ length = min(length, obj->buffer.length);
51
+ memcpy(bios+offset, obj->buffer.pointer, length);
52
+ kfree(buffer.pointer);
53
+ return length;
54
+#else
3855 return -EINVAL;
39
-}
4056 #endif
57
+}
4158
4259 /* This version of the shadow function disobeys the ACPI spec and tries
4360 * to fetch in units of more than 4KiB at a time. This is a LOT faster
....@@ -51,7 +68,7 @@
5168 u32 fetch = limit - start;
5269
5370 if (nvbios_extend(bios, limit) >= 0) {
54
- int ret = nouveau_acpi_get_bios_chunk(bios->data, start, fetch);
71
+ int ret = acpi_read_bios(data, bios->data, start, fetch);
5572 if (ret == fetch)
5673 return fetch;
5774 }
....@@ -73,9 +90,8 @@
7390
7491 if (nvbios_extend(bios, limit) >= 0) {
7592 while (start + fetch < limit) {
76
- int ret = nouveau_acpi_get_bios_chunk(bios->data,
77
- start + fetch,
78
- 0x1000);
93
+ int ret = acpi_read_bios(data, bios->data,
94
+ start + fetch, 0x1000);
7995 if (ret != 0x1000)
8096 break;
8197 fetch += 0x1000;
....@@ -88,9 +104,22 @@
88104 static void *
89105 acpi_init(struct nvkm_bios *bios, const char *name)
90106 {
91
- if (!nouveau_acpi_rom_supported(bios->subdev.device->dev))
107
+#if defined(CONFIG_ACPI) && defined(CONFIG_X86)
108
+ acpi_status status;
109
+ acpi_handle dhandle, rom_handle;
110
+
111
+ dhandle = ACPI_HANDLE(bios->subdev.device->dev);
112
+ if (!dhandle)
92113 return ERR_PTR(-ENODEV);
93
- return NULL;
114
+
115
+ status = acpi_get_handle(dhandle, "_ROM", &rom_handle);
116
+ if (ACPI_FAILURE(status))
117
+ return ERR_PTR(-ENODEV);
118
+
119
+ return rom_handle;
120
+#else
121
+ return ERR_PTR(-ENODEV);
122
+#endif
94123 }
95124
96125 const struct nvbios_source