OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [mips/] [idt79s334a/] [v2_0/] [src/] [plf_misc.c] - Blame information for rev 174

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
//==========================================================================
2
//
3
//      plf_misc.c
4
//
5
//      HAL platform miscellaneous functions
6
//
7
//==========================================================================
8
//####ECOSGPLCOPYRIGHTBEGIN####
9
// -------------------------------------------
10
// This file is part of eCos, the Embedded Configurable Operating System.
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
12
//
13
// eCos is free software; you can redistribute it and/or modify it under
14
// the terms of the GNU General Public License as published by the Free
15
// Software Foundation; either version 2 or (at your option) any later version.
16
//
17
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
19
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20
// for more details.
21
//
22
// You should have received a copy of the GNU General Public License along
23
// with eCos; if not, write to the Free Software Foundation, Inc.,
24
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25
//
26
// As a special exception, if other files instantiate templates or use macros
27
// or inline functions from this file, or you compile this file and link it
28
// with other works to produce a work based on this file, this file does not
29
// by itself cause the resulting work to be covered by the GNU General Public
30
// License. However the source code for this file must still be made available
31
// in accordance with section (3) of the GNU General Public License.
32
//
33
// This exception does not invalidate any other reasons why a work based on
34
// this file might be covered by the GNU General Public License.
35
//
36
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37
// at http://sources.redhat.com/ecos/ecos-license/
38
// -------------------------------------------
39
//####ECOSGPLCOPYRIGHTEND####
40
//==========================================================================
41
//#####DESCRIPTIONBEGIN####
42
//
43
// Author(s):    tmichals
44
// Contributors: 
45
// Date:         2002-09-01
46
// Purpose:      HAL miscellaneous functions
47
// Description:  This file contains miscellaneous functions provided by the
48
//               HAL.
49
//
50
//####DESCRIPTIONEND####
51
//
52
//========================================================================*/
53
 
54
#include <pkgconf/hal.h>
55
#include <pkgconf/system.h>
56
 
57
#include CYGBLD_HAL_PLATFORM_H
58
 
59
#include <cyg/infra/cyg_type.h>         // Base types
60
#include <cyg/infra/cyg_trac.h>         // tracing macros
61
#include <cyg/infra/cyg_ass.h>          // assertion macros
62
#include <cyg/hal/hal_arch.h>           // architectural definitions
63
#include <cyg/hal/hal_intr.h>           // Interrupt handling
64
#include <cyg/hal/hal_cache.h>          // Cache handling
65
 
66
/* This is the Reference board configuration */
67
#include <cyg/hal/idt79rc233x.h>
68
 
69
#include <cyg/io/pci_hw.h>
70
#include <cyg/io/pci.h>
71
 
72
void  hal_rc334PciInit (void);
73
static void mmuInit (void);
74
static void sysDisableBusError (void) ;
75
static void sysEnableBusError(void);
76
void   ecosPciConfigOutByte(  int busNo, int devFnNo,int regOffset,unsigned char data );
77
void   ecosPciConfigOutHalfWord( int busNo,int devFnNo,int regOffset,unsigned short data );
78
void   ecosPciConfigOutWord( int busNo,int devFnNo,int regOffset,unsigned int data );
79
unsigned char ecosPciConfigInByte(int busNo, int devFnNo,int regOffset);
80
unsigned short ecosPciConfigInHalfWord( int busNo,int devFnNo,int regOffset);
81
unsigned int ecosPciConfigInWord( int busNo, int devFnNo,int regOffset);
82
void displayLED(char *str, int count);
83
 
84
/*------------------------------------------------------------------------*/
85
 
86
  /* this is called from the kernel */
87
void hal_platform_init(void)
88
{
89
 
90
    HAL_ICACHE_INVALIDATE_ALL();
91
    HAL_ICACHE_ENABLE();
92
    HAL_DCACHE_INVALIDATE_ALL();
93
    HAL_DCACHE_ENABLE();
94
 
95
    displayLED("eCOS", 4);
96
    hal_if_init();
97
    mmuInit();
98
    hal_rc334PciInit();
99
}
100
 
101
 
102
 
