1530d68baSNigel Croxon /*++
2530d68baSNigel Croxon
3530d68baSNigel Croxon Copyright (c) 1998 Intel Corporation
4530d68baSNigel Croxon
5530d68baSNigel Croxon Module Name:
6530d68baSNigel Croxon
7530d68baSNigel Croxon hw.c
8530d68baSNigel Croxon
9530d68baSNigel Croxon Abstract:
10530d68baSNigel Croxon
11530d68baSNigel Croxon Debug library functions for Hardware IO access
12530d68baSNigel Croxon
13530d68baSNigel Croxon
14530d68baSNigel Croxon
15530d68baSNigel Croxon Revision History
16530d68baSNigel Croxon
17530d68baSNigel Croxon --*/
18530d68baSNigel Croxon
19530d68baSNigel Croxon #include "lib.h"
20530d68baSNigel Croxon
21530d68baSNigel Croxon
22530d68baSNigel Croxon EFI_STATUS
InitializeGlobalIoDevice(IN EFI_DEVICE_PATH * DevicePath,IN EFI_GUID * Protocol,IN CHAR8 * ErrorStr EFI_UNUSED,OUT EFI_DEVICE_IO_INTERFACE ** GlobalIoFncs)23530d68baSNigel Croxon InitializeGlobalIoDevice (
24530d68baSNigel Croxon IN EFI_DEVICE_PATH *DevicePath,
25530d68baSNigel Croxon IN EFI_GUID *Protocol,
26*5ff74ecaSNigel Croxon IN CHAR8 *ErrorStr EFI_UNUSED,
27530d68baSNigel Croxon OUT EFI_DEVICE_IO_INTERFACE **GlobalIoFncs
28530d68baSNigel Croxon )
29530d68baSNigel Croxon /*++
30530d68baSNigel Croxon
31530d68baSNigel Croxon Routine Description:
32530d68baSNigel Croxon
33530d68baSNigel Croxon Check to see if DevicePath exists for a given Protocol. Return Error if it
34530d68baSNigel Croxon exists. Return GlobalIoFuncs set match the DevicePath
35530d68baSNigel Croxon
36530d68baSNigel Croxon Arguments:
37530d68baSNigel Croxon
38530d68baSNigel Croxon DevicePath - to operate on
39530d68baSNigel Croxon Protocol - to check the DevicePath against
40530d68baSNigel Croxon ErrorStr - ASCII string to display on error
41530d68baSNigel Croxon GlobalIoFncs - Returned with DeviceIoProtocol for the DevicePath
42530d68baSNigel Croxon
43530d68baSNigel Croxon Returns:
44530d68baSNigel Croxon
45530d68baSNigel Croxon Pass or Fail based on wether GlobalIoFncs where found
46530d68baSNigel Croxon
47530d68baSNigel Croxon --*/
48530d68baSNigel Croxon {
49530d68baSNigel Croxon EFI_STATUS Status;
50530d68baSNigel Croxon EFI_HANDLE Handle;
51530d68baSNigel Croxon
52530d68baSNigel Croxon //
53530d68baSNigel Croxon // Check to see if this device path already has Protocol on it.
54530d68baSNigel Croxon // if so we are loading recursivly and should exit with an error
55530d68baSNigel Croxon //
56530d68baSNigel Croxon Status = uefi_call_wrapper(BS->LocateDevicePath, 3, Protocol, &DevicePath, &Handle);
57530d68baSNigel Croxon if (!EFI_ERROR(Status)) {
58530d68baSNigel Croxon DEBUG ((D_INIT, "Device Already Loaded for %a device\n", ErrorStr));
59530d68baSNigel Croxon return EFI_LOAD_ERROR;
60530d68baSNigel Croxon }
61530d68baSNigel Croxon
62530d68baSNigel Croxon Status = uefi_call_wrapper(BS->LocateDevicePath, 3, &DeviceIoProtocol, &DevicePath, &Handle);
63530d68baSNigel Croxon if (!EFI_ERROR(Status)) {
64530d68baSNigel Croxon Status = uefi_call_wrapper(BS->HandleProtocol, 3, Handle, &DeviceIoProtocol, (VOID*)GlobalIoFncs);
65530d68baSNigel Croxon }
66530d68baSNigel Croxon
67530d68baSNigel Croxon ASSERT (!EFI_ERROR(Status));
68530d68baSNigel Croxon return Status;
69530d68baSNigel Croxon }
70530d68baSNigel Croxon
71530d68baSNigel Croxon UINT32
ReadPort(IN EFI_DEVICE_IO_INTERFACE * GlobalIoFncs,IN EFI_IO_WIDTH Width,IN UINTN Port)72530d68baSNigel Croxon ReadPort (
73530d68baSNigel Croxon IN EFI_DEVICE_IO_INTERFACE *GlobalIoFncs,
74530d68baSNigel Croxon IN EFI_IO_WIDTH Width,
75530d68baSNigel Croxon IN UINTN Port
76530d68baSNigel Croxon )
77530d68baSNigel Croxon {
78530d68baSNigel Croxon UINT32 Data;
79*5ff74ecaSNigel Croxon EFI_STATUS Status EFI_UNUSED;
80530d68baSNigel Croxon
81530d68baSNigel Croxon Status = uefi_call_wrapper(GlobalIoFncs->Io.Read, 5, GlobalIoFncs, Width, (UINT64)Port, 1, &Data);
82530d68baSNigel Croxon ASSERT(!EFI_ERROR(Status));
83530d68baSNigel Croxon return Data;
84530d68baSNigel Croxon }
85530d68baSNigel Croxon
86530d68baSNigel Croxon UINT32
WritePort(IN EFI_DEVICE_IO_INTERFACE * GlobalIoFncs,IN EFI_IO_WIDTH Width,IN UINTN Port,IN UINTN Data)87530d68baSNigel Croxon WritePort (
88530d68baSNigel Croxon IN EFI_DEVICE_IO_INTERFACE *GlobalIoFncs,
89530d68baSNigel Croxon IN EFI_IO_WIDTH Width,
90530d68baSNigel Croxon IN UINTN Port,
91530d68baSNigel Croxon IN UINTN Data
92530d68baSNigel Croxon )
93530d68baSNigel Croxon {
94*5ff74ecaSNigel Croxon EFI_STATUS Status EFI_UNUSED;
95530d68baSNigel Croxon
96530d68baSNigel Croxon Status = uefi_call_wrapper(GlobalIoFncs->Io.Write, 5, GlobalIoFncs, Width, (UINT64)Port, 1, &Data);
97530d68baSNigel Croxon ASSERT(!EFI_ERROR(Status));
98530d68baSNigel Croxon return (UINT32)Data;
99530d68baSNigel Croxon }
100530d68baSNigel Croxon
101530d68baSNigel Croxon UINT32
ReadPciConfig(IN EFI_DEVICE_IO_INTERFACE * GlobalIoFncs,IN EFI_IO_WIDTH Width,IN UINTN Address)102530d68baSNigel Croxon ReadPciConfig (
103530d68baSNigel Croxon IN EFI_DEVICE_IO_INTERFACE *GlobalIoFncs,
104530d68baSNigel Croxon IN EFI_IO_WIDTH Width,
105530d68baSNigel Croxon IN UINTN Address
106530d68baSNigel Croxon )
107530d68baSNigel Croxon {
108530d68baSNigel Croxon UINT32 Data;
109*5ff74ecaSNigel Croxon EFI_STATUS Status EFI_UNUSED;
110530d68baSNigel Croxon
111530d68baSNigel Croxon Status = uefi_call_wrapper(GlobalIoFncs->Pci.Read, 5, GlobalIoFncs, Width, (UINT64)Address, 1, &Data);
112530d68baSNigel Croxon ASSERT(!EFI_ERROR(Status));
113530d68baSNigel Croxon return Data;
114530d68baSNigel Croxon }
115530d68baSNigel Croxon
116530d68baSNigel Croxon UINT32
WritePciConfig(IN EFI_DEVICE_IO_INTERFACE * GlobalIoFncs,IN EFI_IO_WIDTH Width,IN UINTN Address,IN UINTN Data)117530d68baSNigel Croxon WritePciConfig (
118530d68baSNigel Croxon IN EFI_DEVICE_IO_INTERFACE *GlobalIoFncs,
119530d68baSNigel Croxon IN EFI_IO_WIDTH Width,
120530d68baSNigel Croxon IN UINTN Address,
121530d68baSNigel Croxon IN UINTN Data
122530d68baSNigel Croxon )
123530d68baSNigel Croxon {
124*5ff74ecaSNigel Croxon EFI_STATUS Status EFI_UNUSED;
125530d68baSNigel Croxon
126530d68baSNigel Croxon Status = uefi_call_wrapper(GlobalIoFncs->Pci.Write, 5, GlobalIoFncs, Width, (UINT64)Address, 1, &Data);
127530d68baSNigel Croxon ASSERT(!EFI_ERROR(Status));
128530d68baSNigel Croxon return (UINT32)Data;
129530d68baSNigel Croxon }
130530d68baSNigel Croxon
131530d68baSNigel Croxon
132530d68baSNigel Croxon
133