vanjeff | e1f414b | 2007-06-22 03:21:45 +0000 | [diff] [blame] | 1 | /** @file
|
| 2 | I/O Library. This file has compiler specifics for Microsft C as there is no
|
| 3 | ANSI C standard for doing IO.
|
| 4 |
|
| 5 | MSC - uses intrinsic functions and the optimize will remove the function call
|
| 6 | overhead.
|
| 7 |
|
| 8 | We don't advocate putting compiler specifics in libraries or drivers but there
|
| 9 | is no other way to make this work.
|
| 10 |
|
| 11 | Copyright (c) 2006 - 2007, Intel Corporation<BR>
|
| 12 | All rights reserved. This program and the accompanying materials
|
| 13 | are licensed and made available under the terms and conditions of the BSD License
|
| 14 | which accompanies this distribution. The full text of the license may be found at
|
| 15 | http://opensource.org/licenses/bsd-license.php
|
| 16 |
|
| 17 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
| 18 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
| 19 |
|
| 20 | Module Name: IoLibMsc.c
|
| 21 |
|
| 22 | **/
|
| 23 |
|
| 24 |
|
| 25 | //
|
| 26 | // Include common header file for this module.
|
| 27 | //
|
| 28 | #include "CommonHeader.h"
|
| 29 |
|
| 30 | //
|
| 31 | // Microsoft Visual Studio 7.1 Function Prototypes for I/O Intrinsics
|
| 32 | //
|
| 33 | int _inp (unsigned short port);
|
| 34 | unsigned short _inpw (unsigned short port);
|
| 35 | unsigned long _inpd (unsigned short port);
|
| 36 | int _outp (unsigned short port, int databyte );
|
| 37 | unsigned short _outpw (unsigned short port, unsigned short dataword );
|
| 38 | unsigned long _outpd (unsigned short port, unsigned long dataword );
|
| 39 | void _ReadWriteBarrier (void);
|
| 40 |
|
| 41 | #pragma intrinsic(_inp)
|
| 42 | #pragma intrinsic(_inpw)
|
| 43 | #pragma intrinsic(_inpd)
|
| 44 | #pragma intrinsic(_outp)
|
| 45 | #pragma intrinsic(_outpw)
|
| 46 | #pragma intrinsic(_outpd)
|
| 47 | #pragma intrinsic(_ReadWriteBarrier)
|
| 48 |
|
| 49 | //
|
| 50 | // _ReadWriteBarrier() forces memory reads and writes to complete at the point
|
| 51 | // in the call. This is only a hint to the compiler and does emit code.
|
| 52 | // In past versions of the compiler, _ReadWriteBarrier was enforced only
|
| 53 | // locally and did not affect functions up the call tree. In Visual C++
|
| 54 | // 2005, _ReadWriteBarrier is enforced all the way up the call tree.
|
| 55 | //
|
| 56 |
|
| 57 | /**
|
| 58 | Reads an 8-bit I/O port.
|
| 59 |
|
| 60 | Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
|
| 61 | This function must guarantee that all I/O read and write operations are
|
| 62 | serialized.
|
| 63 |
|
| 64 | If 8-bit I/O port operations are not supported, then ASSERT().
|
| 65 |
|
| 66 | @param Port The I/O port to read.
|
| 67 |
|
| 68 | @return The value read.
|
| 69 |
|
| 70 | **/
|
| 71 | UINT8
|
| 72 | EFIAPI
|
| 73 | IoRead8 (
|
| 74 | IN UINTN Port
|
| 75 | )
|
| 76 | {
|
| 77 | UINT8 Value;
|
| 78 |
|
| 79 | _ReadWriteBarrier ();
|
| 80 | Value = (UINT8)_inp ((UINT16)Port);
|
| 81 | _ReadWriteBarrier ();
|
| 82 | return Value;
|
| 83 | }
|
| 84 |
|
| 85 | /**
|
| 86 | Writes an 8-bit I/O port.
|
| 87 |
|
| 88 | Writes the 8-bit I/O port specified by Port with the value specified by Value
|
| 89 | and returns Value. This function must guarantee that all I/O read and write
|
| 90 | operations are serialized.
|
| 91 |
|
| 92 | If 8-bit I/O port operations are not supported, then ASSERT().
|
| 93 |
|
| 94 | @param Port The I/O port to write.
|
| 95 | @param Value The value to write to the I/O port.
|
| 96 |
|
| 97 | @return The value written the I/O port.
|
| 98 |
|
| 99 | **/
|
| 100 | UINT8
|
| 101 | EFIAPI
|
| 102 | IoWrite8 (
|
| 103 | IN UINTN Port,
|
| 104 | IN UINT8 Value
|
| 105 | )
|
| 106 | {
|
| 107 | _ReadWriteBarrier ();
|
| 108 | (UINT8)_outp ((UINT16)Port, Value);
|
| 109 | _ReadWriteBarrier ();
|
| 110 | return Value;
|
| 111 | }
|
| 112 |
|
| 113 | /**
|
| 114 | Reads a 16-bit I/O port.
|
| 115 |
|
| 116 | Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
|
| 117 | This function must guarantee that all I/O read and write operations are
|
| 118 | serialized.
|
| 119 |
|
| 120 | If 16-bit I/O port operations are not supported, then ASSERT().
|
| 121 |
|
| 122 | @param Port The I/O port to read.
|
| 123 |
|
| 124 | @return The value read.
|
| 125 |
|
| 126 | **/
|
| 127 | UINT16
|
| 128 | EFIAPI
|
| 129 | IoRead16 (
|
| 130 | IN UINTN Port
|
| 131 | )
|
| 132 | {
|
| 133 | UINT16 Value;
|
| 134 |
|
| 135 | ASSERT ((Port & 1) == 0);
|
| 136 | _ReadWriteBarrier ();
|
| 137 | Value = _inpw ((UINT16)Port);
|
| 138 | _ReadWriteBarrier ();
|
| 139 | return Value;
|
| 140 | }
|
| 141 |
|
| 142 | /**
|
| 143 | Writes a 16-bit I/O port.
|
| 144 |
|
| 145 | Writes the 16-bit I/O port specified by Port with the value specified by Value
|
| 146 | and returns Value. This function must guarantee that all I/O read and write
|
| 147 | operations are serialized.
|
| 148 |
|
| 149 | If 16-bit I/O port operations are not supported, then ASSERT().
|
| 150 |
|
| 151 | @param Port The I/O port to write.
|
| 152 | @param Value The value to write to the I/O port.
|
| 153 |
|
| 154 | @return The value written the I/O port.
|
| 155 |
|
| 156 | **/
|
| 157 | UINT16
|
| 158 | EFIAPI
|
| 159 | IoWrite16 (
|
| 160 | IN UINTN Port,
|
| 161 | IN UINT16 Value
|
| 162 | )
|
| 163 | {
|
| 164 | ASSERT ((Port & 1) == 0);
|
| 165 | _ReadWriteBarrier ();
|
| 166 | _outpw ((UINT16)Port, Value);
|
| 167 | _ReadWriteBarrier ();
|
| 168 | return Value;
|
| 169 | }
|
| 170 |
|
| 171 | /**
|
| 172 | Reads a 32-bit I/O port.
|
| 173 |
|
| 174 | Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
|
| 175 | This function must guarantee that all I/O read and write operations are
|
| 176 | serialized.
|
| 177 |
|
| 178 | If 32-bit I/O port operations are not supported, then ASSERT().
|
| 179 |
|
| 180 | @param Port The I/O port to read.
|
| 181 |
|
| 182 | @return The value read.
|
| 183 |
|
| 184 | **/
|
| 185 | UINT32
|
| 186 | EFIAPI
|
| 187 | IoRead32 (
|
| 188 | IN UINTN Port
|
| 189 | )
|
| 190 | {
|
| 191 | UINT32 Value;
|
| 192 |
|
| 193 | ASSERT ((Port & 3) == 0);
|
| 194 | _ReadWriteBarrier ();
|
| 195 | Value = _inpd ((UINT16)Port);
|
| 196 | _ReadWriteBarrier ();
|
| 197 | return Value;
|
| 198 | }
|
| 199 |
|
| 200 | /**
|
| 201 | Writes a 32-bit I/O port.
|
| 202 |
|
| 203 | Writes the 32-bit I/O port specified by Port with the value specified by Value
|
| 204 | and returns Value. This function must guarantee that all I/O read and write
|
| 205 | operations are serialized.
|
| 206 |
|
| 207 | If 32-bit I/O port operations are not supported, then ASSERT().
|
| 208 |
|
| 209 | @param Port The I/O port to write.
|
| 210 | @param Value The value to write to the I/O port.
|
| 211 |
|
| 212 | @return The value written the I/O port.
|
| 213 |
|
| 214 | **/
|
| 215 | UINT32
|
| 216 | EFIAPI
|
| 217 | IoWrite32 (
|
| 218 | IN UINTN Port,
|
| 219 | IN UINT32 Value
|
| 220 | )
|
| 221 | {
|
| 222 | ASSERT ((Port & 3) == 0);
|
| 223 | _ReadWriteBarrier ();
|
| 224 | _outpd ((UINT16)Port, Value);
|
| 225 | _ReadWriteBarrier ();
|
| 226 | return Value;
|
| 227 | }
|
| 228 |
|
| 229 |
|
| 230 | /**
|
| 231 | Reads an 8-bit MMIO register.
|
| 232 |
|
| 233 | Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
|
| 234 | returned. This function must guarantee that all MMIO read and write
|
| 235 | operations are serialized.
|
| 236 |
|
| 237 | If 8-bit MMIO register operations are not supported, then ASSERT().
|
| 238 |
|
| 239 | @param Address The MMIO register to read.
|
| 240 |
|
| 241 | @return The value read.
|
| 242 |
|
| 243 | **/
|
| 244 | UINT8
|
| 245 | EFIAPI
|
| 246 | MmioRead8 (
|
| 247 | IN UINTN Address
|
| 248 | )
|
| 249 | {
|
| 250 | UINT8 Value;
|
| 251 |
|
| 252 | Value = *(volatile UINT8*)Address;
|
| 253 | return Value;
|
| 254 | }
|
| 255 |
|
| 256 | /**
|
| 257 | Writes an 8-bit MMIO register.
|
| 258 |
|
| 259 | Writes the 8-bit MMIO register specified by Address with the value specified
|
| 260 | by Value and returns Value. This function must guarantee that all MMIO read
|
| 261 | and write operations are serialized.
|
| 262 |
|
| 263 | If 8-bit MMIO register operations are not supported, then ASSERT().
|
| 264 |
|
| 265 | @param Address The MMIO register to write.
|
| 266 | @param Value The value to write to the MMIO register.
|
| 267 |
|
| 268 | **/
|
| 269 | UINT8
|
| 270 | EFIAPI
|
| 271 | MmioWrite8 (
|
| 272 | IN UINTN Address,
|
| 273 | IN UINT8 Value
|
| 274 | )
|
| 275 | {
|
| 276 | return *(volatile UINT8*)Address = Value;
|
| 277 | }
|
| 278 |
|
| 279 | /**
|
| 280 | Reads a 16-bit MMIO register.
|
| 281 |
|
| 282 | Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
|
| 283 | returned. This function must guarantee that all MMIO read and write
|
| 284 | operations are serialized.
|
| 285 |
|
| 286 | If 16-bit MMIO register operations are not supported, then ASSERT().
|
| 287 |
|
| 288 | @param Address The MMIO register to read.
|
| 289 |
|
| 290 | @return The value read.
|
| 291 |
|
| 292 | **/
|
| 293 | UINT16
|
| 294 | EFIAPI
|
| 295 | MmioRead16 (
|
| 296 | IN UINTN Address
|
| 297 | )
|
| 298 | {
|
| 299 | UINT16 Value;
|
| 300 |
|
| 301 | ASSERT ((Address & 1) == 0);
|
| 302 | Value = *(volatile UINT16*)Address;
|
| 303 | return Value;
|
| 304 | }
|
| 305 |
|
| 306 | /**
|
| 307 | Writes a 16-bit MMIO register.
|
| 308 |
|
| 309 | Writes the 16-bit MMIO register specified by Address with the value specified
|
| 310 | by Value and returns Value. This function must guarantee that all MMIO read
|
| 311 | and write operations are serialized.
|
| 312 |
|
| 313 | If 16-bit MMIO register operations are not supported, then ASSERT().
|
| 314 |
|
| 315 | @param Address The MMIO register to write.
|
| 316 | @param Value The value to write to the MMIO register.
|
| 317 |
|
| 318 | **/
|
| 319 | UINT16
|
| 320 | EFIAPI
|
| 321 | MmioWrite16 (
|
| 322 | IN UINTN Address,
|
| 323 | IN UINT16 Value
|
| 324 | )
|
| 325 | {
|
| 326 | ASSERT ((Address & 1) == 0);
|
| 327 | return *(volatile UINT16*)Address = Value;
|
| 328 | }
|
| 329 |
|
| 330 | /**
|
| 331 | Reads a 32-bit MMIO register.
|
| 332 |
|
| 333 | Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
|
| 334 | returned. This function must guarantee that all MMIO read and write
|
| 335 | operations are serialized.
|
| 336 |
|
| 337 | If 32-bit MMIO register operations are not supported, then ASSERT().
|
| 338 |
|
| 339 | @param Address The MMIO register to read.
|
| 340 |
|
| 341 | @return The value read.
|
| 342 |
|
| 343 | **/
|
| 344 | UINT32
|
| 345 | EFIAPI
|
| 346 | MmioRead32 (
|
| 347 | IN UINTN Address
|
| 348 | )
|
| 349 | {
|
| 350 | UINT32 Value;
|
| 351 |
|
| 352 | ASSERT ((Address & 3) == 0);
|
| 353 | Value = *(volatile UINT32*)Address;
|
| 354 | return Value;
|
| 355 | }
|
| 356 |
|
| 357 | /**
|
| 358 | Writes a 32-bit MMIO register.
|
| 359 |
|
| 360 | Writes the 32-bit MMIO register specified by Address with the value specified
|
| 361 | by Value and returns Value. This function must guarantee that all MMIO read
|
| 362 | and write operations are serialized.
|
| 363 |
|
| 364 | If 32-bit MMIO register operations are not supported, then ASSERT().
|
| 365 |
|
| 366 | @param Address The MMIO register to write.
|
| 367 | @param Value The value to write to the MMIO register.
|
| 368 |
|
| 369 | **/
|
| 370 | UINT32
|
| 371 | EFIAPI
|
| 372 | MmioWrite32 (
|
| 373 | IN UINTN Address,
|
| 374 | IN UINT32 Value
|
| 375 | )
|
| 376 | {
|
| 377 | ASSERT ((Address & 3) == 0);
|
| 378 | return *(volatile UINT32*)Address = Value;
|
| 379 | }
|
| 380 |
|
| 381 | /**
|
| 382 | Reads a 64-bit MMIO register.
|
| 383 |
|
| 384 | Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
|
| 385 | returned. This function must guarantee that all MMIO read and write
|
| 386 | operations are serialized.
|
| 387 |
|
| 388 | If 64-bit MMIO register operations are not supported, then ASSERT().
|
| 389 |
|
| 390 | @param Address The MMIO register to read.
|
| 391 |
|
| 392 | @return The value read.
|
| 393 |
|
| 394 | **/
|
| 395 | UINT64
|
| 396 | EFIAPI
|
| 397 | MmioRead64 (
|
| 398 | IN UINTN Address
|
| 399 | )
|
| 400 | {
|
| 401 | UINT64 Value;
|
| 402 |
|
| 403 | ASSERT ((Address & 7) == 0);
|
| 404 | Value = *(volatile UINT64*)Address;
|
| 405 | return Value;
|
| 406 | }
|
| 407 |
|
| 408 | /**
|
| 409 | Writes a 64-bit MMIO register.
|
| 410 |
|
| 411 | Writes the 64-bit MMIO register specified by Address with the value specified
|
| 412 | by Value and returns Value. This function must guarantee that all MMIO read
|
| 413 | and write operations are serialized.
|
| 414 |
|
| 415 | If 64-bit MMIO register operations are not supported, then ASSERT().
|
| 416 |
|
| 417 | @param Address The MMIO register to write.
|
| 418 | @param Value The value to write to the MMIO register.
|
| 419 |
|
| 420 | **/
|
| 421 | UINT64
|
| 422 | EFIAPI
|
| 423 | MmioWrite64 (
|
| 424 | IN UINTN Address,
|
| 425 | IN UINT64 Value
|
| 426 | )
|
| 427 | {
|
| 428 | ASSERT ((Address & 7) == 0);
|
| 429 | return *(volatile UINT64*)Address = Value;
|
| 430 | }
|
| 431 |
|