103
/* PCI Configuration Registers */
104
#define  PCI_CFG_VENDORID         0x00
105
#define  PCI_CFG_DEVICEID         0x02
106
#define  PCI_CFG_COMMAND          0x04
107
#define  PCI_CFG_STATUS           0x06
108
#define  PCI_CFG_REVID            0x08 
109
#define  PCI_CFG_CLASS_CODE       0x09
110
#define  PCI_CFG_CACHELINE        0x0c
111
#define  PCI_CFG_LATENCY_TIMER    0x0d
112
#define  PCI_CFG_HEADER_TYPE      0x0e
113
#define  PCI_CFG_BIST             0x0f
114
#define  PCI_CFG_BAR0             0x10
115
#define  PCI_CFG_BAR1             0x14
116
#define  PCI_CFG_BAR2             0x18
117
#define  PCI_CFG_BAR3             0x1c
118
#define  PCI_CFG_BAR4             0x20
119
#define  PCI_CFG_BAR5             0x24
120
#define  PCI_CFG_CIS_POINTER      0x28
121
#define  PCI_CFG_SUB_VENDORID     0x2c
122
#define  PCI_CFG_SUB_SYSTEMID     0x2e
123
#define  PCI_CFG_EXP_ROM          0x30
124
#define  PCI_CFG_CAPABILITIES     0x34
125
#define  PCI_CFG_RESERVED1        0x35
126
#define  PCI_CFG_RESERVED2        0x38
127
#define  PCI_CFG_INT_LINE         0x3c
128
#define  PCI_CFG_INT_PIN          0x3d
129
#define  PCI_CFG_MIN_GRANT        0x3e
130
#define  PCI_CFG_MAX_LATENCY      0x3f
131
#define  PCI_CFG_TRDY_TIMEOUT     0x40
132
#define  PCI_CFG_RETRY_TIMEOUT    0x41
133
 
134
#define RC334_CONFIG0           0x80000000
135
/* Typical values used in this example */
136
#define RC334_PCI_CONFIG0 0x0204111D /* Device ID & Vendor ID */
137
#define RC334_PCI_CONFIG1       0x00200157   /* Command : MWINV, Enable bus master, 
138
                        memory I/O access       */
139
#define RC334_PCI_CONFIG2       0x06800001   /* Class Code & Revision ID */
140
#define RC334_PCI_CONFIG3       0x0000ff04   /* BIST, Header Type, Master Latency,
141
        Cache line size */
142
#define RC334_PCI_CONFIG4       0xA0000008    /* Memory Base Address Reg, prefetchable  */
143
#define RC334_PCI_CONFIG5       0x60000000    /* Integrated Controller Reg, non-prefetchable    */
144
#define RC334_PCI_CONFIG6       0x00800001    /* IO Base Address Reg      */
145
#define RC334_PCI_CONFIG7       0x00000000    /* Unused BAR space, assign some address 
146
        that never gets generated on PCI Bus      */
147
 
148
/* Reserved  registers */
149
#define RC334_PCI_CONFIG8       0x00000000
150
#define RC334_PCI_CONFIG9       0x00000000
151
#define RC334_PCI_CONFIG10      0x00000000
152
 
153
/* Subsystem ID and the subsystem Vendor ID */
154
#define RC334_PCI_CONFIG11      0x00000000
155
 
156
/* Reserved registers */
157
#define RC334_PCI_CONFIG12      0x00000000
158
#define RC334_PCI_CONFIG13      0x00000000
159
#define RC334_PCI_CONFIG14      0x00000000
160
 
161
/* Max latency, Min Grant, Interrupt pin and interrupt line */
162
#define RC334_PCI_CONFIG15      0x38080101
163
 
164
/* Retry timeout value, TRDY timeout value. Set to default 0x80 */
165
#define RC334_PCI_CONFIG16      0x00008080
166
 
167
/* Rc32334 specific PCI registers                  */
168
#define RC334_PCI_REG_BASE       0xb8000000
169
#define RC334_CPUTOPCI_BASE_REG1  (RC334_PCI_REG_BASE + 0x20B0)
170
#define RC334_CPUTOPCI_BASE_REG2  (RC334_PCI_REG_BASE + 0x20B8)
171
#define RC334_CPUTOPCI_BASE_REG3  (RC334_PCI_REG_BASE + 0x20C0)
172
#define RC334_CPUTOPCI_BASE_REG4    (RC334_PCI_REG_BASE + 0x20C8)
173
 
