Changeset View
Changeset View
Standalone View
Standalone View
graphics/igt-gpu-tools/files/patch-lib_igt__kmod.c
- This file was added.
--- lib/igt_kmod.c.orig 2022-08-17 23:41:16 UTC | |||||
+++ lib/igt_kmod.c | |||||
@@ -32,6 +32,12 @@ | |||||
#include "igt_sysfs.h" | |||||
#include "igt_taints.h" | |||||
+#ifdef __FreeBSD__ | |||||
+struct kmod_ctx { | |||||
+ int refcount; | |||||
+}; | |||||
+#endif | |||||
+ | |||||
/** | |||||
* SECTION:igt_kmod | |||||
* @short_description: Wrappers around libkmod for module loading/unloading | |||||
@@ -59,6 +65,7 @@ static struct kmod_ctx *kmod_ctx(void) | |||||
static struct kmod_ctx *kmod_ctx(void) | |||||
{ | |||||
+#ifdef __linux__ | |||||
static struct kmod_ctx *ctx; | |||||
const char **config_paths = NULL; | |||||
char *config_paths_str; | |||||
@@ -106,6 +113,10 @@ out: | |||||
kmod_set_log_fn(ctx, squelch, NULL); | |||||
out: | |||||
return ctx; | |||||
+#elif defined(__FreeBSD__) | |||||
+ static struct kmod_ctx *ctx = NULL; | |||||
+ return ctx; | |||||
+#endif | |||||
} | |||||
/** | |||||
@@ -121,6 +132,7 @@ igt_kmod_is_loaded(const char *mod_name) | |||||
bool | |||||
igt_kmod_is_loaded(const char *mod_name) | |||||
{ | |||||
+#ifdef __linux__ | |||||
struct kmod_ctx *ctx = kmod_ctx(); | |||||
struct kmod_list *mod, *list; | |||||
bool ret = false; | |||||
@@ -142,16 +154,24 @@ out: | |||||
kmod_module_unref_list(list); | |||||
out: | |||||
return ret; | |||||
+#elif defined(__FreeBSD__) | |||||
+ return false; | |||||
+#endif | |||||
} | |||||
static bool | |||||
igt_kmod_is_loading(struct kmod_module *kmod) | |||||
{ | |||||
+#ifdef __linux__ | |||||
return kmod_module_get_initstate(kmod) == KMOD_MODULE_COMING; | |||||
+#elif defined(__FreeBSD__) | |||||
+ return false; | |||||
+#endif | |||||
} | |||||
static int modprobe(struct kmod_module *kmod, const char *options) | |||||
{ | |||||
+#ifdef __linux__ | |||||
unsigned int flags; | |||||
flags = 0; | |||||
@@ -160,6 +180,9 @@ static int modprobe(struct kmod_module *kmod, const ch | |||||
return kmod_module_probe_insert_module(kmod, flags, options, | |||||
NULL, NULL, NULL); | |||||
+#elif defined(__FreeBSD__) | |||||
+ return -ENOSYS; | |||||
+#endif | |||||
} | |||||
/** | |||||
@@ -171,6 +194,7 @@ bool igt_kmod_has_param(const char *module_name, const | |||||
*/ | |||||
bool igt_kmod_has_param(const char *module_name, const char *param) | |||||
{ | |||||
+#ifdef __linux__ | |||||
struct kmod_module *kmod; | |||||
struct kmod_list *d, *pre; | |||||
bool result = false; | |||||
@@ -200,6 +224,9 @@ out: | |||||
out: | |||||
kmod_module_unref(kmod); | |||||
return result; | |||||
+#elif defined(__FreeBSD__) | |||||
+ return false; | |||||
+#endif | |||||
} | |||||
/** | |||||
@@ -220,6 +247,7 @@ igt_kmod_load(const char *mod_name, const char *opts) | |||||
int | |||||
igt_kmod_load(const char *mod_name, const char *opts) | |||||
{ | |||||
+#ifdef __linux__ | |||||
struct kmod_ctx *ctx = kmod_ctx(); | |||||
struct kmod_module *kmod; | |||||
int err = 0; | |||||
@@ -249,10 +277,14 @@ out: | |||||
out: | |||||
kmod_module_unref(kmod); | |||||
return err < 0 ? err : 0; | |||||
+#elif defined(__FreeBSD__) | |||||
+ return -ENOSYS; | |||||
+#endif | |||||
} | |||||
static int igt_kmod_unload_r(struct kmod_module *kmod, unsigned int flags) | |||||
{ | |||||
+#ifdef __linux__ | |||||
struct kmod_list *holders, *pos; | |||||
int err = 0; | |||||
@@ -280,6 +312,9 @@ static int igt_kmod_unload_r(struct kmod_module *kmod, | |||||
} | |||||
return kmod_module_remove_module(kmod, flags); | |||||
+#elif defined(__FreeBSD__) | |||||
+ return -ENOSYS; | |||||
+#endif | |||||
} | |||||
/** | |||||
@@ -296,6 +331,7 @@ igt_kmod_unload(const char *mod_name, unsigned int fla | |||||
int | |||||
igt_kmod_unload(const char *mod_name, unsigned int flags) | |||||
{ | |||||
+#ifdef __linux__ | |||||
struct kmod_ctx *ctx = kmod_ctx(); | |||||
struct kmod_module *kmod; | |||||
int err; | |||||
@@ -316,6 +352,9 @@ out: | |||||
out: | |||||
kmod_module_unref(kmod); | |||||
return err < 0 ? err : 0; | |||||
+#elif defined(__FreeBSD__) | |||||
+ return -ENOSYS; | |||||
+#endif | |||||
} | |||||
/** | |||||
@@ -326,6 +365,7 @@ igt_kmod_list_loaded(void) | |||||
void | |||||
igt_kmod_list_loaded(void) | |||||
{ | |||||
+#ifdef __linux__ | |||||
struct kmod_ctx *ctx = kmod_ctx(); | |||||
struct kmod_list *module, *list; | |||||
@@ -361,6 +401,7 @@ igt_kmod_list_loaded(void) | |||||
} | |||||
kmod_module_unref_list(list); | |||||
+#endif | |||||
} | |||||
static void *strdup_realloc(char *origptr, const char *strdata) | |||||
@@ -382,6 +423,7 @@ igt_i915_driver_load(const char *opts) | |||||
int | |||||
igt_i915_driver_load(const char *opts) | |||||
{ | |||||
+#ifdef __linux__ | |||||
int ret; | |||||
if (opts) | |||||
@@ -397,10 +439,14 @@ igt_i915_driver_load(const char *opts) | |||||
igt_kmod_load("snd_hda_intel", NULL); | |||||
return 0; | |||||
+#elif defined(__FreeBSD__) | |||||
+ return -ENOSYS; | |||||
+#endif | |||||
} | |||||
static int igt_always_unload_audio_driver(char **who) | |||||
{ | |||||
+#ifdef __linux__ | |||||
int ret; | |||||
const char *sound[] = { | |||||
"snd_hda_intel", | |||||
@@ -443,6 +489,9 @@ static int igt_always_unload_audio_driver(char **who) | |||||
} | |||||
} | |||||
return 0; | |||||
+#elif defined(__FreeBSD__) | |||||
+ return -ENOSYS; | |||||
+#endif | |||||
} | |||||
struct module_ref { | |||||
@@ -455,6 +504,7 @@ static struct module_ref *read_module_dependencies(uns | |||||
static struct module_ref *read_module_dependencies(unsigned int *num_mod) | |||||
{ | |||||
+#ifdef __linux__ | |||||
FILE *fp = fopen("/proc/modules", "r"); | |||||
struct module_ref *mod = NULL; | |||||
size_t line_buf_size = 0; | |||||
@@ -509,10 +559,15 @@ static struct module_ref *read_module_dependencies(uns | |||||
*num_mod = n_mod; | |||||
return mod; | |||||
+#elif defined(__FreeBSD__) | |||||
+ struct module_ref *mod = NULL; | |||||
+ return mod; | |||||
+#endif | |||||
} | |||||
static void free_module_ref(struct module_ref *mod, unsigned int num_mod) | |||||
{ | |||||
+#ifdef __linux__ | |||||
int i; | |||||
for (i = 0; i < num_mod; i++) { | |||||
@@ -520,11 +575,13 @@ static void free_module_ref(struct module_ref *mod, un | |||||
free(mod[i].required_by); | |||||
} | |||||
free(mod); | |||||
+#endif | |||||
} | |||||
static int igt_unload_driver(struct module_ref *mod, unsigned int num_mod, | |||||
unsigned int pos) | |||||
{ | |||||
+#ifdef __linux__ | |||||
int ret, i; | |||||
/* Recursively remove depending modules, if any */ | |||||
@@ -536,6 +593,9 @@ static int igt_unload_driver(struct module_ref *mod, u | |||||
} | |||||
return igt_kmod_unload(mod[pos].name, 0); | |||||
+#elif defined(__FreeBSD__) | |||||
+ return -ENOSYS; | |||||
+#endif | |||||
} | |||||
#define LINUX_VERSION(major, minor, patch) \ | |||||
@@ -543,6 +603,7 @@ static int linux_kernel_version(void) | |||||
static int linux_kernel_version(void) | |||||
{ | |||||
+#ifdef __linux__ | |||||
struct utsname utsname; | |||||
int ver[3] = { 0 }; | |||||
int i = 0; | |||||
@@ -572,10 +633,14 @@ static int linux_kernel_version(void) | |||||
} | |||||
return LINUX_VERSION(ver[0], ver[1], ver[2]); | |||||
+#elif defined(__FreeBSD__) | |||||
+ return -ENOSYS; | |||||
+#endif | |||||
} | |||||
int igt_audio_driver_unload(char **who) | |||||
{ | |||||
+#ifdef __linux__ | |||||
const char *drm_driver = "i915"; | |||||
unsigned int num_mod, i, j; | |||||
struct module_ref *mod; | |||||
@@ -647,10 +712,14 @@ ret: | |||||
free_module_ref(mod, num_mod); | |||||
return ret; | |||||
+#elif defined(__FreeBSD__) | |||||
+ return -ENOSYS; | |||||
+#endif | |||||
} | |||||
int __igt_i915_driver_unload(char **who) | |||||
{ | |||||
+#ifdef __linux__ | |||||
int ret; | |||||
const char *aux[] = { | |||||
@@ -694,6 +763,9 @@ int __igt_i915_driver_unload(char **who) | |||||
} | |||||
return 0; | |||||
+#elif defined(__FreeBSD__) | |||||
+ return -ENOSYS; | |||||
+#endif | |||||
} | |||||
/** | |||||
@@ -705,6 +777,7 @@ igt_i915_driver_unload(void) | |||||
int | |||||
igt_i915_driver_unload(void) | |||||
{ | |||||
+#ifdef __linux__ | |||||
char *who = NULL; | |||||
int ret; | |||||
@@ -731,6 +804,9 @@ igt_i915_driver_unload(void) | |||||
} | |||||
return 0; | |||||
+#elif defined(__FreeBSD__) | |||||
+ return -ENOSYS; | |||||
+#endif | |||||
} | |||||
/** | |||||
@@ -745,6 +821,7 @@ igt_amdgpu_driver_load(const char *opts) | |||||
int | |||||
igt_amdgpu_driver_load(const char *opts) | |||||
{ | |||||
+#ifdef __linux__ | |||||
if (opts) | |||||
igt_info("Reloading amdgpu with %s\n\n", opts); | |||||
@@ -756,6 +833,9 @@ igt_amdgpu_driver_load(const char *opts) | |||||
bind_fbcon(true); | |||||
return IGT_EXIT_SUCCESS; | |||||
+#elif defined(__FreeBSD__) | |||||
+ return -ENOSYS; | |||||
+#endif | |||||
} | |||||
/** | |||||
@@ -770,6 +850,7 @@ igt_amdgpu_driver_unload(void) | |||||
int | |||||
igt_amdgpu_driver_unload(void) | |||||
{ | |||||
+#ifdef __linux__ | |||||
bind_fbcon(false); | |||||
if (igt_kmod_is_loaded("amdgpu")) { | |||||
@@ -790,6 +871,9 @@ igt_amdgpu_driver_unload(void) | |||||
} | |||||
return IGT_EXIT_SUCCESS; | |||||
+#elif defined(__FreeBSD__) | |||||
+ return -ENOSYS; | |||||
+#endif | |||||
} | |||||
static void kmsg_dump(int fd) | |||||
@@ -834,6 +918,7 @@ static void tests_add(struct igt_kselftest_list *tl, s | |||||
static void tests_add(struct igt_kselftest_list *tl, struct igt_list_head *list) | |||||
{ | |||||
+#ifdef __linux__ | |||||
struct igt_kselftest_list *pos; | |||||
igt_list_for_each_entry(pos, list, link) | |||||
@@ -841,12 +926,14 @@ static void tests_add(struct igt_kselftest_list *tl, s | |||||
break; | |||||
igt_list_add_tail(&tl->link, &pos->link); | |||||
+#endif | |||||
} | |||||
void igt_kselftest_get_tests(struct kmod_module *kmod, | |||||
const char *filter, | |||||
struct igt_list_head *tests) | |||||
{ | |||||
+#ifdef __linux__ | |||||
const char *param_prefix = "igt__"; | |||||
const int prefix_len = strlen(param_prefix); | |||||
struct kmod_list *d, *pre; | |||||
@@ -892,19 +979,25 @@ void igt_kselftest_get_tests(struct kmod_module *kmod, | |||||
tests_add(tl, tests); | |||||
} | |||||
kmod_module_info_free_list(pre); | |||||
+#endif | |||||
} | |||||
static int open_parameters(const char *module_name) | |||||
{ | |||||
+#ifdef __linux__ | |||||
char path[256]; | |||||
snprintf(path, sizeof(path), "/sys/module/%s/parameters", module_name); | |||||
return open(path, O_RDONLY); | |||||
+#elif defined(__FreeBSD__) | |||||
+ return -ENOSYS; | |||||
+#endif | |||||
} | |||||
int igt_kselftest_init(struct igt_kselftest *tst, | |||||
const char *module_name) | |||||
{ | |||||
+#ifdef __linux__ | |||||
int err; | |||||
memset(tst, 0, sizeof(*tst)); | |||||
@@ -920,10 +1013,14 @@ int igt_kselftest_init(struct igt_kselftest *tst, | |||||
return err; | |||||
return 0; | |||||
+#elif defined(__FreeBSD__) | |||||
+ return -ENOSYS; | |||||
+#endif | |||||
} | |||||
int igt_kselftest_begin(struct igt_kselftest *tst) | |||||
{ | |||||
+#ifdef __linux__ | |||||
int err; | |||||
if (strcmp(tst->module_name, "i915") == 0) | |||||
@@ -935,6 +1032,9 @@ int igt_kselftest_begin(struct igt_kselftest *tst) | |||||
tst->kmsg = open("/dev/kmsg", O_RDONLY | O_NONBLOCK); | |||||
return 0; | |||||
+#elif defined(__FreeBSD__) | |||||
+ return -ENOSYS; | |||||
+#endif | |||||
} | |||||
int igt_kselftest_execute(struct igt_kselftest *tst, | |||||
@@ -942,6 +1042,7 @@ int igt_kselftest_execute(struct igt_kselftest *tst, | |||||
const char *options, | |||||
const char *result) | |||||
{ | |||||
+#ifdef __linux__ | |||||
unsigned long taints; | |||||
char buf[1024]; | |||||
int err; | |||||
@@ -973,18 +1074,25 @@ int igt_kselftest_execute(struct igt_kselftest *tst, | |||||
igt_assert_eq(igt_kernel_tainted(&taints), 0); | |||||
return err; | |||||
+#elif defined(__FreeBSD__) | |||||
+ return -ENOSYS; | |||||
+#endif | |||||
} | |||||
void igt_kselftest_end(struct igt_kselftest *tst) | |||||
{ | |||||
+#ifdef __linux__ | |||||
kmod_module_remove_module(tst->kmod, KMOD_REMOVE_FORCE); | |||||
close(tst->kmsg); | |||||
+#endif | |||||
} | |||||
void igt_kselftest_fini(struct igt_kselftest *tst) | |||||
{ | |||||
+#ifdef __linux__ | |||||
free(tst->module_name); | |||||
kmod_module_unref(tst->kmod); | |||||
+#endif | |||||
} | |||||
static const char *unfilter(const char *filter, const char *name) |