linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* PATCH/RFC: driver model/pmcore wakeup hooks (1/4)
@ 2004-10-04 21:00 David Brownell
  2004-10-05 19:37 ` Pavel Machek
  0 siblings, 1 reply; 11+ messages in thread
From: David Brownell @ 2004-10-04 21:00 UTC (permalink / raw)
  To: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 136 bytes --]

This lets drivers standardize how they present their ability to issue
wakeups, and how they manage whether that ability should be used.

[-- Attachment #2: wake-core.patch --]
[-- Type: text/x-diff, Size: 4495 bytes --]

This adds basic driver model and sysfs support for device wakeup
capabilities.

 - adds two driver model pmcore wakeup bits:
     * can_wakeup, initialized using device_init_wakeup() in bus
       or device driver code
     * should_wakeup, tested by device_may_wakeup() during device
       power state transitions

 - make that new state observable and manageable by letting sysfs
   change the should_wakeup policy by writing the "wakeup" attribute

This patch doesn't add callers or change existing wakeup code like:

 - USB (these bits replace two existing usb-internal bits)
 - PCI (can_wakeup coming from PCI PM capability)
 - ACPI (this should probably replace the new /proc/acpi/wakeup)
 - Ethtool should just set WOL policies
 - ... probably there are others.

Patches for the USB and PCI exist already.

[ against 2.6.9-rc3 ]


--- 1.4/drivers/base/power/sysfs.c	Wed Jun  9 23:34:24 2004
+++ edited/drivers/base/power/sysfs.c	Mon Oct  4 12:22:13 2004
@@ -48,8 +48,71 @@
 static DEVICE_ATTR(state, 0644, state_show, state_store);
 
 
+/*
+ *	wakeup - Report/change current wakeup option for device
+ *
+ *	Some devices support "wakeup" events, which are hardware signals
+ *	used to activate devices in suspended or low power states.  Such
+ *	devices have one of two wakeup options:  "enabled" to issue the
+ *	events, otherwise "disabled".  The value is effective at the next
+ *	state change.  (Other devices have no value for this option.)
+ *
+ *	Familiar examples of devices that can issue wakeup events include
+ *	keyboards and mice (both PS2 and USB styles), power buttons, clocks,
+ *	"Wake-On-LAN" Ethernet links, modems, and more.  Sometimes these
+ *	events will wake the system from a suspend state, but often they
+ *	just wake up a single device that's been selectively suspended.
+ *
+ *	It is the responsibility of device drivers to enable (or disable)
+ *	wakeup signaling as part of changing device suspend or power states,
+ *	respecting the policy choice provided through the driver model.
+ *
+ *	Devices may not be able to generate wakeup events from all power
+ *	states.  Also, the events may be ignored in some configurations;
+ *	for example, they might need help from other devices.  Some drivers
+ *	use wakeup events internally, keeping their hardware in a low power
+ *	mode most of the time (even without a system-wide suspend state),
+ *	unless wakeup is disabled.
+ */
+
+static const char enabled[] = "enabled";
+static const char disabled[] = "disabled";
+
+static ssize_t wake_show(struct device * dev, char * buf)
+{
+	return sprintf(buf, "%s\n", device_can_wakeup(dev)
+		? (device_may_wakeup(dev) ? enabled : disabled)
+		: "");
+}
+
+static ssize_t wake_store(struct device * dev, const char * buf, size_t n)
+{
+	char *cp;
+	int len = n;
+
+	if (!device_can_wakeup(dev))
+		return -EINVAL;
+
+	cp = memchr(buf, '\n', n);
+	if (cp)
+		len = cp - buf;
+	if (len == sizeof enabled - 1
+			&& strncmp(buf, enabled, sizeof enabled - 1) == 0)
+		device_set_wakeup_enable(dev, 1);
+	else if (len == sizeof disabled - 1
+			&& strncmp(buf, disabled, sizeof disabled - 1) == 0)
+		device_set_wakeup_enable(dev, 0);
+	else
+		return -EINVAL;
+	return n;
+}
+
+static DEVICE_ATTR(wakeup, 0644, wake_show, wake_store);
+
+
 static struct attribute * power_attrs[] = {
 	&dev_attr_state.attr,
+	&dev_attr_wakeup.attr,
 	NULL,
 };
 static struct attribute_group pm_attr_group = {
--- 1.19/include/linux/pm.h	Thu Sep 30 11:23:17 2004
+++ edited/include/linux/pm.h	Mon Oct  4 12:22:13 2004
@@ -237,6 +237,8 @@
 	atomic_t		pm_users;
 	struct device		* pm_parent;
 	struct list_head	entry;
+	unsigned		can_wakeup:1;
+	unsigned		should_wakeup:1;
 #endif
 };
 
@@ -247,6 +249,23 @@
 extern void device_power_up(void);
 extern void device_resume(void);
 
+/* wakeup changes take effect on device's next pm state change */
+#ifdef CONFIG_PM
+#define device_init_wakeup(dev,val) \
+	((dev)->power.can_wakeup = ((dev)->power.should_wakeup = !!(val)))
+#define device_set_wakeup_enable(dev,val) \
+	((dev)->power.should_wakeup = (dev)->power.can_wakeup ? !!(val) : 0)
+#define device_can_wakeup(dev) \
+	((dev)->power.can_wakeup)
+#define device_may_wakeup(dev) \
+	(device_can_wakeup(dev) && (dev)->power.should_wakeup)
+
+#else /* !CONFIG_PM */
+#define device_init_wakeup(dev,val)		do()while(0)
+#define device_set_wakeup_enable(dev,val)	do()while(0)
+#define device_can_wakeup(dev)			(0)
+#define device_may_wakeup(dev)			(0)
+#endif
 
 #endif /* __KERNEL__ */
 

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: PATCH/RFC: driver model/pmcore wakeup hooks (1/4)
  2004-10-04 21:00 PATCH/RFC: driver model/pmcore wakeup hooks (1/4) David Brownell
@ 2004-10-05 19:37 ` Pavel Machek
  2004-10-05 20:09   ` David Brownell
  0 siblings, 1 reply; 11+ messages in thread
From: Pavel Machek @ 2004-10-05 19:37 UTC (permalink / raw)
  To: David Brownell; +Cc: linux-kernel

Hi!

> This lets drivers standardize how they present their ability to issue
> wakeups, and how they manage whether that ability should be used.

Why do you assign "enabled" to variable instead of using it directly?
And perhaps you should print "not supported" instead of empty string...

				Pavel

-- 
64 bytes from 195.113.31.123: icmp_seq=28 ttl=51 time=448769.1 ms         


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: PATCH/RFC: driver model/pmcore wakeup hooks (1/4)
  2004-10-05 19:37 ` Pavel Machek