174
#define RC334_PCI_ARB_REG   (RC334_PCI_REG_BASE + 0x20E0)
175
#define RC334_PCITOCPU__BASE_REG1  (RC334_PCI_REG_BASE + 0x20E8)
176
#define RC334_PCITOCPU__BASE_REG2   (RC334_PCI_REG_BASE + 0x20F4)
177
#define RC334_PCITOCPU__BASE_REG3   (RC334_PCI_REG_BASE + 0x2100)
178
#define RC334_PCITOCPU__BASE_REG4   (RC334_PCI_REG_BASE + 0x210C)
179
 
180
/* Considering a typical case  */
181
#define CPUTOPCI_BASE_REG1_VAL      0x40000001
182
#define CPUTOPCI_BASE_REG2_VAL      0x00000000
183
#define CPUTOPCI_BASE_REG3_VAL      0x00000000
184
#define CPUTOPCI_BASE_REG4_VAL      0x18800001 
185
 
186
//TCM#define PCITOCPU_BASE_REG3_VAL      0x00000000
187
//TCM#define PCITOCPU_BASE_REG4_VAL      0x18000051    /*    Size field set to 0x14 : 1MB size    */
188
 
189
#define  RC334_PCITOCPU_BASE_REG1           (RC334_PCI_REG_BASE+0x20E8)
190
#define  RC334_PCITOCPU_BASE_REG2           (RC334_PCI_REG_BASE+0x20F4)
191
#define  RC334_PCITOCPU_BASE_REG3           (RC334_PCI_REG_BASE+0x2100)
192
#define  RC334_PCITOCPU_BASE_REG4           (RC334_PCI_REG_BASE+0x210C)
193
 
194
#define  PCITOCPU_MEM_BASE(addr)  ( (addr & 0xFFFFFF)<<8)
195
#define  PCITOCPU_SIZE(i)                      ( ( i & 0x1F) << 2 )
196
#define  PCITOCPU_EN_SWAP                 1
197
 
198
#define  SIZE_1MB                                      0x14
199
#define  SIZE_64MB                                    0x1A
200
 
201
#define SYS_MEM_BASE                          0x0              /* local sdram starting address */
202
#define RC32334_INT_REG_BASE           0x18000000 /* Integrated controller's internal registers */
203
 
204
/* PCI Target Control Register is provided in the RC32334 to utilize
205
eager prefetches and reduce target disconnects and retries. In the
206
following example, an optimized value is picked that enables eager
207
prefetch for all BAR's, enables Memory Write and Memory Write and
208
Invalidate (MWMWI), uses threshold for target write FIFO of 8 words,
209
and sets disconnect and retry timer to 40 PCI clocks */
210
 
211
#define  PCI_TARGET_CONTROL_REG           0xB80020A4
212
#define  PCI_TARGET_CONTROL_REG_VAL       0x7EF02828
213
 
214
/* BAR1 is selected as memory base register with 64 Mbyte address
215
range starting at physical address 0x0000_0000, allowing external PCI
216
masters to access the local SDRAM for data read and write. This
217
register setting works with the BAR1 register in the PCI configuration
218
register in the PCI bridge of the RC32334 which, in this example, has
219
been set to 0xA000_0000. With the given settings, the external PCI
220
masters can access addresses in the range 0xA000_0000 through
221
0xA3FF_FFFF using BAR1 which gets translated to address range
222
0x0000_0000 through 0x03FF_FFFF on the local CPU bus owing to the
223
PCITOCPU_BASE_REG1 settings. */
224
 
225
#define  PCITOCPU_BASE_REG1_VAL   ((PCITOCPU_MEM_BASE(SYS_MEM_BASE)) | \
226
                                              (PCITOCPU_SIZE(SIZE_64MB) ) | \
227
                                              (PCITOCPU_EN_SWAP) )
228
 
