Commit 9e8a6e88 authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] put ide_driver_t on lists

instead of messing with ide_module_t, we put ide_driver_t themselves on
a (cyclic) list - said list being the only use of ide_module_t for
high-level drivers.  ide_register_module()/ide_unregister_module() takes
ide_driver_t now (renamed to ide_register_driver()).  /proc/ide/drivers
switched to use of that cyclic list and uses seq_file instead of old
home-grown code.
parent 0d567824
......@@ -3085,10 +3085,6 @@ static ide_driver_t ide_cdrom_driver = {
drives: LIST_HEAD_INIT(ide_cdrom_driver.drives),
};
static ide_module_t ide_cdrom_module = {
info: &ide_cdrom_driver,
};
/* options */
char *ignore = NULL;
......@@ -3143,12 +3139,12 @@ static int ide_cdrom_reinit (ide_drive_t *drive)
static void __exit ide_cdrom_exit(void)
{
ide_unregister_module (&ide_cdrom_module);
ide_unregister_driver(&ide_cdrom_driver);
}
static int ide_cdrom_init(void)
{
ide_register_module(&ide_cdrom_module);
ide_register_driver(&ide_cdrom_driver);
return 0;
}
......
......@@ -1673,10 +1673,6 @@ static ide_driver_t idedisk_driver = {
drives: LIST_HEAD_INIT(idedisk_driver.drives),
};
static ide_module_t idedisk_module = {
info: &idedisk_driver,
};
MODULE_DESCRIPTION("ATA DISK Driver");
static int idedisk_reinit(ide_drive_t *drive)
......@@ -1710,12 +1706,12 @@ static int idedisk_reinit(ide_drive_t *drive)
static void __exit idedisk_exit (void)
{
ide_unregister_module(&idedisk_module);
ide_unregister_driver(&idedisk_driver);
}
static int idedisk_init (void)
{
ide_register_module(&idedisk_module);
ide_register_driver(&idedisk_driver);
return 0;
}
......
......@@ -2184,10 +2184,6 @@ static ide_driver_t idefloppy_driver = {
drives: LIST_HEAD_INIT(idefloppy_driver.drives),
};
static ide_module_t idefloppy_module = {
info: &idefloppy_driver,
};
static int idefloppy_reinit (ide_drive_t *drive)
{
idefloppy_floppy_t *floppy;
......@@ -2226,7 +2222,7 @@ MODULE_DESCRIPTION("ATAPI FLOPPY Driver");
static void __exit idefloppy_exit (void)
{
ide_unregister_module(&idefloppy_module);
ide_unregister_driver(&idefloppy_driver);
}
/*
......@@ -2235,7 +2231,7 @@ static void __exit idefloppy_exit (void)
static int idefloppy_init (void)
{
printk("ide-floppy driver " IDEFLOPPY_VERSION "\n");
ide_register_module(&idefloppy_module);
ide_register_driver(&idefloppy_driver);
return 0;
}
......
......@@ -67,6 +67,7 @@
#include <linux/ctype.h>
#include <linux/hdreg.h>
#include <linux/ide.h>
#include <linux/seq_file.h>
#include <asm/io.h>
......@@ -374,24 +375,6 @@ static int ide_getdigit(char c)
return digit;
}
static int proc_ide_read_drivers
(char *page, char **start, off_t off, int count, int *eof, void *data)
{
char *out = page;
int len;
ide_module_t *p = ide_modules;
ide_driver_t *driver;
while (p) {
driver = (ide_driver_t *) p->info;
if (driver)
out += sprintf(out, "%s version %s\n", driver->name, driver->version);
p = p->next;
}
len = out - page;
PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
}
static int proc_ide_read_imodel
(char *page, char **start, off_t off, int count, int *eof, void *data)
{
......@@ -832,15 +815,29 @@ static void destroy_proc_ide_interfaces(void)
}
}
extern struct seq_operations ide_drivers_op;
static int ide_drivers_open(struct inode *inode, struct file *file)
{
return seq_open(file, &ide_drivers_op);
}
static struct file_operations ide_drivers_operations = {
open: ide_drivers_open,
read: seq_read,
llseek: seq_lseek,
release: seq_release,
};
void proc_ide_create(void)
{
struct proc_dir_entry *entry;
proc_ide_root = proc_mkdir("ide", 0);
if (!proc_ide_root) return;
create_proc_ide_interfaces();
create_proc_read_entry("drivers", 0, proc_ide_root,
proc_ide_read_drivers, NULL);
entry = create_proc_entry("drivers", 0, proc_ide_root);
if (entry)
entry->proc_fops = &ide_drivers_operations;
#ifdef CONFIG_BLK_DEV_AEC62XX
if ((aec62xx_display_info) && (aec62xx_proc))
......
......@@ -6340,10 +6340,6 @@ static ide_driver_t idetape_driver = {
drives: LIST_HEAD_INIT(idetape_driver.drives),
};
static ide_module_t idetape_module = {
info: &idetape_driver,
};
/*
* Our character device supporting functions, passed to register_chrdev.
*/
......@@ -6414,7 +6410,7 @@ MODULE_LICENSE("GPL");
static void __exit idetape_exit (void)
{
ide_unregister_module(&idetape_module);
ide_unregister_driver(&idetape_driver);
unregister_chrdev(IDETAPE_MAJOR, "ht");
}
......@@ -6427,7 +6423,7 @@ static int idetape_init (void)
printk(KERN_ERR "ide-tape: Failed to register character device interface\n");
return -EBUSY;
}
ide_register_module(&idetape_module);
ide_register_driver(&idetape_driver);
return 0;
}
......
......@@ -151,6 +151,7 @@
#include <linux/completion.h>
#include <linux/reboot.h>
#include <linux/cdrom.h>
#include <linux/seq_file.h>
#include <asm/byteorder.h>
#include <asm/irq.h>
......@@ -196,7 +197,6 @@ int noautodma = 0;
/*
* ide_modules keeps track of the available IDE chipset/probe/driver modules.
*/
ide_module_t *ide_modules;
ide_module_t *ide_probe;
/*
......@@ -1900,6 +1900,41 @@ static int ide_release (struct inode * inode, struct file * file)
static LIST_HEAD(ata_unused);
static spinlock_t drives_lock = SPIN_LOCK_UNLOCKED;
static spinlock_t drivers_lock = SPIN_LOCK_UNLOCKED;
static LIST_HEAD(drivers);
/* Iterator */
static void *m_start(struct seq_file *m, loff_t *pos)
{
struct list_head *p;
loff_t l = *pos;
spin_lock(&drivers_lock);
list_for_each(p, &drivers)
if (!l--)
return list_entry(p, ide_driver_t, drivers);
return NULL;
}
static void *m_next(struct seq_file *m, void *v, loff_t *pos)
{
struct list_head *p = ((ide_driver_t *)v)->drivers.next;
(*pos)++;
return p==&drivers ? NULL : list_entry(p, ide_driver_t, drivers);
}
static void m_stop(struct seq_file *m, void *v)
{
spin_unlock(&drivers_lock);
}
static int show_driver(struct seq_file *m, void *v)
{
ide_driver_t *driver = v;
seq_printf(m, "%s version %s\n", driver->name, driver->version);
return 0;
}
struct seq_operations ide_drivers_op = {
start: m_start,
next: m_next,
stop: m_stop,
show: show_driver
};
/*
* Locking is badly broken here - since way back. That sucker is
......@@ -2508,10 +2543,10 @@ int system_bus_clock (void)
int ata_attach(ide_drive_t *drive)
{
ide_module_t *module;
struct list_head *p;
spin_lock(&drivers_lock);
for (module = ide_modules; module; module = module->next) {
ide_driver_t *driver = module->info;
list_for_each(p, &drivers) {
ide_driver_t *driver = list_entry(p, ide_driver_t, drivers);
if (!try_inc_mod_count(driver->owner))
continue;
spin_unlock(&drivers_lock);
......@@ -3523,20 +3558,12 @@ int ide_unregister_subdriver (ide_drive_t *drive)
return 0;
}
int ide_register_module (ide_module_t *module)
int ide_register_driver(ide_driver_t *driver)
{
ide_module_t *p;
struct list_head list;
spin_lock(&drivers_lock);
for (p = ide_modules; p; p = p->next) {
if (p == module) {
spin_unlock(&drivers_lock);
return 1;
}
}
module->next = ide_modules;
ide_modules = module;
list_add(&driver->drivers, &drivers);
spin_unlock(&drivers_lock);
spin_lock(&drives_lock);
......@@ -3553,16 +3580,12 @@ int ide_register_module (ide_module_t *module)
return 0;
}
void ide_unregister_module (ide_module_t *module)
void ide_unregister_driver(ide_driver_t *driver)
{
ide_driver_t *driver = module->info;
ide_module_t **p;
ide_drive_t *drive;
spin_lock(&drivers_lock);
for (p = &ide_modules; (*p) && (*p) != module; p = &((*p)->next));
if (*p)
*p = (*p)->next;
list_del(&driver->drivers);
spin_unlock(&drivers_lock);
while(!list_empty(&driver->drives)) {
......@@ -3591,8 +3614,8 @@ struct block_device_operations ide_fops[] = {{
}};
EXPORT_SYMBOL(ide_hwifs);
EXPORT_SYMBOL(ide_register_module);
EXPORT_SYMBOL(ide_unregister_module);
EXPORT_SYMBOL(ide_register_driver);
EXPORT_SYMBOL(ide_unregister_driver);
EXPORT_SYMBOL(ide_spin_wait_hwgroup);
/*
......
......@@ -569,10 +569,6 @@ static ide_driver_t idescsi_driver = {
drives: LIST_HEAD_INIT(idescsi_driver.drives),
};
static ide_module_t idescsi_module = {
info: &idescsi_driver,
};
static int idescsi_reinit(ide_drive_t *drive)
{
idescsi_scsi_t *scsi;
......@@ -847,7 +843,7 @@ static Scsi_Host_Template idescsi_template = {
static int __init init_idescsi_module(void)
{
ide_register_module(&idescsi_module);
ide_register_driver(&idescsi_driver);
scsi_register_host(&idescsi_template);
return 0;
}
......@@ -855,7 +851,7 @@ static int __init init_idescsi_module(void)
static void __exit exit_idescsi_module(void)
{
scsi_unregister_host(&idescsi_template);
ide_unregister_module(&idescsi_module);
ide_unregister_driver(&idescsi_driver);
}
module_init(init_idescsi_module);
......
......@@ -919,6 +919,7 @@ typedef struct ide_driver_s {
void (*ata_prebuilder)(ide_drive_t *);
void (*atapi_prebuilder)(ide_drive_t *);
struct list_head drives;
struct list_head drivers;
} ide_driver_t;
#define DRIVER(drive) ((drive)->driver)
......@@ -948,7 +949,6 @@ typedef struct ide_module_s {
*/
#ifndef _IDE_C
extern ide_hwif_t ide_hwifs[]; /* master data repository */
extern ide_module_t *ide_modules;
extern ide_module_t *ide_probe;
#endif
extern int noautodma;
......@@ -1219,8 +1219,8 @@ int ideprobe_init (void);
#endif /* CONFIG_BLK_DEV_IDE */
#endif /* _IDE_C */
int ide_register_module (ide_module_t *module);
void ide_unregister_module (ide_module_t *module);
int ide_register_driver(ide_driver_t *driver);
void ide_unregister_driver(ide_driver_t *driver);
int ide_register_subdriver (ide_drive_t *drive, ide_driver_t *driver, int version);
int ide_unregister_subdriver (ide_drive_t *drive);
int ide_replace_subdriver(ide_drive_t *drive, const char *driver);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment