3 * This file is subject to the terms and conditions of the GNU General Public
4 * License. See the file "COPYING" in the main directory of this archive
7 * ioconfig_bus - SGI's Persistent PCI Bus Numbering.
9 * Copyright (C) 1992-1997, 2000-2003 Silicon Graphics, Inc. All rights reserved.
12 #include <linux/types.h>
13 #include <linux/slab.h>
14 #include <linux/ctype.h>
15 #include <linux/module.h>
16 #include <linux/init.h>
18 #include <linux/pci.h>
20 #include <asm/sn/sgi.h>
21 #include <linux/devfs_fs.h>
22 #include <linux/devfs_fs_kernel.h>
24 #include <asm/sn/iograph.h>
25 #include <asm/sn/invent.h>
26 #include <asm/sn/hcl.h>
27 #include <asm/sn/labelcl.h>
28 #include <asm//sn/sn_sal.h>
29 #include <asm/sn/addrs.h>
30 #include <asm/sn/ioconfig_bus.h>
32 #define SGI_IOCONFIG_BUS "SGI-PERSISTENT PCI BUS NUMBERING"
33 #define SGI_IOCONFIG_BUS_VERSION "1.0"
36 * Some Global definitions.
38 devfs_handle_t ioconfig_bus_handle = NULL;
39 unsigned long ioconfig_bus_debug = 0;
41 #ifdef IOCONFIG_BUS_DEBUG
42 #define DBG(x...) printk(x)
47 u64 ioconfig_file = 0;
48 u64 ioconfig_file_size = 0;
49 u64 ioconfig_activated = 0;
50 char ioconfig_kernopts[128];
53 * For debugging purpose .. hardcode a table ..
55 struct ascii_moduleid *ioconfig_bus_table;
56 u64 ioconfig_bus_table_size = 0;
62 int next_basebus_number = 0;
65 ioconfig_get_busnum(char *io_moduleid, int *bus_num)
67 struct ascii_moduleid *temp;
70 DBG("ioconfig_get_busnum io_moduleid %s\n", io_moduleid);
73 temp = ioconfig_bus_table;
74 for (index = 0; index < free_entry; temp++, index++) {
75 if ( (io_moduleid[0] == temp->io_moduleid[0]) &&
76 (io_moduleid[1] == temp->io_moduleid[1]) &&
77 (io_moduleid[2] == temp->io_moduleid[2]) &&
78 (io_moduleid[4] == temp->io_moduleid[4]) &&
79 (io_moduleid[5] == temp->io_moduleid[5]) ) {
80 *bus_num = index * 0x10;
86 * New IO Brick encountered.
88 if (((int)io_moduleid[0]) == 0) {
89 DBG("ioconfig_get_busnum: Invalid Module Id given %s\n", io_moduleid);
94 strcpy((char *)&(ioconfig_bus_table[free_entry].io_moduleid), io_moduleid);
95 *bus_num = free_entry * 0x10;
100 dump_ioconfig_table()
104 struct ascii_moduleid *temp;
106 temp = ioconfig_bus_table;
107 while (index < free_entry) {
108 DBG("ASSCI Module ID %s\n", temp->io_moduleid);
116 * This routine returns the nextline in the buffer.
118 int nextline(char *buffer, char **next, char *line)
123 if (buffer[0] == 0x0) {
147 * This routine parses the ioconfig contents read into
148 * memory by ioconfig command in EFI and builds the
149 * persistent pci bus naming table.
152 build_moduleid_table(char *file_contents, struct ascii_moduleid *table)
155 * Read the whole file into memory.
163 struct ascii_moduleid *moduleid;
165 line = kmalloc(256, GFP_KERNEL);
167 name = kmalloc(125, GFP_KERNEL);
168 memset(name, 0, 125);
170 current = file_contents;
171 while (nextline(current, &next, line)){
173 DBG("current 0x%lx next 0x%lx\n", current, next);
177 * Skip all leading Blank lines ..
179 while (isspace(*temp))
187 memset(line, 0, 256);
196 memset(line, 0, 256);
201 * Get the next free entry in the table.
203 rc = sscanf(temp, "%s", name);
204 strcpy(&moduleid->io_moduleid[0], name);
205 DBG("Found %s\n", name);
209 memset(line, 0, 256);
212 new_entry = free_entry;
220 ioconfig_bus_init(void)
223 struct ia64_sal_retval ret_stuff;
227 DBG("ioconfig_bus_init called.\n");
229 for (cnode = 0; cnode < numnodes; cnode++) {
232 * Make SAL call to get the address of the bus configuration table.
234 ret_stuff.status = (uint64_t)0;
235 ret_stuff.v0 = (uint64_t)0;
236 ret_stuff.v1 = (uint64_t)0;
237 ret_stuff.v2 = (uint64_t)0;
238 nasid = COMPACT_TO_NASID_NODEID(cnode);
239 SAL_CALL(ret_stuff, SN_SAL_BUS_CONFIG, 0, nasid, 0, 0, 0, 0, 0);
240 temp = (u64 *)TO_NODE_CAC(nasid, ret_stuff.v0);
241 ioconfig_file = *temp;
242 DBG("ioconfig_bus_init: Nasid %d ret_stuff.v0 0x%lx\n", nasid,
245 ioconfig_file_size = ret_stuff.v1;
246 ioconfig_file = (ioconfig_file | CACHEABLE_MEM_SPACE);
247 ioconfig_activated = 1;
252 DBG("ioconfig_bus_init: ret_stuff.v0 %p ioconfig_file %p %d\n",
253 ret_stuff.v0, (void *)ioconfig_file, (int)ioconfig_file_size);
255 ioconfig_bus_table = kmalloc( 512, GFP_KERNEL );
256 memset(ioconfig_bus_table, 0, 512);
259 * If ioconfig options are given on the bootline .. take it.
261 if (*ioconfig_kernopts != '\0') {
263 * ioconfig="..." kernel options given.
265 DBG("ioconfig_bus_init: Kernel Options given.\n");
266 (void) build_moduleid_table((char *)ioconfig_kernopts, ioconfig_bus_table);
267 (void) dump_ioconfig_table(ioconfig_bus_table);
271 if (ioconfig_activated) {
272 DBG("ioconfig_bus_init: ioconfig file given.\n");
273 (void) build_moduleid_table((char *)ioconfig_file, ioconfig_bus_table);
274 (void) dump_ioconfig_table(ioconfig_bus_table);
276 DBG("ioconfig_bus_init: ioconfig command not executed in prom\n");
282 ioconfig_bus_new_entries(void)
287 struct ascii_moduleid *temp;
289 if ((ioconfig_activated) && (free_entry > new_entry)) {
290 printk("### Please add the following new IO Bricks Module ID \n");
291 printk("### to your Persistent Bus Numbering Config File\n");
296 temp = &ioconfig_bus_table[index];
297 while (index < free_entry) {
298 printk("%s\n", temp);
305 static int ioconfig_bus_ioctl(struct inode * inode, struct file * file,
306 unsigned int cmd, unsigned long arg)
309 struct ioconfig_parm parm;
312 * Copy in the parameters.
314 copy_from_user(&parm, (char *)arg, sizeof(struct ioconfig_parm));
315 parm.number = free_entry - new_entry;
316 parm.ioconfig_activated = ioconfig_activated;
317 copy_to_user((char *)arg, &parm, sizeof(struct ioconfig_parm));
318 copy_to_user((char *)parm.buffer, &ioconfig_bus_table[new_entry], sizeof(struct ascii_moduleid) * (free_entry - new_entry));
324 * ioconfig_bus_open - Opens the special device node "/dev/hw/.ioconfig_bus".
326 static int ioconfig_bus_open(struct inode * inode, struct file * filp)
328 if (ioconfig_bus_debug) {
329 DBG("ioconfig_bus_open called.\n");
337 * ioconfig_bus_close - Closes the special device node "/dev/hw/.ioconfig_bus".
339 static int ioconfig_bus_close(struct inode * inode, struct file * filp)
342 if (ioconfig_bus_debug) {
343 DBG("ioconfig_bus_close called.\n");
349 struct file_operations ioconfig_bus_fops = {
350 ioctl:ioconfig_bus_ioctl,
351 open:ioconfig_bus_open, /* open */
352 release:ioconfig_bus_close /* release */
357 * init_ifconfig_bus() - Boot time initialization. Ensure that it is called
358 * after devfs has been initialized.
361 int init_ioconfig_bus(void)
363 ioconfig_bus_handle = NULL;
364 ioconfig_bus_handle = hwgraph_register(hwgraph_root, ".ioconfig_bus",
365 0, DEVFS_FL_AUTO_DEVNUM,
367 S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP, 0, 0,
368 &ioconfig_bus_fops, NULL);
370 if (ioconfig_bus_handle == NULL) {
371 panic("Unable to create SGI PERSISTENT BUS NUMBERING Driver.\n");
378 static int __init ioconfig_bus_setup (char *str)
383 DBG("ioconfig_bus_setup: Kernel Options %s\n", str);
385 temp = (char *)ioconfig_kernopts;
386 memset(temp, 0, 128);
387 while ( (*str != '\0') && !isspace (*str) ) {
402 __setup("ioconfig=", ioconfig_bus_setup);