Search
lxdream.org :: lxdream/src/asic.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/asic.c
changeset 35:21a4be098304
prev31:495e480360d7
next42:d06affd949ec
author nkeynes
date Mon Dec 26 03:54:55 2005 +0000 (14 years ago)
permissions -rw-r--r--
last change Remove modules.h - move definitions into dream.h
Add source string to output list (taken from module name)
ARM Work in progress
file annotate diff log raw
nkeynes@31
     1
/**
nkeynes@35
     2
 * $Id: asic.c,v 1.8 2005-12-26 03:54:52 nkeynes Exp $
nkeynes@31
     3
 *
nkeynes@31
     4
 * Support for the miscellaneous ASIC functions (Primarily event multiplexing,
nkeynes@31
     5
 * and DMA). 
nkeynes@31
     6
 *
nkeynes@31
     7
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@31
     8
 *
nkeynes@31
     9
 * This program is free software; you can redistribute it and/or modify
nkeynes@31
    10
 * it under the terms of the GNU General Public License as published by
nkeynes@31
    11
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@31
    12
 * (at your option) any later version.
nkeynes@31
    13
 *
nkeynes@31
    14
 * This program is distributed in the hope that it will be useful,
nkeynes@31
    15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@31
    16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@31
    17
 * GNU General Public License for more details.
nkeynes@31
    18
 */
nkeynes@35
    19
nkeynes@35
    20
#define MODULE asic_module
nkeynes@35
    21
nkeynes@1
    22
#include <assert.h>
nkeynes@1
    23
#include "dream.h"
nkeynes@1
    24
#include "mem.h"
nkeynes@1
    25
#include "sh4/intc.h"
nkeynes@2
    26
#include "dreamcast.h"
nkeynes@25
    27
#include "maple/maple.h"
nkeynes@25
    28
#include "gdrom/ide.h"
nkeynes@15
    29
#include "asic.h"
nkeynes@1
    30
#define MMIO_IMPL
nkeynes@1
    31
#include "asic.h"
nkeynes@1
    32
/*
nkeynes@1
    33
 * Open questions:
nkeynes@1
    34
 *   1) Does changing the mask after event occurance result in the
nkeynes@1
    35
 *      interrupt being delivered immediately?
nkeynes@1
    36
 * TODO: Logic diagram of ASIC event/interrupt logic.
nkeynes@1
    37
 *
nkeynes@1
    38
 * ... don't even get me started on the "EXTDMA" page, about which, apparently,
nkeynes@1
    39
 * practically nothing is publicly known...
nkeynes@1
    40
 */
nkeynes@1
    41
nkeynes@15
    42
struct dreamcast_module asic_module = { "ASIC", asic_init, NULL, NULL, NULL,
nkeynes@23
    43
					NULL, NULL, NULL };
nkeynes@15
    44
nkeynes@20
    45
void asic_check_cleared_events( void );
nkeynes@20
    46
nkeynes@1
    47
void asic_init( void )
nkeynes@1
    48
{
nkeynes@1
    49
    register_io_region( &mmio_region_ASIC );
nkeynes@1
    50
    register_io_region( &mmio_region_EXTDMA );
nkeynes@1
    51
    mmio_region_ASIC.trace_flag = 0; /* Because this is called so often */
nkeynes@1
    52
    asic_event( EVENT_GDROM_CMD );
nkeynes@1
    53
}
nkeynes@1
    54
nkeynes@1
    55
