Search
lxdream.org :: lxdream/test/asic.c
lxdream 0.9.1
released Jun 29
Download Now
filename test/asic.c
changeset 815:866c103d72cd
prev753:1fe39c3a9bbc
author nkeynes
date Sat Dec 27 02:59:35 2008 +0000 (15 years ago)
branchlxdream-mem
permissions -rw-r--r--
last change Replace fpscr_mask/fpscr flags in xlat_cache_block with a single xlat_sh4_mode,
which tracks the field of the same name in sh4r - actually a little faster this way.
Now depends on SR.MD, FPSCR.PR and FPSCR.SZ (although it doesn't benefit from the SR
flag yet).

Also fixed the failure to check the flags in the common case (code address returned
by previous block) which took away the performance benefits, but oh well.
view annotate diff log raw
     1 /**
     2  * $Id$
     3  * 
     4  * General ASIC support code
     5  *
     6  * Copyright (c) 2006 Nathan Keynes.
     7  *
     8  * This program is free software; you can redistribute it and/or modify
     9  * it under the terms of the GNU General Public License as published by
    10  * the Free Software Foundation; either version 2 of the License, or
    11  * (at your option) any later version.
    12  *
    13  * This program is distributed in the hope that it will be useful,
    14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    16  * GNU General Public License for more details.
    17  */
    19 #include "lib.h"
    21 #define ASIC_BASE 0xA05F6000
    22 #define ASIC_PIRQ(n) (ASIC_BASE + 0x900 + (n<<2))
    23 #define ASIC_IRQA(n) (ASIC_BASE + 0x910 + (n<<2))
    24 #define ASIC_IRQB(n) (ASIC_BASE + 0x920 + (n<<2))
    25 #define ASIC_IRQC(n) (ASIC_BASE + 0x930 + (n<<2))
    26 #define G2_FIFO  (ASIC_BASE + 0x88C)
    27 #define TIMEOUT 10000000
    29 /**
    30  * Wait for an ASIC event. 
    31  * @return 0 if the event occurred, otherwise -1 if the wait timed out.
    32  */
    33 int asic_wait( int event )
    34 {
    35     int n = event >> 5;
    36     unsigned int mask = (1<< (event&0x1f));
    37     int i;
    38     for( i=0; i<TIMEOUT; i++ ) {
    39 	if( long_read(ASIC_PIRQ(n)) & mask ) {
    40 	    return 0;
    41 	}
    42     }
    43     return -1; /* Timeout */
    44 }
    46 /**
    47  * Wait for either of 2 ASIC events. 
    48  * @return the event id if the event occurred, otherwise -1 if the wait timed out.
    49  */
    50 int asic_wait2( int event1, int event2 )
    51 {
    52     int n1 = event1 >> 5;
    53     int n2 = event2 >> 5;
    54     unsigned int mask1 = (1<< (event1&0x1f));
    55     unsigned int mask2 = (1<< (event2&0x1f));
    56     int i;
    57     for( i=0; i<TIMEOUT; i++ ) {
    58 	if( long_read(ASIC_PIRQ(n1)) & mask1 ) {
    59 	    return event1;
    60 	}
    61 	if( long_read(ASIC_PIRQ(n2)) & mask2 ) {
    62             return event2;
    63         }
    64     }
    65     return -1; /* Timeout */
    66 }
    68 /**
    69  * Clear all asic events
    70  */
    71 void asic_clear()
    72 {
    73     long_write(ASIC_PIRQ(0), 0xFFFFFFFF);
    74     long_write(ASIC_PIRQ(1), 0xFFFFFFFF);
    75     long_write(ASIC_PIRQ(2), 0xFFFFFFFF);
    76 }
    78 int asic_check( int event ) 
    79 {
    80     int n = event >> 5;
    81     unsigned int mask = (1<< (event&0x1f));
    82     return (long_read(ASIC_PIRQ(n)) & mask) != 0;
    83 }
    85 void asic_mask_all()
    86 {
    87     long_write(ASIC_IRQA(0), 0);
    88     long_write(ASIC_IRQA(1), 0);
    89     long_write(ASIC_IRQA(2), 0);
    90     long_write(ASIC_IRQB(0), 0);
    91     long_write(ASIC_IRQB(1), 0);
    92     long_write(ASIC_IRQB(2), 0);
    93     long_write(ASIC_IRQC(0), 0);
    94     long_write(ASIC_IRQC(1), 0);
    95     long_write(ASIC_IRQC(2), 0);
    96 }
    98 /**
    99  * Print the contents of the ASIC event registers to the supplied FILE
   100  */
   101 void asic_dump( FILE *f )
   102 {
   103     int i,j;
   104     fprintf( f, "Events: " );
   105     for( i=0; i<3; i++ ) {
   106 	uint32_t val = long_read(ASIC_PIRQ(i));
   107 	for( j=0; j<32; j++ ) {
   108 	    if( val & (1<<j) ) {
   109 		fprintf( f, "%d ", (i<<5)+j );
   110 	    }
   111 	}
   112     }
   113     fprintf( f, "\n" );
   114 }
   116 /**
   117  * Wait until the g2 fifo is clear to write more data.
   118  */
   119 int g2_fifo_wait()
   120 {
   121     int i;
   122     for (i=0; i<0x1800; i++) {
   123         if (!(long_read(G2_FIFO) & 0x11)) {
   124             return 0;
   125         }
   127     }
   128     return -1;
.