2010-05-14 09:29:00 +02:00
|
|
|
/*
|
|
|
|
* QEMU PC APM controller Emulation
|
|
|
|
* This is split out from acpi.c
|
|
|
|
*
|
|
|
|
* Copyright (c) 2006 Fabrice Bellard
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* 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, see <http://www.gnu.org/licenses/>
|
2012-01-13 17:44:23 +01:00
|
|
|
*
|
|
|
|
* Contributions after 2012-01-13 are licensed under the terms of the
|
|
|
|
* GNU GPL, version 2 or (at your option) any later version.
|
2010-05-14 09:29:00 +02:00
|
|
|
*/
|
|
|
|
|
2016-01-26 19:17:30 +01:00
|
|
|
#include "qemu/osdep.h"
|
2013-02-05 17:06:20 +01:00
|
|
|
#include "hw/isa/apm.h"
|
2013-02-04 15:40:22 +01:00
|
|
|
#include "hw/hw.h"
|
|
|
|
#include "hw/pci/pci.h"
|
2010-05-14 09:29:00 +02:00
|
|
|
|
|
|
|
//#define DEBUG
|
|
|
|
|
2010-05-14 09:29:23 +02:00
|
|
|
#ifdef DEBUG
|
|
|
|
# define APM_DPRINTF(format, ...) printf(format, ## __VA_ARGS__)
|
|
|
|
#else
|
|
|
|
# define APM_DPRINTF(format, ...) do { } while (0)
|
|
|
|
#endif
|
|
|
|
|
2010-05-14 09:29:00 +02:00
|
|
|
/* fixed I/O location */
|
|
|
|
#define APM_CNT_IOPORT 0xb2
|
|
|
|
#define APM_STS_IOPORT 0xb3
|
|
|
|
|
2012-09-19 13:50:03 +02:00
|
|
|
static void apm_ioport_writeb(void *opaque, hwaddr addr, uint64_t val,
|
|
|
|
unsigned size)
|
2010-05-14 09:29:00 +02:00
|
|
|
{
|
|
|
|
APMState *apm = opaque;
|
|
|
|
addr &= 1;
|
Fix debug print warning
Steps:
1.enable qemu debug print, using simply scprit as below:
grep "//#define DEBUG" * -rl | xargs sed -i "s/\/\/#define DEBUG/#define DEBUG/g"
2. make -j
3. get some warning:
hw/i2c/pm_smbus.c: In function 'smb_ioport_writeb':
hw/i2c/pm_smbus.c:142: warning: format '%04x' expects type 'unsigned int', but argument 2 has type 'hwaddr'
hw/i2c/pm_smbus.c:142: warning: format '%02x' expects type 'unsigned int', but argument 3 has type 'uint64_t'
hw/i2c/pm_smbus.c: In function 'smb_ioport_readb':
hw/i2c/pm_smbus.c:209: warning: format '%04x' expects type 'unsigned int', but argument 2 has type 'hwaddr'
hw/intc/i8259.c: In function 'pic_ioport_read':
hw/intc/i8259.c:373: warning: format '%02x' expects type 'unsigned int', but argument 2 has type 'hwaddr'
hw/input/pckbd.c: In function 'kbd_write_command':
hw/input/pckbd.c:232: warning: format '%02x' expects type 'unsigned int', but argument 2 has type 'uint64_t'
hw/input/pckbd.c: In function 'kbd_write_data':
hw/input/pckbd.c:333: warning: format '%02x' expects type 'unsigned int', but argument 2 has type 'uint64_t'
hw/isa/apm.c: In function 'apm_ioport_writeb':
hw/isa/apm.c:44: warning: format '%x' expects type 'unsigned int', but argument 2 has type 'hwaddr'
hw/isa/apm.c:44: warning: format '%02x' expects type 'unsigned int', but argument 3 has type 'uint64_t'
hw/isa/apm.c: In function 'apm_ioport_readb':
hw/isa/apm.c:67: warning: format '%x' expects type 'unsigned int', but argument 2 has type 'hwaddr'
hw/timer/mc146818rtc.c: In function 'cmos_ioport_write':
hw/timer/mc146818rtc.c:394: warning: format '%02x' expects type 'unsigned int', but argument 3 has type 'uint64_t'
hw/i386/pc.c: In function 'port92_write':
hw/i386/pc.c:479: warning: format '%02x' expects type 'unsigned int', but argument 2 has type 'uint64_t'
Fix them.
Cc: qemu-trivial@nongnu.org
Signed-off-by: Gonglei <arei.gonglei@huawei.com>
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
2014-08-25 04:01:27 +02:00
|
|
|
APM_DPRINTF("apm_ioport_writeb addr=0x%" HWADDR_PRIx
|
|
|
|
" val=0x%02" PRIx64 "\n", addr, val);
|
2010-05-14 09:29:00 +02:00
|
|
|
if (addr == 0) {
|
|
|
|
apm->apmc = val;
|
|
|
|
|
|
|
|
if (apm->callback) {
|
|
|
|
(apm->callback)(val, apm->arg);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
apm->apms = val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-19 13:50:03 +02:00
|
|
|
static uint64_t apm_ioport_readb(void *opaque, hwaddr addr, unsigned size)
|
2010-05-14 09:29:00 +02:00
|
|
|
{
|
|
|
|
APMState *apm = opaque;
|
|
|
|
uint32_t val;
|
|
|
|
|
|
|
|
addr &= 1;
|
|
|
|
if (addr == 0) {
|
|
|
|
val = apm->apmc;
|
|
|
|
} else {
|
|
|
|
val = apm->apms;
|
|
|
|
}
|
Fix debug print warning
Steps:
1.enable qemu debug print, using simply scprit as below:
grep "//#define DEBUG" * -rl | xargs sed -i "s/\/\/#define DEBUG/#define DEBUG/g"
2. make -j
3. get some warning:
hw/i2c/pm_smbus.c: In function 'smb_ioport_writeb':
hw/i2c/pm_smbus.c:142: warning: format '%04x' expects type 'unsigned int', but argument 2 has type 'hwaddr'
hw/i2c/pm_smbus.c:142: warning: format '%02x' expects type 'unsigned int', but argument 3 has type 'uint64_t'
hw/i2c/pm_smbus.c: In function 'smb_ioport_readb':
hw/i2c/pm_smbus.c:209: warning: format '%04x' expects type 'unsigned int', but argument 2 has type 'hwaddr'
hw/intc/i8259.c: In function 'pic_ioport_read':
hw/intc/i8259.c:373: warning: format '%02x' expects type 'unsigned int', but argument 2 has type 'hwaddr'
hw/input/pckbd.c: In function 'kbd_write_command':
hw/input/pckbd.c:232: warning: format '%02x' expects type 'unsigned int', but argument 2 has type 'uint64_t'
hw/input/pckbd.c: In function 'kbd_write_data':
hw/input/pckbd.c:333: warning: format '%02x' expects type 'unsigned int', but argument 2 has type 'uint64_t'
hw/isa/apm.c: In function 'apm_ioport_writeb':
hw/isa/apm.c:44: warning: format '%x' expects type 'unsigned int', but argument 2 has type 'hwaddr'
hw/isa/apm.c:44: warning: format '%02x' expects type 'unsigned int', but argument 3 has type 'uint64_t'
hw/isa/apm.c: In function 'apm_ioport_readb':
hw/isa/apm.c:67: warning: format '%x' expects type 'unsigned int', but argument 2 has type 'hwaddr'
hw/timer/mc146818rtc.c: In function 'cmos_ioport_write':
hw/timer/mc146818rtc.c:394: warning: format '%02x' expects type 'unsigned int', but argument 3 has type 'uint64_t'
hw/i386/pc.c: In function 'port92_write':
hw/i386/pc.c:479: warning: format '%02x' expects type 'unsigned int', but argument 2 has type 'uint64_t'
Fix them.
Cc: qemu-trivial@nongnu.org
Signed-off-by: Gonglei <arei.gonglei@huawei.com>
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
2014-08-25 04:01:27 +02:00
|
|
|
APM_DPRINTF("apm_ioport_readb addr=0x%" HWADDR_PRIx " val=0x%02x\n", addr, val);
|
2010-05-14 09:29:00 +02:00
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
const VMStateDescription vmstate_apm = {
|
|
|
|
.name = "APM State",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_UINT8(apmc, APMState),
|
|
|
|
VMSTATE_UINT8(apms, APMState),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-09-19 13:50:03 +02:00
|
|
|
static const MemoryRegionOps apm_ops = {
|
|
|
|
.read = apm_ioport_readb,
|
|
|
|
.write = apm_ioport_writeb,
|
|
|
|
.impl = {
|
|
|
|
.min_access_size = 1,
|
|
|
|
.max_access_size = 1,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
void apm_init(PCIDevice *dev, APMState *apm, apm_ctrl_changed_t callback,
|
|
|
|
void *arg)
|
2010-05-14 09:29:00 +02:00
|
|
|
{
|
|
|
|
apm->callback = callback;
|
|
|
|
apm->arg = arg;
|
|
|
|
|
|
|
|
/* ioport 0xb2, 0xb3 */
|
2013-06-07 03:25:08 +02:00
|
|
|
memory_region_init_io(&apm->io, OBJECT(dev), &apm_ops, apm, "apm-io", 2);
|
2012-09-19 13:50:03 +02:00
|
|
|
memory_region_add_subregion(pci_address_space_io(dev), APM_CNT_IOPORT,
|
|
|
|
&apm->io);
|
2010-05-14 09:29:00 +02:00
|
|
|
}
|