2 * Find I2O capable controllers on the PCI bus, and register/install
3 * them with the I2O layer
5 * (C) Copyright 1999 Red Hat Software
7 * Written by Alan Cox, Building Number Three Ltd
8 * Modified by Deepak Saxena <deepak@plexity.net>
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version
13 * 2 of the License, or (at your option) any later version.
16 * Support polled I2O PCI controllers.
19 #include <linux/module.h>
20 #include <linux/kernel.h>
21 #include <linux/pci.h>
22 #include <linux/i2o.h>
23 #include <linux/errno.h>
24 #include <linux/init.h>
25 #include <linux/malloc.h>
31 * See <include/linux/i2o.h> for an explanation
33 static struct i2o_core_func_table
*core
;
35 /* Core attach function */
36 extern int i2o_pci_core_attach(struct i2o_core_func_table
*);
37 extern void i2o_pci_core_detach(void);
41 * Free bus specific resources
43 static void i2o_pci_dispose(struct i2o_controller
*c
)
45 I2O_IRQ_WRITE32(c
,0xFFFFFFFF);
46 if(c
->bus
.pci
.irq
> 0)
47 free_irq(c
->bus
.pci
.irq
, c
);
48 iounmap(((u8
*)c
->post_port
)-0x40);
52 * No real bus specific handling yet (note that later we will
53 * need to 'steal' PCI devices on i960 mainboards)
56 static int i2o_pci_bind(struct i2o_controller
*c
, struct i2o_device
*dev
)
62 static int i2o_pci_unbind(struct i2o_controller
*c
, struct i2o_device
*dev
)
69 * Bus specific interrupt handler
72 static void i2o_pci_interrupt(int irq
, void *dev_id
, struct pt_regs
*r
)
74 struct i2o_controller
*c
= dev_id
;
83 * Install a PCI (or in theory AGP) i2o controller
86 int __init
i2o_pci_install(struct pci_dev
*dev
)
88 struct i2o_controller
*c
=kmalloc(sizeof(struct i2o_controller
),
98 printk(KERN_ERR
"i2o_pci: insufficient memory to add controller.\n");
101 memset(c
, 0, sizeof(*c
));
105 /* Skip I/O spaces */
106 if(!(dev
->resource
[i
].flags
&PCI_BASE_ADDRESS_SPACE
))
108 memptr
=dev
->resource
[i
].start
;
115 printk(KERN_ERR
"i2o_pci: I2O controller has no memory regions defined.\n");
120 size
= dev
->resource
[i
].end
-dev
->resource
[i
].start
+1;
121 /* Map the I2O controller */
123 printk(KERN_INFO
"PCI I2O controller at 0x%08X size=%d\n", memptr
, size
);
124 mem
= ioremap(memptr
, size
);
127 printk(KERN_ERR
"i2o_pci: Unable to map controller.\n");
134 c
->irq_mask
= (volatile u32
*)(mem
+0x34);
135 c
->post_port
= (volatile u32
*)(mem
+0x40);
136 c
->reply_port
= (volatile u32
*)(mem
+0x44);
138 c
->mem_phys
= memptr
;
139 c
->mem_offset
= (u32
)mem
;
140 c
->destructor
= i2o_pci_dispose
;
142 c
->bind
= i2o_pci_bind
;
143 c
->unbind
= i2o_pci_unbind
;
145 c
->type
= I2O_TYPE_PCI
;
147 I2O_IRQ_WRITE32(c
,0xFFFFFFFF);
150 i
= core
->install(c
);
152 i
= i2o_install_controller(c
);
157 printk(KERN_ERR
"i2o: unable to install controller.\n");
163 c
->bus
.pci
.irq
= dev
->irq
;
166 i
=request_irq(dev
->irq
, i2o_pci_interrupt
, SA_SHIRQ
,
170 printk(KERN_ERR
"%s: unable to allocate interrupt %d.\n",
176 i2o_delete_controller(c
);
186 int __init
i2o_pci_scan(void)
191 printk(KERN_INFO
"Checking for PCI I2O controllers...\n");
193 for(dev
=pci_devices
; dev
!=NULL
; dev
=dev
->next
)
195 if((dev
->class>>8)!=PCI_CLASS_INTELLIGENT_I2O
)
197 if((dev
->class&0xFF)>1)
199 printk(KERN_INFO
"I2O controller found but does not support I2O 1.5 (skipping).\n");
202 printk(KERN_INFO
"I2O controller on bus %d at %d.\n",
203 dev
->bus
->number
, dev
->devfn
);
205 if(i2o_pci_install(dev
)==0)
209 printk(KERN_INFO
"%d I2O controller%s found and installed.\n", count
,
211 return count
?count
:-ENODEV
;
214 static void i2o_pci_unload(void)
217 struct i2o_controller
*c
;
219 for(i
= 0; i
< MAX_I2O_CONTROLLERS
; i
++)
224 c
=i2o_find_controller(i
);
233 i2o_unlock_controller(c
);
236 if(c
->type
== I2O_TYPE_PCI
)
240 i2o_delete_controller(c
);
245 static void i2o_pci_activate(void)
248 struct i2o_controller
*c
;
250 for(i
= 0; i
< MAX_I2O_CONTROLLERS
; i
++)
255 c
=i2o_find_controller(i
);
261 if(c
->type
== I2O_TYPE_PCI
)
264 if(core
->activate(c
))
266 if(i2o_activate_controller(c
))
269 printk("I2O: Failed to initialize iop%d\n", c
->unit
);
274 i2o_unlock_controller(c
);
275 i2o_delete_controller(c
);
279 I2O_IRQ_WRITE32(c
,0);
284 i2o_unlock_controller(c
);
292 int i2o_pci_core_attach(struct i2o_core_func_table
*table
)
300 if((i
= i2o_pci_scan())<0)
307 void i2o_pci_core_detach(void)
314 int init_module(void)
316 printk(KERN_INFO
"Linux I2O PCI support (c) 1999 Red Hat Software.\n");
319 * Let the core call the scan function for module dependency
320 * reasons. See include/linux/i2o.h for the reason why this
323 * if(i2o_pci_scan()<0)
325 * i2o_pci_activate();
332 void cleanup_module(void)
336 EXPORT_SYMBOL(i2o_pci_core_attach
);
337 EXPORT_SYMBOL(i2o_pci_core_detach
);
339 MODULE_AUTHOR("Red Hat Software");
340 MODULE_DESCRIPTION("I2O PCI Interface");
343 void __init
i2o_pci_init(void)
345 printk(KERN_INFO
"Linux I2O PCI support (c) 1999 Red Hat Software.\n");
346 if(i2o_pci_scan()>=0)