@@ -128,12 +128,13 @@ static int EC_FLAGS_SKIP_DSDT_SCAN; /* Not all BIOS survive early DSDT scan */
128128static int EC_FLAGS_CLEAR_ON_RESUME ; /* Needs acpi_ec_clear() on boot/resume */
129129
130130/* --------------------------------------------------------------------------
131- Transaction Management
132- -------------------------------------------------------------------------- */
131+ * Transaction Management
132+ * -------------------------------------------------------------------------- */
133133
134134static inline u8 acpi_ec_read_status (struct acpi_ec * ec )
135135{
136136 u8 x = inb (ec -> command_addr );
137+
137138 pr_debug ("EC_SC(R) = 0x%2.2x "
138139 "SCI_EVT=%d BURST=%d CMD=%d IBF=%d OBF=%d\n" ,
139140 x ,
@@ -148,6 +149,7 @@ static inline u8 acpi_ec_read_status(struct acpi_ec *ec)
148149static inline u8 acpi_ec_read_data (struct acpi_ec * ec )
149150{
150151 u8 x = inb (ec -> data_addr );
152+
151153 pr_debug ("EC_DATA(R) = 0x%2.2x\n" , x );
152154 return x ;
153155}
@@ -164,10 +166,32 @@ static inline void acpi_ec_write_data(struct acpi_ec *ec, u8 data)
164166 outb (data , ec -> data_addr );
165167}
166168
169+ #ifdef DEBUG
170+ static const char * acpi_ec_cmd_string (u8 cmd )
171+ {
172+ switch (cmd ) {
173+ case 0x80 :
174+ return "RD_EC" ;
175+ case 0x81 :
176+ return "WR_EC" ;
177+ case 0x82 :
178+ return "BE_EC" ;
179+ case 0x83 :
180+ return "BD_EC" ;
181+ case 0x84 :
182+ return "QR_EC" ;
183+ }
184+ return "UNKNOWN" ;
185+ }
186+ #else
187+ #define acpi_ec_cmd_string (cmd ) "UNDEF"
188+ #endif
189+
167190static int ec_transaction_completed (struct acpi_ec * ec )
168191{
169192 unsigned long flags ;
170193 int ret = 0 ;
194+
171195 spin_lock_irqsave (& ec -> lock , flags );
172196 if (ec -> curr && (ec -> curr -> flags & ACPI_EC_COMMAND_COMPLETE ))
173197 ret = 1 ;
@@ -181,7 +205,8 @@ static bool advance_transaction(struct acpi_ec *ec)
181205 u8 status ;
182206 bool wakeup = false;
183207
184- pr_debug ("===== %s =====\n" , in_interrupt () ? "IRQ" : "TASK" );
208+ pr_debug ("===== %s (%d) =====\n" ,
209+ in_interrupt () ? "IRQ" : "TASK" , smp_processor_id ());
185210 status = acpi_ec_read_status (ec );
186211 t = ec -> curr ;
187212 if (!t )
@@ -198,7 +223,8 @@ static bool advance_transaction(struct acpi_ec *ec)
198223 if (t -> rlen == t -> ri ) {
199224 t -> flags |= ACPI_EC_COMMAND_COMPLETE ;
200225 if (t -> command == ACPI_EC_COMMAND_QUERY )
201- pr_debug ("hardware QR_EC completion\n" );
226+ pr_debug ("***** Command(%s) hardware completion *****\n" ,
227+ acpi_ec_cmd_string (t -> command ));
202228 wakeup = true;
203229 }
204230 } else
@@ -221,7 +247,8 @@ static bool advance_transaction(struct acpi_ec *ec)
221247 t -> flags |= ACPI_EC_COMMAND_POLL ;
222248 t -> rdata [t -> ri ++ ] = 0x00 ;
223249 t -> flags |= ACPI_EC_COMMAND_COMPLETE ;
224- pr_debug ("software QR_EC completion\n" );
250+ pr_debug ("***** Command(%s) software completion *****\n" ,
251+ acpi_ec_cmd_string (t -> command ));
225252 wakeup = true;
226253 } else if ((status & ACPI_EC_FLAG_IBF ) == 0 ) {
227254 acpi_ec_write_cmd (ec , t -> command );
@@ -264,6 +291,7 @@ static int ec_poll(struct acpi_ec *ec)
264291{
265292 unsigned long flags ;
266293 int repeat = 5 ; /* number of command restarts */
294+
267295 while (repeat -- ) {
268296 unsigned long delay = jiffies +
269297 msecs_to_jiffies (ec_delay );
@@ -296,18 +324,25 @@ static int acpi_ec_transaction_unlocked(struct acpi_ec *ec,
296324{
297325 unsigned long tmp ;
298326 int ret = 0 ;
327+
299328 if (EC_FLAGS_MSI )
300329 udelay (ACPI_EC_MSI_UDELAY );
301330 /* start transaction */
302331 spin_lock_irqsave (& ec -> lock , tmp );
303332 /* following two actions should be kept atomic */
304333 ec -> curr = t ;
334+ pr_debug ("***** Command(%s) started *****\n" ,
335+ acpi_ec_cmd_string (t -> command ));
305336 start_transaction (ec );
306337 spin_unlock_irqrestore (& ec -> lock , tmp );
307338 ret = ec_poll (ec );
308339 spin_lock_irqsave (& ec -> lock , tmp );
309- if (ec -> curr -> command == ACPI_EC_COMMAND_QUERY )
340+ if (ec -> curr -> command == ACPI_EC_COMMAND_QUERY ) {
310341 clear_bit (EC_FLAGS_QUERY_PENDING , & ec -> flags );
342+ pr_debug ("***** Event stopped *****\n" );
343+ }
344+ pr_debug ("***** Command(%s) stopped *****\n" ,
345+ acpi_ec_cmd_string (t -> command ));
311346 ec -> curr = NULL ;
312347 spin_unlock_irqrestore (& ec -> lock , tmp );
313348 return ret ;
@@ -317,6 +352,7 @@ static int acpi_ec_transaction(struct acpi_ec *ec, struct transaction *t)
317352{
318353 int status ;
319354 u32 glk ;
355+
320356 if (!ec || (!t ) || (t -> wlen && !t -> wdata ) || (t -> rlen && !t -> rdata ))
321357 return - EINVAL ;
322358 if (t -> rdata )
@@ -333,8 +369,6 @@ static int acpi_ec_transaction(struct acpi_ec *ec, struct transaction *t)
333369 goto unlock ;
334370 }
335371 }
336- pr_debug ("transaction start (cmd=0x%02x, addr=0x%02x)\n" ,
337- t -> command , t -> wdata ? t -> wdata [0 ] : 0 );
338372 /* disable GPE during transaction if storm is detected */
339373 if (test_bit (EC_FLAGS_GPE_STORM , & ec -> flags )) {
340374 /* It has to be disabled, so that it doesn't trigger. */
@@ -355,7 +389,6 @@ static int acpi_ec_transaction(struct acpi_ec *ec, struct transaction *t)
355389 t -> irq_count );
356390 set_bit (EC_FLAGS_GPE_STORM , & ec -> flags );
357391 }
358- pr_debug ("transaction end\n" );
359392 if (ec -> global_lock )
360393 acpi_release_global_lock (glk );
361394unlock :
@@ -383,7 +416,7 @@ static int acpi_ec_burst_disable(struct acpi_ec *ec)
383416 acpi_ec_transaction (ec , & t ) : 0 ;
384417}
385418
386- static int acpi_ec_read (struct acpi_ec * ec , u8 address , u8 * data )
419+ static int acpi_ec_read (struct acpi_ec * ec , u8 address , u8 * data )
387420{
388421 int result ;
389422 u8 d ;
@@ -419,10 +452,9 @@ int ec_read(u8 addr, u8 *val)
419452 if (!err ) {
420453 * val = temp_data ;
421454 return 0 ;
422- } else
423- return err ;
455+ }
456+ return err ;
424457}
425-
426458EXPORT_SYMBOL (ec_read );
427459
428460int ec_write (u8 addr , u8 val )
@@ -436,22 +468,21 @@ int ec_write(u8 addr, u8 val)
436468
437469 return err ;
438470}
439-
440471EXPORT_SYMBOL (ec_write );
441472
442473int ec_transaction (u8 command ,
443- const u8 * wdata , unsigned wdata_len ,
444- u8 * rdata , unsigned rdata_len )
474+ const u8 * wdata , unsigned wdata_len ,
475+ u8 * rdata , unsigned rdata_len )
445476{
446477 struct transaction t = {.command = command ,
447478 .wdata = wdata , .rdata = rdata ,
448479 .wlen = wdata_len , .rlen = rdata_len };
480+
449481 if (!first_ec )
450482 return - ENODEV ;
451483
452484 return acpi_ec_transaction (first_ec , & t );
453485}
454-
455486EXPORT_SYMBOL (ec_transaction );
456487
457488/* Get the handle to the EC device */
@@ -461,7 +492,6 @@ acpi_handle ec_get_handle(void)
461492 return NULL ;
462493 return first_ec -> handle ;
463494}
464-
465495EXPORT_SYMBOL (ec_get_handle );
466496
467497/*
@@ -525,13 +555,14 @@ void acpi_ec_unblock_transactions_early(void)
525555 clear_bit (EC_FLAGS_BLOCKED , & first_ec -> flags );
526556}
527557
528- static int acpi_ec_query_unlocked (struct acpi_ec * ec , u8 * data )
558+ static int acpi_ec_query_unlocked (struct acpi_ec * ec , u8 * data )
529559{
530560 int result ;
531561 u8 d ;
532562 struct transaction t = {.command = ACPI_EC_COMMAND_QUERY ,
533563 .wdata = NULL , .rdata = & d ,
534564 .wlen = 0 , .rlen = 1 };
565+
535566 if (!ec || !data )
536567 return - EINVAL ;
537568 /*
@@ -557,6 +588,7 @@ int acpi_ec_add_query_handler(struct acpi_ec *ec, u8 query_bit,
557588{
558589 struct acpi_ec_query_handler * handler =
559590 kzalloc (sizeof (struct acpi_ec_query_handler ), GFP_KERNEL );
591+
560592 if (!handler )
561593 return - ENOMEM ;
562594
@@ -569,12 +601,12 @@ int acpi_ec_add_query_handler(struct acpi_ec *ec, u8 query_bit,
569601 mutex_unlock (& ec -> mutex );
570602 return 0 ;
571603}
572-
573604EXPORT_SYMBOL_GPL (acpi_ec_add_query_handler );
574605
575606void acpi_ec_remove_query_handler (struct acpi_ec * ec , u8 query_bit )
576607{
577608 struct acpi_ec_query_handler * handler , * tmp ;
609+
578610 mutex_lock (& ec -> mutex );
579611 list_for_each_entry_safe (handler , tmp , & ec -> list , node ) {
580612 if (query_bit == handler -> query_bit ) {
@@ -584,20 +616,20 @@ void acpi_ec_remove_query_handler(struct acpi_ec *ec, u8 query_bit)
584616 }
585617 mutex_unlock (& ec -> mutex );
586618}
587-
588619EXPORT_SYMBOL_GPL (acpi_ec_remove_query_handler );
589620
590621static void acpi_ec_run (void * cxt )
591622{
592623 struct acpi_ec_query_handler * handler = cxt ;
624+
593625 if (!handler )
594626 return ;
595- pr_debug ("start query execution \n" );
627+ pr_debug ("##### Query(0x%02x) started ##### \n" , handler -> query_bit );
596628 if (handler -> func )
597629 handler -> func (handler -> data );
598630 else if (handler -> handle )
599631 acpi_evaluate_object (handler -> handle , NULL , NULL , NULL );
600- pr_debug ("stop query execution \n" );
632+ pr_debug ("##### Query(0x%02x) stopped ##### \n" , handler -> query_bit );
601633 kfree (handler );
602634}
603635
@@ -620,8 +652,8 @@ static int acpi_ec_sync_query(struct acpi_ec *ec, u8 *data)
620652 if (!copy )
621653 return - ENOMEM ;
622654 memcpy (copy , handler , sizeof (* copy ));
623- pr_debug ("push query execution (0x%2x) on queue \n" ,
624- value );
655+ pr_debug ("##### Query (0x%02x) scheduled ##### \n" ,
656+ handler -> query_bit );
625657 return acpi_os_execute ((copy -> func ) ?
626658 OSL_NOTIFY_HANDLER : OSL_GPE_HANDLER ,
627659 acpi_ec_run , copy );
@@ -633,6 +665,7 @@ static int acpi_ec_sync_query(struct acpi_ec *ec, u8 *data)
633665static void acpi_ec_gpe_query (void * ec_cxt )
634666{
635667 struct acpi_ec * ec = ec_cxt ;
668+
636669 if (!ec )
637670 return ;
638671 mutex_lock (& ec -> mutex );
@@ -644,7 +677,7 @@ static int ec_check_sci(struct acpi_ec *ec, u8 state)
644677{
645678 if (state & ACPI_EC_FLAG_SCI ) {
646679 if (!test_and_set_bit (EC_FLAGS_QUERY_PENDING , & ec -> flags )) {
647- pr_debug ("push gpe query to the queue \n" );
680+ pr_debug ("***** Event started ***** \n" );
648681 return acpi_os_execute (OSL_NOTIFY_HANDLER ,
649682 acpi_ec_gpe_query , ec );
650683 }
@@ -667,8 +700,8 @@ static u32 acpi_ec_gpe_handler(acpi_handle gpe_device,
667700}
668701
669702/* --------------------------------------------------------------------------
670- Address Space Management
671- -------------------------------------------------------------------------- */
703+ * Address Space Management
704+ * -------------------------------------------------------------------------- */
672705
673706static acpi_status
674707acpi_ec_space_handler (u32 function , acpi_physical_address address ,
@@ -699,27 +732,26 @@ acpi_ec_space_handler(u32 function, acpi_physical_address address,
699732 switch (result ) {
700733 case - EINVAL :
701734 return AE_BAD_PARAMETER ;
702- break ;
703735 case - ENODEV :
704736 return AE_NOT_FOUND ;
705- break ;
706737 case - ETIME :
707738 return AE_TIME ;
708- break ;
709739 default :
710740 return AE_OK ;
711741 }
712742}
713743
714744/* --------------------------------------------------------------------------
715- Driver Interface
716- -------------------------------------------------------------------------- */
745+ * Driver Interface
746+ * -------------------------------------------------------------------------- */
747+
717748static acpi_status
718749ec_parse_io_ports (struct acpi_resource * resource , void * context );
719750
720751static struct acpi_ec * make_acpi_ec (void )
721752{
722753 struct acpi_ec * ec = kzalloc (sizeof (struct acpi_ec ), GFP_KERNEL );
754+
723755 if (!ec )
724756 return NULL ;
725757 ec -> flags = 1 << EC_FLAGS_QUERY_PENDING ;
@@ -742,9 +774,8 @@ acpi_ec_register_query_methods(acpi_handle handle, u32 level,
742774
743775 status = acpi_get_name (handle , ACPI_SINGLE_NAME , & buffer );
744776
745- if (ACPI_SUCCESS (status ) && sscanf (node_name , "_Q%x" , & value ) == 1 ) {
777+ if (ACPI_SUCCESS (status ) && sscanf (node_name , "_Q%x" , & value ) == 1 )
746778 acpi_ec_add_query_handler (ec , value , handle , NULL , NULL );
747- }
748779 return AE_OK ;
749780}
750781
@@ -753,7 +784,6 @@ ec_parse_device(acpi_handle handle, u32 Level, void *context, void **retval)
753784{
754785 acpi_status status ;
755786 unsigned long long tmp = 0 ;
756-
757787 struct acpi_ec * ec = context ;
758788
759789 /* clear addr values, ec_parse_io_ports depend on it */
@@ -781,6 +811,7 @@ ec_parse_device(acpi_handle handle, u32 Level, void *context, void **retval)
781811static int ec_install_handlers (struct acpi_ec * ec )
782812{
783813 acpi_status status ;
814+
784815 if (test_bit (EC_FLAGS_HANDLERS_INSTALLED , & ec -> flags ))
785816 return 0 ;
786817 status = acpi_install_gpe_handler (NULL , ec -> gpe ,
@@ -1078,7 +1109,8 @@ int __init acpi_ec_ecdt_probe(void)
10781109 boot_ec -> data_addr = ecdt_ptr -> data .address ;
10791110 boot_ec -> gpe = ecdt_ptr -> gpe ;
10801111 boot_ec -> handle = ACPI_ROOT_OBJECT ;
1081- acpi_get_handle (ACPI_ROOT_OBJECT , ecdt_ptr -> id , & boot_ec -> handle );
1112+ acpi_get_handle (ACPI_ROOT_OBJECT , ecdt_ptr -> id ,
1113+ & boot_ec -> handle );
10821114 /* Don't trust ECDT, which comes from ASUSTek */
10831115 if (!EC_FLAGS_VALIDATE_ECDT )
10841116 goto install ;
@@ -1162,6 +1194,5 @@ static void __exit acpi_ec_exit(void)
11621194{
11631195
11641196 acpi_bus_unregister_driver (& acpi_ec_driver );
1165- return ;
11661197}
11671198#endif /* 0 */
0 commit comments