xref: /qemu/include/hw/acpi/generic_event_device.h (revision c9c8ba69)
1ebb62075SSamuel Ortiz /*
2ebb62075SSamuel Ortiz  *
3ebb62075SSamuel Ortiz  * Copyright (c) 2018 Intel Corporation
4ebb62075SSamuel Ortiz  * Copyright (c) 2019 Huawei Technologies R & D (UK) Ltd
5ebb62075SSamuel Ortiz  * Written by Samuel Ortiz, Shameer Kolothum
6ebb62075SSamuel Ortiz  *
7ebb62075SSamuel Ortiz  * This program is free software; you can redistribute it and/or modify it
8ebb62075SSamuel Ortiz  * under the terms and conditions of the GNU General Public License,
9ebb62075SSamuel Ortiz  * version 2 or later, as published by the Free Software Foundation.
10ebb62075SSamuel Ortiz  *
11ebb62075SSamuel Ortiz  * The ACPI Generic Event Device (GED) is a hardware-reduced specific
12ebb62075SSamuel Ortiz  * device[ACPI v6.1 Section 5.6.9] that handles all platform events,
13ebb62075SSamuel Ortiz  * including the hotplug ones. Generic Event Device allows platforms
14ebb62075SSamuel Ortiz  * to handle interrupts in ACPI ASL statements. It follows a very
15ebb62075SSamuel Ortiz  * similar approach like the _EVT method from GPIO events. All
16ebb62075SSamuel Ortiz  * interrupts are listed in  _CRS and the handler is written in _EVT
17ebb62075SSamuel Ortiz  * method. Here, we use a single interrupt for the GED device, relying
18ebb62075SSamuel Ortiz  * on IO memory region to communicate the type of device affected by
19ebb62075SSamuel Ortiz  * the interrupt. This way, we can support up to 32 events with a
20ebb62075SSamuel Ortiz  * unique interrupt.
21ebb62075SSamuel Ortiz  *
22ebb62075SSamuel Ortiz  * Here is an example.
23ebb62075SSamuel Ortiz  *
24ebb62075SSamuel Ortiz  * Device (\_SB.GED)
25ebb62075SSamuel Ortiz  * {
26ebb62075SSamuel Ortiz  *     Name (_HID, "ACPI0013")
27ebb62075SSamuel Ortiz  *     Name (_UID, Zero)
28ebb62075SSamuel Ortiz  *     Name (_CRS, ResourceTemplate ()
29ebb62075SSamuel Ortiz  *     {
30ebb62075SSamuel Ortiz  *         Interrupt (ResourceConsumer, Edge, ActiveHigh, Exclusive, ,, )
31ebb62075SSamuel Ortiz  *         {
32ebb62075SSamuel Ortiz  *              0x00000029,
33ebb62075SSamuel Ortiz  *         }
34ebb62075SSamuel Ortiz  *     })
35ebb62075SSamuel Ortiz  *     OperationRegion (EREG, SystemMemory, 0x09080000, 0x04)
36ebb62075SSamuel Ortiz  *     Field (EREG, DWordAcc, NoLock, WriteAsZeros)
37ebb62075SSamuel Ortiz  *     {
38ebb62075SSamuel Ortiz  *         ESEL,   32
39ebb62075SSamuel Ortiz  *     }
40ebb62075SSamuel Ortiz  *
41ebb62075SSamuel Ortiz  *     Method (_EVT, 1, Serialized)  // _EVT: Event
42ebb62075SSamuel Ortiz  *     {
43ebb62075SSamuel Ortiz  *         Local0 = ESEL // ESEL = IO memory region which specifies the
44ebb62075SSamuel Ortiz  *                       // device type.
45ebb62075SSamuel Ortiz  *         If (((Local0 & One) == One))
46ebb62075SSamuel Ortiz  *         {
47ebb62075SSamuel Ortiz  *             MethodEvent1()
48ebb62075SSamuel Ortiz  *         }
49ebb62075SSamuel Ortiz  *         If ((Local0 & 0x2) == 0x2)
50ebb62075SSamuel Ortiz  *         {
51ebb62075SSamuel Ortiz  *             MethodEvent2()
52ebb62075SSamuel Ortiz  *         }
53ebb62075SSamuel Ortiz  *         ...
54ebb62075SSamuel Ortiz  *     }
55ebb62075SSamuel Ortiz  * }
56ebb62075SSamuel Ortiz  *
57ebb62075SSamuel Ortiz  */
58ebb62075SSamuel Ortiz 
5952581c71SMarkus Armbruster #ifndef HW_ACPI_GENERIC_EVENT_DEVICE_H
6052581c71SMarkus Armbruster #define HW_ACPI_GENERIC_EVENT_DEVICE_H
61ebb62075SSamuel Ortiz 
62ebb62075SSamuel Ortiz #include "hw/sysbus.h"
63ebb62075SSamuel Ortiz #include "hw/acpi/memory_hotplug.h"
64a08a6462SDongjiu Geng #include "hw/acpi/ghes.h"
65db1015e9SEduardo Habkost #include "qom/object.h"
66ebb62075SSamuel Ortiz 
671962f31bSShameer Kolothum #define ACPI_POWER_BUTTON_DEVICE "PWRB"
681962f31bSShameer Kolothum 
69ebb62075SSamuel Ortiz #define TYPE_ACPI_GED "acpi-ged"
708063396bSEduardo Habkost OBJECT_DECLARE_SIMPLE_TYPE(AcpiGedState, ACPI_GED)
71ebb62075SSamuel Ortiz 
72ebb62075SSamuel Ortiz #define ACPI_GED_EVT_SEL_OFFSET    0x0
73ebb62075SSamuel Ortiz #define ACPI_GED_EVT_SEL_LEN       0x4
74ebb62075SSamuel Ortiz 
7514404dd2SGerd Hoffmann #define ACPI_GED_REG_SLEEP_CTL     0x00
7614404dd2SGerd Hoffmann #define ACPI_GED_REG_SLEEP_STS     0x01
7714404dd2SGerd Hoffmann #define ACPI_GED_REG_RESET         0x02
7814404dd2SGerd Hoffmann #define ACPI_GED_REG_COUNT         0x03
7914404dd2SGerd Hoffmann 
8014404dd2SGerd Hoffmann /* ACPI_GED_REG_RESET value for reset*/
8114404dd2SGerd Hoffmann #define ACPI_GED_RESET_VALUE       0x42
8214404dd2SGerd Hoffmann 
8314404dd2SGerd Hoffmann /* ACPI_GED_REG_SLEEP_CTL.SLP_TYP value for S5 (aka poweroff) */
8414404dd2SGerd Hoffmann #define ACPI_GED_SLP_TYP_S5        0x05
8514404dd2SGerd Hoffmann 
86ebb62075SSamuel Ortiz #define GED_DEVICE      "GED"
87ebb62075SSamuel Ortiz #define AML_GED_EVT_REG "EREG"
88ebb62075SSamuel Ortiz #define AML_GED_EVT_SEL "ESEL"
89ebb62075SSamuel Ortiz 
90ebb62075SSamuel Ortiz /*
91ebb62075SSamuel Ortiz  * Platforms need to specify the GED event bitmap
92ebb62075SSamuel Ortiz  * to describe what kind of events they want to support
93ebb62075SSamuel Ortiz  * through GED.
94ebb62075SSamuel Ortiz  */
95ebb62075SSamuel Ortiz #define ACPI_GED_MEM_HOTPLUG_EVT   0x1
961962f31bSShameer Kolothum #define ACPI_GED_PWR_DOWN_EVT      0x2
97c2505d1cSShameer Kolothum #define ACPI_GED_NVDIMM_HOTPLUG_EVT 0x4
98ebb62075SSamuel Ortiz 
99ebb62075SSamuel Ortiz typedef struct GEDState {
10032905fc9SGerd Hoffmann     MemoryRegion evt;
10114404dd2SGerd Hoffmann     MemoryRegion regs;
102ebb62075SSamuel Ortiz     uint32_t     sel;
103ebb62075SSamuel Ortiz } GEDState;
104ebb62075SSamuel Ortiz 
105db1015e9SEduardo Habkost struct AcpiGedState {
106ebb62075SSamuel Ortiz     SysBusDevice parent_obj;
107ebb62075SSamuel Ortiz     MemHotplugState memhp_state;
108ebb62075SSamuel Ortiz     MemoryRegion container_memhp;
109ebb62075SSamuel Ortiz     GEDState ged_state;
110ebb62075SSamuel Ortiz     uint32_t ged_event_bitmap;
111ebb62075SSamuel Ortiz     qemu_irq irq;
112a08a6462SDongjiu Geng     AcpiGhesState ghes_state;
113db1015e9SEduardo Habkost };
114ebb62075SSamuel Ortiz 
115ebb62075SSamuel Ortiz void build_ged_aml(Aml *table, const char* name, HotplugHandler *hotplug_dev,
116ebb62075SSamuel Ortiz                    uint32_t ged_irq, AmlRegionSpace rs, hwaddr ged_base);
1177bf2567cSGerd Hoffmann void acpi_dsdt_add_power_button(Aml *scope);
118ebb62075SSamuel Ortiz 
119ebb62075SSamuel Ortiz #endif
120