implement power chip
v2 cover implement power chip
By now, all devices of QEMU do not have much more
power management consideration, for example, if
system do suspend, it will call all registered notifiers,
this was loosely required, and the code to do power management state transition seems just do 'ugly emulation', rather than be conscious with whole system devices, same condition with reset. shutdown, in real world, commonly all devices' power are controlled by a power chip, then all power sequence can be done just
issue commands or raise signals connected to this chip.
so, I come across an idea to implement qdev'ed power device, and make all qdev struct of devices aware of self power management(connect power signal with power chip, then respond to power state change), this will bring tidy power management, and the emulation will more like what happened in real world.
Of course, it's only a patch-set for RFC, I'd like to ask all developers to help correct this idea, if it's worth to implement, I'll go head to refactor more.
v2: change from functions calling to signal connecting between
power chip and devices.
Li Guang (7)
hw/irq: move struct IRQState to irq.h hw/power: add main power chip implementation
vl: create power chip device
sysemu: remove PowerReason in sysemu.h
qdev: add power_signal_in for DeviceState
ich9: refactor wakeup/reset function
vl: run power_management
hw/acpi.c | 20 +++++++++----------- hw/acpi.h | 3 ++- hw/acpi_ich9.c | 2 +- hw/Makefile.objs | 1 + hw/ich9.h | 2 ++ hw/irq.c | 6 ------ hw/irq.h | 6 ++++++ hw/lpc_ich9.c | 30 +++++++++++++++++++++++++++++- hw/power.c | 178 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/power.h | 50 +++++++++++++++ hw/qdev-core.h | 1 + include/sysemu/sysemu.h | 7 +------ vl.c | 5 ++++ 13 files changed, 285 insertions(+), 26 deletions(-) create mode 100644 hw/power.c create mode 100644 hw/power.h
RFC PATCH v2 1/7 hw/irq: move struct IRQState to irq.h
define struct IRQState in irq.c bring in
a annoying result, if you want dereference of
IRQState's member like opaque outside ofirq.c, compiler will complain:
"error: dereferencing pointer to incomplete type"
--- hw/irq.c | 6 ------ hw/irq.h | 6 ++++++ 2 files changed, 6 insertions(+), 6 deletions(-)
hw/irq.c +0 -6
@@ -24,12 +24,6 @@#include "qemu-common.h" #include "hw/irq.h" -struct IRQState { -qemu_irq_handler handler; -void *opaque; -int n; -}; -void qemu_set_irq (qemu_irq irq,int level) {if (!irq)
hw/irq.h +6 -0
@@ -7,6 +7,12 @@ typedef struct IRQState *qemu_irq;typedef void (*qemu_irq_handler )(void *opaque,int n,int level); +struct IRQState { +qemu_irq_handler handler; +void *opaque; +int n; +}; +void qemu_set_irq (qemu_irq irq,int level);static inline void qemu_irq_raise (qemu_irq irq)
Signature · 1 line
1.7.2.5
Re: [Qemu-devel] [PATCH][RFC v2 1/7] hw/irq: move struct IRQState to irq.h
Quoted 5 lines · liguang
define struct IRQState in
irq.cbring in
a annoying result, if you want dereference of
IRQState's member like opaque outside ofirq.c, compiler will complain:
"error: dereferencing pointer to incomplete type"
No, this is deliberate -- it's an opaque type which should only be used inside irq.c. If you think you need to dereference it you're probably doing something wrong.
thanks
-- PMM
Re: [Qemu-devel] [PATCH][RFC v2 1/7] hw/irq: move struct IRQState to irq.h
Quoted 11 lines · 在 2013-04-05五的 09:34 +0100,Peter Maydell写道:
Quoted 5 lines · liguang
define struct IRQState in
irq.cbring in
a annoying result, if you want dereference of
IRQState's member like opaque outside ofirq.c, compiler will complain:
"error: dereferencing pointer to incomplete type"No, this is deliberate -- it's an opaque type which should only be used inside
irq.c. If you think you need to dereference it you're probably doing something wrong.
Yes, you're right, it's only a suggestion for
some hacking conditions.
RFC PATCH v2 2/7 hw/power: add main power chip implementation
In reply to liguanghere, we will handle power state transition between on, off, suspend, wakeup, we treat reset as power on then off, and power out pin will be connected to power in pin of devices, if we want a transition, we will trigger a power signal(qemu_irq), then all connected devices will be reply for this.
--- hw/Makefile.objs | 1 + hw/power.c | 178 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/power.h | 50 +++++++++++++++ 3 files changed, 229 insertions(+), 0 deletions(-) create mode 100644 hw/power.c create mode 100644 hw/power.h
hw/Makefile.objs +1 -0
@@ -2,6 +2,7 @@ common-obj-y += qdev.o qdev-properties.o # irq.o needed for qdev GPIO handling: common-obj-y += irq.o +common-obj-y += power.o ifeq ($(CONFIG_SOFTMMU),y) common-obj-y += usb/ ide/ pci/
hw/power.c new file +178 -0
178 lines not on this page · raw message
hw/power.h new file +50 -0
50 lines not on this page · raw message
Signature · 1 line
1.7.2.5
Re: [Qemu-devel] [PATCH][RFC v2 2/7] hw/power: add main power chip implementation
Quoted 6 lines · liguang
here, we will handle power state transition between on, off, suspend, wakeup, we treat reset as power on then off, and power out pin will be connected to power in pin of devices, if we want a transition, we will trigger a power
signal(qemu_irq), then all connected devices will be reply for this.
What actual hardware is this supposed to be modelling? I don't believe there's such a thing as a 'generic power controller' that makes sense for all architectures.
-- PMM
Re: [Qemu-devel] [PATCH][RFC v2 2/7] hw/power: add main power chip implementation
Quoted 8 lines · 在 2013-04-05五的 09:35 +0100,Peter Maydell写道:
Quoted 6 lines · liguang
here, we will handle power state transition between on, off, suspend, wakeup, we treat reset as power on then off, and power out pin will be connected to power in pin of devices, if we want a transition, we will trigger a power
signal(qemu_irq), then all connected devices will be reply for this.
Quoted 4 lines
What actual hardware is this supposed to be modelling? I don't believe there's such a thing as a 'generic power controller' that makes sense for all architectures.
unfortunately, I'm considering it as generic and abstract. I think we have no need to model a specific type of power controller, because what we are doing is to construct a power controlling process, not to realize a hardware platform's device for special purpose.
Yes, you can say not all devices are happy to do with power management, but I would say, I'm not going to force every devices to do that.
Re: [Qemu-devel] [PATCH][RFC v2 2/7] hw/power: add main power chip implementation
Quoted 10 lines · li guang
Quoted 3 lines · 在 2013-04-05五的 09:35 +0100,Peter Maydell写道:
What actual hardware is this supposed to be modelling? I don't believe there's such a thing as a 'generic power controller' that makes sense for all architectures.
unfortunately, I'm considering it as generic and abstract. I think we have no need to model a specific type of power controller, because what we are doing is to construct a power controlling process, not to realize a hardware platform's device for special purpose.
QEMU is fundamentally modelling real hardware platforms, not abstract devices. You have to model a real power controller to at least some extent, because that's what guest OSes expect to be interacting with, and what device and board hardware models expect to be dealing with.
-- PMM
Re: [Qemu-devel] [PATCH][RFC v2 2/7] hw/power: add main power chip implementation
Quoted 12 lines · 在 2013-04-05五的 10:23 +0100,Peter Maydell写道:
Quoted 10 lines · li guang
Quoted 3 lines · 在 2013-04-05五的 09:35 +0100,Peter Maydell写道:
What actual hardware is this supposed to be modelling? I don't believe there's such a thing as a 'generic power controller' that makes sense for all architectures.
unfortunately, I'm considering it as generic and abstract. I think we have no need to model a specific type of power controller, because what we are doing is to construct a power controlling process, not to realize a hardware platform's device for special purpose.
Quoted 5 lines
QEMU is fundamentally modelling real hardware platforms, not abstract devices. You have to model a real power controller to at least some extent, because that's what guest OSes expect to be interacting with, and what device and board hardware models expect to be dealing with.
Hmm, let me see ...
but you know, in my mind OS mostly dose not care more about power controller, for example, if OS want to reset, it just issues a command or writes a special value to register in a chip(not power controller), like PC, one of reset path is to issue a KBC reset command to IO register 0x64. so it seems OS has no idea about power controller(chip), though for the platform of laptop seems power controller is happened to be a ACPI defined device EC, power control mostly is one of jobs of EC, but OS doesn't know that.
am I right for this point?
Re: [Qemu-devel] [PATCH][RFC v2 2/7] hw/power: add main power chip implementation
Quoted 7 lines · li guang
Quoted 5 lines · 在 2013-04-05五的 10:23 +0100,Peter Maydell写道:
QEMU is fundamentally modelling real hardware platforms, not abstract devices. You have to model a real power controller to at least some extent, because that's what guest OSes expect to be interacting with, and what device and board hardware models expect to be dealing with.
Quoted 6 lines
Hmm, let me see ...
but you know, in my mind OS mostly dose not care more about power controller, for example, if OS want to reset, it just issues a command or writes a special value to register in a chip(not power controller), like PC, one of reset path is to issue a KBC reset command to IO register0x64. so it seems OS has no idea about power controller(chip),
This is architecture specific, which is my point. You can provide generic mechanisms for making it easier to implement power control, but you have to be clear about what is generic (and optional) mechanism and what is board and hardware specific.
-- PMM
Re: [Qemu-devel] [PATCH][RFC v2 2/7] hw/power: add main power chip implementation
Quoted 15 lines · 在 2013-04-08一的 10:21 +0100,Peter Maydell写道:
Quoted 7 lines · li guang
Quoted 5 lines · 在 2013-04-05五的 10:23 +0100,Peter Maydell写道:
QEMU is fundamentally modelling real hardware platforms, not abstract devices. You have to model a real power controller to at least some extent, because that's what guest OSes expect to be interacting with, and what device and board hardware models expect to be dealing with.
Quoted 6 lines
Hmm, let me see ...
but you know, in my mind OS mostly dose not care more about power controller, for example, if OS want to reset, it just issues a command or writes a special value to register in a chip(not power controller), like PC, one of reset path is to issue a KBC reset command to IO register0x64. so it seems OS has no idea about power controller(chip),
Quoted 5 lines
This is architecture specific, which is my point. You can provide generic mechanisms for making it easier to implement power control, but you have to be clear about what is generic (and optional) mechanism and what is board and hardware specific.
The approach of power-control may be specific for architectures, but, I think the thought beneath is common, e.g. for some ARM and MIPS platforms, OS issue commands to a embedded controller's firmware, then this firmware will help to do the real power-control job( on/off, of course no suspend), and also, there are some platforms directly generate power signals on some specific GPIOs then, these signals via a power chip will affect other devices.
1. 2.
----- -----
| OS | | OS |
--+-- -----
|on/off |on/off
---------------------------------------------
| -----+----- -----+----- |
| | firmware | | GPIO | |
| -----+----- -----+----- |
---------+----------------- | | part 2
|on/off | |on/off |
+------+------+ | ----+----- |
| | | | |power chip| |
------ ----- ---- | ---------- |
| dev0 ||dev1 ||dev2| --------|on/off---
------ ----- ---- +------+------+
| | |
------ ----- ----
| dev0 ||dev1 ||dev2|
------ ----- ----so, in graph 1, firmware acts like the power chip and related gpios in graph 2, then, I boldly assume a conceptual power chip exist, it can either be part 2 of graph 1 or 2.
as you said, qemu should only model real hardware,
I am confused, can the demonstration above part 2 be consider a real hardware? but it does not have vendor and dev-id ... and it's not real hardware? but it dose work just same with real hardware.
Re: [Qemu-devel] [PATCH][RFC v2 2/7] hw/power: add main power chip implementation
Il 09/04/2013 10:14, li guang ha scritto:
Quoted 27 lines
The approach of power-control may be specific for architectures, but, I think the thought beneath is common, e.g. for some ARM and MIPS platforms, OS issue commands to a embedded controller's firmware, then this firmware will help to do the real power-control
job( on/off, of course no suspend), and also, there are some platforms directly generate power signals on some specific GPIOs then, these signals via a power chip will affect other devices.
1. 2.----- ----- | OS | | OS | --+-- ----- |on/off |on/off --------------------------------------------- | -----+----- -----+----- | | | firmware | | GPIO | | | -----+----- -----+----- | ---------+----------------- | | part 2 |on/off | |on/off | +------+------+ | ----+----- | | | | | |power chip| | ------ ----- ---- | ---------- | | dev0 ||dev1 ||dev2| --------|on/off--- ------ ----- ---- +------+------+ | | | ------ ----- ---- | dev0 ||dev1 ||dev2| ------ ----- ----
Quoted 3 lines
so, in graph 1, firmware acts like the power chip and related gpios in graph 2, then, I boldly assume a conceptual power chip exist, it can either be part 2 of graph 1 or 2.
But QEMU doesn't treat conceptual things as devices. It models them as APIs, such as the memory API or the one that I pointed out in my previous message.
Paolo
Quoted 5 lines
as you said, qemu should only model real hardware,
I am confused, can the demonstration above part 2 be consider a real hardware? but it does not have vendor and dev-id ... and it's not real hardware? but it dose work just same with real hardware.
RFC PATCH v2 3/7 vl: create power chip device
In reply to liguang--- vl.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
vl.c +4 -0
@@ -171,6 +171,8 @@ int main(int argc, char **argv)#include "ui/qemu-spice.h" #include "qapi/string-input-visitor.h" +#include "hw/power.h" +//#define DEBUG_NET //#define DEBUG_SLIRP
@@ -4295,6 +4297,8 @@ int main(int argc, char **argv, char **envp)qdev_machine_init (); +qdev_init_nofail (qdev_create (NULL ,TYPE_POWER_CHIP )); +QEMUMachineInitArgs args = { .ram_size = ram_size, .boot_device = (boot_devices[0] == '\0') ? machine->boot_order :
Signature · 1 line
1.7.2.5
Re: [Qemu-devel] [PATCH][RFC v2 3/7] vl: create power chip device
Il 05/04/2013 06:28, liguang ha scritto:
Quoted 19 lines
Signed-off-by liguang <[email protected]>--- vl.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)vl.c +2
-0@@ -171,6 +171,8 @@ int main(int argc, char **argv)#include "ui/qemu-spice.h" #include "qapi/string-input-visitor.h" +#include "hw/power.h" +//#define DEBUG_NET //#define DEBUG_SLIRP
vl.c int main(int argc, char **argv, char **envp) · line 4301
Quoted 5 lines
vl.c +2
-0@@ -4295,6 +4297,8 @@ int main(int argc, char **argv, char **envp)qdev_machine_init (); +qdev_init_nofail (qdev_create (NULL ,TYPE_POWER_CHIP )); +
You cannot just add a random device to the machine.
Perhaps what you want to do is define a QOM interface that some device in the machine will implement.
But right now this all seems very nebulous. Honestly, I read the patches and I have no idea _why_ you are doing this.
Paolo
Quoted 4 lines
vl.c +0
-0QEMUMachineInitArgs args = { .ram_size = ram_size, .boot_device = (boot_devices[0] == '\0') ? machine->boot_order :
Re: [Qemu-devel] [PATCH][RFC v2 3/7] vl: create power chip device
Quoted 28 lines · 在 2013-04-05五的 13:48 +0200,Paolo Bonzini写道:
Il 05/04/2013 06:28, liguang ha scritto:
Quoted 19 lines
Signed-off-by liguang <[email protected]>--- vl.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)vl.c +2
-0@@ -171,6 +171,8 @@ int main(int argc, char **argv)#include "ui/qemu-spice.h" #include "qapi/string-input-visitor.h" +#include "hw/power.h" +//#define DEBUG_NET //#define DEBUG_SLIRP vl.c int main(int argc, char **argv, char **envp) · line 4301
Quoted 5 lines
vl.c +2
-0@@ -4295,6 +4297,8 @@ int main(int argc, char **argv, char **envp)qdev_machine_init (); +qdev_init_nofail (qdev_create (NULL ,TYPE_POWER_CHIP )); +You cannot just add a random device to the machine.
Quoted 5 lines
Perhaps what you want to do is define a QOM interface that some device in the machine will implement.
But right now this all seems very nebulous. Honestly, I read the patches and I have no idea _why_ you are doing this.
In short, the purpose is to implement a power control process just like real world(hardware platform),
a power chip(controller) connect power signals to other devices, and devices can do power (on, off, ...) controlled by power chip(controller).
Is this reasonable?
Quoted 5 lines
Quoted 4 lines
vl.c +0
-0QEMUMachineInitArgs args = { .ram_size = ram_size, .boot_device = (boot_devices[0] == '\0') ? machine->boot_order :
Re: [Qemu-devel] [PATCH][RFC v2 3/7] vl: create power chip device
Il 08/04/2013 02:18, li guang ha scritto:
Quoted 6 lines
In short, the purpose is to implement a power control process just like real world(hardware platform),
a power chip(controller) connect power signals to other devices, and devices can do power (on, off, ...) controlled by power chip(controller).
Is this reasonable?
It may be reasonable, but it will be board-dependent. The meaning of "power on/power off" varies wildly depending on the kind of device, the platform, etc.
Similarly, "reset" is very different from a power cycle.
Are you trying to implement D-states?
Paolo
Re: [Qemu-devel] [PATCH][RFC v2 3/7] vl: create power chip device
Quoted 8 lines · 在 2013-04-08一的 11:53 +0200,Paolo Bonzini写道:
Il 08/04/2013 02:18, li guang ha scritto:
Quoted 6 lines
In short, the purpose is to implement a power control process just like real world(hardware platform),
a power chip(controller) connect power signals to other devices, and devices can do power (on, off, ...) controlled by power chip(controller).
Is this reasonable?
Quoted 7 lines
It may be reasonable, but it will be board-dependent. The meaning of "power on/power off" varies wildly depending on the kind of device, the platform, etc.
Similarly, "reset" is very different from a power cycle.
Are you trying to implement D-states?
Hmm ... maybe, but,
S-states may be more exactly,
S0 -> power on
S3 -> suspend
S5 -> power off
but that are conceptual,
actually, I just want centralize controlling of power state transition of whole emulated machine.
Re: [Qemu-devel] [PATCH][RFC v2 3/7] vl: create power chip device
Il 09/04/2013 09:34, li guang ha scritto:
Quoted 8 lines
Hmm ... maybe, but,
S-states may be more exactly,
S0 -> power on
S3 -> suspend
S5 -> power off
but that are conceptual,
actually, I just want centralize controlling of power state transition of whole emulated machine.
That is already there:
qemu_system_suspend_request, qemu_register_suspend_notifier
for S0->S3
qemu_system_wakeup_request, qemu_register_wakeup_notifier
for S3->S0
qemu_system_powerdown_request, qemu_register_powerdown_notifier
for Sx->S5
and the reset mechanism for S5->S0.
Most of these should only be used by one "power management device" on the board (e.g. the PIIX3 or ICH9 power management devices in hw/acpi/*) and distributed to the other devices via whatever buses exist on the real machine.
Paolo
Re: [Qemu-devel] [PATCH][RFC v2 3/7] vl: create power chip device
Quoted 15 lines · 在 2013-04-09二的 09:43 +0200,Paolo Bonzini写道:
Il 09/04/2013 09:34, li guang ha scritto:
Quoted 8 lines
Hmm ... maybe, but,
S-states may be more exactly,
S0 -> power on
S3 -> suspend
S5 -> power off
but that are conceptual,
actually, I just want centralize controlling of power state transition of whole emulated machine.That is already there:
qemu_system_suspend_request,qemu_register_suspend_notifier
forS0->S3
Quoted 7 lines
qemu_system_wakeup_request,qemu_register_wakeup_notifier
forS3->S0
qemu_system_powerdown_request,qemu_register_powerdown_notifier
forSx->S5and the reset mechanism for
S5->S0.
Yep, I'm trying to supersede these functions
by my power chip emulation.
Quoted 4 lines
Most of these should only be used by one "power management device" on the board (e.g. the PIIX3 or ICH9 power management devices in hw/acpi/*) and distributed to the other devices via whatever buses exist on the real machine.
Re: [Qemu-devel] [PATCH][RFC v2 3/7] vl: create power chip device
Il 09/04/2013 10:26, li guang ha scritto:
Quoted 6 lines
Quoted 6 lines
qemu_system_suspend_request,qemu_register_suspend_notifier
forS0->S3
qemu_system_wakeup_request,qemu_register_wakeup_notifier
forS3->S0
Quoted 7 lines
Quoted 4 lines
qemu_system_powerdown_request,qemu_register_powerdown_notifier
forSx->S5and the reset mechanism for
S5->S0.Yep, I'm trying to supersede these functions
by my power chip emulation.
Then I explained in my other message why this is wrong. The API may well be "bad" (if so, please explain why), but at least it is the right tool to model this. QEMU models abstract concepts (memory, timers, powerdown) with APIs, not with devices.
Paolo
Re: [Qemu-devel] [PATCH][RFC v2 3/7] vl: create power chip device
Quoted 12 lines · 在 2013-04-09二的 13:06 +0200,Paolo Bonzini写道:
Il 09/04/2013 10:26, li guang ha scritto:
Quoted 11 lines
Quoted 10 lines
qemu_system_suspend_request,qemu_register_suspend_notifier
forS0->S3
qemu_system_wakeup_request,qemu_register_wakeup_notifier
forS3->S0
qemu_system_powerdown_request,qemu_register_powerdown_notifier
forSx->S5and the reset mechanism for
S5->S0.
Quoted 8 lines
Quoted 2 lines
Yep, I'm trying to supersede these functions
by my power chip emulation.Then I explained in my other message why this is wrong. The API may well be "bad" (if so, please explain why), but at least it is the right tool to model this. QEMU models abstract concepts (memory, timers, powerdown) with APIs, not with devices.
It's probably not 'bad', just only not native, because real hardware does not do thing that way, and also, this power chip is not purely conceptual, it just try to integrate jobs of power control from different platform.
of course, I can model this power chip as real hardware which exists in specific platform.
can we just feel happy with current implementation and don't want to try other things? :-)
or do you consider this totally wrong for direction?
Re: [Qemu-devel] [PATCH][RFC v2 3/7] vl: create power chip device
Il 10/04/2013 02:09, li guang ha scritto:
Quoted 7 lines
Quoted 6 lines
Quoted 6 lines
Then I explained in my other message why this is wrong. The API may well be "bad" (if so, please explain why), but at least it is the right tool to model this. QEMU models abstract concepts (memory, timers, powerdown) with APIs, not with devices.
It's probably not 'bad', just only not native,
The point of having an API, instead of a device, is to do things in a way that works decently for both "sides" who use it: device models on one side, monitor and user interface on the other.
Quoted 1 line
because real hardware does not do thing that way
At some point you have to depart from real hardware, for example in the case of a disk a virtual machine will write to a file and not to a magnetic surface. We try to place APIs at the exact point where this separation happens. Are you saying our API is placed wrong? If so, where would you put it?
Quoted 3 lines
, and also, this power chip is not purely
conceptual, it just try to integrate jobs of power control from different platform.
That's the job of an API, not a device.
Quoted 2 lines
of course, I can model this power chip as real hardware which exists in specific platform.
What power chip do you have in mind, for example, in PCs? Can you point to the datasheet? Would an implementation of that device require changes to the API?
Quoted 3 lines
can we just feel happy with current implementation and don't want to try other things? :-)
or do you consider this totally wrong for direction?
Creating an abstract device that does not match real hardware is wrong.
Improving the API could be more interesting.
Paolo
Re: [Qemu-devel] [PATCH][RFC v2 3/7] vl: create power chip device
In reply to li guangAm 10.04.2013 02:09, schrieb li guang:
Quoted 22 lines · 在 2013-04-09二的 13:06 +0200,Paolo Bonzini写道:
Quoted 12 lines
Il 09/04/2013 10:26, li guang ha scritto:
Quoted 11 lines
Quoted 10 lines
qemu_system_suspend_request,qemu_register_suspend_notifier
forS0->S3
qemu_system_wakeup_request,qemu_register_wakeup_notifier
forS3->S0
qemu_system_powerdown_request,qemu_register_powerdown_notifier
forSx->S5and the reset mechanism for
S5->S0.Quoted 8 lines
Quoted 2 lines
Yep, I'm trying to supersede these functions
by my power chip emulation.Then I explained in my other message why this is wrong. The API may well be "bad" (if so, please explain why), but at least it is the right tool to model this. QEMU models abstract concepts (memory, timers, powerdown) with APIs, not with devices.
Quoted 6 lines
It's probably not 'bad', just only not native, because real hardware does not do thing that way, and also, this power chip is not purely conceptual, it just try to integrate jobs of power control from different platform.
of course, I can model this power chip as real hardware which exists in specific platform.
Li Guang, I think your problem is a conceptual one: QEMU does not do a system simulation, it does a system emulation. Thus if a chip is hidden from software and not directly accessed in terms of registers from guest software, then we don't model it as a device but call some API functions from where it is supposed to show effects (keyboard controller device MemoryRegionOps, TCG instruction, monitor command, ...).
Thus we are reluctant to accept a QOM Device that is neither exposed to the guest nor uses any QOM concepts like inheritance AFAICS. Especially when the advantage of doing so is not well explained.
Andreas
Quoted 3 lines
can we just feel happy with current implementation and don't want to try other things? :-)
or do you consider this totally wrong for direction?
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Re: [Qemu-devel] [PATCH][RFC v2 3/7] vl: create power chip device
Yes, you're right.
The motivation is I want to implement a device called EC which is a notion from laptop for QEMU, EC has some main functions, like keyboard, mouse, low-speed device control(I2C), special ACPI space,
i8042 and ps2 mouse has been done, power control
was left, so I tried to add this.
so, Andreas,
do you know this chip for laptop?
any suggestions for this?
Thanks!
2013/4/10 Andreas Färber <[email protected]>
Quoted 52 lines
Am 10.04.2013 02:09, schrieb li guang:
Quoted 22 lines · 在 2013-04-09二的 13:06 +0200,Paolo Bonzini写道:
Quoted 12 lines
Il 09/04/2013 10:26, li guang ha scritto:
Quoted 11 lines
Quoted 10 lines
qemu_system_suspend_request,qemu_register_suspend_notifier
forS0->S3
qemu_system_wakeup_request,qemu_register_wakeup_notifier
forS3->S0
qemu_system_powerdown_request,qemu_register_powerdown_notifier
forSx->S5and the reset mechanism for
S5->S0.Quoted 8 lines
Quoted 2 lines
Yep, I'm trying to supersede these functions
by my power chip emulation.Then I explained in my other message why this is wrong. The API may well be "bad" (if so, please explain why), but at least it is the right tool to model this. QEMU models abstract concepts (memory, timers, powerdown) with APIs, not with devices.
Quoted 6 lines
It's probably not 'bad', just only not native, because real hardware does not do thing that way, and also, this power chip is not purely conceptual, it just try to integrate jobs of power control from different platform.
of course, I can model this power chip as real hardware which exists in specific platform.Li Guang, I think your problem is a conceptual one: QEMU does not do a system simulation, it does a system emulation. Thus if a chip is hidden from software and not directly accessed in terms of registers from guest software, then we don't model it as a device but call some API functions from where it is supposed to show effects (keyboard controller device MemoryRegionOps, TCG instruction, monitor command, ...).
Thus we are reluctant to accept a QOM Device that is neither exposed to the guest nor uses any QOM concepts like inheritance AFAICS. Especially when the advantage of doing so is not well explained.
Andreas
Quoted 3 lines
can we just feel happy with current implementation and don't want to try other things? :-)
or do you consider this totally wrong for direction?--
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Signature · 2 lines
* Sidere mens eadem mutato*
Re: [Qemu-devel] [PATCH][RFC v2 3/7] vl: create power chip device
Il 10/04/2013 15:41, guang li ha scritto:
Quoted 7 lines
Yes, you're right.
The motivation is I want to implement a device called EC which is a notion from laptop for QEMU, EC has some main functions, like keyboard, mouse, low-speed device control(I2C), special ACPI space,
i8042 and ps2 mouse has been done, power control
was left, so I tried to add this.
Do you have a datasheet? Have you looked at hw/acpi/?
Paolo
Re: [Qemu-devel] [PATCH][RFC v2 3/7] vl: create power chip device
Quoted 11 lines · 在 2013-04-10三的 15:52 +0200,Paolo Bonzini写道:
Il 10/04/2013 15:41, guang li ha scritto:
Quoted 7 lines
Yes, you're right.
The motivation is I want to implement a device called EC which is a notion from laptop for QEMU, EC has some main functions, like keyboard, mouse, low-speed device control(I2C), special ACPI space,
i8042 and ps2 mouse has been done, power control
was left, so I tried to add this.Do you have a datasheet? Have you looked at hw/acpi/?
Oh, that's a tough question, maybe you can find some data-sheets of EC chip(WPCE775L, IT8718F, ...) at their official website.
I can send you an old data-sheet for IT8718F that download from website privately for avoiding possible business issues.
Yes, I read codes at hw/acpi,
but, I can't get indication for my question.
Paolo, Thanks!
Re: [Qemu-devel] [PATCH][RFC v2 3/7] vl: create power chip device
In reply to Paolo BonziniQuoted 10 lines · Paolo Bonzini
Il 10/04/2013 15:41, guang li ha scritto:
Quoted 7 lines
Yes, you're right.
The motivation is I want to implement a device called EC which is a notion from laptop for QEMU, EC has some main functions, like keyboard, mouse, low-speed device control(I2C), special ACPI space,
i8042 and ps2 mouse has been done, power control
was left, so I tried to add this.Do you have a datasheet? Have you looked at hw/acpi/?
http://www.coreboot.org/Embedded_controller
Has more than you probably ever wanted to know about ECs.
I don't see much reason to model an EC in QEMU. It's only visible to firmware (at least on the PC) so there's little benefit to modeling.
Regards,
Anthony Liguori
Quoted 2 lines
Paolo
Re: [Qemu-devel] [PATCH][RFC v2 3/7] vl: create power chip device
Quoted 11 lines · 在 2013-04-16二的 15:45 -0500,Anthony Liguori写道:
Quoted 9 lines · Paolo Bonzini
Il 10/04/2013 15:41, guang li ha scritto:
Quoted 7 lines
Yes, you're right.
The motivation is I want to implement a device called EC which is a notion from laptop for QEMU, EC has some main functions, like keyboard, mouse, low-speed device control(I2C), special ACPI space,
i8042 and ps2 mouse has been done, power control
was left, so I tried to add this.
Quoted 8 lines
Quoted 1 line
Do you have a datasheet? Have you looked at hw/acpi/?
http://www.coreboot.org/Embedded_controller
Has more than you probably ever wanted to know about ECs.
I don't see much reason to model an EC in QEMU. It's only visible to firmware (at least on the PC)
No, it's certainly visible to OS.
you can get more from coreboot source code.
Quoted 1 line
so there's little benefit to modeling.
but it is very important to laptop.
Quoted 8 lines
Regards,
Anthony Liguori
Quoted 2 lines
Paolo
RFC PATCH v2 4/7 sysemu: remove PowerReason in sysemu.h
In reply to liguang--- include/sysemu/sysemu.h | 7 +------ 1 files changed, 1 insertions(+), 6 deletions(-)
include/sysemu/sysemu.h +1 -6
@@ -9,6 +9,7 @@#include "qapi-types.h" #include "qemu/notify.h" #include "qemu/main-loop.h" +#include "hw/power.h" /* vl.c */
@@ -37,12 +38,6 @@ void vm_start(void);void vm_stop (RunState state);void vm_stop_force_state (RunState state); -typedef enum WakeupReason { -QEMU_WAKEUP_REASON_OTHER =0 , -QEMU_WAKEUP_REASON_RTC , -QEMU_WAKEUP_REASON_PMTIMER , -}WakeupReason ; -void qemu_system_reset_request (void );void qemu_system_suspend_request (void );void qemu_register_suspend_notifier (Notifier *notifier);
Signature · 1 line
1.7.2.5
RFC PATCH v2 5/7 qdev: add power_signal_in for DeviceState
In reply to liguangso, devices can connect power signal with power chip
--- hw/qdev-core.h | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
hw/qdev-core.h +1 -0
@@ -121,6 +121,7 @@ struct DeviceState {qemu_irq *gpio_out;int num_gpio_in;qemu_irq *gpio_in; +qemu_irq *power_signal_in; QLIST_HEAD(, BusState) child_bus;int num_child_bus;int instance_id_alias;
Signature · 1 line
1.7.2.5
RFC PATCH v2 6/7 ich9: refactor wakeup/reset function
In reply to liguangrealize wakeup function for ICH9-LPC device
--- hw/acpi.c | 20 +++++++++----------- hw/acpi.h | 3 ++- hw/acpi_ich9.c | 2 +- hw/ich9.h | 2 ++ hw/lpc_ich9.c | 31 ++++++++++++++++++++++++++++++- 5 files changed, 44 insertions(+), 14 deletions(-)
hw/acpi.c +9 -11
@@ -241,12 +241,11 @@ int acpi_table_add(const char *t) } -static void acpi_notify_wakeup (Notifier *notifier,void *data) +void acpi_power_wakeup (ACPIREGS *ar) { -ACPIREGS *ar =container_of (notifier,ACPIREGS , wakeup); -WakeupReason *reason = data; +WakeupReason reason =power_management_wakeup_reason (); -switch (*reason) { +switch (reason) {case QEMU_WAKEUP_REASON_RTC : ar->pm1.evt.sts |= (ACPI_BITMASK_WAKE_STATUS |ACPI_BITMASK_RT_CLOCK_STATUS );
@@ -288,9 +287,9 @@ static void acpi_pm1_evt_write_sts(ACPIREGS *ar, uint16_t val)static void acpi_pm1_evt_write_en (ACPIREGS *ar,uint16_t val) { ar->pm1.evt.en = val; -qemu_system_wakeup_enable (QEMU_WAKEUP_REASON_RTC , +power_management_wakeup_capability (QEMU_WAKEUP_REASON_RTC , val &ACPI_BITMASK_RT_CLOCK_ENABLE ); -qemu_system_wakeup_enable (QEMU_WAKEUP_REASON_PMTIMER , +power_management_wakeup_capability (QEMU_WAKEUP_REASON_PMTIMER , val &ACPI_BITMASK_TIMER_ENABLE ); }
@@ -306,8 +305,8 @@ void acpi_pm1_evt_reset(ACPIREGS *ar) { ar->pm1.evt.sts =0 ; ar->pm1.evt.en =0 ; -qemu_system_wakeup_enable (QEMU_WAKEUP_REASON_RTC ,0 ); -qemu_system_wakeup_enable (QEMU_WAKEUP_REASON_PMTIMER ,0 ); +power_management_wakeup_capability (QEMU_WAKEUP_REASON_RTC , false); +power_management_wakeup_capability (QEMU_WAKEUP_REASON_PMTIMER , false); }static uint64_t acpi_pm_evt_read (void *opaque,hwaddr addr,unsigned width)
@@ -385,7 +384,8 @@ static uint32_t acpi_pm_tmr_get(ACPIREGS *ar)static void acpi_pm_tmr_timer (void *opaque) {ACPIREGS *ar = opaque; -qemu_system_wakeup_request (QEMU_WAKEUP_REASON_PMTIMER ); +power_management_wakeup_reason_set (QEMU_WAKEUP_REASON_PMTIMER ); +power_management_set (POWER_WAKEUP ); ar->tmr.update_sci (ar); }
@@ -474,8 +474,6 @@ static const MemoryRegionOps acpi_pm_cnt_ops = {void acpi_pm1_cnt_init (ACPIREGS *ar,MemoryRegion *parent) { - ar->wakeup.notify = acpi_notify_wakeup; -qemu_register_wakeup_notifier (&ar->wakeup);memory_region_init_io (&ar->pm1.cnt.io, &acpi_pm_cnt_ops, ar,"acpi-cnt" ,2 );memory_region_add_subregion (parent,4 , &ar->pm1.cnt.io); }
hw/acpi.h +2 -1
@@ -117,7 +117,6 @@ struct ACPIREGS {ACPIPM1EVT evt;ACPIPM1CNT cnt; } pm1; -Notifier wakeup; };/* PM_TMR */
@@ -154,4 +153,6 @@ void acpi_gpe_reset(ACPIREGS *ar);void acpi_gpe_ioport_writeb (ACPIREGS *ar,uint32_t addr,uint32_t val);uint32_t acpi_gpe_ioport_readb (ACPIREGS *ar,uint32_t addr); +void acpi_power_wakeup (ACPIREGS *ar); +#endif /* !QEMU_HW_ACPI_H */
hw/acpi_ich9.c +1 -1
@@ -176,7 +176,7 @@ const VMStateDescription vmstate_ich9_pm = { } }; -static void pm_reset (void *opaque) +void pm_reset (void *opaque) {ICH9LPCPMRegs *pm = opaque;ich9_pm_iospace_update (pm,0 );
hw/ich9.h +2 -0
@@ -22,6 +22,7 @@ PCIINTxRoute ich9_route_intx_pin_to_irq(void *opaque, int pirq_pin);void ich9_lpc_pm_init (PCIDevice *pci_lpc,qemu_irq cmos_s3);PCIBus *ich9_d2pbr_init (PCIBus *bus,int devfn,int sec_bus);i2c_bus *ich9_smb_init (PCIBus *bus,int devfn,uint32_t smb_io_base); +void pm_reset (void *opaque);#define ICH9_CC_SIZE (16 * 1024)/* 16KB */
@@ -30,6 +31,7 @@ i2c_bus *ich9_smb_init(PCIBus *bus, int devfn, uint32_t smb_io_base); OBJECT_CHECK(ICH9LPCState, (obj), TYPE_ICH9_LPC_DEVICE) typedef struct ICH9LPCState { + DeviceState qdev; /* ICH9 LPC PCI to ISA bridge */ PCIDevice d;
hw/lpc_ich9.c +30 -1
@@ -467,6 +467,8 @@ static void ich9_lpc_reset(DeviceState *qdev) lpc->sci_level =0 ; lpc->rst_cnt =0 ; + +pm_reset (&lpc->pm); }static const MemoryRegionOps rbca_mmio_ops = {
@@ -525,11 +527,39 @@ static const MemoryRegionOps ich9_rst_cnt_ops = { .endianness = DEVICE_LITTLE_ENDIAN }; +static void ich9_lpc_wakeup (DeviceState *dev) +{ +ICH9LPCState *lpc =ICH9_LPC_DEVICE (PCI_DEVICE (dev)); + +acpi_power_wakeup (&lpc->pm.acpi_regs); +} + +static void ich9_lpc_powr_management (void *opaque,int n,int l) +{ +DeviceState *qdev = opaque; + +switch (power_state ()) { +case POWER_WAKEUP : +ich9_lpc_wakeup (qdev); +break ; +case POWER_RESET : +case POWER_ON : +ich9_lpc_reset (qdev); +break ; +case POWER_OFF : +default : +break ; + } +} +static int ich9_lpc_initfn (PCIDevice *d) {ICH9LPCState *lpc =ICH9_LPC_DEVICE (d);ISABus *isa_bus; + lpc->qdev.power_signal_in =qemu_allocate_irqs (ich9_lpc_powr_management, + d,1 ); +connect_power_signal (lpc->qdev.power_signal_in); isa_bus =isa_bus_new (&d->qdev,get_system_io ()); pci_set_long(d->wmask + ICH9_LPC_PMBASE,
@@ -610,7 +640,6 @@ static void ich9_lpc_class_init(ObjectClass *klass, void *data) k->device_id =PCI_DEVICE_ID_INTEL_ICH9_8 ; k->revision =ICH9_A2_LPC_REVISION ; k->class_id =PCI_CLASS_BRIDGE_ISA ; - }static const TypeInfo ich9_lpc_info = {
Signature · 1 line
1.7.2.5
RFC PATCH v2 7/7 vl: run power_management
In reply to liguangrun power_management temporarily,
later, if this approach is accepted,
will try to replace main_loop_should_exit()
--- vl.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
vl.c +1 -0
@@ -2041,6 +2041,7 @@ static void main_loop(void)#ifdef CONFIG_PROFILER dev_time +=profile_getclock () - ti;#endif +power_management (); }while (!main_loop_should_exit ()); }
Signature · 1 line
1.7.2.5