* SuperIO driver redesign.
@ 2005-05-19 6:25 Evgeniy Polyakov
2005-05-19 6:25 ` Evgeniy Polyakov
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Evgeniy Polyakov @ 2005-05-19 6:25 UTC (permalink / raw)
To: lm-sensors
Skipped content of type multipart/mixed-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.lm-sensors.org/pipermail/lm-sensors/attachments/20040827/5a39ca36/attachment.bin
^ permalink raw reply [flat|nested] 4+ messages in thread
* SuperIO driver redesign.
2005-05-19 6:25 SuperIO driver redesign Evgeniy Polyakov
@ 2005-05-19 6:25 ` Evgeniy Polyakov
2005-05-19 6:25 ` Evgeniy Polyakov
2005-05-19 6:25 ` Evgeniy Polyakov
2 siblings, 0 replies; 4+ messages in thread
From: Evgeniy Polyakov @ 2005-05-19 6:25 UTC (permalink / raw)
To: lm-sensors
Skipped content of type multipart/mixed-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.lm-sensors.org/pipermail/lm-sensors/attachments/20040830/234920f5/attachment.bin
^ permalink raw reply [flat|nested] 4+ messages in thread
* SuperIO driver redesign.
2005-05-19 6:25 SuperIO driver redesign Evgeniy Polyakov
2005-05-19 6:25 ` Evgeniy Polyakov
2005-05-19 6:25 ` Evgeniy Polyakov
@ 2005-05-19 6:25 ` Evgeniy Polyakov
2 siblings, 0 replies; 4+ messages in thread
From: Evgeniy Polyakov @ 2005-05-19 6:25 UTC (permalink / raw)
To: lm-sensors
SuperIO update.
This update contains mostly stub drivers for SCx200/SC1100 SuperIO, and
stub driver( it can not be found neither in scx200/sc1100 chip nor in
pc87366 chip) for Access buss logical device.
Main feature is logical device cloning feature:
When new logical device is being added SuperIO core checks if any
registered SuperIO chip expects this logical device but with different
index, then SuperIO core will clone logical device being added and
registers clones with appropriate sc_dev devices. When logical device is
being removed, then SuperIO core finds all it's clones(by looking into
ldev_list) and remove them also.
Please review and comment.
This will include following changeset:
# do not edit -- automatically generated by arch changelog
# arch-tag:
automatic-ChangeLog--johnpol@2ka.mipt.ru-2004/soekris--main--0
#
2004-09-03 18:39:39 GMT Evgeniy Polyakov <johnpol@2ka.mipt.ru> patch-46
Summary:
Fixed unclone bug. Process all logical devices that SuperIO chips
has in it's structure, little optimization in reference counting in
sc_ldev_clone(). Revision:
soekris--main--0--patch-46
Fixed unclone bug. Bit operation must be done on pointers to the
bitfield.
Process all logical devices that SuperIO chips has in it's
structure, do not break if first one was not activated.
Little optimization in reference counting - increment original
logical device refcnt after it was copied.
modified files:
sc.c
2004-09-03 13:12:03 GMT Evgeniy Polyakov <johnpol@2ka.mipt.ru> patch-45
Summary:
Added scx200.c - driver for SCx200/SC1100 SuperIO chips.
Revision:
soekris--main--0--patch-45
Added scx200.c - driver for SCx200/SC1100 SuperIO chips.
new files:
.arch-ids/scx200.c.id scx200.c
modified files:
Makefile
2004-09-03 13:10:10 GMT Evgeniy Polyakov <johnpol@2ka.mipt.ru> patch-44
Summary:
Commented unused variable.
Revision:
soekris--main--0--patch-44
Commented unused variable.
modified files:
sc_gpio.c
2004-09-03 13:04:33 GMT Evgeniy Polyakov <johnpol@2ka.mipt.ru> patch-43
Summary:
Finished cloning mechanism.
Revision:
soekris--main--0--patch-43
Finished cloning mechanism.
When new logical device is being added SuperIO core checks if any
registered SuperIO chip expects this logical device but with
different index, then SuperIO core will clone logical device being added
and registers clones with appropriate sc_dev devices.
When logical device is being removed, then SuperIO core finds all
it's clones(by looking into ldev_list) and remove them also.
modified files:
sc.c sc.h
2004-09-03 08:19:39 GMT Evgeniy Polyakov <johnpol@2ka.mipt.ru> patch-42
Summary:
Moved SIO_ definitions common to all SuperIO chips into sc.h
Revision:
soekris--main--0--patch-42
Moved SIO_ definitions common to all SuperIO chips into sc.h
modified files:
pc8736x.h
2004-09-03 08:18:23 GMT Evgeniy Polyakov <johnpol@2ka.mipt.ru> patch-41
Summary:
Set orig_dev to NULL in initialization time.
Revision:
soekris--main--0--patch-41
Set orig_dev to NULL in initialization time.
This means that in initialization time we do not have any clones of
this device.
modified files:
sc_acb.c sc_gpio.c
2004-09-03 08:16:38 GMT Evgeniy Polyakov <johnpol@2ka.mipt.ru> patch-40
Summary:
Changed locking schema, added cloning functions.
Revision:
soekris--main--0--patch-40
Changed locking schema - get appropriate lock when access to logical
device or sc device. This will be needed when we will add/remove
different device not only in loading/unloading time but in any other
moment through clone creating.
Added cloning functions.
modified files:
sc.c sc.h
2004-09-03 05:31:30 GMT Evgeniy Polyakov <johnpol@2ka.mipt.ru> patch-39
Summary:
Changed name for the struct sc_sio_chip to sc_chip_id.
Revision:
soekris--main--0--patch-39
Changed name for the struct sc_sio_chip to sc_chip_id.
modified files:
pc8736x.c sc.h
2004-09-03 05:20:57 GMT Evgeniy Polyakov <johnpol@2ka.mipt.ru> patch-38
Summary:
Added sc_get_ldev_index() - search logical device by name and
index. Revision:
soekris--main--0--patch-38
Added sc_get_ldev_index() - search logical device by name and index.
modified files:
sc.c
2004-09-03 04:29:26 GMT Evgeniy Polyakov <johnpol@2ka.mipt.ru> patch-37
Summary:
Added sc_acb.c - driver for Access Bus logical device.
Revision:
soekris--main--0--patch-37
Added sc_acb.c - driver for Access Bus logical device.
new files:
.arch-ids/sc_acb.c.id sc_acb.c
modified files:
Makefile pc8736x.h
2004-09-03 04:27:21 GMT Evgeniy Polyakov <johnpol@2ka.mipt.ru> patch-36
Summary:
Compilation fix in sc_sdev_equal().
Revision:
soekris--main--0--patch-36
Compilation fix in sc_sdev_equal().
modified files:
sc.c
2004-09-03 04:24:44 GMT Evgeniy Polyakov <johnpol@2ka.mipt.ru> patch-35
Summary:
Added sc_{sdev,ldev}_equal() functions.
Revision:
soekris--main--0--patch-35
Added sc_{sdev,ldev}_equal() functions.
The check if two given sdev/ldev are equal.
modified files:
sc.c
2004-09-02 11:15:59 GMT Evgeniy Polyakov <johnpol@2ka.mipt.ru> patch-34
Summary:
Changes module description.
Revision:
soekris--main--0--patch-34
Changes module description.
sc_gpio.c is not driver for any w1 device.
modified files:
sc_gpio.c
Evgeniy Polyakov ( s0mbre )
Only failure makes us experts. -- Theo de Raadt
-------------- next part --------------
diff -Nru soekris.old/Makefile soekris/Makefile
--- soekris.old/Makefile 2004-09-03 22:27:27.000000000 +0400
+++ soekris/Makefile 2004-09-03 22:40:05.000000000 +0400
@@ -1,6 +1,5 @@
-obj-m := superio.o sc_gpio.o pc8736x.o
+obj-m := superio.o sc_gpio.o pc8736x.o sc_acb.o scx200.o
superio-objs := sc.o chain.o
-# sc_gpio.o sc_w1.o pc8736x.o
#KDIR := /lib/modules/$(shell uname -r)/build
KDIR := /usr/local/src/linux-2.6/linux-2.6.6
@@ -10,5 +9,5 @@
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
clean:
- rm -f *.o *.ko *.mod.* .*.cmd *~
+ rm -f *.o *.ko *.mod.* .*.cmd *~ .*.o.*
rm -rf .tmp_versions
diff -Nru soekris.old/pc8736x.c soekris/pc8736x.c
--- soekris.old/pc8736x.c 2004-09-03 22:27:27.000000000 +0400
+++ soekris/pc8736x.c 2004-09-03 22:40:05.000000000 +0400
@@ -54,7 +54,7 @@
//.write pc8736x_write,
};
-static struct sc_sio_chip pc8736x_sio_ids[] =
+static struct sc_chip_id pc8736x_sio_ids[] =
{
{"PC87360", 0xe1},
{"PC87363", 0xe8},
diff -Nru soekris.old/pc8736x.h soekris/pc8736x.h
--- soekris.old/pc8736x.h 2004-09-03 22:27:27.000000000 +0400
+++ soekris/pc8736x.h 2004-09-03 22:40:05.000000000 +0400
@@ -23,22 +23,6 @@
#ifndef __PC8736X_H
#define __PC8736X_H
-#define SIO_REG_SID 0x20 /* Super I/O ID */
-#define SIO_SID_PC87366 0xE9 /* PC87366 is identified as 0xE9.*/
-
-#define SIO_REG_SRID 0x27 /* Super I/O Revision */
-#define SIO_REG_IRQ 0x70 /* IRQ number */
-#define SIO_REG_IRQ_TYPE 0x71 /* IRQ type */
-
-#define SIO_REG_LDN 0x07 /* Logical Device Number */
-#define SIO_LDN_GPIO 0x07 /* General-Purpose I/O (GPIO) Ports */
-
-#define SIO_REG_ACTIVE 0x30 /* Logical Device Activate Register */
-#define SIO_ACTIVE_EN 0x01 /* enabled */
-
-#define SIO_REG_IO_MSB 0x60 /* I/O Port Base, bits 15-8 */
-#define SIO_REG_IO_LSB 0x61 /* I/O Port Base, bits 7-0 */
-
#define SIO_GPDO0 0x00
#define SIO_GPDI0 0x01
#define SIO_GPEVEN0 0x02
diff -Nru soekris.old/sc.c soekris/sc.c
--- soekris.old/sc.c 2004-09-03 22:27:28.000000000 +0400
+++ soekris/sc.c 2004-09-03 22:40:06.000000000 +0400
@@ -52,6 +52,21 @@
static int __devinit sc_init(void);
static void __devexit sc_fini(void);
+static inline int sc_ldev_equal(struct logical_dev *l1, struct logical_dev *l2)
+{
+ return (!strncmp(l1->name, l2->name, SC_NAME_LEN) && l1->index = l2->index);
+}
+
+static inline int sc_ldev_equal_name(struct logical_dev *l1, struct logical_dev *l2)
+{
+ return (!strncmp(l1->name, l2->name, SC_NAME_LEN));
+}
+
+static inline int sc_sdev_equal(struct sc_dev *s1, struct sc_dev *s2)
+{
+ return (!strncmp(s1->name, s2->name, SC_NAME_LEN));
+}
+
static void sc_del_sdev_from_ldev(struct sc_dev *sdev, struct logical_dev *ldev)
{
struct sc_dev *__sdev;
@@ -63,7 +78,7 @@
{
__sdev = ch->ptr;
- if (!strncmp(__sdev->name, sdev->name, SC_NAME_LEN))
+ if (sc_sdev_equal(__sdev, sdev))
{
list_del(&ch->chain_entry);
chain_free(ch);
@@ -75,9 +90,6 @@
spin_unlock(&ldev->chain_lock);
}
-/*
- * Must be called under sc_dev->ldev_lock and sdev_lock held.
- */
static int __sc_add_logical_dev(struct sc_dev *dev, struct logical_dev *__ldev)
{
int err;
@@ -86,27 +98,11 @@
err = 0;
- ch = chain_alloc(dev);
- if (!ch)
- {
- err = -ENOMEM;
- goto err_out;
- }
-
- lch = chain_alloc(__ldev);
- if (!lch)
- {
- err = -ENOMEM;
- goto err_out_free_chain;
- }
-
- spin_lock(&dev->chain_lock);
-
list_for_each_entry(_ch, &dev->chain_list, chain_entry)
{
ldev = _ch->ptr;
- if (!strncmp(ldev->name, __ldev->name, SC_NAME_LEN))
+ if (sc_ldev_equal(ldev, __ldev))
{
printk(KERN_INFO "Logical device %s already registered in SuperIO chip %s.\n",
ldev->name, dev->name);
@@ -117,9 +113,54 @@
if (err)
{
- spin_unlock(&dev->chain_lock);
err = -ENODEV;
- goto err_out_free_logical_chain;
+ goto err_out;
+ }
+
+ if (!sc_ldev_is_clone(__ldev))
+ {
+ struct sc_chip_id *cid;
+
+ /*
+ * SuperIO core is registering logical device.
+ * SuperIO chip knows where it must live.
+ * If logical device being registered lives at the different location
+ * (for example when it was registered for all devices,
+ * but has address(index) corresponding to only one SuperIO chip)
+ * then we will register new logical device with the same name
+ * but with the different location(index).
+ *
+ * It is called clone.
+ */
+
+ for (cid = dev->ldevs; cid && strlen(cid->name); ++cid)
+ {
+ if (!strncmp(cid->name, __ldev->name, SC_NAME_LEN) && cid->id != __ldev->index)
+ {
+ struct logical_dev *clone;
+
+ printk(KERN_INFO "Logical device %s in chip %s lives at %x, but provided address %x.\n"
+ "Registering new logical device %s in chip %s with address %x.\n",
+ __ldev->name, dev->name, cid->id, __ldev->index,
+ __ldev->name, dev->name, cid->id);
+
+ clone = sc_ldev_clone(__ldev);
+ if (!clone)
+ {
+ err = -ENOMEM;
+ continue;
+ }
+
+ clone->index = cid->id;
+
+ err = __sc_add_logical_dev(dev, clone);
+ if (err)
+ {
+ sc_ldev_unclone(clone);
+ continue;
+ }
+ }
+ }
}
__ldev->pdev = dev;
@@ -128,9 +169,22 @@
{
printk(KERN_INFO "Logical device %s is not found in SuperIO chip %s.\n",
__ldev->name, dev->name);
- spin_unlock(&dev->chain_lock);
err = -EINVAL;
- goto err_out_free_logical_chain;
+ goto err_out;
+ }
+
+ ch = chain_alloc(dev);
+ if (!ch)
+ {
+ err = -ENOMEM;
+ goto err_out;
+ }
+
+ lch = chain_alloc(__ldev);
+ if (!lch)
+ {
+ err = -ENOMEM;
+ goto err_out_free_chain;
}
ch->ptr = dev;
@@ -138,17 +192,13 @@
spin_lock(&__ldev->chain_lock);
atomic_inc(&__ldev->refcnt);
list_add_tail(&ch->chain_entry, &__ldev->chain_list);
-
spin_unlock(&__ldev->chain_lock);
-
+
atomic_inc(&dev->refcnt);
list_add_tail(&lch->chain_entry, &dev->chain_list);
- spin_unlock(&dev->chain_lock);
-
return 0;
-err_out_free_logical_chain:
chain_free(lch);
err_out_free_chain:
chain_free(ch);
@@ -163,16 +213,23 @@
int err, found = 0;
struct logical_dev *ldev;
+ printk(KERN_INFO "Adding logical device %s [%x] [%s].\n",
+ __ldev->name, __ldev->index, (sc_ldev_is_clone(__ldev))?"clone":"not clone");
+
spin_lock_init(&__ldev->chain_lock);
INIT_LIST_HEAD(&__ldev->chain_list);
+
+ spin_lock_init(&__ldev->lock);
atomic_set(&__ldev->refcnt, 0);
if (sdev)
{
- spin_lock(&sdev_lock);
+ spin_lock(&sdev->lock);
+ spin_lock(&sdev->chain_lock);
err = __sc_add_logical_dev(sdev, __ldev);
- spin_unlock(&sdev_lock);
+ spin_unlock(&sdev->chain_lock);
+ spin_unlock(&sdev->lock);
if (!err)
found = 1;
@@ -183,7 +240,11 @@
spin_lock(&sdev_lock);
list_for_each_entry(dev, &sdev_list, sdev_entry)
{
+ spin_lock(&dev->lock);
+ spin_lock(&dev->chain_lock);
err = __sc_add_logical_dev(dev, __ldev);
+ spin_unlock(&dev->chain_lock);
+ spin_unlock(&dev->lock);
if (!err)
found = 1;
}
@@ -197,7 +258,7 @@
spin_lock(&ldev_lock);
list_for_each_entry(ldev, &ldev_list, ldev_entry)
{
- if (!strncmp(ldev->name, __ldev->name, SC_NAME_LEN))
+ if (sc_ldev_equal(ldev, __ldev))
{
__found = 1;
break;
@@ -216,18 +277,19 @@
}
/*
- * Must be called under sc_dev->ldev_lock and sdev_lock held.
+ * Must be called under ldev->chain_lock and ldev_lock held.
*/
-static void __sc_del_logical_dev(struct sc_dev *dev, struct logical_dev *ldev)
+static void __sc_del_logical_dev(struct sc_dev *dev, struct logical_dev *__ldev)
{
struct dev_chain *ch, *n;
+ struct logical_dev *ldev;
spin_lock(&dev->chain_lock);
list_for_each_entry_safe(ch, n, &dev->chain_list, chain_entry)
{
ldev = ch->ptr;
- if (!strncmp(ldev->name, ldev->name, SC_NAME_LEN))
+ if (sc_ldev_equal(ldev, __ldev))
{
list_del(&ch->chain_entry);
atomic_dec(&ldev->refcnt);
@@ -245,26 +307,76 @@
{
struct sc_dev *dev;
struct dev_chain *ch, *n;
-
+
+ spin_lock(&ldev->lock);
+
spin_lock(&ldev->chain_lock);
list_for_each_entry_safe(ch, n, &ldev->chain_list, chain_entry)
{
dev = ch->ptr;
+ spin_lock(&dev->lock);
__sc_del_logical_dev(dev, ldev);
list_del(&ch->chain_entry);
atomic_dec(&dev->refcnt);
chain_free(ch);
+ spin_unlock(&dev->lock);
}
spin_unlock(&ldev->chain_lock);
+ if (sc_ldev_is_clone(ldev))
+ {
+ spin_unlock(&ldev->lock);
+ return;
+ }
+
+ spin_lock(&ldev_lock);
+ list_del(&ldev->ldev_entry);
+ spin_unlock(&ldev_lock);
+
+ if (sc_ldev_cloned(ldev))
+ {
+ struct logical_dev *ld, *ln;
+
+ /*
+ * When logical device is clonned
+ * clone's chunks can point to the diferent device
+ * than origianl logical device's chunks.
+ * Since we do not have backlink from the original device
+ * to it's clones we must run through the whole ldev_list.
+ */
+
+ spin_lock(&ldev_lock);
+ list_for_each_entry_safe(ld, ln, &ldev_list, ldev_entry)
+ {
+ if (sc_ldev_is_clone(ld) && sc_ldev_equal_name(ld, ldev))
+ {
+ sc_del_logical_dev(ld);
+ list_del(&ld->ldev_entry);
+ sc_ldev_unclone(ld);
+
+ /*
+ * sc_ldev_unclone() can unclone the last clone
+ * and mark ldev as not clonned.
+ */
+ if (!sc_ldev_cloned(ldev))
+ break;
+ }
+ }
+ spin_unlock(&ldev_lock);
+ }
+
+ spin_unlock(&ldev->lock);
+
while(atomic_read(&ldev->refcnt))
{
- printk(KERN_INFO "Waiting logical device %s to become free: refcnt=%d.\n",
- ldev->name, atomic_read(&ldev->refcnt));
+ printk(KERN_INFO "Waiting logical device %s [%x] [%s] to become free: refcnt=%d.\n",
+ ldev->name, ldev->index,
+ (sc_ldev_is_clone(ldev))?"clone":"not clone", atomic_read(&ldev->refcnt));
schedule_timeout(HZ);
}
+
}
static int sc_check_sc_dev(struct sc_dev *dev)
@@ -281,6 +393,9 @@
return -EINVAL;
}
+ if (!dev->ldevs)
+ printk(KERN_INFO "SuperIO device %s does not have logical device table.\n", dev->name);
+
return 0;
}
@@ -295,10 +410,12 @@
spin_lock_init(&__sdev->chain_lock);
INIT_LIST_HEAD(&__sdev->chain_list);
+ spin_lock_init(&__sdev->lock);
+
spin_lock(&sdev_lock);
list_for_each_entry(sdev, &sdev_list, sdev_entry)
{
- if (!strncmp(sdev->name, __sdev->name, SC_NAME_LEN))
+ if (sc_sdev_equal(sdev, __sdev))
{
printk(KERN_INFO "Super IO chip %s already registered.\n",
sdev->name);
@@ -338,14 +455,15 @@
struct logical_dev *ldev;
struct sc_dev *sdev, *sn;
+ spin_lock(&__sdev->lock);
spin_lock(&sdev_lock);
list_for_each_entry_safe(sdev, sn, &sdev_list, sdev_entry)
{
- if (!strncmp(sdev->name, __sdev->name, SC_NAME_LEN))
+ if (sc_sdev_equal(sdev, __sdev))
{
list_del(&sdev->sdev_entry);
+ break;
}
- break;
}
spin_unlock(&sdev_lock);
@@ -362,6 +480,7 @@
sc_del_sdev_from_ldev(__sdev, ldev);
}
spin_unlock(&__sdev->chain_lock);
+ spin_unlock(&__sdev->lock);
while(atomic_read(&__sdev->refcnt))
{
@@ -373,7 +492,7 @@
static void sc_deactivate_logical(struct sc_dev *dev, struct logical_dev *ldev)
{
- printk(KERN_INFO "Deactivating logical device %s from SuperIO chip %s.\n", ldev->name, dev->name);
+ printk(KERN_INFO "Deactivating logical device %s in SuperIO chip %s.\n", ldev->name, dev->name);
if (dev->deactivate_one)
dev->deactivate_one(ldev);
@@ -386,7 +505,7 @@
{
int err;
- printk(KERN_INFO "Activating logical device %s.\n", ldev->name);
+ printk(KERN_INFO "Activating logical device %s [%x].\n", ldev->name, ldev->index);
ldev->pdev = dev;
err = dev->activate_one(ldev);
@@ -417,6 +536,31 @@
atomic_dec(&sdev->refcnt);
}
+/*
+ * Get logical device which has given name and index.
+ */
+struct logical_dev *sc_get_ldev_index(char *name, u8 index)
+{
+ struct logical_dev *ldev;
+
+ spin_lock(&ldev_lock);
+ list_for_each_entry(ldev, &ldev_list, ldev_entry)
+ {
+ if (!strcmp(name, ldev->name) && ldev->index = index)
+ {
+ atomic_inc(&ldev->refcnt);
+ spin_unlock(&ldev_lock);
+ return ldev;
+ }
+ }
+ spin_unlock(&ldev_lock);
+
+ return NULL;
+}
+
+/*
+ * Get the first logical device with the given name.
+ */
struct logical_dev *sc_get_ldev(char *name)
{
struct logical_dev *ldev;
@@ -441,6 +585,116 @@
atomic_dec(&ldev->refcnt);
}
+/*
+ * Cloned logical device has the same structure as original device.
+ * Although cloned and original devices do not cross, they both point
+ * to the same block of the memory(they have pointers to the same functions),
+ * so we will increment reference counter for original device
+ * like cloned device has a reference to it.
+ */
+struct logical_dev *sc_ldev_clone(struct logical_dev *ldev)
+{
+ struct logical_dev *__ldev;
+
+ __ldev = sc_ldev_alloc(ldev->name, ldev->index);
+ if (!__ldev)
+ return NULL;
+
+ memcpy(__ldev, ldev, sizeof(*__ldev));
+
+ atomic_inc(&ldev->refcnt);
+ set_bit(LDEV_CLONED, (long *)&ldev->flags);
+
+ __ldev->orig_ldev = ldev;
+
+ return __ldev;
+}
+
+inline int sc_ldev_is_clone(struct logical_dev *ldev)
+{
+ return (ldev->orig_ldev)?1:0;
+}
+
+inline int sc_ldev_cloned(struct logical_dev *ldev)
+{
+ return (test_bit(LDEV_CLONED, (long *)&ldev->flags) && (atomic_read(&ldev->refcnt) > 1));
+}
+
+void sc_ldev_unclone(struct logical_dev *clone)
+{
+ struct logical_dev *orig = clone->orig_ldev;
+
+ if (!sc_ldev_is_clone(clone))
+ {
+ printk(KERN_INFO "Logical device %s is not clone.\n", clone->name);
+ return;
+ }
+
+ if (atomic_dec_and_test(&orig->refcnt))
+ clear_bit(LDEV_CLONED, (long *)&orig->flags);
+
+ memset(clone, 0, sizeof(*clone));
+ kfree(clone);
+ clone = NULL;
+}
+
+struct logical_dev *sc_ldev_alloc(char *name, u8 index)
+{
+ struct logical_dev *ldev;
+
+ ldev = kmalloc(sizeof(*ldev), GFP_ATOMIC);
+ if (!ldev)
+ {
+ printk(KERN_ERR "Failed to allocate new logical device %s at address %x.\n",
+ name, index);
+ return NULL;
+ }
+
+ memset(ldev, 0, sizeof(*ldev));
+
+ snprintf(ldev->name, sizeof(ldev->name), "%s", name);
+ ldev->index = index;
+
+ return ldev;
+}
+
+void sc_ldev_free(struct logical_dev *ldev)
+{
+ if (ldev->orig_ldev)
+ {
+ struct logical_dev *orig = ldev->orig_ldev;
+ /*
+ * It is clone.
+ */
+ atomic_dec(&ldev->refcnt);
+ if (atomic_read(&ldev->refcnt))
+ {
+ /*
+ * It is impossible, clone can not have clones.
+ */
+ printk(KERN_INFO "Logical device clone %s has refcnt=%d and flags=%x.\n",
+ ldev->name, atomic_read(&ldev->refcnt), ldev->flags);
+ BUG();
+ }
+
+ spin_lock(&orig->lock);
+
+ clear_bit(LDEV_CLONED, (long *)&orig->flags);
+ atomic_dec(&orig->refcnt);
+
+ memset(ldev, 0, sizeof(*ldev));
+ kfree(ldev);
+
+ spin_unlock(&orig->lock);
+ }
+ else if (sc_ldev_cloned(ldev))
+ {
+ /*
+ * It is cloned.
+ */
+ }
+}
+
static int __devinit sc_init(void)
{
printk(KERN_INFO "Soekris SuperIO driver is starting...\n");
@@ -464,3 +718,9 @@
EXPORT_SYMBOL(sc_del_sc_dev);
EXPORT_SYMBOL(sc_get_sdev);
EXPORT_SYMBOL(sc_put_sdev);
+EXPORT_SYMBOL(sc_ldev_alloc);
+EXPORT_SYMBOL(sc_ldev_free);
+EXPORT_SYMBOL(sc_ldev_clone);
+EXPORT_SYMBOL(sc_ldev_unclone);
+EXPORT_SYMBOL(sc_ldev_cloned);
+EXPORT_SYMBOL(sc_ldev_is_clone);
diff -Nru soekris.old/sc.h soekris/sc.h
--- soekris.old/sc.h 2004-09-03 22:27:27.000000000 +0400
+++ soekris/sc.h 2004-09-03 22:40:05.000000000 +0400
@@ -29,6 +29,24 @@
#define SC_NAME_LEN 16
+#define SIO_REG_SID 0x20 /* Super I/O ID */
+
+#define SIO_REG_SRID 0x27 /* Super I/O Revision */
+#define SIO_REG_IRQ 0x70 /* IRQ number */
+#define SIO_REG_IRQ_TYPE 0x71 /* IRQ type */
+
+#define SIO_REG_LDN 0x07 /* Logical Device Number */
+#define SIO_LDN_GPIO 0x07 /* General-Purpose I/O (GPIO) Ports */
+#define SIO_LDN_ACB 0x08 /* Access bus */
+
+#define SIO_REG_ACTIVE 0x30 /* Logical Device Activate Register */
+#define SIO_ACTIVE_EN 0x01 /* enabled */
+
+#define SIO_REG_IO_MSB 0x60 /* I/O Port Base, bits 15-8 */
+#define SIO_REG_IO_LSB 0x61 /* I/O Port Base, bits 7-0 */
+
+#define LDEV_CLONED (1<<0)
+
struct logical_dev
{
struct list_head ldev_entry;
@@ -48,6 +66,7 @@
u32 flags;
void *pdev;
+ void *orig_ldev;
u8 irq;
u8 irq_type;
@@ -73,6 +92,8 @@
void *pdev;
unsigned long base_index, base_data;
+ struct sc_chip_id *ldevs;
+
int (*probe)(void *, unsigned long);
int (*activate_one)(struct logical_dev *);
int (*deactivate_one)(struct logical_dev *);
@@ -80,7 +101,7 @@
void (*write)(struct logical_dev *, unsigned long, u8);
};
-struct sc_sio_chip
+struct sc_chip_id
{
unsigned char name[SC_NAME_LEN];
u8 id;
@@ -95,4 +116,13 @@
void sc_del_sc_dev(struct sc_dev *);
struct sc_dev *sc_get_sdev(char *);
void sc_put_sdev(struct sc_dev *);
+
+struct logical_dev *sc_ldev_clone(struct logical_dev *ldev);
+void sc_ldev_unclone(struct logical_dev *ldev);
+inline int sc_ldev_cloned(struct logical_dev *ldev);
+inline int sc_ldev_is_clone(struct logical_dev *ldev);
+
+struct logical_dev *sc_ldev_alloc(char *name, u8 index);
+void sc_ldev_free(struct logical_dev *ldev);
+
#endif /* __SC_H */
diff -Nru soekris.old/sc_acb.c soekris/sc_acb.c
--- soekris.old/sc_acb.c 1970-01-01 03:00:00.000000000 +0300
+++ soekris/sc_acb.c 2004-09-03 22:40:05.000000000 +0400
@@ -0,0 +1,120 @@
+/*
+ * sc_acb.c
+ *
+ * 2004 Copyright (c) Evgeniy Polyakov <johnpol@2ka.mipt.ru>
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/string.h>
+
+#include <asm/io.h>
+
+#include "sc.h"
+
+int sc_acb_activate(void *data);
+u8 sc_acb_read(void *data, int reg);
+void sc_acb_write(void *data, int reg, u8 byte);
+void sc_acb_control(void *data, int pin, u8 mask, u8 ctl);
+
+static struct logical_dev ldev_acb =
+{
+ .name = "ACB",
+ .index = 0x08,
+ .range = 16,
+
+ .activate = sc_acb_activate,
+ .read = sc_acb_read,
+ .write = sc_acb_write,
+ .control = sc_acb_control,
+
+ .flags = 0,
+ .orig_ldev = NULL,
+};
+
+void sc_write_reg(struct sc_dev *dev, u8 reg, u8 val)
+{
+ outb(reg, dev->base_index);
+ outb(val, dev->base_data);
+}
+
+u8 sc_read_reg(struct sc_dev *dev, u8 reg)
+{
+ u8 val;
+
+ outb(reg, dev->base_index);
+ val = inb(dev->base_data);
+
+ return val;
+}
+
+int sc_acb_activate(void *data)
+{
+ return 0;
+}
+
+u8 sc_acb_read(void *data, int reg)
+{
+ struct logical_dev *ldev = (struct logical_dev *)data;
+ u8 val;
+
+ val = inb(ldev->base_addr + reg);
+
+ //printk("R: %02x\n", val);
+
+ return val;
+}
+
+void sc_acb_write(void *data, int reg, u8 byte)
+{
+ struct logical_dev *ldev = (struct logical_dev *)data;
+
+ //printk("W: %02x\n", val);
+
+ outb(byte, ldev->base_addr + reg);
+}
+
+void sc_acb_control(void *data, int pin, u8 mask, u8 ctl)
+{
+}
+
+static int __devinit sc_acb_init(void)
+{
+ printk(KERN_INFO "Access Bus logical device driver is activating now.\n");
+ INIT_LIST_HEAD(&ldev_acb.ldev_entry);
+ spin_lock_init(&ldev_acb.lock);
+ return sc_add_logical_dev(NULL, &ldev_acb);
+}
+
+static void __devexit sc_acb_fini(void)
+{
+ sc_del_logical_dev(&ldev_acb);
+ printk(KERN_INFO "Access Bus logical device driver finished.\n");
+}
+
+module_init(sc_acb_init);
+module_exit(sc_acb_fini);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Evgeniy Polyakov <johnpol@2ka.mipt.ru>");
+MODULE_DESCRIPTION("Driver for Access Bus logical device.");
+
+EXPORT_SYMBOL(sc_acb_activate);
+EXPORT_SYMBOL(sc_acb_read);
+EXPORT_SYMBOL(sc_acb_write);
+EXPORT_SYMBOL(sc_acb_control);
diff -Nru soekris.old/sc_gpio.c soekris/sc_gpio.c
--- soekris.old/sc_gpio.c 2004-09-03 22:27:28.000000000 +0400
+++ soekris/sc_gpio.c 2004-09-03 22:40:05.000000000 +0400
@@ -43,6 +43,7 @@
.control = sc_gpio_control,
.flags = 0,
+ .orig_ldev = 0,
};
void sc_write_reg(struct sc_dev *dev, u8 reg, u8 val)
@@ -77,7 +78,7 @@
int sc_gpio_activate(void *data)
{
- struct logical_dev *ldev = (struct logical_dev *)data;
+ //struct logical_dev *ldev = (struct logical_dev *)data;
int i;
memset(gpin, 0, sizeof(gpin));
diff -Nru soekris.old/scx200.c soekris/scx200.c
--- soekris.old/scx200.c 1970-01-01 03:00:00.000000000 +0300
+++ soekris/scx200.c 2004-09-03 22:40:05.000000000 +0400
@@ -0,0 +1,203 @@
+/*
+ * scx200.c
+ *
+ * 2004 Copyright (c) Evgeniy Polyakov <johnpol@2ka.mipt.ru>
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <asm/atomic.h>
+#include <asm/types.h>
+#include <asm/io.h>
+
+#include <linux/delay.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/list.h>
+#include <linux/interrupt.h>
+#include <linux/spinlock.h>
+#include <linux/timer.h>
+#include <linux/slab.h>
+#include <linux/timer.h>
+
+#include "sc.h"
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Evgeniy Polyakov <johnpol@2ka.mipt.ru>");
+MODULE_DESCRIPTION("Driver for SCx200/SC1100 SuperIO chips.");
+
+static int scx200_probe(void *, unsigned long base);
+static int scx200_activate_one_logical(struct logical_dev *ldev);
+
+static struct sc_chip_id scx200_logical_devs[] =
+{
+ {"RTC", 0x00},
+ {"SWC", 0x01},
+ {"IRCP", 0x02},
+ {"ACB", 0x05},
+ {"ACB", 0x06},
+ {"SPORT", 0x08},
+ {}
+};
+
+static struct sc_dev scx200_dev =
+{
+ .name "SCx200",
+ .probe scx200_probe,
+ .ldevs scx200_logical_devs,
+ .activate_one scx200_activate_one_logical,
+};
+
+static struct sc_chip_id scx200_sio_ids[] =
+{
+ {"SCx200/SC1100", 0xF5},
+};
+
+void scx200_write_reg(struct sc_dev *dev, u8 reg, u8 val)
+{
+ outb(reg, dev->base_index);
+ outb(val, dev->base_data);
+}
+
+u8 scx200_read_reg(struct sc_dev *dev, u8 reg)
+{
+ u8 val;
+
+ outb(reg, dev->base_index);
+ val = inb(dev->base_data);
+
+ return val;
+}
+
+static int scx200_ldev_index_by_name(char *name)
+{
+ int i;
+
+ for (i=0; i<sizeof(scx200_logical_devs)/sizeof(scx200_logical_devs[0]); ++i)
+ if (!strncmp(scx200_logical_devs[i].name, name, SC_NAME_LEN))
+ return i;
+
+ return -ENODEV;
+}
+
+static int scx200_chip_index(u8 id)
+{
+ int i;
+
+ for (i=0; i<sizeof(scx200_sio_ids)/sizeof(scx200_sio_ids[0]); ++i)
+ if (scx200_sio_ids[i].id = id)
+ return i;
+
+ return -ENODEV;
+}
+
+static int scx200_probe(void *data, unsigned long base)
+{
+ unsigned long size = 2;
+ u8 id;
+ int chip_num;
+ struct sc_dev *dev = (struct sc_dev *)data;
+
+ /*
+ * Special address to handle.
+ */
+ if (base = 0)
+ {
+ return scx200_probe(data, 0x015C);
+ }
+
+ dev->base_index = base;
+ dev->base_data = base + 1;
+
+ id = scx200_read_reg(dev, SIO_REG_SID);
+ chip_num = scx200_chip_index(id);
+
+ if (chip_num >= 0)
+ {
+ printk(KERN_INFO "Found %s [0x%x] at 0x%04lx-0x%04lx.\n",
+ scx200_sio_ids[chip_num].name, scx200_sio_ids[chip_num].id,
+ base, base+size-1);
+ return 0;
+ }
+
+ printk(KERN_INFO "Found nothing at 0x%04lx-0x%04lx.\n", base, base+size-1);
+
+ return -ENODEV;
+}
+
+static int scx200_activate_one_logical(struct logical_dev *ldev)
+{
+ int err, idx;
+ struct sc_dev *dev = ldev->pdev;
+
+
+ idx = scx200_ldev_index_by_name(ldev->name);
+ if (idx < 0)
+ {
+ printk(KERN_INFO "Chip %s does not have logical device %s.\n", dev->name, ldev->name);
+ return -ENODEV;
+ }
+
+ scx200_write_reg(dev, SIO_REG_LDN, ldev->index);
+ if ((scx200_read_reg(dev, SIO_REG_ACTIVE) & SIO_ACTIVE_EN) = 0)
+ {
+ printk(KERN_INFO "\t%16s - not activated: HW.\n", ldev->name);
+ return -ENODEV;
+ }
+
+ ldev->base_addr = scx200_read_reg(dev, SIO_REG_IO_LSB);
+ ldev->base_addr |= (scx200_read_reg(dev, SIO_REG_IO_MSB) << 8);
+
+ err = ldev->activate(ldev);
+ if (err < 0)
+ {
+ printk(KERN_INFO "\t%16s - not activated: ->activate() failed with error code %d.\n",
+ ldev->name, err);
+ return -ENODEV;
+ }
+
+ printk(KERN_INFO "\t%16s - activated: 0x%04lx-0x%04lx\n",
+ ldev->name, ldev->base_addr, ldev->base_addr + ldev->range);
+
+ return 0;
+}
+
+static int scx200_init(void)
+{
+ int err;
+
+ err = sc_add_sc_dev(&scx200_dev);
+ if (err)
+ return err;
+
+ printk(KERN_INFO "Driver for %s SuperIO chip.\n", scx200_dev.name);
+ return 0;
+}
+
+static void scx200_fini(void)
+{
+ sc_del_sc_dev(&scx200_dev);
+
+ while (atomic_read(&scx200_dev.refcnt))
+ schedule_timeout(HZ);
+}
+
+module_init(scx200_init);
+module_exit(scx200_fini);
+
+EXPORT_SYMBOL(scx200_write_reg);
+EXPORT_SYMBOL(scx200_read_reg);
^ permalink raw reply [flat|nested] 4+ messages in thread
* SuperIO driver redesign.
2005-05-19 6:25 SuperIO driver redesign Evgeniy Polyakov
2005-05-19 6:25 ` Evgeniy Polyakov
@ 2005-05-19 6:25 ` Evgeniy Polyakov
2005-05-19 6:25 ` Evgeniy Polyakov
2 siblings, 0 replies; 4+ messages in thread
From: Evgeniy Polyakov @ 2005-05-19 6:25 UTC (permalink / raw)
To: lm-sensors
Skipped content of type multipart/mixed-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.lm-sensors.org/pipermail/lm-sensors/attachments/20040908/2416ef5d/attachment.bin
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2005-05-19 6:25 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-19 6:25 SuperIO driver redesign Evgeniy Polyakov
2005-05-19 6:25 ` Evgeniy Polyakov
2005-05-19 6:25 ` Evgeniy Polyakov
2005-05-19 6:25 ` Evgeniy Polyakov
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.