Frank Vibrans | 2b4c831 | 2011-02-14 18:30:54 +0000 | [diff] [blame] | 1 | /** |
| 2 | * @file |
| 3 | * |
| 4 | * Southbridge IO access common routine |
| 5 | * |
| 6 | * |
| 7 | * |
| 8 | * @xrefitem bom "File Content Label" "Release Content" |
| 9 | * @e project: CIMx-SB |
| 10 | * @e sub-project: |
| 11 | * @e \$Revision:$ @e \$Date:$ |
| 12 | * |
| 13 | */ |
| 14 | /* |
| 15 | ***************************************************************************** |
| 16 | * |
| 17 | * Copyright (c) 2011, Advanced Micro Devices, Inc. |
| 18 | * All rights reserved. |
Edward O'Callaghan | ef5981b | 2014-07-06 19:20:52 +1000 | [diff] [blame] | 19 | * |
Frank Vibrans | 2b4c831 | 2011-02-14 18:30:54 +0000 | [diff] [blame] | 20 | * Redistribution and use in source and binary forms, with or without |
| 21 | * modification, are permitted provided that the following conditions are met: |
| 22 | * * Redistributions of source code must retain the above copyright |
| 23 | * notice, this list of conditions and the following disclaimer. |
| 24 | * * Redistributions in binary form must reproduce the above copyright |
| 25 | * notice, this list of conditions and the following disclaimer in the |
| 26 | * documentation and/or other materials provided with the distribution. |
Edward O'Callaghan | ef5981b | 2014-07-06 19:20:52 +1000 | [diff] [blame] | 27 | * * Neither the name of Advanced Micro Devices, Inc. nor the names of |
| 28 | * its contributors may be used to endorse or promote products derived |
Frank Vibrans | 2b4c831 | 2011-02-14 18:30:54 +0000 | [diff] [blame] | 29 | * from this software without specific prior written permission. |
Edward O'Callaghan | ef5981b | 2014-07-06 19:20:52 +1000 | [diff] [blame] | 30 | * |
Frank Vibrans | 2b4c831 | 2011-02-14 18:30:54 +0000 | [diff] [blame] | 31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 32 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 33 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 34 | * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY |
| 35 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 36 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 37 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 38 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 39 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 40 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Edward O'Callaghan | ef5981b | 2014-07-06 19:20:52 +1000 | [diff] [blame] | 41 | * |
Frank Vibrans | 2b4c831 | 2011-02-14 18:30:54 +0000 | [diff] [blame] | 42 | * *************************************************************************** |
| 43 | * |
| 44 | */ |
| 45 | |
| 46 | #include "SBPLATFORM.h" |
| 47 | #include "cbtypes.h" |
| 48 | |
| 49 | /*----------------------------------------------------------------------------------------*/ |
| 50 | /** |
| 51 | * SbStall - Delay routine |
| 52 | * |
| 53 | * |
| 54 | * |
| 55 | * @param[in] uSec |
| 56 | * |
| 57 | */ |
| 58 | VOID |
| 59 | SbStall ( |
| 60 | IN UINT32 uSec |
| 61 | ) |
| 62 | { |
| 63 | UINT16 timerAddr; |
| 64 | UINT32 startTime; |
| 65 | UINT32 elapsedTime; |
| 66 | |
| 67 | ReadMEM (ACPI_MMIO_BASE + PMIO_BASE + SB_PMIOA_REG64, AccWidthUint16, &timerAddr); |
| 68 | if ( timerAddr == 0 ) { |
| 69 | uSec = uSec / 2; |
| 70 | while ( uSec != 0 ) { |
| 71 | ReadIO (0x80, AccWidthUint8, (UINT8 *) (&startTime)); |
| 72 | uSec--; |
| 73 | } |
| 74 | } else { |
| 75 | ReadIO (timerAddr, AccWidthUint32, &startTime); |
| 76 | for ( ;; ) { |
| 77 | ReadIO (timerAddr, AccWidthUint32, &elapsedTime); |
| 78 | if ( elapsedTime < startTime ) { |
| 79 | elapsedTime = elapsedTime + 0xFFFFFFFF - startTime; |
| 80 | } else { |
| 81 | elapsedTime = elapsedTime - startTime; |
| 82 | } |
| 83 | if ( (elapsedTime * 28 / 100) > uSec ) { |
| 84 | break; |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | /*----------------------------------------------------------------------------------------*/ |
| 91 | /** |
| 92 | * SbReset - Generate a reset command |
| 93 | * |
| 94 | * |
| 95 | * |
| 96 | * @param[in] OpFlag - Dummy |
| 97 | * |
| 98 | */ |
| 99 | VOID |
| 100 | SbReset ( |
| 101 | IN UINT8 OpFlag |
| 102 | ) |
| 103 | { |
Frank Vibrans | 2b4c831 | 2011-02-14 18:30:54 +0000 | [diff] [blame] | 104 | RWIO (0xcf9, AccWidthUint8, 0x0, 0x06); |
| 105 | } |
| 106 | |
| 107 | /*----------------------------------------------------------------------------------------*/ |
| 108 | /** |
| 109 | * outPort80 - Send data to PORT 80 (debug port) |
| 110 | * |
| 111 | * |
| 112 | * |
| 113 | * @param[in] pcode - debug code (32 bits) |
| 114 | * |
| 115 | */ |
| 116 | VOID |
| 117 | outPort80 ( |
| 118 | IN UINT32 pcode |
| 119 | ) |
| 120 | { |
| 121 | WriteIO (0x80, AccWidthUint8, &pcode); |
| 122 | return; |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * AmdSbCopyMem - Memory copy |
| 127 | * |
| 128 | * @param[in] pDest - Destance address point |
| 129 | * @param[in] pSource - Source Address point |
| 130 | * @param[in] Length - Data length |
| 131 | * |
| 132 | */ |
| 133 | VOID |
| 134 | AmdSbCopyMem ( |
| 135 | IN VOID* pDest, |
| 136 | IN VOID* pSource, |
| 137 | IN UINTN Length |
| 138 | ) |
| 139 | { |
| 140 | UINTN i; |
| 141 | UINT8 *Ptr; |
| 142 | UINT8 *Source; |
| 143 | Ptr = (UINT8*)pDest; |
| 144 | Source = (UINT8*)pSource; |
| 145 | for (i = 0; i < Length; i++) { |
| 146 | *Ptr = *Source; |
| 147 | Source++; |
| 148 | Ptr++; |
| 149 | } |
| 150 | } |