@ 2004-10-05 20:09   ` David Brownell
  2004-10-05 20:15     ` Pavel Machek
  2004-10-16  6:03     ` Len Brown
  0 siblings, 2 replies; 11+ messages in thread
From: David Brownell @ 2004-10-05 20:09 UTC (permalink / raw)
  To: Pavel Machek; +Cc: linux-kernel

On Tuesday 05 October 2004 12:37 pm, Pavel Machek wrote:
> Hi!
> 
> > This lets drivers standardize how they present their ability to issue
> > wakeups, and how they manage whether that ability should be used.
> 
> Why do you assign "enabled" to variable instead of using it directly?

So there's exactly one copy of that string in use, agreeing with itself.
Also, so strncmp() can be used.  It won't matter if the sysadmin goes

   echo -n enabled > wakeup
   echo enabled > wakeup

I'd personally rather use "on" and "off", but there seems to be
a convention in /proc/acpi/wakeup in favor of polysyllabicism.


> And perhaps you should print "not supported" instead of empty string...

Except that's two words, not one, which will make shell script
bugs happen more readily.  I thought about "(none)" which
has the same issue, and "-".  But I figured that if it were very
important, a good solution would appear ... ;)

- Dave

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: PATCH/RFC: driver model/pmcore wakeup hooks (1/4)
  2004-10-05 20:09   ` David Brownell
