aboutsummaryrefslogtreecommitdiffstats
path: root/arch/ia64/sn/io/ioconfig_bus.c
blob: 91dea65c3fceb55c93ce80a1d8b777573f1a31d2 (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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
/* $Id$
 *
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file "COPYING" in the main directory of this archive
 * for more details.
 *
 *  ioconfig_bus - SGI's Persistent PCI Bus Numbering.
 *
 * Copyright (C) 1992-1997, 2000-2003 Silicon Graphics, Inc.  All rights reserved.
 */

#include <linux/types.h>
#include <linux/slab.h>
#include <linux/ctype.h>
#include <linux/module.h>
#include <linux/init.h>

#include <linux/pci.h>

#include <asm/sn/sgi.h>
#include <linux/devfs_fs.h>
#include <linux/devfs_fs_kernel.h>
#include <asm/io.h>
#include <asm/sn/iograph.h>
#include <asm/sn/invent.h>
#include <asm/sn/hcl.h>
#include <asm/sn/labelcl.h>
#include <asm//sn/sn_sal.h>
#include <asm/sn/addrs.h>
#include <asm/sn/ioconfig_bus.h>

#define SGI_IOCONFIG_BUS "SGI-PERSISTENT PCI BUS NUMBERING"
#define SGI_IOCONFIG_BUS_VERSION "1.0"

/*
 * Some Global definitions.
 */
devfs_handle_t ioconfig_bus_handle = NULL;
unsigned long ioconfig_bus_debug = 0;

#ifdef IOCONFIG_BUS_DEBUG
#define DBG(x...)	printk(x)
#else
#define DBG(x...)
#endif

u64 ioconfig_file = 0;
u64 ioconfig_file_size = 0;
u64 ioconfig_activated = 0;
char ioconfig_kernopts[128];

/*
 * For debugging purpose .. hardcode a table ..
 */
struct  ascii_moduleid *ioconfig_bus_table;
u64 ioconfig_bus_table_size = 0;


int free_entry = 0;
int new_entry = 0;

int next_basebus_number = 0;

void
ioconfig_get_busnum(char *io_moduleid, int *bus_num)
{
	struct	ascii_moduleid  *temp;
	int index;

	DBG("ioconfig_get_busnum io_moduleid %s\n", io_moduleid);

	*bus_num = -1;
	temp = ioconfig_bus_table;
	for (index = 0; index < free_entry; temp++, index++) {
		if ( (io_moduleid[0] == temp->io_moduleid[0]) &&
		     (io_moduleid[1] == temp->io_moduleid[1]) &&
		     (io_moduleid[2] == temp->io_moduleid[2]) &&
		     (io_moduleid[4] == temp->io_moduleid[4]) &&
		     (io_moduleid[5] == temp->io_moduleid[5]) ) {
			*bus_num = index * 0x10;
			return;
		}
	}

	/*
	 * New IO Brick encountered.
	 */
	if (((int)io_moduleid[0]) == 0) {
		DBG("ioconfig_get_busnum: Invalid Module Id given %s\n", io_moduleid);
		return;
	}

	io_moduleid[3] = '#';
	strcpy((char *)&(ioconfig_bus_table[free_entry].io_moduleid), io_moduleid);
	*bus_num = free_entry * 0x10;
	free_entry++;
}

void
dump_ioconfig_table()
{

	int index = 0;
	struct ascii_moduleid *temp;

	temp = ioconfig_bus_table;
	while (index < free_entry) {
		DBG("ASSCI Module ID %s\n", temp->io_moduleid);
		temp++;
		index++;
	}
}

/*
 * nextline
 *	This routine returns the nextline in the buffer.
 */
int nextline(char *buffer, char **next, char *line)
{

	char *temp;

	if (buffer[0] == 0x0) {
		return(0);
	}

	temp = buffer;
	while (*temp != 0) {
		*line = *temp;
		if (*temp != '\n'){
			*line = *temp;
			temp++; line++;
		} else
			break;
	}

	if (*temp == 0)
		*next = temp;
	else
		*next = ++temp;

	return(1);
}

/*
 * build_pcibus_name
 *	This routine parses the ioconfig contents read into
 *	memory by ioconfig command in EFI and builds the
 *	persistent pci bus naming table.
 */
void
build_moduleid_table(char *file_contents, struct ascii_moduleid *table)
{
	/*
	 * Read the whole file into memory.
	 */
	int rc;
	char *name;
	char *temp;
	char *next;
	char *current;
	char *line;
	struct ascii_moduleid *moduleid;

	line = kmalloc(256, GFP_KERNEL);
	memset(line, 0,256);
	name = kmalloc(125, GFP_KERNEL);
	memset(name, 0, 125);
	moduleid = table;
	current = file_contents;
	while (nextline(current, &next, line)){

		DBG("current 0x%lx next 0x%lx\n", current, next);

		temp = line;
		/*
		 * Skip all leading Blank lines ..
		 */
		while (isspace(*temp))
			if (*temp != '\n')
				temp++;
			else
				break;

		if (*temp == '\n') {
			current = next;
			memset(line, 0, 256);
			continue;
		}
 
		/*
		 * Skip comment lines
		 */
		if (*temp == '#') {
			current = next;
			memset(line, 0, 256);
			continue;
		}

		/*
		 * Get the next free entry in the table.
		 */
		rc = sscanf(temp, "%s", name);
		strcpy(&moduleid->io_moduleid[0], name);
		DBG("Found %s\n", name);
		moduleid++;
		free_entry++;
		current = next;
		memset(line, 0, 256);
	}

	new_entry = free_entry;
	kfree(line);
	kfree(name);

	return;
}

void
ioconfig_bus_init(void)
{

	struct ia64_sal_retval ret_stuff;
	u64	*temp;
	int	cnode;

	DBG("ioconfig_bus_init called.\n");

        for (cnode = 0; cnode < numnodes; cnode++) {
		nasid_t nasid;
		/*
	 	 * Make SAL call to get the address of the bus configuration table.
	 	 */
		ret_stuff.status = (uint64_t)0;
		ret_stuff.v0 = (uint64_t)0;
		ret_stuff.v1 = (uint64_t)0;
		ret_stuff.v2 = (uint64_t)0;
		nasid = COMPACT_TO_NASID_NODEID(cnode);
		SAL_CALL(ret_stuff, SN_SAL_BUS_CONFIG, 0, nasid, 0, 0, 0, 0, 0);
		temp = (u64 *)TO_NODE_CAC(nasid, ret_stuff.v0);
		ioconfig_file = *temp;
		DBG("ioconfig_bus_init: Nasid %d ret_stuff.v0 0x%lx\n", nasid,
			ret_stuff.v0);
		if (ioconfig_file) {
			ioconfig_file_size = ret_stuff.v1;
			ioconfig_file = (ioconfig_file | CACHEABLE_MEM_SPACE);
			ioconfig_activated = 1;
			break;
		}
	}

	DBG("ioconfig_bus_init: ret_stuff.v0 %p ioconfig_file %p %d\n",
		ret_stuff.v0, (void *)ioconfig_file, (int)ioconfig_file_size);

	ioconfig_bus_table = kmalloc( 512, GFP_KERNEL );
	memset(ioconfig_bus_table, 0, 512);

	/*
	 * If ioconfig options are given on the bootline .. take it.
	 */
	if (*ioconfig_kernopts != '\0') {
		/*
		 * ioconfig="..." kernel options given.
		 */
		DBG("ioconfig_bus_init: Kernel Options given.\n");
		(void) build_moduleid_table((char *)ioconfig_kernopts, ioconfig_bus_table);
		(void) dump_ioconfig_table(ioconfig_bus_table);
		return;
	}

	if (ioconfig_activated) {
		DBG("ioconfig_bus_init: ioconfig file given.\n");
		(void) build_moduleid_table((char *)ioconfig_file, ioconfig_bus_table);
		(void) dump_ioconfig_table(ioconfig_bus_table);
	} else {
		DBG("ioconfig_bus_init: ioconfig command not executed in prom\n");
	}

}

void
ioconfig_bus_new_entries(void)
{

	
	int index = 0;
	struct ascii_moduleid *temp;

	if ((ioconfig_activated) && (free_entry > new_entry)) {
		printk("### Please add the following new IO Bricks Module ID \n");
		printk("### to your Persistent Bus Numbering Config File\n");
	} else
		return;

	index = new_entry;
	temp = &ioconfig_bus_table[index];
        while (index < free_entry) {
                printk("%s\n", temp);
		temp++;
                index++;
        }
	printk("### End\n");

}
static int ioconfig_bus_ioctl(struct inode * inode, struct file * file,
        unsigned int cmd, unsigned long arg)
{

	struct ioconfig_parm parm;

	/*
	 * Copy in the parameters.
	 */
	copy_from_user(&parm, (char *)arg, sizeof(struct ioconfig_parm));
	parm.number = free_entry - new_entry;
	parm.ioconfig_activated = ioconfig_activated;
	copy_to_user((char *)arg, &parm, sizeof(struct ioconfig_parm));
	copy_to_user((char *)parm.buffer, &ioconfig_bus_table[new_entry], sizeof(struct  ascii_moduleid) * (free_entry - new_entry));

	return 0;
}

/*
 * ioconfig_bus_open - Opens the special device node "/dev/hw/.ioconfig_bus".
 */
static int ioconfig_bus_open(struct inode * inode, struct file * filp)
{
	if (ioconfig_bus_debug) {
        	DBG("ioconfig_bus_open called.\n");
	}

        return(0);

}

/*
 * ioconfig_bus_close - Closes the special device node "/dev/hw/.ioconfig_bus".
 */
static int ioconfig_bus_close(struct inode * inode, struct file * filp)
{

	if (ioconfig_bus_debug) {
        	DBG("ioconfig_bus_close called.\n");
	}

        return(0);
}

struct file_operations ioconfig_bus_fops = {
	ioctl:ioconfig_bus_ioctl,
	open:ioconfig_bus_open,		/* open */
	release:ioconfig_bus_close	/* release */
};


/*
 * init_ifconfig_bus() - Boot time initialization.  Ensure that it is called 
 *	after devfs has been initialized.
 *
 */
int init_ioconfig_bus(void)
{
	ioconfig_bus_handle = NULL;
	ioconfig_bus_handle = hwgraph_register(hwgraph_root, ".ioconfig_bus",
			0, DEVFS_FL_AUTO_DEVNUM,
			0, 0,
			S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP, 0, 0,
			&ioconfig_bus_fops, NULL);

	if (ioconfig_bus_handle == NULL) {
		panic("Unable to create SGI PERSISTENT BUS NUMBERING Driver.\n");
	}

	return(0);

}

static int __init ioconfig_bus_setup (char *str)
{

	char *temp;

	DBG("ioconfig_bus_setup: Kernel Options %s\n", str);

	temp = (char *)ioconfig_kernopts;
	memset(temp, 0, 128);
	while ( (*str != '\0') && !isspace (*str) ) {
		if (*str == ',') {
			*temp = '\n';
			temp++;
			str++;
			continue;
		}
		*temp = *str;
		temp++;
		str++;
	}

	return(0);
		
}
__setup("ioconfig=", ioconfig_bus_setup);