]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/char/ipmi/ipmi_devintf.c
Merge master.kernel.org:/pub/scm/linux/kernel/git/davej/agpgart
[linux-2.6-omap-h63xx.git] / drivers / char / ipmi / ipmi_devintf.c
index e0a53570fea1a755485a90f1aa59c8778d753b26..81fcf0ce21d1c91cf95f478a960a20d2459a6772 100644 (file)
@@ -31,7 +31,6 @@
  *  675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/errno.h>
 #include <linux/poll.h>
 #include <linux/spinlock.h>
 #include <linux/slab.h>
-#include <linux/devfs_fs_kernel.h>
 #include <linux/ipmi.h>
-#include <asm/semaphore.h>
+#include <linux/mutex.h>
 #include <linux/init.h>
 #include <linux/device.h>
 #include <linux/compat.h>
 
-#define IPMI_DEVINTF_VERSION "v33"
-
 struct ipmi_file_private
 {
        ipmi_user_t          user;
@@ -57,7 +53,7 @@ struct ipmi_file_private
        struct file          *file;
        struct fasync_struct *fasync_queue;
        wait_queue_head_t    wait;
-       struct semaphore     recv_sem;
+       struct mutex         recv_mutex;
        int                  default_retries;
        unsigned int         default_retry_time_ms;
 };
@@ -92,7 +88,7 @@ static unsigned int ipmi_poll(struct file *file, poll_table *wait)
 
        spin_lock_irqsave(&priv->recv_msg_lock, flags);
 
-       if (! list_empty(&(priv->recv_msgs)))
+       if (!list_empty(&(priv->recv_msgs)))
                mask |= (POLLIN | POLLRDNORM);
 
        spin_unlock_irqrestore(&priv->recv_msg_lock, flags);
@@ -143,7 +139,7 @@ static int ipmi_open(struct inode *inode, struct file *file)
        INIT_LIST_HEAD(&(priv->recv_msgs));
        init_waitqueue_head(&priv->wait);
        priv->fasync_queue = NULL;
-       sema_init(&(priv->recv_sem), 1);
+       mutex_init(&priv->recv_mutex);
 
        /* Use the low-level defaults. */
        priv->default_retries = -1;
@@ -287,15 +283,15 @@ static int ipmi_ioctl(struct inode  *inode,
                        break;
                }
 
-               /* We claim a semaphore because we don't want two
+               /* We claim a mutex because we don't want two
                    users getting something from the queue at a time.
                    Since we have to release the spinlock before we can
                    copy the data to the user, it's possible another
                    user will grab something from the queue, too.  Then
                    the messages might get out of order if something
                    fails and the message gets put back onto the
-                   queue.  This semaphore prevents that problem. */
-               down(&(priv->recv_sem));
+                   queue.  This mutex prevents that problem. */
+               mutex_lock(&priv->recv_mutex);
 
                /* Grab the message off the list. */
                spin_lock_irqsave(&(priv->recv_msg_lock), flags);
@@ -354,7 +350,7 @@ static int ipmi_ioctl(struct inode  *inode,
                        goto recv_putback_on_err;
                }
 
-               up(&(priv->recv_sem));
+               mutex_unlock(&priv->recv_mutex);
                ipmi_free_recv_msg(msg);
                break;
 
@@ -364,11 +360,11 @@ static int ipmi_ioctl(struct inode  *inode,
                spin_lock_irqsave(&(priv->recv_msg_lock), flags);
                list_add(entry, &(priv->recv_msgs));
                spin_unlock_irqrestore(&(priv->recv_msg_lock), flags);
-               up(&(priv->recv_sem));
+               mutex_unlock(&priv->recv_mutex);
                break;
 
        recv_err:
-               up(&(priv->recv_sem));
+               mutex_unlock(&priv->recv_mutex);
                break;
        }
 
@@ -381,7 +377,8 @@ static int ipmi_ioctl(struct inode  *inode,
                        break;
                }
 
-               rv = ipmi_register_for_cmd(priv->user, val.netfn, val.cmd);
+               rv = ipmi_register_for_cmd(priv->user, val.netfn, val.cmd,
+                                          IPMI_CHAN_ALL);
                break;
        }
 
@@ -394,7 +391,36 @@ static int ipmi_ioctl(struct inode  *inode,
                        break;
                }
 
-               rv = ipmi_unregister_for_cmd(priv->user, val.netfn, val.cmd);
+               rv = ipmi_unregister_for_cmd(priv->user, val.netfn, val.cmd,
+                                            IPMI_CHAN_ALL);
+               break;
+       }
+
+       case IPMICTL_REGISTER_FOR_CMD_CHANS:
+       {
+               struct ipmi_cmdspec_chans val;
+
+               if (copy_from_user(&val, arg, sizeof(val))) {
+                       rv = -EFAULT;
+                       break;
+               }
+
+               rv = ipmi_register_for_cmd(priv->user, val.netfn, val.cmd,
+                                          val.chans);
+               break;
+       }
+
+       case IPMICTL_UNREGISTER_FOR_CMD_CHANS:
+       {
+               struct ipmi_cmdspec_chans val;
+
+               if (copy_from_user(&val, arg, sizeof(val))) {
+                       rv = -EFAULT;
+                       break;
+               }
+
+               rv = ipmi_unregister_for_cmd(priv->user, val.netfn, val.cmd,
+                                            val.chans);
                break;
        }
 
