2 Copyright (C) 2017, The AROS Development Team. All rights reserved.
7 #include <aros/debug.h>
9 #include <proto/utility.h>
12 #include <utility/tagitem.h>
14 #include "acpibutton_intern.h"
16 struct ACPIButton_ServiceTask
18 struct Task
*acpist_Task
;
24 struct ACPIButton_ServiceTask acpiButton_Service
;
26 CONST_STRPTR acpiPowerButton_str
= "ACPI Power Button Device";
27 CONST_STRPTR acpiFPowerButton_str
= "ACPI Fixed Power Button Device";
28 CONST_STRPTR acpiSleepButton_str
= "ACPI Sleep Button Device";
29 CONST_STRPTR acpiFSleepButton_str
= "ACPI Fixed Sleep Button Device";
30 CONST_STRPTR acpiLidButton_str
= "ACPI Lid Device";
32 CONST_STRPTR acpiButton_str
= "ACPI Button Device";
33 CONST_STRPTR acpiFButton_str
= "ACPI Fixed Button Device";
35 void ACPIButtonServiceTask(struct ExecBase
*SysBase
)
39 D(bug("[ACPI:Button] %s()\n", __func__
));
41 acpiButton_Service
.acpist_SigPower
= AllocSignal(-1);
42 acpiButton_Service
.acpist_SigSleep
= AllocSignal(-1);
43 acpiButton_Service
.acpist_SigLid
= AllocSignal(-1);
45 while (signals
= Wait((1 << acpiButton_Service
.acpist_SigPower
) | (1 << acpiButton_Service
.acpist_SigSleep
) | (1 << acpiButton_Service
.acpist_SigLid
)))
47 if (signals
& (1 << acpiButton_Service
.acpist_SigPower
))
49 D(bug("[ACPI:Button] %s: Power Button Signal Received..\n", __func__
));
50 ShutdownA(SD_ACTION_POWEROFF
);
52 else if (signals
& (1 << acpiButton_Service
.acpist_SigSleep
))
54 D(bug("[ACPI:Button] %s: Sleep Button Signal Received..\n", __func__
));
56 else if (signals
& (1 << acpiButton_Service
.acpist_SigLid
))
58 D(bug("[ACPI:Button] %s: Lid Signal Received..\n", __func__
));
63 void ACPIButton_ButtonNotifyHandler(ACPI_HANDLE acpiDevice
, UINT32 acpiEvent
, void *acpiContext
)
65 OOP_Object
*o
= (OOP_Object
*)acpiContext
;
67 D(bug("[ACPI:Button] %s()\n", __func__
));
68 D(bug("[ACPI:Button] %s: Device 0x%p, Event %08x\n", __func__
, acpiDevice
, acpiEvent
));
72 struct Hook
*buttonHook
= NULL
;
75 D(bug("[ACPI:Button] %s: OOP_Object @ 0x%p\n", __func__
, o
));
79 OOP_GetAttr(o
, aHW_ACPIButton_Hook
, (IPTR
*)&buttonHook
);
84 bug("[ACPI:Button] %s: Calling Object Hook @ 0x%p\n", __func__
, buttonHook
);
85 bug("[ACPI:Button] %s: Func @ 0x%p\n", __func__
, buttonHook
->h_Entry
);
87 buttonHook
->h_Data
= (void *)(IPTR
)acpiEvent
;
88 CALLHOOKPKT(buttonHook
, o
, (void *)acpiDevice
);
93 ACPI_STATUS
ACPIButton_FixedButtonNotifyHandler(void *acpiContext
)
95 D(bug("[ACPI:Button] %s()\n", __func__
));
98 return AE_BAD_PARAMETER
;
100 ACPIButton_ButtonNotifyHandler(NULL
, ACPI_EVENT_TYPE_FIXED
, acpiContext
);
106 OOP_Object
*ACPIButton__Root__New(OOP_Class
*cl
, OOP_Object
*o
, struct pRoot_New
*msg
)
108 struct pRoot_New acpiNewButtonMsg
;
109 ULONG acpiButtonEvent
= ACPI_EVENT_GLOBAL
;
110 struct Library
*UtilityBase
= CSD(cl
)->cs_UtilityBase
;
111 ULONG buttonType
= (ULONG
)GetTagData(aHW_ACPIButton_Type
, 0, msg
->attrList
);
112 struct Hook
*buttonHook
= (struct Hook
*)GetTagData(aHW_ACPIButton_Hook
, 0, msg
->attrList
);
113 ACPI_HANDLE acpiHandle
= (ACPI_HANDLE
)GetTagData(aHW_ACPIButton_Handle
, 0, msg
->attrList
);
114 OOP_Object
**buttonO
= NULL
;
115 BOOL buttonFixed
= FALSE
;
116 CONST_STRPTR deviceName
;
117 __unused CONST_STRPTR deviceClass
;
119 D(bug("[ACPI:Button] %s()\n", __func__
));
123 case vHW_ACPIButton_PowerF
:
124 acpiButtonEvent
= ACPI_EVENT_POWER_BUTTON
;
126 deviceName
= acpiFPowerButton_str
;
127 deviceClass
= acpiFButton_str
;
128 case vHW_ACPIButton_Power
:
129 buttonO
= &CSD(cl
)->powerButtonObj
;
130 if (acpiButtonEvent
!= ACPI_EVENT_POWER_BUTTON
)
132 deviceName
= acpiPowerButton_str
;
133 deviceClass
= acpiButton_str
;
134 acpiButtonEvent
= ACPI_DEVICE_NOTIFY
;
138 case vHW_ACPIButton_SleepF
:
139 acpiButtonEvent
= ACPI_EVENT_SLEEP_BUTTON
;
141 deviceName
= acpiFSleepButton_str
;
142 deviceClass
= acpiFButton_str
;
143 case vHW_ACPIButton_Sleep
:
144 buttonO
= &CSD(cl
)->sleepButtonObj
;
145 if (acpiButtonEvent
!= ACPI_EVENT_SLEEP_BUTTON
)
147 deviceName
= acpiSleepButton_str
;
148 deviceClass
= acpiButton_str
;
149 acpiButtonEvent
= ACPI_DEVICE_NOTIFY
;
153 case vHW_ACPIButton_Lid
:
154 buttonO
= &CSD(cl
)->lidButtonObj
;
155 acpiButtonEvent
= ACPI_DEVICE_NOTIFY
;
156 deviceName
= acpiLidButton_str
;
157 deviceClass
= acpiButton_str
;
161 D(bug("[ACPI:Button] %s: Unhandled button type %d\n", __func__
, buttonType
));
169 struct TagItem new_tags
[] =
171 { aHidd_Name
, (IPTR
)"acpibutton.hidd" },
172 { aHidd_HardwareName
, (IPTR
)deviceName
},
175 acpiNewButtonMsg
.mID
= msg
->mID
,
176 acpiNewButtonMsg
.attrList
= new_tags
;
180 new_tags
[2].ti_Tag
= TAG_MORE
;
181 new_tags
[2].ti_Data
= (IPTR
)msg
->attrList
;
184 D(bug("[ACPI:Button] %s: ACPI Handle @ 0x%p\n", __func__
, acpiHandle
));
186 if ((*buttonO
= (OOP_Object
*)OOP_DoSuperMethod(cl
, o
, &acpiNewButtonMsg
.mID
)) != NULL
)
188 struct HWACPIButtonData
*data
= OOP_INST_DATA(cl
, *buttonO
);
189 data
->acpib_Type
= buttonType
;
190 data
->acpib_Handle
= acpiHandle
;
191 data
->acpib_Hook
= buttonHook
;
193 D(bug("[ACPI:Button] %s: Object @ 0x%p\n", __func__
, *buttonO
));
195 if (!acpiButton_Service
.acpist_Task
)
197 acpiButton_Service
.acpist_Task
= NewCreateTask(TASKTAG_NAME
, "ACPI Button Service Task",
199 #if defined(__AROSEXEC_SMP__)
200 TASKTAG_AFFINITY
, TASKAFFINITY_ANY
,
202 TASKTAG_PC
, ACPIButtonServiceTask
,
203 TASKTAG_ARG1
, SysBase
,
208 AcpiInstallFixedEventHandler(acpiButtonEvent
, ACPIButton_FixedButtonNotifyHandler
, *buttonO
);
210 AcpiInstallNotifyHandler(acpiHandle
, acpiButtonEvent
, ACPIButton_ButtonNotifyHandler
, *buttonO
);
219 VOID
ACPIButton__Root__Dispose(OOP_Class
*cl
, OOP_Object
*o
, OOP_Msg msg
)
221 D(bug("[ACPI:Button] %s()\n", __func__
));
223 /* We are singletone. Cannot dispose. */
227 VOID
ACPIButton__Root__Get(OOP_Class
*cl
, OOP_Object
*o
, struct pRoot_Get
*msg
)
229 struct HWACPIButtonData
*data
= OOP_INST_DATA(cl
, o
);
232 D(bug("[ACPI:Button] %s()\n", __func__
));
234 HW_ACPIButton_Switch(msg
->attrID
, idx
)
236 case aoHW_ACPIButton_Type
:
237 *msg
->storage
= (IPTR
)data
->acpib_Type
;
240 case aoHW_ACPIButton_Handle
:
241 *msg
->storage
= (IPTR
)data
->acpib_Handle
;
244 case aoHW_ACPIButton_Hook
:
245 *msg
->storage
= (IPTR
)data
->acpib_Hook
;
248 case aoHW_ACPIButton_ServiceTask
:
249 *msg
->storage
= (IPTR
)acpiButton_Service
.acpist_Task
;
252 case aoHW_ACPIButton_ServiceSigPower
:
253 *msg
->storage
= (IPTR
)acpiButton_Service
.acpist_SigPower
;
256 case aoHW_ACPIButton_ServiceSigSleep
:
257 *msg
->storage
= (IPTR
)acpiButton_Service
.acpist_SigSleep
;
260 case aoHW_ACPIButton_ServiceSigLid
:
261 *msg
->storage
= (IPTR
)acpiButton_Service
.acpist_SigLid
;
266 OOP_DoSuperMethod(cl
, o
, &msg
->mID
);