summaryrefslogtreecommitdiff
path: root/arch/arm/cpu/arm926ejs/aspeed/LIB.c
blob: f2a0c54637434c120aa5895437c9a73e7717cfd8 (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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*
 *  This program 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 General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
#define LIB_C
static const char ThisFile[] = "LIB.c";

#include "SWFUNC.H"

#ifdef SLT_UBOOT
  #include <common.h>
  #include <command.h>
#endif
#ifdef SLT_DOS
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <conio.h>
#include <dos.h>
#include <mem.h>
#endif

#include "LIB.H"
#include "TYPEDEF.H"

#ifdef USE_P2A
//------------------------------------------------------------
// PCI
//------------------------------------------------------------
ULONG ReadPCIReg (ULONG ulPCIConfigAddress, BYTE jOffest, ULONG ulMask)
{
#ifndef Windows
    OUTDWPORT(0xcf8, ulPCIConfigAddress + jOffest);

    return (((ULONG)INDWPORT(0xcfc)) & ulMask);
#else
    WRITE_PORT_ULONG((PULONG)0xcf8, ulPCIConfigAddress + jOffest);
    
    return (READ_PORT_ULONG((PULONG)0xcfc) & ulMask);
#endif
}

//------------------------------------------------------------
VOID WritePCIReg (ULONG ulPCIConfigAddress, BYTE jOffest, ULONG ulMask, ULONG ulData)
{
#ifndef Windows
    OUTDWPORT(0xcf8, ulPCIConfigAddress + jOffest);
    OUTDWPORT(0xcfc, (INDWPORT(0xcfc) & ulMask | ulData));
#else
    WRITE_PORT_ULONG((PULONG)0xcf8, ulPCIConfigAddress + jOffest);
    WRITE_PORT_ULONG((PULONG)0xcfc, (READ_PORT_ULONG((PULONG)0xcfc) & ulMask | ulData));
#endif
}

//------------------------------------------------------------
ULONG FindPCIDevice (USHORT usVendorID, USHORT usDeviceID, USHORT usBusType)
{
//Return: ulPCIConfigAddress
//usBusType: ACTIVE/PCI/AGP/PCI-E

    ULONG   Base[256];
    ULONG   ebx;
    USHORT  i;
    USHORT  j;
    
    for (i = 0; i < 256; i++) {
        Base[i] = 0x80000000 + 0x10000 * i;
    }
    
    if (usBusType == PCI)
    {
      ebx = 0x80000000;
    }
    else if (usBusType == PCIE)
    {
      ebx = 0x80020000;
    }
    else     // AGP and ACTIVE
    {
      ebx = 0x80010000;
    }
    
    if ( usBusType != ACTIVE )    //AGP, PCI, PCIE
    {
      for (i = 0; i < 32; i++)
      {
        ebx = ebx + (0x800);
        if (((USHORT)ReadPCIReg(ebx, 0, 0xffff) == usVendorID) && ((USHORT)(ReadPCIReg(ebx, 0, 0xffff0000) >> 16) == usDeviceID))
        {
          return ebx;
        }
      }
      return 0;
    }
    else     //ACTIVE
    {
      for (j = 0; j < 256; j++)
      {
        ebx = Base[j];
        for (i = 0; i < 32; i++)
        {
          ebx = ebx + (0x800);
          if (((USHORT)ReadPCIReg(ebx, 0, 0xffff) == usVendorID) && ((USHORT)(ReadPCIReg(ebx, 0, 0xffff0000) >> 16) == usDeviceID))
          {
            return ebx;
          }
        }
      }
      return 0;
    }
} // End ULONG FindPCIDevice (USHORT usVendorID, USHORT usDeviceID, USHORT usBusType)
#endif
//------------------------------------------------------------
// Allocate Resource
//------------------------------------------------------------
#ifdef SLT_DOS
ULONG InitDOS32()
{
  union REGS regs ;

  regs.w.ax = 0xee00;
  INTFUNC(0x31, &regs, &regs) ;

  if(regs.w.ax >= 0x301)    // DOS32 version >= 3.01 ?
    return 1;
  else
    return 0;
}

//------------------------------------------------------------
USHORT CheckDOS()
{
    union REGS  regs;

    regs.w.ax = 0xeeff;
    int386(0x31, &regs, &regs);
    if (regs.x.eax == 0x504d4457)
    {
        return 0;
    } else {
        printf("PMODEW Init. fail\n");
        return 1;
    }
}

//------------------------------------------------------------
ULONG MapPhysicalToLinear (ULONG ulBaseAddress, ULONG ulSize)
{
  union REGS regs;

  regs.w.ax = 0x0800;                        // map physcial memory
  regs.w.bx = ulBaseAddress >> 16;           // bx:cx = physical address
  regs.w.cx = ulBaseAddress;
  regs.w.si = ulSize >> 16;                  // si:di = mapped memory block size
  regs.w.di = ulSize;
  INTFUNC(0x31, &regs, &regs);               // int386(0x31, &regs, &regs);
  if (regs.w.cflag == 0)
    return (ULONG) (regs.w.bx << 16 + regs.w.cx);  // Linear Addr = bx:cx
  else
    return 0;
}

//------------------------------------------------------------
USHORT FreePhysicalMapping(ULONG udwLinAddress)
{
    union REGS regs;

    regs.w.ax = 0x0801;
    regs.w.bx = udwLinAddress >> 16;
    regs.w.cx = udwLinAddress & 0xFFFF;
    int386(0x31, &regs, &regs);

    if (regs.x.cflag)
        return ((USHORT) 0);
    else return ((USHORT) 1);
}
#endif