summaryrefslogtreecommitdiff
path: root/drivers/char/ipmi/kcs_bmc.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/char/ipmi/kcs_bmc.c')
-rw-r--r--drivers/char/ipmi/kcs_bmc.c80
1 files changed, 74 insertions, 6 deletions
diff --git a/drivers/char/ipmi/kcs_bmc.c b/drivers/char/ipmi/kcs_bmc.c
index 2ec934f0dba3..9860c7b75157 100644
--- a/drivers/char/ipmi/kcs_bmc.c
+++ b/drivers/char/ipmi/kcs_bmc.c
@@ -5,7 +5,9 @@
*/
#include <linux/device.h>
+#include <linux/list.h>
#include <linux/module.h>
+#include <linux/mutex.h>
#include "kcs_bmc.h"
@@ -13,6 +15,11 @@
#include "kcs_bmc_device.h"
#include "kcs_bmc_client.h"
+/* Record registered devices and drivers */
+static DEFINE_MUTEX(kcs_bmc_lock);
+static LIST_HEAD(kcs_bmc_devices);
+static LIST_HEAD(kcs_bmc_drivers);
+
/* Consumer data access */
u8 kcs_bmc_read_data(struct kcs_bmc_device *kcs_bmc)
@@ -98,22 +105,83 @@ void kcs_bmc_disable_device(struct kcs_bmc_device *kcs_bmc, struct kcs_bmc_clien
}
EXPORT_SYMBOL(kcs_bmc_disable_device);
-int kcs_bmc_ipmi_add_device(struct kcs_bmc_device *kcs_bmc);
int kcs_bmc_add_device(struct kcs_bmc_device *kcs_bmc)
{
- return kcs_bmc_ipmi_add_device(kcs_bmc);
+ struct kcs_bmc_driver *drv;
+ int error = 0;
+ int rc;
+
+ spin_lock_init(&kcs_bmc->lock);
+ kcs_bmc->client = NULL;
+
+ mutex_lock(&kcs_bmc_lock);
+ list_add(&kcs_bmc->entry, &kcs_bmc_devices);
+ list_for_each_entry(drv, &kcs_bmc_drivers, entry) {
+ rc = drv->ops->add_device(kcs_bmc);
+ if (!rc)
+ continue;
+
+ dev_err(kcs_bmc->dev, "Failed to add chardev for KCS channel %d: %d",
+ kcs_bmc->channel, rc);
+ error = rc;
+ }
+ mutex_unlock(&kcs_bmc_lock);
+
+ return error;
}
EXPORT_SYMBOL(kcs_bmc_add_device);
-int kcs_bmc_ipmi_remove_device(struct kcs_bmc_device *kcs_bmc);
void kcs_bmc_remove_device(struct kcs_bmc_device *kcs_bmc)
{
- if (kcs_bmc_ipmi_remove_device(kcs_bmc))
- pr_warn("Failed to remove device for KCS channel %d\n",
- kcs_bmc->channel);
+ struct kcs_bmc_driver *drv;
+ int rc;
+
+ mutex_lock(&kcs_bmc_lock);
+ list_del(&kcs_bmc->entry);
+ list_for_each_entry(drv, &kcs_bmc_drivers, entry) {
+ rc = drv->ops->remove_device(kcs_bmc);
+ if (rc)
+ dev_err(kcs_bmc->dev, "Failed to remove chardev for KCS channel %d: %d",
+ kcs_bmc->channel, rc);
+ }
+ mutex_unlock(&kcs_bmc_lock);
}
EXPORT_SYMBOL(kcs_bmc_remove_device);
+void kcs_bmc_register_driver(struct kcs_bmc_driver *drv)
+{
+ struct kcs_bmc_device *kcs_bmc;
+ int rc;
+
+ mutex_lock(&kcs_bmc_lock);
+ list_add(&drv->entry, &kcs_bmc_drivers);
+ list_for_each_entry(kcs_bmc, &kcs_bmc_devices, entry) {
+ rc = drv->ops->add_device(kcs_bmc);
+ if (rc)
+ dev_err(kcs_bmc->dev, "Failed to add driver for KCS channel %d: %d",
+ kcs_bmc->channel, rc);
+ }
+ mutex_unlock(&kcs_bmc_lock);
+}
+EXPORT_SYMBOL(kcs_bmc_register_driver);
+
+void kcs_bmc_unregister_driver(struct kcs_bmc_driver *drv)
+{
+ struct kcs_bmc_device *kcs_bmc;
+ int rc;
+
+ mutex_lock(&kcs_bmc_lock);
+ list_del(&drv->entry);
+ list_for_each_entry(kcs_bmc, &kcs_bmc_devices, entry) {
+ rc = drv->ops->remove_device(kcs_bmc);
+ if (rc)
+ dev_err(kcs_bmc->dev, "Failed to remove driver for KCS channel %d: %d",
+ kcs_bmc->channel, rc);
+ }
+ mutex_unlock(&kcs_bmc_lock);
+}
+EXPORT_SYMBOL(kcs_bmc_unregister_driver);
+
MODULE_LICENSE("GPL v2");
MODULE_AUTHOR("Haiyue Wang <haiyue.wang@linux.intel.com>");
MODULE_AUTHOR("Andrew Jeffery <andrew@aj.id.au>");