From: "Michael S. Tsirkin" <mst@redhat.com>
To: Isaku Yamahata <yamahata@valinux.co.jp>
Cc: qemu-devel@nongnu.org
Subject: [Qemu-devel] Re: [PATCH V8 02/18] acpi: split out apm register emulation from acpi.c
Date: Mon, 7 Dec 2009 11:07:04 +0200 [thread overview]
Message-ID: <20091207090704.GA30817@redhat.com> (raw)
In-Reply-To: <1259905865-25295-3-git-send-email-yamahata@valinux.co.jp>
On Fri, Dec 04, 2009 at 02:50:49PM +0900, Isaku Yamahata wrote:
> Split out apm register emulation for acpi.c into pc_apm.c.
> The apm emulation will be used later.
>
> Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
I don't know much about acpi.
One general comment below.
> ---
> Makefile.target | 4 +-
> hw/acpi.c | 57 ++++++++++-------------------------
> hw/pc_apm.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
> hw/pc_apm.h | 43 ++++++++++++++++++++++++++
> 4 files changed, 150 insertions(+), 43 deletions(-)
> create mode 100644 hw/pc_apm.c
> create mode 100644 hw/pc_apm.h
>
> diff --git a/Makefile.target b/Makefile.target
> index acf8865..bbeef20 100644
> --- a/Makefile.target
> +++ b/Makefile.target
> @@ -195,7 +195,7 @@ obj-i386-y += cirrus_vga.o apic.o ioapic.o parallel.o acpi.o piix_pci.o
> obj-i386-y += usb-uhci.o vmmouse.o vmport.o vmware_vga.o hpet.o
> obj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o
> obj-i386-y += ne2000-isa.o
> -obj-i386-y += pc_smbus.o
> +obj-i386-y += pc_smbus.o pc_apm.o
>
> # shared objects
> obj-ppc-y = ppc.o ide/core.o ide/qdev.o ide/isa.o ide/pci.o ide/macio.o
> @@ -226,7 +226,7 @@ obj-mips-y += ide/core.o ide/qdev.o ide/isa.o ide/pci.o ide/piix.o
> obj-mips-y += gt64xxx.o pckbd.o fdc.o mc146818rtc.o usb-uhci.o acpi.o ds1225y.o
> obj-mips-y += piix4.o parallel.o cirrus_vga.o pcspk.o $(sound-obj-y)
> obj-mips-y += mipsnet.o ne2000-isa.o
> -obj-mips-y += pc_smbus.o
> +obj-mips-y += pc_smbus.o pc_apm.o
> obj-mips-y += pflash_cfi01.o
> obj-mips-y += vmware_vga.o
>
> diff --git a/hw/acpi.c b/hw/acpi.c
> index 6b030bb..b503b16 100644
> --- a/hw/acpi.c
> +++ b/hw/acpi.c
> @@ -17,6 +17,7 @@
> */
> #include "hw.h"
> #include "pc.h"
> +#include "pc_apm.h"
> #include "pc_smbus.h"
> #include "pci.h"
> #include "qemu-timer.h"
> @@ -37,8 +38,9 @@ typedef struct PIIX4PMState {
> uint16_t pmsts;
> uint16_t pmen;
> uint16_t pmcntrl;
> - uint8_t apmc;
> - uint8_t apms;
> +
> + APMState apm;
> +
> QEMUTimer *tmr_timer;
> int64_t tmr_overflow_time;
>
> @@ -217,46 +219,20 @@ static uint32_t pm_ioport_readl(void *opaque, uint32_t addr)
> return val;
> }
>
> -static void pm_smi_writeb(void *opaque, uint32_t addr, uint32_t val)
> +static void apm_ctrl_changed(uint32_t val, void *arg)
> {
> - PIIX4PMState *s = opaque;
> - addr &= 1;
> -#ifdef DEBUG
> - printf("pm_smi_writeb addr=0x%x val=0x%02x\n", addr, val);
> -#endif
> - if (addr == 0) {
> - s->apmc = val;
> -
> - /* ACPI specs 3.0, 4.7.2.5 */
> - if (val == ACPI_ENABLE) {
> - s->pmcntrl |= SCI_EN;
> - } else if (val == ACPI_DISABLE) {
> - s->pmcntrl &= ~SCI_EN;
> - }
> + PIIX4PMState *s = arg;
>
> - if (s->dev.config[0x5b] & (1 << 1)) {
> - cpu_interrupt(first_cpu, CPU_INTERRUPT_SMI);
> - }
> - } else {
> - s->apms = val;
> + /* ACPI specs 3.0, 4.7.2.5 */
> + if (val == ACPI_ENABLE) {
> + s->pmcntrl |= SCI_EN;
> + } else if (val == ACPI_DISABLE) {
> + s->pmcntrl &= ~SCI_EN;
> }
> -}
>
> -static uint32_t pm_smi_readb(void *opaque, uint32_t addr)
> -{
> - PIIX4PMState *s = opaque;
> - uint32_t val;
> -
> - addr &= 1;
> - if (addr == 0) {
> - val = s->apmc;
> - } else {
> - val = s->apms;
> + if (s->dev.config[0x5b] & (1 << 1)) {
> + cpu_interrupt(first_cpu, CPU_INTERRUPT_SMI);
> }
> -#ifdef DEBUG
> - printf("pm_smi_readb addr=0x%x val=0x%02x\n", addr, val);
> -#endif
> - return val;
> }
>
> static void acpi_dbg_writel(void *opaque, uint32_t addr, uint32_t val)
> @@ -312,8 +288,7 @@ static const VMStateDescription vmstate_acpi = {
> VMSTATE_UINT16(pmsts, PIIX4PMState),
> VMSTATE_UINT16(pmen, PIIX4PMState),
> VMSTATE_UINT16(pmcntrl, PIIX4PMState),
> - VMSTATE_UINT8(apmc, PIIX4PMState),
> - VMSTATE_UINT8(apms, PIIX4PMState),
> + VMSTATE_STRUCT(apm, PIIX4PMState, 0, vmstate_pc_apm, APMState),
> VMSTATE_TIMER(tmr_timer, PIIX4PMState),
> VMSTATE_INT64(tmr_overflow_time, PIIX4PMState),
> VMSTATE_END_OF_LIST()
> @@ -373,8 +348,8 @@ i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
>
> pci_conf[0x40] = 0x01; /* PM io base read only bit */
>
> - register_ioport_write(0xb2, 2, 1, pm_smi_writeb, s);
> - register_ioport_read(0xb2, 2, 1, pm_smi_readb, s);
> + /* APM */
> + apm_init(&s->apm, apm_ctrl_changed, s);
>
> register_ioport_write(ACPI_DBG_IO_ADDR, 4, 4, acpi_dbg_writel, s);
>
> diff --git a/hw/pc_apm.c b/hw/pc_apm.c
> new file mode 100644
> index 0000000..730a576
> --- /dev/null
> +++ b/hw/pc_apm.c
> @@ -0,0 +1,89 @@
> +/*
> + * QEMU PC APM controller Emulation
> + *
> + * Copyright (c) 2009 Isaku Yamahata <yamahata at valinux co jp>
> + * VA Linux Systems Japan K.K.
> + *
> + * This is split out from acpi.c
If all you did was rearrange routines, it seems
wrong to remove Fabrice's copyright and replace
with your own.
> + *
> + * This library is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2 of the License, or (at your option) any later version.
> + *
> + * This library is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with this library; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA
> + */
> +
> +#include "pc_apm.h"
> +#include "hw.h"
> +#include "isa.h"
> +
> +//#define DEBUG
> +
> +/* fixed I/O location */
> +#define APM_CNT_IOPORT 0xb2
> +#define APM_STS_IOPORT 0xb3
> +
> +static void apm_ioport_writeb(void *opaque, uint32_t addr, uint32_t val)
> +{
> + APMState *apm = opaque;
> + addr &= 1;
> +#ifdef DEBUG
> + printf("apm_ioport_writeb addr=0x%x val=0x%02x\n", addr, val);
> +#endif
> + if (addr == 0) {
> + apm->apmc = val;
> +
> + if (apm->callback) {
> + (apm->callback)(val, apm->arg);
> + }
> + } else {
> + apm->apms = val;
> + }
> +}
> +
> +static uint32_t apm_ioport_readb(void *opaque, uint32_t addr)
> +{
> + APMState *apm = opaque;
> + uint32_t val;
> +
> + addr &= 1;
> + if (addr == 0) {
> + val = apm->apmc;
> + } else {
> + val = apm->apms;
> + }
> +#ifdef DEBUG
> + printf("apm_ioport_readb addr=0x%x val=0x%02x\n", addr, val);
> +#endif
> + return val;
> +}
> +
> +const VMStateDescription vmstate_pc_apm = {
> + .name = "PC APM State",
> + .version_id = 1,
> + .minimum_version_id = 1,
> + .minimum_version_id_old = 1,
> + .fields = (VMStateField[]) {
> + VMSTATE_UINT8(apmc, APMState),
> + VMSTATE_UINT8(apms, APMState),
> + VMSTATE_END_OF_LIST()
> + }
> +};
> +
> +void apm_init(APMState *apm, apm_ctrl_changed_t callback, void *arg)
> +{
> + apm->callback = callback;
> + apm->arg = arg;
> +
> + /* ioport 0xb2, 0xb3 */
> + register_ioport_write(APM_CNT_IOPORT, 2, 1, apm_ioport_writeb, apm);
> + register_ioport_read(APM_CNT_IOPORT, 2, 1, apm_ioport_readb, apm);
> +}
> diff --git a/hw/pc_apm.h b/hw/pc_apm.h
> new file mode 100644
> index 0000000..f7fab33
> --- /dev/null
> +++ b/hw/pc_apm.h
> @@ -0,0 +1,43 @@
> +/*
> + * QEMU PC APM controller Emulation
> + *
> + * Copyright (c) 2009 Isaku Yamahata <yamahata at valinux co jp>
> + * VA Linux Systems Japan K.K.
> + *
> + * This library is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2 of the License, or (at your option) any later version.
> + *
> + * This library is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with this library; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA
> + */
> +
Let's not put copyright notices into headers, please.
This 20 line header is IMO ridiculous for 4 declarations,
and the real code is in .c anyway.
> +#ifndef PC_APM_H
> +#define PC_APM_H
> +
> +#include <stdint.h>
> +#include "qemu-common.h"
> +#include "hw.h"
> +
> +typedef void (*apm_ctrl_changed_t)(uint32_t val, void *arg);
> +
> +typedef struct APMState {
> + uint8_t apmc;
> + uint8_t apms;
> +
> + apm_ctrl_changed_t callback;
> + void *arg;
> +} APMState;
> +
> +void apm_init(APMState *s, apm_ctrl_changed_t callback, void *arg);
> +
> +extern const VMStateDescription vmstate_pc_apm;
> +
> +#endif /* PC_APM_H */
> --
> 1.6.5.4
>
>
next prev parent reply other threads:[~2009-12-07 9:09 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-12-04 5:50 [Qemu-devel] [PATCH V8 00/18] split out piix specific part from pc emulator Isaku Yamahata
2009-12-04 5:50 ` [Qemu-devel] [PATCH V8 01/18] acpi: split out pc smbus routines from acpi.c into pc_smbus.c Isaku Yamahata
2009-12-04 5:50 ` [Qemu-devel] [PATCH V8 02/18] acpi: split out apm register emulation from acpi.c Isaku Yamahata
2009-12-07 9:07 ` Michael S. Tsirkin [this message]
2009-12-04 5:50 ` [Qemu-devel] [PATCH V8 03/18] acpi: add acpi constants from linux header files and use them Isaku Yamahata
2009-12-04 5:50 ` [Qemu-devel] [PATCH V8 04/18] acpi: split acpi.c into the common part and the piix4 part Isaku Yamahata
2009-12-04 5:50 ` [Qemu-devel] [PATCH V8 05/18] acpi_piix4: remove unused variable in get_pmsts() Isaku Yamahata
2009-12-04 5:50 ` [Qemu-devel] [PATCH V8 06/18] pc, i440fx: Make smm enable/disable function i440fx independent Isaku Yamahata
2009-12-04 5:50 ` [Qemu-devel] [PATCH V8 07/18] pc: make an unnecessary global variable, pit, local Isaku Yamahata
2009-12-04 5:50 ` [Qemu-devel] [PATCH V8 08/18] pc: remove a global variable, floppy_controller Isaku Yamahata
2009-12-04 5:50 ` [Qemu-devel] [PATCH V8 09/18] pc: remove a global variable, RTCState *rtc_state Isaku Yamahata
2009-12-07 9:15 ` Gerd Hoffmann
2009-12-09 2:44 ` Isaku Yamahata
2009-12-04 5:50 ` [Qemu-devel] [PATCH V8 10/18] pc: introduce a function to allocate cpu irq Isaku Yamahata
2009-12-04 5:50 ` [Qemu-devel] [PATCH V8 11/18] pc: make pc_init1() not refer ferr_irq directly Isaku Yamahata
2009-12-04 5:50 ` [Qemu-devel] [PATCH V8 12/18] pc: split out cpu initialization from pc_init1() into pc_cpus_init() Isaku Yamahata
2009-12-04 5:51 ` [Qemu-devel] [PATCH V8 13/18] pc: split out memory allocation from pc_init1() into pc_memory_init() Isaku Yamahata
2009-12-04 5:51 ` [Qemu-devel] [PATCH V8 14/18] pc: split out vga initialization from pc_init1() into pc_vga_init() Isaku Yamahata
2009-12-04 5:51 ` [Qemu-devel] [PATCH V8 15/18] pc: split out basic device init from pc_init1() into pc_basic_device_init() Isaku Yamahata
2009-12-04 5:51 ` [Qemu-devel] [PATCH V8 16/18] pc: split out pci device init from pc_init1() into pc_pci_device_init() Isaku Yamahata
2009-12-04 5:51 ` [Qemu-devel] [PATCH V8 17/18] pc: split out piix specific part from pc.c into pc_piix.c Isaku Yamahata
2009-12-04 5:51 ` [Qemu-devel] [PATCH V8 18/18] pc_piix: initialize ioapic before use Isaku Yamahata
2009-12-07 9:23 ` Gerd Hoffmann
2009-12-04 14:09 ` [Qemu-devel] [PATCH V8 00/18] split out piix specific part from pc emulator Anthony Liguori
2009-12-05 0:20 ` Isaku Yamahata
2009-12-07 9:40 ` Gerd Hoffmann
2009-12-07 9:07 ` [Qemu-devel] " Michael S. Tsirkin
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=20091207090704.GA30817@redhat.com \
--to=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=yamahata@valinux.co.jp \
/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.