Skip to content

Commit b950c8c

Browse files
author
Ben Skeggs
committed
drm/nouveau/bios: move ACPI _ROM handling
Signed-off-by: Ben Skeggs <[email protected]>
1 parent 2dd4d16 commit b950c8c

File tree

3 files changed

+47
-76
lines changed

3 files changed

+47
-76
lines changed

drivers/gpu/drm/nouveau/nouveau_acpi.c

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ static struct nouveau_dsm_priv {
4949
bool optimus_flags_detected;
5050
bool optimus_skip_dsm;
5151
acpi_handle dhandle;
52-
acpi_handle rom_handle;
5352
} nouveau_dsm_priv;
5453

5554
bool nouveau_is_optimus(void) {
@@ -385,59 +384,6 @@ void nouveau_unregister_dsm_handler(void) {}
385384
void nouveau_switcheroo_optimus_dsm(void) {}
386385
#endif
387386

388-
/* retrieve the ROM in 4k blocks */
389-
static int nouveau_rom_call(acpi_handle rom_handle, uint8_t *bios,
390-
int offset, int len)
391-
{
392-
acpi_status status;
393-
union acpi_object rom_arg_elements[2], *obj;
394-
struct acpi_object_list rom_arg;
395-
struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL};
396-
397-
rom_arg.count = 2;
398-
rom_arg.pointer = &rom_arg_elements[0];
399-
400-
rom_arg_elements[0].type = ACPI_TYPE_INTEGER;
401-
rom_arg_elements[0].integer.value = offset;
402-
403-
rom_arg_elements[1].type = ACPI_TYPE_INTEGER;
404-
rom_arg_elements[1].integer.value = len;
405-
406-
status = acpi_evaluate_object(rom_handle, NULL, &rom_arg, &buffer);
407-
if (ACPI_FAILURE(status)) {
408-
pr_info("failed to evaluate ROM got %s\n",
409-
acpi_format_exception(status));
410-
return -ENODEV;
411-
}
412-
obj = (union acpi_object *)buffer.pointer;
413-
len = min(len, (int)obj->buffer.length);
414-
memcpy(bios+offset, obj->buffer.pointer, len);
415-
kfree(buffer.pointer);
416-
return len;
417-
}
418-
419-
bool nouveau_acpi_rom_supported(struct device *dev)
420-
{
421-
acpi_status status;
422-
acpi_handle dhandle, rom_handle;
423-
424-
dhandle = ACPI_HANDLE(dev);
425-
if (!dhandle)
426-
return false;
427-
428-
status = acpi_get_handle(dhandle, "_ROM", &rom_handle);
429-
if (ACPI_FAILURE(status))
430-
return false;
431-
432-
nouveau_dsm_priv.rom_handle = rom_handle;
433-
return true;
434-
}
435-
436-
int nouveau_acpi_get_bios_chunk(uint8_t *bios, int offset, int len)
437-
{
438-
return nouveau_rom_call(nouveau_dsm_priv.rom_handle, bios, offset, len);
439-
}
440-
441387
void *
442388
nouveau_acpi_edid(struct drm_device *dev, struct drm_connector *connector)
443389
{

drivers/gpu/drm/nouveau/nouveau_acpi.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,13 @@ bool nouveau_is_v1_dsm(void);
1010
void nouveau_register_dsm_handler(void);
1111
void nouveau_unregister_dsm_handler(void);
1212
void nouveau_switcheroo_optimus_dsm(void);
13-
int nouveau_acpi_get_bios_chunk(uint8_t *bios, int offset, int len);
14-
bool nouveau_acpi_rom_supported(struct device *);
1513
void *nouveau_acpi_edid(struct drm_device *, struct drm_connector *);
1614
#else
1715
static inline bool nouveau_is_optimus(void) { return false; };
1816
static inline bool nouveau_is_v1_dsm(void) { return false; };
1917
static inline void nouveau_register_dsm_handler(void) {}
2018
static inline void nouveau_unregister_dsm_handler(void) {}
2119
static inline void nouveau_switcheroo_optimus_dsm(void) {}
22-
static inline bool nouveau_acpi_rom_supported(struct device *dev) { return false; }
23-
static inline int nouveau_acpi_get_bios_chunk(uint8_t *bios, int offset, int len) { return -EINVAL; }
2420
static inline void *nouveau_acpi_edid(struct drm_device *dev, struct drm_connector *connector) { return NULL; }
2521
#endif
2622

drivers/gpu/drm/nouveau/nvkm/subdev/bios/shadowacpi.c

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,39 @@
2222
*/
2323
#include "priv.h"
2424

25-
#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)
25+
static int
26+
acpi_read_bios(acpi_handle rom_handle, u8 *bios, u32 offset, u32 length)
3127
{
32-
return false;
33-
}
28+
#if defined(CONFIG_ACPI) && defined(CONFIG_X86)
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 @@ acpi_read_fast(void *data, u32 offset, u32 length, struct nvkm_bios *bios)
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 @@ acpi_read_slow(void *data, u32 offset, u32 length, struct nvkm_bios *bios)
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 @@ acpi_read_slow(void *data, u32 offset, u32 length, struct nvkm_bios *bios)
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

0 commit comments

Comments
 (0)