void mmio_region_ASIC_write( uint32_t reg, uint32_t val )
nkeynes@1
    56
{
nkeynes@1
    57
    switch( reg ) {
nkeynes@1
    58
        case PIRQ0:
nkeynes@1
    59
        case PIRQ1:
nkeynes@1
    60
        case PIRQ2:
nkeynes@1
    61
            /* Clear any interrupts */
nkeynes@1
    62
            MMIO_WRITE( ASIC, reg, MMIO_READ(ASIC, reg)&~val );
nkeynes@20
    63
	    DEBUG( "ASIC Write %08X => %08X", val, reg );
nkeynes@20
    64
	    asic_check_cleared_events();
nkeynes@1
    65
            break;
nkeynes@1
    66
        case MAPLE_STATE:
nkeynes@1
    67
            MMIO_WRITE( ASIC, reg, val );
nkeynes@1
    68
            if( val & 1 ) {
nkeynes@1
    69
                uint32_t maple_addr = MMIO_READ( ASIC, MAPLE_DMA) &0x1FFFFFE0;
nkeynes@2
    70
		WARN( "Maple request initiated at %08X, halting", maple_addr );
nkeynes@2
    71
                maple_handle_buffer( maple_addr );
nkeynes@1
    72
                MMIO_WRITE( ASIC, reg, 0 );
nkeynes@2
    73
//                dreamcast_stop();
nkeynes@1
    74
            }
nkeynes@1
    75
            break;
nkeynes@1
    76
        default:
nkeynes@1
    77
            MMIO_WRITE( ASIC, reg, val );
nkeynes@1
    78
            WARN( "Write to ASIC (%03X <= %08X) [%s: %s]",
nkeynes@1
    79
                  reg, val, MMIO_REGID(ASIC,reg), MMIO_REGDESC(ASIC,reg) );
nkeynes@1
    80
    }
nkeynes@1
    81
}
nkeynes@1
    82
nkeynes@1
    83
int32_t mmio_region_ASIC_read( uint32_t reg )
nkeynes@1
    84
{
nkeynes@1
    85
    int32_t val;
nkeynes@1
    86
    switch( reg ) {
nkeynes@2
    87
        /*
nkeynes@2
    88
        case 0x89C:
nkeynes@2
    89
            sh4_stop();
nkeynes@2
    90
            return 0x000000B;
nkeynes@2
    91
        */     
nkeynes@1
    92
        case PIRQ0:
nkeynes@1
    93
        case PIRQ1:
nkeynes@1
    94
        case PIRQ2:
nkeynes@1
    95
            val = MMIO_READ(ASIC, reg);
nkeynes@1
    96
//            WARN( "Read from ASIC (%03X => %08X) [%s: %s]",
nkeynes@1
    97
//                  reg, val, MMIO_REGID(ASIC,reg), MMIO_REGDESC(ASIC,reg) );
nkeynes@1
    98
            return val;            
nkeynes@1
    99
        case G2STATUS:
nkeynes@1
   100
            return 0; /* find out later if there's any cases we actually need to care about */
nkeynes@1
   101
        default:
nkeynes@1
   102
            val = MMIO_READ(ASIC, reg);
nkeynes@1
   103
            WARN( "Read from ASIC (%03X => %08X) [%s: %s]",
nkeynes@1
   104
                  reg, val, MMIO_REGID(ASIC,reg), MMIO_REGDESC(ASIC,reg) );
nkeynes@1
   105
            return val;
nkeynes@1
   106
    }
nkeynes@1
   107
           
nkeynes@1
   108
}
nkeynes@1
   109
nkeynes@1
   110
void asic_event( int event )
nkeynes@1
   111
{
nkeynes@1
   112
    int offset = ((event&0x60)>>3);
nkeynes@1
   113
    int result = (MMIO_READ(ASIC, PIRQ0 + offset))  |=  (1<<(event&0x1F));
nkeynes@1
   114
nkeynes@1
   115
    if( result & MMIO_READ(ASIC, IRQA0 + offset) )
nkeynes@1
   116
        intc_raise_interrupt( INT_IRQ13 );
nkeynes@1
   117
    if( result & MMIO_READ(ASIC, IRQB0 + offset) )
nkeynes@1
   118
        intc_raise_interrupt( INT_IRQ11 );
nkeynes@1
   119
    if( result & MMIO_READ(ASIC, IRQC0 + offset) )
nkeynes@1
   120
        intc_raise_interrupt( INT_IRQ9 );
nkeynes@1
   121
}
nkeynes@1
   122
nkeynes@20
   123