@ 2004-10-05 20:15     ` Pavel Machek
  2004-10-05 21:53       ` David Brownell
  2004-10-16  6:03     ` Len Brown
  1 sibling, 1 reply; 11+ messages in thread
From: Pavel Machek @ 2004-10-05 20:15 UTC (permalink / raw)
  To: David Brownell; +Cc: Pavel Machek, linux-kernel

Hi!

> > > This lets drivers standardize how they present their ability to issue
> > > wakeups, and how they manage whether that ability should be used.
> > 
> > Why do you assign "enabled" to variable instead of using it directly?
> 
> So there's exactly one copy of that string in use, agreeing with itself.
> Also, so strncmp() can be used.  It won't matter if the sysadmin goes
> 
>    echo -n enabled > wakeup
>    echo enabled > wakeup

Well, you could make that 0,1. That would be more sysfs-style...

> I'd personally rather use "on" and "off", but there seems to be
> a convention in /proc/acpi/wakeup in favor of polysyllabicism.
> 
> 
> > And perhaps you should print "not supported" instead of empty string...
> 
> Except that's two words, not one, which will make shell script
> bugs happen more readily.  I thought about "(none)" which
> has the same issue, and "-".  But I figured that if it were very
> important, a good solution would appear ... ;)

On the second thought, perhaps file simply should not be there if
wakeup is not supported.
								Pavel
-- 
People were complaining that M$ turns users into beta-testers...
...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: PATCH/RFC: driver model/pmcore wakeup hooks (1/4)
  2004-10-05 20:15     ` Pavel Machek
@ 2004-10-05 21:53       ` David Brownell
  0 siblings, 0 replies; 11+ messages in thread
From: David Brownell @ 2004-10-05 21:53 UTC (permalink / raw)
  To: Pavel Machek; +Cc: linux-kernel

On Tuesday 05 October 2004 1:15 pm, Pavel Machek wrote:

> > Also, so strncmp() can be used.  It won't matter if the sysadmin goes
> > 
> >    echo -n enabled > wakeup
> >    echo enabled > wakeup
> 
> Well, you could make that 0,1. That would be more sysfs-style...

Only for things like detach_state and power_state, which shouldn't
be numbers in the first place ... :)

The /sys/module/*/OPTION strings use Y/N for booleans, and
maybe sysfs should actually have generic code to read/write
such boolean values.


> On the second thought, perhaps file simply should not be there if
> wakeup is not supported.

That doesn't work too well for things like USB, where one config
may support wakeup but another doesn't ... and unconfigured
devices never support it.  The "can_support" value changes
over time.

- Dave

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: PATCH/RFC: driver model/pmcore wakeup hooks (1/4)
  2004-10-05 20:09   ` David Brownell
  2004-10-05 20:15     ` Pavel Machek
@ 2004-10-16  6:03     ` Len Brown
  2004-10-19  3:41       ` David Brownell
  1 sibling, 1 reply; 11+ messages in thread
From: Len Brown @ 2004-10-16  6:03 UTC (permalink / raw)
  To: David Brownell; +Cc: Pavel Machek, linux-kernel, ACPI Developers

> - ACPI (this should probably replace the new /proc/acpi/wakeup)

Agreed.  That file is a temporary solution.
The right solution is for the devices to appear in the right
place in the device tree and to hang the wakeup capabilities
off of them there.

thanks,
-Len



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: PATCH/RFC: driver model/pmcore wakeup hooks (1/4)
  2004-10-16  6:03     ` Len Brown
@ 2004-10-19  3:41       ` David Brownell
  2004-10-19  4:55         ` [ACPI] " Hiroshi 2 Itoh
  2004-10-20  6:16         ` Len Brown
  0 siblings, 2 replies; 11+ messages in thread
From: David Brownell @ 2004-10-19  3:41 UTC (permalink / raw)
  To: Len Brown; +Cc: Pavel Machek, linux-kernel, ACPI Developers

On Friday 15 October 2004 11:03 pm, Len Brown wrote:
> > - ACPI (this should probably replace the new /proc/acpi/wakeup)
> 
> Agreed.  That file is a temporary solution.
> The right solution is for the devices to appear in the right
> place in the device tree and to hang the wakeup capabilities
> off of them there.

So what would that patch need before ACPI could convert to use it?

I didn't notice any obvious associations between the strings in
the acpi/wakeup file and anything in sysfs.  Which of USB1..USB4
was which of the three controllers shown by "lspci" (and which
one was "extra"!), as one head-scratcher.

For PCI, I'd kind of expect pci_enable_wake() to trigger the
additional ACPI-specific work to make sure the device can
actually wake that system.   Seems like dev->platform_data
might need to combine with some platform-specific API hook.

- Dave

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [ACPI] Re: PATCH/RFC: driver model/pmcore wakeup hooks (1/4)
  2004-10-19  3:41       ` David Brownell
