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