Removed kobject from domain.
authorFlorian Pose <fp@igh-essen.com>
Thu, 12 Jun 2008 07:26:38 +0000
changeset 993 8c32564252fd
parent 992 50a44cbd30af
child 994 e29edcced328
Removed kobject from domain.
TODO
master/domain.c
master/domain.h
master/master.c
--- a/TODO	Thu Jun 12 07:15:54 2008 +0000
+++ b/TODO	Thu Jun 12 07:26:38 2008 +0000
@@ -26,6 +26,7 @@
 * Remove configs_attached flag.
 * Remove EC_IOCTL_DOMAIN_COUNT.
 * Remove ATOMIC allocations.
+* Clear FMMU configs.
 
 Future issues:
 
--- a/master/domain.c	Thu Jun 12 07:15:54 2008 +0000
+++ b/master/domain.c	Thu Jun 12 07:26:38 2008 +0000
@@ -48,41 +48,13 @@
 
 /*****************************************************************************/
 
-void ec_domain_clear(struct kobject *);
 void ec_domain_clear_data(ec_domain_t *);
-ssize_t ec_show_domain_attribute(struct kobject *, struct attribute *, char *);
-
-/*****************************************************************************/
-
-/** \cond */
-
-EC_SYSFS_READ_ATTR(image_size);
-
-static struct attribute *def_attrs[] = {
-    &attr_image_size,
-    NULL,
-};
-
-static struct sysfs_ops sysfs_ops = {
-    .show = &ec_show_domain_attribute,
-    .store = NULL
-};
-
-static struct kobj_type ktype_ec_domain = {
-    .release = ec_domain_clear,
-    .sysfs_ops = &sysfs_ops,
-    .default_attrs = def_attrs
-};
-
-/** \endcond */
 
 /*****************************************************************************/
 
 /** Domain constructor.
- *
- * \return 0 in case of success, else < 0
- */
-int ec_domain_init(
+ */
+void ec_domain_init(
         ec_domain_t *domain, /**< EtherCAT domain. */
         ec_master_t *master, /**< Parent master. */
         unsigned int index /**< Index. */
@@ -100,69 +72,25 @@
     domain->expected_working_counter = 0x0000;
     domain->working_counter_changes = 0;
     domain->notify_jiffies = 0;
-
-    // init kobject and add it to the hierarchy
-    memset(&domain->kobj, 0x00, sizeof(struct kobject));
-    kobject_init(&domain->kobj);
-    domain->kobj.ktype = &ktype_ec_domain;
-    domain->kobj.parent = &master->kobj;
-    if (kobject_set_name(&domain->kobj, "domain%u", index)) {
-        EC_ERR("Failed to set kobj name.\n");
-        kobject_put(&domain->kobj);
-        return -1;
-    }
-    if (kobject_add(&domain->kobj)) {
-        EC_ERR("Failed to add domain kobject.\n");
-        kobject_put(&domain->kobj);
-        return -1;
-    }
-
-    return 0;
 }
 
 /*****************************************************************************/
 
 /** Domain destructor.
- *
- * Clears and frees a domain object.
- */
-void ec_domain_destroy(ec_domain_t *domain /**< EtherCAT domain */)
-{
-    ec_datagram_t *datagram;
-
-    // dequeue datagrams
-    list_for_each_entry(datagram, &domain->datagrams, list) {
+ */
+void ec_domain_clear(ec_domain_t *domain /**< EtherCAT domain */)
+{
+    ec_datagram_t *datagram, *next;
+
+    // dequeue and free datagrams
+    list_for_each_entry_safe(datagram, next, &domain->datagrams, list) {
         if (!list_empty(&datagram->queue)) // datagram queued?
-            list_del_init(&datagram->queue);
-    }
-
-    // destroy self
-    kobject_del(&domain->kobj);
-    kobject_put(&domain->kobj);
-}
-
-/*****************************************************************************/
-
-/** Clear and free domain.
- *
- * This method is called by the kobject, once there are no more references
- * to it.
- */
-void ec_domain_clear(struct kobject *kobj /**< kobject of the domain */)
-{
-    ec_domain_t *domain;
-    ec_datagram_t *datagram, *next;
-
-    domain = container_of(kobj, ec_domain_t, kobj);
-
-    list_for_each_entry_safe(datagram, next, &domain->datagrams, list) {
+            list_del(&datagram->queue);
         ec_datagram_clear(datagram);
         kfree(datagram);
     }
 
     ec_domain_clear_data(domain);
-
-    kfree(domain);
 }
 
 /*****************************************************************************/
@@ -323,7 +251,8 @@
         datagram_size += fmmu->data_size;
     }
 
-    // allocate last datagram, if data are left
+    // Allocate last datagram, if data are left (this is also the case if the
+    // process data fit into a single datagram)
     if (datagram_size) {
         if (ec_domain_add_datagram(domain,
                     domain->logical_base_address + datagram_offset,
@@ -348,27 +277,6 @@
 
 /*****************************************************************************/
 
-/**
-   Formats attribute data for SysFS reading.
-   \return number of bytes to read
-*/
-
-ssize_t ec_show_domain_attribute(struct kobject *kobj, /**< kobject */
-                                 struct attribute *attr, /**< attribute */
-                                 char *buffer /**< memory to store data in */
-                                 )
-{
-    ec_domain_t *domain = container_of(kobj, ec_domain_t, kobj);
-
-    if (attr == &attr_image_size) {
-        return sprintf(buffer, "%u\n", domain->data_size);
-    }
-
-    return 0;
-}
-
-/*****************************************************************************/
-
 unsigned int ec_domain_fmmu_count(const ec_domain_t *domain)
 {
     const ec_fmmu_config_t *fmmu;
@@ -477,9 +385,10 @@
                     domain->index, domain->working_counter,
                     domain->expected_working_counter);
         } else {
-            EC_INFO("Domain %u: %u working counter changes. Currently %u/%u.\n",
-                    domain->index, domain->working_counter_changes,
-                    domain->working_counter, domain->expected_working_counter);
+            EC_INFO("Domain %u: %u working counter changes. "
+                    "Currently %u/%u.\n", domain->index,
+                    domain->working_counter_changes, domain->working_counter,
+                    domain->expected_working_counter);
         }
         domain->working_counter_changes = 0;
     }
--- a/master/domain.h	Thu Jun 12 07:15:54 2008 +0000
+++ b/master/domain.h	Thu Jun 12 07:26:38 2008 +0000
@@ -42,7 +42,6 @@
 #define __EC_DOMAIN_H__
 
 #include <linux/list.h>
-#include <linux/kobject.h>
 
 #include "globals.h"
 #include "datagram.h"
@@ -51,15 +50,13 @@
 
 /*****************************************************************************/
 
-/**
-   EtherCAT domain.
-   Handles the process data and the therefore needed datagrams of a certain
-   group of slaves.
-*/
-
+/** EtherCAT domain.
+ *
+ * Handles the process data and the therefore needed datagrams of a certain
+ * group of slaves.
+ */
 struct ec_domain
 {
-    struct kobject kobj; /**< kobject. */
     struct list_head list; /**< List item. */
     ec_master_t *master; /**< EtherCAT master owning the domain. */
     unsigned int index; /**< Index (just a number). */
@@ -81,8 +78,8 @@
 
 /*****************************************************************************/
 
-int ec_domain_init(ec_domain_t *, ec_master_t *, unsigned int);
-void ec_domain_destroy(ec_domain_t *);
+void ec_domain_init(ec_domain_t *, ec_master_t *, unsigned int);
+void ec_domain_clear(ec_domain_t *);
 
 void ec_domain_add_fmmu_config(ec_domain_t *, ec_fmmu_config_t *);
 int ec_domain_finish(ec_domain_t *, uint32_t);
--- a/master/master.c	Thu Jun 12 07:15:54 2008 +0000
+++ b/master/master.c	Thu Jun 12 07:26:38 2008 +0000
@@ -58,7 +58,7 @@
 /*****************************************************************************/
 
 void ec_master_destroy_slave_configs(ec_master_t *);
-void ec_master_destroy_domains(ec_master_t *);
+void ec_master_clear_domains(ec_master_t *);
 static int ec_master_idle_thread(ec_master_t *);
 static int ec_master_operation_thread(ec_master_t *);
 #ifdef EC_EOE
@@ -231,7 +231,7 @@
 #endif
     ec_master_destroy_slave_configs(master);
     ec_master_clear_slaves(master);
-    ec_master_destroy_domains(master);
+    ec_master_clear_domains(master);
     ec_fsm_master_clear(&master->fsm);
     ec_datagram_clear(&master->fsm_datagram);
     ec_device_clear(&master->backup_device);
@@ -299,13 +299,14 @@
    Destroy all domains.
 */
 
-void ec_master_destroy_domains(ec_master_t *master)
+void ec_master_clear_domains(ec_master_t *master)
 {
     ec_domain_t *domain, *next;
 
     list_for_each_entry_safe(domain, next, &master->domains, list) {
         list_del(&domain->list);
-        ec_domain_destroy(domain);
+        ec_domain_clear(domain);
+        kfree(domain);
     }
 }
 
@@ -517,7 +518,7 @@
     master->cb_data = master;
     
     ec_master_destroy_slave_configs(master);
-    ec_master_destroy_domains(master);
+    ec_master_clear_domains(master);
 
     // set states for all slaves
     list_for_each_entry(slave, &master->slaves, list) {
@@ -1202,17 +1203,14 @@
         return NULL;
     }
 
-    if (list_empty(&master->domains)) index = 0;
-    else {
+    if (list_empty(&master->domains)) {
+        index = 0;
+    } else {
         last_domain = list_entry(master->domains.prev, ec_domain_t, list);
         index = last_domain->index + 1;
     }
 
-    if (ec_domain_init(domain, master, index)) {
-        EC_ERR("Failed to init domain.\n");
-        return NULL;
-    }
-
+    ec_domain_init(domain, master, index);
     list_add_tail(&domain->list, &master->domains);
 
     return domain;