Skip to content

Commit 3449744

Browse files
committed
rproc: Support -s for PAS based remoteproc as well
The old mechanism searched for remoteproc instances from the qcom_q6v5_mss driver, but in modern platforms the MSA based remoteproc model has been replaced by the PAS based one. As such we use the common qcom_q6v5_pas driver - as with other subsystems. Use the modalias to find remoteproc drivers with the mpss-pas or mss-pil compatible to find these, and fall back to the old heuristics if this fails. Signed-off-by: Bjorn Andersson <[email protected]>
1 parent 710e6cf commit 3449744

File tree

1 file changed

+84
-11
lines changed

1 file changed

+84
-11
lines changed

rproc.c

Lines changed: 84 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,74 @@
1313
#include "rmtfs.h"
1414

1515
#define RPROC_BASE_PATH "/sys/bus/platform/drivers/qcom-q6v5-mss/"
16+
#define RPROC_CLASS_PATH "/sys/class/remoteproc/"
1617

1718
static pthread_t start_thread;
1819
static pthread_t stop_thread;
1920
static int rproc_state_fd;
2021
static int rproc_pipe[2];
2122

22-
int rproc_init(void)
23+
static int rproc_init_by_modalias(void)
24+
{
25+
struct dirent *rproc_de;
26+
char modalias[256];
27+
DIR *base_dir;
28+
int modalias_fd;
29+
int rproc_fd;
30+
int state_fd = -1;
31+
int base_fd;
32+
int ret;
33+
34+
base_fd = open(RPROC_CLASS_PATH, O_RDONLY | O_DIRECTORY);
35+
if (base_fd < 0)
36+
return -1;
37+
38+
base_dir = fdopendir(base_fd);
39+
if (!base_dir) {
40+
fprintf(stderr, "failed to open remoteproc class path\n");
41+
close(base_fd);
42+
return -1;
43+
}
44+
45+
while (state_fd < 0 && (rproc_de = readdir(base_dir)) != NULL) {
46+
if (!strcmp(rproc_de->d_name, ".") ||
47+
!strcmp(rproc_de->d_name, ".."))
48+
continue;
49+
50+
rproc_fd = openat(base_fd, rproc_de->d_name, O_RDONLY | O_DIRECTORY);
51+
if (rproc_fd < 0)
52+
continue;
53+
54+
modalias_fd = openat(rproc_fd, "device/modalias", O_RDONLY);
55+
if (modalias_fd < 0)
56+
goto close_rproc_fd;
57+
58+
ret = read(modalias_fd, modalias, sizeof(modalias));
59+
if (ret < 0)
60+
goto close_modalias_fd;
61+
62+
if (!strstr(modalias, "-mpss-pas") && !strstr(modalias, "-mss-pil"))
63+
goto close_modalias_fd;
64+
65+
state_fd = openat(rproc_fd, "state", O_WRONLY);
66+
if (state_fd < 0) {
67+
fprintf(stderr,
68+
"unable to open remoteproc \"state\" control file of %s\n",
69+
rproc_de->d_name);
70+
}
71+
72+
close_modalias_fd:
73+
close(modalias_fd);
74+
close_rproc_fd:
75+
close(rproc_fd);
76+
}
77+
closedir(base_dir);
78+
close(base_fd);
79+
80+
return state_fd;
81+
}
82+
83+
static int rproc_init_by_mss_driver(void)
2384
{
2485
struct dirent *device_de;
2586
struct dirent *rproc_de;
@@ -28,10 +89,8 @@ int rproc_init(void)
2889
DIR *base_dir;
2990
int device_fd;
3091
int rproc_fd;
92+
int state_fd = -1;
3193
int base_fd;
32-
int ret;
33-
34-
rproc_state_fd = -1;
3594

3695
base_fd = open(RPROC_BASE_PATH, O_RDONLY | O_DIRECTORY);
3796
if (base_fd < 0)
@@ -44,7 +103,7 @@ int rproc_init(void)
44103
return -1;
45104
}
46105

47-
while (rproc_state_fd < 0 && (device_de = readdir(base_dir)) != NULL) {
106+
while (state_fd < 0 && (device_de = readdir(base_dir)) != NULL) {
48107
if (!strcmp(device_de->d_name, ".") ||
49108
!strcmp(device_de->d_name, ".."))
50109
continue;
@@ -60,7 +119,7 @@ int rproc_init(void)
60119
}
61120

62121
rproc_dir = fdopendir(rproc_base_fd);
63-
while (rproc_state_fd < 0 && (rproc_de = readdir(rproc_dir)) != NULL) {
122+
while (state_fd < 0 && (rproc_de = readdir(rproc_dir)) != NULL) {
64123
if (!strcmp(rproc_de->d_name, ".") ||
65124
!strcmp(rproc_de->d_name, ".."))
66125
continue;
@@ -69,8 +128,8 @@ int rproc_init(void)
69128
if (rproc_fd < 0)
70129
continue;
71130

72-
rproc_state_fd = openat(rproc_fd, "state", O_WRONLY);
73-
if (rproc_state_fd < 0) {
131+
state_fd = openat(rproc_fd, "state", O_WRONLY);
132+
if (state_fd < 0) {
74133
fprintf(stderr,
75134
"unable to open remoteproc \"state\" control file of %s\n",
76135
device_de->d_name);
@@ -86,15 +145,29 @@ int rproc_init(void)
86145
closedir(base_dir);
87146
close(base_fd);
88147

89-
if (rproc_state_fd < 0)
90-
return -1;
148+
return state_fd;
149+
}
150+
151+
int rproc_init(void)
152+
{
153+
int state_fd;
154+
int ret;
155+
156+
state_fd = rproc_init_by_modalias();
157+
if (state_fd < 0) {
158+
state_fd = rproc_init_by_mss_driver();
159+
if (state_fd < 0)
160+
return -1;
161+
}
91162

92163
ret = pipe(rproc_pipe);
93164
if (ret < 0) {
94-
close(rproc_state_fd);
165+
close(state_fd);
95166
return -1;
96167
}
97168

169+
rproc_state_fd = state_fd;
170+
98171
return rproc_pipe[0];
99172
}
100173

0 commit comments

Comments
 (0)