There are 3 different drivers that touch the it87 hardware registers. The 3 drivers have been written independently and access the it87 hardware registers assuming they are the only driver accessing it. This change attempts to serialize access to the hardware by using "request_muxed_region" macro defined by Alan Cox. Call to this macro will hold off the requestor if the resource is currently busy. The use of the above macro makes it possible to get rid of spinlocks in it8712f_wdt.c and it87_wdt.c watchdog drivers. This also greatly simplifies the implementation of it87_wdt.c driver.
01 - Changes to it87 watchdog driver to use "request_muxed_region"
drivers/watchdog/it8712f_wdt.c drivers/watchdog/it87_wdt.c
02 - Chages to hwmon it87 driver to use "request_muxed_region"
drivers/hwmon/it87.c
drivers/hwmon/it87.c | 14 +++- drivers/watchdog/it8712f_wdt.c | 60 ++++++++++---- drivers/watchdog/it87_wdt.c | 165 +++++++++++++++++++++++---------------- 3 files changed, 152 insertions(+), 87 deletions(-)
drivers/hwmon/it87.c +0 -0
Patch History:
v8:
- Return the error actually returned by superio_enter and not -EBUSY. Notifier routines return NOTIFY_DONE even if underlying calls from notifier to routines that invoke superio_enter return with error. Make sure release routines returns do proper clean up even if calls to superio_enter fail.
v7:
- superio_enter return error if call to "request_muxed_region" fails. Rest of the changes deal with error returns from superio_enter. Changes to it87_wdt.c are untested.
v6:
- Pay attention to value returned by request_muxed_region. The first call to request_muxed_region will attempt 10 times to reserve the region before it gives up. This will typically get called from the driver init routines. If this succeeds then subsequent calls wait forever for the resource to be available.
v5:
- Remove unnecessary while from superio_enter.
v4:
- Remove extra braces in superio_enter routines.
v3:
- Totally abandon the spinlock based approach and use "request_muxed_region" to hold off requestors if the resource is busy.
v2:
- More verbose patch headers. Add In-Reply-To: field.
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
PATCH v8 1/2 Use "request_muxed_region" in it87 watchdog drivers
01 - Changes to it87 watchdog driver to use "request_muxed_region" Serialize access to the hardware by using "request_muxed_region" macro defined by Alan Cox. Call to this macro will hold off the requestor if the resource is currently busy.
The use of the above macro makes it possible to get rid of spinlocks in it8712f_wdt.c and it87_wdt.c watchdog drivers. This also greatly simplifies the implementation of it87_wdt.c driver.
"superio_enter" will return an error if call to "request_muxed_region" fails.
Rest of the code change is to ripple an error return from superio_enter to the top level.
---
drivers/watchdog/it8712f_wdt.c +43 -17
@@ -51,7 +51,6 @@ MODULE_PARM_DESC(nowayout, "Disable watchdog shutdown on close");static unsigned long wdt_open;static unsigned expect_close; -static spinlock_t io_lock;static unsigned char revision;/* Dog Food address - We use the game port address */
@@ -121,20 +120,27 @@ static inline void superio_select(int ldn)outb (ldn,VAL ); } -static inline void superio_enter (void ) +static inline int +superio_enter (void ) { -spin_lock (&io_lock); +/* +* Try to reserve REG and REG + 1 for exclusive access. +*/ +if (!request_muxed_region (REG ,2 ,NAME )) +return -EBUSY ; +outb (0x87 ,REG );outb (0x01 ,REG );outb (0x55 ,REG );outb (0x55 ,REG ); +return 0 ; }static inline void superio_exit (void ) {outb (0x02 ,REG );outb (0x02 ,VAL ); -spin_unlock (&io_lock); +release_region (REG ,2 ); }static inline void it8712f_wdt_ping (void )
@@ -173,10 +179,13 @@ static int it8712f_wdt_get_status(void)return 0 ; } -static void it8712f_wdt_enable (void ) +static int it8712f_wdt_enable (void ) { +int ret =superio_enter (); +if (ret) +return ret; + printk(KERN_DEBUG NAME ": enabling watchdog timer\n"); -superio_enter ();superio_select (LDN_GPIO );superio_outb (wdt_control_reg,WDT_CONTROL );
@@ -186,13 +195,18 @@ static void it8712f_wdt_enable(void)superio_exit ();it8712f_wdt_ping (); + +return 0 ; } -static void it8712f_wdt_disable (void ) +static int it8712f_wdt_disable (void ) { - printk(KERN_DEBUG NAME ": disabling watchdog timer\n"); +int ret =superio_enter (); + +if (ret) +return ret; -superio_enter (); + printk(KERN_DEBUG NAME ": disabling watchdog timer\n");superio_select (LDN_GPIO );superio_outb (0 ,WDT_CONFIG );
@@ -202,6 +216,7 @@ static void it8712f_wdt_disable(void)superio_outb (0 ,WDT_TIMEOUT );superio_exit (); +return 0 ; } static int it8712f_wdt_notify(struct notifier_block *this,
@@ -252,6 +267,7 @@ static long it8712f_wdt_ioctl(struct file *file, unsigned int cmd, WDIOF_MAGICCLOSE, };int value; +int ret;switch (cmd) {case WDIOC_GETSUPPORT :
@@ -259,7 +275,9 @@ static long it8712f_wdt_ioctl(struct file *file, unsigned int cmd,return -EFAULT ;return 0 ;case WDIOC_GETSTATUS : -superio_enter (); + ret =superio_enter (); +if (ret) +return ret;superio_select (LDN_GPIO ); value =it8712f_wdt_get_status ();
@@ -280,7 +298,9 @@ static long it8712f_wdt_ioctl(struct file *file, unsigned int cmd,if (value > (max_units *60 ))return -EINVAL ; margin = value; -superio_enter (); + ret =superio_enter (); +if (ret) +return -EBUSY ;superio_select (LDN_GPIO );it8712f_wdt_update_margin ();
@@ -299,10 +319,14 @@ static long it8712f_wdt_ioctl(struct file *file, unsigned int cmd,static int it8712f_wdt_open (struct inode *inode,struct file *file) { +int ret;/* only allow one at a time */ if (test_and_set_bit (0 , &wdt_open))return -EBUSY ; -it8712f_wdt_enable (); + + ret =it8712f_wdt_enable (); +if (ret) +return ret;return nonseekable_open (inode, file); }
@@ -313,7 +337,8 @@ static int it8712f_wdt_release(struct inode *inode, struct file *file)": watchdog device closed unexpectedly, will not" " disable the watchdog timer\n"); }else if (!nowayout) { -it8712f_wdt_disable (); +if (it8712f_wdt_disable ()) + printk(KERN_WARNING NAME "Watchdog disable failed\n"); } expect_close =0 ;clear_bit (0 , &wdt_open);
@@ -340,8 +365,10 @@ static int __init it8712f_wdt_find(unsigned short *address) {int err = -ENODEV ;int chip_type; +int ret =superio_enter (); +if (ret) +return ret; -superio_enter (); chip_type =superio_inw (DEVID );if (chip_type !=IT8712F_DEVID ) goto exit;
@@ -382,8 +409,6 @@ static int __init it8712f_wdt_init(void) {int err =0 ; -spin_lock_init (&io_lock); -if (it8712f_wdt_find (&address))return -ENODEV ;
@@ -392,7 +417,8 @@ static int __init it8712f_wdt_init(void)return -EBUSY ; } -it8712f_wdt_disable (); +if (it8712f_wdt_disable ()) +return -EBUSY ; err =register_reboot_notifier (&it8712f_wdt_notifier);if (err) {
drivers/watchdog/it87_wdt.c +97 -68
339 lines not on this page · raw message
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
PATCH v8 2/2 Use "request_muxed_region" in it87 hwmon drivers
In reply to Nat Gurumoorthy02 - Chages to hwmon it87 driver to use "request_muxed_region" Serialize access to the hardware by using "request_muxed_region" macro defined by Alan Cox. Call to this macro will hold off the requestor if the resource is currently busy. "superio_enter" will return an error if call to "request_muxed_region" fails. Rest of the code change is to ripple an error return from superio_enter to the top level.
---
drivers/hwmon/it87.c +12 -2
@@ -108,13 +108,20 @@ superio_select(int ldn)outb (ldn,VAL ); } -static inline void +static inline int superio_enter (void ) { +/* +* Try to reserve REG and REG + 1 for exclusive access. +*/ +if (!request_muxed_region (REG ,2 ,DRVNAME )) +return -EBUSY ; +outb (0x87 ,REG );outb (0x01 ,REG );outb (0x55 ,REG );outb (0x55 ,REG ); +return 0 ; } static inline void
@@ -122,6 +129,7 @@ superio_exit(void) {outb (0x02 ,REG );outb (0x02 ,VAL ); +release_region (REG ,2 ); }/* Logical device 4 registers */
@@ -1546,7 +1554,9 @@ static int __init it87_find(unsigned short *address,u16 chip_type;const char *board_vendor, *board_name; -superio_enter (); +if (superio_enter ()) +return -EBUSY ; + chip_type = force_id ? force_id :superio_inw (DEVID );switch (chip_type) {
Signature · 7 lines
1.7.3.1 _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Quoted 23 lines · Nat Gurumoorthy
There are 3 different drivers that touch the it87 hardware registers. The 3 drivers have been written independently and access the it87 hardware registers assuming they are the only driver accessing it. This change attempts to serialize access to the hardware by using "
request_muxed_region" macro defined by Alan Cox. Call to this macro will hold off the requestor if the resource is currently busy. The use of the above macro makes it possible to get rid of spinlocks init8712f_wdt.candit87_wdt.cwatchdog drivers. This also greatly simplifies the implementation ofit87_wdt.cdriver.01 - Changes to it87 watchdog driver to use "
request_muxed_region"
drivers/watchdog/it8712f_wdt.cdrivers/watchdog/it87_wdt.c02 - Chages to hwmon it87 driver to use "
request_muxed_region"
drivers/hwmon/it87.cdrivers/hwmon/it87.c | 14 +++- drivers/watchdog/it8712f_wdt.c | 60 ++++++++++---- drivers/watchdog/it87_wdt.c | 165 +++++++++++++++++++++++---------------- 3 files changed, 152 insertions(+), 87 deletions(-)drivers/hwmon/it87.c +0
-0
Quoted 5 lines
Signed-off-by Nat Gurumoorthy <[email protected]>Patch History:
v8:
- Return the error actually returned bysuperio_enterand not-EBUSY.
Hi Nat,
Your use of -EBUSY vs. the returned error code is still inconsistent, for superio_enter() as well as for other functions returning an error code.
Also, the following line split is really unnecessary.
-static inline void superio_enter(void)
+static inline int
+superio_enter(void)
Guenter
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Guenter,
Good catch. Forgot to checkin drivers/hwmon/it87.c. Also found a
couple of places I missed in driver/watch/it8712_wdt.c. Patch #9 will be shipped later tonight. Got pulled off to do something else. Expect patch late tonight.
Regards
Nat
Quoted 46 lines · Guenter Roeck
Quoted 23 lines · Nat Gurumoorthy
There are 3 different drivers that touch the it87 hardware registers. The 3 drivers have been written independently and access the it87 hardware registers assuming they are the only driver accessing it. This change attempts to serialize access to the hardware by using "
request_muxed_region" macro defined by Alan Cox. Call to this macro will hold off the requestor if the resource is currently busy. The use of the above macro makes it possible to get rid of spinlocks init8712f_wdt.candit87_wdt.cwatchdog drivers. This also greatly simplifies the implementation ofit87_wdt.cdriver.01 - Changes to it87 watchdog driver to use "
request_muxed_region"drivers/watchdog/it8712f_wdt.cdrivers/watchdog/it87_wdt.c02 - Chages to hwmon it87 driver to use "
request_muxed_region"drivers/hwmon/it87.cdrivers/hwmon/it87.c | 14 +++-
drivers/watchdog/it8712f_wdt.c| 60 ++++++++++----drivers/watchdog/it87_wdt.c| 165 +++++++++++++++++++++++----------------3 files changed, 152 insertions(+), 87 deletions(-)drivers/hwmon/it87.c +0
-0Quoted 5 lines
Signed-off-by Nat Gurumoorthy <[email protected]>Patch History:
v8:
- Return the error actually returned bysuperio_enterand not-EBUSY.Hi Nat,
Your use of
-EBUSYvs. the returned error code is still inconsistent, forsuperio_enter()as well as for other functions returning an error code.Also, the following line split is really unnecessary.
(quoted diff) +2
-1-static inline void superio_enter(void) +static inline int +superio_enter(void)Guenter
Signature · 7 lines
Regards Nat Gurumoorthy AB6SJ _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors