Skip to content

Commit e90f340

Browse files
committed
liblua: Create lacpi
1 parent b8fb47d commit e90f340

File tree

14 files changed

+1309
-1
lines changed

14 files changed

+1309
-1
lines changed

stand/liblua/Makefile

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

32+
# ACPI
33+
.if ${MACHINE_CPUARCH} == "amd64" && ${DO32:U0} == 0
34+
.PATH: ${LIBLUASRC}/acpi
35+
36+
SRCS+= lacpi.c lacpi_object.c lacpi_utils.c lacpi_walk.c lacpi_data.c
37+
38+
CFLAGS+= -I${SYSDIR}/contrib/dev/acpica/include \
39+
-I${EFISRC}/libacpi/acpi/include -I${EFISRC}/include \
40+
-I${EFISRC}/include/amd64 -I${LIBLUASRC}/acpi/include
41+
42+
DPADD+= ${LIBACPI}
43+
LDADD+= ${LIBACPI}
44+
.endif
45+
3246
WARNS?= 3
3347

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

stand/liblua/acpi/include/lacpi.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
extern void lacpi_data_interp_ref(void);
10+
11+
struct lua_acpi_module {
12+
const char *mod_name;
13+
lua_module_init_fn init;
14+
};
15+
16+
SET_DECLARE(lua_acpi_modules, struct lua_acpi_module);
17+
18+
#define LUA_ACPI_COMPILE_SET(name, initfn) \
19+
static struct lua_acpi_module lua_##name = \
20+
{ \
21+
.mod_name = #name, \
22+
.init = initfn \
23+
}; \
24+
DATA_SET(lua_acpi_modules, lua_##name)
25+
26+
struct lacpi_node {
27+
const char* pathname;
28+
ACPI_HANDLE handle;
29+
};
30+
31+
void lacpi_interp_ref(void);
32+
void lua_acpi_register_hook(void);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#pragma once
2+
3+
#include <lua.h>
4+
#include <lauxlib.h>
5+
6+
void lacpi_data_interp_ref(void);
7+
int luaopen_lacpi_data(lua_State *L);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#pragma once
2+
3+
#include <lua.h>
4+
#include <lauxlib.h>
5+
6+
void lacpi_object_interp_ref(void);
7+
void lacpi_node_register_mt(lua_State *L);
8+
int luaopen_lacpi_object(lua_State *L);
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#pragma once
2+
3+
#include <lauxlib.h>
4+
#include <lua.h>
5+
#include <lacpi_walk.h>
6+
#include <contrib/dev/acpica/include/acpi.h>
7+
8+
/***** UTILITY *****/
9+
10+
/* verifies lua passed over a handle on the stack */
11+
ACPI_HANDLE lacpi_check_handle(lua_State *L, int idx);
12+
13+
/* destructor dispatcher */
14+
typedef void (*acpi_destructor_t)(ACPI_OBJECT *);
15+
16+
/* safety check -- lua stores integers as 64bit */
17+
ACPI_STATUS lacpi_int_to_uint32(lua_State *L, int index, UINT32 *num);
18+
19+
/* to convert ACPI_OBJECT_TYPE from table value */
20+
ACPI_STATUS lacpi_infer_type(lua_State *L, int idx, UINT32 *type);
21+
22+
/* build error code and push it onto stack */
23+
int lacpi_push_err(lua_State *L, const int push_nil, const char *errmsg,
24+
const ACPI_STATUS status);
25+
26+
/* extract error message relating to ACPI_STATUS */
27+
char *lacpi_extract_status(const ACPI_STATUS status);
28+
29+
/***** FACTORY *****/
30+
31+
/* create metatable gc */
32+
int lacpi_create_mt_gc(lua_State *L, const char *mt, lua_CFunction gc_func);
33+
34+
/*** ACPI_OBJECT ***/
35+
/* build ACPI_OBJECTs */
36+
ACPI_STATUS build_int(lua_State *L, ACPI_OBJECT *obj, int idx);
37+
ACPI_STATUS build_str(lua_State *L, ACPI_OBJECT *obj, int idx);
38+
ACPI_STATUS build_buff(lua_State *L, ACPI_OBJECT *obj, int idx);
39+
ACPI_STATUS build_pkg(lua_State *L, ACPI_OBJECT *obj, int idx);
40+
ACPI_STATUS build_acpi_obj(lua_State *L, ACPI_OBJECT *obj, UINT32 obj_type, int idx);
41+
ACPI_STATUS build_ref(lua_State *L, ACPI_OBJECT *obj, int idx);
42+
ACPI_STATUS build_proc(lua_State *L, ACPI_OBJECT *obj, int idx);
43+
ACPI_STATUS build_pow(lua_State *L, ACPI_OBJECT *obj, int idx);
44+
45+
/* push ACPI_OBJECTs onto lua stack */
46+
void push_int(lua_State *L, ACPI_OBJECT *obj);
47+
void push_str(lua_State *L, ACPI_OBJECT *obj);
48+
void push_buff(lua_State *L, ACPI_OBJECT *obj);
49+
void push_pkg(lua_State *L, ACPI_OBJECT *obj);
50+
void push_acpi_obj(lua_State *L, ACPI_OBJECT *obj);
51+
void push_ref(lua_State *L, ACPI_OBJECT *obj);
52+
void push_proc(lua_State *L, ACPI_OBJECT *obj);
53+
void push_pow(lua_State *L, ACPI_OBJECT *obj);
54+
55+
/* free ACPI_OBJECTs */
56+
void free_fake(ACPI_OBJECT *obj);
57+
void free_str(ACPI_OBJECT *obj);
58+
void free_buff(ACPI_OBJECT *obj);
59+
void free_pkg(ACPI_OBJECT *obj);
60+
void free_acpi_obj(ACPI_OBJECT *obj);
61+
void free_acpi_objs(ACPI_OBJECT **objs, UINT32 init_count);
62+
63+
/*** ACPI Namespace Node ***/
64+
void push_path(struct context *curr_ctx, const char *path);
65+
void push_lvl(struct context *curr_ctx, UINT32 level);
66+
void push_hid(struct context *curr_ctx, const char *hid);
67+
void push_uid(struct context *curr_ctx, const char *uid);
68+
void push_node(struct context *curr_ctx, const char *path, UINT32 level,
69+
ACPI_HANDLE handle);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#pragma once
2+
3+
#include <lauxlib.h>
4+
5+
struct context {
6+
lua_State *L;
7+
int tbl;
8+
int idx;
9+
};
10+
11+
int luaopen_lacpi_walk(lua_State *L);
12+
void lacpi_walk_interp_ref(void);

stand/liblua/acpi/lacpi.c

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#include <init_acpi.h>
2+
#include <lutils.h>
3+
#include <lauxlib.h>
4+
#include "lacpi.h"
5+
#include "lacpi_object.h"
6+
#include "lacpi_walk.h"
7+
#include "lacpi_data.h"
8+
9+
/*
10+
* Reference set for all lacpi modules.
11+
*/
12+
void
13+
lacpi_interp_ref(void)
14+
{
15+
lacpi_object_interp_ref();
16+
lacpi_walk_interp_ref();
17+
lacpi_data_interp_ref();
18+
}
19+
20+
int
21+
luaopen_lacpi(lua_State *L)
22+
{
23+
lua_newtable(L);
24+
25+
luaopen_lacpi_object(L);
26+
lua_setfield(L, -2, "object");
27+
28+
luaopen_lacpi_walk(L);
29+
lua_setfield(L, -2, "walk");
30+
31+
luaopen_lacpi_data(L);
32+
lua_setfield(L, -2, "data");
33+
34+
return 1;
35+
}
36+
37+
/*
38+
* Unpacks all lacpi modules.
39+
*/
40+
static void
41+
lua_acpi_bindings(lua_State *L)
42+
{
43+
struct lua_acpi_module **mod;
44+
45+
SET_FOREACH(mod, lua_acpi_modules) {
46+
(*mod)->init(L);
47+
lua_setglobal(L, (*mod)->mod_name);
48+
}
49+
}
50+
51+
/*
52+
* Function hook for lacpi modules.
53+
*/
54+
void
55+
lua_acpi_register_hook(void)
56+
{
57+
if (acpi_is_initialized()) {
58+
lua_acpi_register = lua_acpi_bindings;
59+
}
60+
}
61+
62+
LUA_ACPI_COMPILE_SET(lacpi, luaopen_lacpi);

0 commit comments

Comments
 (0)