Subversion Repositories HelenOS

Rev

Rev 2726 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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