229
/* BAR2 is selected as memory base register with 1 Mbyte range
230
starting at the physical address 0x1800_0000. This maps to the RC32334
231
internal registers allowing external PCI masters to read/modify the
232
RC32334 registers. In this example, the BAR2 register in the PCI
233
configuration register of the RC32334 PCI bridge has been set to
234
0xB800_0000 (note that this address is in the PCI space and should not
235
be confused with the CPU address map). External PCI masters can access
236
memory range 0xB800_0000 through 0xB80F_FFFF, sufficient enough to
237
access all the RC32334 internal registers. The PCITOCPU_BASE_REG2
238
settings map all PCI cycles falling in the above range to physical
239
address range 0x1800_0000 — 0x180F_FFFF on the local CPU bus.  */
240
 
241
#define  PCITOCPU_BASE_REG2_VAL   ((PCITOCPU_MEM_BASE(RC32334_INT_REG_BASE)) | \
242
                                              (PCITOCPU_SIZE(SIZE_1MB) ) | \
243
                                              (PCITOCPU_EN_SWAP) )
244
 
245
/* BAR3 is selected as IO base register with 1 Mbyte range mapped to
246
address 0x1800_0000, providing another window for accessing the
247
Integrated controller registers. In this example, the value for the
248
BAR3 has been picked as 0x0000_0000 (address range 0x0000_00000
249
through 0x000F_FFFF). Any PCI IO cycles to this address range would
250
get translated to local CPU address range of 0x1800_0000 through
251
0x180F_FFFF using this register settings. */
252
 
253
#define  PCITOCPU_BASE_REG3_VAL   (        \
254
                                              (PCITOCPU_MEM_BASE(RC32334_INT_REG_BASE)) | \
255
                                              (PCITOCPU_SIZE(SIZE_1MB) ) | \
256
                                              (PCITOCPU_EN_SWAP) )
257
 
258
/* BAR4 register is not used. Therefore, it can be disabled by selecting the SIZE value 1-7 */
259
#define  PCITOCPU_BASE_REG4_VAL     ( PCITOCPU_SIZE( 1 ) )
260
 
261
/* Arbitration register value:
262
   Target Ready, internal arbiter, fixed priority
263
*/
264
#define PCI_ARB_REG_VAL           0x00000001
265
 
266
/*  Rc32334 config address/data definitions  */
267
#define PCI_CONFIG_ADDR_REG      0xb8002cf8
268
#define PCI_CONFIG_DATA_REG      0xb8002cfc
269
 
270
/* BYTE SWAP macros */
271
#define HALF_WORD_SWAP(x) \
272
             (  ( ( x  << 8 ) & 0xff00)    |  \
273
                 ( (x  >> 8 ) & 0x00ff )  )
274
 
275
#define WORD_SWAP(x)\
276
             ( ( ( x << 24 )  & 0xff000000 ) |  \
277
                ( (x << 8   )  & 0x00ff0000 ) |  \
278
                ( (x >> 8   )  & 0x0000ff00 ) |  \
279
                ( (x >> 24 )  & 0x000000ff )    )
280
 
281
/* PCI Functions */
282
unsigned int   pciConfigInWord( int busNo, int devNo, int funcNo, int regOffset);
283
unsigned short pciConfigInHalfWord( int busNo, int devNo, int funcNo, int regOffset);
284
unsigned char pciConfigInByte( int busNo, int devNo, int funcNo, int regOffset);
285
void   pciConfigOutWord ( int busNo, int devNo, int funcNo, int regOffset, unsigned int data );
286
void   pciConfigOutHalfWord ( int busNo, int devNo, int funcNo, int regOffset, unsigned short data );
287
void   pciConfigOutChar ( int busNo, int devNo, int funcNo, int regOffset, unsigned char data );
288
 
289
/* Rc32334 Bus error register. The bit7 of this register can be used
290
to enable or disable the BusError. The bus error is disabled briefly
291
at the time of pci Scanning and enabled thereafter. */
292
 
293
#define  RC334_BUS_ERR_CNTL_REG  0xb8000010
294
 
