Skip to content

Commit bf884a3

Browse files
committed
WIP: LAcpiEvaluateObject
This work follows #1817.
1 parent 9bfca9d commit bf884a3

File tree

12 files changed

+515
-5
lines changed

12 files changed

+515
-5
lines changed

stand/efi/acpica/init_acpi.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
*/
2626

2727
#include <stand.h>
28-
#include <acpi.h>
29-
#include <accommon.h>
30-
#include <acoutput.h>
28+
#include <contrib/dev/acpica/include/acpi.h>
29+
#include <contrib/dev/acpica/include/accommon.h>
30+
#include <contrib/dev/acpica/include/acoutput.h>
3131
#include <init_acpi.h>
3232

3333
#define _COMPONENT ACPI_LOADER

stand/efi/loader/Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,10 @@ LIBACPI= ${BOOTOBJ}/efi/libacpi/libacpi.a
146146
DPADD= ${LDR_INTERP32} ${LIBEFI32} ${LIBSA32} ${LDSCRIPT}
147147
LDADD= ${LDR_INTERP32} ${LIBEFI32} ${LIBSA32}
148148
.elif ${__arch} == "amd64"
149-
DPADD= ${LDR_INTERP} ${LIBEFI} ${LIBSAFDT} ${LIBEFI_FDT} ${LIBSA} ${LIBACPI} ${LDSCRIPT}
150-
LDADD= ${LDR_INTERP} ${LIBEFI} ${LIBSAFDT} ${LIBEFI_FDT} ${LIBSA} ${LIBACPI}
149+
DPADD= ${LDR_INTERP} ${LIBEFI} ${LIBSAFDT} ${LIBEFI_FDT} \
150+
${LIBSA} ${LIBACPI} ${LIBLUA} ${LDSCRIPT}
151+
LDADD= ${LDR_INTERP} ${LIBEFI} ${LIBSAFDT} ${LIBEFI_FDT} \
152+
${LIBSA} ${LIBACPI} ${LIBLUA}
151153
.else
152154
DPADD= ${LDR_INTERP} ${LIBEFI} ${LIBSAFDT} ${LIBEFI_FDT} ${LIBSA} ${LDSCRIPT}
153155
LDADD= ${LDR_INTERP} ${LIBEFI} ${LIBSAFDT} ${LIBEFI_FDT} ${LIBSA}

stand/efi/loader/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,6 +1236,9 @@ main(int argc, CHAR16 *argv[])
12361236
if ((ret = init_acpi()) != 0) {
12371237
printf("Failed to initialize ACPI\n.");
12381238
}
1239+
1240+
lacpi_interp_ref();
1241+
lua_acpi_register_hook();
12391242
#endif
12401243

12411244
/*

stand/liblua/Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ SRCS+= lfs.c
2929
.PATH: ${FLUALIB}/libhash
3030
SRCS+= lhash.c
3131

32+
# ACPI
33+
.if ${MACHINE_CPUARCH} == "amd64"
34+
.PATH: ${LIBLUASRC}/acpi
35+
SRCS+= lacpi.c lacpi_object.c lacpi_factory.c
36+
CFLAGS+= -I${LIBLUASRC}/acpi -I${SYSDIR}/contrib/dev/acpica/include \
37+
-I${EFISRC}/acpica/include
38+
DPADD+= ${LIBACPI}
39+
LDADD+= ${LIBACPI}
40+
.endif
41+
3242
WARNS?= 3
3343

3444
CFLAGS+= -DLUA_PATH=\"${LUAPATH}\" -DLUA_PATH_DEFAULT=\"${LUAPATH}/\?.lua\"

stand/liblua/acpi/lacpi.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <init_acpi.h>
2+
#include <lutils.h>
3+
#include "lacpi.h"
4+
5+
/*
6+
* Reference set for all lacpi modules.
7+
*/
8+
void
9+
lacpi_interp_ref(void)
10+
{
11+
lacpi_object_interp_ref();
12+
}
13+
14+
/*
15+
* Unpacks all lacpi modules.
16+
*/
17+
static void
18+
lua_acpi_bindings(lua_State *L)
19+
{
20+
struct lua_acpi_module **mod;
21+
22+
SET_FOREACH(mod, lua_acpi_modules) {
23+
(*mod)->init(L);
24+
lua_setglobal(L, (*mod)->mod_name);
25+
}
26+
}
27+
28+
/*
29+
* Function hook for lacpi modules.
30+
*/
31+
void
32+
lua_acpi_register_hook(void)
33+
{
34+
if (acpi_is_initialized()) {
35+
lua_acpi_register = lua_acpi_bindings;
36+
}
37+
}

stand/liblua/acpi/lacpi.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#pragma once
2+
3+
#include <lua.h>
4+
#include <sys/linker_set.h>
5+
#include <contrib/dev/acpica/include/acpi.h>
6+
7+
typedef int (*lua_module_init_fn)(lua_State *L);
8+
extern void lacpi_object_interp_ref(void);
9+
10+
struct lua_acpi_module {
11+
const char *mod_name;
12+
lua_module_init_fn init;
13+
};
14+
15+
SET_DECLARE(lua_acpi_modules, struct lua_acpi_module);
16+
17+
#define LUA_ACPI_COMPILE_SET(name, initfn) \
18+
static struct lua_acpi_module lua_##name = \
19+
{ \
20+
.mod_name = #name, \
21+
.init = initfn \
22+
}; \
23+
DATA_SET(lua_acpi_modules, lua_##name)
24+
25+
struct lacpi_node {
26+
const char* pathname;
27+
ACPI_HANDLE handle;
28+
};

stand/liblua/acpi/lacpi_factory.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <lua.h>
2+
#include <lauxlib.h>
3+
#include <lualib.h>
4+
5+
int
6+
lacpi_create_mt_gc(lua_State *L, const char *mt, lua_CFunction gc_func)
7+
{
8+
if (luaL_newmetatable(L, mt)) {
9+
lua_pushcfunction(L, gc_func);
10+
lua_setfield(L, -2, "__gc");
11+
12+
lua_pushvalue(L, -1);
13+
lua_setfield(L, -2, "__index");
14+
}
15+
16+
return 1;
17+
}

stand/liblua/acpi/lacpi_factory.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#pragma once
2+
3+
int lacpi_create_mt_gc(lua_State *L, const char *mt, lua_CFunction gc_func);

0 commit comments

Comments
 (0)