]>
Commit | Line | Data |
---|---|---|
4e522096 DW |
1 | /** @file\r |
2 | Functions for access I2C MMIO register.\r | |
3 | \r | |
4 | Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r | |
5 | This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php.\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #include <PiPei.h>\r | |
16 | #include <Library/DebugLib.h>\r | |
17 | #include <Library/PeiServicesTablePointerLib.h>\r | |
18 | \r | |
19 | /**\r | |
20 | Reads an 8-bit MMIO register.\r | |
21 | \r | |
22 | Reads the 8-bit MMIO register specified by Address. The 8-bit read value is\r | |
23 | returned. This function must guarantee that all MMIO read and write\r | |
24 | operations are serialized.\r | |
25 | \r | |
26 | If 8-bit MMIO register operations are not supported, then ASSERT().\r | |
27 | \r | |
28 | @param Address The MMIO register to read.\r | |
29 | \r | |
30 | @return The value read.\r | |
31 | \r | |
32 | **/\r | |
33 | UINT8\r | |
34 | EFIAPI\r | |
35 | I2CLibPeiMmioRead8 (\r | |
36 | IN UINTN Address\r | |
37 | )\r | |
38 | {\r | |
39 | UINT8 Value;\r | |
40 | \r | |
41 | Value = *(volatile UINT8*)Address;\r | |
42 | return Value;\r | |
43 | }\r | |
44 | \r | |
45 | /**\r | |
46 | Reads a 16-bit MMIO register.\r | |
47 | \r | |
48 | Reads the 16-bit MMIO register specified by Address. The 16-bit read value is\r | |
49 | returned. This function must guarantee that all MMIO read and write\r | |
50 | operations are serialized.\r | |
51 | \r | |
52 | If 16-bit MMIO register operations are not supported, then ASSERT().\r | |
53 | If Address is not aligned on a 16-bit boundary, then ASSERT().\r | |
54 | \r | |
55 | @param Address The MMIO register to read.\r | |
56 | \r | |
57 | @return The value read.\r | |
58 | \r | |
59 | **/\r | |
60 | UINT16\r | |
61 | EFIAPI\r | |
62 | I2CLibPeiMmioRead16 (\r | |
63 | IN UINTN Address\r | |
64 | )\r | |
65 | {\r | |
66 | UINT16 Value;\r | |
67 | \r | |
68 | ASSERT ((Address & 1) == 0);\r | |
69 | Value = *(volatile UINT16*)Address;\r | |
70 | return Value;\r | |
71 | }\r | |
72 | \r | |
73 | /**\r | |
74 | Writes a 16-bit MMIO register.\r | |
75 | \r | |
76 | Writes the 16-bit MMIO register specified by Address with the value specified\r | |
77 | by Value and returns Value. This function must guarantee that all MMIO read\r | |
78 | and write operations are serialized.\r | |
79 | \r | |
80 | If 16-bit MMIO register operations are not supported, then ASSERT().\r | |
81 | If Address is not aligned on a 16-bit boundary, then ASSERT().\r | |
82 | \r | |
83 | @param Address The MMIO register to write.\r | |
84 | @param Value The value to write to the MMIO register.\r | |
85 | \r | |
86 | @return Value.\r | |
87 | \r | |
88 | **/\r | |
89 | UINT16\r | |
90 | EFIAPI\r | |
91 | I2CLibPeiMmioWrite16 (\r | |
92 | IN UINTN Address,\r | |
93 | IN UINT16 Value\r | |
94 | )\r | |
95 | {\r | |
96 | ASSERT ((Address & 1) == 0);\r | |
97 | *(volatile UINT16*)Address = Value;\r | |
98 | return Value;\r | |
99 | }\r | |
100 | \r | |
101 | /**\r | |
102 | Reads a 32-bit MMIO register.\r | |
103 | \r | |
104 | Reads the 32-bit MMIO register specified by Address. The 32-bit read value is\r | |
105 | returned. This function must guarantee that all MMIO read and write\r | |
106 | operations are serialized.\r | |
107 | \r | |
108 | If 32-bit MMIO register operations are not supported, then ASSERT().\r | |
109 | If Address is not aligned on a 32-bit boundary, then ASSERT().\r | |
110 | \r | |
111 | @param Address The MMIO register to read.\r | |
112 | \r | |
113 | @return The value read.\r | |
114 | \r | |
115 | **/\r | |
116 | UINT32\r | |
117 | EFIAPI\r | |
118 | I2CLibPeiMmioRead32 (\r | |
119 | IN UINTN Address\r | |
120 | )\r | |
121 | {\r | |
122 | UINT32 Value;\r | |
123 | \r | |
124 | ASSERT ((Address & 3) == 0);\r | |
125 | Value = *(volatile UINT32*)Address;\r | |
126 | \r | |
127 | return Value;\r | |
128 | }\r | |
129 | \r | |
130 | /**\r | |
131 | Writes a 32-bit MMIO register.\r | |
132 | \r | |
133 | Writes the 32-bit MMIO register specified by Address with the value specified\r | |
134 | by Value and returns Value. This function must guarantee that all MMIO read\r | |
135 | and write operations are serialized.\r | |
136 | \r | |
137 | If 32-bit MMIO register operations are not supported, then ASSERT().\r | |
138 | If Address is not aligned on a 32-bit boundary, then ASSERT().\r | |
139 | \r | |
140 | @param Address The MMIO register to write.\r | |
141 | @param Value The value to write to the MMIO register.\r | |
142 | \r | |
143 | @return Value.\r | |
144 | \r | |
145 | **/\r | |
146 | UINT32\r | |
147 | EFIAPI\r | |
148 | I2CLibPeiMmioWrite32 (\r | |
149 | IN UINTN Address,\r | |
150 | IN UINT32 Value\r | |
151 | )\r | |
152 | {\r | |
153 | ASSERT ((Address & 3) == 0);\r | |
154 | *(volatile UINT32*)Address = Value;\r | |
155 | return Value;\r | |
156 | }\r | |
157 | \r | |
158 | /**\r | |
159 | OR a 32-bit MMIO register.\r | |
160 | \r | |
161 | OR the 32-bit MMIO register specified by Address with the value specified\r | |
162 | by Value and returns Value. This function must guarantee that all MMIO read\r | |
163 | and write operations are serialized.\r | |
164 | \r | |
165 | If 32-bit MMIO register operations are not supported, then ASSERT().\r | |
166 | If Address is not aligned on a 32-bit boundary, then ASSERT().\r | |
167 | \r | |
168 | @param Address The MMIO register to write OR.\r | |
169 | @param Value The value to OR to the MMIO register.\r | |
170 | \r | |
171 | @return Value.\r | |
172 | \r | |
173 | **/\r | |
174 | UINT32\r | |
175 | EFIAPI\r | |
176 | I2CLibPeiMmioOr32 (\r | |
177 | IN UINTN Address,\r | |
178 | IN UINT32 OrData\r | |
179 | )\r | |
180 | {\r | |
181 | return I2CLibPeiMmioWrite32 (Address, I2CLibPeiMmioRead32(Address) | OrData);\r | |
182 | }\r | |
183 | \r | |
184 | \r |