* added 0.99 linux version
[mascara-docs.git] / i386 / linux / linux-2.3.21 / drivers / i2o / i2o_pci.c
blobf7afa9a46b6e43eb0f1b1c3db8f2ccd5c2961c13
1 /*
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
6 *
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.
15 * TODO:
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>
26 #include <asm/io.h>
28 #ifdef MODULE
30 * Core function table
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);
38 #endif /* MODULE */
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)
58 MOD_INC_USE_COUNT;
59 return 0;
62 static int i2o_pci_unbind(struct i2o_controller *c, struct i2o_device *dev)
64 MOD_DEC_USE_COUNT;
65 return 0;
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;
75 #ifdef MODULE
76 core->run_queue(c);
77 #else
78 i2o_run_queue(c);
79 #endif /* MODULE */
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),
89 GFP_KERNEL);
90 u8 *mem;
91 u32 memptr = 0;
92 u32 size;
94 int i;
96 if(c==NULL)
98 printk(KERN_ERR "i2o_pci: insufficient memory to add controller.\n");
99 return -ENOMEM;
101 memset(c, 0, sizeof(*c));
103 for(i=0; i<6; i++)
105 /* Skip I/O spaces */
106 if(!(dev->resource[i].flags&PCI_BASE_ADDRESS_SPACE))
108 memptr=dev->resource[i].start;
109 break;
113 if(i==6)
115 printk(KERN_ERR "i2o_pci: I2O controller has no memory regions defined.\n");
116 kfree(c);
117 return -EINVAL;
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);
125 if(mem==NULL)
127 printk(KERN_ERR "i2o_pci: Unable to map controller.\n");
128 kfree(c);
129 return -EINVAL;
132 c->bus.pci.irq = -1;
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);
149 #ifdef MODULE
150 i = core->install(c);
151 #else
152 i = i2o_install_controller(c);
153 #endif /* MODULE */
155 if(i<0)
157 printk(KERN_ERR "i2o: unable to install controller.\n");
158 kfree(c);
159 iounmap(mem);
160 return i;
163 c->bus.pci.irq = dev->irq;
164 if(c->bus.pci.irq)
166 i=request_irq(dev->irq, i2o_pci_interrupt, SA_SHIRQ,
167 c->name, c);
168 if(i<0)
170 printk(KERN_ERR "%s: unable to allocate interrupt %d.\n",
171 c->name, dev->irq);
172 c->bus.pci.irq = -1;
173 #ifdef MODULE
174 core->delete(c);
175 #else
176 i2o_delete_controller(c);
177 #endif /* MODULE */
178 kfree(c);
179 iounmap(mem);
180 return -EBUSY;
183 return 0;
186 int __init i2o_pci_scan(void)
188 struct pci_dev *dev;
189 int count=0;
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)
196 continue;
197 if((dev->class&0xFF)>1)
199 printk(KERN_INFO "I2O controller found but does not support I2O 1.5 (skipping).\n");
200 continue;
202 printk(KERN_INFO "I2O controller on bus %d at %d.\n",
203 dev->bus->number, dev->devfn);
204 pci_set_master(dev);
205 if(i2o_pci_install(dev)==0)
206 count++;
208 if(count)
209 printk(KERN_INFO "%d I2O controller%s found and installed.\n", count,
210 count==1?"":"s");
211 return count?count:-ENODEV;
214 static void i2o_pci_unload(void)
216 int i=0;
217 struct i2o_controller *c;
219 for(i = 0; i < MAX_I2O_CONTROLLERS; i++)
221 #ifdef MODULE
222 c=core->find(i);
223 #else
224 c=i2o_find_controller(i);
225 #endif /* MODULE */
227 if(c==NULL)
228 continue;
230 #ifdef MODULE
231 core->unlock(c);
232 #else
233 i2o_unlock_controller(c);
234 #endif /* MODULE */
236 if(c->type == I2O_TYPE_PCI)
237 #ifdef MODULE
238 core->delete(c);
239 #else
240 i2o_delete_controller(c);
241 #endif /* MODULE */
245 static void i2o_pci_activate(void)
247 int i=0;
248 struct i2o_controller *c;
250 for(i = 0; i < MAX_I2O_CONTROLLERS; i++)
252 #ifdef MODULE
253 c=core->find(i);
254 #else
255 c=i2o_find_controller(i);
256 #endif /* MODULE */
258 if(c==NULL)
259 continue;
261 if(c->type == I2O_TYPE_PCI)
263 #ifdef MODULE
264 if(core->activate(c))
265 #else
266 if(i2o_activate_controller(c))
267 #endif /* MODULE */
269 printk("I2O: Failed to initialize iop%d\n", c->unit);
270 #ifdef MODULE
271 core->unlock(c);
272 core->delete(c);
273 #else
274 i2o_unlock_controller(c);
275 i2o_delete_controller(c);
276 #endif
277 continue;
279 I2O_IRQ_WRITE32(c,0);
281 #ifdef MODULE
282 core->unlock(c);
283 #else
284 i2o_unlock_controller(c);
285 #endif
290 #ifdef MODULE
292 int i2o_pci_core_attach(struct i2o_core_func_table *table)
294 int i;
296 MOD_INC_USE_COUNT;
298 core = table;
300 if((i = i2o_pci_scan())<0)
301 return -ENODEV;
302 i2o_pci_activate();
304 return i;
307 void i2o_pci_core_detach(void)
309 i2o_pci_unload();
311 MOD_DEC_USE_COUNT;
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
321 * is done.
323 * if(i2o_pci_scan()<0)
324 * return -ENODEV;
325 * i2o_pci_activate();
328 return 0;
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");
342 #else
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)
348 i2o_pci_activate();
351 #endif