Browse Source

[efi] Raise TPL within EFI_USB_IO_PROTOCOL entry points

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 6 years ago
parent
commit
f672a27b34
1 changed files with 41 additions and 6 deletions
  1. 41
    6
      src/interface/efi/efi_usb.c

+ 41
- 6
src/interface/efi/efi_usb.c View File

505
 			   EFI_USB_DATA_DIRECTION direction,
505
 			   EFI_USB_DATA_DIRECTION direction,
506
 			   UINT32 timeout, VOID *data, UINTN len,
506
 			   UINT32 timeout, VOID *data, UINTN len,
507
 			   UINT32 *status ) {
507
 			   UINT32 *status ) {
508
+	EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
508
 	struct efi_usb_interface *usbintf =
509
 	struct efi_usb_interface *usbintf =
509
 		container_of ( usbio, struct efi_usb_interface, usbio );
510
 		container_of ( usbio, struct efi_usb_interface, usbio );
510
 	struct efi_usb_device *usbdev = usbintf->usbdev;
511
 	struct efi_usb_device *usbdev = usbintf->usbdev;
512
 				 USB_REQUEST_TYPE ( packet->Request ) );
513
 				 USB_REQUEST_TYPE ( packet->Request ) );
513
 	unsigned int value = le16_to_cpu ( packet->Value );
514
 	unsigned int value = le16_to_cpu ( packet->Value );
514
 	unsigned int index = le16_to_cpu ( packet->Index );
515
 	unsigned int index = le16_to_cpu ( packet->Index );
516
+	EFI_TPL saved_tpl;
515
 	int rc;
517
 	int rc;
516
 
518
 
517
 	DBGC2 ( usbdev, "USBDEV %s control %04x:%04x:%04x:%04x %s %dms "
519
 	DBGC2 ( usbdev, "USBDEV %s control %04x:%04x:%04x:%04x %s %dms "
520
 		efi_usb_direction_name ( direction ), timeout, data,
522
 		efi_usb_direction_name ( direction ), timeout, data,
521
 		( ( size_t ) len ) );
523
 		( ( size_t ) len ) );
522
 
524
 
525
+	/* Raise TPL */
526
+	saved_tpl = bs->RaiseTPL ( TPL_CALLBACK );
527
+
523
 	/* Clear status */
528
 	/* Clear status */
524
 	*status = 0;
529
 	*status = 0;
525
 
530
 
563
 
568
 
564
  err_control:
569
  err_control:
565
  err_change_config:
570
  err_change_config:
571
+	bs->RestoreTPL ( saved_tpl );
566
 	return EFIRC ( rc );
572
 	return EFIRC ( rc );
567
 }
573
 }
568
 
574
 
580
 static EFI_STATUS EFIAPI
586
 static EFI_STATUS EFIAPI
581
 efi_usb_bulk_transfer ( EFI_USB_IO_PROTOCOL *usbio, UINT8 endpoint, VOID *data,
587
 efi_usb_bulk_transfer ( EFI_USB_IO_PROTOCOL *usbio, UINT8 endpoint, VOID *data,
582
 			UINTN *len, UINTN timeout, UINT32 *status ) {
588
 			UINTN *len, UINTN timeout, UINT32 *status ) {
589
+	EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
583
 	struct efi_usb_interface *usbintf =
590
 	struct efi_usb_interface *usbintf =
584
 		container_of ( usbio, struct efi_usb_interface, usbio );
591
 		container_of ( usbio, struct efi_usb_interface, usbio );
585
 	struct efi_usb_device *usbdev = usbintf->usbdev;
592
 	struct efi_usb_device *usbdev = usbintf->usbdev;
586
 	size_t actual = *len;
593
 	size_t actual = *len;
594
+	EFI_TPL saved_tpl;
587
 	int rc;
595
 	int rc;
588
 
596
 
589
 	DBGC2 ( usbdev, "USBDEV %s bulk %s %p+%zx %dms\n", usbintf->name,
597
 	DBGC2 ( usbdev, "USBDEV %s bulk %s %p+%zx %dms\n", usbintf->name,
590
 		( ( endpoint & USB_ENDPOINT_IN ) ? "IN" : "OUT" ), data,
598
 		( ( endpoint & USB_ENDPOINT_IN ) ? "IN" : "OUT" ), data,
591
 		( ( size_t ) *len ), ( ( unsigned int ) timeout ) );
599
 		( ( size_t ) *len ), ( ( unsigned int ) timeout ) );
592
 
600
 
601
+	/* Raise TPL */
602
+	saved_tpl = bs->RaiseTPL ( TPL_CALLBACK );
603
+
593
 	/* Clear status */
604
 	/* Clear status */
594
 	*status = 0;
605
 	*status = 0;
595
 
606
 
599
 					    data, &actual ) ) != 0 ) {
610
 					    data, &actual ) ) != 0 ) {
600
 		/* Assume that any error represents a timeout */
611
 		/* Assume that any error represents a timeout */
601
 		*status = EFI_USB_ERR_TIMEOUT;
612
 		*status = EFI_USB_ERR_TIMEOUT;
602
-		return rc;
613
+		goto err_transfer;
603
 	}