295
/*
296
    Function name       : hal_rc334PciInit
297
    Parameters passed  : none
298
    return value       : none
299
    The function initialises the configuration registers of    Rc32334 PCI interface controller.
300
*/
301
void hal_rc334PciInit ( )
302
{
303
 
304
        unsigned int pciConfigData[17];
305
        int index                     ;
306
        volatile unsigned int *configAddrReg   ;
307
        volatile unsigned int *configDataReg   ;
308
        volatile unsigned int  *regPointer     ;
309
 
310
        configAddrReg  = (volatile unsigned int*) PCI_CONFIG_ADDR_REG;
311
        configDataReg  = (volatile unsigned int*) PCI_CONFIG_DATA_REG;
312
 
313
        pciConfigData[0]    = RC334_PCI_CONFIG0;
314
        pciConfigData[1]    = RC334_PCI_CONFIG1;
315
        pciConfigData[2]    = RC334_PCI_CONFIG2;
316
        pciConfigData[3]    = RC334_PCI_CONFIG3;
317
        pciConfigData[4]    = RC334_PCI_CONFIG4;
318
        pciConfigData[5]    = RC334_PCI_CONFIG5;
319
        pciConfigData[6]    = RC334_PCI_CONFIG6;
320
        pciConfigData[7]    = RC334_PCI_CONFIG7;
321
        pciConfigData[8]    = RC334_PCI_CONFIG8;
322
        pciConfigData[9]    = RC334_PCI_CONFIG9;
323
        pciConfigData[10]  = RC334_PCI_CONFIG10;
324
        pciConfigData[11]  = RC334_PCI_CONFIG11;
325
        pciConfigData[12]  = RC334_PCI_CONFIG12;
326
        pciConfigData[13]  = RC334_PCI_CONFIG13;
327
        pciConfigData[14]  = RC334_PCI_CONFIG14;
328
        pciConfigData[15]  = RC334_PCI_CONFIG15;
329
        pciConfigData[16]  = RC334_PCI_CONFIG16;
330
 
331
        *configAddrReg = (unsigned int)RC334_CONFIG0 ;
332
/*   This example writes to all the configuration registers. Some of
333
the PCI configuration registers (such as Device ID, Vendor ID, Class
334
Code, Revision ID, BIST, Header Type, Subsystem Vendor ID, Maximum
335
Latency, Minimum Grant, Interrupt Pin) need not be initialized */
336
 
337
        for (index =0; index <17; index++ )
338
                {
339
                *configDataReg = pciConfigData[index];
340
                *configAddrReg = *configAddrReg + 4;
341
                }
342
 
343
       /* Park the Address Register */
344
       configAddrReg = ( volatile unsigned int*)0x0 ;
345
 
346
/* Set Rc32334 specific registers */
347
 
348
regPointer = ( volatile unsigned int*)(RC334_CPUTOPCI_BASE_REG1) ;
349
*regPointer = (unsigned int)(CPUTOPCI_BASE_REG1_VAL );
350
 
351
regPointer = (volatile unsigned int*)(RC334_CPUTOPCI_BASE_REG2) ;
352
*regPointer = (unsigned int)(CPUTOPCI_BASE_REG2_VAL );
353
 
354
regPointer = (volatile unsigned int*)(RC334_CPUTOPCI_BASE_REG3) ;
355
*regPointer = (unsigned int)(CPUTOPCI_BASE_REG3_VAL );
356
 
357
regPointer = (volatile unsigned int*)(RC334_CPUTOPCI_BASE_REG4) ;
358
*regPointer = (unsigned int)(CPUTOPCI_BASE_REG4_VAL );
359
 
360
regPointer = (volatile unsigned int*)(RC334_PCITOCPU_BASE_REG1) ;
361
*regPointer = (unsigned int)(PCITOCPU_BASE_REG1_VAL );
362
 
363
regPointer = ( volatile unsigned int*)(RC334_PCITOCPU_BASE_REG2) ;
364
*regPointer = (unsigned int)(PCITOCPU_BASE_REG2_VAL );
365
 
366
regPointer = (volatile unsigned int*)(RC334_PCITOCPU_BASE_REG3) ;
367
*regPointer = (unsigned int)(PCITOCPU_BASE_REG3_VAL );
368
 
369
regPointer = (volatile unsigned int*)(RC334_PCITOCPU_BASE_REG4) ;
370
*regPointer = (unsigned int)(PCITOCPU_BASE_REG4_VAL );
371
 
372
regPointer = (volatile unsigned int*)PCI_TARGET_CONTROL_REG ;
373
*regPointer = (unsigned int)PCI_TARGET_CONTROL_REG_VAL ;
374
 
375
regPointer = (volatile unsigned int*)(RC334_PCI_ARB_REG);
376
*regPointer = (unsigned int)(PCI_ARB_REG_VAL);
377
 
378
}
379
 
