summaryrefslogtreecommitdiff
path: root/cpu/amd/geode_lx/gplvsa_ii/sysmgr/mbiu.c
blob: 4a35388f5f218e320930e0d64e680b1e450c96f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
* Copyright (c) 2006-2008 Advanced Micro Devices,Inc. ("AMD").
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of the
* License, or (at your option) any later version.
*
* This code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.

* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA 
*/

//*	 Function:                                                          *
//*    Utility routines for managing MBIUs  


#include "VSA2.H"
#include "PROTOS.H"
#include "GX2.H"
#include "VPCI.H"
#include "DESCR.H"
#include "SYSMGR.H"


extern void InitStatCounters(ULONG, UCHAR);


// External variables:
extern ULONG Mbiu0;

// Local variables:
ULONG ExtendedMemoryDescr0, ExtendedMemoryDescr1 = 0;
MBIU_INFO MbiuInfo[MAX_MBIU];
UCHAR NumMbius=0;





//***********************************************************************
// Called once for each MBIU:
// - Initializes statistic counters
// - Records all available descriptors
//***********************************************************************
void pascal Init_MBIU(UCHAR * CountPtr, ULONG Msr)
{ UCHAR Type, i;
  ULONG Default[2], MsrData[2];


  // Record info about MBIU
  MbiuInfo[NumMbius].Mbiu = Msr;
  MbiuInfo[NumMbius].SubtrPid = Read_MSR_LO(Msr + MBD_MSR_CONFIG) << 29;
  MbiuInfo[NumMbius].NumCounters = ((CAPABILITIES *)CountPtr)->NSTATS;
  MbiuInfo[NumMbius].ActiveCounters = 0x00;
  MbiuInfo[NumMbius].ClockGating = Read_MSR_LO(Msr + MBD_MSR_PM);

  // Clear SMIs on this MBIU & disable all events except HW Emulation
  MsrData[0] = 0x0000000E;
  MsrData[1] = 0x0000000F;
  (USHORT)Msr = MBD_MSR_SMI;
  Write_MSR(Msr, MsrData);

  //*********************************************
  // Initialize Statistics MSRs
  //*********************************************
  InitStatCounters(Msr, ((CAPABILITIES *)CountPtr)->NSTATS);

  //*********************************************
  // Begin with P2D_BM descriptors
  //*********************************************
  Type = P2D_BM;
  (USHORT)Msr = MSR_MEM_DESCR;

  do {

    // Get number of next type of descriptor     
    if (i = *(CountPtr++)) {

      // Get the default value for this descriptor type
      Get_Descriptor_Default(Type, Default);

      // Loop through all descriptors of a given type
      do {

        // If descriptor is already in use by the BIOS, skip it
        Read_MSR(Msr, MsrData);
        if ((MsrData[0] == Default[0]) && (MsrData[1] == Default[1])) {

          // Initialize Descriptor[] entry
          if (Init_Descr(Type, Msr)) {
            // Not enough table entries...abort
            Type = 0x99;
            break;
          }

        } else {
          // Descriptor is in use.
          // If it's an extended memory descriptor, record the routing address.
          if (Type == P2D_R) {
            if ((Msr & ROUTING) == Mbiu0) {
              ExtendedMemoryDescr0 = Msr;
            } else {
              ExtendedMemoryDescr1 = Msr;
            }
          }
        }
        Msr++;
      } while (--i);
    }          

    // Check next descriptor type.
    // If transitioning from P2D to IOD descriptors...
	if (++Type == IOD_BM) {
      // change MSR offset to 0xE0
      (USHORT)Msr = MSR_IO_DESCR;
    }
  } while (Type <= IOD_SC);

  // Increment number of MBIUs
  NumMbius++;
}