]> git.proxmox.com Git - mirror_edk2.git/blob - Vlv2TbltDevicePkg/Library/I2CLibPei/I2CIoLibPei.c
6a37dbec1d4ba49cec98ae907f1735cb21735fe9
[mirror_edk2.git] / Vlv2TbltDevicePkg / Library / I2CLibPei / I2CIoLibPei.c
1 /** @file
2 Functions for access I2C MMIO register.
3
4 Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include <PiPei.h>
10 #include <Library/DebugLib.h>
11 #include <Library/PeiServicesTablePointerLib.h>
12
13 /**
14 Reads an 8-bit MMIO register.
15
16 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
17 returned. This function must guarantee that all MMIO read and write
18 operations are serialized.
19
20 If 8-bit MMIO register operations are not supported, then ASSERT().
21
22 @param Address The MMIO register to read.
23
24 @return The value read.
25
26 **/
27 UINT8
28 EFIAPI
29 I2CLibPeiMmioRead8 (
30 IN UINTN Address
31 )
32 {
33 UINT8 Value;
34
35 Value = *(volatile UINT8*)Address;
36 return Value;
37 }
38
39 /**
40 Reads a 16-bit MMIO register.
41
42 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
43 returned. This function must guarantee that all MMIO read and write
44 operations are serialized.
45
46 If 16-bit MMIO register operations are not supported, then ASSERT().
47 If Address is not aligned on a 16-bit boundary, then ASSERT().
48
49 @param Address The MMIO register to read.
50
51 @return The value read.
52
53 **/
54 UINT16
55 EFIAPI
56 I2CLibPeiMmioRead16 (
57 IN UINTN Address
58 )
59 {
60 UINT16 Value;
61
62 ASSERT ((Address & 1) == 0);
63 Value = *(volatile UINT16*)Address;
64 return Value;
65 }
66
67 /**
68 Writes a 16-bit MMIO register.
69
70 Writes the 16-bit MMIO register specified by Address with the value specified
71 by Value and returns Value. This function must guarantee that all MMIO read
72 and write operations are serialized.
73
74 If 16-bit MMIO register operations are not supported, then ASSERT().
75 If Address is not aligned on a 16-bit boundary, then ASSERT().
76
77 @param Address The MMIO register to write.
78 @param Value The value to write to the MMIO register.
79
80 @return Value.
81
82 **/
83 UINT16
84 EFIAPI
85 I2CLibPeiMmioWrite16 (
86 IN UINTN Address,
87 IN UINT16 Value
88 )
89 {
90 ASSERT ((Address & 1) == 0);
91 *(volatile UINT16*)Address = Value;
92 return Value;
93 }
94
95 /**
96 Reads a 32-bit MMIO register.
97
98 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
99 returned. This function must guarantee that all MMIO read and write
100 operations are serialized.
101
102 If 32-bit MMIO register operations are not supported, then ASSERT().
103 If Address is not aligned on a 32-bit boundary, then ASSERT().
104
105 @param Address The MMIO register to read.
106
107 @return The value read.
108
109 **/
110 UINT32
111 EFIAPI
112 I2CLibPeiMmioRead32 (
113 IN UINTN Address
114 )
115 {
116 UINT32 Value;
117
118 ASSERT ((Address & 3) == 0);
119 Value = *(volatile UINT32*)Address;
120
121 return Value;
122 }
123
124 /**
125 Writes a 32-bit MMIO register.
126
127 Writes the 32-bit MMIO register specified by Address with the value specified
128 by Value and returns Value. This function must guarantee that all MMIO read
129 and write operations are serialized.
130
131 If 32-bit MMIO register operations are not supported, then ASSERT().
132 If Address is not aligned on a 32-bit boundary, then ASSERT().
133
134 @param Address The MMIO register to write.
135 @param Value The value to write to the MMIO register.
136
137 @return Value.
138
139 **/
140 UINT32
141 EFIAPI
142 I2CLibPeiMmioWrite32 (
143 IN UINTN Address,
144 IN UINT32 Value
145 )
146 {
147 ASSERT ((Address & 3) == 0);
148 *(volatile UINT32*)Address = Value;
149 return Value;
150 }
151
152 /**
153 OR a 32-bit MMIO register.
154
155 OR the 32-bit MMIO register specified by Address with the value specified
156 by Value and returns Value. This function must guarantee that all MMIO read
157 and write operations are serialized.
158
159 If 32-bit MMIO register operations are not supported, then ASSERT().
160 If Address is not aligned on a 32-bit boundary, then ASSERT().
161
162 @param Address The MMIO register to write OR.
163 @param Value The value to OR to the MMIO register.
164
165 @return Value.
166
167 **/
168 UINT32
169 EFIAPI
170 I2CLibPeiMmioOr32 (
171 IN UINTN Address,
172 IN UINT32 OrData
173 )
174 {
175 return I2CLibPeiMmioWrite32 (Address, I2CLibPeiMmioRead32(Address) | OrData);
176 }
177
178