summaryrefslogtreecommitdiffstats
path: root/loader/pcmcia.c
blob: 7eadb90ba47d8efbc8a69c41240e51b8a4bcbb60 (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
#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, 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;

    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 */

    if (strstr(buf, "TCIC-2 probe: not found")) {
	logMessage("no pcic controller found");
	return;
    } else if (strstr(buf, "TCIC"))
	pcic = "tcic";
    else 
	pcic = "i82365";

    logMessage("need to load %s", pcic);

    if (mlLoadModule("pcmcia_core", NULL, modLoaded, modDeps, NULL, flags)) {
	logMessage("failed to load pcmcia_core");
	return;
    }
    if (mlLoadModule(pcic, NULL, modLoaded, modDeps, NULL, flags)) {
	logMessage("failed to load pcic");
	return;
    }
    if (mlLoadModule("ds", NULL, modLoaded, modDeps, NULL, 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);
}