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