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" 6506f1f495SSalil Mehta #include "hw/acpi/cpu.h" 66db1015e9SEduardo Habkost #include "qom/object.h" 67ebb62075SSamuel Ortiz 681962f31bSShameer Kolothum #define ACPI_POWER_BUTTON_DEVICE "PWRB" 691962f31bSShameer Kolothum 70ebb62075SSamuel Ortiz #define TYPE_ACPI_GED "acpi-ged" 718063396bSEduardo Habkost OBJECT_DECLARE_SIMPLE_TYPE(AcpiGedState, ACPI_GED) 72ebb62075SSamuel Ortiz 73ebb62075SSamuel Ortiz #define ACPI_GED_EVT_SEL_OFFSET 0x0 74ebb62075SSamuel Ortiz #define ACPI_GED_EVT_SEL_LEN 0x4 75ebb62075SSamuel Ortiz 7614404dd2SGerd Hoffmann #define ACPI_GED_REG_SLEEP_CTL 0x00 7714404dd2SGerd Hoffmann #define ACPI_GED_REG_SLEEP_STS 0x01 7814404dd2SGerd Hoffmann #define ACPI_GED_REG_RESET 0x02 7914404dd2SGerd Hoffmann #define ACPI_GED_REG_COUNT 0x03 8014404dd2SGerd Hoffmann 8114404dd2SGerd Hoffmann /* ACPI_GED_REG_RESET value for reset*/ 8214404dd2SGerd Hoffmann #define ACPI_GED_RESET_VALUE 0x42 8314404dd2SGerd Hoffmann 84*edafc90bSBibo Mao /* [ACPI 5.0 Chapter 4.8.3.7] Sleep Control and Status Register */ 85*edafc90bSBibo Mao #define ACPI_GED_SLP_TYP_POS 0x2 /* SLP_TYPx Bit Offset */ 86*edafc90bSBibo Mao #define ACPI_GED_SLP_TYP_MASK 0x07 /* SLP_TYPx 3-bit mask */ 87*edafc90bSBibo Mao #define ACPI_GED_SLP_TYP_S5 0x05 /* System _S5 State (Soft Off) */ 88*edafc90bSBibo Mao #define ACPI_GED_SLP_EN 0x20 /* SLP_EN write-only bit */ 8914404dd2SGerd Hoffmann 90ebb62075SSamuel Ortiz #define GED_DEVICE "GED" 91ebb62075SSamuel Ortiz #define AML_GED_EVT_REG "EREG" 92ebb62075SSamuel Ortiz #define AML_GED_EVT_SEL "ESEL" 93549c9a9dSSalil Mehta #define AML_GED_EVT_CPU_SCAN_METHOD "\\_SB.GED.CSCN" 94ebb62075SSamuel Ortiz 95ebb62075SSamuel Ortiz /* 96ebb62075SSamuel Ortiz * Platforms need to specify the GED event bitmap 97ebb62075SSamuel Ortiz * to describe what kind of events they want to support 98ebb62075SSamuel Ortiz * through GED. 99ebb62075SSamuel Ortiz */ 100ebb62075SSamuel Ortiz #define ACPI_GED_MEM_HOTPLUG_EVT 0x1 1011962f31bSShameer Kolothum #define ACPI_GED_PWR_DOWN_EVT 0x2 102c2505d1cSShameer Kolothum #define ACPI_GED_NVDIMM_HOTPLUG_EVT 0x4 10306f1f495SSalil Mehta #define ACPI_GED_CPU_HOTPLUG_EVT 0x8 104ebb62075SSamuel Ortiz 105ebb62075SSamuel Ortiz typedef struct GEDState { 10632905fc9SGerd Hoffmann MemoryRegion evt; 10714404dd2SGerd Hoffmann MemoryRegion regs; 108ebb62075SSamuel Ortiz uint32_t sel; 109ebb62075SSamuel Ortiz } GEDState; 110ebb62075SSamuel Ortiz 111db1015e9SEduardo Habkost struct AcpiGedState { 112ebb62075SSamuel Ortiz SysBusDevice parent_obj; 113ebb62075SSamuel Ortiz MemHotplugState memhp_state; 114ebb62075SSamuel Ortiz MemoryRegion container_memhp; 11506f1f495SSalil Mehta CPUHotplugState cpuhp_state; 11606f1f495SSalil Mehta MemoryRegion container_cpuhp; 117ebb62075SSamuel Ortiz GEDState ged_state; 118ebb62075SSamuel Ortiz uint32_t ged_event_bitmap; 119ebb62075SSamuel Ortiz qemu_irq irq; 120a08a6462SDongjiu Geng AcpiGhesState ghes_state; 121db1015e9SEduardo Habkost }; 122ebb62075SSamuel Ortiz 123ebb62075SSamuel Ortiz void build_ged_aml(Aml *table, const char* name, HotplugHandler *hotplug_dev, 124ebb62075SSamuel Ortiz uint32_t ged_irq, AmlRegionSpace rs, hwaddr ged_base); 1257bf2567cSGerd Hoffmann void acpi_dsdt_add_power_button(Aml *scope); 126ebb62075SSamuel Ortiz 127ebb62075SSamuel Ortiz #endif 128