@@ -112,6 +112,12 @@ ACPI_MODULE_NAME("ASUS-WMI")
112
112
#define ASUS_WMI_DSTS_BRIGHTNESS_MASK 0x000000FF
113
113
#define ASUS_WMI_DSTS_MAX_BRIGTH_MASK 0x0000FF00
114
114
115
+ /* Events */
116
+ #define ASUS_WMI_EVENT_QUEUE_SIZE 0x10
117
+ #define ASUS_WMI_EVENT_QUEUE_END 0x1
118
+ #define ASUS_WMI_EVENT_MASK 0xFFFF
119
+ #define ASUS_WMI_EVENT_VALUE_ATK 0xFF
120
+
115
121
struct acpi_asus_wmi_softc {
116
122
device_t dev ;
117
123
device_t wmi_dev ;
@@ -120,6 +126,7 @@ struct acpi_asus_wmi_softc {
120
126
struct sysctl_oid * sysctl_tree ;
121
127
int dsts_id ;
122
128
int handle_keys ;
129
+ bool event_queue ;
123
130
struct cdev * kbd_bkl ;
124
131
uint32_t kbd_bkl_level ;
125
132
#ifdef EVDEV_SUPPORT
@@ -363,6 +370,8 @@ static int acpi_wpi_asus_get_devstate(struct acpi_asus_wmi_softc *sc,
363
370
UINT32 dev_id , UINT32 * retval );
364
371
static int acpi_wpi_asus_set_devstate (struct acpi_asus_wmi_softc * sc ,
365
372
UINT32 dev_id , UINT32 ctrl_param , UINT32 * retval );
373
+ static int acpi_asus_wmi_get_event_code (device_t wmi_dev , UINT32 notify ,
374
+ int * code );
366
375
static void acpi_asus_wmi_notify (ACPI_HANDLE h , UINT32 notify , void * context );
367
376
static int acpi_asus_wmi_backlight_update_status (device_t dev ,
368
377
struct backlight_props * props );
@@ -463,7 +472,7 @@ acpi_asus_wmi_attach(device_t dev)
463
472
{
464
473
struct acpi_asus_wmi_softc * sc ;
465
474
UINT32 val ;
466
- int dev_id , i ;
475
+ int dev_id , i , code ;
467
476
bool have_kbd_bkl = false;
468
477
469
478
ACPI_FUNCTION_TRACE ((char * )(uintptr_t ) __func__ );
@@ -577,6 +586,23 @@ acpi_asus_wmi_attach(device_t dev)
577
586
}
578
587
ACPI_SERIAL_END (asus_wmi );
579
588
589
+ /* Detect and flush event queue */
590
+ if (sc -> dsts_id == ASUS_WMI_METHODID_DSTS2 ) {
591
+ for (i = 0 ; i <= ASUS_WMI_EVENT_QUEUE_SIZE ; i ++ ) {
592
+ if (acpi_asus_wmi_get_event_code (sc -> wmi_dev ,
593
+ ASUS_WMI_EVENT_VALUE_ATK , & code ) != 0 ) {
594
+ device_printf (dev ,
595
+ "Can not flush event queue\n" );
596
+ break ;
597
+ }
598
+ if (code == ASUS_WMI_EVENT_QUEUE_END ||
599
+ code == ASUS_WMI_EVENT_MASK ) {
600
+ sc -> event_queue = true;
601
+ break ;
602
+ }
603
+ }
604
+ }
605
+
580
606
#ifdef EVDEV_SUPPORT
581
607
if (sc -> notify_guid != NULL ) {
582
608
sc -> evdev = evdev_alloc ();
@@ -746,6 +772,24 @@ acpi_asus_wmi_free_buffer(ACPI_BUFFER* buf) {
746
772
}
747
773
}
748
774
775
+ static int
776
+ acpi_asus_wmi_get_event_code (device_t wmi_dev , UINT32 notify , int * code )
777
+ {
778
+ ACPI_BUFFER response = { ACPI_ALLOCATE_BUFFER , NULL };
779
+ ACPI_OBJECT * obj ;
780
+ int error = 0 ;
781
+
782
+ if (ACPI_FAILURE (ACPI_WMI_GET_EVENT_DATA (wmi_dev , notify , & response )))
783
+ return (EIO );
784
+ obj = (ACPI_OBJECT * ) response .Pointer ;
785
+ if (obj && obj -> Type == ACPI_TYPE_INTEGER )
786
+ * code = obj -> Integer .Value & ASUS_WMI_EVENT_MASK ;
787
+ else
788
+ error = EINVAL ;
789
+ acpi_asus_wmi_free_buffer (& response );
790
+ return (error );
791
+ }
792
+
749
793
#ifdef EVDEV_SUPPORT
750
794
static void
751
795
acpi_asus_wmi_push_evdev_event (struct evdev_dev * evdev , UINT32 notify )
@@ -768,20 +812,11 @@ acpi_asus_wmi_push_evdev_event(struct evdev_dev *evdev, UINT32 notify)
768
812
#endif
769
813
770
814
static void
771
- acpi_asus_wmi_notify ( ACPI_HANDLE h , UINT32 notify , void * context )
815
+ acpi_asus_wmi_handle_event ( struct acpi_asus_wmi_softc * sc , int code )
772
816
{
773
- device_t dev = context ;
774
- ACPI_FUNCTION_TRACE_U32 ((char * )(uintptr_t )__func__ , notify );
775
817
UINT32 val ;
776
- int code = 0 ;
777
818
778
- struct acpi_asus_wmi_softc * sc = device_get_softc (dev );
779
- ACPI_BUFFER response = { ACPI_ALLOCATE_BUFFER , NULL };
780
- ACPI_OBJECT * obj ;
781
- ACPI_WMI_GET_EVENT_DATA (sc -> wmi_dev , notify , & response );
782
- obj = (ACPI_OBJECT * ) response .Pointer ;
783
- if (obj && obj -> Type == ACPI_TYPE_INTEGER ) {
784
- code = obj -> Integer .Value ;
819
+ if (code != 0 ) {
785
820
acpi_UserNotify ("ASUS" , ACPI_ROOT_OBJECT ,
786
821
code );
787
822
#ifdef EVDEV_SUPPORT
@@ -814,7 +849,35 @@ acpi_asus_wmi_notify(ACPI_HANDLE h, UINT32 notify, void *context)
814
849
ASUS_WMI_DEVID_TOUCHPAD , val , NULL );
815
850
}
816
851
}
817
- acpi_asus_wmi_free_buffer (& response );
852
+ }
853
+
854
+ static void
855
+ acpi_asus_wmi_notify (ACPI_HANDLE h , UINT32 notify , void * context )
856
+ {
857
+ device_t dev = context ;
858
+ struct acpi_asus_wmi_softc * sc = device_get_softc (dev );
859
+ int code = 0 , i = 1 ;
860
+
861
+ ACPI_FUNCTION_TRACE_U32 ((char * )(uintptr_t )__func__ , notify );
862
+
863
+ if (sc -> event_queue )
864
+ i += ASUS_WMI_EVENT_QUEUE_SIZE ;
865
+ do {
866
+ if (acpi_asus_wmi_get_event_code (sc -> wmi_dev , notify , & code )
867
+ != 0 ) {
868
+ device_printf (dev , "Failed to get event code\n" );
869
+ return ;
870
+ }
871
+ if (code == ASUS_WMI_EVENT_QUEUE_END ||
872
+ code == ASUS_WMI_EVENT_MASK )
873
+ return ;
874
+ acpi_asus_wmi_handle_event (sc , code );
875
+ if (notify != ASUS_WMI_EVENT_VALUE_ATK )
876
+ return ;
877
+ } while (-- i != 0 );
878
+ if (sc -> event_queue )
879
+ device_printf (dev , "Can not read event queue, "
880
+ "last code: 0x%x\n" , code );
818
881
}
819
882
820
883
static int
0 commit comments