614
 	}
604
 
615
 
605
-	return 0;
616
+ err_transfer:
617
+	bs->RestoreTPL ( saved_tpl );
618
+	return EFIRC ( rc );
606
 }
619
 }
607
 
620
 
608
 /**
621
 /**
620
 efi_usb_sync_interrupt_transfer ( EFI_USB_IO_PROTOCOL *usbio, UINT8 endpoint,
633
 efi_usb_sync_interrupt_transfer ( EFI_USB_IO_PROTOCOL *usbio, UINT8 endpoint,
621
 				  VOID *data, UINTN *len, UINTN timeout,
634
 				  VOID *data, UINTN *len, UINTN timeout,
622
 				  UINT32 *status ) {
635
 				  UINT32 *status ) {
636
+	EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
623
 	struct efi_usb_interface *usbintf =
637
 	struct efi_usb_interface *usbintf =
624
 		container_of ( usbio, struct efi_usb_interface, usbio );
638
 		container_of ( usbio, struct efi_usb_interface, usbio );
625
 	struct efi_usb_device *usbdev = usbintf->usbdev;
639
 	struct efi_usb_device *usbdev = usbintf->usbdev;
626
 	size_t actual = *len;
640
 	size_t actual = *len;
641
+	EFI_TPL saved_tpl;
627
 	int rc;
642
 	int rc;
628
 
643
 
629
 	DBGC2 ( usbdev, "USBDEV %s sync intr %s %p+%zx %dms\n", usbintf->name,
644
 	DBGC2 ( usbdev, "USBDEV %s sync intr %s %p+%zx %dms\n", usbintf->name,
630
 		( ( endpoint & USB_ENDPOINT_IN ) ? "IN" : "OUT" ), data,
645
 		( ( endpoint & USB_ENDPOINT_IN ) ? "IN" : "OUT" ), data,
631
 		( ( size_t ) *len ), ( ( unsigned int ) timeout ) );
646
 		( ( size_t ) *len ), ( ( unsigned int ) timeout ) );
632
 
647
 
648
+	/* Raise TPL */
649
+	saved_tpl = bs->RaiseTPL ( TPL_CALLBACK );
650
+
633
 	/* Clear status */
651
 	/* Clear status */
634
 	*status = 0;
652
 	*status = 0;
635
 
653
 
639
 					    timeout, data, &actual ) ) != 0 ) {
657
 					    timeout, data, &actual ) ) != 0 ) {
640
 		/* Assume that any error represents a timeout */
658
 		/* Assume that any error represents a timeout */
641
 		*status = EFI_USB_ERR_TIMEOUT;
659
 		*status = EFI_USB_ERR_TIMEOUT;
642
-		return rc;
660
+		goto err_transfer;
643
 	}
661
 	}
644
 
662
 
645
-	return 0;
663
+ err_transfer:
664
+	bs->RestoreTPL ( saved_tpl );
665
+	return EFIRC ( rc );
646
 }
666
 }
647
 
667
 
