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