@ 2004-10-19  4:55         ` Hiroshi 2 Itoh
  2004-10-19  5:18           ` David Brownell
  2004-10-20  6:16         ` Len Brown
  1 sibling, 1 reply; 11+ messages in thread
From: Hiroshi 2 Itoh @ 2004-10-19  4:55 UTC (permalink / raw)
  To: David Brownell; +Cc: ACPI Developers, Len Brown, linux-kernel, Pavel Machek





David Brownell wrote:

>So what would that patch need before ACPI could convert to use it?

>I didn't notice any obvious associations between the strings in
>the acpi/wakeup file and anything in sysfs.  Which of USB1..USB4
>was which of the three controllers shown by "lspci" (and which
>one was "extra"!), as one head-scratcher.

>For PCI, I'd kind of expect pci_enable_wake() to trigger the
>additional ACPI-specific work to make sure the device can
>actually wake that system.   Seems like dev->platform_data
>might need to combine with some platform-specific API hook.

>- Dave

Does anoyone give me a link to the original RFC?
I cannot find the original mail as a newbie associated with this list.

Hiro.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [ACPI] Re: PATCH/RFC: driver model/pmcore wakeup hooks (1/4)
  2004-10-19  4:55         ` [ACPI] " Hiroshi 2 Itoh
@ 2004-10-19  5:18           ` David Brownell
  0 siblings, 0 replies; 11+ messages in thread
From: David Brownell @ 2004-10-19  5:18 UTC (permalink / raw)
  To: Hiroshi 2 Itoh; +Cc: ACPI Developers, Len Brown, linux-kernel, Pavel Machek

On Monday 18 October 2004 9:55 pm, Hiroshi 2 Itoh wrote:
> >So what would that patch need before ACPI could convert to use it?
> 
> Does anoyone give me a link to the original RFC?
> I cannot find the original mail as a newbie associated with this list.

Messages 0-4 are:

http://marc.theaimsgroup.com/?l=linux-kernel&m=109692668310738&w=2
http://marc.theaimsgroup.com/?l=linux-kernel&m=109692668228442&w=2
http://marc.theaimsgroup.com/?l=linux-kernel&m=109692610403412&w=2
http://marc.theaimsgroup.com/?l=linux-kernel&m=109692915107429&w=2
http://marc.theaimsgroup.com/?l=linux-kernel&m=109692881326178&w=2

Click on the second one ... :)

- Dave

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: PATCH/RFC: driver model/pmcore wakeup hooks (1/4)
  2004-10-19  3:41       ` David Brownell
  2004-10-19  4:55         ` [ACPI] " Hiroshi 2 Itoh
@ 2004-10-20  6:16         ` Len Brown
  1 sibling, 0 replies; 11+ messages in thread
From: Len Brown @ 2004-10-20  6:16 UTC (permalink / raw)
  To: David Brownell; +Cc: Pavel Machek, linux-kernel, ACPI Developers

On Mon, 2004-10-18 at 23:41, David Brownell wrote:
> On Friday 15 October 2004 11:03 pm, Len Brown wrote:
> > > - ACPI (this should probably replace the new /proc/acpi/wakeup)
> >
> > Agreed.  That file is a temporary solution.
> > The right solution is for the devices to appear in the right
> > place in the device tree and to hang the wakeup capabilities
> > off of them there.
> 
> So what would that patch need before ACPI could convert to use it?
> 
> I didn't notice any obvious associations between the strings in
> the acpi/wakeup file and anything in sysfs.  Which of USB1..USB4
> was which of the three controllers shown by "lspci" (and which
> one was "extra"!), as one head-scratcher.