@@ -411,6 +437,7 @@ static int ipmi_ioctl(struct inode  *inode,
                break;
        }
 
+       /* The next four are legacy, not per-channel. */
        case IPMICTL_SET_MY_ADDRESS_CMD:
        {
                unsigned int val;
@@ -420,22 +447,25 @@ static int ipmi_ioctl(struct inode  *inode,
                        break;
                }
 
-               ipmi_set_my_address(priv->user, val);
-               rv = 0;
+               rv = ipmi_set_my_address(priv->user, 0, val);
                break;
        }
 
        case IPMICTL_GET_MY_ADDRESS_CMD:
        {
-               unsigned int val;
+               unsigned int  val;
+               unsigned char rval;
 
-               val = ipmi_get_my_address(priv->user);
+               rv = ipmi_get_my_address(priv->user, 0, &rval);
+               if (rv)
+                       break;
+
+               val = rval;
 
                if (copy_to_user(arg, &val, sizeof(val))) {
                        rv = -EFAULT;
                        break;
                }
-               rv = 0;
                break;
        }
 
@@ -448,24 +478,94 @@ static int ipmi_ioctl(struct inode  *inode,
                        break;
                }
 
-               ipmi_set_my_LUN(priv->user, val);
-               rv = 0;
+               rv = ipmi_set_my_LUN(priv->user, 0, val);
                break;
        }
 
        case IPMICTL_GET_MY_LUN_CMD:
        {
-               unsigned int val;
+               unsigned int  val;
+               unsigned char rval;
+
+               rv = ipmi_get_my_LUN(priv->user, 0, &rval);
+               if (rv)
+                       break;
 
-               val = ipmi_get_my_LUN(priv->user);
+               val = rval;
 
                if (copy_to_user(arg, &val, sizeof(val))) {
                        rv = -EFAULT;
                        break;
                }
-               rv = 0;
                break;
        }
