blob: 6cce4f1b50a244062e14c179e4992c50460f1c73 [file] [log] [blame]
Frank Vibrans2b4c8312011-02-14 18:30:54 +00001/**
2 * @file
3 *
4 * Southbridge PMIO access common routine
5 *
6 */
7/*
8 *****************************************************************************
9 *
10 * Copyright (c) 2011, Advanced Micro Devices, Inc.
11 * All rights reserved.
Edward O'Callaghanef5981b2014-07-06 19:20:52 +100012 *
Frank Vibrans2b4c8312011-02-14 18:30:54 +000013 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions are met:
15 * * Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * * Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
Edward O'Callaghanef5981b2014-07-06 19:20:52 +100020 * * Neither the name of Advanced Micro Devices, Inc. nor the names of
21 * its contributors may be used to endorse or promote products derived
Frank Vibrans2b4c8312011-02-14 18:30:54 +000022 * from this software without specific prior written permission.
Edward O'Callaghanef5981b2014-07-06 19:20:52 +100023 *
Frank Vibrans2b4c8312011-02-14 18:30:54 +000024 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY
28 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Edward O'Callaghanef5981b2014-07-06 19:20:52 +100034 *
Frank Vibrans2b4c8312011-02-14 18:30:54 +000035 * ***************************************************************************
36 *
37 */
38
39#include "SBPLATFORM.h"
40#include "cbtypes.h"
41
42/*----------------------------------------------------------------------------------------*/
43/**
44 * Read PMIO
45 *
46 *
47 *
48 * @param[in] Address - PMIO Offset value
49 * @param[in] OpFlag - Access sizes
50 * @param[in] Value - Read Data Buffer
51 *
52 */
53VOID
54ReadPMIO (
55 IN UINT8 Address,
56 IN UINT8 OpFlag,
57 IN VOID* Value
58 )
59{
60 UINT8 i;
61 OpFlag = OpFlag & 0x7f;
62
63 if ( OpFlag == 0x02 ) {
64 OpFlag = 0x03;
65 }
66 for ( i = 0; i <= OpFlag; i++ ) {
67 WriteIO (0xCD6, AccWidthUint8, &Address); // SB_IOMAP_REGCD6
68 Address++;
69 ReadIO (0xCD7, AccWidthUint8, (UINT8 *)Value + i); // SB_IOMAP_REGCD7
70 }
71}
72
73/*----------------------------------------------------------------------------------------*/
74/**
75 * Write PMIO
76 *
77 *
78 *
79 * @param[in] Address - PMIO Offset value
80 * @param[in] OpFlag - Access sizes
81 * @param[in] Value - Write Data Buffer
82 *
83 */
84VOID
85WritePMIO (
86 IN UINT8 Address,
87 IN UINT8 OpFlag,
88 IN VOID* Value
89 )
90{
91 UINT8 i;
92 OpFlag = OpFlag & 0x7f;
93
94 if ( OpFlag == 0x02 ) {
95 OpFlag = 0x03;
96 }
97 for ( i = 0; i <= OpFlag; i++ ) {
98 WriteIO (0xCD6, AccWidthUint8, &Address); // SB_IOMAP_REGCD6
99 Address++;
100 WriteIO (0xCD7, AccWidthUint8, (UINT8 *)Value + i); // SB_IOMAP_REGCD7
101 }
102}
103
104/*----------------------------------------------------------------------------------------*/
105/**
106 * RWPMIO - Read/Write PMIO
107 *
108 *
109 *
110 * @param[in] Address - PMIO Offset value
111 * @param[in] OpFlag - Access sizes
112 * @param[in] AndMask - Data And Mask 32 bits
113 * @param[in] OrMask - Data OR Mask 32 bits
114 *
115 */
116VOID
117RWPMIO (
118 IN UINT8 Address,
119 IN UINT8 OpFlag,
120 IN UINT32 AndMask,
121 IN UINT32 OrMask
122 )
123{
124 UINT32 Result;
125 OpFlag = OpFlag & 0x7f;
126 ReadPMIO (Address, OpFlag, &Result);
127 Result = (Result & AndMask) | OrMask;
128 WritePMIO (Address, OpFlag, &Result);
129}