380
/*     Function name :   sysDisableBusError
381
                         Disables the Bus Error prior to pciScan.
382
*/
383
static void sysDisableBusError (  ) {
384
        unsigned int*  regPointer ;
385
        unsigned int    data      ;
386
        regPointer = (unsigned int*) ( RC334_BUS_ERR_CNTL_REG);
387
        data       = *regPointer  ;
388
        /* Set bit7 to disable busError */
389
        data   =  data |  0x00000080 ;
390
        *regPointer = data ;
391
}
392
 
393
/*  Function name :   sysEnableBusError
394
                      Enables the Bus Error after pciScan
395
*/
396
static void sysEnableBusError (  ) {
397
        unsigned int*  regPointer ;
398
        unsigned int    data      ;
399
        regPointer = (unsigned int*) ( RC334_BUS_ERR_CNTL_REG);
400
        data       = *regPointer  ;
401
        /* Reset bit7 to enable busError */
402
        data   =  data & 0xffffff7f;
403
        *regPointer = data ;
404
}
405
 
406
 
407
 
408
 
409
#define TLB_HI_MASK                          0xffffe000
410
#define TLB_LO_MASK                         0x3fffffff
411
#define PAGEMASK_SHIFT                        13
412
#define TLB_LO_SHIFT                                 6
413
#define PCI_PAGE_SIZE                          0x01000000    /* 16 Mbyte */
414
#define MMU_PAGE_UNCACHED        0x00000010
415
#define MMU_PAGE_DIRTY                  0x00000004
416
#define MMU_PAGE_VALID                  0x00000002
417
#define MMU_PAGE_GLOBAL              0x00000001
418
#define PCI_MMU_PAGEMASK             0x00000fff
419
#define PCI_MMU_PAGEATTRIB    (MMU_PAGE_UNCACHED|MMU_PAGE_DIRTY| MMU_PAGE_VALID|MMU_PAGE_GLOBAL)
420
#define PCI_MEMORY_SPACE1           0x40000000
421
#define PCI_MEMORY_SPACE2           0x60000000
422
#define PCI_IO_SPACE                           0x18000000
423
/*
424
   Function name : mmuInit
425
                  Tlb Initialisation for the PCI  memory/IO windows.
426
*/
427
static void mmuInit (  ) {
428
        unsigned int Tlb_Attrib ;
429
        unsigned int Tlb_Hi     ;
430
        unsigned int Tlb_Lo0    ;
431
        unsigned int Tlb_Lo1    ;
432
        unsigned int Page_Size  ;
433
        unsigned int pageFrame  ;
434
        unsigned int Tlb_Inx    ;
435
 
436
        /* Uncached, dirty, global and valid MMU page */
437
          Tlb_Attrib = PCI_MMU_PAGEATTRIB ;
438
 
439
        Page_Size = PCI_MMU_PAGEMASK   ;
440
        Page_Size = (Page_Size << (PAGEMASK_SHIFT));
441
        hal_setPageSize(Page_Size);
442
 
443
/*
444
 * MMU mapping for PCI_MEMORY_SPACE1
445
 * Map 16MB pages
446
 * Virtual 0x40000000-0x40ffffff to Physical 0x40000000 - 0x40ffffff
447
 * Virtual 0x41000000-0x41ffffff to Physical 0x41000000 - 0x41ffffff
448
 */
449
 
450
        Tlb_Hi     = PCI_MEMORY_SPACE1     ; /* VPN2:VirtualPageframeNumber%2 */
451
        Tlb_Hi     = (Tlb_Hi & TLB_HI_MASK)  ;
452
 
453
        pageFrame  = PCI_MEMORY_SPACE1       ;
454
                                                                                  /* Even PFN:Page Frame Number */
455
        pageFrame  = pageFrame >> TLB_LO_SHIFT;
456
        Tlb_Lo0     = pageFrame ;
457
        Tlb_Lo0    = ( Tlb_Lo0 | Tlb_Attrib) ;
458
        Tlb_Lo0    = ( Tlb_Lo0 & TLB_LO_MASK);
459
 
460
        pageFrame  = (PCI_MEMORY_SPACE1 | PCI_PAGE_SIZE) ;
461
                                                                                /* Odd PFN:Page Frame Number*/
462
        pageFrame  = pageFrame >> TLB_LO_SHIFT ;
463
        Tlb_Lo1    = pageFrame               ;
464
        Tlb_Lo1    = ( Tlb_Lo1 | Tlb_Attrib) ;
465
        Tlb_Lo1    = ( Tlb_Lo1 & TLB_LO_MASK);
466
        Tlb_Inx    =           0             ;
467
        hal_setTlbEntry(Tlb_Inx, Tlb_Hi, Tlb_Lo0, Tlb_Lo1);
468
 
469
/*
470
 * MMU mapping for PCI_MEMORY_SPACE2
471
 * Virtual 0x60000000-0x60ffffff to Physical 0x60000000 - 0x60ffffff
472
 * Virtual 0x61000000-0x61ffffff to Physical 0x61000000 - 0x61ffffff
473
 */
474
        Tlb_Hi     = PCI_MEMORY_SPACE2       ;   /* VPN2    */
475
        Tlb_Hi     = ( Tlb_Hi & TLB_HI_MASK );
476
 
477
        pageFrame  = PCI_MEMORY_SPACE2       ;
478
        pageFrame  = pageFrame >> TLB_LO_SHIFT ; /*Even PFN */
479
        Tlb_Lo0    = pageFrame               ;
480
 
481
        Tlb_Lo0    = ( Tlb_Lo0 | Tlb_Attrib) ;
482
        Tlb_Lo0    = ( Tlb_Lo0 & TLB_LO_MASK);
483
 
484
        pageFrame  = ( PCI_MEMORY_SPACE2 | PCI_PAGE_SIZE ) ;
485
        pageFrame  = pageFrame >> TLB_LO_SHIFT ; /* Odd PFN */
486
        Tlb_Lo1    = pageFrame               ;
487
        Tlb_Lo1    = ( Tlb_Lo1 | Tlb_Attrib) ;
488
        Tlb_Lo1    = ( Tlb_Lo1 & TLB_LO_MASK);
489
        Tlb_Inx    =           1             ;
490
        hal_setTlbEntry(Tlb_Inx, Tlb_Hi, Tlb_Lo0, Tlb_Lo1);
491
 
492
/*
493
 * MMU mapping PCI IO space
494
 * Virtual 0x18000000-0x18ffffff to Physical 0x18000000 - 0x18ffffff
495
 * Virtual 0x19000000-0x19ffffff to Physical 0x19000000 - 0x19ffffff
496
 */
497
        Tlb_Hi     = PCI_IO_SPACE            ;   /* VPN2   */
498
        Tlb_Hi     = ( Tlb_Hi & TLB_HI_MASK );
499
 
500
        pageFrame  = PCI_IO_SPACE            ;
501
 
502
        pageFrame  = pageFrame >> TLB_LO_SHIFT ; /* Even PFN */
503
        Tlb_Lo0    = pageFrame               ;
504
        Tlb_Lo0    = ( Tlb_Lo0 | Tlb_Attrib) ;
505
        Tlb_Lo0    = ( Tlb_Lo0 & TLB_LO_MASK);
506
 
507
        pageFrame  = (PCI_IO_SPACE | PCI_PAGE_SIZE) ;
508
        pageFrame  = pageFrame >> TLB_LO_SHIFT ; /* Odd PFN  */
509
        Tlb_Lo1    = pageFrame               ;
510
        Tlb_Lo1    = ( Tlb_Lo1 | Tlb_Attrib) ;
511
        Tlb_Lo1    = ( Tlb_Lo1 & TLB_LO_MASK);
512
        Tlb_Inx    =           2             ;
513
        hal_setTlbEntry(Tlb_Inx, Tlb_Hi, Tlb_Lo0, Tlb_Lo1);
514
    }