void asic_check_cleared_events( )
nkeynes@20
   124
{
nkeynes@20
   125
    int i, setA = 0, setB = 0, setC = 0;
nkeynes@20
   126
    uint32_t bits;
nkeynes@20
   127
    for( i=0; i<3; i++ ) {
nkeynes@20
   128
	bits = MMIO_READ( ASIC, PIRQ0 + i );
nkeynes@20
   129
	setA |= (bits & MMIO_READ(ASIC, IRQA0 + i ));
nkeynes@20
   130
	setB |= (bits & MMIO_READ(ASIC, IRQB0 + i ));
nkeynes@20
   131
	setC |= (bits & MMIO_READ(ASIC, IRQC0 + i ));
nkeynes@20
   132
    }
nkeynes@20
   133
    if( setA == 0 )
nkeynes@20
   134
	intc_clear_interrupt( INT_IRQ13 );
nkeynes@20
   135
    if( setB == 0 )
nkeynes@20
   136
	intc_clear_interrupt( INT_IRQ11 );
nkeynes@20
   137
    if( setC == 0 )
nkeynes@20
   138
	intc_clear_interrupt( INT_IRQ9 );
nkeynes@20
   139
}
nkeynes@1
   140
nkeynes@1
   141
nkeynes@1
   142
MMIO_REGION_WRITE_FN( EXTDMA, reg, val )
nkeynes@1
   143
{
nkeynes@2
   144
    switch( reg ) {
nkeynes@2
   145
        case IDEALTSTATUS: /* Device control */
nkeynes@2
   146
            ide_write_control( val );
nkeynes@2
   147
            break;
nkeynes@2
   148
        case IDEDATA:
nkeynes@2
   149
            ide_write_data_pio( val );
nkeynes@2
   150
            break;
nkeynes@2
   151
        case IDEFEAT:
nkeynes@2
   152
            if( ide_can_write_regs() )
nkeynes@2
   153
                idereg.feature = (uint8_t)val;
nkeynes@2
   154
            break;
nkeynes@2
   155
        case IDECOUNT:
nkeynes@2
   156
            if( ide_can_write_regs() )
nkeynes@2
   157
                idereg.count = (uint8_t)val;
nkeynes@2
   158
            break;
nkeynes@2
   159
        case IDELBA0:
nkeynes@2
   160
            if( ide_can_write_regs() )
nkeynes@2
   161
                idereg.lba0 = (uint8_t)val;
nkeynes@2
   162
            break;
nkeynes@2
   163
        case IDELBA1:
nkeynes@2
   164
            if( ide_can_write_regs() )
nkeynes@2
   165
                idereg.lba1 = (uint8_t)val;
nkeynes@2
   166
            break;
nkeynes@2
   167
        case IDELBA2:
nkeynes@2
   168
            if( ide_can_write_regs() )
nkeynes@2
   169
                idereg.lba2 = (uint8_t)val;
nkeynes@2
   170
            break;
nkeynes@2
   171
        case IDEDEV:
nkeynes@2
   172
            if( ide_can_write_regs() )
nkeynes@2
   173
                idereg.device = (uint8_t)val;
nkeynes@2
   174
            break;
nkeynes@2
   175
        case IDECMD:
nkeynes@2
   176
            if( ide_can_write_regs() ) {
nkeynes@2
   177
                ide_clear_interrupt();
nkeynes@2
   178
                ide_write_command( (uint8_t)val );
nkeynes@2
   179
            }
nkeynes@2
   180
            break;
nkeynes@2
   181
            
nkeynes@2
   182
        default:
nkeynes@2
   183
            MMIO_WRITE( EXTDMA, reg, val );
nkeynes@2
   184
    }
nkeynes@1
   185
}
nkeynes@1
   186
nkeynes@1
   187
MMIO_REGION_READ_FN( EXTDMA, reg )
nkeynes@1
   188
{
nkeynes@1
   189
    switch( reg ) {
nkeynes@2
   190
        case IDEALTSTATUS: return idereg.status;
nkeynes@2
   191
        case IDEDATA: return ide_read_data_pio( );
nkeynes@2
   192
        case IDEFEAT: return idereg.error;
nkeynes@2
   193
        case IDECOUNT:return idereg.count;
nkeynes@2
   194
        case IDELBA0: return idereg.disc;
nkeynes@2
   195
        case IDELBA1: return idereg.lba1;
nkeynes@2
   196
        case IDELBA2: return idereg.lba2;
nkeynes@2
   197
        case IDEDEV: return idereg.device;
nkeynes@2
   198
        case IDECMD:
nkeynes@2
   199
            ide_clear_interrupt();
nkeynes@2
   200
            return idereg.status;
nkeynes@1
   201
        default:
nkeynes@1
   202
            return MMIO_READ( EXTDMA, reg );
nkeynes@1
   203
    }
nkeynes@1
   204
}
nkeynes@1
   205
.