+
+       case IPMICTL_SET_MY_CHANNEL_ADDRESS_CMD:
+       {
+               struct ipmi_channel_lun_address_set val;
+
+               if (copy_from_user(&val, arg, sizeof(val))) {
+                       rv = -EFAULT;
+                       break;
+               }
+
+               return ipmi_set_my_address(priv->user, val.channel, val.value);
+               break;
+       }
+
+       case IPMICTL_GET_MY_CHANNEL_ADDRESS_CMD:
+       {
+               struct ipmi_channel_lun_address_set val;
+
+               if (copy_from_user(&val, arg, sizeof(val))) {
+                       rv = -EFAULT;
+                       break;
+               }
+
+               rv = ipmi_get_my_address(priv->user, val.channel, &val.value);
+               if (rv)
+                       break;
+
+               if (copy_to_user(arg, &val, sizeof(val))) {
+                       rv = -EFAULT;
+                       break;
+               }
+               break;
+       }
+
+       case IPMICTL_SET_MY_CHANNEL_LUN_CMD:
+       {
+               struct ipmi_channel_lun_address_set val;
+
+               if (copy_from_user(&val, arg, sizeof(val))) {
+                       rv = -EFAULT;
+                       break;
+               }
+
+               rv = ipmi_set_my_LUN(priv->user, val.channel, val.value);
+               break;
+       }
+
+       case IPMICTL_GET_MY_CHANNEL_LUN_CMD:
+       {
+               struct ipmi_channel_lun_address_set val;
+
+               if (copy_from_user(&val, arg, sizeof(val))) {
+                       rv = -EFAULT;
+                       break;
+               }
+
+               rv = ipmi_get_my_LUN(priv->user, val.channel, &val.value);
+               if (rv)
+                       break;
+
+               if (copy_to_user(arg, &val, sizeof(val))) {
+                       rv = -EFAULT;
+                       break;
+               }
+               break;
+       }
+
        case IPMICTL_SET_TIMING_PARMS_CMD:
        {
                struct ipmi_timing_parms parms;
@@ -663,7 +763,8 @@ static long compat_ipmi_ioctl(struct file *filep, unsigned int cmd,
        case COMPAT_IPMICTL_RECEIVE_MSG:
        case COMPAT_IPMICTL_RECEIVE_MSG_TRUNC:
        {
-               struct ipmi_recv   *precv64, recv64;
+               struct ipmi_recv   __user *precv64;
+               struct ipmi_recv   recv64;
 
                if (get_compat_ipmi_recv(&recv64, compat_ptr(arg)))
                        return -EFAULT;
@@ -676,7 +777,7 @@ static long compat_ipmi_ioctl(struct file *filep, unsigned int cmd,
                                ((cmd == COMPAT_IPMICTL_RECEIVE_MSG)
                                 ? IPMICTL_RECEIVE_MSG
                                 : IPMICTL_RECEIVE_MSG_TRUNC),
-                               (long) precv64);
+                               (unsigned long) precv64);
                if (rc != 0)
                        return rc;
 
@@ -694,7 +795,7 @@ static long compat_ipmi_ioctl(struct file *filep, unsigned int cmd,
 }
 #endif
 
-static struct file_operations ipmi_fops = {
+static const struct file_operations ipmi_fops = {
        .owner          = THIS_MODULE,
        .ioctl          = ipmi_ioctl,
 #ifdef CONFIG_COMPAT
@@ -716,22 +817,50 @@ MODULE_PARM_DESC(ipmi_major, "Sets the major number of the IPMI device.  By"
                 " interface.  Other values will set the major device number"
                 " to that value.");
 
+/* Keep track of the devices that are registered. */
+struct ipmi_reg_list {
+       dev_t            dev;
+       struct list_head link;
+};
+static LIST_HEAD(reg_list);
+static DEFINE_MUTEX(reg_list_mutex);
+
 static struct class *ipmi_class;
 
-static void ipmi_new_smi(int if_num)
+static void ipmi_new_smi(int if_num, struct device *device)
 {
        dev_t dev = MKDEV(ipmi_major, if_num);
+       struct ipmi_reg_list *entry;
 
-       devfs_mk_cdev(dev, S_IFCHR | S_IRUSR | S_IWUSR,
-                     "ipmidev/%d", if_num);
+       entry = kmalloc(sizeof(*entry), GFP_KERNEL);
+       if (!entry) {
+               printk(KERN_ERR "ipmi_devintf: Unable to create the"
+                      " ipmi class device link\n");
+               return;
+       }
+       entry->dev = dev;
 
-       class_device_create(ipmi_class, dev, NULL, "ipmi%d", if_num);
+       mutex_lock(&reg_list_mutex);
+       class_device_create(ipmi_class, NULL, dev, device, "ipmi%d", if_num);
+       list_add(&entry->link, &reg_list);
+       mutex_unlock(&reg_list_mutex);
 }
 
 static void ipmi_smi_gone(int if_num)
 {
-       class_device_destroy(ipmi_class, MKDEV(ipmi_major, if_num));
-       devfs_remove("ipmidev/%d", if_num);
+       dev_t dev = MKDEV(ipmi_major, if_num);
+       struct ipmi_reg_list *entry;
+
+       mutex_lock(&reg_list_mutex);
+       list_for_each_entry(entry, &reg_list, link) {
+               if (entry->dev == dev) {
+                       list_del(&entry->link);
+                       kfree(entry);
+                       break;
+               }
+       }
+       class_device_destroy(ipmi_class, dev);
+       mutex_unlock(&reg_list_mutex);
 }
 
 static struct ipmi_smi_watcher smi_watcher =
@@ -748,8 +877,7 @@ static __init int init_ipmi_devintf(void)
        if (ipmi_major < 0)
                return -EINVAL;
 
-       printk(KERN_INFO "ipmi device interface version "
-              IPMI_DEVINTF_VERSION "\n");
+       printk(KERN_INFO "ipmi device interface\n");
 
        ipmi_class = class_create(THIS_MODULE, "ipmi");
        if (IS_ERR(ipmi_class)) {
@@ -768,8 +896,6 @@ static __init int init_ipmi_devintf(void)
                ipmi_major = rv;
        }
 
-       devfs_mk_dir(DEVICE_NAME);
-
        rv = ipmi_smi_watcher_register(&smi_watcher);
        if (rv) {
                unregister_chrdev(ipmi_major, DEVICE_NAME);
@@ -784,11 +910,20 @@ module_init(init_ipmi_devintf);
 
 static __exit void cleanup_ipmi(void)
 {
+       struct ipmi_reg_list *entry, *entry2;
+       mutex_lock(&reg_list_mutex);
+       list_for_each_entry_safe(entry, entry2, &reg_list, link) {
+               list_del(&entry->link);
+               class_device_destroy(ipmi_class, entry->dev);
+               kfree(entry);
+       }
+       mutex_unlock(&reg_list_mutex);
        class_destroy(ipmi_class);
        ipmi_smi_watcher_unregister(&smi_watcher);
-       devfs_remove(DEVICE_NAME);
        unregister_chrdev(ipmi_major, DEVICE_NAME);
 }
 module_exit(cleanup_ipmi);
 
 MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Corey Minyard <minyard@mvista.com>");
+MODULE_DESCRIPTION("Linux device interface for the IPMI message handler.");