515
 
516
 
517
 
518
 
519
/* ecos PCI functions */
520
 
521
 
522
 void   ecosPciConfigOutByte
523
        (  int busNo,
524
           int devFnNo,
525
           int regOffset,
526
           unsigned char data ){
527
 
528
          unsigned int    address ;
529
 
530
          address   = (  ( (busNo << 16) & 0x00ff0000 ) |
531
                         ( ( devFnNo << 8 )  & 0x0000ff00 )
532
                            );
533
          address = ( address | 0x80000000 | (regOffset ) );
534
          hal_sysConfigOutByte(address, data, (regOffset & 0x3) );
535
}
536
 
537
void   ecosPciConfigOutHalfWord
538
       ( int busNo,
539
         int devFnNo,
540
         int regOffset,
541
         unsigned short data ){
542
 
543
         unsigned int       address ;
544
 
545
         address   = (  ( (busNo << 16) & 0x00ff0000 ) |
546
                        ( ( devFnNo << 8 ) & 0x0000ff00)
547
                            );
548
         address = ( address | 0x80000000 | (regOffset ) );
549
         hal_sysConfigOutHalfWord(address, data, (regOffset & 0x3) );
550
}
551
 
552
 
553
void   ecosPciConfigOutWord
554
        ( int busNo,
555
          int devFnNo,
556
          int regOffset,
557
          unsigned int data ){
558
 
559
          unsigned int    address ;
560
          address   = (  ( (busNo << 16) & 0x00ff0000 ) |
561
                         ( ( devFnNo << 8 ) & 0x0000ff00)
562
                            );
563
          address = ( address | 0x80000000 | (regOffset ) );
564
 
565
          hal_sysConfigOutWord(address, data);
566
}
567
 
