summaryrefslogtreecommitdiffstats
path: root/loader/pcmcia.c
blob: ec48a958c403b7f66426b7a16f5b85f7fc2c25b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>

#include "../isys/isys.h"

#include "log.h"
#include "modules.h"

int probe_main (int argc, char ** argv);
int cardmgr_main (int argc, char ** argv);

void startPcmcia(moduleList modLoaded, moduleDeps modDeps,
		 moduleInfoSet modInfo, int flags) {
    pid_t child;
    char * probeArgs[] = { "/sbin/probe", NULL };
    char * cardmgrArgs[] = { "/sbin/cardmgr", "-o", "-m", "/modules", "-d", 
			NULL };
    int p[2];
    char buf[4096];
    int i, status;
    char * pcic = NULL;
    char * line = NULL;

    logMessage("in startPcmcia()");

    pipe(p);

    if (!(child = fork())) {
	close(p[0]);
	dup2(p[1], 1);
	close(p[1]);
	exit(probe_main(1, probeArgs));
    }

    close(p[1]);
    
    waitpid(child, NULL, 0);

    i = read(p[0], buf, sizeof(buf));
    close(p[0]);
    buf[i] = '\0';

    logMessage("pcmcia probe returned: |%s|", buf);
 
    /* So this is totally counter-intuitive. Just remember that probe
       stops printing output once it finds a pcic, so this is actually
       correct */

    line = strtok(buf, "\r\n");

    do {
	if (!strstr(line, "not found"))
	{
	    if (strstr(line, "TCIC"))
	        pcic = "tcic";
	    else
		pcic = "i82365";
	}
    } while((line = strtok(NULL, "\r\n")));

    if (!pcic)
    {
	logMessage("no pcic controller found");
	return;
    }
    logMessage("need to load %s", pcic);

    if (mlLoadModule("pcmcia_core", NULL, modLoaded, modDeps, 
		     NULL, modInfo, flags)) {
	logMessage("failed to load pcmcia_core");
	return;
    }
    if (mlLoadModule(pcic, NULL, modLoaded, modDeps, NULL, 
		     modInfo, flags)) {
	logMessage("failed to load pcic");
	return;
    }
    if (mlLoadModule("ds", NULL, modLoaded, modDeps, NULL, 
		     modInfo, flags)) {
	logMessage("failed to load ds");
	return;
    }

    if (!(child = fork())) {
	exit(cardmgr_main(5, cardmgrArgs));
    }

    logMessage("cardmgr running as pid %d", child);

    waitpid(child, &status, 0);

    logMessage("cardmgr returned 0x%x", status);
}