hw.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*++
  2. Copyright (c) 1998 Intel Corporation
  3. Module Name:
  4. hw.c
  5. Abstract:
  6. Debug library functions for Hardware IO access
  7. Revision History
  8. --*/
  9. #include "lib.h"
  10. EFI_STATUS
  11. InitializeGlobalIoDevice (
  12. IN EFI_DEVICE_PATH *DevicePath,
  13. IN EFI_GUID *Protocol,
  14. IN CHAR8 *ErrorStr EFI_UNUSED,
  15. OUT EFI_DEVICE_IO_INTERFACE **GlobalIoFncs
  16. )
  17. /*++
  18. Routine Description:
  19. Check to see if DevicePath exists for a given Protocol. Return Error if it
  20. exists. Return GlobalIoFuncs set match the DevicePath
  21. Arguments:
  22. DevicePath - to operate on
  23. Protocol - to check the DevicePath against
  24. ErrorStr - ASCII string to display on error
  25. GlobalIoFncs - Returned with DeviceIoProtocol for the DevicePath
  26. Returns:
  27. Pass or Fail based on wether GlobalIoFncs where found
  28. --*/
  29. {
  30. EFI_STATUS Status;
  31. EFI_HANDLE Handle;
  32. //
  33. // Check to see if this device path already has Protocol on it.
  34. // if so we are loading recursivly and should exit with an error
  35. //
  36. Status = uefi_call_wrapper(BS->LocateDevicePath, 3, Protocol, &DevicePath, &Handle);
  37. if (!EFI_ERROR(Status)) {
  38. DEBUG ((D_INIT, "Device Already Loaded for %a device\n", ErrorStr));
  39. return EFI_LOAD_ERROR;
  40. }
  41. Status = uefi_call_wrapper(BS->LocateDevicePath, 3, &DeviceIoProtocol, &DevicePath, &Handle);
  42. if (!EFI_ERROR(Status)) {
  43. Status = uefi_call_wrapper(BS->HandleProtocol, 3, Handle, &DeviceIoProtocol, (VOID*)GlobalIoFncs);
  44. }
  45. ASSERT (!EFI_ERROR(Status));
  46. return Status;
  47. }
  48. UINT32
  49. ReadPort (
  50. IN EFI_DEVICE_IO_INTERFACE *GlobalIoFncs,
  51. IN EFI_IO_WIDTH Width,
  52. IN UINTN Port
  53. )
  54. {
  55. UINT32 Data;
  56. EFI_STATUS Status EFI_UNUSED;
  57. Status = uefi_call_wrapper(GlobalIoFncs->Io.Read, 5, GlobalIoFncs, Width, (UINT64)Port, 1, &Data);
  58. ASSERT(!EFI_ERROR(Status));
  59. return Data;
  60. }
  61. UINT32
  62. WritePort (
  63. IN EFI_DEVICE_IO_INTERFACE *GlobalIoFncs,
  64. IN EFI_IO_WIDTH Width,
  65. IN UINTN Port,
  66. IN UINTN Data
  67. )
  68. {
  69. EFI_STATUS Status EFI_UNUSED;
  70. Status = uefi_call_wrapper(GlobalIoFncs->Io.Write, 5, GlobalIoFncs, Width, (UINT64)Port, 1, &Data);
  71. ASSERT(!EFI_ERROR(Status));
  72. return (UINT32)Data;
  73. }
  74. UINT32
  75. ReadPciConfig (
  76. IN EFI_DEVICE_IO_INTERFACE *GlobalIoFncs,
  77. IN EFI_IO_WIDTH Width,
  78. IN UINTN Address
  79. )
  80. {
  81. UINT32 Data;
  82. EFI_STATUS Status EFI_UNUSED;
  83. Status = uefi_call_wrapper(GlobalIoFncs->Pci.Read, 5, GlobalIoFncs, Width, (UINT64)Address, 1, &Data);
  84. ASSERT(!EFI_ERROR(Status));
  85. return Data;
  86. }
  87. UINT32
  88. WritePciConfig (
  89. IN EFI_DEVICE_IO_INTERFACE *GlobalIoFncs,
  90. IN EFI_IO_WIDTH Width,
  91. IN UINTN Address,
  92. IN UINTN Data
  93. )
  94. {
  95. EFI_STATUS Status EFI_UNUSED;
  96. Status = uefi_call_wrapper(GlobalIoFncs->Pci.Write, 5, GlobalIoFncs, Width, (UINT64)Address, 1, &Data);
  97. ASSERT(!EFI_ERROR(Status));
  98. return (UINT32)Data;
  99. }