Skip to content

Commit f1158d8

Browse files
committed
lima-textured-cube: Automatically load mali kernel module
Move the kernel module loading code into a separate source file and use it for both lima-memtester and lima-textured-cube. Signed-off-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
1 parent 2755687 commit f1158d8

File tree

6 files changed

+126
-34
lines changed

6 files changed

+126
-34
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ include_directories(limadriver/include limadriver/limare/lib
99
limadriver/limare/tests/common)
1010

1111
add_executable(lima-textured-cube
12-
textured_cube_mainloop.c
12+
lima-textured-cube.c textured_cube_mainloop.c load_mali_kernel_module.c
1313
limadriver/limare/lib/gp.c limadriver/limare/lib/limare.c
1414
limadriver/limare/lib/bmp.c limadriver/limare/lib/program.c
1515
limadriver/limare/lib/plb.c limadriver/limare/lib/dump.c
@@ -24,7 +24,7 @@ add_executable(lima-textured-cube
2424
target_link_libraries(lima-textured-cube m rt ${CMAKE_THREAD_LIBS_INIT})
2525

2626
add_executable(lima-memtester
27-
main.c textured_cube_mainloop.c
27+
lima-memtester.c textured_cube_mainloop.c load_mali_kernel_module.c
2828
memtester-4.3.0/memtester.c memtester-4.3.0/tests.c
2929
memtester-4.3.0/arm-asm-helpers.S
3030
limadriver/limare/lib/gp.c limadriver/limare/lib/limare.c

main.c renamed to lima-memtester.c

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,11 @@
2626
#include <stdio.h>
2727
#include <stdlib.h>
2828
#include <string.h>
29+
#include "load_mali_kernel_module.h"
2930

3031
int textured_cube_main(void);
3132
int memtester_main(int argc, char *argv[]);
3233

33-
static void check_kernel_cmdline(void)
34-
{
35-
char buffer[1024];
36-
FILE *f = fopen("/proc/cmdline", "r");
37-
if (!f) {
38-
printf("Warning: can't open /proc/cmdline\n");
39-
return;
40-
}
41-
if (fgets(buffer, sizeof(buffer), f) &&
42-
strstr(buffer, "sunxi_no_mali_mem_reserve"))
43-
{
44-
fprintf(stderr, "Please remove 'sunxi_no_mali_mem_reserve' option from\n");
45-
fprintf(stderr, "your kernel command line. Otherwise the mali kernel\n");
46-
fprintf(stderr, "driver may be non-functional and actually knock down\n");
47-
fprintf(stderr, "your system with some old linux-sunxi kernels.\n");
48-
abort();
49-
}
50-
fclose(f);
51-
}
52-
5334
static void *lima_thread(void *threadid)
5435
{
5536
textured_cube_main();
@@ -62,13 +43,7 @@ static void start_lima_thread(void)
6243
{
6344
pthread_t th;
6445

65-
check_kernel_cmdline();
66-
67-
if (system("modprobe mali >/dev/null 2>&1")) {
68-
fprintf(stderr, "Failed to 'modprobe mali'.\n");
69-
abort();
70-
}
71-
46+
load_mali_kernel_module();
7247
pthread_create(&th, NULL, lima_thread, NULL);
7348

7449
/* Wait a bit and let lima stop spamming to the console */

lima-textured-cube.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) 2014 Siarhei Siamashka
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sub license,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice (including the
12+
* next paragraph) shall be included in all copies or substantial portions
13+
* of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21+
* DEALINGS IN THE SOFTWARE.
22+
*/
23+
24+
#include <unistd.h>
25+
#include <stdio.h>
26+
#include <stdlib.h>
27+
#include <string.h>
28+
#include "load_mali_kernel_module.h"
29+
30+
int textured_cube_main(void);
31+
32+
int main(int argc, char *argv[])
33+
{
34+
load_mali_kernel_module();
35+
textured_cube_main();
36+
return 0;
37+
}

load_mali_kernel_module.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (c) 2014 Siarhei Siamashka
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sub license,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice (including the
12+
* next paragraph) shall be included in all copies or substantial portions
13+
* of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21+
* DEALINGS IN THE SOFTWARE.
22+
*/
23+
24+
#include <stdlib.h>
25+
#include <stdio.h>
26+
#include <string.h>
27+
28+
static void check_kernel_cmdline(void)
29+
{
30+
char buffer[1024];
31+
FILE *f = fopen("/proc/cmdline", "r");
32+
if (!f) {
33+
printf("Warning: can't open /proc/cmdline\n");
34+
return;
35+
}
36+
if (fgets(buffer, sizeof(buffer), f) &&
37+
strstr(buffer, "sunxi_no_mali_mem_reserve"))
38+
{
39+
fprintf(stderr, "Please remove 'sunxi_no_mali_mem_reserve' option from\n");
40+
fprintf(stderr, "your kernel command line. Otherwise the mali kernel\n");
41+
fprintf(stderr, "driver may be non-functional and actually knock down\n");
42+
fprintf(stderr, "your system with some old linux-sunxi kernels.\n");
43+
abort();
44+
}
45+
fclose(f);
46+
}
47+
48+
void load_mali_kernel_module(void)
49+
{
50+
check_kernel_cmdline();
51+
52+
if (system("modprobe mali >/dev/null 2>&1")) {
53+
fprintf(stderr, "Failed to 'modprobe mali'.\n");
54+
abort();
55+
}
56+
}

load_mali_kernel_module.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) 2014 Siarhei Siamashka
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sub license,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice (including the
12+
* next paragraph) shall be included in all copies or substantial portions
13+
* of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21+
* DEALINGS IN THE SOFTWARE.
22+
*/
23+
24+
#ifndef LOAD_MALI_KERNEL_MODULE_H
25+
#define LOAD_MALI_KERNEL_MODULE_H
26+
27+
void load_mali_kernel_module(void);
28+
29+
#endif

textured_cube_mainloop.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,7 @@
2929
#include "cube_mesh.h"
3030
#include "companion.h"
3131

32-
#ifdef MEMTESTER_MODE
3332
int textured_cube_main(void)
34-
#else
35-
int
36-
main(int argc, char *argv[])
37-
#endif
3833
{
3934
struct limare_state *state;
4035
int ret;

0 commit comments

Comments
 (0)