All of lore.kernel.org
 help / color / mirror / Atom feed
From: Aaron Lu <aaron.lu@intel.com>
To: "Rafael J. Wysocki" <rjw@sisk.pl>
Cc: Oliver Neukum <oliver@neukum.org>,
	James Bottomley <James.Bottomley@hansenpartnership.com>,
	Alan Stern <stern@rowland.harvard.edu>,
	Jeff Garzik <jgarzik@pobox.com>,
	linux-scsi@vger.kernel.org, linux-ide@vger.kernel.org,
	linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org,
	Aaron Lu <aaron.lwe@gmail.com>
Subject: Re: [PATCH v7 0/6] ZPODD patches
Date: Tue, 25 Sep 2012 16:18:26 +0800	[thread overview]
Message-ID: <20120925081825.GA1666@mint-spring.sh.intel.com> (raw)
In-Reply-To: <201209242346.03414.rjw@sisk.pl>

On Mon, Sep 24, 2012 at 11:46:03PM +0200, Rafael J. Wysocki wrote:
> On Monday, September 24, 2012, Aaron Lu wrote:
> > On Mon, Sep 24, 2012 at 03:06:11PM +0200, Rafael J. Wysocki wrote:
> > > On Monday, September 24, 2012, Aaron Lu wrote:
> > > > need_eject:
> > > > First consider how the device will be runtime resumed:
> > > > 1 Some program opens the block device;
> > > > 2 Events checking poll when it's not powered off yet;
> > > > 3 User presses the eject button or inserts a disc into the slot when the
> > > >   device is in powered off state.
> > > > And the need_eject flag is for case 3, when the device is in powered off
> > > > state and user presses the eject button, it will be powered on(through
> > > > acpi wake notification function) and runtime resumed. In its runtime
> > > > resume callback, its tray needs to be ejected since user just presses
> > > > the eject button. The whole process of ZPODD is opaque to the user,
> > > > he/she doesn't know the ODD lost power so the ODD has to behave exactly
> > > > like it doesn't lose power.
> > > 
> > > Do you think it can be useful for other types of devices, not necessarily
> > > handled through ACPI?
> > 
> > I can only say that it is useful for ZPODD, if ZPODD someday is used on
> > another platform that does not use ACPI, the need_eject flag should
> > still be needed.
> > 
> > As for other scsi devices, I'm not sure.
> 
> I see.  This means we don't really have good arguments for putting that flag
> into struct scsi_device ...

OK.

I'm thinking of moving the acpi wake notification code from ata to scsi,
so that the notification function lives in sr module and then I do not
need to set this need_eject flag in scsi_device and scsi_cd structure
needs to host this flag.

A example patch would be something like the following, I didn't seperate
these ACPI calls in sr.c as this is just a concept proof, if this is the
right thing to do, I will separate them into another file sr-acpi.c and
make empty stubs for them in sr.h for systems do not have ACPI configured.


diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index ef72682..94d17f1 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -46,6 +46,7 @@
 #include <linux/mutex.h>
 #include <linux/slab.h>
 #include <linux/pm_runtime.h>
+#include <linux/acpi.h>
 #include <asm/uaccess.h>
 
 #include <scsi/scsi.h>
@@ -57,6 +58,8 @@
 #include <scsi/scsi_host.h>
 #include <scsi/scsi_ioctl.h>	/* For the door lock/unlock commands */
 
+#include <acpi/acpi_bus.h>
+
 #include "scsi_logging.h"
 #include "sr.h"
 
@@ -212,8 +220,8 @@ static int sr_resume(struct device *dev)
 	scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES, &sshdr);
 
 	/* If user wakes up the ODD, eject the tray */