The strings "USB1" etc. are completely arbitrary, which is one
reason that /proc/acpi/wakeup is only marginally useful.

> For PCI, I'd kind of expect pci_enable_wake() to trigger the
> additional ACPI-specific work to make sure the device can
> actually wake that system.   Seems like dev->platform_data
> might need to combine with some platform-specific API hook.

In the ACPI DSDT...
Devices are explicitly identified as PCI busses by their PNP-id.
These PCI busses are enumerated by their _BBN or _CRS.
The devices under the PCI busses all contain an _ADR which encodes the
PCI device/function number.

Ie. ACPI tells us the PCI bus/dev/func for each PCI device in the DSDT,
and with this information it needs to be able to find devices in the
Linux device tree and associate some ACPI capabilities with it.

-Len



^ permalink raw reply	[flat|nested] 11+ messages in thread

* RE: PATCH/RFC: driver model/pmcore wakeup hooks (1/4)
@ 2004-10-19  9:11 Li, Shaohua
  0 siblings, 0 replies; 11+ messages in thread
From: Li, Shaohua @ 2004-10-19  9:11 UTC (permalink / raw)
  To: David Brownell, Brown, Len; +Cc: Pavel Machek, linux-kernel, ACPI Developers

A final solution is device core adds an ACPI layer. That is we can link
ACPI device and physical device. This way, the PCI device can know which
ACPI is linked with it, so the PCI API can use specific ACPI method. 
You are right, we currently haven't a method to reach the goal. To match
a physical device and ACPI device, we need to know the ACPI device's
_ADR and bus.
I have a toy to link the PCI device and ACPI device, and some PCI
function can use _SxD method and _PSx method to get some information for
suspend/resume.

Thanks,
Shaohua
>-----Original Message-----
>From: linux-kernel-owner@vger.kernel.org [mailto:linux-kernel-
>owner@vger.kernel.org] On Behalf Of David Brownell
>Sent: Tuesday, October 19, 2004 11:41 AM
>To: Brown, Len
>Cc: Pavel Machek; linux-kernel@vger.kernel.org; ACPI Developers
>Subject: Re: PATCH/RFC: driver model/pmcore wakeup hooks (1/4)
>
>On Friday 15 October 2004 11:03 pm, Len Brown wrote:
>> > - ACPI (this should probably replace the new /proc/acpi/wakeup)
>>
>> Agreed.  That file is a temporary solution.
>> The right solution is for the devices to appear in the right
>> place in the device tree and to hang the wakeup capabilities
>> off of them there.
>
>So what would that patch need before ACPI could convert to use it?
>
>I didn't notice any obvious associations between the strings in
>the acpi/wakeup file and anything in sysfs.  Which of USB1..USB4
>was which of the three controllers shown by "lspci" (and which
>one was "extra"!), as one head-scratcher.
>
>For PCI, I'd kind of expect pci_enable_wake() to trigger the
>additional ACPI-specific work to make sure the device can
>actually wake that system.   Seems like dev->platform_data
>might need to combine with some platform-specific API hook.
>
>- Dave
>-
>To unsubscribe from this list: send the line "unsubscribe linux-kernel"
in
>the body of a message to majordomo@vger.kernel.org
>More majordomo info at  http://vger.kernel.org/majordomo-info.html
>Please read the FAQ at  http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2004-10-20  6:26 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-04 21:00 PATCH/RFC: driver model/pmcore wakeup hooks (1/4) David Brownell
2004-10-05 19:37 ` Pavel Machek
2004-10-05 20:09   ` David Brownell
2004-10-05 20:15     ` Pavel Machek
2004-10-05 21:53       ` David Brownell
2004-10-16  6:03     ` Len Brown
2004-10-19  3:41       ` David Brownell
2004-10-19  4:55         ` [ACPI] " Hiroshi 2 Itoh
2004-10-19  5:18           ` David Brownell
2004-10-20  6:16         ` Len Brown
2004-10-19  9:11 Li, Shaohua

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).