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#include <linux/module.h>
48#include <linux/types.h>
49#include <linux/string.h>
50#include <linux/kernel.h>
51#include <linux/interrupt.h>
52#include <linux/major.h>
53#include <linux/errno.h>
54#include <linux/genhd.h>
55#include <linux/slab.h>
56#include <linux/init.h>
57#include <linux/pci.h>
58#include <linux/ide.h>
59#include <linux/hdreg.h>
60#include <linux/completion.h>
61#include <linux/device.h>
62
63struct class *ide_port_class;
64
65
66
67
68
69
70
71
72int ide_device_get(ide_drive_t *drive)
73{
74 struct device *host_dev;
75 struct module *module;
76
77 if (!get_device(&drive->gendev))
78 return -ENXIO;
79
80 host_dev = drive->hwif->host->dev[0];
81 module = host_dev ? host_dev->driver->owner : NULL;
82
83 if (module && !try_module_get(module)) {
84 put_device(&drive->gendev);
85 return -ENXIO;
86 }
87
88 return 0;
89}
90EXPORT_SYMBOL_GPL(ide_device_get);
91
92
93
94
95
96
97
98
99void ide_device_put(ide_drive_t *drive)
100{
101#ifdef CONFIG_MODULE_UNLOAD
102 struct device *host_dev = drive->hwif->host->dev[0];
103 struct module *module = host_dev ? host_dev->driver->owner : NULL;
104
105 if (module)
106 module_put(module);
107#endif
108 put_device(&drive->gendev);
109}
110EXPORT_SYMBOL_GPL(ide_device_put);
111
112static int ide_bus_match(struct device *dev, struct device_driver *drv)
113{
114 return 1;
115}
116
117static int ide_uevent(struct device *dev, struct kobj_uevent_env *env)
118{
119 ide_drive_t *drive = to_ide_device(dev);
120
121 add_uevent_var(env, "MEDIA=%s", ide_media_string(drive));
122 add_uevent_var(env, "DRIVENAME=%s", drive->name);
123 add_uevent_var(env, "MODALIAS=ide:m-%s", ide_media_string(drive));
124 return 0;
125}
126
127static int generic_ide_probe(struct device *dev)
128{
129 ide_drive_t *drive = to_ide_device(dev);
130 struct ide_driver *drv = to_ide_driver(dev->driver);
131
132 return drv->probe ? drv->probe(drive) : -ENODEV;
133}
134
135static int generic_ide_remove(struct device *dev)
136{
137 ide_drive_t *drive = to_ide_device(dev);
138 struct ide_driver *drv = to_ide_driver(dev->driver);
139
140 if (drv->remove)
141 drv->remove(drive);
142
143 return 0;
144}
145
146static void generic_ide_shutdown(struct device *dev)
147{
148 ide_drive_t *drive = to_ide_device(dev);
149 struct ide_driver *drv = to_ide_driver(dev->driver);
150
151 if (dev->driver && drv->shutdown)
152 drv->shutdown(drive);
153}
154
155struct bus_type ide_bus_type = {
156 .name = "ide",
157 .match = ide_bus_match,
158 .uevent = ide_uevent,
159 .probe = generic_ide_probe,
160 .remove = generic_ide_remove,
161 .shutdown = generic_ide_shutdown,
162 .dev_attrs = ide_dev_attrs,
163 .suspend = generic_ide_suspend,
164 .resume = generic_ide_resume,
165};
166
167EXPORT_SYMBOL_GPL(ide_bus_type);
168
169int ide_vlb_clk;
170EXPORT_SYMBOL_GPL(ide_vlb_clk);
171
172module_param_named(vlb_clock, ide_vlb_clk, int, 0);
173MODULE_PARM_DESC(vlb_clock, "VLB clock frequency (in MHz)");
174
175int ide_pci_clk;
176EXPORT_SYMBOL_GPL(ide_pci_clk);
177
178module_param_named(pci_clock, ide_pci_clk, int, 0);
179MODULE_PARM_DESC(pci_clock, "PCI bus clock frequency (in MHz)");
180
181static int ide_set_dev_param_mask(const char *s, struct kernel_param *kp)
182{
183 int a, b, i, j = 1;
184 unsigned int *dev_param_mask = (unsigned int *)kp->arg;
185
186
187 if (sscanf(s, "%d.%d:%d", &a, &b, &j) != 3 &&
188 sscanf(s, "%d.%d", &a, &b) != 2)
189 return -EINVAL;
190
191 i = a * MAX_DRIVES + b;
192
193 if (i >= MAX_HWIFS * MAX_DRIVES || j < 0 || j > 1)
194 return -EINVAL;
195
196 if (j)
197 *dev_param_mask |= (1 << i);
198 else
199 *dev_param_mask &= ~(1 << i);
200
201 return 0;
202}
203
204static unsigned int ide_nodma;
205
206module_param_call(nodma, ide_set_dev_param_mask, NULL, &ide_nodma, 0);
207MODULE_PARM_DESC(nodma, "disallow DMA for a device");
208
209static unsigned int ide_noflush;
210
211module_param_call(noflush, ide_set_dev_param_mask, NULL, &ide_noflush, 0);
212MODULE_PARM_DESC(noflush, "disable flush requests for a device");
213
214static unsigned int ide_nohpa;
215
216module_param_call(nohpa, ide_set_dev_param_mask, NULL, &ide_nohpa, 0);
217MODULE_PARM_DESC(nohpa, "disable Host Protected Area for a device");
218
219static unsigned int ide_noprobe;
220
221module_param_call(noprobe, ide_set_dev_param_mask, NULL, &ide_noprobe, 0);
222MODULE_PARM_DESC(noprobe, "skip probing for a device");
223
224static unsigned int ide_nowerr;
225
226module_param_call(nowerr, ide_set_dev_param_mask, NULL, &ide_nowerr, 0);
227MODULE_PARM_DESC(nowerr, "ignore the ATA_DF bit for a device");
228
229static unsigned int ide_cdroms;
230
231module_param_call(cdrom, ide_set_dev_param_mask, NULL, &ide_cdroms, 0);
232MODULE_PARM_DESC(cdrom, "force device as a CD-ROM");
233
234struct chs_geom {
235 unsigned int cyl;
236 u8 head;
237 u8 sect;
238};
239
240static unsigned int ide_disks;
241static struct chs_geom ide_disks_chs[MAX_HWIFS * MAX_DRIVES];
242
243static int ide_set_disk_chs(const char *str, struct kernel_param *kp)
244{
245 int a, b, c = 0, h = 0, s = 0, i, j = 1;
246
247
248
249 if (sscanf(str, "%d.%d:%d,%d,%d", &a, &b, &c, &h, &s) != 5 &&
250 sscanf(str, "%d.%d:%d", &a, &b, &j) != 3)
251 return -EINVAL;
252
253 i = a * MAX_DRIVES + b;
254
255 if (i >= MAX_HWIFS * MAX_DRIVES || j < 0 || j > 1)
256 return -EINVAL;
257
258 if (c > INT_MAX || h > 255 || s > 255)
259 return -EINVAL;
260
261 if (j)
262 ide_disks |= (1 << i);
263 else
264 ide_disks &= ~(1 << i);
265
266 ide_disks_chs[i].cyl = c;
267 ide_disks_chs[i].head = h;
268 ide_disks_chs[i].sect = s;
269
270 return 0;
271}
272
273module_param_call(chs, ide_set_disk_chs, NULL, NULL, 0);
274MODULE_PARM_DESC(chs, "force device as a disk (using CHS)");
275
276static void ide_dev_apply_params(ide_drive_t *drive, u8 unit)
277{
278 int i = drive->hwif->index * MAX_DRIVES + unit;
279
280 if (ide_nodma & (1 << i)) {
281 printk(KERN_INFO "ide: disallowing DMA for %s\n", drive->name);
282 drive->dev_flags |= IDE_DFLAG_NODMA;
283 }
284 if (ide_noflush & (1 << i)) {
285 printk(KERN_INFO "ide: disabling flush requests for %s\n",
286 drive->name);
287 drive->dev_flags |= IDE_DFLAG_NOFLUSH;
288 }
289 if (ide_nohpa & (1 << i)) {
290 printk(KERN_INFO "ide: disabling Host Protected Area for %s\n",
291 drive->name);
292 drive->dev_flags |= IDE_DFLAG_NOHPA;
293 }
294 if (ide_noprobe & (1 << i)) {
295 printk(KERN_INFO "ide: skipping probe for %s\n", drive->name);
296 drive->dev_flags |= IDE_DFLAG_NOPROBE;
297 }
298 if (ide_nowerr & (1 << i)) {
299 printk(KERN_INFO "ide: ignoring the ATA_DF bit for %s\n",
300 drive->name);
301 drive->bad_wstat = BAD_R_STAT;
302 }
303 if (ide_cdroms & (1 << i)) {
304 printk(KERN_INFO "ide: forcing %s as a CD-ROM\n", drive->name);
305 drive->dev_flags |= IDE_DFLAG_PRESENT;
306 drive->media = ide_cdrom;
307
308 drive->ready_stat = 0;
309 }
310 if (ide_disks & (1 << i)) {
311 drive->cyl = drive->bios_cyl = ide_disks_chs[i].cyl;
312 drive->head = drive->bios_head = ide_disks_chs[i].head;
313 drive->sect = drive->bios_sect = ide_disks_chs[i].sect;
314
315 printk(KERN_INFO "ide: forcing %s as a disk (%d/%d/%d)\n",
316 drive->name,
317 drive->cyl, drive->head, drive->sect);
318
319 drive->dev_flags |= IDE_DFLAG_FORCED_GEOM | IDE_DFLAG_PRESENT;
320 drive->media = ide_disk;
321 drive->ready_stat = ATA_DRDY;
322 }
323}
324
325static unsigned int ide_ignore_cable;
326
327static int ide_set_ignore_cable(const char *s, struct kernel_param *kp)
328{
329 int i, j = 1;
330
331
332
333 if (sscanf(s, "%d:%d", &i, &j) != 2 && sscanf(s, "%d", &i) != 1)
334 return -EINVAL;
335
336 if (i >= MAX_HWIFS || j < 0 || j > 1)
337 return -EINVAL;
338
339 if (j)
340 ide_ignore_cable |= (1 << i);
341 else
342 ide_ignore_cable &= ~(1 << i);
343
344 return 0;
345}
346
347module_param_call(ignore_cable, ide_set_ignore_cable, NULL, NULL, 0);
348MODULE_PARM_DESC(ignore_cable, "ignore cable detection");
349
350void ide_port_apply_params(ide_hwif_t *hwif)
351{
352 ide_drive_t *drive;
353 int i;
354
355 if (ide_ignore_cable & (1 << hwif->index)) {
356 printk(KERN_INFO "ide: ignoring cable detection for %s\n",
357 hwif->name);
358 hwif->cbl = ATA_CBL_PATA40_SHORT;
359 }
360
361 ide_port_for_each_dev(i, drive, hwif)
362 ide_dev_apply_params(drive, i);
363}
364
365
366
367
368static int __init ide_init(void)
369{
370 int ret;
371
372 printk(KERN_INFO "Uniform Multi-Platform E-IDE driver\n");
373
374 ret = bus_register(&ide_bus_type);
375 if (ret < 0) {
376 printk(KERN_WARNING "IDE: bus_register error: %d\n", ret);
377 return ret;
378 }
379
380 ide_port_class = class_create(THIS_MODULE, "ide_port");
381 if (IS_ERR(ide_port_class)) {
382 ret = PTR_ERR(ide_port_class);
383 goto out_port_class;
384 }
385
386 ide_acpi_init();
387
388 proc_ide_create();
389
390 return 0;
391
392out_port_class:
393 bus_unregister(&ide_bus_type);
394
395 return ret;
396}
397
398static void __exit ide_exit(void)
399{
400 proc_ide_destroy();
401
402 class_destroy(ide_port_class);
403
404 bus_unregister(&ide_bus_type);
405}
406
407module_init(ide_init);
408module_exit(ide_exit);
409
410MODULE_LICENSE("GPL");
411