summaryrefslogtreecommitdiffstats
path: root/loader2/pcmcia.c
blob: 61e652ca54946471caa3c22e01d551855d3a205b (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
144
145
146
147
148
149
150
151
152
153
154
155
/*
 * pcmcia.c - pcmcia functionality
 *
 * Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005  Red Hat, Inc.
 * All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Red Hat Author(s): 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>
 */

#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 uint64_t 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;
                            int i;
			    
			    logMessage(DEBUGLVL, "found pcmcia adapter %s", devices[x]->driver);
			    if (!pcic)
				    tmp = strdup(devices[x]->driver);
			    else {
                                    i = asprintf(&tmp, "%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;
    int i;

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

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

    i = asprintf(&mods, "pcmcia_core:%s:pcmcia", pcic);
    free(pcic);
    mlLoadModuleSet(mods, modLoaded, modDeps, modInfo);
    free(mods);

    startupPcmciaControllers();
    return 0;
}