qemu/include/hw/acpi/acpi.h
<<
>>
Prefs
   1#ifndef QEMU_HW_ACPI_H
   2#define QEMU_HW_ACPI_H
   3
   4/*
   5 *  Copyright (c) 2009 Isaku Yamahata <yamahata at valinux co jp>
   6 *                     VA Linux Systems Japan K.K.
   7 *
   8 * This library is free software; you can redistribute it and/or
   9 * modify it under the terms of the GNU Lesser General Public
  10 * License as published by the Free Software Foundation; either
  11 * version 2 of the License, or (at your option) any later version.
  12 *
  13 * This library is distributed in the hope that it will be useful,
  14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16 * Lesser General Public License for more details.
  17 *
  18 * You should have received a copy of the GNU Lesser General Public
  19 * License along with this library; if not, see
  20 * <http://www.gnu.org/licenses/>.
  21 */
  22
  23#include "qemu/notify.h"
  24#include "exec/memory.h"
  25#include "hw/acpi/acpi_dev_interface.h"
  26
  27/*
  28 * current device naming scheme supports up to 256 memory devices
  29 */
  30#define ACPI_MAX_RAM_SLOTS 256
  31
  32/* from linux include/acpi/actype.h */
  33/* Default ACPI register widths */
  34
  35#define ACPI_GPE_REGISTER_WIDTH         8
  36#define ACPI_PM1_REGISTER_WIDTH         16
  37#define ACPI_PM2_REGISTER_WIDTH         8
  38#define ACPI_PM_TIMER_WIDTH             32
  39
  40/* PC-style peripherals (also used by other machines).  */
  41#define ACPI_PM_PROP_S3_DISABLED "disable_s3"
  42#define ACPI_PM_PROP_S4_DISABLED "disable_s4"
  43#define ACPI_PM_PROP_S4_VAL "s4_val"
  44#define ACPI_PM_PROP_SCI_INT "sci_int"
  45#define ACPI_PM_PROP_ACPI_ENABLE_CMD "acpi_enable_cmd"
  46#define ACPI_PM_PROP_ACPI_DISABLE_CMD "acpi_disable_cmd"
  47#define ACPI_PM_PROP_PM_IO_BASE "pm_io_base"
  48#define ACPI_PM_PROP_GPE0_BLK "gpe0_blk"
  49#define ACPI_PM_PROP_GPE0_BLK_LEN "gpe0_blk_len"
  50
  51/* PM Timer ticks per second (HZ) */
  52#define PM_TIMER_FREQUENCY  3579545
  53
  54
  55/* ACPI fixed hardware registers */
  56
  57/* from linux/drivers/acpi/acpica/aclocal.h */
  58/* Masks used to access the bit_registers */
  59
  60/* PM1x_STS */
  61#define ACPI_BITMASK_TIMER_STATUS               0x0001
  62#define ACPI_BITMASK_BUS_MASTER_STATUS          0x0010
  63#define ACPI_BITMASK_GLOBAL_LOCK_STATUS         0x0020
  64#define ACPI_BITMASK_POWER_BUTTON_STATUS        0x0100
  65#define ACPI_BITMASK_SLEEP_BUTTON_STATUS        0x0200
  66#define ACPI_BITMASK_RT_CLOCK_STATUS            0x0400
  67#define ACPI_BITMASK_PCIEXP_WAKE_STATUS         0x4000  /* ACPI 3.0 */
  68#define ACPI_BITMASK_WAKE_STATUS                0x8000
  69
  70#define ACPI_BITMASK_ALL_FIXED_STATUS           (\
  71        ACPI_BITMASK_TIMER_STATUS          | \
  72        ACPI_BITMASK_BUS_MASTER_STATUS     | \
  73        ACPI_BITMASK_GLOBAL_LOCK_STATUS    | \
  74        ACPI_BITMASK_POWER_BUTTON_STATUS   | \
  75        ACPI_BITMASK_SLEEP_BUTTON_STATUS   | \
  76        ACPI_BITMASK_RT_CLOCK_STATUS       | \
  77        ACPI_BITMASK_WAKE_STATUS)
  78
  79/* PM1x_EN */
  80#define ACPI_BITMASK_TIMER_ENABLE               0x0001
  81#define ACPI_BITMASK_GLOBAL_LOCK_ENABLE         0x0020
  82#define ACPI_BITMASK_POWER_BUTTON_ENABLE        0x0100
  83#define ACPI_BITMASK_SLEEP_BUTTON_ENABLE        0x0200
  84#define ACPI_BITMASK_RT_CLOCK_ENABLE            0x0400
  85#define ACPI_BITMASK_PCIEXP_WAKE_DISABLE        0x4000  /* ACPI 3.0 */
  86
  87#define ACPI_BITMASK_PM1_COMMON_ENABLED         ( \
  88        ACPI_BITMASK_RT_CLOCK_ENABLE        | \
  89        ACPI_BITMASK_POWER_BUTTON_ENABLE    | \
  90        ACPI_BITMASK_GLOBAL_LOCK_ENABLE     | \
  91        ACPI_BITMASK_TIMER_ENABLE)
  92
  93/* PM1x_CNT */
  94#define ACPI_BITMASK_SCI_ENABLE                 0x0001
  95#define ACPI_BITMASK_BUS_MASTER_RLD             0x0002
  96#define ACPI_BITMASK_GLOBAL_LOCK_RELEASE        0x0004
  97#define ACPI_BITMASK_SLEEP_TYPE                 0x1C00
  98#define ACPI_BITMASK_SLEEP_ENABLE               0x2000
  99
 100/* PM2_CNT */
 101#define ACPI_BITMASK_ARB_DISABLE                0x0001
 102
 103/* structs */
 104typedef struct ACPIPMTimer ACPIPMTimer;
 105typedef struct ACPIPM1EVT ACPIPM1EVT;
 106typedef struct ACPIPM1CNT ACPIPM1CNT;
 107typedef struct ACPIGPE ACPIGPE;
 108typedef struct ACPIREGS ACPIREGS;
 109
 110typedef void (*acpi_update_sci_fn)(ACPIREGS *ar);
 111
 112struct ACPIPMTimer {
 113    QEMUTimer *timer;
 114    MemoryRegion io;
 115    int64_t overflow_time;
 116
 117    acpi_update_sci_fn update_sci;
 118};
 119
 120struct ACPIPM1EVT {
 121    MemoryRegion io;
 122    uint16_t sts;
 123    uint16_t en;
 124    acpi_update_sci_fn update_sci;
 125};
 126
 127struct ACPIPM1CNT {
 128    MemoryRegion io;
 129    uint16_t cnt;
 130    uint8_t s4_val;
 131};
 132
 133struct ACPIGPE {
 134    uint8_t len;
 135
 136    uint8_t *sts;
 137    uint8_t *en;
 138};
 139
 140struct ACPIREGS {
 141    ACPIPMTimer     tmr;
 142    ACPIGPE         gpe;
 143    struct {
 144        ACPIPM1EVT  evt;
 145        ACPIPM1CNT  cnt;
 146    } pm1;
 147    Notifier wakeup;
 148};
 149
 150/* PM_TMR */
 151void acpi_pm_tmr_update(ACPIREGS *ar, bool enable);
 152void acpi_pm_tmr_calc_overflow_time(ACPIREGS *ar);
 153void acpi_pm_tmr_init(ACPIREGS *ar, acpi_update_sci_fn update_sci,
 154                      MemoryRegion *parent);
 155void acpi_pm_tmr_reset(ACPIREGS *ar);
 156
 157/* PM1a_EVT: piix and ich9 don't implement PM1b. */
 158uint16_t acpi_pm1_evt_get_sts(ACPIREGS *ar);
 159void acpi_pm1_evt_power_down(ACPIREGS *ar);
 160void acpi_pm1_evt_reset(ACPIREGS *ar);
 161void acpi_pm1_evt_init(ACPIREGS *ar, acpi_update_sci_fn update_sci,
 162                       MemoryRegion *parent);
 163
 164/* PM1a_CNT: piix and ich9 don't implement PM1b CNT. */
 165void acpi_pm1_cnt_init(ACPIREGS *ar, MemoryRegion *parent,
 166                       bool disable_s3, bool disable_s4, uint8_t s4_val);
 167void acpi_pm1_cnt_update(ACPIREGS *ar,
 168                         bool sci_enable, bool sci_disable);
 169void acpi_pm1_cnt_reset(ACPIREGS *ar);
 170
 171/* GPE0 */
 172void acpi_gpe_init(ACPIREGS *ar, uint8_t len);
 173void acpi_gpe_reset(ACPIREGS *ar);
 174
 175void acpi_gpe_ioport_writeb(ACPIREGS *ar, uint32_t addr, uint32_t val);
 176uint32_t acpi_gpe_ioport_readb(ACPIREGS *ar, uint32_t addr);
 177
 178void acpi_send_gpe_event(ACPIREGS *ar, qemu_irq irq,
 179                         AcpiEventStatusBits status);
 180
 181void acpi_update_sci(ACPIREGS *acpi_regs, qemu_irq irq);
 182
 183/* acpi.c */
 184extern int acpi_enabled;
 185extern char unsigned *acpi_tables;
 186extern size_t acpi_tables_len;
 187
 188uint8_t *acpi_table_first(void);
 189uint8_t *acpi_table_next(uint8_t *current);
 190unsigned acpi_table_len(void *current);
 191void acpi_table_add(const QemuOpts *opts, Error **errp);
 192
 193typedef struct AcpiSlicOem AcpiSlicOem;
 194struct AcpiSlicOem {
 195  char *id;
 196  char *table_id;
 197};
 198int acpi_get_slic_oem(AcpiSlicOem *oem);
 199
 200#endif /* QEMU_HW_ACPI_H */
 201