648
 /**
668
 /**
662
 				   BOOLEAN start, UINTN interval, UINTN len,
682
 				   BOOLEAN start, UINTN interval, UINTN len,
663
 				   EFI_ASYNC_USB_TRANSFER_CALLBACK callback,
683
 				   EFI_ASYNC_USB_TRANSFER_CALLBACK callback,
664
 				   VOID *context ) {
684
 				   VOID *context ) {
685
+	EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
665
 	struct efi_usb_interface *usbintf =
686
 	struct efi_usb_interface *usbintf =
666
 		container_of ( usbio, struct efi_usb_interface, usbio );
687
 		container_of ( usbio, struct efi_usb_interface, usbio );
667
 	struct efi_usb_device *usbdev = usbintf->usbdev;
688
 	struct efi_usb_device *usbdev = usbintf->usbdev;
689
+	EFI_TPL saved_tpl;
668
 	int rc;
690
 	int rc;
669
 
691
 
670
 	DBGC2 ( usbdev, "USBDEV %s async intr %s len %#zx int %d %p/%p\n",
692
 	DBGC2 ( usbdev, "USBDEV %s async intr %s len %#zx int %d %p/%p\n",
673
 		( ( size_t ) len ), ( ( unsigned int ) interval ),
695
 		( ( size_t ) len ), ( ( unsigned int ) interval ),
674
 		callback, context );
696
 		callback, context );
675
 
697
 
698
+	/* Raise TPL */
699
+	saved_tpl = bs->RaiseTPL ( TPL_CALLBACK );
700
+
676
 	/* Start/stop transfer as applicable */
701
 	/* Start/stop transfer as applicable */
677
 	if ( start ) {
702
 	if ( start ) {
678
 
703
 
687
 		/* Stop transfer */
712
 		/* Stop transfer */
688
 		efi_usb_async_stop ( usbintf, endpoint );
713
 		efi_usb_async_stop ( usbintf, endpoint );
689
 
714
 
690
-	}
715
+		/* Success */
716
+		rc = 0;
691
 
717
 
692
-	return 0;
718
+	}
693
 
719
 
694
  err_start:
720
  err_start:
721
+	bs->RestoreTPL ( saved_tpl );
695
 	return EFIRC ( rc );
722
 	return EFIRC ( rc );
696
 }
723
 }
697
 
724
 
889
 	struct usb_descriptor_header header;
916
 	struct usb_descriptor_header header;
890
 	VOID *buffer;
917
 	VOID *buffer;
891
 	size_t len;
918
 	size_t len;
919
+	EFI_TPL saved_tpl;
892
 	EFI_STATUS efirc;
920
 	EFI_STATUS efirc;
893
 	int rc;
921
 	int rc;
894
 
922
 
895
 	DBGC2 ( usbdev, "USBDEV %s get string %d:%d descriptor\n",
923
 	DBGC2 ( usbdev, "USBDEV %s get string %d:%d descriptor\n",
896
 		usbintf->name, language, index );
924
 		usbintf->name, language, index );
897
 
925
 
926
+	/* Raise TPL */
927
+	saved_tpl = bs->RaiseTPL ( TPL_CALLBACK );
928
+
898
 	/* Read descriptor header */
929
 	/* Read descriptor header */
899
 	if ( ( rc = usb_get_descriptor ( usbdev->usb, 0, USB_STRING_DESCRIPTOR,
930
 	if ( ( rc = usb_get_descriptor ( usbdev->usb, 0, USB_STRING_DESCRIPTOR,
900
 					 index, language, &header,
931
 					 index, language, &header,
928
 		  ( len - sizeof ( header ) ) );
959
 		  ( len - sizeof ( header ) ) );
929
 	memset ( ( buffer + len - sizeof ( header ) ), 0, sizeof ( **string ) );
960
 	memset ( ( buffer + len - sizeof ( header ) ), 0, sizeof ( **string ) );
930
 
961
 
962
+	/* Restore TPL */
963
+	bs->RestoreTPL ( saved_tpl );
964
+
931
 	/* Return allocated string */
965
 	/* Return allocated string */
932
 	*string = buffer;
966
 	*string = buffer;
933
 	return 0;
967
 	return 0;
936
 	bs->FreePool ( buffer );
970
 	bs->FreePool ( buffer );
937
  err_alloc:
971
  err_alloc:
938
  err_get_header:
972
  err_get_header:
973
+	bs->RestoreTPL ( saved_tpl );
939
 	return EFIRC ( rc );
974
 	return EFIRC ( rc );
940
 }
975
 }
941
 
976
 

Loading…
Cancel
Save