Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
3.1 KiB

  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,
  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 = BS->LocateDevicePath (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 = BS->LocateDevicePath (&DeviceIoProtocol, &DevicePath, &Handle);
  42. if (!EFI_ERROR(Status)) {
  43. Status = BS->HandleProtocol (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;
  57. Status = GlobalIoFncs->Io.Read (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;
  70. Status = GlobalIoFncs->Io.Write (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;
  83. Status = GlobalIoFncs->Pci.Read (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;
  96. Status = GlobalIoFncs->Pci.Write (GlobalIoFncs, Width, (UINT64)Address, 1, &Data);
  97. ASSERT(!EFI_ERROR(Status));
  98. return (UINT32)Data;
  99. }