568
unsigned char ecosPciConfigInByte
569
        (int busNo,
570
         int devFnNo,
571
         int regOffset
572
                  ){
573
 
574
          unsigned int    address ;
575
          unsigned char  retVal   ;
576
 
577
         address   = (  ( (busNo << 16) & 0x00ff0000 ) |
578
                        ( ( devFnNo << 8 ) & 0x0000ff00)
579
                     );
580
         address = ( address | 0x80000000 | (regOffset ) );
581
                 sysDisableBusError( );
582
         retVal  = (unsigned char)(hal_sysConfigInByte(address));
583
                 sysEnableBusError( );
584
         return ( retVal );
585
}
586
 
587
unsigned short ecosPciConfigInHalfWord
588
        ( int busNo,
589
          int devFnNo,
590
          int regOffset
591
                  ){
592
 
593
          unsigned int            address;
594
          unsigned short           retVal;
595
 
596
          address   = (  ( (busNo << 16) & 0x00ff0000 ) |
597
                         ( ( devFnNo << 8 ) & 0x0000ff00)
598
                       );
599
         address = ( address | 0x80000000 | (regOffset ) );
600
                 sysDisableBusError( );
601
         retVal = (unsigned short)hal_sysConfigInHalfWord(address);
602
                 sysEnableBusError( );
603
                 return retVal;
604
 
605
}
606
unsigned int ecosPciConfigInWord
607
        ( int busNo,
608
          int devFnNo,
609
          int regOffset
610
                  ){
611
 
612
          unsigned int            address;
613
          unsigned int           retVal;
614
 
615
          address   = (  ( (busNo << 16) & 0x00ff0000 ) |
616
                              ( ( devFnNo << 8 ) & 0x0000ff00)
617
                       );
618
         address = ( address | 0x80000000 | regOffset );
619
                 sysDisableBusError( );
620
         retVal  = hal_sysConfigInWord(address);
621
                 sysEnableBusError( );
622
                 return retVal;
623
}
624
 
625
 
626
void displayLED(char *str, int count)
627
{
628
        char *pChar = (char *)0xB4000000;
629
 
630
        char temp;
631
 
632
        /* clear */
633
        temp = pChar[0x400];
634
 
635
        if (count)
636
                pChar[0xf]= str[0];
637
        else
638
                return;
639
 
640
        if (--count)
641
                pChar[0xb]= str[1];
642
        else
643
                return;
644
 
645
        if (--count)
646
                pChar[0x7]= str[2];
647
        else
648
                return;
649
 
650
        if (--count)
651
                pChar[0x3]= str[3];
652
        else
653
                return;
654
 
655
}
656
 
657
/*------------------------------------------------------------------------*/
658
/* End of plf_misc.c                                                      */
659
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.