summaryrefslogtreecommitdiff
path: root/Chipset/eM/Ahci/AhciAccess.c
blob: 36ea2642af3518b87f5e7ef6ebea4aa98706d250 (plain)
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
//**********************************************************************
//**********************************************************************
//**                                                                  **
//**        (C)Copyright 1985-2011, American Megatrends, Inc.         **
//**                                                                  **
//**                       All Rights Reserved.                       **
//**                                                                  **
//**         5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093        **
//**                                                                  **
//**                       Phone: (770)-246-8600                      **
//**                                                                  **
//**********************************************************************
//**********************************************************************

//**********************************************************************
// $Header: /Alaska/SOURCE/Modules/AHCI/AhciAccess.c 3     2/11/11 4:09a Rameshr $
//
// $Revision: 3 $
//
// $Date: 2/11/11 4:09a $
//**********************************************************************
// Revision History
// ----------------
// $Log: /Alaska/SOURCE/Modules/AHCI/AhciAccess.c $
// 
// 3     2/11/11 4:09a Rameshr
// [TAG]  		EIP53704
// [Category]  	Improvement
// [Description]  	AMI headers update for Alaska Ahci Driver
// [Files]  		AhciAccess.c
// 
// 2     5/07/10 11:51a Krishnakumarg
// Update for coding standard.
// 
// 1     5/28/08 9:49a Rameshraju
// Initial Check-in for Index/Data access method.
//
//**********************************************************************
//<AMI_FHDR_START>
//
// Name: AhciAccess.c
//
// Description: Provides Index Data Port Access to AHCI Controller
//
//<AMI_FHDR_END>
//**********************************************************************
//#include <AmiDxeLib.h>

#define LBAR_REGISTER           0x20
#define LBAR_ADDRESS_MASK       0xFFFFFFE0
#define INDEX_OFFSET_FROM_LBAR  0x10
#define DATA_OFFSET_FROM_LBAR   0x14

#include "AmiDxeLib.h"
#include "Protocol\PciIo.h"

UINT16 IndexPort, DataPort;

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Name:        InitilizeIndexDataPortAddress
//
// Description: This is chipset porting routine that returns index/data ports
//              to access memory-mapped registers.
//
// Input:       PciIo
//
// Output:      EFI_SUCCESS         - Access information is collected
//              EFI_ACCESS_DENIED   - No Access information avaliable
//
//-------------------------------------------------------------------------
//<AMI_PHDR_END>

EFI_STATUS
InitilizeIndexDataPortAddress (
    IN EFI_PCI_IO_PROTOCOL *PciIo
)
{
    EFI_STATUS Status;
    UINT32 lbar;

    Status = PciIo->Pci.Read(PciIo, EfiPciIoWidthUint32, LBAR_REGISTER, 1, &lbar);
    ASSERT_EFI_ERROR(Status);

    lbar &= LBAR_ADDRESS_MASK;  // Legacy Bus Master Base Address

    IndexPort = (UINT16)lbar + INDEX_OFFSET_FROM_LBAR;
    DataPort = (UINT16)lbar + DATA_OFFSET_FROM_LBAR;

    return EFI_SUCCESS;

}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Name:        ReadDataDword
//
// Description: Read the Dword Data using Index/Data access method
//
// Input:       BaseAddress - BaseAddress of AHCI Controller
//              Index       - Index address to read           
//
// Output:      Value Read
//              
//
//-------------------------------------------------------------------------
//<AMI_PHDR_END>
UINT32
ReadDataDword(
    IN  UINTN   BaseAddr,
    IN  UINTN   Index
)
{ 
    IoWrite32(IndexPort, (UINT32)Index);
    return IoRead32(DataPort);
}
//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Name:        WriteDataDword
//
// Description: WriteRead the Dword Data using Index/Data access method
//
// Input:       BaseAddress - BaseAddress of AHCI Controller
//              Index       - Index address to Write
//              Data        - Data to be written        
//
// Output:      Nothing
//              
//
//-------------------------------------------------------------------------
//<AMI_PHDR_END>
VOID
WriteDataDword(
    IN  UINTN   BaseAddr,
    IN  UINTN   Index, 
    IN  UINTN   Data
)
{ 
    IoWrite32(IndexPort, (UINT32)Index);
    IoWrite32(DataPort, (UINT32)Data);
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Name:        ReadDataDword
//
// Description: Read the Word Data using Index/Data access method
//
// Input:       BaseAddress - BaseAddress of AHCI Controller
//              Index       - Index address to read           
//
// Output:      Value Read
//              
//
//-------------------------------------------------------------------------
//<AMI_PHDR_END>
UINT16
ReadDataWord(
    IN  UINTN   BaseAddr,
    IN  UINTN   Index
)
{ 
    IoWrite32(IndexPort, (UINT32)Index);
    return (UINT16)IoRead32(DataPort);
}
//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Name:        WriteDataDword
//
// Description: WriteRead the word Data using Index/Data access method
//
// Input:       BaseAddress - BaseAddress of AHCI Controller
//              Index       - Index address to Write
//              Data        - Data to be written        
//
// Output:      Nothing
//              
//
//-------------------------------------------------------------------------
//<AMI_PHDR_END>
VOID
WriteDataWord(
    IN  UINTN   BaseAddr,
    IN  UINTN   Index, 
    IN  UINTN   Data
)
{ 
    IoWrite32(IndexPort, (UINT32)Index);
    IoWrite32(DataPort, (UINT16)Data);
}
//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Name:        ReadDataDword
//
// Description: Read the Byte Data using Index/Data access method
//
// Input:       BaseAddress - BaseAddress of AHCI Controller
//              Index       - Index address to read           
//
// Output:      Value Read
//              
//
//-------------------------------------------------------------------------
//<AMI_PHDR_END>
UINT8
ReadDataByte(
    IN  UINTN   BaseAddr,
    IN  UINTN   Index
)
{ 
    IoWrite32(IndexPort, (UINT32)Index);
    return (UINT8)IoRead32(DataPort);
}
//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Name:        WriteDataByte
//
// Description: WriteRead the Dword Data using Index/Data access method
//
// Input:       BaseAddress - BaseAddress of AHCI Controller
//              Index       - Index address to Write
//              Data        - Data to be written        
//
// Output:      Nothing
//              
//
//-------------------------------------------------------------------------
//<AMI_PHDR_END>
VOID
WriteDataByte(
    IN  UINTN   BaseAddr,
    IN  UINTN   Index,
    IN  UINTN   Data
)
{ 
    IoWrite32(IndexPort, (UINT32)Index);
    IoWrite8(DataPort, (UINT8)Data);
}

//**********************************************************************
//**********************************************************************
//**                                                                  **
//**        (C)Copyright 1985-2011, American Megatrends, Inc.         **
//**                                                                  **
//**                       All Rights Reserved.                       **
//**                                                                  **
//**         5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093        **
//**                                                                  **
//**                       Phone: (770)-246-8600                      **
//**                                                                  **
//**********************************************************************
//**********************************************************************