-	if (cd->device->need_eject) {
-		cd->device->need_eject = 0;
+	if (cd->need_eject) {
+		cd->need_eject = false;
 		/* But only for tray type ODD when door is not locked */
 		if (!(cd->cdi.mask & CDC_CLOSE_TRAY) && !cd->door_locked)
 			sr_tray_move(&cd->cdi, 1);
@@ -704,6 +711,58 @@ static void sr_release(struct cdrom_device_info *cdi)
 
 }
 
+static void sr_acpi_wake_dev(acpi_handle handle, u32 event, void *context)
+{
+	struct device *dev = context;
+	struct scsi_cd *cd = dev_get_drvdata(dev);
+
+	if (event == ACPI_NOTIFY_DEVICE_WAKE && pm_runtime_suspended(dev)) {
+		cd->need_eject = true;
+		pm_runtime_resume(dev);
+	}
+}
+
+static void sr_acpi_add_pm_notifier(struct device *dev)
+{
+	struct acpi_device *acpi_dev;
+	acpi_handle handle;
+	acpi_status status;
+
+	handle = dev->archdata.acpi_handle;
+	if (!handle)
+		return;
+
+	status = acpi_bus_get_device(handle, &acpi_dev);
+	if (ACPI_FAILURE(status))
+		return;
+
+	acpi_power_resource_register_device(dev, handle);
+	acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
+					sr_acpi_wake_dev, dev);
+	device_set_run_wake(dev, true);
+}
+
+static void sr_acpi_remove_pm_notifier(struct device *dev)
+{
+	struct acpi_device *acpi_dev;
+	acpi_handle handle;
+	acpi_status status;
+
+	handle = dev->archdata.acpi_handle;
+	if (!handle)
+		return;
+
+	status = acpi_bus_get_device(handle, &acpi_dev);
+	if (ACPI_FAILURE(status))
+		return;
+
+	acpi_power_resource_unregister_device(dev, handle);
+	device_set_run_wake(dev, false);
+	acpi_remove_notify_handler(handle, ACPI_SYSTEM_NOTIFY, sr_acpi_wake_dev);
+}
+
 static int sr_probe(struct device *dev)
 {
 	struct scsi_device *sdev = to_scsi_device(dev);
@@ -786,7 +845,9 @@ static int sr_probe(struct device *dev)
 	sdev_printk(KERN_DEBUG, sdev,
 		    "Attached scsi CD-ROM %s\n", cd->cdi.name);
 
-	/* enable runtime pm */
+	if (sdev->can_power_off)
+		sr_acpi_add_pm_notifier(dev);
+
 	scsi_autopm_put_device(cd->device);
 
 	return 0;
@@ -1036,8 +1097,9 @@ static int sr_remove(struct device *dev)
 {
 	struct scsi_cd *cd = dev_get_drvdata(dev);
 
-	/* disable runtime pm */
 	scsi_autopm_get_device(cd->device);
+	if (cd->device->can_power_off)
+		sr_acpi_remove_pm_notifier(dev);
 
 	blk_queue_prep_rq(cd->device->request_queue, scsi_prep_fn);
 	del_gendisk(cd->disk);


Thanks,
Aaron


  reply	other threads:[~2012-09-25  8:18 UTC|newest]

Thread overview: 85+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-12  8:29 [PATCH v7 0/6] ZPODD patches Aaron Lu
2012-09-12  8:29 ` [PATCH v7 1/6] block: genhd: add an interface to set disk poll interval Aaron Lu
2012-09-20 20:35   ` Rafael J. Wysocki
2012-09-12  8:29 ` [PATCH v7 2/6] scsi: sr: support runtime pm Aaron Lu
2012-09-20 20:48   ` Rafael J. Wysocki
2012-09-20 20:54     ` Alan Stern
2012-09-21  1:02     ` Aaron Lu
2012-09-21 20:49       ` Rafael J. Wysocki
2012-09-24  1:20         ` Aaron Lu
2012-09-24 12:55           ` Rafael J. Wysocki
2012-09-24 14:52             ` Aaron Lu
2012-09-24 21:40               ` Rafael J. Wysocki
2012-09-25  8:01                 ` Aaron Lu
2012-09-25 11:47                   ` Rafael J. Wysocki
2012-09-25 14:20                     ` Aaron Lu
2012-09-25 14:23                       ` Oliver Neukum
2012-09-25 14:46                         ` Aaron Lu
2012-09-25 21:45                           ` Rafael J. Wysocki
2012-09-26  1:03                             ` Aaron Lu
2012-09-26 11:18                               ` Rafael J. Wysocki
2012-09-26 14:52                                 ` Aaron Lu
2012-09-26  7:20                           ` Oliver Neukum
2012-09-27 10:46                   ` Oliver Neukum
2012-09-28  8:20                     ` Aaron Lu
2012-09-12  8:29 ` [PATCH v7 3/6] scsi: sr: support zero power ODD(ZPODD) Aaron Lu
2012-09-20 22:07   ` Rafael J. Wysocki
2012-09-21  1:39     ` Aaron Lu
2012-09-21 21:02       ` Rafael J. Wysocki
2012-09-27  9:26         ` Aaron Lu
2012-09-27 14:42           ` Alan Stern
2012-09-27 14:55             ` Aaron Lu
2012-09-27 23:29               ` Rafael J. Wysocki
2012-09-24 21:55   ` Jeff Garzik
2012-09-12  8:29 ` [PATCH v7 4/6] scsi: pm: add may_power_off flag Aaron Lu
2012-09-12  8:29 ` [PATCH v7 5/6] scsi: sr: use may_power_off Aaron Lu
2012-09-12  8:29 ` [PATCH v7 6/6] libata: acpi: respect may_power_off flag Aaron Lu
2012-09-24 21:55   ` Jeff Garzik
2012-09-19  8:03 ` [PATCH v7 0/6] ZPODD patches Aaron Lu
2012-09-19 12:27   ` James Bottomley
2012-09-19 12:50     ` Rafael J. Wysocki
2012-09-19 14:19       ` Aaron Lu
2012-09-20 20:00         ` Rafael J. Wysocki
2012-09-21  5:48           ` Aaron Lu
2012-09-21 21:18             ` Rafael J. Wysocki
2012-09-22  7:32               ` Oliver Neukum
2012-09-22 11:28                 ` Rafael J. Wysocki
2012-09-22 15:38                   ` Alan Stern
2012-09-22 19:46                     ` Rafael J. Wysocki
2012-09-22 20:23                       ` Alan Stern
2012-09-22 21:48                         ` Rafael J. Wysocki
2012-09-24  2:55               ` Aaron Lu
2012-09-24 13:06                 ` Rafael J. Wysocki
2012-09-24 15:04                   ` Aaron Lu
2012-09-24 21:46                     ` Rafael J. Wysocki
2012-09-25  8:18                       ` Aaron Lu [this message]
2012-09-25 11:02                         ` James Bottomley
2012-09-25 13:56                           ` Aaron Lu
2012-09-27  9:43                           ` Aaron Lu
2012-09-24 15:47                 ` Alan Stern
2012-09-19 14:52       ` James Bottomley
2012-09-20 21:46         ` Rafael J. Wysocki
2012-09-19 13:05     ` Oliver Neukum
2012-09-19 15:19     ` David Woodhouse
2012-09-20  0:34       ` Jack Wang
     [not found] ` <201209280115.06964.rjw@sisk.pl>
     [not found]   ` <5064FA08.6030005@intel.com>
     [not found]     ` <201209282346.15872.rjw@sisk.pl>
2012-09-29  2:10       ` [PATCH v7 2/6] scsi: sr: support runtime pm Aaron Lu
2012-09-29 14:29         ` Alan Stern
2012-09-29 15:03           ` Aaron Lu
2012-09-29 22:44             ` Rafael J. Wysocki
2012-09-30 12:32               ` Aaron Lu
2012-09-30 14:47                 ` Alan Stern
2012-09-30 15:39                   ` Aaron Lu
2012-09-30 19:15                   ` Jeff Garzik
2012-09-30 19:08               ` Jeff Garzik
2012-09-29 22:31           ` Rafael J. Wysocki
2012-09-30 19:03             ` Jeff Garzik
2012-09-30 19:43               ` Alan Stern
2012-10-01  4:57                 ` Jeff Garzik
2012-10-08  9:27                 ` Aaron Lu
2012-10-08 10:21                   ` James Bottomley
2012-10-09  7:20                     ` Aaron Lu
2012-10-09 14:58                       ` James Bottomley
2012-10-11  7:49                         ` Aaron Lu
2012-10-09 23:26                       ` Rafael J. Wysocki
2012-09-29 22:27         ` Rafael J. Wysocki
2012-09-30 12:38           ` Aaron Lu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120925081825.GA1666@mint-spring.sh.intel.com \
    --to=aaron.lu@intel.com \
    --cc=James.Bottomley@hansenpartnership.com \
    --cc=aaron.lwe@gmail.com \
    --cc=jgarzik@pobox.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=oliver@neukum.org \
    --cc=rjw@sisk.pl \
    --cc=stern@rowland.harvard.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.