summaryrefslogtreecommitdiffstats
path: root/loader2/pcmcia.c
blob: bf4b3df5e0aab2c5bfae34fb64638631ba3c9976 (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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
 * pcmcia.c - pcmcia functionality
 *
 * Erik Troan <ewt@redhat.com>
 * Matt Wilson <msw@redhat.com>
 * Michael Fulbright <msf@redhat.com>
 * Jeremy Katz <katzj@redhat.com>
 * Bill Nottingham <notting@redhat.com>
 *
 * Copyright 1999 - 2005 Red Hat, Inc.
 *
 * This software may be freely redistributed under the terms of the GNU
 * General Public License.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <errno.h>
#include <fcntl.h>
#include <kudzu/kudzu.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <unistd.h>

#include "loader.h"
#include "loadermisc.h"
#include "log.h"
#include "modules.h"

/* boot flags */
extern int flags;

char * getPcicController() {
    struct device ** devices;
    static int probed = 0;
    static char * pcic = NULL;

    if (!probed) {
        probed = 1;
 
        devices = probeDevices(CLASS_SOCKET, BUS_UNSPEC, 0);
	if (devices) {    
	    int x;
		
	    for (x = 0; devices[x]; x++) {
		    if (devices[x]->driver) {
			    char *tmp;
			    
			    logMessage(DEBUGLVL, "found pcmcia adapter %s", devices[x]->driver);
			    if (!pcic)
				    tmp = strdup(devices[x]->driver);
			    else {
				    tmp = sdupprintf("%s:%s",pcic,devices[x]->driver);
				    free(pcic);
			    }
			    pcic = tmp;
		    }
	    }
        }

        if (!pcic) {
            logMessage(DEBUGLVL, "no pcic controller found");
        }
        return pcic;
    } else {
        return pcic;
    }
}

int startupPcmciaControllers() {
	char *adj_io[] = {
		"0x00000100 - 0x000003af",
		"0x000003bb - 0x000004cf",
		"0x000004d8 - 0x000004ff",
		"0x00000a00 - 0x00000aff",
		"0x00000c00 - 0x00000cff",
		"0x00004000 - 0x00008fff",
		NULL
	};
	char *adj_mem[] = {
		"0x000c0000 - 0x000fffff",
		"0x60000000 - 0x60ffffff",
		"0xa0000000 - 0xa0ffffff",
		"0xc0200000 - 0xcfffffff",
		"0xe8000000 - 0xefffffff",
		NULL
	};
	char path[128];
	int x;
	
	for (x = 0; ; x++) {
		int y;
		FILE *f;
		
		sprintf(path,"/sys/class/pcmcia_socket/pcmcia_socket%d/available_resources_io", x);
		f = fopen(path, "w");
		if (!f)
			break;
		for (y = 0; adj_io[y]; y++) {
			fprintf(f, "%s\n", adj_io[y]);
		}
		fclose(f);
		
		sprintf(path,"/sys/class/pcmcia_socket/pcmcia_socket%d/available_resources_mem", x);
		f = fopen(path, "w");
		if (!f)
			break;
		for (y = 0; adj_mem[y]; y++) {
			fprintf(f, "%s\n", adj_mem[y]);
		}
		fclose(f);
		
		sprintf(path,"/sys/class/pcmcia_socket/pcmcia_socket%d/available_resources_setup_done", x);
		f = fopen(path,"w");
		if (!f)
			break;
		fprintf(f,"1\n");
		fclose(f);
	}
	return 0;
}

int initializePcmciaController(moduleList modLoaded, moduleDeps modDeps,
                               moduleInfoSet modInfo) {
    char * pcic = NULL;
    char * mods;

    if (FL_NOPCMCIA(flags) || FL_TESTING(flags))
	return 0;

    pcic = getPcicController();
    if (!pcic)
        return 0;

    mods = sdupprintf("pcmcia_core:%s:pcmcia", pcic);
    mlLoadModuleSet(mods, modLoaded, modDeps, modInfo);
	
    startupPcmciaControllers();
    return 0;
}