lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:	Tue, 22 Mar 2011 17:08:54 +0900
From:	MyungJoo Ham <myungjoo.ham@...sung.com>
To:	rtc-linux@...glegroups.com
Cc:	linux-kernel@...r.kernel.org,
	Alessandro Zummo <a.zummo@...ertech.it>,
	John Stultz <john.stultz@...aro.org>,
	kyungmin.park@...sung.com, myungjoo.ham@...il.com
Subject: [PATCH v2] RTC: Selectively enable PIE-Hrtimer emulation.

The patch of John Stultz, "RTC: Rework RTC code to use timerqueue for
events", has enabled PIE interrupt emulation with hrtimer unconditionally.
However, we do have RTC devices that support PIE and such devices are
not meant to be emulated by hrtimer. Besides, we sometimes need RTC-PIE
to function while hrtimer does not; e.g., CPU's RTC PIE as a
suspend-to-RAM wakeup source.

This patch allows to selectively use the PIE emulation. If the rtc
driver has implemented PIE related ops (irq_set_state and irq_set_freq),
PIE emulation is not used. Currently, rtc-s3c, rtc-cmos,
rtc-davinci, rtc-pl031, rtc-pxa, rtc-sa1100, rtc-sh, and rtc-vt41xx have
them.

Besides, rtc->pie_enabled is renamed as rtc->pie_emul_enabled. It is
because that variable denotes whether HRTimer-PIE is set or not.

Signed-off-by: MyungJoo Ham <myungjoo.ham@...sung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@...sung.com>
---
 drivers/rtc/class.c     |    2 +-
 drivers/rtc/interface.c |   33 +++++++++++++++++++++++++--------
 include/linux/rtc.h     |    2 +-
 3 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
index c404b61..102d706 100644
--- a/drivers/rtc/class.c
+++ b/drivers/rtc/class.c
@@ -164,7 +164,7 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev,
 	/* Init pie timer */
 	hrtimer_init(&rtc->pie_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
 	rtc->pie_timer.function = rtc_pie_update_irq;
-	rtc->pie_enabled = 0;
+	rtc->pie_emul_enabled = 0;
 
 	strlcpy(rtc->name, name, RTC_DEVICE_NAME_SIZE);
 	dev_set_name(&rtc->dev, "rtc%d", id);
diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index cb2f072..6d5aa3b 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -450,16 +450,25 @@ int rtc_irq_set_state(struct rtc_device *rtc, struct rtc_task *task, int enabled
 		err = -EBUSY;
 	if (rtc->irq_task != task)
 		err = -EACCES;
+	if (err)
+		goto out;
 
-	if (enabled) {
-		ktime_t period = ktime_set(0, NSEC_PER_SEC/rtc->irq_freq);
-		hrtimer_start(&rtc->pie_timer, period, HRTIMER_MODE_REL);
+	if (rtc->ops->irq_set_state) {
+		err = rtc->ops->irq_set_state(rtc->dev.parent, enabled);
+		rtc->pie_emul_enabled = 0;
 	} else {
-		hrtimer_cancel(&rtc->pie_timer);
+		if (enabled) {
+			ktime_t period = ktime_set(0, NSEC_PER_SEC /
+					rtc->irq_freq);
+			hrtimer_start(&rtc->pie_timer, period,
+					HRTIMER_MODE_REL);
+		} else {
+			hrtimer_cancel(&rtc->pie_timer);
+		}
+		rtc->pie_emul_enabled = enabled;
 	}
-	rtc->pie_enabled = enabled;
+out:
 	spin_unlock_irqrestore(&rtc->irq_task_lock, flags);
-
 	return err;
 }
 EXPORT_SYMBOL_GPL(rtc_irq_set_state);
@@ -487,9 +496,16 @@ int rtc_irq_set_freq(struct rtc_device *rtc, struct rtc_task *task, int freq)
 		err = -EBUSY;
 	if (rtc->irq_task != task)
 		err = -EACCES;
-	if (err == 0) {
+	if (err)
+		goto out;
+
+	if (rtc->ops->irq_set_freq) {
+		err = rtc->ops->irq_set_freq(rtc->dev.parent, freq);
+		if (err == 0)
+			rtc->irq_freq = freq;
+	} else {
 		rtc->irq_freq = freq;
-		if (rtc->pie_enabled) {
+		if (rtc->pie_emul_enabled) {
 			ktime_t period;
 			hrtimer_cancel(&rtc->pie_timer);
 			period = ktime_set(0, NSEC_PER_SEC/rtc->irq_freq);
@@ -497,6 +513,7 @@ int rtc_irq_set_freq(struct rtc_device *rtc, struct rtc_task *task, int freq)
 					HRTIMER_MODE_REL);
 		}
 	}
+out:
 	spin_unlock_irqrestore(&rtc->irq_task_lock, flags);
 	return err;
 }
diff --git a/include/linux/rtc.h b/include/linux/rtc.h
index 89c3e51..b2c0a62 100644
--- a/include/linux/rtc.h
+++ b/include/linux/rtc.h
@@ -201,7 +201,7 @@ struct rtc_device
 	struct rtc_timer aie_timer;
 	struct rtc_timer uie_rtctimer;
 	struct hrtimer pie_timer; /* sub second exp, so needs hrtimer */
-	int pie_enabled;
+	int pie_emul_enabled;
 	struct work_struct irqwork;
 
 
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